Search in sources :

Example 26 with NotFoundException

use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.

the class SystemAppEnableExecutor method startProgram.

private void startProgram(ProgramId programId) throws Exception {
    try {
        ProgramStatus currentStatus = programLifecycleService.getProgramStatus(programId);
        // checking if artifact version has changed would be a good start.
        try {
            if (currentStatus == ProgramStatus.RUNNING) {
                programLifecycleService.stop(programId);
            }
        } catch (ConflictException e) {
        // Will reach here if the program is already stopped, which means it tried to stop after the status check above.
        // ignore this, as it means the program is stopped as we wanted.
        }
        programLifecycleService.run(programId, Collections.emptyMap(), false);
    } catch (ConflictException e) {
    // thrown if the program is already running, which means it was started after the status check above.
    // ignore this, as it means the program is running as expected
    } catch (NotFoundException e) {
        // use a nicer error message
        throw new IllegalArgumentException(String.format("Cannot start %s because it does not exist.", programId), e);
    }
}
Also used : ConflictException(io.cdap.cdap.common.ConflictException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProgramStatus(io.cdap.cdap.proto.ProgramStatus)

Example 27 with NotFoundException

use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.

the class AppCreator method execute.

@Override
public void execute(Arguments arguments) throws Exception {
    ApplicationId appId = arguments.getId();
    ArtifactSummary artifactSummary = arguments.getArtifact();
    if (appExists(appId) && !arguments.overwrite) {
        return;
    }
    KerberosPrincipalId ownerPrincipalId = arguments.getOwnerPrincipal() == null ? null : new KerberosPrincipalId(arguments.getOwnerPrincipal());
    // if we don't null check, it gets serialized to "null"
    String configString = arguments.getConfig() == null ? null : GSON.toJson(arguments.getConfig());
    try {
        appLifecycleService.deployApp(appId.getParent(), appId.getApplication(), appId.getVersion(), artifactSummary, configString, x -> {
        }, ownerPrincipalId, arguments.canUpdateSchedules(), false, Collections.emptyMap());
    } catch (NotFoundException | UnauthorizedException | InvalidArtifactException e) {
        // up to the default time limit
        throw e;
    } catch (DatasetManagementException e) {
        if (e.getCause() instanceof UnauthorizedException) {
            throw (UnauthorizedException) e.getCause();
        } else {
            throw new RetryableException(e);
        }
    } catch (Exception e) {
        throw new RetryableException(e);
    }
}
Also used : DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) RetryableException(io.cdap.cdap.api.retry.RetryableException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) RetryableException(io.cdap.cdap.api.retry.RetryableException) DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 28 with NotFoundException

use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.

the class ProgramStarter method execute.

@Override
public void execute(Arguments arguments) throws Exception {
    ProgramId programId = arguments.getId();
    Preconditions.checkArgument(programLifecycleService.getProgramSpecification(programId) != null, "Cannot start %s because it does not exist.", programId);
    try {
        // do nothing if the program is already running
        ProgramStatus currentStatus = programLifecycleService.getProgramStatus(programId);
        if (currentStatus != ProgramStatus.STOPPED) {
            LOG.info("Program {} is in the {} state, skipping start program bootstrap step.", programId, currentStatus);
            return;
        }
        programLifecycleService.run(programId, Collections.emptyMap(), false);
    } catch (ConflictException e) {
    // thrown if the program is already running, which means it was started after the status check above.
    // ignore this, as it means the program is running as expected
    } catch (NotFoundException e) {
        // use a nicer error message
        throw new IllegalArgumentException(String.format("Cannot start %s because it does not exist.", programId), e);
    }
}
Also used : ConflictException(io.cdap.cdap.common.ConflictException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProgramId(io.cdap.cdap.proto.id.ProgramId) ProgramStatus(io.cdap.cdap.proto.ProgramStatus)

Example 29 with NotFoundException

use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.

the class ApplicationLifecycleService method upgradeApplication.

/**
 * Upgrades an existing application by upgrading application artifact versions and plugin artifact versions.
 *
 * @param appId the id of the application to upgrade.
 * @param allowedArtifactScopes artifact scopes allowed while looking for latest artifacts for upgrade.
 * @param allowSnapshot whether to consider snapshot version of artifacts or not for upgrade.
 * @throws IllegalStateException if something unexpected happened during upgrade.
 * @throws IOException if there was an IO error during initializing application class from artifact.
 * @throws JsonIOException if there was an error in serializing or deserializing app config.
 * @throws UnsupportedOperationException if application does not support upgrade operation.
 * @throws InvalidArtifactException if candidate application artifact is invalid for upgrade purpose.
 * @throws NotFoundException if any object related to upgrade is not found like application/artifact.
 * @throws Exception if there was an exception during the upgrade of application. This exception will often wrap
 *                   the actual exception
 */
public void upgradeApplication(ApplicationId appId, Set<ArtifactScope> allowedArtifactScopes, boolean allowSnapshot) throws Exception {
    // Check if the current user has admin privileges on it before updating.
    accessEnforcer.enforce(appId, authenticationContext.getPrincipal(), StandardPermission.UPDATE);
    // check that app exists
    ApplicationSpecification currentSpec = store.getApplication(appId);
    if (currentSpec == null) {
        LOG.info("Application {} not found for upgrade.", appId);
        throw new NotFoundException(appId);
    }
    ArtifactId currentArtifact = currentSpec.getArtifactId();
    ArtifactSummary candidateArtifact = getLatestAppArtifactForUpgrade(appId, currentArtifact, allowedArtifactScopes, allowSnapshot);
    ArtifactVersion candidateArtifactVersion = new ArtifactVersion(candidateArtifact.getVersion());
    // Current artifact should not have higher version than candidate artifact.
    if (currentArtifact.getVersion().compareTo(candidateArtifactVersion) > 0) {
        String error = String.format("The current artifact has a version higher %s than any existing artifact.", currentArtifact.getVersion());
        throw new InvalidArtifactException(error);
    }
    ArtifactId newArtifactId = new ArtifactId(candidateArtifact.getName(), candidateArtifactVersion, candidateArtifact.getScope());
    Id.Artifact newArtifact = Id.Artifact.fromEntityId(Artifacts.toProtoArtifactId(appId.getParent(), newArtifactId));
    ArtifactDetail newArtifactDetail = artifactRepository.getArtifact(newArtifact);
    updateApplicationInternal(appId, currentSpec.getConfiguration(), programId -> {
    }, newArtifactDetail, Collections.singletonList(ApplicationConfigUpdateAction.UPGRADE_ARTIFACT), allowedArtifactScopes, allowSnapshot, ownerAdmin.getOwner(appId), false);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) Id(io.cdap.cdap.common.id.Id) InstanceId(io.cdap.cdap.proto.id.InstanceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) EntityId(io.cdap.cdap.proto.id.EntityId) ProgramId(io.cdap.cdap.proto.id.ProgramId) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)

Example 30 with NotFoundException

use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.

the class ProgramLifecycleService method createProgramOptions.

@VisibleForTesting
ProgramOptions createProgramOptions(ProgramId programId, Map<String, String> userArgs, Map<String, String> sysArgs, boolean debug) throws NotFoundException, ProfileConflictException {
    ProfileId profileId = SystemArguments.getProfileIdForProgram(programId, userArgs);
    Map<String, String> profileProperties = SystemArguments.getProfileProperties(userArgs);
    Profile profile = profileService.getProfile(profileId, profileProperties);
    if (profile.getStatus() == ProfileStatus.DISABLED) {
        throw new ProfileConflictException(String.format("Profile %s in namespace %s is disabled. It cannot be " + "used to start the program %s", profileId.getProfile(), profileId.getNamespace(), programId.toString()), profileId);
    }
    ProvisionerDetail spec = provisioningService.getProvisionerDetail(profile.getProvisioner().getName());
    if (spec == null) {
        throw new NotFoundException(String.format("Provisioner '%s' not found.", profile.getProvisioner().getName()));
    }
    // get and add any user overrides for profile properties
    Map<String, String> systemArgs = new HashMap<>(sysArgs);
    // add profile properties to the system arguments
    SystemArguments.addProfileArgs(systemArgs, profile);
    // Set the ClusterMode. If it is NATIVE profile, then it is ON_PREMISE, otherwise is ISOLATED
    // This should probably move into the provisioner later once we have a better contract for the
    // provisioner to actually pick what launching mechanism it wants to use.
    systemArgs.put(ProgramOptionConstants.CLUSTER_MODE, (ProfileId.NATIVE.equals(profileId) ? ClusterMode.ON_PREMISE : ClusterMode.ISOLATED).name());
    ProgramSpecification programSpecification = getProgramSpecificationWithoutAuthz(programId);
    if (programSpecification == null) {
        throw new NotFoundException(programId);
    }
    addAppCDAPVersion(programId, systemArgs);
    // put all the plugin requirements if any involved in the run
    systemArgs.put(ProgramOptionConstants.PLUGIN_REQUIREMENTS, GSON.toJson(getPluginRequirements(programSpecification)));
    return new SimpleProgramOptions(programId, new BasicArguments(systemArgs), new BasicArguments(userArgs), debug);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) HashMap(java.util.HashMap) NotFoundException(io.cdap.cdap.common.NotFoundException) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) Profile(io.cdap.cdap.proto.profile.Profile) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

NotFoundException (io.cdap.cdap.common.NotFoundException)266 HttpResponse (io.cdap.common.http.HttpResponse)86 URL (java.net.URL)76 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)54 ProgramId (io.cdap.cdap.proto.id.ProgramId)52 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)50 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)50 Path (javax.ws.rs.Path)50 BadRequestException (io.cdap.cdap.common.BadRequestException)42 ProgramNotFoundException (io.cdap.cdap.common.ProgramNotFoundException)42 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)36 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)36 IOException (java.io.IOException)36 GET (javax.ws.rs.GET)36 Test (org.junit.Test)30 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)28 HashMap (java.util.HashMap)28 ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)26 ConflictException (io.cdap.cdap.common.ConflictException)26 ArrayList (java.util.ArrayList)26