use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.
the class MetadataHttpHandler method getTags.
@GET
@Path("/**/metadata/tags")
public void getTags(HttpRequest request, HttpResponder responder, @QueryParam("scope") String scope, @QueryParam("type") String type, @Nullable @QueryParam("responseFormat") @DefaultValue("v5") String responseFormat) throws Exception {
MetadataEntity entity = getMetadataEntityFromPath(request.uri(), type, "/metadata/tags");
if (isEntityType(entity)) {
accessEnforcer.enforce(EntityId.<EntityId>fromMetadataEntity(entity), authenticationContext.getPrincipal(), StandardPermission.GET);
}
MetadataScope theScope = validateScope(scope);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson("v5".equals(responseFormat) ? (scope == null ? metadataAdmin.getTags(entity) : metadataAdmin.getTags(theScope, entity)) : metadataAdmin.getMetadata(entity, theScope, MetadataKind.TAG)));
}
use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.
the class MetadataHttpHandler method removeTags.
@DELETE
@Path("/**/metadata/tags")
public void removeTags(HttpRequest request, HttpResponder responder, @QueryParam("type") String type, @QueryParam("async") @DefaultValue("false") Boolean async) throws Exception {
MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/tags");
enforce(metadataEntity, StandardPermission.UPDATE);
metadataAdmin.removeTags(metadataEntity, async ? ASYNC : SYNC);
responder.sendString(HttpResponseStatus.OK, String.format("Metadata tags for %s deleted successfully.", metadataEntity));
}
use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.
the class MetadataHttpHandler method getMetadata.
@GET
@Path("/**/metadata")
public void getMetadata(HttpRequest request, HttpResponder responder, @Nullable @QueryParam("scope") String scope, @Nullable @QueryParam("type") String type, @Nullable @QueryParam("responseFormat") @DefaultValue("v5") String responseFormat) throws Exception {
MetadataEntity entity = getMetadataEntityFromPath(request.uri(), type, "/metadata");
if (isEntityType(entity)) {
accessEnforcer.enforce(EntityId.<EntityId>fromMetadataEntity(entity), authenticationContext.getPrincipal(), StandardPermission.GET);
}
MetadataScope theScope = validateScope(scope);
Metadata metadata = scope == null ? metadataAdmin.getMetadata(entity) : metadataAdmin.getMetadata(entity, theScope);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson("v5".equals(responseFormat) ? MetadataCompatibility.toV5MetadataRecords(entity, metadata, scope) : metadata));
}
use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.
the class MetadataHttpHandler method makeBackwardCompatible.
/**
* 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;
}
use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.
the class MetadataHttpHandler method addProperties.
@POST
@Path("/**/metadata/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void addProperties(FullHttpRequest request, HttpResponder responder, @QueryParam("type") String type, @QueryParam("async") @DefaultValue("false") Boolean async) throws Exception {
MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/properties");
enforce(metadataEntity, StandardPermission.UPDATE);
metadataAdmin.addProperties(metadataEntity, readProperties(request), async ? ASYNC : SYNC);
responder.sendString(HttpResponseStatus.OK, String.format("Metadata properties for %s added successfully.", metadataEntity));
}
Aggregations