use of io.cdap.cdap.internal.capability.CapabilityConfig 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.internal.capability.CapabilityConfig in project cdap by caskdata.
the class TestBase method copyConfigFile.
private static void copyConfigFile(String capability) throws IOException {
String capabilityFileName = String.format("%s.json", capability);
if (TestBase.class.getClassLoader().getResource(capabilityFileName) == null) {
// create a basic file to enable
File capabilityFile = new File(cConf.get(Constants.Capability.CONFIG_DIR), String.format("%s.json", capability));
CapabilityConfig capabilityConfig = new CapabilityConfig("Enable", CapabilityStatus.ENABLED, capability, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
String content = new Gson().toJson(capabilityConfig);
try (FileWriter writer = new FileWriter(capabilityFile)) {
writer.write(content);
}
return;
}
copyTempFile(capabilityFileName, new File(cConf.get(Constants.Capability.CONFIG_DIR)));
}
Aggregations