/** * @return a {@link String} which describes the {@link MetadataEntity} for a user in plain english. * If the {@link MetadataEntity} represents a known CDAP entity then the description is worded to show relations * in the hierarchy. */ public String getDescription() { return getDescription(new StringBuilder(), getType()); }
private String addQueryParams(String path, MetadataEntity metadataEntity, @Nullable MetadataScope scope, boolean aggregateRun) { StringBuilder builder = new StringBuilder(path); String prefix = "?"; if (!Iterables.getLast(metadataEntity.getKeys()).equalsIgnoreCase(metadataEntity.getType())) { // if last leaf node is not the entity type specify it through query para builder.append(prefix); builder.append("type="); builder.append(metadataEntity.getType()); prefix = "&"; } // the default value of aggregateRun is true so in the case it is false we need to include it as query param if (!aggregateRun) { builder.append(prefix); builder.append("aggregateRun="); builder.append(false); prefix = "&"; } if (scope == null) { return builder.toString(); } else { builder.append(prefix); builder.append("scope="); builder.append(scope); } return builder.toString(); } }
/** * Returns the EntityId represented by the given MetadataEntity. Note: Custom MetadataEntity cannot be converted * into EntityId hence this call is only safe to be called if the MetadataEntity does represent an EntityId and can * actually be converted to an EntityId. * @param metadataEntity the MetadataEntity which needs to be converted to EntityId * @return the EntityId * @throws IllegalArgumentException if the metadataEntity does not represent an EntityId and is a custom * metadataEntity. */ public static <T extends EntityId> T fromMetadataEntity(MetadataEntity metadataEntity) { // check that the type of teh metadata entity is known type EntityType.valueOf(metadataEntity.getType().toUpperCase()); return getSelfOrParentEntityId(metadataEntity); }
/** * Returns the EntityId represented by the given MetadataEntity. Note: Custom MetadataEntity cannot be converted * into EntityId hence this call is only safe to be called if the MetadataEntity does represent an EntityId and can * actually be converted to an EntityId. * @param metadataEntity the MetadataEntity which needs to be converted to EntityId * @return the EntityId * @throws IllegalArgumentException if the metadataEntity does not represent an EntityId and is a custom * metadataEntity. */ public static <T extends EntityId> T fromMetadataEntity(MetadataEntity metadataEntity) { // check that the type of teh metadata entity is known type EntityType.valueOf(metadataEntity.getType().toUpperCase()); return getSelfOrParentEntityId(metadataEntity); }
/** * Returns a CLI friendly representation of MetadataEntity. * For a dataset ds1 in ns1 the EntityId representation will be * <pre>dataset:ns1.ds1</pre> * It's equivalent MetadataEntity representation will be * <pre>MetadataEntity{details={namespace=ns1, dataset=ds1}, type='dataset'}</pre> * The CLI friendly representation will be * <pre>namespace=ns1,dataset=ds1,type=dataset</pre> * * Note: It is not necessary to give a type, if a type is not provided the * last key-value pair's key in the hierarchy will be considered as the type. */ public static String toCliString(MetadataEntity metadataEntity) { StringBuilder builder = new StringBuilder(); for (MetadataEntity.KeyValue keyValue : metadataEntity) { builder.append(keyValue.getKey()); builder.append(METADATA_ENTITY_KV_SEPARATOR); builder.append(keyValue.getValue()); builder.append(METADATA_ENTITY_PARTS_SEPARATOR); } builder.append(METADATA_ENTITY_TYPE); builder.append(METADATA_ENTITY_KV_SEPARATOR); builder.append(metadataEntity.getType()); return builder.toString(); }
/** * Returns a CLI friendly representation of MetadataEntity. * For a dataset ds1 in ns1 the EntityId representation will be * <pre>dataset:ns1.ds1</pre> * It's equivalent MetadataEntity representation will be * <pre>MetadataEntity{details={namespace=ns1, dataset=ds1}, type='dataset'}</pre> * The CLI friendly representation will be * <pre>namespace=ns1,dataset=ds1,type=dataset</pre> * * Note: It is not necessary to give a type, if a type is not provided the * last key-value pair's key in the hierarchy will be considered as the type. */ public static String toCliString(MetadataEntity metadataEntity) { StringBuilder builder = new StringBuilder(); for (MetadataEntity.KeyValue keyValue : metadataEntity) { builder.append(keyValue.getKey()); builder.append(METADATA_ENTITY_KV_SEPARATOR); builder.append(keyValue.getValue()); builder.append(METADATA_ENTITY_PARTS_SEPARATOR); } builder.append(METADATA_ENTITY_TYPE); builder.append(METADATA_ENTITY_KV_SEPARATOR); builder.append(metadataEntity.getType()); return builder.toString(); }
private Set<MetadataRecord> getMetadata(MetadataEntity metadataEntity, @Nullable String scope, boolean aggregateRun) throws BadRequestException { // the lineage admin handles the metadata call for program runs so delegate the call to that Set<MetadataRecord> metadata; if (aggregateRun && metadataEntity.getType().equals(MetadataEntity.PROGRAM_RUN)) { // CDAP-13721 for backward compatibility we need to support metadata aggregation of runId. metadata = lineageAdmin.getMetadataForRun(EntityId.fromMetadataEntity(metadataEntity)); } else { if (scope == null) { metadata = metadataAdmin.getMetadata(metadataEntity); } else { metadata = metadataAdmin.getMetadata(validateScope(scope), metadataEntity); } } return metadata; }
private static MDSKey.Builder getMDSKeyPrefix(MetadataEntity metadataEntity, byte[] rowPrefix) { MDSKey.Builder builder = new MDSKey.Builder(); builder.add(rowPrefix); builder.add(metadataEntity.getType()); // add all the key value pairs from the metadata entity this is the targetId for (MetadataEntity.KeyValue keyValue : metadataEntity) { // CDAP-13597 for versioned entities like application, schedule and programs their metadata is not versioned if (VERSIONED_ENTITIES.contains(metadataEntity.getType()) && keyValue.getKey().equalsIgnoreCase(MetadataEntity.VERSION)) { continue; } builder.add(keyValue.getKey()); builder.add(keyValue.getValue()); } return builder; } private MetadataKey() {
/** * If the MetadataEntity Builder key-value represent an application or artifact which is versioned in CDAP i.e. their * metadata entity representation ends with 'version' rather than 'application' or 'artifact' and the type is also * set to 'version' then for backward compatibility of rest end points return an updated builder which has the * correct type. This is only needed in 5.0 for backward compatibility of the rest endpoint. * From 5.0 and later the rest end point must be called with a query parameter which specify the type of the * metadata entity if the type is not the last key. (CDAP-13678) */ @VisibleForTesting static MetadataEntity.Builder makeBackwardCompatible(MetadataEntity.Builder builder) { MetadataEntity entity = builder.build(); List<MetadataEntity.KeyValue> entityKeyValues = StreamSupport.stream(entity.spliterator(), false) .collect(Collectors.toList()); if (entityKeyValues.size() == 3 && entity.getType().equals(MetadataEntity.VERSION) && (entityKeyValues.get(1).getKey().equals(MetadataEntity.ARTIFACT) || entityKeyValues.get(1).getKey().equals(MetadataEntity.APPLICATION))) { // this is artifact or application so update the builder MetadataEntity.Builder actualEntityBuilder = MetadataEntity.builder(); // namespace actualEntityBuilder.append(entityKeyValues.get(0).getKey(), entityKeyValues.get(0).getValue()); // application or artifact (so append as type) actualEntityBuilder.appendAsType(entityKeyValues.get(1).getKey(), entityKeyValues.get(1).getValue()); // version detail actualEntityBuilder.append(entityKeyValues.get(2).getKey(), entityKeyValues.get(2).getValue()); return actualEntityBuilder; } return builder; }
private Set<MetadataRecordV2> getMetadata(MetadataEntity metadataEntity, @Nullable String scope, boolean aggregateRun) throws BadRequestException { // the lineage admin handles the metadata call for program runs so delegate the call to that Set<MetadataRecordV2> metadata; if (aggregateRun && metadataEntity.getType().equals(MetadataEntity.PROGRAM_RUN)) { // CDAP-13721 for backward compatibility we need to support metadata aggregation of runId. metadata = lineageAdmin.getMetadataForRun(EntityId.fromMetadataEntity(metadataEntity)); } else { if (scope == null) { metadata = metadataAdmin.getMetadata(metadataEntity); } else { metadata = metadataAdmin.getMetadata(validateScope(scope), metadataEntity); } } return metadata; }
/** * If the MetadataEntity Builder key-value represent an application or artifact which is versioned in CDAP i.e. their * metadata entity representation ends with 'version' rather than 'application' or 'artifact' and the type is also * set to 'version' then for backward compatibility of rest end points return an updated builder which has the * correct type. This is only needed in 5.0 for backward compatibility of the rest endpoint. * From 5.0 and later the rest end point must be called with a query parameter which specify the type of the * metadata entity if the type is not the last key. (CDAP-13678) */ @VisibleForTesting static MetadataEntity.Builder makeBackwardCompatible(MetadataEntity.Builder builder) { MetadataEntity entity = builder.build(); List<MetadataEntity.KeyValue> entityKeyValues = StreamSupport.stream(entity.spliterator(), false) .collect(Collectors.toList()); if (entityKeyValues.size() == 3 && entity.getType().equals(MetadataEntity.VERSION) && (entityKeyValues.get(1).getKey().equals(MetadataEntity.ARTIFACT) || entityKeyValues.get(1).getKey().equals(MetadataEntity.APPLICATION))) { // this is artifact or application so update the builder MetadataEntity.Builder actualEntityBuilder = MetadataEntity.builder(); // namespace actualEntityBuilder.append(entityKeyValues.get(0).getKey(), entityKeyValues.get(0).getValue()); // application or artifact (so append as type) actualEntityBuilder.appendAsType(entityKeyValues.get(1).getKey(), entityKeyValues.get(1).getValue()); // version detail actualEntityBuilder.append(entityKeyValues.get(2).getKey(), entityKeyValues.get(2).getValue()); return actualEntityBuilder; } return builder; }
private static MDSKey.Builder getMDSKeyPrefix(MetadataEntity metadataEntity, byte[] rowPrefix) { MDSKey.Builder builder = new MDSKey.Builder(); builder.add(rowPrefix); builder.add(metadataEntity.getType()); // add all the key value pairs from the metadata entity this is the targetId for (MetadataEntity.KeyValue keyValue : metadataEntity) { // CDAP-13597 for versioned entities like application, schedule and programs their metadata is not versioned if (VERSIONED_ENTITIES.contains(metadataEntity.getType()) && keyValue.getKey().equalsIgnoreCase(MetadataEntity.VERSION)) { continue; } builder.add(keyValue.getKey()); builder.add(keyValue.getValue()); } return builder; } private MetadataKey() {
builder.append(String.format(" of type '%s'", getType())); return builder.toString();
private static MDSKey.Builder getKeyPart(MetadataEntity metadataEntity) { MDSKey.Builder builder = new MDSKey.Builder(); builder.add(ROW_PREFIX); builder.add(metadataEntity.getType()); for (MetadataEntity.KeyValue keyValue : metadataEntity) { builder.add(keyValue.getKey()); builder.add(keyValue.getValue()); } return builder; } }
private static MDSKey.Builder getKeyPart(MetadataEntity metadataEntity) { MDSKey.Builder builder = new MDSKey.Builder(); builder.add(ROW_PREFIX); builder.add(metadataEntity.getType()); for (MetadataEntity.KeyValue keyValue : metadataEntity) { builder.add(keyValue.getKey()); builder.add(keyValue.getValue()); } return builder; } }
if (VERSIONED_ENTITIES.contains(metadataEntity.getType())) {
if (VERSIONED_ENTITIES.contains(metadataEntity.getType())) {