Search in sources :

Example 1 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 2 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 3 with ProgramSpecification

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());
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification)

Example 4 with ProgramSpecification

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;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ForwardingApplicationSpecification(co.cask.cdap.internal.app.ForwardingApplicationSpecification) ProgramSpecification(co.cask.cdap.api.ProgramSpecification)

Example 5 with ProgramSpecification

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;
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) ProgramType(co.cask.cdap.proto.ProgramType)

Aggregations

ProgramSpecification (co.cask.cdap.api.ProgramSpecification)14 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)5 ProgramId (co.cask.cdap.proto.id.ProgramId)5 ProgramType (co.cask.cdap.proto.ProgramType)4 ApplicationId (co.cask.cdap.proto.id.ApplicationId)4 Test (org.junit.Test)3 AllProgramsApp (co.cask.cdap.AllProgramsApp)2 NotFoundException (co.cask.cdap.common.NotFoundException)2 ProgramSystemMetadataWriter (co.cask.cdap.data2.metadata.system.ProgramSystemMetadataWriter)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)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 AbstractApplication (co.cask.cdap.api.app.AbstractApplication)1 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1 StreamSpecification (co.cask.cdap.api.data.stream.StreamSpecification)1 Plugin (co.cask.cdap.api.plugin.Plugin)1 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)1