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(HttpRequest 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));
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class MetadataHttpHandler method addProgramProperties.
@POST
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/metadata/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void addProgramProperties(HttpRequest 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.addProperties(program, readMetadata(request));
responder.sendString(HttpResponseStatus.OK, "Metadata added successfully to " + program);
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method setWorkerInstances.
/**
* Sets the number of instances of a worker.
*/
@PUT
@Path("/apps/{app-id}/workers/{worker-id}/instances")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void setWorkerInstances(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("worker-id") String workerId) throws Exception {
int instances = getInstances(request);
try {
lifecycleService.setInstances(new ProgramId(namespaceId, appId, ProgramType.WORKER, workerId), instances);
responder.sendStatus(HttpResponseStatus.OK);
} catch (SecurityException e) {
responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
} catch (Throwable e) {
if (respondIfElementNotFound(e, responder)) {
return;
}
throw e;
}
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getStatuses.
/**
* Returns the status for all programs that are passed into the data. The data is an array of JSON objects
* where each object must contain the following three elements: appId, programType, and programId
* (flow name, service name, etc.).
* <p>
* Example input:
* <pre><code>
* [{"appId": "App1", "programType": "Service", "programId": "Service1"},
* {"appId": "App1", "programType": "Mapreduce", "programId": "MapReduce2"},
* {"appId": "App2", "programType": "Flow", "programId": "Flow1"}]
* </code></pre>
* </p><p>
* The response will be an array of JsonObjects each of which will contain the three input parameters
* as well as 2 fields, "status" which maps to the status of the program and "statusCode" which maps to the
* status code for the data in that JsonObjects.
* </p><p>
* If an error occurs in the input (for the example above, App2 does not exist), then all JsonObjects for which the
* parameters have a valid status will have the status field but all JsonObjects for which the parameters do not have
* a valid status will have an error message and statusCode.
* </p><p>
* For example, if there is no App2 in the data above, then the response would be 200 OK with following possible data:
* </p>
* <pre><code>
* [{"appId": "App1", "programType": "Service", "programId": "Service1", "statusCode": 200, "status": "RUNNING"},
* {"appId": "App1", "programType": "Mapreduce", "programId": "Mapreduce2", "statusCode": 200, "status": "STOPPED"},
* {"appId":"App2", "programType":"Flow", "programId":"Flow1", "statusCode":404, "error": "App: App2 not found"}]
* </code></pre>
*/
@POST
@Path("/status")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void getStatuses(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
List<BatchProgram> programs = validateAndGetBatchInput(request, BATCH_PROGRAMS_TYPE);
List<BatchProgramStatus> statuses = new ArrayList<>(programs.size());
for (BatchProgram program : programs) {
ProgramId programId = new ProgramId(namespaceId, program.getAppId(), program.getProgramType(), program.getProgramId());
try {
ProgramStatus programStatus = lifecycleService.getProgramStatus(programId);
statuses.add(new BatchProgramStatus(program, HttpResponseStatus.OK.getCode(), null, programStatus.name()));
} catch (NotFoundException e) {
statuses.add(new BatchProgramStatus(program, HttpResponseStatus.NOT_FOUND.getCode(), e.getMessage(), null));
}
}
responder.sendJson(HttpResponseStatus.OK, statuses);
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method setServiceInstances.
/**
* Set instances of a service.
*/
@PUT
@Path("/apps/{app-id}/services/{service-id}/instances")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void setServiceInstances(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("service-id") String serviceId) throws Exception {
try {
ProgramId programId = new ProgramId(namespaceId, appId, ProgramType.SERVICE, serviceId);
if (!store.programExists(programId)) {
responder.sendString(HttpResponseStatus.NOT_FOUND, "Service not found");
return;
}
int instances = getInstances(request);
lifecycleService.setInstances(programId, instances);
responder.sendStatus(HttpResponseStatus.OK);
} catch (SecurityException e) {
responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
} catch (Throwable throwable) {
if (respondIfElementNotFound(throwable, responder)) {
return;
}
throw throwable;
}
}
Aggregations