Search in sources :

Example 6 with ConflictException

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());
    }
}
Also used : ConflictException(io.cdap.cdap.common.ConflictException) DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) DatasetId(io.cdap.cdap.proto.id.DatasetId) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 7 with ConflictException

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));
}
Also used : ConflictException(io.cdap.cdap.common.ConflictException) BatchProgramResult(io.cdap.cdap.proto.BatchProgramResult) ArrayList(java.util.ArrayList) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) BadRequestException(io.cdap.cdap.common.BadRequestException) BatchProgramStart(io.cdap.cdap.proto.BatchProgramStart) ProgramId(io.cdap.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Example 8 with ConflictException

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.");
}
Also used : ProgramController(io.cdap.cdap.app.runtime.ProgramController) ConflictException(io.cdap.cdap.common.ConflictException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 9 with ConflictException

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);
}
Also used : ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) ConflictException(io.cdap.cdap.common.ConflictException) ProgramScheduleRecord(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleRecord)

Example 10 with ConflictException

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.");
        }
    }
}
Also used : ProgramScheduleStatus(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleStatus) AlreadyExistsException(io.cdap.cdap.common.AlreadyExistsException) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) ConflictException(io.cdap.cdap.common.ConflictException)

Aggregations

ConflictException (io.cdap.cdap.common.ConflictException)36 NotFoundException (io.cdap.cdap.common.NotFoundException)14 IOException (java.io.IOException)10 POST (javax.ws.rs.POST)10 Path (javax.ws.rs.Path)10 BadRequestException (io.cdap.cdap.common.BadRequestException)8 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)8 ProgramId (io.cdap.cdap.proto.id.ProgramId)8 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)8 JsonSyntaxException (com.google.gson.JsonSyntaxException)6 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)6 AccessException (io.cdap.cdap.api.security.AccessException)6 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)6 ArtifactAlreadyExistsException (io.cdap.cdap.common.ArtifactAlreadyExistsException)6 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)6 File (java.io.File)6 InvalidArtifactException (io.cdap.cdap.common.InvalidArtifactException)5 NotImplementedException (io.cdap.cdap.common.NotImplementedException)5 ServiceException (io.cdap.cdap.common.ServiceException)5 WriteConflictException (io.cdap.cdap.internal.app.runtime.artifact.WriteConflictException)5