Search in sources :

Example 1 with AppDeploymentRuntimeInfo

use of io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo in project cdap by caskdata.

the class AbstractProgramRuntimeService method regenerateAppSpec.

/**
 * Regenerates the app spec before the program start
 *
 * @return the regenerated app spec, or null if there is any exception generating the app spec.
 */
@Nullable
private ApplicationSpecification regenerateAppSpec(ArtifactDetail artifactDetail, ProgramId programId, ArtifactId artifactId, ApplicationSpecification existingAppSpec, ProgramOptions options) throws InterruptedException, ExecutionException, TimeoutException {
    ApplicationClass appClass = Iterables.getFirst(artifactDetail.getMeta().getClasses().getApps(), null);
    if (appClass == null) {
        // This should never happen.
        throw new IllegalStateException(String.format("No application class found in artifact '%s' in namespace '%s'.", artifactDetail.getDescriptor().getArtifactId(), programId.getNamespace()));
    }
    AppDeploymentInfo deploymentInfo = new AppDeploymentInfo(artifactId, artifactDetail.getDescriptor().getLocation(), programId.getNamespaceId(), appClass, existingAppSpec.getName(), existingAppSpec.getAppVersion(), existingAppSpec.getConfiguration(), null, false, new AppDeploymentRuntimeInfo(existingAppSpec, options.getUserArguments().asMap(), options.getArguments().asMap()));
    Configurator configurator = this.configuratorFactory.create(deploymentInfo);
    ListenableFuture<ConfigResponse> future = configurator.config();
    ConfigResponse response = future.get(120, TimeUnit.SECONDS);
    if (response.getExitCode() == 0) {
        AppSpecInfo appSpecInfo = response.getAppSpecInfo();
        if (appSpecInfo != null && appSpecInfo.getAppSpec() != null) {
            return appSpecInfo.getAppSpec();
        }
    }
    return null;
}
Also used : AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) Configurator(io.cdap.cdap.app.deploy.Configurator) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) AppDeploymentRuntimeInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo) Nullable(javax.annotation.Nullable)

Example 2 with AppDeploymentRuntimeInfo

use of io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo in project cdap by caskdata.

the class ApplicationLifecycleService method deployApp.

private ApplicationWithPrograms deployApp(NamespaceId namespaceId, @Nullable String appName, @Nullable String appVersion, @Nullable String configStr, ProgramTerminator programTerminator, ArtifactDetail artifactDetail, @Nullable KerberosPrincipalId ownerPrincipal, boolean updateSchedules, boolean isPreview, Map<String, String> userProps) throws Exception {
    // Now to deploy an app, we need ADMIN privilege on the owner principal if it is present, and also ADMIN on the app
    // But since at this point, app name is unknown to us, so the enforcement on the app is happening in the deploy
    // pipeline - LocalArtifactLoaderStage
    // need to enforce on the principal id if impersonation is involved
    KerberosPrincipalId effectiveOwner = SecurityUtil.getEffectiveOwner(ownerAdmin, namespaceId, ownerPrincipal == null ? null : ownerPrincipal.getPrincipal());
    Principal requestingUser = authenticationContext.getPrincipal();
    // impersonated principal
    if (effectiveOwner != null) {
        accessEnforcer.enforce(effectiveOwner, requestingUser, AccessPermission.SET_OWNER);
    }
    ApplicationClass appClass = Iterables.getFirst(artifactDetail.getMeta().getClasses().getApps(), null);
    if (appClass == null) {
        throw new InvalidArtifactException(String.format("No application class found in artifact '%s' in namespace '%s'.", artifactDetail.getDescriptor().getArtifactId(), namespaceId));
    }
    if (!NamespaceId.SYSTEM.equals(namespaceId)) {
        capabilityReader.checkAllEnabled(appClass.getRequirements().getCapabilities());
    }
    // deploy application with newly added artifact
    AppDeploymentInfo deploymentInfo = new AppDeploymentInfo(Artifacts.toProtoArtifactId(namespaceId, artifactDetail.getDescriptor().getArtifactId()), artifactDetail.getDescriptor().getLocation(), namespaceId, appClass, appName, appVersion, configStr, ownerPrincipal, updateSchedules, isPreview ? new AppDeploymentRuntimeInfo(null, userProps, Collections.emptyMap()) : null);
    Manager<AppDeploymentInfo, ApplicationWithPrograms> manager = managerFactory.create(programTerminator);
    // TODO: (CDAP-3258) Manager needs MUCH better error handling.
    ApplicationWithPrograms applicationWithPrograms;
    try {
        applicationWithPrograms = manager.deploy(deploymentInfo).get();
    } catch (ExecutionException e) {
        Throwables.propagateIfPossible(e.getCause(), Exception.class);
        throw Throwables.propagate(e.getCause());
    }
    adminEventPublisher.publishAppCreation(applicationWithPrograms.getApplicationId(), applicationWithPrograms.getSpecification());
    return applicationWithPrograms;
}
Also used : AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) ExecutionException(java.util.concurrent.ExecutionException) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId) Principal(io.cdap.cdap.proto.security.Principal) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) CapabilityNotAvailableException(io.cdap.cdap.internal.capability.CapabilityNotAvailableException) IOException(java.io.IOException) CannotBeDeletedException(io.cdap.cdap.common.CannotBeDeletedException) ExecutionException(java.util.concurrent.ExecutionException) AccessException(io.cdap.cdap.api.security.AccessException) JsonIOException(com.google.gson.JsonIOException) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) ArtifactAlreadyExistsException(io.cdap.cdap.common.ArtifactAlreadyExistsException) NotFoundException(io.cdap.cdap.common.NotFoundException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) AppDeploymentRuntimeInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo)

Example 3 with AppDeploymentRuntimeInfo

use of io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo in project cdap by caskdata.

the class DefaultRuntimeJob method regenerateAppSpec.

@Nullable
private ApplicationSpecification regenerateAppSpec(Map<String, String> systemArguments, Map<String, String> userArguments, ProgramId programId, ApplicationSpecification existingAppSpec, ProgramDescriptor programDescriptor, ConfiguratorFactory configuratorFactory) throws InterruptedException, ExecutionException, TimeoutException {
    String appClassName = systemArguments.get(ProgramOptionConstants.APPLICATION_CLASS);
    Location programJarLocation = Locations.toLocation(new File(systemArguments.get(ProgramOptionConstants.PROGRAM_JAR)));
    AppDeploymentInfo deploymentInfo = new AppDeploymentInfo(programDescriptor.getArtifactId(), programJarLocation, programId.getNamespaceId(), appClassName, programId.getApplication(), programId.getVersion(), existingAppSpec.getConfiguration(), null, false, new AppDeploymentRuntimeInfo(existingAppSpec, userArguments, systemArguments));
    Configurator configurator = configuratorFactory.create(deploymentInfo);
    ListenableFuture<ConfigResponse> future = configurator.config();
    ConfigResponse response = future.get(120, TimeUnit.SECONDS);
    if (response.getExitCode() == 0) {
        AppSpecInfo appSpecInfo = response.getAppSpecInfo();
        if (appSpecInfo != null && appSpecInfo.getAppSpec() != null) {
            return appSpecInfo.getAppSpec();
        }
    }
    return null;
}
Also used : AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) InMemoryConfigurator(io.cdap.cdap.internal.app.deploy.InMemoryConfigurator) Configurator(io.cdap.cdap.app.deploy.Configurator) ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) File(java.io.File) Location(org.apache.twill.filesystem.Location) AppDeploymentRuntimeInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo) Nullable(javax.annotation.Nullable)

Aggregations

AppDeploymentInfo (io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo)3 AppDeploymentRuntimeInfo (io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo)3 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)2 ConfigResponse (io.cdap.cdap.app.deploy.ConfigResponse)2 Configurator (io.cdap.cdap.app.deploy.Configurator)2 AppSpecInfo (io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo)2 Nullable (javax.annotation.Nullable)2 JsonIOException (com.google.gson.JsonIOException)1 AccessException (io.cdap.cdap.api.security.AccessException)1 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)1 ArtifactAlreadyExistsException (io.cdap.cdap.common.ArtifactAlreadyExistsException)1 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)1 CannotBeDeletedException (io.cdap.cdap.common.CannotBeDeletedException)1 InvalidArtifactException (io.cdap.cdap.common.InvalidArtifactException)1 NotFoundException (io.cdap.cdap.common.NotFoundException)1 InMemoryConfigurator (io.cdap.cdap.internal.app.deploy.InMemoryConfigurator)1 ApplicationWithPrograms (io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms)1 CapabilityNotAvailableException (io.cdap.cdap.internal.capability.CapabilityNotAvailableException)1 KerberosPrincipalId (io.cdap.cdap.proto.id.KerberosPrincipalId)1 Principal (io.cdap.cdap.proto.security.Principal)1