use of io.cdap.cdap.common.ConflictException in project cdap by cdapio.
the class RemoteDatasetOpExecutor method doRequest.
private HttpResponse doRequest(DatasetId datasetInstanceId, String opName, @Nullable String body) throws IOException, ConflictException, UnauthorizedException {
String path = String.format("namespaces/%s/data/datasets/%s/admin/%s", datasetInstanceId.getNamespace(), datasetInstanceId.getEntityName(), opName);
LOG.trace("executing POST on {} with body {}", path, body);
try {
HttpRequest.Builder builder = remoteClient.requestBuilder(HttpMethod.POST, path);
if (body != null) {
builder.withBody(body);
}
String userId = authenticationContext.getPrincipal().getName();
if (userId != null) {
builder.addHeader(Constants.Security.Headers.USER_ID, userId);
}
HttpResponse httpResponse = remoteClient.execute(builder.build());
LOG.trace("executed POST on {} with body {}: {}", path, body, httpResponse.getResponseCode());
verifyResponse(httpResponse);
return httpResponse;
} catch (Exception e) {
LOG.trace("Caught exception for POST on {} with body {}", path, body, e);
throw e;
}
}
use of io.cdap.cdap.common.ConflictException in project cdap by cdapio.
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 cdapio.
the class WorkflowHttpHandler method suspendWorkflowRun.
@POST
@Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/suspend")
public void suspendWorkflowRun(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.SUSPENDED) {
throw new ConflictException("Program run already suspended");
}
controller.suspend().get();
responder.sendString(HttpResponseStatus.OK, "Program run suspended.");
}
use of io.cdap.cdap.common.ConflictException in project cdap by cdapio.
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 cdapio.
the class SystemProgramManagementService method startPrograms.
private void startPrograms(Map<ProgramId, Arguments> enabledProgramsMap) {
for (ProgramId programId : enabledProgramsMap.keySet()) {
Map<String, String> overrides = enabledProgramsMap.get(programId).asMap();
LOG.debug("Starting program {} with args {}", programId, overrides);
try {
programLifecycleService.start(programId, overrides, false, false);
} catch (ConflictException ex) {
// Ignore if the program is already running.
LOG.debug("Program {} is already running.", programId);
} catch (Exception ex) {
LOG.warn("Could not start program {} , will be retried in next run.", programId, ex);
}
}
}
Aggregations