use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.
the class DefaultStore method getDeletedProgramSpecifications.
// todo: this method should be moved into DeletedProgramHandlerState, bad design otherwise
@Override
public List<ProgramSpecification> getDeletedProgramSpecifications(ApplicationId id, ApplicationSpecification appSpec) {
ApplicationMeta existing = TransactionRunners.run(transactionRunner, context -> {
return getAppMetadataStore(context).getApplication(id.getNamespace(), id.getApplication(), id.getVersion());
});
List<ProgramSpecification> deletedProgramSpecs = Lists.newArrayList();
if (existing != null) {
ApplicationSpecification existingAppSpec = existing.getSpec();
Map<String, ProgramSpecification> existingSpec = ImmutableMap.<String, ProgramSpecification>builder().putAll(existingAppSpec.getMapReduce()).putAll(existingAppSpec.getSpark()).putAll(existingAppSpec.getWorkflows()).putAll(existingAppSpec.getServices()).putAll(existingAppSpec.getWorkers()).build();
Map<String, ProgramSpecification> newSpec = ImmutableMap.<String, ProgramSpecification>builder().putAll(appSpec.getMapReduce()).putAll(appSpec.getSpark()).putAll(appSpec.getWorkflows()).putAll(appSpec.getServices()).putAll(appSpec.getWorkers()).build();
MapDifference<String, ProgramSpecification> mapDiff = Maps.difference(existingSpec, newSpec);
deletedProgramSpecs.addAll(mapDiff.entriesOnlyOnLeft().values());
}
return deletedProgramSpecs;
}
use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.
the class DefaultStoreTest method testCheckDeletedWorkflow.
@Test
public void testCheckDeletedWorkflow() {
// Deploy program with all types of programs.
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
store.addApplication(appId, spec);
Set<String> specsToBeDeleted = Sets.newHashSet();
specsToBeDeleted.addAll(spec.getWorkflows().keySet());
Assert.assertEquals(1, specsToBeDeleted.size());
// Get the spec for app that contains only flow and mapreduce - removing workflows.
spec = Specifications.from(new DefaultStoreTestApp());
// Get the deleted program specs by sending a spec with same name as AllProgramsApp but with no programs
List<ProgramSpecification> deletedSpecs = store.getDeletedProgramSpecifications(appId, spec);
Assert.assertEquals(2, deletedSpecs.size());
for (ProgramSpecification specification : deletedSpecs) {
// Remove the spec that is verified, to check the count later.
specsToBeDeleted.remove(specification.getName());
}
// 2 specs should have been deleted and 0 should be remaining.
Assert.assertEquals(0, specsToBeDeleted.size());
}
use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.
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);
}
use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.
the class ProgramLifecycleService method getExistingAppProgramStatus.
/**
* Returns the program status with no need of application existence check.
* @param appSpec the ApplicationSpecification of the existing application
* @param programId the id of the program for which the status call is made
* @return the status of the program
* @throws NotFoundException if the application to which this program belongs was not found
*/
private ProgramStatus getExistingAppProgramStatus(ApplicationSpecification appSpec, ProgramId programId) throws Exception {
accessEnforcer.enforce(programId, authenticationContext.getPrincipal(), StandardPermission.GET);
ProgramSpecification spec = getExistingAppProgramSpecification(appSpec, programId);
if (spec == null) {
// program doesn't exist
throw new NotFoundException(programId);
}
return getProgramStatus(store.getActiveRuns(programId).values());
}
use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.
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;
}
Aggregations