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 ProgramLifecycleHttpHandler method programSpecification.
@GET
@Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}")
public void programSpecification(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-name") String appName, @PathParam("app-version") String appVersion, @PathParam("program-type") String type, @PathParam("program-name") String programName) throws Exception {
ProgramType programType = getProgramType(type);
if (programType == null) {
throw new MethodNotAllowedException(request.getMethod(), request.getUri());
}
ApplicationId application = new ApplicationId(namespaceId, appName, appVersion);
ProgramId programId = application.program(programType, programName);
ProgramSpecification specification = lifecycleService.getProgramSpecification(programId);
if (specification == null) {
throw new NotFoundException(programId);
}
responder.sendJson(HttpResponseStatus.OK, specification);
}
use of co.cask.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]
List<String> deletedFlows = Lists.newArrayList();
for (ProgramSpecification spec : deletedSpecs) {
//call the deleted spec
ProgramType type = ProgramTypes.fromSpecification(spec);
final ProgramId programId = appSpec.getApplicationId().program(type, spec.getName());
programTerminator.stop(programId);
// revoke privileges
privilegesManager.revoke(programId);
// drop all queues and stream states of a deleted flow
if (ProgramType.FLOW.equals(type)) {
FlowSpecification flowSpecification = (FlowSpecification) spec;
// Collects stream name to all group ids consuming that stream
final Multimap<String, Long> streamGroups = HashMultimap.create();
for (FlowletConnection connection : flowSpecification.getConnections()) {
if (connection.getSourceType() == FlowletConnection.Type.STREAM) {
long groupId = FlowUtils.generateConsumerGroupId(programId, connection.getTargetName());
streamGroups.put(connection.getSourceName(), groupId);
}
}
// Remove all process states and group states for each stream
final String namespace = String.format("%s.%s", programId.getApplication(), programId.getProgram());
final NamespaceId namespaceId = appSpec.getApplicationId().getParent();
impersonator.doAs(appSpec.getApplicationId(), new Callable<Void>() {
@Override
public Void call() throws Exception {
for (Map.Entry<String, Collection<Long>> entry : streamGroups.asMap().entrySet()) {
streamConsumerFactory.dropAll(namespaceId.stream(entry.getKey()), namespace, entry.getValue());
}
queueAdmin.dropAllForFlow(programId.getParent().flow(programId.getEntityName()));
return null;
}
});
deletedFlows.add(programId.getEntityName());
}
// Remove metadata for the deleted program
metadataStore.removeMetadata(programId);
}
if (!deletedFlows.isEmpty()) {
deleteMetrics(appSpec.getApplicationId(), deletedFlows);
}
emit(appSpec);
}
use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
the class ProgramGenerationStage method process.
@Override
public void process(final ApplicationDeployable input) throws Exception {
List<ProgramDescriptor> programDescriptors = new ArrayList<>();
final ApplicationSpecification appSpec = input.getSpecification();
// Now, we iterate through all ProgramSpecification and generate programs
Iterable<ProgramSpecification> specifications = Iterables.concat(appSpec.getMapReduce().values(), appSpec.getFlows().values(), appSpec.getWorkflows().values(), appSpec.getServices().values(), appSpec.getSpark().values(), appSpec.getWorkers().values());
for (ProgramSpecification spec : specifications) {
ProgramType type = ProgramTypes.fromSpecification(spec);
ProgramId programId = input.getApplicationId().program(type, spec.getName());
privilegesManager.grant(programId, authenticationContext.getPrincipal(), EnumSet.allOf(Action.class));
programDescriptors.add(new ProgramDescriptor(programId, appSpec));
}
emit(new ApplicationWithPrograms(input, programDescriptors));
}
Aggregations