Search in sources :

Example 11 with ProgramSpecification

use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.

the class ApplicationDetail method fromSpec.

public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
    List<ProgramRecord> programs = new ArrayList<>();
    for (ProgramSpecification programSpec : spec.getFlows().values()) {
        programs.add(new ProgramRecord(ProgramType.FLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    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<StreamDetail> streams = new ArrayList<>();
    for (StreamSpecification streamSpec : spec.getStreams().values()) {
        streams.add(new StreamDetail(streamSpec.getName()));
    }
    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(), streams, datasets, programs, plugins, summary, ownerPrincipal);
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) ArrayList(java.util.ArrayList) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) Map(java.util.Map) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 12 with ProgramSpecification

use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.

the class DefaultStoreTest method testCheckDeletedWorkflow.

@Test
public void testCheckDeletedWorkflow() 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> 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 FlowMapReduceApp());
    //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(co.cask.cdap.api.app.ApplicationSpecification) ProgramSpecification(co.cask.cdap.api.ProgramSpecification) FlowMapReduceApp(co.cask.cdap.FlowMapReduceApp) AllProgramsApp(co.cask.cdap.AllProgramsApp) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 13 with ProgramSpecification

use of co.cask.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.getFlows().values(), specification.getMapReduce().values(), specification.getWorkflows().values());
    VerifyResult result;
    for (ProgramSpecification programSpec : programSpecs) {
        result = getVerifier(programSpec.getClass()).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()));
        }
        // TODO StreamSizeSchedules should be resilient to stream inexistence [CDAP-1446]
        Trigger trigger = entry.getValue().getTrigger();
        if (trigger instanceof StreamSizeTrigger) {
            StreamId streamId = ((StreamSizeTrigger) trigger).getStreamId();
            if (!specification.getStreams().containsKey(streamId.getStream()) && store.getStream(streamId.getParent(), streamId.getStream()) == null) {
                throw new RuntimeException(String.format("Schedule '%s' uses a Stream '%s' that does not exit", entry.getValue().getName(), streamId));
            }
        }
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ProgramSpecification(co.cask.cdap.api.ProgramSpecification) ScheduleCreationSpec(co.cask.cdap.internal.schedule.ScheduleCreationSpec) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) Trigger(co.cask.cdap.internal.schedule.trigger.Trigger) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) VerifyResult(co.cask.cdap.app.verification.VerifyResult) Map(java.util.Map)

Example 14 with ProgramSpecification

use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.

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 {
    ProgramRuntimeService.RuntimeInfo runtimeInfo = findRuntimeInfo(programId);
    if (runtimeInfo == null) {
        if (programId.getType() != ProgramType.WEBAPP) {
            //Runtime info not found. Check to see if the program exists.
            ProgramSpecification spec = getExistingAppProgramSpecification(appSpec, programId);
            if (spec == null) {
                // program doesn't exist
                throw new NotFoundException(programId);
            }
            ensureAccess(programId);
            if ((programId.getType() == ProgramType.MAPREDUCE || programId.getType() == ProgramType.SPARK) && !store.getRuns(programId, ProgramRunStatus.RUNNING, 0, Long.MAX_VALUE, 1).isEmpty()) {
                // MapReduce program exists and running as a part of Workflow
                return ProgramStatus.RUNNING;
            }
            return ProgramStatus.STOPPED;
        }
        throw new IllegalStateException("Webapp status is not supported");
    }
    return runtimeInfo.getController().getState().getProgramStatus();
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) RuntimeInfo(co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo) ProgramRuntimeService(co.cask.cdap.app.runtime.ProgramRuntimeService)

Example 15 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)

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