Search in sources :

Example 16 with ProgramSpecification

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

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

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

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

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

the class ApplicationDetail method fromSpec.

public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
    List<ProgramRecord> programs = new ArrayList<>();
    for (ProgramSpecification programSpec : spec.getMapReduce().values()) {
        programs.add(new ProgramRecord(ProgramType.MAPREDUCE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getServices().values()) {
        programs.add(new ProgramRecord(ProgramType.SERVICE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getSpark().values()) {
        programs.add(new ProgramRecord(ProgramType.SPARK, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkers().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKER, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkflows().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKFLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    List<DatasetDetail> datasets = new ArrayList<>();
    for (DatasetCreationSpec datasetSpec : spec.getDatasets().values()) {
        datasets.add(new DatasetDetail(datasetSpec.getInstanceName(), datasetSpec.getTypeName()));
    }
    List<PluginDetail> plugins = new ArrayList<>();
    for (Map.Entry<String, Plugin> pluginEnty : spec.getPlugins().entrySet()) {
        plugins.add(new PluginDetail(pluginEnty.getKey(), pluginEnty.getValue().getPluginClass().getName(), pluginEnty.getValue().getPluginClass().getType()));
    }
    // this is only required if there are old apps lying around that failed to get upgrading during
    // the upgrade to v3.2 for some reason. In those cases artifact id will be null until they re-deploy the app.
    // in the meantime, we don't want this api call to null pointer exception.
    ArtifactSummary summary = spec.getArtifactId() == null ? new ArtifactSummary(spec.getName(), null) : ArtifactSummary.from(spec.getArtifactId());
    return new ApplicationDetail(spec.getName(), spec.getAppVersion(), spec.getDescription(), spec.getConfiguration(), datasets, programs, plugins, summary, ownerPrincipal);
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ArrayList(java.util.ArrayList) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) DatasetCreationSpec(io.cdap.cdap.internal.dataset.DatasetCreationSpec) Map(java.util.Map) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 19 with ProgramSpecification

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

the class ProgramLifecycleService method getExistingAppProgramStatus.

/**
 * Returns the program status with no need of application existence check.
 * @param appSpec the ApplicationSpecification of the existing application
 * @param programId the id of the program for which the status call is made
 * @return the status of the program
 * @throws NotFoundException if the application to which this program belongs was not found
 */
private ProgramStatus getExistingAppProgramStatus(ApplicationSpecification appSpec, ProgramId programId) throws Exception {
    accessEnforcer.enforce(programId, authenticationContext.getPrincipal(), StandardPermission.GET);
    ProgramSpecification spec = getExistingAppProgramSpecification(appSpec, programId);
    if (spec == null) {
        // program doesn't exist
        throw new NotFoundException(programId);
    }
    return getProgramStatus(store.getActiveRuns(programId).values());
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 20 with ProgramSpecification

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

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}, or {@code null} if it does
 *         not exist
 */
@Nullable
private ProgramSpecification getExistingAppProgramSpecification(ApplicationSpecification appSpec, ProgramId programId) {
    String programName = programId.getProgram();
    ProgramType type = programId.getType();
    ProgramSpecification programSpec;
    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(io.cdap.cdap.api.ProgramSpecification) ProgramType(io.cdap.cdap.proto.ProgramType) Nullable(javax.annotation.Nullable)

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