use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ArtifactRepositoryTest method testGreatGrandparentsAreInvalid.
@Test
public void testGreatGrandparentsAreInvalid() throws Exception {
// create child artifact
io.cdap.cdap.proto.id.ArtifactId childId = NamespaceId.DEFAULT.artifact("child", "1.0.0");
Manifest manifest = createManifest(ManifestFields.EXPORT_PACKAGE, Plugin1.class.getPackage().getName());
File jarFile = createPluginJar(Plugin1.class, new File(tmpDir, "child-1.0.0.jar"), manifest);
// add the artifact
Set<ArtifactRange> parents = ImmutableSet.of(new ArtifactRange(APP_ARTIFACT_ID.getNamespace().getId(), APP_ARTIFACT_ID.getName(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
artifactRepository.addArtifact(Id.Artifact.fromEntityId(childId), jarFile, parents, null);
// create grandchild
io.cdap.cdap.proto.id.ArtifactId grandchildId = NamespaceId.DEFAULT.artifact("grandchild", "1.0.0");
manifest = createManifest(ManifestFields.EXPORT_PACKAGE, Plugin2.class.getPackage().getName());
jarFile = createPluginJar(Plugin2.class, new File(tmpDir, "grandchild-1.0.0.jar"), manifest);
parents = ImmutableSet.of(new ArtifactRange(childId.getNamespace(), childId.getArtifact(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
artifactRepository.addArtifact(Id.Artifact.fromEntityId(grandchildId), jarFile, parents, null);
// try and create great grandchild, should fail
io.cdap.cdap.proto.id.ArtifactId greatGrandchildId = NamespaceId.DEFAULT.artifact("greatgrandchild", "1.0.0");
manifest = createManifest(ManifestFields.EXPORT_PACKAGE, Plugin2.class.getPackage().getName());
jarFile = createPluginJar(Plugin2.class, new File(tmpDir, "greatgrandchild-1.0.0.jar"), manifest);
parents = ImmutableSet.of(new ArtifactRange(grandchildId.getNamespace(), grandchildId.getArtifact(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
try {
artifactRepository.addArtifact(Id.Artifact.fromEntityId(greatGrandchildId), jarFile, parents, null);
Assert.fail("Artifact repository is not supposed to allow great grandparents.");
} catch (InvalidArtifactException e) {
// expected
}
}
use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ArtifactRepositoryTest method testPluginMetadata.
@Test
public void testPluginMetadata() throws Exception {
// Create a plugin jar. It contains two plugins, TestPlugin and TestPlugin2 inside.
Id.Artifact artifact1Id = Id.Artifact.from(Id.Namespace.DEFAULT, "myPlugin", "1.0");
Manifest manifest = createManifest(ManifestFields.EXPORT_PACKAGE, TestPlugin.class.getPackage().getName());
File jarFile = createPluginJar(TestPlugin.class, new File(tmpDir, "myPlugin-1.0.jar"), manifest);
// Build up the plugin repository.
Set<ArtifactRange> parents = ImmutableSet.of(new ArtifactRange(APP_ARTIFACT_ID.getNamespace().getId(), APP_ARTIFACT_ID.getName(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
artifactRepository.addArtifact(artifact1Id, jarFile, parents, null);
PluginId testPlugin1 = new PluginId("default", "myPlugin", "1.0", "TestPlugin", "plugin");
Metadata expected = new Metadata(MetadataScope.SYSTEM, ImmutableSet.of("tag1", "tag2", "tag3"), ImmutableMap.of("k1", "v1", "k2", "v2"));
Assert.assertEquals(expected, metadataAdmin.getMetadata(testPlugin1.toMetadataEntity()));
PluginId testPlugin2 = new PluginId("default", "myPlugin", "1.0", "TestPlugin2", "plugin");
expected = new Metadata(MetadataScope.SYSTEM, ImmutableSet.of("test-tag1", "test-tag2", "test-tag3"), ImmutableMap.of("key1", "val1", "key2", "val2"));
Assert.assertEquals(expected, metadataAdmin.getMetadata(testPlugin2.toMetadataEntity()));
// test metadata is cleaned up when the artifact gets deleted
artifactRepository.deleteArtifact(artifact1Id);
Assert.assertEquals(Metadata.EMPTY, metadataAdmin.getMetadata(testPlugin1.toMetadataEntity()));
Assert.assertEquals(Metadata.EMPTY, metadataAdmin.getMetadata(testPlugin2.toMetadataEntity()));
}
use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class LocalApplicationManagerTest method testGoodPipeline.
/**
* Good pipeline with good tests.
*/
@Test
public void testGoodPipeline() throws Exception {
Location deployedJar = AppJarHelper.createDeploymentJar(lf, AllProgramsApp.class);
ArtifactId artifactId = new ArtifactId("app", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
ApplicationClass applicationClass = new ApplicationClass(AllProgramsApp.class.getName(), "", null);
AppDeploymentInfo info = new AppDeploymentInfo(Artifacts.toProtoArtifactId(NamespaceId.DEFAULT, artifactId), deployedJar, NamespaceId.DEFAULT, applicationClass, null, null, null);
ApplicationWithPrograms input = AppFabricTestHelper.getLocalManager().deploy(info).get();
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
// Validate that all programs are being captured by the deployment pipeline
Map<ProgramType, Set<String>> programByTypes = new HashMap<>();
for (ProgramDescriptor desc : input.getPrograms()) {
ProgramId programId = desc.getProgramId();
programByTypes.computeIfAbsent(programId.getType(), k -> new HashSet<>()).add(programId.getProgram());
}
for (io.cdap.cdap.api.app.ProgramType programType : io.cdap.cdap.api.app.ProgramType.values()) {
Assert.assertEquals(appSpec.getProgramsByType(programType), programByTypes.getOrDefault(ProgramType.valueOf(programType.name()), Collections.emptySet()));
}
}
use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class LocalApplicationManagerTest method testDeployCustomDatasetModule.
@Test
public void testDeployCustomDatasetModule() throws Exception {
Location deployedJar = AppJarHelper.createDeploymentJar(lf, AppWithCustomDatasetModule.class);
ArtifactId artifactId = new ArtifactId("customDSModule", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
ApplicationClass applicationClass = new ApplicationClass(AppWithCustomDatasetModule.class.getName(), "", null);
AppDeploymentInfo info = new AppDeploymentInfo(Artifacts.toProtoArtifactId(NamespaceId.DEFAULT, artifactId), deployedJar, NamespaceId.DEFAULT, applicationClass, "CustomDSApp", null, null);
try {
AppFabricTestHelper.getLocalManager().deploy(info).get();
if (!allowCustomDatasetModule) {
Assert.fail("Expected to throw IllegalArgumentException when custom dataset module is not supported");
}
} catch (ExecutionException e) {
// There shouldn't be any exception if custom dataset module is allowed
if (allowCustomDatasetModule) {
throw e;
}
if (!(e.getCause() instanceof IllegalStateException)) {
throw e;
}
}
}
use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ArtifactRangeTest method testIsInRange.
@Test
public void testIsInRange() {
ArtifactRange range = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "test", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0"));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("0.0.9")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("0.9.0")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("0.9")));
// 1 < 1.0 < 1.0.0-SNAPSHOT < 1.0.0
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("1")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("1.0")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("1.0.0-SNAPSHOT")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("1.0.0")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("1.0.1-SNAPSHOT")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("1.0.1")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("1.1.0")));
// 2 < 2.0 < 2.0.0-SNAPSHOT < 2.0.0
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("2")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("2.0")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("2.0.0-SNAPSHOT")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("2.0.0")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("2.0.1")));
}
Aggregations