use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
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());
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class DefaultStoreTest method testProgramRunCount.
@Test
public void testProgramRunCount() {
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
ArtifactId testArtifact = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
ProgramId workflowId = appId.workflow(AllProgramsApp.NoOpWorkflow.NAME);
ProgramId serviceId = appId.service(AllProgramsApp.NoOpService.NAME);
ProgramId nonExistingAppProgramId = NamespaceId.DEFAULT.app("nonExisting").workflow("test");
ProgramId nonExistingProgramId = appId.workflow("nonExisting");
// add the application
store.addApplication(appId, spec);
// add some run records to workflow and service
for (int i = 0; i < 5; i++) {
setStart(workflowId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
setStart(serviceId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
}
List<RunCountResult> result = store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId, nonExistingAppProgramId, nonExistingProgramId));
// compare the result
Assert.assertEquals(4, result.size());
for (RunCountResult runCountResult : result) {
ProgramId programId = runCountResult.getProgramId();
Long count = runCountResult.getCount();
if (programId.equals(nonExistingAppProgramId) || programId.equals(nonExistingProgramId)) {
Assert.assertNull(count);
Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
} else {
Assert.assertNotNull(count);
Assert.assertEquals(5L, count.longValue());
}
}
// remove the app should remove all run count
store.removeApplication(appId);
for (RunCountResult runCountResult : store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId))) {
Assert.assertNull(runCountResult.getCount());
Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
}
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class CapabilityManagementServiceTest method testCapabilityManagement.
@Test
public void testCapabilityManagement() throws Exception {
String appName = AllProgramsApp.NAME;
String programName = AllProgramsApp.NoOpService.NAME;
Class<AllProgramsApp> appClass = AllProgramsApp.class;
String version = "1.0.0";
String namespace = NamespaceId.SYSTEM.getNamespace();
// deploy the artifact
deployTestArtifact(namespace, appName, version, appClass);
ApplicationId applicationId = new ApplicationId(namespace, appName, version);
ProgramId programId = new ProgramId(applicationId, ProgramType.SERVICE, programName);
String externalConfigPath = tmpFolder.newFolder("capability-config-test").getAbsolutePath();
cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
String fileName = "cap1.json";
File testJson = new File(CapabilityManagementServiceTest.class.getResource(String.format("/%s", fileName)).getPath());
Files.copy(testJson, new File(externalConfigPath, fileName));
capabilityManagementService.runTask();
List<JsonObject> appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// 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);
// remove the file and make sure it gets removed
new File(externalConfigPath, fileName).delete();
capabilityManagementService.runTask();
Assert.assertTrue(getAppList(namespace).isEmpty());
// insert a pending entry, this should get re-applied and enable the capability
FileReader fileReader = new FileReader(testJson);
CapabilityConfig capabilityConfig = GSON.fromJson(fileReader, CapabilityConfig.class);
capabilityStatusStore.addOrUpdateCapabilityOperation("cap1", CapabilityAction.ENABLE, capabilityConfig);
capabilityManagementService.runTask();
capabilityStatusStore.checkAllEnabled(Collections.singleton("cap1"));
Assert.assertEquals(0, capabilityStatusStore.getCapabilityRecords().values().stream().filter(capabilityRecord -> capabilityRecord.getCapabilityOperationRecord() != null).count());
// pending task out of the way , on next run should be deleted
capabilityManagementService.runTask();
try {
capabilityStatusStore.checkAllEnabled(Collections.singleton("cap1"));
Assert.fail("expecting exception");
} catch (CapabilityNotAvailableException ex) {
// expected
}
// disable from delete and see if it is applied correctly
CapabilityConfig disableConfig = new CapabilityConfig(capabilityConfig.getLabel(), CapabilityStatus.DISABLED, capabilityConfig.getCapability(), capabilityConfig.getApplications(), capabilityConfig.getPrograms(), capabilityConfig.getHubs());
writeConfigAsFile(externalConfigPath, fileName, disableConfig);
capabilityManagementService.runTask();
try {
capabilityStatusStore.checkAllEnabled(Collections.singleton("cap1"));
Assert.fail("expecting exception");
} catch (CapabilityNotAvailableException ex) {
// expected
}
Assert.assertEquals(disableConfig, capabilityStatusStore.getConfigs(Collections.singleton("cap1")).get("cap1"));
// enable again
writeConfigAsFile(externalConfigPath, fileName, capabilityConfig);
capabilityManagementService.runTask();
capabilityStatusStore.checkAllEnabled(Collections.singleton("cap1"));
// 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);
// cleanup
new File(externalConfigPath, fileName).delete();
capabilityManagementService.runTask();
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class CapabilityManagementServiceTest method testCapabilityRefreshWithSameArtifact.
@Test
public void testCapabilityRefreshWithSameArtifact() throws Exception {
String externalConfigPath = tmpFolder.newFolder("capability-config-refresh-redeploy-same").getAbsolutePath();
cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
String appName = AllProgramsApp.NAME;
String programName = AllProgramsApp.NoOpService.NAME;
Class<AllProgramsApp> appClass = AllProgramsApp.class;
String appVersion = "1.0.0";
String namespace = NamespaceId.SYSTEM.getNamespace();
// deploy the artifact with older version.
String artifactVersion = "1.0.0";
deployTestArtifact(namespace, appName, artifactVersion, appClass);
ApplicationId applicationId = new ApplicationId(namespace, appName, appVersion);
ProgramId programId = new ProgramId(applicationId, ProgramType.SERVICE, programName);
// check that app is not available
List<JsonObject> appList = getAppList(namespace);
Assert.assertTrue(appList.isEmpty());
// enable the capability
CapabilityConfig config = getTestConfig(artifactVersion);
writeConfigAsFile(externalConfigPath, config.getCapability(), config);
capabilityManagementService.runTask();
// app should show up and program should have run
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// 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);
String capability = config.getCapability();
capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
// disable capability. Program should stop, status should be disabled and app should still be present.
CapabilityConfig disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), 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) {
// expected
}
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// enable the capability again but with same artifact.
config = getTestConfig(artifactVersion);
writeConfigAsFile(externalConfigPath, config.getCapability(), config);
capabilityManagementService.runTask();
// app should show up with newer artifact and program should have run.
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// Verify that application is still same as before.
Assert.assertEquals(artifactVersion, appList.get(0).get("artifact").getAsJsonObject().get("version").getAsString());
// 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);
capability = config.getCapability();
capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
// disable capability again. Program should stop, status should be disabled and app should still be present.
disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), 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) {
// expected
}
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// delete capability. Program should stop, status should be disabled and app should still be present.
new File(externalConfigPath, disabledConfig.getCapability()).delete();
capabilityManagementService.runTask();
Assert.assertTrue(capabilityStatusStore.getConfigs(Collections.singleton(capability)).isEmpty());
appList = getAppList(namespace);
Assert.assertTrue(appList.isEmpty());
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class CapabilityManagementServiceTest method testCapabilityRefreshWithNewArtifact.
@Test
public void testCapabilityRefreshWithNewArtifact() throws Exception {
String externalConfigPath = tmpFolder.newFolder("capability-config-refresh-redeploy").getAbsolutePath();
cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
String appName = AllProgramsApp.NAME;
String programName = AllProgramsApp.NoOpService.NAME;
Class<AllProgramsApp> appClass = AllProgramsApp.class;
String appVersion = "1.0.0";
String namespace = NamespaceId.SYSTEM.getNamespace();
// deploy the artifact with older version.
String oldArtifactVersion = "1.0.0";
deployTestArtifact(namespace, appName, oldArtifactVersion, appClass);
ApplicationId applicationId = new ApplicationId(namespace, appName, appVersion);
ProgramId programId = new ProgramId(applicationId, ProgramType.SERVICE, programName);
// check that app is not available
List<JsonObject> appList = getAppList(namespace);
Assert.assertTrue(appList.isEmpty());
// enable the capability
CapabilityConfig config = getTestConfig(oldArtifactVersion);
writeConfigAsFile(externalConfigPath, config.getCapability(), config);
capabilityManagementService.runTask();
// app should show up and program should have run
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// 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);
String capability = config.getCapability();
capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
// disable capability. Program should stop, status should be disabled and app should still be present.
CapabilityConfig disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), 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) {
// expected
}
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
String newArtifactVersion = "2.0.0";
// deploy the new artifact.
deployTestArtifact(namespace, appName, newArtifactVersion, appClass);
// enable the capability again.
config = getTestConfig(newArtifactVersion);
writeConfigAsFile(externalConfigPath, config.getCapability(), config);
capabilityManagementService.runTask();
// app should show up with newer artifact and program should have run.
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// Verify that application is redeployed with newer artifact.
Assert.assertEquals(newArtifactVersion, appList.get(0).get("artifact").getAsJsonObject().get("version").getAsString());
// 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);
capability = config.getCapability();
capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
// disable capability again. Program should stop, status should be disabled and app should still be present.
disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), 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) {
// expected
}
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// delete capability. Program should stop, status should be disabled and app should still be present.
new File(externalConfigPath, disabledConfig.getCapability()).delete();
capabilityManagementService.runTask();
Assert.assertTrue(capabilityStatusStore.getConfigs(Collections.singleton(capability)).isEmpty());
appList = getAppList(namespace);
Assert.assertTrue(appList.isEmpty());
}
Aggregations