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()));
}
Aggregations