private String constructPath(MetadataEntity metadataEntity) { StringBuilder builder = new StringBuilder(); metadataEntity.iterator().forEachRemaining(keyValue -> { if (ENTITY_TYPE_TO_API_PART.containsKey(keyValue.getKey())) { builder.append(ENTITY_TYPE_TO_API_PART.get(keyValue.getKey())); } else { builder.append(keyValue.getKey()); } builder.append("/"); builder.append(keyValue.getValue()); builder.append("/"); }); // remove the last / builder.replace(builder.length() - 1, builder.length(), ""); return builder.toString(); }
private String constructPath(MetadataEntity metadataEntity) { StringBuilder builder = new StringBuilder(); metadataEntity.iterator().forEachRemaining(keyValue -> { if (ENTITY_TYPE_TO_API_PART.containsKey(keyValue.getKey())) { builder.append(ENTITY_TYPE_TO_API_PART.get(keyValue.getKey())); } else { builder.append(keyValue.getKey()); } builder.append("/"); builder.append(keyValue.getValue()); builder.append("/"); }); // remove the last / builder.replace(builder.length() - 1, builder.length(), ""); 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(); }
builder.append(keyValue.getKey()); builder.append("="); builder.append(keyValue.getValue()); builder.append(",");
extractedParts = metadataEntity.head(MetadataEntity.VERSION); extractedParts.iterator().forEachRemaining(keyValue -> values.add(keyValue.getValue())); return entityType.fromIdParts(values);
extractedParts = metadataEntity.head(MetadataEntity.VERSION); extractedParts.iterator().forEachRemaining(keyValue -> values.add(keyValue.getValue())); return entityType.fromIdParts(values);
/** * 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; }
/** * 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; }
/** * 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 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() {
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() {
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; } }