use of io.cdap.cdap.api.plugin.Requirements 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.api.plugin.Requirements in project cdap by cdapio.
the class ApplicationClassCodec method deserialize.
@Override
public ApplicationClass deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
Schema configSchema = getConfigSchema(jsonObject, context);
Requirements requirements = getRequirements(jsonObject, context);
return new ApplicationClass(getStringValue(jsonObject, CLASS_NAME), getStringValue(jsonObject, DESCRIPTION), configSchema, requirements);
}
use of io.cdap.cdap.api.plugin.Requirements in project cdap by cdapio.
the class ArtifactStoreTest method testExcludedPlugins.
@Test
public void testExcludedPlugins() throws Exception {
ArtifactRange parentArtifacts = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "parent", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0"));
// does not have any requirement
PluginClass includedPlugin1 = PluginClass.builder().setName("includedPlugin1").setType("A").setDescription("desc").setClassName("c.p2").setConfigFieldName("conf").setProperties(ImmutableMap.of("stream", new PluginPropertyField("stream", "description", "string", true, false))).build();
PluginClass excludedPlugin1 = PluginClass.builder().setName("excludedPlugin1").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(Table.TYPE))).build();
PluginClass excludedPlugin2 = PluginClass.builder().setName("excludedPlugin2").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(KeyValueTable.TYPE))).build();
PluginClass excludedPlugin3 = PluginClass.builder().setName("excludedPlugin3").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(Table.TYPE, KeyValueTable.TYPE))).build();
PluginClass excludedPlugin4 = PluginClass.builder().setName("excludedPlugin4").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(Table.TYPE, KeyValueTable.TYPE, Cube.TYPE))).build();
PluginClass excludedPlugin5 = PluginClass.builder().setName("excludedPlugin5").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(Table.TYPE, Cube.TYPE))).build();
PluginClass includedPlugin2 = PluginClass.builder().setName("includedPlugin2").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of("noTransactionNeeded"))).build();
PluginClass includedPlugin3 = PluginClass.builder().setName("includedPlugin3").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of("noTransactionNeeded", "tpfs"))).build();
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "ArtifactWithTransactionalPlugins", "1.0.0");
ArtifactMeta artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addPlugins(includedPlugin1, includedPlugin2, includedPlugin3, excludedPlugin1, excludedPlugin2, excludedPlugin3, excludedPlugin4, excludedPlugin5).build(), ImmutableSet.of(parentArtifacts));
writeArtifact(artifactId, artifactMeta, "no-content");
ArtifactDescriptor artifactInfo = artifactStore.getArtifact(artifactId).getDescriptor();
// plugins which have transaction or spark as requirement should be excluded from plugins listed for the artifact
Map<ArtifactDescriptor, Set<PluginClass>> actual = artifactStore.getPluginClasses(NamespaceId.DEFAULT, artifactId);
Set<PluginClass> expectedPlugins = ImmutableSet.of(includedPlugin1, includedPlugin2, includedPlugin3);
Assert.assertEquals(ImmutableMap.of(artifactInfo, expectedPlugins), actual);
// excluded plugins should also not be in the plugins listed for the namespace
List<ArtifactDetail> actualArtifacts = artifactStore.getArtifacts(NamespaceId.DEFAULT);
Assert.assertEquals(1, actualArtifacts.size());
Assert.assertEquals(expectedPlugins, actualArtifacts.get(0).getMeta().getClasses().getPlugins());
// excluded plugins should also not be in the plugins listed for the artifact id
ArtifactDetail actualArtifact = artifactStore.getArtifact(artifactId);
Assert.assertEquals(expectedPlugins, actualArtifact.getMeta().getClasses().getPlugins());
}
use of io.cdap.cdap.api.plugin.Requirements in project cdap by caskdata.
the class ArtifactStoreTest method testExcludedPlugins.
@Test
public void testExcludedPlugins() throws Exception {
ArtifactRange parentArtifacts = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "parent", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0"));
// does not have any requirement
PluginClass includedPlugin1 = PluginClass.builder().setName("includedPlugin1").setType("A").setDescription("desc").setClassName("c.p2").setConfigFieldName("conf").setProperties(ImmutableMap.of("stream", new PluginPropertyField("stream", "description", "string", true, false))).build();
PluginClass excludedPlugin1 = PluginClass.builder().setName("excludedPlugin1").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(Table.TYPE))).build();
PluginClass excludedPlugin2 = PluginClass.builder().setName("excludedPlugin2").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(KeyValueTable.TYPE))).build();
PluginClass excludedPlugin3 = PluginClass.builder().setName("excludedPlugin3").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(Table.TYPE, KeyValueTable.TYPE))).build();
PluginClass excludedPlugin4 = PluginClass.builder().setName("excludedPlugin4").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(Table.TYPE, KeyValueTable.TYPE, Cube.TYPE))).build();
PluginClass excludedPlugin5 = PluginClass.builder().setName("excludedPlugin5").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of(Table.TYPE, Cube.TYPE))).build();
PluginClass includedPlugin2 = PluginClass.builder().setName("includedPlugin2").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of("noTransactionNeeded"))).build();
PluginClass includedPlugin3 = PluginClass.builder().setName("includedPlugin3").setType("A").setDescription("desc").setClassName("c.p1").setConfigFieldName("cfg").setProperties(ImmutableMap.of("threshold", new PluginPropertyField("thresh", "description", "double", true, false), "retry", new PluginPropertyField("retries", "description", "int", false, false))).setRequirements(new Requirements(ImmutableSet.of("noTransactionNeeded", "tpfs"))).build();
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "ArtifactWithTransactionalPlugins", "1.0.0");
ArtifactMeta artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addPlugins(includedPlugin1, includedPlugin2, includedPlugin3, excludedPlugin1, excludedPlugin2, excludedPlugin3, excludedPlugin4, excludedPlugin5).build(), ImmutableSet.of(parentArtifacts));
writeArtifact(artifactId, artifactMeta, "no-content");
ArtifactDescriptor artifactInfo = artifactStore.getArtifact(artifactId).getDescriptor();
// plugins which have transaction or spark as requirement should be excluded from plugins listed for the artifact
Map<ArtifactDescriptor, Set<PluginClass>> actual = artifactStore.getPluginClasses(NamespaceId.DEFAULT, artifactId);
Set<PluginClass> expectedPlugins = ImmutableSet.of(includedPlugin1, includedPlugin2, includedPlugin3);
Assert.assertEquals(ImmutableMap.of(artifactInfo, expectedPlugins), actual);
// excluded plugins should also not be in the plugins listed for the namespace
List<ArtifactDetail> actualArtifacts = artifactStore.getArtifacts(NamespaceId.DEFAULT);
Assert.assertEquals(1, actualArtifacts.size());
Assert.assertEquals(expectedPlugins, actualArtifacts.get(0).getMeta().getClasses().getPlugins());
// excluded plugins should also not be in the plugins listed for the artifact id
ArtifactDetail actualArtifact = artifactStore.getArtifact(artifactId);
Assert.assertEquals(expectedPlugins, actualArtifact.getMeta().getClasses().getPlugins());
}
use of io.cdap.cdap.api.plugin.Requirements in project cdap by caskdata.
the class RequirementsCodecTest method testCodec.
@Test
public void testCodec() throws IOException {
String test1 = getData("Requirements_Pre_6_3.json");
Gson gsonWithoutCodec = new Gson();
Requirements requirements = gsonWithoutCodec.fromJson(test1, Requirements.class);
// Will be null without codec
Assert.assertNull(requirements.getCapabilities());
Gson gson = new GsonBuilder().registerTypeAdapter(Requirements.class, new RequirementsCodec()).create();
requirements = gson.fromJson(test1, Requirements.class);
// not null with codec
Assert.assertNotNull(requirements.getCapabilities());
Assert.assertEquals(Arrays.stream(new String[] { "d1", "d2" }).collect(Collectors.toSet()), requirements.getDatasetTypes());
String test2 = getData("Requirements_6_3.json");
requirements = gson.fromJson(test2, Requirements.class);
// Verify serialize and deserialize works as expected
Assert.assertEquals(Arrays.stream(new String[] { "c1", "c2" }).collect(Collectors.toSet()), requirements.getCapabilities());
Assert.assertEquals(Arrays.stream(new String[] { "d1", "d2" }).collect(Collectors.toSet()), requirements.getDatasetTypes());
Assert.assertEquals(requirements, gson.fromJson(gson.toJson(requirements, Requirements.class), Requirements.class));
String test3 = getData("PluginClass_Pre_6_3.json");
PluginClass pluginClass = gson.fromJson(test3, PluginClass.class);
Assert.assertNotNull(pluginClass.getRequirements().getCapabilities());
}
Aggregations