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));
}
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);
}
}
Aggregations