Search in sources :

Example 6 with ProgramSpecification

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());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ProgramSpecification(co.cask.cdap.api.ProgramSpecification) NoProgramsApp(co.cask.cdap.NoProgramsApp) AllProgramsApp(co.cask.cdap.AllProgramsApp) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 7 with ProgramSpecification

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());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ProgramSpecification(co.cask.cdap.api.ProgramSpecification) AppWithServices(co.cask.cdap.AppWithServices) AbstractApplication(co.cask.cdap.api.app.AbstractApplication) AppWithNoServices(co.cask.cdap.AppWithNoServices) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 8 with ProgramSpecification

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);
}
Also used : MethodNotAllowedException(co.cask.cdap.common.MethodNotAllowedException) ProgramSpecification(co.cask.cdap.api.ProgramSpecification) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ProgramType(co.cask.cdap.proto.ProgramType) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 9 with ProgramSpecification

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);
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) FlowletConnection(co.cask.cdap.api.flow.FlowletConnection) ProgramId(co.cask.cdap.proto.id.ProgramId) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ProgramType(co.cask.cdap.proto.ProgramType) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 10 with ProgramSpecification

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));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) Action(co.cask.cdap.proto.security.Action) ProgramSpecification(co.cask.cdap.api.ProgramSpecification) ArrayList(java.util.ArrayList) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) ProgramType(co.cask.cdap.proto.ProgramType) ProgramId(co.cask.cdap.proto.id.ProgramId)

Aggregations

ProgramSpecification (co.cask.cdap.api.ProgramSpecification)15 ProgramId (co.cask.cdap.proto.id.ProgramId)6 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)5 ProgramType (co.cask.cdap.proto.ProgramType)5 ApplicationId (co.cask.cdap.proto.id.ApplicationId)5 NotFoundException (co.cask.cdap.common.NotFoundException)3 Test (org.junit.Test)3 AllProgramsApp (co.cask.cdap.AllProgramsApp)2 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)2 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)2 ProgramSystemMetadataWriter (co.cask.cdap.data2.metadata.system.ProgramSystemMetadataWriter)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 AppWithNoServices (co.cask.cdap.AppWithNoServices)1 AppWithServices (co.cask.cdap.AppWithServices)1 FlowMapReduceApp (co.cask.cdap.FlowMapReduceApp)1 NoProgramsApp (co.cask.cdap.NoProgramsApp)1