Search in sources :

Example 11 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.

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);
}
Also used : MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ProgramType(io.cdap.cdap.proto.ProgramType) ProgramId(io.cdap.cdap.proto.id.ProgramId) HashSet(java.util.HashSet)

Example 12 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.

the class MetadataWriterStage method collectProgramSystemMetadata.

private void collectProgramSystemMetadata(ApplicationId appId, ProgramType programType, Iterable<? extends ProgramSpecification> specs, List<MetadataMutation> mutations) {
    for (ProgramSpecification spec : specs) {
        ProgramId programId = appId.program(programType, spec.getName());
        mutations.add(new ProgramSystemMetadataWriter(metadataServiceClient, programId, spec, creationTime).getMetadataMutation());
    }
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ProgramId(io.cdap.cdap.proto.id.ProgramId) ProgramSystemMetadataWriter(io.cdap.cdap.data2.metadata.system.ProgramSystemMetadataWriter)

Example 13 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.

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.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());
        programDescriptors.add(new ProgramDescriptor(programId, appSpec));
    }
    emit(new ApplicationWithPrograms(input, programDescriptors));
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ArrayList(java.util.ArrayList) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) ProgramType(io.cdap.cdap.proto.ProgramType) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 14 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.

the class ApplicationVerificationStage method verifyPrograms.

protected void verifyPrograms(ApplicationId appId, ApplicationSpecification specification) {
    Iterable<ProgramSpecification> programSpecs = Iterables.concat(specification.getMapReduce().values(), specification.getWorkflows().values());
    VerifyResult result;
    for (ProgramSpecification programSpec : programSpecs) {
        Verifier<ProgramSpecification> verifier = getVerifier(programSpec.getClass());
        result = verifier.verify(appId, programSpec);
        if (!result.isSuccess()) {
            throw new RuntimeException(result.getMessage());
        }
    }
    for (Map.Entry<String, WorkflowSpecification> entry : specification.getWorkflows().entrySet()) {
        verifyWorkflowSpecifications(specification, entry.getValue());
    }
    for (Map.Entry<String, ScheduleCreationSpec> entry : specification.getProgramSchedules().entrySet()) {
        String programName = entry.getValue().getProgramName();
        if (!specification.getWorkflows().containsKey(programName)) {
            throw new RuntimeException(String.format("Schedule '%s' is invalid: Workflow '%s' is not configured " + "in application '%s'", entry.getValue().getName(), programName, specification.getName()));
        }
    }
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) VerifyResult(io.cdap.cdap.app.verification.VerifyResult) ScheduleCreationSpec(io.cdap.cdap.internal.schedule.ScheduleCreationSpec) Map(java.util.Map)

Example 15 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by cdapio.

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

Aggregations

ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)32 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)12 NotFoundException (io.cdap.cdap.common.NotFoundException)12 ProgramType (io.cdap.cdap.proto.ProgramType)8 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)8 ProgramId (io.cdap.cdap.proto.id.ProgramId)8 Test (org.junit.Test)6 AllProgramsApp (io.cdap.cdap.AllProgramsApp)4 ForwardingApplicationSpecification (io.cdap.cdap.internal.app.ForwardingApplicationSpecification)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AppWithNoServices (io.cdap.cdap.AppWithNoServices)2 AppWithServices (io.cdap.cdap.AppWithServices)2 DefaultStoreTestApp (io.cdap.cdap.DefaultStoreTestApp)2 NoProgramsApp (io.cdap.cdap.NoProgramsApp)2 AbstractApplication (io.cdap.cdap.api.app.AbstractApplication)2 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)2 Plugin (io.cdap.cdap.api.plugin.Plugin)2 WorkflowSpecification (io.cdap.cdap.api.workflow.WorkflowSpecification)2