Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GraphQL): Loosen read time validations on DataPlatforms #2185

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import com.linkedin.common.urn.DataPlatformUrn;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.types.EntityType;
import com.linkedin.datahub.graphql.types.mappers.DataPlatformInfoMapper;
import com.linkedin.datahub.graphql.generated.DataPlatform;
import com.linkedin.datahub.graphql.types.mappers.DataPlatformMapper;
import com.linkedin.dataplatform.client.DataPlatforms;

import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -30,16 +31,11 @@ public List<DataPlatform> batchLoad(final List<String> urns, final QueryContext
try {
if (_urnToPlatform == null) {
_urnToPlatform = _dataPlatformsClient.getAllPlatforms().stream()
.filter(com.linkedin.dataPlatforms.DataPlatform::hasDataPlatformInfo)
.map(platform -> new DataPlatform(
new DataPlatformUrn(platform.getName()).toString(),
com.linkedin.datahub.graphql.generated.EntityType.DATA_PLATFORM,
platform.getName(),
DataPlatformInfoMapper.map(platform.getDataPlatformInfo())))
.map(DataPlatformMapper::map)
.collect(Collectors.toMap(DataPlatform::getUrn, platform -> platform));
}
return urns.stream()
.map(key -> _urnToPlatform.get(key))
.map(key -> _urnToPlatform.containsKey(key) ? _urnToPlatform.get(key) : getUnknownDataPlatform(key))
.collect(Collectors.toList());
} catch (Exception e) {
throw new RuntimeException("Failed to batch load DataPlatforms", e);
Expand All @@ -50,4 +46,14 @@ public List<DataPlatform> batchLoad(final List<String> urns, final QueryContext
public com.linkedin.datahub.graphql.generated.EntityType type() {
return com.linkedin.datahub.graphql.generated.EntityType.DATA_PLATFORM;
}

private DataPlatform getUnknownDataPlatform(final String urnStr) {
try {
final com.linkedin.dataPlatforms.DataPlatform platform = new com.linkedin.dataPlatforms.DataPlatform()
.setName(DataPlatformUrn.createFromString(urnStr).getPlatformNameEntity());
return DataPlatformMapper.map(platform);
} catch (URISyntaxException e) {
throw new RuntimeException(String.format("Invalid DataPlatformUrn %s provided", urnStr), e);
}
}
}