use of io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms 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());
}
use of io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms 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());
}
Aggregations