Search in sources :

Example 26 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ArtifactClientTestRun method setUp.

@Before
public void setUp() throws Throwable {
    super.setUp();
    artifactClient = new ArtifactClient(clientConfig, new RESTClient(clientConfig));
    for (ArtifactSummary artifactSummary : artifactClient.list(NamespaceId.DEFAULT)) {
        artifactClient.delete(NamespaceId.DEFAULT.artifact(artifactSummary.getName(), artifactSummary.getVersion()));
    }
}
Also used : RESTClient(co.cask.cdap.client.util.RESTClient) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) Before(org.junit.Before)

Example 27 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ArtifactClientTestRun method testArtifacts.

@Test
public void testArtifacts() throws Exception {
    // add 2 versions of an artifact with an application
    ArtifactId myapp1Id = NamespaceId.DEFAULT.artifact("myapp", "1.0.0");
    ArtifactId myapp2Id = NamespaceId.DEFAULT.artifact("myapp", "2.0.0");
    LocalLocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(ManifestFields.BUNDLE_VERSION, "2.0.0");
    final Location appJarLoc = AppJarHelper.createDeploymentJar(locationFactory, MyApp.class, manifest);
    InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() {

        @Override
        public InputStream getInput() throws IOException {
            return appJarLoc.getInputStream();
        }
    };
    artifactClient.add(myapp1Id.getParent(), myapp1Id.getArtifact(), inputSupplier, myapp1Id.getVersion());
    // add some properties
    Map<String, String> myapp1Properties = ImmutableMap.of("k1", "v1");
    artifactClient.writeProperties(myapp1Id, myapp1Properties);
    // let it derive version from jar manifest, which has bundle-version at 2.0.0
    artifactClient.add(myapp2Id.getParent(), myapp2Id.getArtifact(), inputSupplier, null, null);
    // add some properties
    Map<String, String> myapp2Properties = ImmutableMap.of("k1", "v1", "k2", "v2");
    artifactClient.writeProperties(myapp2Id, myapp2Properties);
    // add an artifact that contains a plugin, but only extends myapp-2.0.0
    ArtifactId pluginId = NamespaceId.DEFAULT.artifact("myapp-plugins", "2.0.0");
    manifest = new Manifest();
    manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, Plugin1.class.getPackage().getName());
    final Location pluginJarLoc = PluginJarHelper.createPluginJar(locationFactory, manifest, Plugin1.class);
    inputSupplier = new InputSupplier<InputStream>() {

        @Override
        public InputStream getInput() throws IOException {
            return pluginJarLoc.getInputStream();
        }
    };
    Set<ArtifactRange> parents = Sets.newHashSet(new ArtifactRange(myapp2Id.getParent().getNamespace(), myapp2Id.getArtifact(), new ArtifactVersion(myapp2Id.getVersion()), new ArtifactVersion("3.0.0")));
    Set<PluginClass> additionalPlugins = Sets.newHashSet(new PluginClass("jdbc", "mysql", "", "com.mysql.jdbc.Driver", null, Collections.<String, PluginPropertyField>emptyMap()));
    artifactClient.add(pluginId.getParent(), pluginId.getArtifact(), inputSupplier, pluginId.getVersion(), parents, additionalPlugins);
    ArtifactSummary myapp1Summary = new ArtifactSummary(myapp1Id.getArtifact(), myapp1Id.getVersion());
    ArtifactSummary myapp2Summary = new ArtifactSummary(myapp2Id.getArtifact(), myapp2Id.getVersion());
    ArtifactSummary pluginArtifactSummary = new ArtifactSummary(pluginId.getArtifact(), pluginId.getVersion());
    Set<ArtifactSummary> artifacts = Sets.newHashSet(artifactClient.list(NamespaceId.DEFAULT));
    Assert.assertEquals(Sets.newHashSet(myapp1Summary, myapp2Summary, pluginArtifactSummary), artifacts);
    // list all artifacts named 'myapp'
    Assert.assertEquals(Sets.newHashSet(myapp1Summary, myapp2Summary), Sets.newHashSet(artifactClient.listVersions(NamespaceId.DEFAULT, myapp1Id.getArtifact())));
    // list all artifacts named 'myapp-plugins'
    Assert.assertEquals(Sets.newHashSet(pluginArtifactSummary), Sets.newHashSet(artifactClient.listVersions(NamespaceId.DEFAULT, pluginId.getArtifact())));
    // artifacts should be in user scope
    try {
        artifactClient.listVersions(NamespaceId.DEFAULT, pluginId.getArtifact(), ArtifactScope.SYSTEM);
        Assert.fail();
    } catch (ArtifactNotFoundException e) {
    // expected
    }
    // get info about specific artifacts
    Schema myAppConfigSchema = new ReflectionSchemaGenerator(false).generate(MyApp.Conf.class);
    ArtifactClasses myAppClasses = ArtifactClasses.builder().addApp(new ApplicationClass(MyApp.class.getName(), "", myAppConfigSchema)).build();
    // test get myapp-1.0.0
    ArtifactInfo myapp1Info = new ArtifactInfo(myapp1Id.getArtifact(), myapp1Id.getVersion(), ArtifactScope.USER, myAppClasses, myapp1Properties);
    Assert.assertEquals(myapp1Info, artifactClient.getArtifactInfo(myapp1Id));
    // test get myapp-2.0.0
    ArtifactInfo myapp2Info = new ArtifactInfo(myapp2Id.getArtifact(), myapp2Id.getVersion(), ArtifactScope.USER, myAppClasses, myapp2Properties);
    Assert.assertEquals(myapp2Info, artifactClient.getArtifactInfo(myapp2Id));
    // test overwriting properties
    myapp2Properties = ImmutableMap.of("k1", "v3", "k5", "v5");
    artifactClient.writeProperties(myapp2Id, myapp2Properties);
    Assert.assertEquals(myapp2Properties, artifactClient.getArtifactInfo(myapp2Id).getProperties());
    // test deleting property
    artifactClient.deleteProperty(myapp2Id, "k1");
    Assert.assertEquals(ImmutableMap.of("k5", "v5"), artifactClient.getArtifactInfo(myapp2Id).getProperties());
    // test writing property
    artifactClient.writeProperty(myapp2Id, "k5", "v4");
    Assert.assertEquals(ImmutableMap.of("k5", "v4"), artifactClient.getArtifactInfo(myapp2Id).getProperties());
    // test deleting properties
    artifactClient.deleteProperties(myapp2Id);
    Assert.assertTrue(artifactClient.getArtifactInfo(myapp2Id).getProperties().isEmpty());
    // test get myapp-plugins-2.0.0
    Map<String, PluginPropertyField> props = ImmutableMap.of("x", new PluginPropertyField("x", "", "int", true, false));
    ArtifactClasses pluginClasses = ArtifactClasses.builder().addPlugin(new PluginClass("callable", "plugin1", "p1 description", Plugin1.class.getName(), "conf", props)).addPlugins(additionalPlugins).build();
    ArtifactInfo pluginArtifactInfo = new ArtifactInfo(pluginId.getArtifact(), pluginId.getVersion(), ArtifactScope.USER, pluginClasses, ImmutableMap.<String, String>of());
    Assert.assertEquals(pluginArtifactInfo, artifactClient.getArtifactInfo(pluginId));
    // test get all app classes in namespace
    Set<ApplicationClassSummary> expectedSummaries = ImmutableSet.of(new ApplicationClassSummary(myapp1Summary, MyApp.class.getName()), new ApplicationClassSummary(myapp2Summary, MyApp.class.getName()));
    Set<ApplicationClassSummary> appClassSummaries = Sets.newHashSet(artifactClient.getApplicationClasses(NamespaceId.DEFAULT));
    Assert.assertEquals(expectedSummaries, appClassSummaries);
    // test get all app classes in namespace with name MyApp.class.getName()
    Set<ApplicationClassInfo> appClassInfos = Sets.newHashSet(artifactClient.getApplicationClasses(NamespaceId.DEFAULT, MyApp.class.getName()));
    Set<ApplicationClassInfo> expectedInfos = ImmutableSet.of(new ApplicationClassInfo(myapp1Summary, MyApp.class.getName(), myAppConfigSchema), new ApplicationClassInfo(myapp2Summary, MyApp.class.getName(), myAppConfigSchema));
    Assert.assertEquals(expectedInfos, appClassInfos);
    // test get plugin types for myapp-1.0.0. should be empty, since plugins only extends versions [2.0.0 - 3.0.0)
    Assert.assertTrue(artifactClient.getPluginTypes(myapp1Id).isEmpty());
    // test get plugin types for myapp-2.0.0
    Assert.assertEquals(Lists.newArrayList("callable", "jdbc"), artifactClient.getPluginTypes(myapp2Id));
    // test get plugins of type callable for myapp-2.0.0
    PluginSummary pluginSummary = new PluginSummary("plugin1", "callable", "p1 description", Plugin1.class.getName(), pluginArtifactSummary);
    Assert.assertEquals(Sets.newHashSet(pluginSummary), Sets.newHashSet(artifactClient.getPluginSummaries(myapp2Id, "callable")));
    // no plugins of type "runnable"
    Assert.assertTrue(artifactClient.getPluginSummaries(myapp2Id, "runnable").isEmpty());
    // test get plugin details for plugin1 for myapp-2.0.0
    PluginInfo pluginInfo = new PluginInfo("plugin1", "callable", "p1 description", Plugin1.class.getName(), pluginArtifactSummary, props, new HashSet<String>());
    Assert.assertEquals(Sets.newHashSet(pluginInfo), Sets.newHashSet(artifactClient.getPluginInfo(myapp2Id, "callable", "plugin1")));
}
Also used : MyApp(co.cask.cdap.client.artifact.MyApp) ArtifactId(co.cask.cdap.proto.id.ArtifactId) Schema(co.cask.cdap.api.data.schema.Schema) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) PluginPropertyField(co.cask.cdap.api.plugin.PluginPropertyField) ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactClasses(co.cask.cdap.api.artifact.ArtifactClasses) ApplicationClassInfo(co.cask.cdap.proto.artifact.ApplicationClassInfo) PluginInfo(co.cask.cdap.proto.artifact.PluginInfo) PluginSummary(co.cask.cdap.proto.artifact.PluginSummary) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) InputSupplier(com.google.common.io.InputSupplier) Plugin1(co.cask.cdap.client.artifact.plugin.Plugin1) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ApplicationClass(co.cask.cdap.api.artifact.ApplicationClass) IOException(java.io.IOException) ApplicationClassSummary(co.cask.cdap.proto.artifact.ApplicationClassSummary) Manifest(java.util.jar.Manifest) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactInfo(co.cask.cdap.api.artifact.ArtifactInfo) PluginClass(co.cask.cdap.api.plugin.PluginClass) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 28 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ApplicationClientTestRun method testArtifactFilter.

@Test
public void testArtifactFilter() throws Exception {
    ApplicationId appId1 = NamespaceId.DEFAULT.app(FakeApp.NAME);
    ApplicationId appId2 = NamespaceId.DEFAULT.app("fake2");
    ApplicationId appId3 = NamespaceId.DEFAULT.app("fake3");
    try {
        // app1 should use fake-1.0.0-SNAPSHOT
        appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "otherfake", "1.0.0-SNAPSHOT"));
        appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "fake", "0.1.0-SNAPSHOT"));
        // app1 should end up with fake-1.0.0-SNAPSHOT
        appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "fake", "1.0.0-SNAPSHOT"));
        // app2 should use fake-0.1.0-SNAPSHOT
        appClient.deploy(appId2, new AppRequest<Config>(new ArtifactSummary("fake", "0.1.0-SNAPSHOT")));
        // app3 should use otherfake-1.0.0-SNAPSHOT
        appClient.deploy(appId3, new AppRequest<Config>(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT")));
        appClient.waitForDeployed(appId1, 30, TimeUnit.SECONDS);
        appClient.waitForDeployed(appId2, 30, TimeUnit.SECONDS);
        appClient.waitForDeployed(appId3, 30, TimeUnit.SECONDS);
        // check calls that should return nothing
        // these don't match anything
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "ghost", null).isEmpty());
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, (String) null, "1.0.0").isEmpty());
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "ghost", "1.0.0").isEmpty());
        // these match one but not the other
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "otherfake", "0.1.0-SNAPSHOT").isEmpty());
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "fake", "1.0.0").isEmpty());
        // check filter by name only
        Set<ApplicationRecord> apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "fake", null));
        Set<ApplicationRecord> expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
        Assert.assertEquals(expected, apps);
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "otherfake", null));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""));
        Assert.assertEquals(expected, apps);
        // check filter by multiple names
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, ImmutableSet.of("fake", "otherfake"), null));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""), new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
        Assert.assertEquals(expected, apps);
        // check filter by version only
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, (String) null, "0.1.0-SNAPSHOT"));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
        Assert.assertEquals(expected, apps);
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, (String) null, "1.0.0-SNAPSHOT"));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""));
        Assert.assertEquals(expected, apps);
        // check filter by both
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "fake", "0.1.0-SNAPSHOT"));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
        Assert.assertEquals(expected, apps);
    } finally {
        appClient.deleteAll(NamespaceId.DEFAULT);
        appClient.waitForDeleted(appId1, 30, TimeUnit.SECONDS);
        appClient.waitForDeleted(appId2, 30, TimeUnit.SECONDS);
        appClient.waitForDeleted(appId3, 30, TimeUnit.SECONDS);
        Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
    }
}
Also used : FakeApp(co.cask.cdap.client.app.FakeApp) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) Config(co.cask.cdap.api.Config) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord) Test(org.junit.Test)

Example 29 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ApplicationClientTestRun method testAll.

@Test
public void testAll() throws Exception {
    ApplicationId app = NamespaceId.DEFAULT.app(FakeApp.NAME);
    Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
    // deploy app
    LOG.info("Deploying app");
    appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, FakeApp.NAME, "1.0.0-SNAPSHOT"));
    appClient.waitForDeployed(app, 30, TimeUnit.SECONDS);
    Assert.assertEquals(1, appClient.list(NamespaceId.DEFAULT).size());
    try {
        // check program list
        LOG.info("Checking program list for app");
        Map<ProgramType, List<ProgramRecord>> programs = appClient.listProgramsByType(app);
        verifyProgramNames(FakeApp.FLOWS, programs.get(ProgramType.FLOW));
        verifyProgramNames(FakeApp.MAPREDUCES, programs.get(ProgramType.MAPREDUCE));
        verifyProgramNames(FakeApp.WORKFLOWS, programs.get(ProgramType.WORKFLOW));
        verifyProgramNames(FakeApp.SERVICES, programs.get(ProgramType.SERVICE));
        verifyProgramNames(FakeApp.FLOWS, appClient.listPrograms(app, ProgramType.FLOW));
        verifyProgramNames(FakeApp.MAPREDUCES, appClient.listPrograms(app, ProgramType.MAPREDUCE));
        verifyProgramNames(FakeApp.WORKFLOWS, appClient.listPrograms(app, ProgramType.WORKFLOW));
        verifyProgramNames(FakeApp.SERVICES, appClient.listPrograms(app, ProgramType.SERVICE));
        verifyProgramNames(FakeApp.FLOWS, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.FLOW));
        verifyProgramNames(FakeApp.MAPREDUCES, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.MAPREDUCE));
        verifyProgramNames(FakeApp.WORKFLOWS, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.WORKFLOW));
        verifyProgramNames(FakeApp.SERVICES, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.SERVICE));
        verifyProgramRecords(FakeApp.ALL_PROGRAMS, appClient.listAllPrograms(NamespaceId.DEFAULT));
        ApplicationDetail appDetail = appClient.get(app);
        ArtifactSummary expected = new ArtifactSummary(FakeApp.NAME, "1.0.0-SNAPSHOT");
        Assert.assertEquals(expected, appDetail.getArtifact());
    } finally {
        // delete app
        LOG.info("Deleting app");
        appClient.delete(app);
        appClient.waitForDeleted(app, 30, TimeUnit.SECONDS);
        Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
    }
}
Also used : FakeApp(co.cask.cdap.client.app.FakeApp) ApplicationDetail(co.cask.cdap.proto.ApplicationDetail) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) List(java.util.List) ProgramType(co.cask.cdap.proto.ProgramType) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 30 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class MetadataHttpHandlerTestRun method before.

@Before
public void before() throws Exception {
    addAppArtifact(artifactId, AppWithDataset.class);
    AppRequest<Config> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()));
    appClient.deploy(application, appRequest);
    FormatSpecification format = new FormatSpecification("csv", null, null);
    ViewSpecification viewSpec = new ViewSpecification(format, null);
    streamViewClient.createOrUpdate(myview, viewSpec);
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) Config(co.cask.cdap.api.Config) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) ViewSpecification(co.cask.cdap.proto.ViewSpecification) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Before(org.junit.Before)

Aggregations

ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)59 Test (org.junit.Test)34 ApplicationId (co.cask.cdap.proto.id.ApplicationId)31 AppRequest (co.cask.cdap.proto.artifact.AppRequest)28 Id (co.cask.cdap.proto.Id)21 NamespaceId (co.cask.cdap.proto.id.NamespaceId)21 ArtifactId (co.cask.cdap.proto.id.ArtifactId)18 ProgramId (co.cask.cdap.proto.id.ProgramId)13 IOException (java.io.IOException)10 ApplicationManager (co.cask.cdap.test.ApplicationManager)9 HashMap (java.util.HashMap)8 StreamId (co.cask.cdap.proto.id.StreamId)7 HashSet (java.util.HashSet)7 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)6 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)6 PluginInfo (co.cask.cdap.proto.artifact.PluginInfo)6 JsonObject (com.google.gson.JsonObject)6 File (java.io.File)6 URL (java.net.URL)6 NotFoundException (co.cask.cdap.common.NotFoundException)5