use of io.cdap.cdap.internal.pipeline.PluginRequirement 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());
}
use of io.cdap.cdap.internal.pipeline.PluginRequirement in project cdap by cdapio.
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.internal.pipeline.PluginRequirement in project cdap by caskdata.
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.internal.pipeline.PluginRequirement in project cdap by caskdata.
the class ProvisioningService method groupByRequirement.
/**
* Aggregates the given {@link Set} of {@link PluginRequirement} on requirements.
*
* @param requirements the {@link PluginRequirement} which needs to be aggregated.
*
* @return a {@link Map} of requirement to {@link Set} of pluginType:pluginName
*/
@VisibleForTesting
Map<String, Set<String>> groupByRequirement(Set<PluginRequirement> requirements) {
Map<String, Set<String>> pluginsGroupedByRequirements = new HashMap<>();
for (PluginRequirement pluginRequirement : requirements) {
Set<String> reqs = pluginRequirement.getRequirements().getDatasetTypes();
for (String req : reqs) {
Set<String> currentRequirementPlugins = pluginsGroupedByRequirements.getOrDefault(req, new HashSet<>());
currentRequirementPlugins.add(pluginRequirement.getType() + ":" + pluginRequirement.getName());
pluginsGroupedByRequirements.put(req, currentRequirementPlugins);
}
}
return pluginsGroupedByRequirements;
}
use of io.cdap.cdap.internal.pipeline.PluginRequirement in project cdap by cdapio.
the class ProvisioningService method groupByRequirement.
/**
* Aggregates the given {@link Set} of {@link PluginRequirement} on requirements.
*
* @param requirements the {@link PluginRequirement} which needs to be aggregated.
*
* @return a {@link Map} of requirement to {@link Set} of pluginType:pluginName
*/
@VisibleForTesting
Map<String, Set<String>> groupByRequirement(Set<PluginRequirement> requirements) {
Map<String, Set<String>> pluginsGroupedByRequirements = new HashMap<>();
for (PluginRequirement pluginRequirement : requirements) {
Set<String> reqs = pluginRequirement.getRequirements().getDatasetTypes();
for (String req : reqs) {
Set<String> currentRequirementPlugins = pluginsGroupedByRequirements.getOrDefault(req, new HashSet<>());
currentRequirementPlugins.add(pluginRequirement.getType() + ":" + pluginRequirement.getName());
pluginsGroupedByRequirements.put(req, currentRequirementPlugins);
}
}
return pluginsGroupedByRequirements;
}
Aggregations