use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class CapabilityManagementServiceTest method testCapabilityRefresh.
@Test
public void testCapabilityRefresh() throws Exception {
String externalConfigPath = tmpFolder.newFolder("capability-config-refresh").getAbsolutePath();
cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
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);
// check that app is not available
List<JsonObject> appList = getAppList(namespace);
Assert.assertTrue(appList.isEmpty());
// enable the capability
CapabilityConfig config = getTestConfig("1.0.0");
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());
// 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 ApplicationVerificationTest method testGoodApplication.
/**
* Good test
*/
@Test
public void testGoodApplication() {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create();
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
ApplicationVerification app = new ApplicationVerification();
VerifyResult result = app.verify(new ApplicationId("test", newSpec.getName()), newSpec);
Assert.assertSame(result.getMessage(), result.getStatus(), VerifyResult.Status.SUCCESS);
}
use of io.cdap.cdap.AllProgramsApp in project cdap by cdapio.
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 cdapio.
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 cdapio.
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