Search in sources :

Example 16 with ArtifactVersion

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
    }
}
Also used : Plugin2(io.cdap.cdap.internal.app.runtime.artifact.plugin.Plugin2) TestPlugin2(io.cdap.cdap.internal.app.plugins.test.TestPlugin2) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) Manifest(java.util.jar.Manifest) File(java.io.File) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) Test(org.junit.Test)

Example 17 with ArtifactVersion

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()));
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) Metadata(io.cdap.cdap.spi.metadata.Metadata) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) PluginId(io.cdap.cdap.proto.id.PluginId) Id(io.cdap.cdap.common.id.Id) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) Manifest(java.util.jar.Manifest) PluginId(io.cdap.cdap.proto.id.PluginId) File(java.io.File) Test(org.junit.Test)

Example 18 with ArtifactVersion

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()));
    }
}
Also used : Manifest(java.util.jar.Manifest) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Location(org.apache.twill.filesystem.Location) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) RunWith(org.junit.runner.RunWith) AppWithCustomDatasetModule(io.cdap.cdap.AppWithCustomDatasetModule) HashMap(java.util.HashMap) ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) ProgramType(io.cdap.cdap.proto.ProgramType) HashSet(java.util.HashSet) JarEntry(java.util.jar.JarEntry) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) AppFabricTestHelper(io.cdap.cdap.internal.AppFabricTestHelper) Gson(com.google.gson.Gson) After(org.junit.After) Map(java.util.Map) ConfigTestApp(io.cdap.cdap.ConfigTestApp) Locations(io.cdap.cdap.common.io.Locations) ClassRule(org.junit.ClassRule) JarOutputStream(java.util.jar.JarOutputStream) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) Artifacts(io.cdap.cdap.internal.app.runtime.artifact.Artifacts) Collection(java.util.Collection) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramId(io.cdap.cdap.proto.id.ProgramId) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) Test(org.junit.Test) LocationFactory(org.apache.twill.filesystem.LocationFactory) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) Constants(io.cdap.cdap.common.conf.Constants) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Assert(org.junit.Assert) Collections(java.util.Collections) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) TemporaryFolder(org.junit.rules.TemporaryFolder) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) HashSet(java.util.HashSet) Set(java.util.Set) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HashMap(java.util.HashMap) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ProgramId(io.cdap.cdap.proto.id.ProgramId) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) ProgramType(io.cdap.cdap.proto.ProgramType) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) Location(org.apache.twill.filesystem.Location) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with ArtifactVersion

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;
        }
    }
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) AppWithCustomDatasetModule(io.cdap.cdap.AppWithCustomDatasetModule) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) ExecutionException(java.util.concurrent.ExecutionException) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 20 with ArtifactVersion

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")));
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) Test(org.junit.Test)

Aggregations

ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)67 Test (org.junit.Test)47 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)38 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)30 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)28 Id (io.cdap.cdap.common.id.Id)22 PluginClass (io.cdap.cdap.api.plugin.PluginClass)19 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)19 File (java.io.File)18 Manifest (java.util.jar.Manifest)13 Set (java.util.Set)11 Location (org.apache.twill.filesystem.Location)11 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)10 HashSet (java.util.HashSet)10 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)8 PluginNotExistsException (io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException)8 Gson (com.google.gson.Gson)7 ArtifactVersionRange (io.cdap.cdap.api.artifact.ArtifactVersionRange)7