use of io.cdap.cdap.CapabilityAppWithWorkflow in project cdap by caskdata.
the class CapabilityManagementServiceTest method testApplicationDeployment.
@Test
public void testApplicationDeployment() throws Exception {
String externalConfigPath = tmpFolder.newFolder("capability-config-app").getAbsolutePath();
cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
capabilityManagementService.runTask();
String testVersion = "1.0.0";
// Deploy application with capability
Class<CapabilityAppWithWorkflow> appWithWorkflowClass = CapabilityAppWithWorkflow.class;
Requirements declaredAnnotation = appWithWorkflowClass.getDeclaredAnnotation(Requirements.class);
// verify this app has capabilities
Assert.assertTrue(declaredAnnotation.capabilities().length > 0);
try {
capabilityStatusStore.checkAllEnabled(Arrays.asList(declaredAnnotation.capabilities()));
Assert.fail("expecting exception");
} catch (CapabilityNotAvailableException ex) {
}
String appNameWithCapability = appWithWorkflowClass.getSimpleName() + UUID.randomUUID();
deployTestArtifact(Id.Namespace.DEFAULT.getId(), appNameWithCapability, testVersion, appWithWorkflowClass);
try {
// deploy app
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, appNameWithCapability, testVersion);
applicationLifecycleService.deployApp(NamespaceId.DEFAULT, appNameWithCapability, testVersion, artifactId, null, programId -> {
});
Assert.fail("Expecting exception");
} catch (CapabilityNotAvailableException ex) {
// expected
}
// Deploy application without capability
Class<WorkflowAppWithFork> appNoCapabilityClass = WorkflowAppWithFork.class;
Requirements declaredAnnotation1 = appNoCapabilityClass.getDeclaredAnnotation(Requirements.class);
// verify this app has no capabilities
Assert.assertNull(declaredAnnotation1);
String appNameWithOutCapability = appWithWorkflowClass.getSimpleName() + UUID.randomUUID();
deployArtifactAndApp(appNoCapabilityClass, appNameWithOutCapability, testVersion);
// enable the capabilities
List<CapabilityConfig> capabilityConfigs = Arrays.stream(declaredAnnotation.capabilities()).map(capability -> new CapabilityConfig("Test capability", CapabilityStatus.ENABLED, capability, Collections.emptyList(), Collections.emptyList(), Collections.emptyList())).collect(Collectors.toList());
for (CapabilityConfig capabilityConfig : capabilityConfigs) {
writeConfigAsFile(externalConfigPath, capabilityConfig.getCapability(), capabilityConfig);
}
capabilityManagementService.runTask();
// deployment should go through now
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, appNameWithCapability, testVersion);
applicationLifecycleService.deployApp(NamespaceId.DEFAULT, appNameWithCapability, testVersion, artifactId, null, programId -> {
});
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithCapability, testVersion));
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithOutCapability, testVersion));
artifactRepository.deleteArtifact(Id.Artifact.from(new Id.Namespace(NamespaceId.DEFAULT.getNamespace()), appNameWithCapability, testVersion));
artifactRepository.deleteArtifact(Id.Artifact.from(new Id.Namespace(NamespaceId.DEFAULT.getNamespace()), appNameWithOutCapability, testVersion));
for (CapabilityConfig capabilityConfig : capabilityConfigs) {
new File(externalConfigPath, capabilityConfig.getCapability()).delete();
}
capabilityManagementService.runTask();
}
use of io.cdap.cdap.CapabilityAppWithWorkflow in project cdap by caskdata.
the class CapabilityApplierTest method testGetAppsWithCapability.
@Test
public void testGetAppsWithCapability() throws Exception {
// Deploy application with capability
Class<CapabilityAppWithWorkflow> appWithWorkflowClass = CapabilityAppWithWorkflow.class;
Requirements declaredAnnotation = appWithWorkflowClass.getDeclaredAnnotation(Requirements.class);
// verify this app has capabilities
Assert.assertTrue(declaredAnnotation.capabilities().length > 0);
String appNameWithCapabilities = appWithWorkflowClass.getSimpleName() + UUID.randomUUID();
for (String capability : declaredAnnotation.capabilities()) {
CapabilityConfig capabilityConfig = new CapabilityConfig("Enable", CapabilityStatus.ENABLED, capability, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
capabilityWriter.addOrUpdateCapability(capability, CapabilityStatus.ENABLED, capabilityConfig);
}
deployArtifactAndApp(appWithWorkflowClass, appNameWithCapabilities);
// Deploy application without capability
Class<WorkflowAppWithFork> appNoCapabilityClass = WorkflowAppWithFork.class;
Requirements declaredAnnotation1 = appNoCapabilityClass.getDeclaredAnnotation(Requirements.class);
// verify this app has no capabilities
Assert.assertNull(declaredAnnotation1);
String appNameWithoutCapability = appNoCapabilityClass.getSimpleName() + UUID.randomUUID();
deployArtifactAndApp(appNoCapabilityClass, appNameWithoutCapability);
// verify that list applications return the application tagged with capability only
for (String capability : declaredAnnotation.capabilities()) {
EntityResult<ApplicationId> appsForCapability = capabilityApplier.getApplications(NamespaceId.DEFAULT, capability, null, 0, 10);
Set<ApplicationId> applicationIds = new HashSet<>(appsForCapability.getEntities());
List<ApplicationDetail> appsReturned = new ArrayList<>(applicationLifecycleService.getAppDetails(applicationIds).values());
appsReturned.forEach(applicationDetail -> Assert.assertEquals(appNameWithCapabilities, applicationDetail.getArtifact().getName()));
}
// delete the app and verify nothing is returned.
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithCapabilities, TEST_VERSION));
for (String capability : declaredAnnotation.capabilities()) {
Set<ApplicationId> applicationIds = new HashSet<>(capabilityApplier.getApplications(NamespaceId.DEFAULT, capability, null, 0, 10).getEntities());
List<ApplicationDetail> appsReturned = new ArrayList<>(applicationLifecycleService.getAppDetails(applicationIds).values());
Assert.assertTrue(appsReturned.isEmpty());
}
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithoutCapability, TEST_VERSION));
artifactRepository.deleteArtifact(Id.Artifact.from(new Id.Namespace(NamespaceId.DEFAULT.getNamespace()), appNameWithoutCapability, TEST_VERSION));
for (String capability : declaredAnnotation.capabilities()) {
capabilityWriter.deleteCapability(capability);
}
}
use of io.cdap.cdap.CapabilityAppWithWorkflow in project cdap by caskdata.
the class ApplicationLifecycleServiceTest method testCapabilityMetaDataDeletion.
@Test
public void testCapabilityMetaDataDeletion() throws Exception {
Class<CapabilityAppWithWorkflow> appWithWorkflowClass = CapabilityAppWithWorkflow.class;
Requirements declaredAnnotation = appWithWorkflowClass.getDeclaredAnnotation(Requirements.class);
Set<String> expected = Arrays.stream(declaredAnnotation.capabilities()).collect(Collectors.toSet());
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, appWithWorkflowClass.getSimpleName(), "1.0.0-SNAPSHOT");
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, appWithWorkflowClass);
File appJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", artifactId.getName(), artifactId.getVersion().getVersion()));
Locations.linkOrCopyOverwrite(appJar, appJarFile);
appJar.delete();
// deploy app
try {
applicationLifecycleService.deployAppAndArtifact(NamespaceId.DEFAULT, appWithWorkflowClass.getSimpleName(), artifactId, appJarFile, null, null, programId -> {
}, true);
Assert.fail("Expecting exception");
} catch (CapabilityNotAvailableException ex) {
// expected
}
for (String capability : declaredAnnotation.capabilities()) {
CapabilityConfig capabilityConfig = new CapabilityConfig("Test", CapabilityStatus.ENABLED, capability, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
capabilityWriter.addOrUpdateCapability(capability, CapabilityStatus.ENABLED, capabilityConfig);
}
applicationLifecycleService.deployAppAndArtifact(NamespaceId.DEFAULT, appWithWorkflowClass.getSimpleName(), artifactId, appJarFile, null, null, programId -> {
}, true);
// Check for the capability metadata
ApplicationId appId = NamespaceId.DEFAULT.app(appWithWorkflowClass.getSimpleName());
MetadataEntity appMetadataId = appId.toMetadataEntity();
Assert.assertFalse(metadataStorage.read(new Read(appMetadataId, MetadataScope.SYSTEM, MetadataKind.PROPERTY)).isEmpty());
Map<String, String> metadataProperties = metadataStorage.read(new Read(appMetadataId)).getProperties(MetadataScope.SYSTEM);
String capabilityMetaData = metadataProperties.get(AppSystemMetadataWriter.CAPABILITY_TAG);
Set<String> actual = Arrays.stream(capabilityMetaData.split(AppSystemMetadataWriter.CAPABILITY_DELIMITER)).collect(Collectors.toSet());
Assert.assertEquals(expected, actual);
// Remove the application and verify that all metadata is removed
applicationLifecycleService.removeApplication(appId);
Assert.assertTrue(metadataStorage.read(new Read(appMetadataId)).isEmpty());
}
use of io.cdap.cdap.CapabilityAppWithWorkflow in project cdap by caskdata.
the class SystemMetadataWriterStageTest method testCapabilityTags.
@Test
public void testCapabilityTags() throws Exception {
String appName = CapabilityAppWithWorkflow.class.getSimpleName();
ApplicationId appId = NamespaceId.DEFAULT.app(appName);
String[] capabilityTestNames = { "cdc", "healthcare" };
Requirements requirements = new Requirements(Collections.emptySet(), Stream.of(capabilityTestNames).collect(Collectors.toSet()));
ApplicationClass applicationClass = new ApplicationClass(CapabilityAppWithWorkflow.class.getName(), appName, null, requirements);
String workflowName = CapabilityAppWithWorkflow.SampleWorkflow.class.getSimpleName();
ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0");
ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName, new CapabilityAppWithWorkflow(), applicationClass);
WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName);
MetadataWriterStage systemMetadataWriterStage = new MetadataWriterStage(metadataServiceClient);
StageContext stageContext = new StageContext(Object.class);
systemMetadataWriterStage.process(stageContext);
systemMetadataWriterStage.process(appWithPrograms);
Assert.assertEquals(false, metadataStorage.read(new Read(appId.toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.PROPERTY)).isEmpty());
// Test that all test capabilities are present in the metadata
Map<String, String> metadataProperties = metadataStorage.read(new Read(appId.toMetadataEntity())).getProperties(MetadataScope.SYSTEM);
Set<String> capabilityNames = Arrays.stream(metadataProperties.get(AppSystemMetadataWriter.CAPABILITY_TAG).split(AppSystemMetadataWriter.CAPABILITY_DELIMITER)).collect(Collectors.toSet());
Assert.assertEquals(Arrays.stream(capabilityTestNames).collect(Collectors.toSet()), capabilityNames);
}
use of io.cdap.cdap.CapabilityAppWithWorkflow in project cdap by caskdata.
the class CapabilityApplierTest method testGetAppsForCapabilityPagination.
@Test
public void testGetAppsForCapabilityPagination() throws Exception {
// Deploy two applications with capability
Class<CapabilityAppWithWorkflow> appWithWorkflowClass = CapabilityAppWithWorkflow.class;
Requirements declaredAnnotation = appWithWorkflowClass.getDeclaredAnnotation(Requirements.class);
// verify this app has capabilities
Assert.assertTrue(declaredAnnotation.capabilities().length > 0);
String appNameWithCapability1 = appWithWorkflowClass.getSimpleName() + UUID.randomUUID();
for (String capability : declaredAnnotation.capabilities()) {
capabilityWriter.addOrUpdateCapability(capability, CapabilityStatus.ENABLED, new CapabilityConfig("Enable", CapabilityStatus.ENABLED, appNameWithCapability1, Collections.emptyList(), Collections.emptyList(), Collections.emptyList()));
}
deployArtifactAndApp(appWithWorkflowClass, appNameWithCapability1);
String appNameWithCapability2 = appWithWorkflowClass.getSimpleName() + UUID.randomUUID();
deployArtifactAndApp(appWithWorkflowClass, appNameWithCapability2);
// search with offset and limit
String capability = declaredAnnotation.capabilities()[0];
EntityResult<ApplicationId> appsForCapability = capabilityApplier.getApplications(NamespaceId.DEFAULT, capability, null, 0, 1);
Assert.assertEquals(1, appsForCapability.getEntities().size());
// next search with pagination
EntityResult<ApplicationId> appsForCapabilityNext = capabilityApplier.getApplications(NamespaceId.DEFAULT, capability, appsForCapability.getCursor(), 1, 1);
Assert.assertEquals(1, appsForCapabilityNext.getEntities().size());
appsForCapabilityNext = capabilityApplier.getApplications(NamespaceId.DEFAULT, capability, appsForCapability.getCursor(), 2, 1);
Assert.assertEquals(0, appsForCapabilityNext.getEntities().size());
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithCapability1, TEST_VERSION));
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithCapability2, TEST_VERSION));
artifactRepository.deleteArtifact(Id.Artifact.from(new Id.Namespace(NamespaceId.DEFAULT.getNamespace()), appNameWithCapability1, TEST_VERSION));
artifactRepository.deleteArtifact(Id.Artifact.from(new Id.Namespace(NamespaceId.DEFAULT.getNamespace()), appNameWithCapability2, TEST_VERSION));
for (String capability1 : declaredAnnotation.capabilities()) {
capabilityWriter.deleteCapability(capability1);
}
}
Aggregations