Search in sources :

Example 6 with Requirements

use of io.cdap.cdap.api.plugin.Requirements in project cdap by caskdata.

the class ApplicationClassCodecTest method testCodec.

@Test
public void testCodec() throws IOException {
    Gson gson = new GsonBuilder().registerTypeAdapter(Schema.class, new SchemaTypeAdapter()).registerTypeAdapter(ApplicationClass.class, new ApplicationClassCodec()).create();
    String testApp1 = getData("ApplicationClass_6_2.json");
    ApplicationClass applicationClass62 = gson.fromJson(testApp1, ApplicationClass.class);
    Assert.assertEquals(Requirements.EMPTY, applicationClass62.getRequirements());
    Assert.assertEquals("io.cdap.cdap.internal.app.runtime.artifact.app.inspection.InspectionApp", applicationClass62.getClassName());
    Assert.assertEquals("", applicationClass62.getDescription());
    Assert.assertNotNull(applicationClass62.getConfigSchema());
    Assert.assertEquals(applicationClass62, gson.fromJson(gson.toJson(applicationClass62), ApplicationClass.class));
    String testApp2 = getData("ApplicationClass_6_3.json");
    ApplicationClass applicationClass63 = gson.fromJson(testApp2, ApplicationClass.class);
    Requirements requirements = applicationClass63.getRequirements();
    Assert.assertEquals(Collections.singleton("cdc"), requirements.getCapabilities());
    Assert.assertEquals(applicationClass63, gson.fromJson(gson.toJson(applicationClass63), ApplicationClass.class));
}
Also used : SchemaTypeAdapter(io.cdap.cdap.internal.io.SchemaTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) Requirements(io.cdap.cdap.api.plugin.Requirements) Test(org.junit.Test)

Example 7 with Requirements

use of io.cdap.cdap.api.plugin.Requirements in project cdap by cdapio.

the class ApplicationClassCodecTest method testCodec.

@Test
public void testCodec() throws IOException {
    Gson gson = new GsonBuilder().registerTypeAdapter(Schema.class, new SchemaTypeAdapter()).registerTypeAdapter(ApplicationClass.class, new ApplicationClassCodec()).create();
    String testApp1 = getData("ApplicationClass_6_2.json");
    ApplicationClass applicationClass62 = gson.fromJson(testApp1, ApplicationClass.class);
    Assert.assertEquals(Requirements.EMPTY, applicationClass62.getRequirements());
    Assert.assertEquals("io.cdap.cdap.internal.app.runtime.artifact.app.inspection.InspectionApp", applicationClass62.getClassName());
    Assert.assertEquals("", applicationClass62.getDescription());
    Assert.assertNotNull(applicationClass62.getConfigSchema());
    Assert.assertEquals(applicationClass62, gson.fromJson(gson.toJson(applicationClass62), ApplicationClass.class));
    String testApp2 = getData("ApplicationClass_6_3.json");
    ApplicationClass applicationClass63 = gson.fromJson(testApp2, ApplicationClass.class);
    Requirements requirements = applicationClass63.getRequirements();
    Assert.assertEquals(Collections.singleton("cdc"), requirements.getCapabilities());
    Assert.assertEquals(applicationClass63, gson.fromJson(gson.toJson(applicationClass63), ApplicationClass.class));
}
Also used : SchemaTypeAdapter(io.cdap.cdap.internal.io.SchemaTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) Requirements(io.cdap.cdap.api.plugin.Requirements) Test(org.junit.Test)

Example 8 with Requirements

use of io.cdap.cdap.api.plugin.Requirements in project cdap by cdapio.

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);
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) StageContext(io.cdap.cdap.internal.pipeline.StageContext) Requirements(io.cdap.cdap.api.plugin.Requirements) Read(io.cdap.cdap.spi.metadata.Read) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) CapabilityAppWithWorkflow(io.cdap.cdap.CapabilityAppWithWorkflow) Test(org.junit.Test)

Example 9 with Requirements

use of io.cdap.cdap.api.plugin.Requirements in project cdap by cdapio.

the class ProvisioningServiceTest method testFulfilledRequirements.

@Test
public void testFulfilledRequirements() {
    Capabilities provisionerCapabilities = new Capabilities(ImmutableSet.of(Table.TYPE));
    Set<PluginRequirement> requirements = ImmutableSet.of(new PluginRequirement("source1", "batchsource", new Requirements(Collections.emptySet())), new PluginRequirement("sink1", "batchsink", new Requirements(ImmutableSet.of(Table.TYPE))));
    // there should not be any incapability
    assertRequirementFulfillment(provisionerCapabilities, requirements, Collections.emptySet());
    provisionerCapabilities = new Capabilities(ImmutableSet.of(Table.TYPE));
    requirements = ImmutableSet.of(new PluginRequirement("source1", "batchsource", new Requirements(ImmutableSet.of(Table.TYPE))), new PluginRequirement("sink1", "batchsink", new Requirements(ImmutableSet.of(Table.TYPE))));
    // there should not be any incapability
    assertRequirementFulfillment(provisionerCapabilities, requirements, Collections.emptySet());
}
Also used : Capabilities(io.cdap.cdap.runtime.spi.provisioner.Capabilities) PluginRequirement(io.cdap.cdap.internal.pipeline.PluginRequirement) Requirements(io.cdap.cdap.api.plugin.Requirements) Test(org.junit.Test)

Example 10 with Requirements

use of io.cdap.cdap.api.plugin.Requirements in project cdap by cdapio.

the class ProvisioningServiceTest method testGroupByRequirement.

@Test
public void testGroupByRequirement() {
    Set<PluginRequirement> requirements = ImmutableSet.of(new PluginRequirement("source1", "batchsource", new Requirements(ImmutableSet.of(Table.TYPE, "unicorn"))), new PluginRequirement("sink1", "batchsink", new Requirements(ImmutableSet.of(Table.TYPE, "dragon"))), new PluginRequirement("sink1", "anothersink", new Requirements(ImmutableSet.of(Table.TYPE, "narwhal"))));
    Map<String, Set<String>> pluginGroupedByRequirement = provisioningService.groupByRequirement(requirements);
    Assert.assertEquals(4, pluginGroupedByRequirement.size());
    Assert.assertEquals(ImmutableSet.of("batchsource:source1", "batchsink:sink1", "anothersink:sink1"), pluginGroupedByRequirement.get(Table.TYPE));
    Assert.assertEquals(ImmutableSet.of("batchsource:source1"), pluginGroupedByRequirement.get("unicorn"));
    Assert.assertEquals(ImmutableSet.of("batchsink:sink1"), pluginGroupedByRequirement.get("dragon"));
    Assert.assertEquals(ImmutableSet.of("anothersink:sink1"), pluginGroupedByRequirement.get("narwhal"));
    // test empty
    pluginGroupedByRequirement = provisioningService.groupByRequirement(Collections.emptySet());
    Assert.assertTrue(pluginGroupedByRequirement.isEmpty());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PluginRequirement(io.cdap.cdap.internal.pipeline.PluginRequirement) Requirements(io.cdap.cdap.api.plugin.Requirements) Test(org.junit.Test)

Aggregations

Requirements (io.cdap.cdap.api.plugin.Requirements)22 Test (org.junit.Test)18 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)8 PluginRequirement (io.cdap.cdap.internal.pipeline.PluginRequirement)8 PluginClass (io.cdap.cdap.api.plugin.PluginClass)6 ImmutableSet (com.google.common.collect.ImmutableSet)4 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 PluginPropertyField (io.cdap.cdap.api.plugin.PluginPropertyField)4 Id (io.cdap.cdap.common.id.Id)4 InspectionApp (io.cdap.cdap.internal.app.runtime.artifact.app.inspection.InspectionApp)4 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)4 Capabilities (io.cdap.cdap.runtime.spi.provisioner.Capabilities)4 Set (java.util.Set)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Sets (com.google.common.collect.Sets)2 JsonObject (com.google.gson.JsonObject)2 CapabilityAppWithWorkflow (io.cdap.cdap.CapabilityAppWithWorkflow)2 ArtifactClasses (io.cdap.cdap.api.artifact.ArtifactClasses)2 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)2