Search in sources :

Example 31 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class ArtifactHttpHandlerInternalTest method testGetArtifactLocation.

@Test
public void testGetArtifactLocation() throws Exception {
    // Add a system artifact
    String systemArtfiactName = "sysApp";
    String systemArtifactVeresion = "1.0.0";
    ArtifactId systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, systemArtifactVeresion);
    addAppAsSystemArtifacts(systemArtifactId);
    String locationPath = getArtifactLocationPath(systemArtifactId);
    Assert.assertNotNull(locationPath);
    ArtifactDetail expectedArtifactDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
    Assert.assertEquals(expectedArtifactDetail.getDescriptor().getLocation().toURI().getPath(), locationPath);
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Test(org.junit.Test)

Example 32 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class PluginExclusionTest method testPluginRequirements.

@Test
public void testPluginRequirements() throws Exception {
    // Add a system artifact
    ArtifactId systemArtifactId = NamespaceId.SYSTEM.artifact("app", "1.0.0");
    addAppAsSystemArtifacts(systemArtifactId);
    Set<ArtifactRange> parents = Sets.newHashSet(new ArtifactRange(systemArtifactId.getNamespace(), systemArtifactId.getArtifact(), new ArtifactVersion(systemArtifactId.getVersion()), true, new ArtifactVersion(systemArtifactId.getVersion()), true));
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, InspectionApp.class.getPackage().getName());
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("inspection", "1.0.0");
    Assert.assertEquals(HttpResponseStatus.OK.code(), addPluginArtifact(Id.Artifact.fromEntityId(artifactId), InspectionApp.class, manifest, parents).getResponseCode());
    Set<PluginClass> plugins = getArtifactInfo(artifactId).getClasses().getPlugins();
    // Only four plugins which does not have transactions as requirement should be visible.
    Assert.assertEquals(6, plugins.size());
    Set<String> actualPluginClassNames = plugins.stream().map(PluginClass::getClassName).collect(Collectors.toSet());
    Set<String> expectedPluginClassNames = ImmutableSet.of(InspectionApp.AppPlugin.class.getName(), InspectionApp.EmptyRequirementPlugin.class.getName(), InspectionApp.SingleEmptyRequirementPlugin.class.getName(), InspectionApp.NonTransactionalPlugin.class.getName(), InspectionApp.CapabilityPlugin.class.getName(), InspectionApp.MultipleCapabilityPlugin.class.getName());
    Assert.assertEquals(expectedPluginClassNames, actualPluginClassNames);
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) Manifest(java.util.jar.Manifest) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) PluginClass(io.cdap.cdap.api.plugin.PluginClass) Test(org.junit.Test)

Example 33 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class MetadataHttpHandlerTestRun method testSearchMetadataDelete.

@Test
public void testSearchMetadataDelete() throws Exception {
    NamespaceId namespace = new NamespaceId("ns1");
    namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
    // Deploy app
    appClient.deploy(namespace, createAppJarFile(AllProgramsApp.class, AllProgramsApp.class.getSimpleName(), "1.0"));
    ArtifactId artifact = namespace.artifact(AllProgramsApp.class.getSimpleName(), "1.0");
    ApplicationId app = namespace.app(AllProgramsApp.NAME);
    ProgramId service = app.service(AllProgramsApp.NoOpService.NAME);
    DatasetId datasetInstance = namespace.dataset(AllProgramsApp.DATASET_NAME);
    // wait for metadata to be processed
    Tasks.waitFor(false, () -> getProperties(app, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
    Tasks.waitFor(false, () -> getProperties(service, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
    Tasks.waitFor(false, () -> getProperties(datasetInstance, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
    Set<String> tags = ImmutableSet.of("tag1", "tag2");
    // Add metadata
    addTags(app, tags);
    addTags(datasetInstance, tags);
    // Assert metadata
    assertSearch(searchMetadata(namespace, AllProgramsApp.DATASET_NAME), datasetInstance);
    assertSearch(searchMetadata(namespace, "all*"), app, artifact);
    assertSearch(searchMetadata(namespace, "tag1"), app, datasetInstance);
    // Delete entities
    appClient.delete(app);
    datasetClient.delete(datasetInstance);
    artifactClient.delete(artifact);
    // Assert no metadata
    waitForSearch(() -> searchMetadata(namespace, AllProgramsApp.DATASET_NAME));
    waitForSearch(() -> searchMetadata(namespace, "all*"));
    waitForSearch(() -> searchMetadata(namespace, "tag1"));
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) AllProgramsApp(io.cdap.cdap.client.app.AllProgramsApp) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 34 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class MetadataHttpHandlerTestRun method testSystemScopeArtifacts.

@Test
public void testSystemScopeArtifacts() 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
    ArtifactId systemId = NamespaceId.SYSTEM.artifact("app", "1.0.0");
    File systemArtifact = createArtifactJarFile(AllProgramsApp.class, "app", "1.0.0", new Manifest());
    StandaloneTester tester = STANDALONE.get();
    tester.addSystemArtifact(systemId.getArtifact(), Id.Artifact.fromEntityId(systemId).getVersion(), systemArtifact, null);
    // wait until the system metadata has been processed
    Tasks.waitFor(false, () -> getProperties(systemId, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
    // verify that user metadata can be added for system-scope artifacts
    Map<String, String> userProperties = ImmutableMap.of("systemArtifactKey", "systemArtifactValue");
    Set<String> userTags = ImmutableSet.of();
    addProperties(systemId, userProperties);
    addTags(systemId, userTags);
    // verify that user and system metadata can be retrieved for system-scope artifacts
    Assert.assertEquals(ImmutableSet.of(new MetadataRecord(systemId, MetadataScope.USER, userProperties, userTags), new MetadataRecord(systemId, MetadataScope.SYSTEM, ImmutableMap.of(MetadataConstants.ENTITY_NAME_KEY, systemId.getEntityName()), ImmutableSet.of())), removeCreationTime(getMetadata(systemId.toMetadataEntity())));
    // verify that system scope artifacts can be returned by a search in the default namespace
    // with no target type
    MetadataSearchResponse response = searchMetadata(ImmutableList.of(NamespaceId.DEFAULT, NamespaceId.SYSTEM), "system*");
    MetadataEntity expectedEntity = systemId.toMetadataEntity();
    Set<MetadataEntity> actualEntities = new HashSet<>(extractMetadataEntities(response.getResults()));
    Assert.assertTrue(actualEntities.contains(expectedEntity));
    // with target type as artifact
    assertSearch(searchMetadata(ImmutableList.of(NamespaceId.DEFAULT, NamespaceId.SYSTEM), "system*", MetadataEntity.ARTIFACT), systemId);
    // verify that user metadata can be deleted for system-scope artifacts
    removeMetadata(systemId);
    Assert.assertEquals(ImmutableSet.of(new MetadataRecord(systemId, MetadataScope.USER, ImmutableMap.of(), ImmutableSet.of()), new MetadataRecord(systemId, MetadataScope.SYSTEM, ImmutableMap.of(MetadataConstants.ENTITY_NAME_KEY, systemId.getEntityName()), ImmutableSet.of())), removeCreationTime(getMetadata(systemId.toMetadataEntity())));
    artifactClient.delete(systemId);
}
Also used : StandaloneTester(io.cdap.cdap.StandaloneTester) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) MetadataSearchResponse(io.cdap.cdap.proto.metadata.MetadataSearchResponse) Manifest(java.util.jar.Manifest) MetadataRecord(io.cdap.cdap.common.metadata.MetadataRecord) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId 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);
    ContentProvider<InputStream> contentProvider = appJarLoc::getInputStream;
    artifactClient.add(myapp1Id.getParent(), myapp1Id.getArtifact(), contentProvider, 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(), contentProvider, 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);
    contentProvider = 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(PluginClass.builder().setName("mysql").setType("jdbc").setDescription("").setClassName(Plugin1.class.getName()).build());
    artifactClient.add(pluginId.getParent(), pluginId.getArtifact(), contentProvider, 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(PluginClass.builder().setName("plugin1").setType("callable").setDescription("p1 description").setClassName(Plugin1.class.getName()).setConfigFieldName("conf").setProperties(props).build()).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", null, Plugin1.class.getName(), pluginArtifactSummary, "p1 description");
    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", null, Plugin1.class.getName(), "conf", pluginArtifactSummary, props, "p1 description");
    Assert.assertEquals(Sets.newHashSet(pluginInfo), Sets.newHashSet(artifactClient.getPluginInfo(myapp2Id, "callable", "plugin1")));
}
Also used : MyApp(io.cdap.cdap.client.artifact.MyApp) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) Schema(io.cdap.cdap.api.data.schema.Schema) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) PluginPropertyField(io.cdap.cdap.api.plugin.PluginPropertyField) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactClasses(io.cdap.cdap.api.artifact.ArtifactClasses) ApplicationClassInfo(io.cdap.cdap.proto.artifact.ApplicationClassInfo) PluginInfo(io.cdap.cdap.proto.artifact.PluginInfo) PluginSummary(io.cdap.cdap.proto.artifact.PluginSummary) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) Plugin1(io.cdap.cdap.client.artifact.plugin.Plugin1) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) ApplicationClassSummary(io.cdap.cdap.proto.artifact.ApplicationClassSummary) Manifest(java.util.jar.Manifest) ReflectionSchemaGenerator(io.cdap.cdap.internal.io.ReflectionSchemaGenerator) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) PluginClass(io.cdap.cdap.api.plugin.PluginClass) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Aggregations

ArtifactId (io.cdap.cdap.proto.id.ArtifactId)214 Test (org.junit.Test)118 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)94 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)68 IOException (java.io.IOException)50 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)42 ProgramId (io.cdap.cdap.proto.id.ProgramId)42 Id (io.cdap.cdap.common.id.Id)40 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)40 File (java.io.File)34 PluginClass (io.cdap.cdap.api.plugin.PluginClass)32 Path (javax.ws.rs.Path)32 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)30 Set (java.util.Set)30 ImmutableSet (com.google.common.collect.ImmutableSet)28 Location (org.apache.twill.filesystem.Location)28 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)26 ArtifactDetail (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)26 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)22 EntityId (io.cdap.cdap.proto.id.EntityId)20