use of io.cdap.cdap.api.artifact.ArtifactRange in project cdap by caskdata.
the class ArtifactRangeTest method testVersionParse.
@Test
public void testVersionParse() throws InvalidArtifactRangeException {
ArtifactRange expected = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "test", new ArtifactVersion("1.0.0"), true, new ArtifactVersion("2.0.0-SNAPSHOT"), false);
ArtifactRange actual = ArtifactRanges.parseArtifactRange(NamespaceId.DEFAULT.getNamespace(), "test[1.0.0,2.0.0-SNAPSHOT)");
Assert.assertEquals(expected, actual);
expected = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "test", new ArtifactVersion("0.1.0-SNAPSHOT"), false, new ArtifactVersion("1.0.0"), true);
actual = ArtifactRanges.parseArtifactRange(NamespaceId.DEFAULT.getNamespace(), "test(0.1.0-SNAPSHOT,1.0.0]");
Assert.assertEquals(expected, actual);
// test compatible with toString
Assert.assertEquals(expected, ArtifactRanges.parseArtifactRange(expected.toString()));
}
use of io.cdap.cdap.api.artifact.ArtifactRange in project cdap by caskdata.
the class ArtifactStoreTest method testGetNonexistantArtifact.
@Test
public void testGetNonexistantArtifact() throws IOException {
NamespaceId namespace = Ids.namespace("ns1");
// no artifacts in a namespace should return an empty collection
Assert.assertTrue(artifactStore.getArtifacts(namespace).isEmpty());
// no artifacts in range should return an empty collection
ArtifactRange range = new ArtifactRange(namespace.getNamespace(), "something", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0"));
Assert.assertTrue(artifactStore.getArtifacts(range, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED).isEmpty());
// no artifact by namespace and artifact name should throw an exception
try {
artifactStore.getArtifacts(namespace, "something", Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.fail();
} catch (ArtifactNotFoundException e) {
// expected
}
// no artifact by namespace, artifact name, and version should throw an exception
try {
artifactStore.getArtifact(Id.Artifact.from(Id.Namespace.fromEntityId(namespace), "something", "1.0.0"));
Assert.fail();
} catch (ArtifactNotFoundException e) {
// expected
}
}
use of io.cdap.cdap.api.artifact.ArtifactRange in project cdap by caskdata.
the class ArtifactStoreTest method testPluginParentVersions.
// this test tests that when an artifact specifies a range of artifact versions it extends,
// those versions are honored
@Test
public void testPluginParentVersions() throws Exception {
// write an artifact that extends parent-[1.0.0, 2.0.0)
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "plugins", "0.1.0");
Set<ArtifactRange> parentArtifacts = ImmutableSet.of(new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "parent", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
Set<PluginClass> plugins = ImmutableSet.of(PluginClass.builder().setName("plugin1").setType("atype").setDescription("").setClassName("c.c.c.plugin1").setConfigFieldName("cfg").setProperties(ImmutableMap.of()).build());
ArtifactMeta meta = new ArtifactMeta(ArtifactClasses.builder().addPlugins(plugins).build(), parentArtifacts);
writeArtifact(artifactId, meta, "some contents");
ArtifactDescriptor artifactInfo = artifactStore.getArtifact(artifactId).getDescriptor();
// check ids that are out of range. They should not return anything
List<Id.Artifact> badIds = Lists.newArrayList(// ids that are too low
Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "0.9.9"), Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "1.0.0-SNAPSHOT"), // ids that are too high
Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "2.0.0"));
ArtifactMeta emptyMeta = new ArtifactMeta(ArtifactClasses.builder().build());
for (Id.Artifact badId : badIds) {
// write the parent artifact to make sure we don't get ArtifactNotFound exceptions with later calls
// we're testing range filtering, not the absence of the parent artifact
writeArtifact(badId, emptyMeta, "content");
Assert.assertTrue(artifactStore.getPluginClasses(NamespaceId.DEFAULT, badId).isEmpty());
Assert.assertTrue(artifactStore.getPluginClasses(NamespaceId.DEFAULT, badId, "atype").isEmpty());
try {
artifactStore.getPluginClasses(NamespaceId.DEFAULT, badId, "atype", "plugin1", null, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.fail();
} catch (PluginNotExistsException e) {
// expected
}
}
// check ids that are in range return what we expect
List<Id.Artifact> goodIds = Lists.newArrayList(// ids that are too low
Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "1.0.0"), // ids that are too high
Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "1.9.9"), Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "1.99.999"), Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "2.0.0-SNAPSHOT"));
Map<ArtifactDescriptor, Set<PluginClass>> expectedPluginsMapList = ImmutableMap.of(artifactInfo, plugins);
Map<ArtifactDescriptor, PluginClass> expectedPluginsMap = ImmutableMap.of(artifactInfo, plugins.iterator().next());
for (Id.Artifact goodId : goodIds) {
// make sure parent actually exists
writeArtifact(goodId, emptyMeta, "content");
Assert.assertEquals(expectedPluginsMapList, artifactStore.getPluginClasses(NamespaceId.DEFAULT, goodId));
Assert.assertEquals(expectedPluginsMapList, artifactStore.getPluginClasses(NamespaceId.DEFAULT, goodId, "atype"));
Assert.assertEquals(expectedPluginsMap, artifactStore.getPluginClasses(NamespaceId.DEFAULT, goodId, "atype", "plugin1", null, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED));
}
}
use of io.cdap.cdap.api.artifact.ArtifactRange in project cdap by caskdata.
the class ArtifactStoreTest method testGetArtifacts.
@Test
public void testGetArtifacts() throws Exception {
// add 1 version of another artifact1
Id.Artifact artifact1V1 = Id.Artifact.from(Id.Namespace.DEFAULT, "artifact1", "1.0.0");
String contents1V1 = "first contents v1";
PluginClass plugin1V1 = PluginClass.builder().setName("plugin1").setType("atype").setDescription("").setClassName("c.c.c.plugin1").setConfigFieldName("cfg").setProperties(ImmutableMap.of()).build();
ArtifactMeta meta1V1 = new ArtifactMeta(ArtifactClasses.builder().addPlugin(plugin1V1).build());
writeArtifact(artifact1V1, meta1V1, contents1V1);
// add 2 versions of an artifact2
Id.Artifact artifact2V1 = Id.Artifact.from(Id.Namespace.DEFAULT, "artifact2", "0.1.0");
Id.Artifact artifact2V2 = Id.Artifact.from(Id.Namespace.DEFAULT, "artifact2", "0.1.1");
Id.Artifact artifact2V3 = Id.Artifact.from(Id.Namespace.DEFAULT, "artifact2", "0.1.1-SNAPSHOT");
String contents2V1 = "second contents v1";
String contents2V2 = "second contents v2";
String contents2V3 = "second contents v3";
PluginClass plugin2V1 = PluginClass.builder().setName("plugin2").setType("atype").setDescription("").setClassName("c.c.c.plugin2").setConfigFieldName("cfg").setProperties(ImmutableMap.of()).build();
PluginClass plugin2V2 = PluginClass.builder().setName("plugin2").setType("atype").setDescription("").setClassName("c.c.c.plugin2").setConfigFieldName("cfg").setProperties(ImmutableMap.of()).build();
PluginClass plugin2V3 = PluginClass.builder().setName("plugin2").setType("atype").setDescription("").setClassName("c.c.c.plugin2").setConfigFieldName("cfg").setProperties(ImmutableMap.of()).build();
ArtifactMeta meta2V1 = new ArtifactMeta(ArtifactClasses.builder().addPlugin(plugin2V1).build());
ArtifactMeta meta2V2 = new ArtifactMeta(ArtifactClasses.builder().addPlugin(plugin2V2).build());
ArtifactMeta meta2V3 = new ArtifactMeta(ArtifactClasses.builder().addPlugin(plugin2V3).build());
writeArtifact(artifact2V1, meta2V1, contents2V1);
writeArtifact(artifact2V2, meta2V2, contents2V2);
writeArtifact(artifact2V3, meta2V3, contents2V3);
// test we get 1 version of artifact1 and 2 versions of artifact2
List<ArtifactDetail> artifact1Versions = artifactStore.getArtifacts(artifact1V1.getNamespace().toEntityId(), artifact1V1.getName(), Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(1, artifact1Versions.size());
assertEqual(artifact1V1, meta1V1, contents1V1, artifact1Versions.get(0));
List<ArtifactDetail> artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifact2Versions.get(0));
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(1));
assertEqual(artifact2V3, meta2V3, contents2V3, artifact2Versions.get(2));
// test get 2 versions of artifact 2
artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), 2, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(2, artifact2Versions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifact2Versions.get(0));
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(1));
// test get sorted version of artifact 2
artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), 3, ArtifactSortOrder.DESC);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifact2Versions.get(1));
assertEqual(artifact2V1, meta2V1, contents2V1, artifact2Versions.get(2));
// test get sorted and limited version of artifact 2
artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), 2, ArtifactSortOrder.DESC);
Assert.assertEquals(2, artifact2Versions.size());
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifact2Versions.get(1));
artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), 3, ArtifactSortOrder.ASC);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifact2Versions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifact2Versions.get(1));
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(2));
// test we get all 3 in the getArtifactSummaries() call for the namespace
List<ArtifactDetail> artifactVersions = artifactStore.getArtifacts(NamespaceId.DEFAULT);
Assert.assertEquals(4, artifactVersions.size());
assertEqual(artifact1V1, meta1V1, contents1V1, artifactVersions.get(0));
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(1));
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(2));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(3));
// test get using a range
// this range should get everything
ArtifactRange range = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "artifact2", new ArtifactVersion("0.1.0"), new ArtifactVersion("0.1.2"));
artifactVersions = artifactStore.getArtifacts(range, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(3, artifactVersions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(0));
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(1));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(2));
// test get one version
artifactVersions = artifactStore.getArtifacts(range, 1, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(1, artifactVersions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(0));
// test get sorted versions
artifactVersions = artifactStore.getArtifacts(range, 3, ArtifactSortOrder.DESC);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(1));
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(2));
artifactVersions = artifactStore.getArtifacts(range, 3, ArtifactSortOrder.ASC);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(1));
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(2));
// this range should get just v0.1.1
range = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "artifact2", new ArtifactVersion("0.1.1"), new ArtifactVersion("1.0.0"));
artifactVersions = artifactStore.getArtifacts(range, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(1, artifactVersions.size());
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(0));
// this range should get just v0.1.0 and v0.1.1-SNAPSHOT
range = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "artifact2", new ArtifactVersion("0.0.0"), new ArtifactVersion("0.1.1"));
artifactVersions = artifactStore.getArtifacts(range, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(2, artifactVersions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(1));
}
use of io.cdap.cdap.api.artifact.ArtifactRange 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());
}
Aggregations