use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
the class DefaultStoreTest method testCheckDeletedProgramSpecs.
@Test
public void testCheckDeletedProgramSpecs() throws Exception {
// 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> specsToBeVerified = Sets.newHashSet();
specsToBeVerified.addAll(spec.getMapReduce().keySet());
specsToBeVerified.addAll(spec.getWorkflows().keySet());
specsToBeVerified.addAll(spec.getFlows().keySet());
specsToBeVerified.addAll(spec.getServices().keySet());
specsToBeVerified.addAll(spec.getWorkers().keySet());
specsToBeVerified.addAll(spec.getSpark().keySet());
// Verify if there are 6 program specs in AllProgramsApp
Assert.assertEquals(7, specsToBeVerified.size());
// Check the diff with the same app - re-deployment scenario where programs are not removed.
List<ProgramSpecification> deletedSpecs = store.getDeletedProgramSpecifications(appId, spec);
Assert.assertEquals(0, deletedSpecs.size());
// Get the spec for app that contains no programs.
spec = Specifications.from(new NoProgramsApp());
// Get the deleted program specs by sending a spec with same name as AllProgramsApp but with no programs
deletedSpecs = store.getDeletedProgramSpecifications(appId, spec);
Assert.assertEquals(7, deletedSpecs.size());
for (ProgramSpecification specification : deletedSpecs) {
// Remove the spec that is verified, to check the count later.
specsToBeVerified.remove(specification.getName());
}
// All the 6 specs should have been deleted.
Assert.assertEquals(0, specsToBeVerified.size());
}
use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
the class DefaultStoreTest method testServiceDeletion.
@Test
public void testServiceDeletion() throws Exception {
// Store the application specification
AbstractApplication app = new AppWithServices();
ApplicationSpecification appSpec = Specifications.from(app);
ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
store.addApplication(appId, appSpec);
AbstractApplication newApp = new AppWithNoServices();
// get the delete program specs after deploying AppWithNoServices
List<ProgramSpecification> programSpecs = store.getDeletedProgramSpecifications(appId, Specifications.from(newApp));
// verify the result.
Assert.assertEquals(1, programSpecs.size());
Assert.assertEquals("NoOpService", programSpecs.get(0).getName());
}
use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
the class ApplicationLifecycleService method deletePreferences.
/**
* Delete stored Preferences of the application and all its programs.
*
* @param appId applicationId
*/
private void deletePreferences(ApplicationId appId) {
Iterable<ProgramSpecification> programSpecs = getProgramSpecs(appId);
for (ProgramSpecification spec : programSpecs) {
preferencesStore.deleteProperties(appId.getNamespace(), appId.getApplication(), ProgramTypes.fromSpecification(spec).getCategoryName(), spec.getName());
LOG.trace("Deleted Preferences of Program : {}, {}, {}, {}", appId.getNamespace(), appId.getApplication(), ProgramTypes.fromSpecification(spec).getCategoryName(), spec.getName());
}
preferencesStore.deleteProperties(appId.getNamespace(), appId.getApplication());
LOG.trace("Deleted Preferences of Application : {}, {}", appId.getNamespace(), appId.getApplication());
}
use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
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 = Transactionals.execute(transactional, 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.getFlows()).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.getFlows()).putAll(appSpec.getServices()).putAll(appSpec.getWorkers()).build();
MapDifference<String, ProgramSpecification> mapDiff = Maps.difference(existingSpec, newSpec);
deletedProgramSpecs.addAll(mapDiff.entriesOnlyOnLeft().values());
}
return deletedProgramSpecs;
}
use of co.cask.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}
*/
private ProgramSpecification getExistingAppProgramSpecification(ApplicationSpecification appSpec, ProgramId programId) throws Exception {
String programName = programId.getProgram();
ProgramType type = programId.getType();
ProgramSpecification programSpec;
if (type == ProgramType.FLOW && appSpec.getFlows().containsKey(programName)) {
programSpec = appSpec.getFlows().get(programName);
} else 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