Search in sources :

Example 81 with AuditPolicy

use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.

the class NamespaceHttpHandler method create.

@PUT
@Path("/namespaces/{namespace-id}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void create(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
    NamespaceId namespace;
    try {
        namespace = new NamespaceId(namespaceId);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Namespace id can contain only alphanumeric characters or '_'.");
    }
    NamespaceMeta metadata = getNamespaceMeta(request);
    if (isReserved(namespaceId)) {
        throw new BadRequestException(String.format("Cannot create the namespace '%s'. '%s' is a reserved namespace.", namespaceId, namespaceId));
    }
    NamespaceMeta.Builder builder = metadata == null ? new NamespaceMeta.Builder() : new NamespaceMeta.Builder(metadata);
    builder.setName(namespace);
    NamespaceMeta finalMetadata = builder.build();
    try {
        namespaceAdmin.create(finalMetadata);
        responder.sendString(HttpResponseStatus.OK, String.format("Namespace '%s' created successfully.", namespaceId));
    } catch (AlreadyExistsException e) {
        responder.sendString(HttpResponseStatus.OK, String.format("Namespace '%s' already exists.", namespaceId));
    }
}
Also used : AlreadyExistsException(co.cask.cdap.common.AlreadyExistsException) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) BadRequestException(co.cask.cdap.common.BadRequestException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 82 with AuditPolicy

use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.

the class MetadataHttpHandler method addStreamProperties.

@POST
@Path("/namespaces/{namespace-id}/streams/{stream-id}/metadata/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void addStreamProperties(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("stream-id") String streamId) throws BadRequestException, NotFoundException {
    StreamId stream = new StreamId(namespaceId, streamId);
    metadataAdmin.addProperties(stream, readMetadata(request));
    responder.sendString(HttpResponseStatus.OK, "Metadata added successfully to " + stream);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Example 83 with AuditPolicy

use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.

the class MetadataHttpHandler method addAppTags.

@POST
@Path("/namespaces/{namespace-id}/apps/{app-id}/metadata/tags")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void addAppTags(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId) throws BadRequestException, NotFoundException {
    ApplicationId app = new ApplicationId(namespaceId, appId);
    metadataAdmin.addTags(app, readArray(request));
    responder.sendString(HttpResponseStatus.OK, String.format("Added tags to application %s successfully.", app));
}
Also used : ApplicationId(co.cask.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Example 84 with AuditPolicy

use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.

the class MetadataHttpHandler method addArtifactProperties.

@POST
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/metadata/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void addArtifactProperties(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersionStr) throws BadRequestException, NotFoundException {
    ArtifactId artifactId = new ArtifactId(namespaceId, artifactName, artifactVersionStr);
    metadataAdmin.addProperties(artifactId, readMetadata(request));
    responder.sendString(HttpResponseStatus.OK, "Metadata added successfully to " + artifactId);
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Example 85 with AuditPolicy

use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.

the class MetadataHttpHandler method addProgramTags.

@POST
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/metadata/tags")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void addProgramTags(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId) throws BadRequestException, NotFoundException {
    ProgramId program = new ProgramId(namespaceId, appId, ProgramType.valueOfCategoryName(programType), programId);
    metadataAdmin.addTags(program, readArray(request));
    responder.sendString(HttpResponseStatus.OK, String.format("Added tags to program %s successfully.", program));
}
Also used : ProgramId(co.cask.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Aggregations

AuditPolicy (co.cask.cdap.common.security.AuditPolicy)86 Path (javax.ws.rs.Path)86 POST (javax.ws.rs.POST)47 PUT (javax.ws.rs.PUT)38 BadRequestException (co.cask.cdap.common.BadRequestException)25 ProgramId (co.cask.cdap.proto.id.ProgramId)22 NamespaceId (co.cask.cdap.proto.id.NamespaceId)17 IOException (java.io.IOException)14 NotFoundException (co.cask.cdap.common.NotFoundException)13 JsonSyntaxException (com.google.gson.JsonSyntaxException)13 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)11 ArtifactId (co.cask.cdap.proto.id.ArtifactId)11 ArrayList (java.util.ArrayList)11 StreamId (co.cask.cdap.proto.id.StreamId)10 ApplicationId (co.cask.cdap.proto.id.ApplicationId)9 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)8 DatasetId (co.cask.cdap.proto.id.DatasetId)8 InputStreamReader (java.io.InputStreamReader)8 Reader (java.io.Reader)8 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)5