Search in sources :

Example 71 with MetadataEntity

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)));
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) MetadataScope(io.cdap.cdap.api.metadata.MetadataScope) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 72 with MetadataEntity

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));
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 73 with 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));
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Metadata(io.cdap.cdap.spi.metadata.Metadata) MetadataScope(io.cdap.cdap.api.metadata.MetadataScope) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 74 with MetadataEntity

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;
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 75 with MetadataEntity

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));
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Path(javax.ws.rs.Path) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Aggregations

MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)192 Test (org.junit.Test)114 Drop (io.cdap.cdap.spi.metadata.MetadataMutation.Drop)58 Update (io.cdap.cdap.spi.metadata.MetadataMutation.Update)56 MetadataScope (io.cdap.cdap.api.metadata.MetadataScope)34 HashMap (java.util.HashMap)30 HashSet (java.util.HashSet)30 Map (java.util.Map)28 ImmutableMap (com.google.common.collect.ImmutableMap)26 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)26 Remove (io.cdap.cdap.spi.metadata.MetadataMutation.Remove)24 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)22 List (java.util.List)22 Metadata (io.cdap.cdap.spi.metadata.Metadata)20 Create (io.cdap.cdap.spi.metadata.MetadataMutation.Create)20 Set (java.util.Set)20 Collectors (java.util.stream.Collectors)20 Nullable (javax.annotation.Nullable)20 Path (javax.ws.rs.Path)20