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