Search in sources :

Example 1 with CapabilityConfig

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());
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) CapabilityNotAvailableException(io.cdap.cdap.internal.capability.CapabilityNotAvailableException) CapabilityConfig(io.cdap.cdap.internal.capability.CapabilityConfig) Requirements(io.cdap.cdap.api.annotation.Requirements) Read(io.cdap.cdap.spi.metadata.Read) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ProgramId(io.cdap.cdap.proto.id.ProgramId) CapabilityAppWithWorkflow(io.cdap.cdap.CapabilityAppWithWorkflow) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) File(java.io.File) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 2 with CapabilityConfig

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)));
}
Also used : CapabilityConfig(io.cdap.cdap.internal.capability.CapabilityConfig) FileWriter(java.io.FileWriter) Gson(com.google.gson.Gson) File(java.io.File)

Aggregations

CapabilityConfig (io.cdap.cdap.internal.capability.CapabilityConfig)2 File (java.io.File)2 Gson (com.google.gson.Gson)1 CapabilityAppWithWorkflow (io.cdap.cdap.CapabilityAppWithWorkflow)1 Requirements (io.cdap.cdap.api.annotation.Requirements)1 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)1 Id (io.cdap.cdap.common.id.Id)1 CapabilityNotAvailableException (io.cdap.cdap.internal.capability.CapabilityNotAvailableException)1 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)1 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)1 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)1 ProgramId (io.cdap.cdap.proto.id.ProgramId)1 Read (io.cdap.cdap.spi.metadata.Read)1 FileWriter (java.io.FileWriter)1 Location (org.apache.twill.filesystem.Location)1 Test (org.junit.Test)1