Search in sources :

Example 1 with ProgramSpecification

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

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

Example 2 with ProgramSpecification

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

the class DefaultStoreTest method testServiceDeletion.

@Test
public void testServiceDeletion() {
    // 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(io.cdap.cdap.api.app.ApplicationSpecification) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) AppWithServices(io.cdap.cdap.AppWithServices) AbstractApplication(io.cdap.cdap.api.app.AbstractApplication) AppWithNoServices(io.cdap.cdap.AppWithNoServices) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 3 with ProgramSpecification

use of io.cdap.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 = 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;
}
Also used : ForwardingApplicationSpecification(io.cdap.cdap.internal.app.ForwardingApplicationSpecification) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification)

Example 4 with ProgramSpecification

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

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 5 with ProgramSpecification

use of io.cdap.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.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)

Aggregations

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