Search in sources :

Example 31 with ProgramDescriptor

use of io.cdap.cdap.app.program.ProgramDescriptor in project cdap by caskdata.

the class CapabilityManagementServiceTest method testProgramStart.

@Test
public void testProgramStart() throws Exception {
    String externalConfigPath = tmpFolder.newFolder("capability-config-program").getAbsolutePath();
    cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
    String appName = CapabilitySleepingWorkflowApp.NAME;
    Class<CapabilitySleepingWorkflowApp> appClass = CapabilitySleepingWorkflowApp.class;
    String version = "1.0.0";
    String namespace = "default";
    // deploy the artifact
    deployTestArtifact(namespace, appName, version, appClass);
    // enable a capability with no system apps and programs
    CapabilityConfig enabledConfig = new CapabilityConfig("Enable healthcare", CapabilityStatus.ENABLED, "healthcare", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    writeConfigAsFile(externalConfigPath, enabledConfig.getCapability(), enabledConfig);
    capabilityManagementService.runTask();
    String capability = enabledConfig.getCapability();
    capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
    // deploy an app with this capability and start a workflow
    ApplicationId applicationId = new ApplicationId(namespace, appName);
    Id.Artifact artifactId = Id.Artifact.from(new Id.Namespace(namespace), appName, version);
    ApplicationWithPrograms applicationWithPrograms = applicationLifecycleService.deployApp(new NamespaceId(namespace), appName, null, artifactId, null, op -> {
    });
    Iterable<ProgramDescriptor> programs = applicationWithPrograms.getPrograms();
    for (ProgramDescriptor program : programs) {
        programLifecycleService.start(program.getProgramId(), new HashMap<>(), false, false);
    }
    ProgramId programId = new ProgramId(applicationId, ProgramType.WORKFLOW, CapabilitySleepingWorkflowApp.SleepWorkflow.class.getSimpleName());
    // Capability management service might not yet have deployed application.
    // So wait till program exists and is in running state.
    waitState(programId, "RUNNING");
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
    // disable the capability -  the program that was started should stop
    CapabilityConfig disabledConfig = new CapabilityConfig("Disable healthcare", CapabilityStatus.DISABLED, "healthcare", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    writeConfigAsFile(externalConfigPath, capability, disabledConfig);
    capabilityManagementService.runTask();
    assertProgramRuns(programId, ProgramRunStatus.KILLED, 1);
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 0);
    try {
        capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
        Assert.fail("expecting exception");
    } catch (CapabilityNotAvailableException ex) {
    }
    // try starting programs
    for (ProgramDescriptor program : programs) {
        try {
            programLifecycleService.start(program.getProgramId(), new HashMap<>(), false, false);
            Assert.fail("expecting exception");
        } catch (CapabilityNotAvailableException ex) {
        // expecting exception
        }
    }
    new File(externalConfigPath, capability).delete();
    capabilityManagementService.runTask();
    Assert.assertTrue(capabilityStatusStore.getConfigs(Collections.singleton(capability)).isEmpty());
}
Also used : CapabilitySleepingWorkflowApp(io.cdap.cdap.CapabilitySleepingWorkflowApp) ProgramId(io.cdap.cdap.proto.id.ProgramId) ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) File(java.io.File) Test(org.junit.Test)

Example 32 with ProgramDescriptor

use of io.cdap.cdap.app.program.ProgramDescriptor in project cdap by caskdata.

the class CapabilityManagementServiceTest method testProgramWithPluginStart.

@Test
public void testProgramWithPluginStart() throws Exception {
    String externalConfigPath = tmpFolder.newFolder("capability-config-program-plugin").getAbsolutePath();
    cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
    String appName = CapabilitySleepingWorkflowPluginApp.NAME;
    Class<CapabilitySleepingWorkflowPluginApp> appClass = CapabilitySleepingWorkflowPluginApp.class;
    String version = "1.0.0";
    String namespace = "default";
    // deploy the artifact
    deployTestArtifact(namespace, appName, version, appClass);
    // deploy the plugin artifact
    Manifest manifest = new Manifest();
    String pluginName = CapabilitySleepingWorkflowPluginApp.SimplePlugin.class.getPackage().getName();
    manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, pluginName);
    Location pluginJar = PluginJarHelper.createPluginJar(locationFactory, manifest, CapabilitySleepingWorkflowPluginApp.SimplePlugin.class);
    Id.Artifact pluginArtifactId = Id.Artifact.from(Id.Namespace.from(namespace), pluginName, version);
    File pluginJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", pluginArtifactId.getName(), version));
    Locations.linkOrCopyOverwrite(pluginJar, pluginJarFile);
    pluginJar.delete();
    artifactRepository.addArtifact(pluginArtifactId, pluginJarFile);
    // enable a capability with no system apps and programs
    CapabilityConfig enabledConfig = new CapabilityConfig("Enable healthcare", CapabilityStatus.ENABLED, "healthcare", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    writeConfigAsFile(externalConfigPath, enabledConfig.getCapability(), enabledConfig);
    capabilityManagementService.runTask();
    String capability = enabledConfig.getCapability();
    capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
    // deploy an app with this capability and start a workflow
    ApplicationId applicationId = new ApplicationId(namespace, appName);
    Id.Artifact artifactId = Id.Artifact.from(new Id.Namespace(namespace), appName, version);
    ApplicationWithPrograms applicationWithPrograms = applicationLifecycleService.deployApp(new NamespaceId(namespace), appName, null, artifactId, null, op -> {
    });
    Iterable<ProgramDescriptor> programs = applicationWithPrograms.getPrograms();
    for (ProgramDescriptor program : programs) {
        programLifecycleService.start(program.getProgramId(), new HashMap<>(), false, false);
    }
    ProgramId programId = new ProgramId(applicationId, ProgramType.WORKFLOW, CapabilitySleepingWorkflowPluginApp.SleepWorkflow.class.getSimpleName());
    // Capability management service might not yet have deployed application.
    // So wait till program exists and is in running state.
    waitState(programId, "RUNNING");
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
    // disable the capability -  the program that was started should stop
    CapabilityConfig disabledConfig = new CapabilityConfig("Disable healthcare", CapabilityStatus.DISABLED, "healthcare", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    writeConfigAsFile(externalConfigPath, capability, disabledConfig);
    capabilityManagementService.runTask();
    assertProgramRuns(programId, ProgramRunStatus.KILLED, 1);
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 0);
    try {
        capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
        Assert.fail("expecting exception");
    } catch (CapabilityNotAvailableException ex) {
    }
    // try starting programs
    for (ProgramDescriptor program : programs) {
        try {
            programLifecycleService.start(program.getProgramId(), new HashMap<>(), false, false);
            Assert.fail("expecting exception");
        } catch (CapabilityNotAvailableException ex) {
        // expecting exception
        }
    }
    new File(externalConfigPath, capability).delete();
    capabilityManagementService.runTask();
    Assert.assertTrue(capabilityStatusStore.getConfigs(Collections.singleton(capability)).isEmpty());
}
Also used : CapabilitySleepingWorkflowPluginApp(io.cdap.cdap.CapabilitySleepingWorkflowPluginApp) Manifest(java.util.jar.Manifest) ProgramId(io.cdap.cdap.proto.id.ProgramId) ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) File(java.io.File) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 33 with ProgramDescriptor

use of io.cdap.cdap.app.program.ProgramDescriptor in project cdap by caskdata.

the class ProgramNotificationSubscriberServiceTest method testAppSpecNotRequiredToWriteState.

@Test
public void testAppSpecNotRequiredToWriteState() throws Exception {
    ProgramId programId = NamespaceId.DEFAULT.app("someapp").program(ProgramType.SERVICE, "s");
    Map<String, String> systemArguments = new HashMap<>();
    systemArguments.put(ProgramOptionConstants.SKIP_PROVISIONING, Boolean.TRUE.toString());
    systemArguments.put(SystemArguments.PROFILE_NAME, ProfileId.NATIVE.getScopedName());
    ProgramOptions programOptions = new SimpleProgramOptions(programId, new BasicArguments(systemArguments), new BasicArguments());
    ProgramRunId runId = programId.run(RunIds.generate());
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
    ApplicationSpecification appSpec = new DefaultApplicationSpecification("name", "1.0.0", ProjectInfo.getVersion().toString(), "desc", null, artifactId, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
    ProgramDescriptor programDescriptor = new ProgramDescriptor(programId, appSpec);
    programStateWriter.start(runId, programOptions, null, programDescriptor);
    Tasks.waitFor(ProgramRunStatus.STARTING, () -> TransactionRunners.run(transactionRunner, context -> {
        AppMetadataStore metadataStoreDataset = AppMetadataStore.create(context);
        RunRecordDetail meta = metadataStoreDataset.getRun(runId);
        if (meta == null) {
            return null;
        }
        Assert.assertEquals(artifactId, meta.getArtifactId());
        return meta.getStatus();
    }), 10, TimeUnit.SECONDS);
    programStateWriter.completed(runId);
}
Also used : RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) Arrays(java.util.Arrays) TransactionRunners(io.cdap.cdap.spi.data.transaction.TransactionRunners) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) TimeoutException(java.util.concurrent.TimeoutException) NodeStatus(io.cdap.cdap.api.workflow.NodeStatus) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) AppFabricTestHelper(io.cdap.cdap.internal.AppFabricTestHelper) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) After(org.junit.After) Map(java.util.Map) RunId(org.apache.twill.api.RunId) Tasks(io.cdap.cdap.common.utils.Tasks) AfterClass(org.junit.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) Id(io.cdap.cdap.common.id.Id) List(java.util.List) AggregationFunction(io.cdap.cdap.api.dataset.lib.cube.AggregationFunction) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Constants(io.cdap.cdap.common.conf.Constants) ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramOptionConstants(io.cdap.cdap.internal.app.runtime.ProgramOptionConstants) BeforeClass(org.junit.BeforeClass) MetricStore(io.cdap.cdap.api.metrics.MetricStore) HashMap(java.util.HashMap) ProgramType(io.cdap.cdap.proto.ProgramType) ArrayList(java.util.ArrayList) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramHeartbeatTable(io.cdap.cdap.reporting.ProgramHeartbeatTable) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) Profile(io.cdap.cdap.proto.profile.Profile) MetricDataQuery(io.cdap.cdap.api.metrics.MetricDataQuery) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) WorkflowNodeStateDetail(io.cdap.cdap.proto.WorkflowNodeStateDetail) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) WorkflowStateWriter(io.cdap.cdap.internal.app.runtime.workflow.WorkflowStateWriter) ProfileService(io.cdap.cdap.internal.profile.ProfileService) RunIds(io.cdap.cdap.common.app.RunIds) ProgramId(io.cdap.cdap.proto.id.ProgramId) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) Test(org.junit.Test) MetricTimeSeries(io.cdap.cdap.api.metrics.MetricTimeSeries) ProjectInfo(io.cdap.cdap.common.utils.ProjectInfo) ProgramRunClusterStatus(io.cdap.cdap.proto.ProgramRunClusterStatus) Injector(com.google.inject.Injector) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) TimeValue(io.cdap.cdap.api.dataset.lib.cube.TimeValue) Assert(org.junit.Assert) Collections(java.util.Collections) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HashMap(java.util.HashMap) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) ProgramId(io.cdap.cdap.proto.id.ProgramId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) Test(org.junit.Test)

Aggregations

ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)33 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)17 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)17 Test (org.junit.Test)16 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)15 ProgramId (io.cdap.cdap.proto.id.ProgramId)15 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)13 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)13 File (java.io.File)12 HashMap (java.util.HashMap)10 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)9 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)9 IOException (java.io.IOException)9 Injector (com.google.inject.Injector)7 SystemArguments (io.cdap.cdap.internal.app.runtime.SystemArguments)7 ProgramType (io.cdap.cdap.proto.ProgramType)7 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)7 Collections (java.util.Collections)7 Program (io.cdap.cdap.app.program.Program)6 RunIds (io.cdap.cdap.common.app.RunIds)6