use of io.cdap.cdap.api.ProgramSpecification in project cdap by caskdata.
the class DeletedProgramHandlerStage method process.
@Override
public void process(ApplicationDeployable appSpec) throws Exception {
List<ProgramSpecification> deletedSpecs = store.getDeletedProgramSpecifications(appSpec.getApplicationId(), appSpec.getSpecification());
// TODO: this should also delete logs and run records (or not?), and do it for all program types [CDAP-2187]
Set<ProgramId> deletedPrograms = new HashSet<>();
for (ProgramSpecification spec : deletedSpecs) {
// call the deleted spec
ProgramType type = ProgramTypes.fromSpecification(spec);
ProgramId programId = appSpec.getApplicationId().program(type, spec.getName());
programTerminator.stop(programId);
programScheduler.deleteSchedules(programId);
programScheduler.modifySchedulesTriggeredByDeletedProgram(programId);
// Remove metadata for the deleted program
metadataServiceClient.drop(new MetadataMutation.Drop(programId.toMetadataEntity()));
deletedPrograms.add(programId);
}
deleteMetrics(deletedPrograms);
emit(appSpec);
}
use of io.cdap.cdap.api.ProgramSpecification in project cdap by caskdata.
the class ProgramLifecycleService method getExistingAppProgramSpecification.
/**
* Returns the {@link ProgramSpecification} for the specified {@link ProgramId program}.
* @param appSpec the {@link ApplicationSpecification} of the existing application
* @param programId the {@link ProgramId program} for which the {@link ProgramSpecification} is requested
* @return the {@link ProgramSpecification} for the specified {@link ProgramId program}, or {@code null} if it does
* not exist
*/
@Nullable
private ProgramSpecification getExistingAppProgramSpecification(ApplicationSpecification appSpec, ProgramId programId) {
String programName = programId.getProgram();
ProgramType type = programId.getType();
ProgramSpecification programSpec;
if (type == ProgramType.MAPREDUCE && appSpec.getMapReduce().containsKey(programName)) {
programSpec = appSpec.getMapReduce().get(programName);
} else if (type == ProgramType.SPARK && appSpec.getSpark().containsKey(programName)) {
programSpec = appSpec.getSpark().get(programName);
} else if (type == ProgramType.WORKFLOW && appSpec.getWorkflows().containsKey(programName)) {
programSpec = appSpec.getWorkflows().get(programName);
} else if (type == ProgramType.SERVICE && appSpec.getServices().containsKey(programName)) {
programSpec = appSpec.getServices().get(programName);
} else if (type == ProgramType.WORKER && appSpec.getWorkers().containsKey(programName)) {
programSpec = appSpec.getWorkers().get(programName);
} else {
programSpec = null;
}
return programSpec;
}
use of io.cdap.cdap.api.ProgramSpecification 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);
}
use of io.cdap.cdap.api.ProgramSpecification in project cdap by caskdata.
the class ProgramLifecycleService method getRunRecordMetas.
/**
* Get the latest runs within the specified start and end times for the specified program.
*
* @param programId the program to get runs for
* @param programRunStatus status of runs to return
* @param start earliest start time of runs to return
* @param end latest start time of runs to return
* @param limit the maximum number of runs to return
* @return the latest runs for the program sorted by start time, with the newest run as the first run
* @throws NotFoundException if the application to which this program belongs was not found or the program is not
* found in the app
* @throws UnauthorizedException if the principal does not have access to the program
* @throws Exception if there was some other exception performing authorization checks
*/
public List<RunRecordDetail> getRunRecordMetas(ProgramId programId, ProgramRunStatus programRunStatus, long start, long end, int limit) throws Exception {
accessEnforcer.enforce(programId, authenticationContext.getPrincipal(), StandardPermission.GET);
ProgramSpecification programSpec = getProgramSpecificationWithoutAuthz(programId);
if (programSpec == null) {
throw new NotFoundException(programId);
}
return store.getRuns(programId, programRunStatus, start, end, limit).values().stream().collect(Collectors.toList());
}
use of io.cdap.cdap.api.ProgramSpecification in project cdap by caskdata.
the class ApplicationDetail method fromSpec.
public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
List<ProgramRecord> programs = new ArrayList<>();
for (ProgramSpecification programSpec : spec.getMapReduce().values()) {
programs.add(new ProgramRecord(ProgramType.MAPREDUCE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getServices().values()) {
programs.add(new ProgramRecord(ProgramType.SERVICE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getSpark().values()) {
programs.add(new ProgramRecord(ProgramType.SPARK, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getWorkers().values()) {
programs.add(new ProgramRecord(ProgramType.WORKER, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getWorkflows().values()) {
programs.add(new ProgramRecord(ProgramType.WORKFLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
List<DatasetDetail> datasets = new ArrayList<>();
for (DatasetCreationSpec datasetSpec : spec.getDatasets().values()) {
datasets.add(new DatasetDetail(datasetSpec.getInstanceName(), datasetSpec.getTypeName()));
}
List<PluginDetail> plugins = new ArrayList<>();
for (Map.Entry<String, Plugin> pluginEnty : spec.getPlugins().entrySet()) {
plugins.add(new PluginDetail(pluginEnty.getKey(), pluginEnty.getValue().getPluginClass().getName(), pluginEnty.getValue().getPluginClass().getType()));
}
// this is only required if there are old apps lying around that failed to get upgrading during
// the upgrade to v3.2 for some reason. In those cases artifact id will be null until they re-deploy the app.
// in the meantime, we don't want this api call to null pointer exception.
ArtifactSummary summary = spec.getArtifactId() == null ? new ArtifactSummary(spec.getName(), null) : ArtifactSummary.from(spec.getArtifactId());
return new ApplicationDetail(spec.getName(), spec.getAppVersion(), spec.getDescription(), spec.getConfiguration(), datasets, programs, plugins, summary, ownerPrincipal);
}
Aggregations