use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ApplicationLifecycleServiceTest method testDeployArtifactAndApplicationCleansUpArtifactOnFailure.
// test that the call to deploy an artifact and application in a single step will delete the artifact
// if the application could not be created
@Test(expected = ArtifactNotFoundException.class)
public void testDeployArtifactAndApplicationCleansUpArtifactOnFailure() throws Exception {
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "missing-mr", "1.0.0-SNAPSHOT");
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, MissingMapReduceWorkflowApp.class);
File appJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", artifactId.getName(), artifactId.getVersion().getVersion()));
Files.copy(Locations.newInputSupplier(appJar), appJarFile);
appJar.delete();
try {
applicationLifecycleService.deployAppAndArtifact(NamespaceId.DEFAULT, "appName", artifactId, appJarFile, null, null, new ProgramTerminator() {
@Override
public void stop(ProgramId programId) throws Exception {
// no-op
}
}, true);
Assert.fail("expected application deployment to fail.");
} catch (Exception e) {
// expected
}
// the artifact should have been cleaned up, and this should throw a not found exception
artifactRepository.getArtifact(artifactId);
}
use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ApplicationLifecycleServiceTest method testMissingDependency.
@Test
public void testMissingDependency() throws Exception {
// tests the fix for CDAP-2543, by having programs which fail to start up due to missing dependency jars
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("missing-guava-dependency", "1.0.0-SNAPSHOT");
Location appJar = createDeploymentJar(locationFactory, AppWithProgramsUsingGuava.class);
File appJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion()));
Files.copy(Locations.newInputSupplier(appJar), appJarFile);
appJar.delete();
applicationLifecycleService.deployAppAndArtifact(NamespaceId.DEFAULT, "appName", Id.Artifact.fromEntityId(artifactId), appJarFile, null, null, new ProgramTerminator() {
@Override
public void stop(ProgramId programId) throws Exception {
// no-op
}
}, true);
ApplicationId appId = NamespaceId.DEFAULT.app("appName");
// run records for programs that have missing dependencies should be FAILED, instead of hanging in RUNNING
// fail the Worker#initialize
ProgramId worker = appId.worker(AppWithProgramsUsingGuava.NoOpWorker.NAME);
startProgram(Id.Program.fromEntityId(worker));
waitForRuns(1, worker, ProgramRunStatus.FAILED);
// fail the MapReduce#initialize
ProgramId mapreduce = appId.mr(AppWithProgramsUsingGuava.NoOpMR.NAME);
startProgram(Id.Program.fromEntityId(mapreduce));
waitForRuns(1, mapreduce, ProgramRunStatus.FAILED);
// fail the CustomAction#initialize
ProgramId workflow = appId.workflow(AppWithProgramsUsingGuava.NoOpWorkflow.NAME);
startProgram(Id.Program.fromEntityId(workflow));
waitForRuns(1, workflow, ProgramRunStatus.FAILED);
// fail the Workflow#initialize
appId.workflow(AppWithProgramsUsingGuava.NoOpWorkflow.NAME);
startProgram(Id.Program.fromEntityId(workflow), ImmutableMap.of("fail.in.workflow.initialize", "true"));
waitForRuns(1, workflow, ProgramRunStatus.FAILED);
}
use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testAppWithConfig.
@Test
public void testAppWithConfig() throws Exception {
Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "ConfigApp");
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "appWithConfig", "1.0.0-SNAPSHOT");
HttpResponse response = addAppArtifact(artifactId, ConfigTestApp.class);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("abc", "def");
response = deploy(appId, new AppRequest<>(ArtifactSummary.from(artifactId.toArtifactId()), config));
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
JsonObject appDetails = getAppDetails(Id.Namespace.DEFAULT.getId(), "ConfigApp");
Assert.assertEquals(GSON.toJson(config), appDetails.get("configuration").getAsString());
deleteApp(appId, 200);
deleteArtifact(artifactId, 200);
}
use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ArtifactHttpHandlerTest method testPluginNamespaceIsolation.
@Test
public void testPluginNamespaceIsolation() throws Exception {
// add a system artifact
ArtifactId systemId = NamespaceId.SYSTEM.artifact("wordcount", "1.0.0");
addSystemArtifacts();
Set<ArtifactRange> parents = Sets.newHashSet(new ArtifactRange(systemId.getNamespace(), systemId.getArtifact(), new ArtifactVersion(systemId.getVersion()), true, new ArtifactVersion(systemId.getVersion()), true));
NamespaceId namespace1 = new NamespaceId("ns1");
NamespaceId namespace2 = new NamespaceId("ns2");
createNamespace(namespace1.getNamespace());
createNamespace(namespace2.getNamespace());
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());
ArtifactId pluginsId1 = namespace1.artifact("plugins1", "1.0.0");
Assert.assertEquals(HttpResponseStatus.OK.code(), addPluginArtifact(Id.Artifact.fromEntityId(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());
ArtifactId pluginsId2 = namespace2.artifact("plugins2", "1.0.0");
Assert.assertEquals(HttpResponseStatus.OK.code(), addPluginArtifact(Id.Artifact.fromEntityId(pluginsId2), Plugin1.class, manifest, parents).getStatusLine().getStatusCode());
ArtifactSummary artifact1 = new ArtifactSummary(pluginsId1.getArtifact(), pluginsId1.getVersion(), ArtifactScope.USER);
ArtifactSummary artifact2 = new ArtifactSummary(pluginsId2.getArtifact(), pluginsId2.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(), "config", artifact1, ImmutableMap.of("x", new PluginPropertyField("x", "", "int", true, false), "stuff", new PluginPropertyField("stuff", "", "string", true, true)), new HashSet<>());
PluginInfo info2Namespace1 = new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), "config", artifact1, ImmutableMap.of("v", new PluginPropertyField("v", "value to return when called", "int", true, false)), new HashSet<>());
PluginInfo info1Namespace2 = new PluginInfo("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), "config", artifact2, ImmutableMap.of("x", new PluginPropertyField("x", "", "int", true, false), "stuff", new PluginPropertyField("stuff", "", "string", true, true)), new HashSet<>());
PluginInfo info2Namespace2 = new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), "config", artifact2, ImmutableMap.of("v", new PluginPropertyField("v", "value to return when called", "int", true, false)), new HashSet<>());
ArtifactId namespace1Artifact = namespace1.artifact(systemId.getArtifact(), systemId.getVersion());
ArtifactId namespace2Artifact = namespace2.artifact(systemId.getArtifact(), 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");
cleanupSystemArtifactsDirectory();
}
}
use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ArtifactHttpHandlerTest method testDeletePropertiesAndArtifacts.
@Test
public void testDeletePropertiesAndArtifacts() throws Exception {
// add 2 versions of the same app that doesn't use config
ArtifactId wordcountId1 = NamespaceId.DEFAULT.artifact("wordcount", "1.0.0");
Assert.assertEquals(HttpResponseStatus.OK.code(), addAppArtifact(Id.Artifact.fromEntityId(wordcountId1), WordCountApp.class).getStatusLine().getStatusCode());
// test get /artifacts endpoint
Set<ArtifactSummary> expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0"));
Set<ArtifactSummary> actualArtifacts = getArtifacts(NamespaceId.DEFAULT);
Assert.assertEquals(expectedArtifacts, actualArtifacts);
addArtifactProperties(Id.Artifact.fromEntityId(wordcountId1), ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3"));
Assert.assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3"), getArtifactProperties(wordcountId1));
// delete a single property
deleteArtifact(wordcountId1, false, "key1", 200);
Assert.assertEquals(ImmutableMap.of("key2", "value2", "key3", "value3"), getArtifactProperties(wordcountId1));
// delete all properties
deleteArtifact(wordcountId1, false, null, 200);
Assert.assertEquals(ImmutableMap.of(), getArtifactProperties(wordcountId1));
Set<MetadataRecord> metadataRecords = metadataClient.getMetadata(Id.Artifact.fromEntityId(wordcountId1), MetadataScope.USER);
Assert.assertEquals(1, metadataRecords.size());
Assert.assertEquals(new MetadataRecord(wordcountId1, MetadataScope.USER), metadataRecords.iterator().next());
// delete artifact
deleteArtifact(wordcountId1, true, null, 200);
try {
metadataClient.getMetadata(Id.Artifact.fromEntityId(wordcountId1), MetadataScope.USER);
Assert.fail("Should not reach here");
} catch (NotFoundException e) {
// no-op
}
actualArtifacts = getArtifacts(NamespaceId.DEFAULT);
Assert.assertTrue(actualArtifacts.isEmpty());
}
Aggregations