Search in sources :

Example 1 with Requirements

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)));
}
Also used : ArrayList(java.util.ArrayList) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) ReflectionSchemaGenerator(io.cdap.cdap.internal.io.ReflectionSchemaGenerator) PluginPropertyField(io.cdap.cdap.api.plugin.PluginPropertyField) Requirements(io.cdap.cdap.api.plugin.Requirements) ArtifactClasses(io.cdap.cdap.api.artifact.ArtifactClasses) Id(io.cdap.cdap.common.id.Id) PluginClass(io.cdap.cdap.api.plugin.PluginClass) File(java.io.File) Location(org.apache.twill.filesystem.Location) InspectionApp(io.cdap.cdap.internal.app.runtime.artifact.app.inspection.InspectionApp) Test(org.junit.Test)

Example 2 with Requirements

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;
}
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 3 with Requirements

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);
}
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 4 with 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());
}
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 5 with Requirements

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

Aggregations

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