Search in sources :

Example 11 with ApplicationClass

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

the class ArtifactHttpHandlerTest method testAddAndGet.

@Test
public void testAddAndGet() throws Exception {
    File wordCountArtifact = buildAppArtifact(WordCountApp.class, "wordcount.jar");
    File configTestArtifact = buildAppArtifact(ConfigTestApp.class, "cfgtest.jar");
    // add 2 versions of the same app that doesn't use config
    Id.Artifact wordcountId1 = Id.Artifact.from(Id.Namespace.DEFAULT, "wordcount", "1.0.0");
    Id.Artifact wordcountId2 = Id.Artifact.from(Id.Namespace.DEFAULT, "wordcount", "2.0.0");
    Assert.assertEquals(HttpResponseStatus.OK.getCode(), addArtifact(wordcountId1, Files.newInputStreamSupplier(wordCountArtifact), null).getStatusLine().getStatusCode());
    Assert.assertEquals(HttpResponseStatus.OK.getCode(), addArtifact(wordcountId2, Files.newInputStreamSupplier(wordCountArtifact), null).getStatusLine().getStatusCode());
    // and 1 version of another app that uses a config
    Id.Artifact configTestAppId = Id.Artifact.from(Id.Namespace.DEFAULT, "cfgtest", "1.0.0");
    Assert.assertEquals(HttpResponseStatus.OK.getCode(), addArtifact(configTestAppId, Files.newInputStreamSupplier(configTestArtifact), null).getStatusLine().getStatusCode());
    // test get /artifacts endpoint
    Set<ArtifactSummary> expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0"), new ArtifactSummary("wordcount", "2.0.0"), new ArtifactSummary("cfgtest", "1.0.0"));
    Set<ArtifactSummary> actualArtifacts = getArtifacts(Id.Namespace.DEFAULT);
    Assert.assertEquals(expectedArtifacts, actualArtifacts);
    // test get /artifacts/wordcount endpoint
    expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0"), new ArtifactSummary("wordcount", "2.0.0"));
    actualArtifacts = getArtifacts(Id.Namespace.DEFAULT, "wordcount");
    Assert.assertEquals(expectedArtifacts, actualArtifacts);
    // test get /artifacts/cfgtest/versions/1.0.0 endpoint
    Schema appConfigSchema = schemaGenerator.generate(ConfigTestApp.ConfigClass.class);
    ArtifactInfo actualInfo = getArtifact(configTestAppId);
    Assert.assertEquals("cfgtest", actualInfo.getName());
    Assert.assertEquals("1.0.0", actualInfo.getVersion());
    ApplicationClass appClass = new ApplicationClass(ConfigTestApp.class.getName(), "", appConfigSchema);
    Assert.assertTrue(actualInfo.getClasses().getApps().contains(appClass));
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactInfo(co.cask.cdap.api.artifact.ArtifactInfo) Schema(co.cask.cdap.api.data.schema.Schema) ApplicationClass(co.cask.cdap.api.artifact.ApplicationClass) Id(co.cask.cdap.proto.Id) NamespaceId(co.cask.cdap.proto.id.NamespaceId) File(java.io.File) ConfigTestApp(co.cask.cdap.ConfigTestApp) Test(org.junit.Test)

Example 12 with ApplicationClass

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

the class ArtifactStore method deleteMeta.

private void deleteMeta(Table table, Id.Artifact artifactId, byte[] oldData) throws IOException {
    // delete old artifact data
    ArtifactCell artifactCell = new ArtifactCell(artifactId);
    table.delete(artifactCell.rowkey, artifactCell.column);
    // delete old plugins
    final ArtifactData oldMeta = GSON.fromJson(Bytes.toString(oldData), ArtifactData.class);
    byte[] artifactColumn = new ArtifactColumn(artifactId).getColumn();
    for (PluginClass pluginClass : oldMeta.meta.getClasses().getPlugins()) {
        // delete metadata for each artifact this plugin extends
        for (ArtifactRange artifactRange : oldMeta.meta.getUsableBy()) {
            // p:{namespace}:{type}:{name}
            PluginKey pluginKey = new PluginKey(artifactRange.getNamespace(), artifactRange.getName(), pluginClass.getType(), pluginClass.getName());
            table.delete(pluginKey.getRowKey(), artifactColumn);
        }
    }
    // delete old appclass metadata
    for (ApplicationClass appClass : oldMeta.meta.getClasses().getApps()) {
        AppClassKey appClassKey = new AppClassKey(artifactId.getNamespace().toEntityId(), appClass.getClassName());
        table.delete(appClassKey.getRowKey(), artifactColumn);
    }
    try {
        new EntityImpersonator(artifactId.toEntityId(), impersonator).impersonate(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Locations.getLocationFromAbsolutePath(locationFactory, oldMeta.getLocationPath()).delete();
                return null;
            }
        });
    } catch (IOException ioe) {
        throw ioe;
    } catch (Exception e) {
        // this should not happen
        throw Throwables.propagate(e);
    }
}
Also used : EntityImpersonator(co.cask.cdap.security.impersonation.EntityImpersonator) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) ApplicationClass(co.cask.cdap.api.artifact.ApplicationClass) IOException(java.io.IOException) TransactionFailureException(org.apache.tephra.TransactionFailureException) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) ArtifactAlreadyExistsException(co.cask.cdap.common.ArtifactAlreadyExistsException) TransactionConflictException(org.apache.tephra.TransactionConflictException) PluginNotExistsException(co.cask.cdap.internal.app.runtime.plugin.PluginNotExistsException) ArtifactRangeNotFoundException(co.cask.cdap.common.ArtifactRangeNotFoundException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) PluginClass(co.cask.cdap.api.plugin.PluginClass)

Aggregations

ApplicationClass (co.cask.cdap.api.artifact.ApplicationClass)12 PluginClass (co.cask.cdap.api.plugin.PluginClass)7 Test (org.junit.Test)7 Id (co.cask.cdap.proto.Id)6 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)5 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)5 ArtifactId (co.cask.cdap.proto.id.ArtifactId)5 NamespaceId (co.cask.cdap.proto.id.NamespaceId)5 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)4 InspectionApp (co.cask.cdap.internal.app.runtime.artifact.app.inspection.InspectionApp)4 IOException (java.io.IOException)4 ArtifactClasses (co.cask.cdap.api.artifact.ArtifactClasses)3 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)3 Schema (co.cask.cdap.api.data.schema.Schema)3 PluginPropertyField (co.cask.cdap.api.plugin.PluginPropertyField)3 Manifest (java.util.jar.Manifest)3 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)2 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)2 ArtifactAlreadyExistsException (co.cask.cdap.common.ArtifactAlreadyExistsException)2 InvalidArtifactException (co.cask.cdap.common.InvalidArtifactException)2