use of io.cdap.cdap.common.ConflictException in project cdap by caskdata.
the class DatasetAdminOpHTTPHandler method update.
@POST
@Path("/data/datasets/{name}/admin/update")
public void update(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) throws Exception {
propagateUserId(request);
InternalDatasetUpdateParams params = GSON.fromJson(request.content().toString(StandardCharsets.UTF_8), InternalDatasetUpdateParams.class);
Preconditions.checkArgument(params.getProperties() != null, "Missing required 'instanceProps' parameter.");
Preconditions.checkArgument(params.getTypeMeta() != null, "Missing required 'typeMeta' parameter.");
Preconditions.checkArgument(params.getExistingSpec() != null, "Missing required 'existingSpec' parameter.");
DatasetProperties props = params.getProperties();
DatasetSpecification existing = params.getExistingSpec();
DatasetTypeMeta typeMeta = params.getTypeMeta();
try {
DatasetId instanceId = new DatasetId(namespaceId, name);
DatasetCreationResponse response = datasetAdminService.createOrUpdate(instanceId, typeMeta, props, existing);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(response));
} catch (IncompatibleUpdateException e) {
throw new ConflictException(e.getMessage());
}
}
use of io.cdap.cdap.common.ConflictException in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method startPrograms.
/**
* Starts 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.). In additional, each object can contain an optional runtimeargs element,
* which is a map of arguments to start the program with.
* <p>
* Example input:
* <pre><code>
* [{"appId": "App1", "programType": "Service", "programId": "Service1"},
* {"appId": "App1", "programType": "Mapreduce", "programId": "MapReduce2", "runtimeargs":{"arg1":"val1"}}]
* </code></pre>
* </p><p>
* The response will be an array of JsonObjects each of which will contain the three input parameters
* as well as a "statusCode" field 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},
* {"appId": "App2", "programType": "Mapreduce", "programId": "Mapreduce2",
* "statusCode":404, "error": "App: App2 not found"}]
* </code></pre>
*/
@POST
@Path("/start")
@AuditPolicy({ AuditDetail.REQUEST_BODY, AuditDetail.RESPONSE_BODY })
public void startPrograms(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
List<BatchProgramStart> programs = validateAndGetBatchInput(request, BATCH_STARTS_TYPE);
List<BatchProgramResult> output = new ArrayList<>(programs.size());
for (BatchProgramStart program : programs) {
ProgramId programId = new ProgramId(namespaceId, program.getAppId(), program.getProgramType(), program.getProgramId());
try {
String runId = lifecycleService.run(programId, program.getRuntimeargs(), false).getId();
output.add(new BatchProgramResult(program, HttpResponseStatus.OK.code(), null, runId));
} catch (NotFoundException e) {
output.add(new BatchProgramResult(program, HttpResponseStatus.NOT_FOUND.code(), e.getMessage()));
} catch (BadRequestException e) {
output.add(new BatchProgramResult(program, HttpResponseStatus.BAD_REQUEST.code(), e.getMessage()));
} catch (ConflictException e) {
output.add(new BatchProgramResult(program, HttpResponseStatus.CONFLICT.code(), e.getMessage()));
}
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(output));
}
use of io.cdap.cdap.common.ConflictException in project cdap by caskdata.
the class WorkflowHttpHandler method resumeWorkflowRun.
@POST
@Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/resume")
public void resumeWorkflowRun(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-name") String workflowName, @PathParam("run-id") String runId) throws Exception {
ProgramController controller = getProgramController(namespaceId, appId, workflowName, runId);
if (controller.getState() == ProgramController.State.ALIVE) {
throw new ConflictException("Program is already running");
}
controller.resume().get();
responder.sendString(HttpResponseStatus.OK, "Program run resumed.");
}
use of io.cdap.cdap.common.ConflictException in project cdap by caskdata.
the class CoreSchedulerService method enableScheduleInternal.
private void enableScheduleInternal(ProgramScheduleStoreDataset store, ScheduleId scheduleId) throws IOException, NotFoundException, ConflictException, SchedulerException {
ProgramScheduleRecord record = store.getScheduleRecord(scheduleId);
if (ProgramScheduleStatus.SUSPENDED != record.getMeta().getStatus()) {
throw new ConflictException("Schedule '" + scheduleId + "' is already enabled");
}
timeSchedulerService.resumeProgramSchedule(record.getSchedule());
store.updateScheduleStatus(scheduleId, ProgramScheduleStatus.SCHEDULED);
}
use of io.cdap.cdap.common.ConflictException in project cdap by caskdata.
the class CoreSchedulerService method updateSchedule.
@Override
public void updateSchedule(ProgramSchedule schedule) throws NotFoundException, BadRequestException, ProfileConflictException {
checkStarted();
ProgramScheduleStatus previousStatus = getScheduleStatus(schedule.getScheduleId());
deleteSchedule(schedule.getScheduleId());
try {
addSchedule(schedule);
} catch (AlreadyExistsException e) {
// Should never reach here because we just deleted it
throw new IllegalStateException("Schedule '" + schedule.getScheduleId() + "' already exists despite just being deleted.");
}
// if the schedule was previously enabled, it should still/again enabled be after the update
if (ProgramScheduleStatus.SCHEDULED == previousStatus) {
try {
enableSchedule(schedule.getScheduleId());
} catch (ConflictException e) {
// Should never reach here because we just added this
throw new IllegalStateException("Schedule '" + schedule.getScheduleId() + "' already enabled despite just being added.");
}
}
}
Aggregations