use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class GenerateClientUsageExample method applicationClient.
public void applicationClient() throws Exception {
// Construct the client used to interact with CDAP
ApplicationClient appClient = new ApplicationClient(clientConfig);
// Fetch the list of applications
List<ApplicationRecord> apps = appClient.list(NamespaceId.DEFAULT);
// Deploy an application
File appJarFile = new File("your-app.jar");
appClient.deploy(NamespaceId.DEFAULT, appJarFile);
// Delete an application
appClient.delete(NamespaceId.DEFAULT.app("Purchase"));
// List programs belonging to an application
appClient.listPrograms(NamespaceId.DEFAULT.app("Purchase"));
}
use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class IntegrationTestBase method assertNoApps.
private void assertNoApps(NamespaceId namespace) throws Exception {
ApplicationClient applicationClient = getApplicationClient();
List<ApplicationRecord> applicationRecords = applicationClient.list(namespace);
List<String> applicationIds = Lists.newArrayList();
for (ApplicationRecord applicationRecord : applicationRecords) {
applicationIds.add(applicationRecord.getName());
}
Assert.assertTrue("Must have no deployed apps, but found the following apps: " + Joiner.on(", ").join(applicationIds), applicationRecords.isEmpty());
}
use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class IntegrationTestBase method doClear.
private void doClear(NamespaceId namespace, boolean deleteNamespace) throws Exception {
// stop all programs in the namespace
getProgramClient().stopAll(namespace);
if (deleteNamespace) {
getNamespaceClient().delete(namespace);
return;
}
// delete all apps in the namespace
for (ApplicationRecord app : getApplicationClient().list(namespace)) {
getApplicationClient().delete(namespace.app(app.getName(), app.getAppVersion()));
}
// delete all streams
for (StreamDetail streamDetail : getStreamClient().list(namespace)) {
getStreamClient().delete(namespace.stream(streamDetail.getName()));
}
// delete all dataset instances
for (DatasetSpecificationSummary datasetSpecSummary : getDatasetClient().list(namespace)) {
getDatasetClient().delete(namespace.dataset(datasetSpecSummary.getName()));
}
ArtifactClient artifactClient = new ArtifactClient(getClientConfig(), getRestClient());
for (ArtifactSummary artifactSummary : artifactClient.list(namespace, ArtifactScope.USER)) {
artifactClient.delete(namespace.artifact(artifactSummary.getName(), artifactSummary.getVersion()));
}
assertIsClear(namespace);
}
use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class ProgramClient method stopAll.
/**
* Stops all currently running programs.
*/
public void stopAll(NamespaceId namespace) throws IOException, UnauthenticatedException, InterruptedException, TimeoutException, UnauthorizedException, ApplicationNotFoundException {
List<ApplicationRecord> allApps = applicationClient.list(namespace);
for (ApplicationRecord applicationRecord : allApps) {
ApplicationId appId = new ApplicationId(namespace.getNamespace(), applicationRecord.getName(), applicationRecord.getAppVersion());
List<ProgramRecord> programRecords = applicationClient.listPrograms(appId);
for (ProgramRecord programRecord : programRecords) {
try {
ProgramId program = appId.program(programRecord.getType(), programRecord.getName());
String status = this.getStatus(program);
if (!status.equals("STOPPED")) {
try {
this.stop(program);
} catch (IOException ioe) {
// ProgramClient#stop calls RestClient, which throws an IOException if the HTTP response code is 400,
// which can be due to the program already being stopped when calling stop on it.
// Most likely, there was a race condition that the program stopped between the time we checked its
// status and calling the stop method.
LOG.warn("Program {} is already stopped, proceeding even though the following exception is raised.", program, ioe);
}
this.waitForStatus(program, ProgramStatus.STOPPED, 60, TimeUnit.SECONDS);
}
} catch (ProgramNotFoundException e) {
// IGNORE
}
}
}
}
use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class ApplicationClientTestRun method testArtifactFilter.
@Test
public void testArtifactFilter() throws Exception {
ApplicationId appId1 = NamespaceId.DEFAULT.app(FakeApp.NAME);
ApplicationId appId2 = NamespaceId.DEFAULT.app("fake2");
ApplicationId appId3 = NamespaceId.DEFAULT.app("fake3");
try {
// app1 should use fake-1.0.0-SNAPSHOT
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "otherfake", "1.0.0-SNAPSHOT"));
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "fake", "0.1.0-SNAPSHOT"));
// app1 should end up with fake-1.0.0-SNAPSHOT
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "fake", "1.0.0-SNAPSHOT"));
// app2 should use fake-0.1.0-SNAPSHOT
appClient.deploy(appId2, new AppRequest<Config>(new ArtifactSummary("fake", "0.1.0-SNAPSHOT")));
// app3 should use otherfake-1.0.0-SNAPSHOT
appClient.deploy(appId3, new AppRequest<Config>(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT")));
appClient.waitForDeployed(appId1, 30, TimeUnit.SECONDS);
appClient.waitForDeployed(appId2, 30, TimeUnit.SECONDS);
appClient.waitForDeployed(appId3, 30, TimeUnit.SECONDS);
// check calls that should return nothing
// these don't match anything
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "ghost", null).isEmpty());
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, (String) null, "1.0.0").isEmpty());
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "ghost", "1.0.0").isEmpty());
// these match one but not the other
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "otherfake", "0.1.0-SNAPSHOT").isEmpty());
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "fake", "1.0.0").isEmpty());
// check filter by name only
Set<ApplicationRecord> apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "fake", null));
Set<ApplicationRecord> expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
Assert.assertEquals(expected, apps);
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "otherfake", null));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""));
Assert.assertEquals(expected, apps);
// check filter by multiple names
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, ImmutableSet.of("fake", "otherfake"), null));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""), new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
Assert.assertEquals(expected, apps);
// check filter by version only
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, (String) null, "0.1.0-SNAPSHOT"));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
Assert.assertEquals(expected, apps);
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, (String) null, "1.0.0-SNAPSHOT"));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""));
Assert.assertEquals(expected, apps);
// check filter by both
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "fake", "0.1.0-SNAPSHOT"));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
Assert.assertEquals(expected, apps);
} finally {
appClient.deleteAll(NamespaceId.DEFAULT);
appClient.waitForDeleted(appId1, 30, TimeUnit.SECONDS);
appClient.waitForDeleted(appId2, 30, TimeUnit.SECONDS);
appClient.waitForDeleted(appId3, 30, TimeUnit.SECONDS);
Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
}
}
Aggregations