Search in sources :

Example 1 with InMemoryConfigurator

use of co.cask.cdap.internal.app.deploy.InMemoryConfigurator in project cdap by caskdata.

the class LocalArtifactLoaderStage method process.

/**
 * Instantiates the Application class and calls configure() on it to generate the {@link ApplicationSpecification}.
 *
 * @param deploymentInfo information needed to deploy the application, such as the artifact to create it from
 *                       and the application config to use.
 */
@Override
public void process(AppDeploymentInfo deploymentInfo) throws Exception {
    ArtifactId artifactId = deploymentInfo.getArtifactId();
    Location artifactLocation = deploymentInfo.getArtifactLocation();
    String appClassName = deploymentInfo.getAppClassName();
    String appVersion = deploymentInfo.getApplicationVersion();
    String configString = deploymentInfo.getConfigString();
    EntityImpersonator classLoaderImpersonator = new EntityImpersonator(artifactId, impersonator);
    ClassLoader artifactClassLoader = artifactRepository.createArtifactClassLoader(artifactLocation, classLoaderImpersonator);
    getContext().setProperty(LocalApplicationManager.ARTIFACT_CLASSLOADER_KEY, artifactClassLoader);
    InMemoryConfigurator inMemoryConfigurator = new InMemoryConfigurator(cConf, Id.Namespace.fromEntityId(deploymentInfo.getNamespaceId()), Id.Artifact.fromEntityId(artifactId), appClassName, artifactRepository, artifactClassLoader, deploymentInfo.getApplicationName(), deploymentInfo.getApplicationVersion(), configString);
    ListenableFuture<ConfigResponse> result = inMemoryConfigurator.config();
    ConfigResponse response = result.get(120, TimeUnit.SECONDS);
    if (response.getExitCode() != 0) {
        throw new IllegalArgumentException("Failed to configure application: " + deploymentInfo);
    }
    ApplicationSpecification specification = adapter.fromJson(response.get());
    ApplicationId applicationId;
    if (appVersion == null) {
        applicationId = deploymentInfo.getNamespaceId().app(specification.getName());
    } else {
        applicationId = deploymentInfo.getNamespaceId().app(specification.getName(), appVersion);
    }
    authorizationEnforcer.enforce(applicationId, authenticationContext.getPrincipal(), Action.ADMIN);
    emit(new ApplicationDeployable(deploymentInfo.getArtifactId(), deploymentInfo.getArtifactLocation(), applicationId, specification, store.getApplication(applicationId), ApplicationDeployScope.USER, deploymentInfo.getOwnerPrincipal(), deploymentInfo.canUpdateSchedules()));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ArtifactId(co.cask.cdap.proto.id.ArtifactId) EntityImpersonator(co.cask.cdap.security.impersonation.EntityImpersonator) ConfigResponse(co.cask.cdap.app.deploy.ConfigResponse) ApplicationId(co.cask.cdap.proto.id.ApplicationId) InMemoryConfigurator(co.cask.cdap.internal.app.deploy.InMemoryConfigurator) Location(org.apache.twill.filesystem.Location)

Aggregations

ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 ConfigResponse (co.cask.cdap.app.deploy.ConfigResponse)1 InMemoryConfigurator (co.cask.cdap.internal.app.deploy.InMemoryConfigurator)1 ApplicationId (co.cask.cdap.proto.id.ApplicationId)1 ArtifactId (co.cask.cdap.proto.id.ArtifactId)1 EntityImpersonator (co.cask.cdap.security.impersonation.EntityImpersonator)1 Location (org.apache.twill.filesystem.Location)1