Skip to content

Commit

Permalink
re-add platform mapping lost from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHolstien committed Feb 15, 2022
1 parent 0436d82 commit 288937d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 46 deletions.
Expand Up @@ -17,6 +17,7 @@
import com.linkedin.datahub.graphql.generated.ChartQueryType;
import com.linkedin.datahub.graphql.generated.ChartType;
import com.linkedin.datahub.graphql.generated.Container;
import com.linkedin.datahub.graphql.generated.DataPlatform;
import com.linkedin.datahub.graphql.generated.Dataset;
import com.linkedin.datahub.graphql.generated.Domain;
import com.linkedin.datahub.graphql.generated.EntityType;
Expand All @@ -34,6 +35,8 @@
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.EnvelopedAspectMap;
import com.linkedin.metadata.key.ChartKey;
import com.linkedin.metadata.key.DataPlatformKey;
import com.linkedin.metadata.utils.EntityKeyUtils;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;

Expand Down Expand Up @@ -81,6 +84,11 @@ private void mapChartKey(@Nonnull Chart chart, @Nonnull DataMap dataMap) {
final ChartKey gmsKey = new ChartKey(dataMap);
chart.setChartId(gmsKey.getChartId());
chart.setTool(gmsKey.getDashboardTool());
chart.setPlatform(DataPlatform.builder()
.setType(EntityType.DATA_PLATFORM)
.setUrn(EntityKeyUtils
.convertEntityKeyToUrn(new DataPlatformKey()
.setPlatformName(gmsKey.getDashboardTool()), DATA_PLATFORM_ENTITY_NAME).toString()).build());
}

private void mapChartInfo(@Nonnull Chart chart, @Nonnull DataMap dataMap) {
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.linkedin.datahub.graphql.generated.DashboardEditableProperties;
import com.linkedin.datahub.graphql.generated.DashboardInfo;
import com.linkedin.datahub.graphql.generated.DashboardProperties;
import com.linkedin.datahub.graphql.generated.DataPlatform;
import com.linkedin.datahub.graphql.generated.Domain;
import com.linkedin.datahub.graphql.generated.EntityType;
import com.linkedin.datahub.graphql.types.common.mappers.AuditStampMapper;
Expand All @@ -31,6 +32,8 @@
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.EnvelopedAspectMap;
import com.linkedin.metadata.key.DashboardKey;
import com.linkedin.metadata.key.DataPlatformKey;
import com.linkedin.metadata.utils.EntityKeyUtils;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;

Expand Down Expand Up @@ -75,6 +78,11 @@ private void mapDashboardKey(@Nonnull Dashboard dashboard, @Nonnull DataMap data
final DashboardKey gmsKey = new DashboardKey(dataMap);
dashboard.setDashboardId(gmsKey.getDashboardId());
dashboard.setTool(gmsKey.getDashboardTool());
dashboard.setPlatform(DataPlatform.builder()
.setType(EntityType.DATA_PLATFORM)
.setUrn(EntityKeyUtils
.convertEntityKeyToUrn(new DataPlatformKey()
.setPlatformName(gmsKey.getDashboardTool()), DATA_PLATFORM_ENTITY_NAME).toString()).build());
}

private void mapDashboardInfo(@Nonnull Dashboard dashboard, @Nonnull DataMap dataMap) {
Expand Down
Expand Up @@ -19,12 +19,14 @@
import com.linkedin.datahub.graphql.types.common.mappers.OwnershipMapper;
import com.linkedin.datahub.graphql.types.common.mappers.StatusMapper;
import com.linkedin.datahub.graphql.types.common.mappers.StringMapMapper;
import com.linkedin.datahub.graphql.types.common.mappers.util.MappingHelper;
import com.linkedin.datahub.graphql.types.glossary.mappers.GlossaryTermsMapper;
import com.linkedin.datahub.graphql.types.mappers.ModelMapper;
import com.linkedin.datahub.graphql.types.tag.mappers.GlobalTagsMapper;
import com.linkedin.datajob.EditableDataFlowProperties;
import com.linkedin.domain.Domains;
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.EnvelopedAspectMap;
import com.linkedin.metadata.key.DataFlowKey;
import com.linkedin.metadata.key.DataPlatformKey;
import com.linkedin.metadata.utils.EntityKeyUtils;
Expand All @@ -46,54 +48,43 @@ public DataFlow apply(@Nonnull final EntityResponse entityResponse) {
final DataFlow result = new DataFlow();
result.setUrn(entityResponse.getUrn().toString());
result.setType(EntityType.DATA_FLOW);
EnvelopedAspectMap aspectMap = entityResponse.getAspects();
MappingHelper<DataFlow> mappingHelper = new MappingHelper<>(aspectMap, result);
mappingHelper.mapToResult(DATA_FLOW_KEY_ASPECT_NAME, this::mapKey);
mappingHelper.mapToResult(DATA_FLOW_INFO_ASPECT_NAME, this::mapInfo);
mappingHelper.mapToResult(EDITABLE_DATA_FLOW_PROPERTIES_ASPECT_NAME, this::mapEditableProperties);
mappingHelper.mapToResult(OWNERSHIP_ASPECT_NAME, (dataFlow, dataMap) ->
dataFlow.setOwnership(OwnershipMapper.map(new Ownership(dataMap))));
mappingHelper.mapToResult(STATUS_ASPECT_NAME, (dataFlow, dataMap) ->
dataFlow.setStatus(StatusMapper.map(new Status(dataMap))));
mappingHelper.mapToResult(GLOBAL_TAGS_ASPECT_NAME, this::mapGlobalTags);
mappingHelper.mapToResult(INSTITUTIONAL_MEMORY_ASPECT_NAME, (dataFlow, dataMap) ->
dataFlow.setInstitutionalMemory(InstitutionalMemoryMapper.map(new InstitutionalMemory(dataMap))));
mappingHelper.mapToResult(GLOSSARY_TERMS_ASPECT_NAME, (dataFlow, dataMap) ->
dataFlow.setGlossaryTerms(GlossaryTermsMapper.map(new GlossaryTerms(dataMap))));
mappingHelper.mapToResult(DOMAINS_ASPECT_NAME, this::mapDomains);
mappingHelper.mapToResult(DEPRECATION_ASPECT_NAME, (dataFlow, dataMap) ->
dataFlow.setDeprecation(DeprecationMapper.map(new Deprecation(dataMap))));

entityResponse.getAspects().forEach((name, aspect) -> {
DataMap data = aspect.getValue().data();
if (DATA_FLOW_KEY_ASPECT_NAME.equals(name)) {
final DataFlowKey gmsKey = new DataFlowKey(data);
result.setOrchestrator(gmsKey.getOrchestrator());
result.setFlowId(gmsKey.getFlowId());
result.setCluster(gmsKey.getCluster());
result.setPlatform(DataPlatform.builder()
.setType(EntityType.DATA_PLATFORM)
.setUrn(EntityKeyUtils
.convertEntityKeyToUrn(new DataPlatformKey()
.setPlatformName(gmsKey.getOrchestrator()), DATA_PLATFORM_ENTITY_NAME).toString()).build());
} else if (DATA_FLOW_INFO_ASPECT_NAME.equals(name)) {
final com.linkedin.datajob.DataFlowInfo gmsDataFlowInfo = new com.linkedin.datajob.DataFlowInfo(data);
result.setInfo(mapDataFlowInfo(gmsDataFlowInfo));
result.setProperties(mapDataFlowInfoToProperties(gmsDataFlowInfo));
} else if (EDITABLE_DATA_FLOW_PROPERTIES_ASPECT_NAME.equals(name)) {
final EditableDataFlowProperties editableDataFlowProperties = new EditableDataFlowProperties(data);
final DataFlowEditableProperties dataFlowEditableProperties = new DataFlowEditableProperties();
dataFlowEditableProperties.setDescription(editableDataFlowProperties.getDescription());
result.setEditableProperties(dataFlowEditableProperties);
} else if (OWNERSHIP_ASPECT_NAME.equals(name)) {
result.setOwnership(OwnershipMapper.map(new Ownership(data)));
} else if (STATUS_ASPECT_NAME.equals(name)) {
result.setStatus(StatusMapper.map(new Status(data)));
} else if (GLOBAL_TAGS_ASPECT_NAME.equals(name)) {
com.linkedin.datahub.graphql.generated.GlobalTags globalTags = GlobalTagsMapper.map(new GlobalTags(data));
result.setGlobalTags(globalTags);
result.setTags(globalTags);
} else if (INSTITUTIONAL_MEMORY_ASPECT_NAME.equals(name)) {
result.setInstitutionalMemory(InstitutionalMemoryMapper.map(new InstitutionalMemory(data)));
} else if (GLOSSARY_TERMS_ASPECT_NAME.equals(name)) {
result.setGlossaryTerms(GlossaryTermsMapper.map(new GlossaryTerms(data)));
} else if (DOMAINS_ASPECT_NAME.equals(name)) {
final Domains domains = new Domains(data);
// Currently we only take the first domain if it exists.
if (domains.getDomains().size() > 0) {
result.setDomain(Domain.builder()
.setType(EntityType.DOMAIN)
.setUrn(domains.getDomains().get(0).toString()).build());
}
} else if (DEPRECATION_ASPECT_NAME.equals(name)) {
result.setDeprecation(DeprecationMapper.map(new Deprecation(data)));
}
});
return mappingHelper.getResult();
}

return result;
private void mapKey(@Nonnull DataFlow dataFlow, @Nonnull DataMap dataMap) {
final DataFlowKey gmsKey = new DataFlowKey(dataMap);
dataFlow.setOrchestrator(gmsKey.getOrchestrator());
dataFlow.setFlowId(gmsKey.getFlowId());
dataFlow.setCluster(gmsKey.getCluster());
dataFlow.setPlatform(DataPlatform.builder()
.setType(EntityType.DATA_PLATFORM)
.setUrn(EntityKeyUtils
.convertEntityKeyToUrn(new DataPlatformKey()
.setPlatformName(gmsKey.getOrchestrator()), DATA_PLATFORM_ENTITY_NAME).toString()).build());
}

private void mapInfo(@Nonnull DataFlow dataFlow, @Nonnull DataMap dataMap) {
final com.linkedin.datajob.DataFlowInfo gmsDataFlowInfo = new com.linkedin.datajob.DataFlowInfo(dataMap);
dataFlow.setInfo(mapDataFlowInfo(gmsDataFlowInfo));
dataFlow.setProperties(mapDataFlowInfoToProperties(gmsDataFlowInfo));
}

/**
Expand Down Expand Up @@ -129,4 +120,27 @@ private DataFlowProperties mapDataFlowInfoToProperties(final com.linkedin.datajo
}
return result;
}

private void mapEditableProperties(@Nonnull DataFlow dataFlow, @Nonnull DataMap dataMap) {
final EditableDataFlowProperties editableDataFlowProperties = new EditableDataFlowProperties(dataMap);
final DataFlowEditableProperties dataFlowEditableProperties = new DataFlowEditableProperties();
dataFlowEditableProperties.setDescription(editableDataFlowProperties.getDescription());
dataFlow.setEditableProperties(dataFlowEditableProperties);
}

private void mapGlobalTags(@Nonnull DataFlow dataFlow, @Nonnull DataMap dataMap) {
com.linkedin.datahub.graphql.generated.GlobalTags globalTags = GlobalTagsMapper.map(new GlobalTags(dataMap));
dataFlow.setGlobalTags(globalTags);
dataFlow.setTags(globalTags);
}

private void mapDomains(@Nonnull DataFlow dataFlow, @Nonnull DataMap dataMap) {
final Domains domains = new Domains(dataMap);
// Currently we only take the first domain if it exists.
if (domains.getDomains().size() > 0) {
dataFlow.setDomain(Domain.builder()
.setType(EntityType.DOMAIN)
.setUrn(domains.getDomains().get(0).toString()).build());
}
}
}

0 comments on commit 288937d

Please sign in to comment.