Search in sources :

Example 1 with PluginSummary

use of co.cask.cdap.proto.artifact.PluginSummary in project cdap by caskdata.

the class ArtifactHttpHandlerTest method testGetPlugins.

@Test
public void testGetPlugins() throws Exception {
    // add an app for plugins to extend
    Id.Artifact wordCount1Id = Id.Artifact.from(Id.Namespace.DEFAULT, "wordcount", "1.0.0");
    Assert.assertEquals(HttpResponseStatus.OK.getCode(), addAppArtifact(wordCount1Id, WordCountApp.class).getStatusLine().getStatusCode());
    Id.Artifact wordCount2Id = Id.Artifact.from(Id.Namespace.DEFAULT, "wordcount", "2.0.0");
    Assert.assertEquals(HttpResponseStatus.OK.getCode(), addAppArtifact(wordCount2Id, WordCountApp.class).getStatusLine().getStatusCode());
    // add some plugins.
    // plugins-1.0.0 extends wordcount[1.0.0,2.0.0)
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, Plugin1.class.getPackage().getName());
    Id.Artifact pluginsId1 = Id.Artifact.from(Id.Namespace.DEFAULT, "plugins", "1.0.0");
    Set<ArtifactRange> plugins1Parents = Sets.newHashSet(new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "wordcount", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
    Assert.assertEquals(HttpResponseStatus.OK.getCode(), addPluginArtifact(pluginsId1, Plugin1.class, manifest, plugins1Parents).getStatusLine().getStatusCode());
    // plugin-2.0.0 extends wordcount[1.0.0,3.0.0)
    Id.Artifact pluginsId2 = Id.Artifact.from(Id.Namespace.DEFAULT, "plugins", "2.0.0");
    Set<ArtifactRange> plugins2Parents = Sets.newHashSet(new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "wordcount", new ArtifactVersion("1.0.0"), new ArtifactVersion("3.0.0")));
    Assert.assertEquals(HttpResponseStatus.OK.getCode(), addPluginArtifact(pluginsId2, Plugin1.class, manifest, plugins2Parents).getStatusLine().getStatusCode());
    ArtifactSummary plugins1Artifact = new ArtifactSummary("plugins", "1.0.0");
    ArtifactSummary plugins2Artifact = new ArtifactSummary("plugins", "2.0.0");
    // get plugin types, should be the same for both
    Set<String> expectedTypes = Sets.newHashSet("dummy", "callable");
    Set<String> actualTypes = getPluginTypes(wordCount1Id);
    Assert.assertEquals(expectedTypes, actualTypes);
    actualTypes = getPluginTypes(wordCount2Id);
    Assert.assertEquals(expectedTypes, actualTypes);
    // get plugin summaries. wordcount1 should see plugins from both plugin artifacts
    Set<PluginSummary> expectedSummaries = Sets.newHashSet(new PluginSummary("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins1Artifact), new PluginSummary("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins2Artifact));
    Set<PluginSummary> actualSummaries = getPluginSummaries(wordCount1Id, "dummy");
    Assert.assertEquals(expectedSummaries, actualSummaries);
    expectedSummaries = Sets.newHashSet(new PluginSummary("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins1Artifact), new PluginSummary("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins2Artifact));
    actualSummaries = getPluginSummaries(wordCount1Id, "callable");
    Assert.assertEquals(expectedSummaries, actualSummaries);
    // wordcount2 should only see plugins from plugins2 artifact
    expectedSummaries = Sets.newHashSet(new PluginSummary("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins2Artifact));
    actualSummaries = getPluginSummaries(wordCount2Id, "dummy");
    Assert.assertEquals(expectedSummaries, actualSummaries);
    expectedSummaries = Sets.newHashSet(new PluginSummary("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins2Artifact));
    actualSummaries = getPluginSummaries(wordCount2Id, "callable");
    Assert.assertEquals(expectedSummaries, actualSummaries);
    // get plugin info. Again, wordcount1 should see plugins from both artifacts
    Map<String, PluginPropertyField> p1Properties = ImmutableMap.of("x", new PluginPropertyField("x", "", "int", true, false), "stuff", new PluginPropertyField("stuff", "", "string", true, true));
    Map<String, PluginPropertyField> p2Properties = ImmutableMap.of("v", new PluginPropertyField("v", "value to return when called", "int", true, false));
    Set<PluginInfo> expectedInfos = Sets.newHashSet(new PluginInfo("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins1Artifact, p1Properties, new HashSet<String>()), new PluginInfo("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins2Artifact, p1Properties, new HashSet<String>()));
    Assert.assertEquals(expectedInfos, getPluginInfos(wordCount1Id, "dummy", "Plugin1"));
    expectedInfos = Sets.newHashSet(new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins1Artifact, p2Properties, new HashSet<String>()), new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins2Artifact, p2Properties, new HashSet<String>()));
    Assert.assertEquals(expectedInfos, getPluginInfos(wordCount1Id, "callable", "Plugin2"));
    // while wordcount2 should only see plugins from plugins2 artifact
    expectedInfos = Sets.newHashSet(new PluginInfo("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins2Artifact, p1Properties, new HashSet<String>()));
    Assert.assertEquals(expectedInfos, getPluginInfos(wordCount2Id, "dummy", "Plugin1"));
    expectedInfos = Sets.newHashSet(new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins2Artifact, p2Properties, new HashSet<String>()));
    Assert.assertEquals(expectedInfos, getPluginInfos(wordCount2Id, "callable", "Plugin2"));
}
Also used : Plugin2(co.cask.cdap.internal.app.runtime.artifact.plugin.Plugin2) Plugin1(co.cask.cdap.internal.app.runtime.artifact.plugin.Plugin1) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) Manifest(java.util.jar.Manifest) PluginPropertyField(co.cask.cdap.api.plugin.PluginPropertyField) ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) WordCountApp(co.cask.cdap.WordCountApp) PluginInfo(co.cask.cdap.proto.artifact.PluginInfo) Id(co.cask.cdap.proto.Id) NamespaceId(co.cask.cdap.proto.id.NamespaceId) PluginSummary(co.cask.cdap.proto.artifact.PluginSummary) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with PluginSummary

use of co.cask.cdap.proto.artifact.PluginSummary in project cdap by caskdata.

the class ArtifactHttpHandlerTest method testPluginNamespaceIsolation.

@Test
public void testPluginNamespaceIsolation() throws Exception {
    // add a system artifact. currently can't do this through the rest api (by design)
    // so bypass it and use the repository directly
    Id.Artifact systemId = Id.Artifact.from(Id.Namespace.SYSTEM, "wordcount", "1.0.0");
    File systemArtifact = buildAppArtifact(WordCountApp.class, "wordcount-1.0.0.jar");
    artifactRepository.addArtifact(systemId, systemArtifact, Sets.<ArtifactRange>newHashSet());
    Set<ArtifactRange> parents = Sets.newHashSet(new ArtifactRange(systemId.getNamespace().getId(), systemId.getName(), systemId.getVersion(), true, systemId.getVersion(), true));
    Id.Namespace namespace1 = Id.Namespace.from("ns1");
    Id.Namespace namespace2 = Id.Namespace.from("ns2");
    createNamespace(namespace1.getId());
    createNamespace(namespace2.getId());
    try {
        // add some plugins in namespace1. Will contain Plugin1 and Plugin2
        Manifest manifest = new Manifest();
        manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, Plugin1.class.getPackage().getName());
        Id.Artifact pluginsId1 = Id.Artifact.from(namespace1, "plugins1", "1.0.0");
        Assert.assertEquals(HttpResponseStatus.OK.getCode(), addPluginArtifact(pluginsId1, Plugin1.class, manifest, parents).getStatusLine().getStatusCode());
        // add some plugins in namespace2. Will contain Plugin1 and Plugin2
        manifest = new Manifest();
        manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, Plugin1.class.getPackage().getName());
        Id.Artifact pluginsId2 = Id.Artifact.from(namespace2, "plugins2", "1.0.0");
        Assert.assertEquals(HttpResponseStatus.OK.getCode(), addPluginArtifact(pluginsId2, Plugin1.class, manifest, parents).getStatusLine().getStatusCode());
        ArtifactSummary artifact1 = new ArtifactSummary(pluginsId1.getName(), pluginsId1.getVersion().getVersion(), ArtifactScope.USER);
        ArtifactSummary artifact2 = new ArtifactSummary(pluginsId2.getName(), pluginsId2.getVersion().getVersion(), ArtifactScope.USER);
        PluginSummary summary1Namespace1 = new PluginSummary("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), artifact1);
        PluginSummary summary2Namespace1 = new PluginSummary("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), artifact1);
        PluginSummary summary1Namespace2 = new PluginSummary("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), artifact2);
        PluginSummary summary2Namespace2 = new PluginSummary("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), artifact2);
        PluginInfo info1Namespace1 = new PluginInfo("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), artifact1, ImmutableMap.of("x", new PluginPropertyField("x", "", "int", true, false), "stuff", new PluginPropertyField("stuff", "", "string", true, true)), new HashSet<String>());
        PluginInfo info2Namespace1 = new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), artifact1, ImmutableMap.of("v", new PluginPropertyField("v", "value to return when called", "int", true, false)), new HashSet<String>());
        PluginInfo info1Namespace2 = new PluginInfo("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), artifact2, ImmutableMap.of("x", new PluginPropertyField("x", "", "int", true, false), "stuff", new PluginPropertyField("stuff", "", "string", true, true)), new HashSet<String>());
        PluginInfo info2Namespace2 = new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), artifact2, ImmutableMap.of("v", new PluginPropertyField("v", "value to return when called", "int", true, false)), new HashSet<String>());
        Id.Artifact namespace1Artifact = Id.Artifact.from(namespace1, systemId.getName(), systemId.getVersion());
        Id.Artifact namespace2Artifact = Id.Artifact.from(namespace2, systemId.getName(), systemId.getVersion());
        // should see same types in both namespaces
        Assert.assertEquals(ImmutableSet.of("dummy", "callable"), getPluginTypes(namespace1Artifact, ArtifactScope.SYSTEM));
        Assert.assertEquals(ImmutableSet.of("dummy", "callable"), getPluginTypes(namespace2Artifact, ArtifactScope.SYSTEM));
        // should see that plugins in namespace1 come only from the namespace1 artifact
        Assert.assertEquals(ImmutableSet.of(summary1Namespace1), getPluginSummaries(namespace1Artifact, "dummy", ArtifactScope.SYSTEM));
        Assert.assertEquals(ImmutableSet.of(summary2Namespace1), getPluginSummaries(namespace1Artifact, "callable", ArtifactScope.SYSTEM));
        Assert.assertEquals(ImmutableSet.of(info1Namespace1), getPluginInfos(namespace1Artifact, "dummy", "Plugin1", ArtifactScope.SYSTEM));
        Assert.assertEquals(ImmutableSet.of(info2Namespace1), getPluginInfos(namespace1Artifact, "callable", "Plugin2", ArtifactScope.SYSTEM));
        // should see that plugins in namespace2 come only from the namespace2 artifact
        Assert.assertEquals(ImmutableSet.of(summary1Namespace2), getPluginSummaries(namespace2Artifact, "dummy", ArtifactScope.SYSTEM));
        Assert.assertEquals(ImmutableSet.of(summary2Namespace2), getPluginSummaries(namespace2Artifact, "callable", ArtifactScope.SYSTEM));
        Assert.assertEquals(ImmutableSet.of(info1Namespace2), getPluginInfos(namespace2Artifact, "dummy", "Plugin1", ArtifactScope.SYSTEM));
        Assert.assertEquals(ImmutableSet.of(info2Namespace2), getPluginInfos(namespace2Artifact, "callable", "Plugin2", ArtifactScope.SYSTEM));
    } finally {
        deleteNamespace("iso1");
        deleteNamespace("iso2");
    }
}
Also used : Plugin2(co.cask.cdap.internal.app.runtime.artifact.plugin.Plugin2) Plugin1(co.cask.cdap.internal.app.runtime.artifact.plugin.Plugin1) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) Manifest(java.util.jar.Manifest) PluginPropertyField(co.cask.cdap.api.plugin.PluginPropertyField) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) PluginInfo(co.cask.cdap.proto.artifact.PluginInfo) Id(co.cask.cdap.proto.Id) NamespaceId(co.cask.cdap.proto.id.NamespaceId) PluginSummary(co.cask.cdap.proto.artifact.PluginSummary) File(java.io.File) Test(org.junit.Test)

Example 3 with PluginSummary

use of co.cask.cdap.proto.artifact.PluginSummary 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 4 with PluginSummary

use of co.cask.cdap.proto.artifact.PluginSummary in project cdap by caskdata.

the class ListArtifactPluginsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
    String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
    ArtifactId artifactId = cliConfig.getCurrentNamespace().artifact(artifactName, artifactVersion);
    String pluginType = arguments.get(ArgumentName.PLUGIN_TYPE.toString());
    final List<PluginSummary> pluginSummaries;
    String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
    if (scopeStr == null) {
        pluginSummaries = artifactClient.getPluginSummaries(artifactId, pluginType);
    } else {
        pluginSummaries = artifactClient.getPluginSummaries(artifactId, pluginType, ArtifactScope.valueOf(scopeStr.toUpperCase()));
    }
    Table table = Table.builder().setHeader("type", "name", "classname", "description", "artifact").setRows(pluginSummaries, new RowMaker<PluginSummary>() {

        @Override
        public List<?> makeRow(PluginSummary object) {
            return Lists.newArrayList(object.getType(), object.getName(), object.getClassName(), object.getDescription(), object.getArtifact().toString());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) ArtifactId(co.cask.cdap.proto.id.ArtifactId) RowMaker(co.cask.cdap.cli.util.RowMaker) PluginSummary(co.cask.cdap.proto.artifact.PluginSummary)

Example 5 with PluginSummary

use of co.cask.cdap.proto.artifact.PluginSummary in project cdap by caskdata.

the class ArtifactHttpHandler method getArtifactPlugins.

@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/extensions/{plugin-type}")
public void getArtifactPlugins(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("plugin-type") String pluginType, @QueryParam("scope") @DefaultValue("user") String scope) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException {
    NamespaceId namespace = Ids.namespace(namespaceId);
    NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope);
    Id.Artifact artifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);
    try {
        SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = artifactRepository.getPlugins(namespace, artifactId, pluginType);
        List<PluginSummary> pluginSummaries = Lists.newArrayList();
        // flatten the map
        for (Map.Entry<ArtifactDescriptor, Set<PluginClass>> pluginsEntry : plugins.entrySet()) {
            ArtifactDescriptor pluginArtifact = pluginsEntry.getKey();
            ArtifactSummary pluginArtifactSummary = ArtifactSummary.from(pluginArtifact.getArtifactId());
            for (PluginClass pluginClass : pluginsEntry.getValue()) {
                pluginSummaries.add(new PluginSummary(pluginClass.getName(), pluginClass.getType(), pluginClass.getDescription(), pluginClass.getClassName(), pluginArtifactSummary));
            }
        }
        responder.sendJson(HttpResponseStatus.OK, pluginSummaries);
    } catch (IOException e) {
        LOG.error("Exception looking up plugins for artifact {}", artifactId, e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store.");
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) IOException(java.io.IOException) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactDescriptor(co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) ArtifactId(co.cask.cdap.proto.id.ArtifactId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) PluginSummary(co.cask.cdap.proto.artifact.PluginSummary) PluginClass(co.cask.cdap.api.plugin.PluginClass) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

PluginSummary (co.cask.cdap.proto.artifact.PluginSummary)6 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)4 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)3 PluginPropertyField (co.cask.cdap.api.plugin.PluginPropertyField)3 Id (co.cask.cdap.proto.Id)3 PluginInfo (co.cask.cdap.proto.artifact.PluginInfo)3 ArtifactId (co.cask.cdap.proto.id.ArtifactId)3 NamespaceId (co.cask.cdap.proto.id.NamespaceId)3 Manifest (java.util.jar.Manifest)3 Test (org.junit.Test)3 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)2 PluginClass (co.cask.cdap.api.plugin.PluginClass)2 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)2 Plugin1 (co.cask.cdap.internal.app.runtime.artifact.plugin.Plugin1)2 Plugin2 (co.cask.cdap.internal.app.runtime.artifact.plugin.Plugin2)2 IOException (java.io.IOException)2 WordCountApp (co.cask.cdap.WordCountApp)1 ApplicationClass (co.cask.cdap.api.artifact.ApplicationClass)1 ArtifactClasses (co.cask.cdap.api.artifact.ArtifactClasses)1 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)1