Search in sources :

Example 6 with PluginRequirement

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

Example 7 with PluginRequirement

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;
}
Also used : Sets(com.google.common.collect.Sets) PluginRequirement(io.cdap.cdap.internal.pipeline.PluginRequirement) Requirements(io.cdap.cdap.api.plugin.Requirements) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with PluginRequirement

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());
}
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 9 with PluginRequirement

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PluginRequirement(io.cdap.cdap.internal.pipeline.PluginRequirement) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with PluginRequirement

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PluginRequirement(io.cdap.cdap.internal.pipeline.PluginRequirement) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

PluginRequirement (io.cdap.cdap.internal.pipeline.PluginRequirement)12 Requirements (io.cdap.cdap.api.plugin.Requirements)8 Test (org.junit.Test)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Capabilities (io.cdap.cdap.runtime.spi.provisioner.Capabilities)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 ImmutableSet (com.google.common.collect.ImmutableSet)2 Sets (com.google.common.collect.Sets)2 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)2 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)2 Provisioner (io.cdap.cdap.runtime.spi.provisioner.Provisioner)2 HashMap (java.util.HashMap)2