Search in sources :

Example 11 with ConflictException

use of co.cask.cdap.common.ConflictException in project cdap by caskdata.

the class CoreSchedulerService method updateSchedule.

@Override
public void updateSchedule(final ProgramSchedule schedule) throws NotFoundException, BadRequestException {
    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(co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleStatus) AlreadyExistsException(co.cask.cdap.common.AlreadyExistsException) ConflictException(co.cask.cdap.common.ConflictException)

Example 12 with ConflictException

use of co.cask.cdap.common.ConflictException in project cdap by caskdata.

the class AppLifecycleHttpHandler method deployAppFromArtifact.

// normally we wouldn't want to use a body consumer but would just want to read the request body directly
// since it wont be big. But the deploy app API has one path with different behavior based on content type
// the other behavior requires a BodyConsumer and only have one method per path is allowed,
// so we have to use a BodyConsumer
private BodyConsumer deployAppFromArtifact(final ApplicationId appId) throws IOException {
    // createTempFile() needs a prefix of at least 3 characters
    return new AbstractBodyConsumer(File.createTempFile("apprequest-" + appId, ".json", tmpDir)) {

        @Override
        protected void onFinish(HttpResponder responder, File uploadedFile) {
            try (FileReader fileReader = new FileReader(uploadedFile)) {
                AppRequest<?> appRequest = GSON.fromJson(fileReader, AppRequest.class);
                ArtifactSummary artifactSummary = appRequest.getArtifact();
                KerberosPrincipalId ownerPrincipalId = appRequest.getOwnerPrincipal() == null ? null : new KerberosPrincipalId(appRequest.getOwnerPrincipal());
                // if we don't null check, it gets serialized to "null"
                String configString = appRequest.getConfig() == null ? null : GSON.toJson(appRequest.getConfig());
                applicationLifecycleService.deployApp(appId.getParent(), appId.getApplication(), appId.getVersion(), artifactSummary, configString, createProgramTerminator(), ownerPrincipalId, appRequest.canUpdateSchedules());
                responder.sendString(HttpResponseStatus.OK, "Deploy Complete");
            } catch (ArtifactNotFoundException e) {
                responder.sendString(HttpResponseStatus.NOT_FOUND, e.getMessage());
            } catch (ConflictException e) {
                responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage());
            } catch (UnauthorizedException e) {
                responder.sendString(HttpResponseStatus.FORBIDDEN, e.getMessage());
            } catch (InvalidArtifactException e) {
                responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
            } catch (IOException e) {
                LOG.error("Error reading request body for creating app {}.", appId);
                responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, String.format("Error while reading json request body for app %s.", appId));
            } catch (Exception e) {
                LOG.error("Deploy failure", e);
                responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
            }
        }
    };
}
Also used : HttpResponder(co.cask.http.HttpResponder) ConflictException(co.cask.cdap.common.ConflictException) WriteConflictException(co.cask.cdap.internal.app.runtime.artifact.WriteConflictException) IOException(java.io.IOException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) ArtifactAlreadyExistsException(co.cask.cdap.common.ArtifactAlreadyExistsException) ConflictException(co.cask.cdap.common.ConflictException) BadRequestException(co.cask.cdap.common.BadRequestException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) WriteConflictException(co.cask.cdap.internal.app.runtime.artifact.WriteConflictException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) InvalidArtifactException(co.cask.cdap.common.InvalidArtifactException) ExecutionException(java.util.concurrent.ExecutionException) NotFoundException(co.cask.cdap.common.NotFoundException) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) AbstractBodyConsumer(co.cask.cdap.common.http.AbstractBodyConsumer) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) FileReader(java.io.FileReader) File(java.io.File) KerberosPrincipalId(co.cask.cdap.proto.id.KerberosPrincipalId) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) InvalidArtifactException(co.cask.cdap.common.InvalidArtifactException)

Aggregations

ConflictException (co.cask.cdap.common.ConflictException)12 NotFoundException (co.cask.cdap.common.NotFoundException)7 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)5 BadRequestException (co.cask.cdap.common.BadRequestException)4 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)4 ProgramId (co.cask.cdap.proto.id.ProgramId)4 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)4 IOException (java.io.IOException)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 ProgramController (co.cask.cdap.app.runtime.ProgramController)3 ArtifactAlreadyExistsException (co.cask.cdap.common.ArtifactAlreadyExistsException)3 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)3 InvalidArtifactException (co.cask.cdap.common.InvalidArtifactException)3 WriteConflictException (co.cask.cdap.internal.app.runtime.artifact.WriteConflictException)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 File (java.io.File)3 ExecutionException (java.util.concurrent.ExecutionException)3 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)2 ProgramRuntimeService (co.cask.cdap.app.runtime.ProgramRuntimeService)2