use of io.cdap.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class AppLifecycleHttpHandler method getAllApps.
/**
* Returns a list of applications associated with a namespace.
*/
@GET
@Path("/apps")
public void getAllApps(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @QueryParam("artifactName") String artifactName, @QueryParam("artifactVersion") String artifactVersion, @QueryParam("pageToken") String pageToken, @QueryParam("pageSize") Integer pageSize, @QueryParam("orderBy") SortOrder orderBy, @QueryParam("nameFilter") String nameFilter) throws Exception {
NamespaceId namespace = validateNamespace(namespaceId);
Set<String> names = new HashSet<>();
if (!Strings.isNullOrEmpty(artifactName)) {
for (String name : Splitter.on(',').split(artifactName)) {
names.add(name);
}
}
if (Optional.ofNullable(pageSize).orElse(0) != 0) {
JsonPaginatedListResponder.respond(GSON, responder, APP_LIST_PAGINATED_KEY, jsonListResponder -> {
AtomicReference<ApplicationRecord> lastRecord = new AtomicReference<>(null);
ScanApplicationsRequest scanRequest = getScanRequest(namespaceId, artifactVersion, pageToken, pageSize, orderBy, nameFilter, names);
boolean pageLimitReached = applicationLifecycleService.scanApplications(scanRequest, appDetail -> {
ApplicationRecord record = new ApplicationRecord(appDetail);
jsonListResponder.send(record);
lastRecord.set(record);
});
ApplicationRecord record = lastRecord.get();
return !pageLimitReached || record == null ? null : record.getName() + EntityId.IDSTRING_PART_SEPARATOR + record.getAppVersion();
});
} else {
ScanApplicationsRequest scanRequest = getScanRequest(namespaceId, artifactVersion, pageToken, null, orderBy, nameFilter, names);
JsonWholeListResponder.respond(GSON, responder, jsonListResponder -> applicationLifecycleService.scanApplications(scanRequest, d -> jsonListResponder.send(new ApplicationRecord(d))));
}
}
use of io.cdap.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class ApplicationClient method list.
/**
* Lists all applications currently deployed, optionally filtering to only include applications that use one of
* the specified artifact names and the specified artifact version.
*
* @param namespace the namespace to list applications from
* @param artifactNames the set of artifact names to allow. If empty, no filtering will be done.
* @param artifactVersion the version of the artifact to filter by. If null, no filtering will be done.
* @return list of {@link ApplicationRecord ApplicationRecords}.
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<ApplicationRecord> list(NamespaceId namespace, Set<String> artifactNames, @Nullable String artifactVersion) throws IOException, UnauthenticatedException, UnauthorizedException {
if (artifactNames.isEmpty() && artifactVersion == null) {
return list(namespace);
}
String path;
if (!artifactNames.isEmpty() && artifactVersion != null) {
path = String.format("apps?artifactName=%s&artifactVersion=%s", Joiner.on(',').join(artifactNames), artifactVersion);
} else if (!artifactNames.isEmpty()) {
path = "apps?artifactName=" + Joiner.on(',').join(artifactNames);
} else {
path = "apps?artifactVersion=" + artifactVersion;
}
HttpResponse response = restClient.execute(HttpMethod.GET, config.resolveNamespacedURLV3(namespace, path), config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<List<ApplicationRecord>>() {
}).getResponseObject();
}
use of io.cdap.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 io.cdap.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class PostUpgradeJobMain method restartPipelinesAndSchedules.
private static void restartPipelinesAndSchedules(ClientConfig clientConfig, long startTimeMillis, boolean restartSystemApps) throws Exception {
long endTimeMillis = System.currentTimeMillis();
ApplicationClient applicationClient = new ApplicationClient(clientConfig);
ScheduleClient scheduleClient = new ScheduleClient(clientConfig);
ProgramClient programClient = new ProgramClient(clientConfig);
NamespaceClient namespaceClient = new NamespaceClient(clientConfig);
List<NamespaceId> namespaceIdList = namespaceClient.list().stream().map(NamespaceMeta::getNamespaceId).collect(Collectors.toList());
if (restartSystemApps) {
namespaceIdList.add(NamespaceId.SYSTEM);
}
for (NamespaceId namespaceId : namespaceIdList) {
for (ApplicationRecord record : applicationClient.list(namespaceId)) {
ApplicationId applicationId = new ApplicationId(namespaceId.getNamespace(), record.getName(), record.getAppVersion());
programClient.restart(applicationId, TimeUnit.MILLISECONDS.toSeconds(startTimeMillis), TimeUnit.MILLISECONDS.toSeconds(endTimeMillis));
}
// Re-enable schedules in a namespace AFTER programs have been restarted.
scheduleClient.reEnableSuspendedSchedules(namespaceId, startTimeMillis, endTimeMillis);
}
}
use of io.cdap.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