use of io.cdap.cdap.api.plugin.Requirements in project cdap by caskdata.
the class DefaultArtifactInspectorTest method inspectAppsAndPlugins.
@Test
public void inspectAppsAndPlugins() throws Exception {
File appFile = getAppFile();
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "InspectionApp", "1.0.0");
Location artifactLocation = Locations.toLocation(appFile);
List<ArtifactDescriptor> parentDescriptor = new ArrayList<>();
parentDescriptor.add(new ArtifactDescriptor(artifactId.getNamespace().getId(), artifactId.toArtifactId(), artifactLocation));
ArtifactClasses classes = artifactInspector.inspectArtifact(artifactId, appFile, parentDescriptor, Collections.emptySet()).getArtifactClasses();
// check app classes
Set<ApplicationClass> expectedApps = ImmutableSet.of(new ApplicationClass(InspectionApp.class.getName(), "", new ReflectionSchemaGenerator(false).generate(InspectionApp.AConfig.class), new Requirements(Collections.emptySet(), Collections.singleton("cdc"))));
Assert.assertEquals(expectedApps, classes.getApps());
// check plugin classes
PluginClass expectedPlugin = PluginClass.builder().setName(InspectionApp.PLUGIN_NAME).setType(InspectionApp.PLUGIN_TYPE).setDescription(InspectionApp.PLUGIN_DESCRIPTION).setClassName(InspectionApp.AppPlugin.class.getName()).setConfigFieldName("pluginConf").setProperties(ImmutableMap.of("y", new PluginPropertyField("y", "", "double", true, true), "isSomething", new PluginPropertyField("isSomething", "", "boolean", true, false))).build();
PluginClass multipleRequirementPlugin = PluginClass.builder().setName(InspectionApp.MULTIPLE_REQUIREMENTS_PLUGIN).setType(InspectionApp.PLUGIN_TYPE).setCategory(InspectionApp.PLUGIN_CATEGORY).setClassName(InspectionApp.MultipleRequirementsPlugin.class.getName()).setConfigFieldName("pluginConf").setProperties(ImmutableMap.of("y", new PluginPropertyField("y", "", "double", true, true), "isSomething", new PluginPropertyField("isSomething", "", "boolean", true, false))).setRequirements(new Requirements(ImmutableSet.of(Table.TYPE, KeyValueTable.TYPE))).setDescription(InspectionApp.PLUGIN_DESCRIPTION).build();
Assert.assertTrue(classes.getPlugins().containsAll(ImmutableSet.of(expectedPlugin, multipleRequirementPlugin)));
}
use of io.cdap.cdap.api.plugin.Requirements in project cdap by caskdata.
the class ProvisioningService method getUnfulfilledRequirements.
/**
* Checks if the given provisioner fulfills all the requirements of a program.
*
* @param provisionerFulfilledRequirements {@link Requirements} containing requirements fulfilled by the provisioner
* @param requirements a {@link Set} of {@link PluginRequirement}
*
* @return {@link Set} {@link PluginRequirement} which consists of plugin identifier and the requirements which
* are not meet
*/
@VisibleForTesting
Set<PluginRequirement> getUnfulfilledRequirements(Capabilities provisionerFulfilledRequirements, Set<PluginRequirement> requirements) {
// create a map of plugin name to unfulfilled requirement if there are any
Set<PluginRequirement> unfulfilledRequirements = new HashSet<>();
Set<String> capabilities = provisionerFulfilledRequirements.getDatasetTypes().stream().map(String::toLowerCase).collect(Collectors.toSet());
for (PluginRequirement pluginRequirement : requirements) {
Requirements requisites = pluginRequirement.getRequirements();
Sets.SetView<String> unfulfilledRequirement = Sets.difference(requisites.getDatasetTypes(), capabilities);
if (!unfulfilledRequirement.isEmpty()) {
unfulfilledRequirements.add(new PluginRequirement(pluginRequirement.getName(), pluginRequirement.getType(), new Requirements(unfulfilledRequirement.immutableCopy())));
}
}
return unfulfilledRequirements;
}
use of io.cdap.cdap.api.plugin.Requirements in project cdap by caskdata.
the class ProvisioningServiceTest method testUnfulfilledRequirements.
@Test
public void testUnfulfilledRequirements() {
Capabilities provisionerCapabilities = new Capabilities(ImmutableSet.of(Table.TYPE));
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"))));
Set<PluginRequirement> expectedUnfulfilledRequirements = ImmutableSet.of(new PluginRequirement("source1", "batchsource", new Requirements(ImmutableSet.of("unicorn"))), new PluginRequirement("sink1", "batchsink", new Requirements(ImmutableSet.of("dragon"))));
assertRequirementFulfillment(provisionerCapabilities, requirements, expectedUnfulfilledRequirements);
// check when there are multiple plugins with same name but different type
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"))));
expectedUnfulfilledRequirements = ImmutableSet.of(new PluginRequirement("source1", "batchsource", new Requirements(ImmutableSet.of("unicorn"))), new PluginRequirement("sink1", "batchsink", new Requirements(ImmutableSet.of("dragon"))), new PluginRequirement("sink1", "anothersink", new Requirements(ImmutableSet.of("narwhal"))));
assertRequirementFulfillment(provisionerCapabilities, requirements, expectedUnfulfilledRequirements);
// check when provisioner does not have any specified capability
provisionerCapabilities = Capabilities.EMPTY;
assertRequirementFulfillment(provisionerCapabilities, requirements, requirements);
}
use of io.cdap.cdap.api.plugin.Requirements in project cdap by caskdata.
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());
}
use of io.cdap.cdap.api.plugin.Requirements 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);
}
Aggregations