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));
}
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));
}
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);
}
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());
}
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());
}
Aggregations