use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class ApplicationLifecycleService method getApps.
/**
* Get all applications in the specified namespace that satisfy the specified predicate.
*
* @param namespace the namespace to get apps from
* @param predicate the predicate that must be satisfied in order to be returned
* @return list of all applications in the namespace that satisfy the specified predicate
*/
public List<ApplicationRecord> getApps(final NamespaceId namespace, com.google.common.base.Predicate<ApplicationRecord> predicate) throws Exception {
List<ApplicationRecord> appRecords = new ArrayList<>();
Set<ApplicationId> appIds = new HashSet<>();
for (ApplicationSpecification appSpec : store.getAllApplications(namespace)) {
appIds.add(namespace.app(appSpec.getName(), appSpec.getAppVersion()));
}
for (ApplicationId appId : appIds) {
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
continue;
}
// possible if this particular app was deploy prior to v3.2 and upgrade failed for some reason.
ArtifactId artifactId = appSpec.getArtifactId();
ArtifactSummary artifactSummary = artifactId == null ? new ArtifactSummary(appSpec.getName(), null) : ArtifactSummary.from(artifactId);
ApplicationRecord record = new ApplicationRecord(artifactSummary, appId, appSpec.getDescription(), ownerAdmin.getOwnerPrincipal(appId));
if (predicate.apply(record)) {
appRecords.add(record);
}
}
Principal principal = authenticationContext.getPrincipal();
final Predicate<EntityId> filter = authorizationEnforcer.createFilter(principal);
return Lists.newArrayList(Iterables.filter(appRecords, new com.google.common.base.Predicate<ApplicationRecord>() {
@Override
public boolean apply(ApplicationRecord appRecord) {
return filter.apply(namespace.app(appRecord.getName()));
}
}));
}
use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class ListAppsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String artifactNamesStr = arguments.getOptional(ArgumentName.ARTIFACT_NAME.toString());
String artifactVersion = arguments.getOptional(ArgumentName.ARTIFACT_VERSION.toString());
Set<String> artifactNames = new HashSet<>();
if (artifactNamesStr != null) {
for (String name : Splitter.on(',').trimResults().split(artifactNamesStr)) {
artifactNames.add(name);
}
}
Table table = Table.builder().setHeader("id", "appVersion", "description", "artifactName", "artifactVersion", "artifactScope", "principal").setRows(appClient.list(cliConfig.getCurrentNamespace(), artifactNames, artifactVersion), new RowMaker<ApplicationRecord>() {
@Override
public List<?> makeRow(ApplicationRecord object) {
return Lists.newArrayList(object.getName(), object.getAppVersion(), object.getDescription(), object.getArtifact().getName(), object.getArtifact().getVersion(), object.getArtifact().getScope(), object.getOwnerPrincipal());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.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 co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class CDAPEntities method collect.
@Override
public void collect() throws Exception {
reset();
List<NamespaceMeta> namespaceMetas;
namespaceMetas = nsQueryAdmin.list();
namespaces = namespaceMetas.size();
for (NamespaceMeta meta : namespaceMetas) {
List<ApplicationRecord> appRecords = appLifecycleService.getApps(meta.getNamespaceId(), Predicates.<ApplicationRecord>alwaysTrue());
apps += appRecords.size();
Set<ProgramType> programTypes = EnumSet.of(ProgramType.FLOW, ProgramType.MAPREDUCE, ProgramType.SERVICE, ProgramType.SPARK, ProgramType.WORKER, ProgramType.WORKFLOW);
for (ProgramType programType : programTypes) {
programs += programLifecycleService.list(meta.getNamespaceId(), programType).size();
}
artifacts += artifactRepository.getArtifactSummaries(meta.getNamespaceId(), true).size();
datasets += dsFramework.getInstances(meta.getNamespaceId()).size();
List<StreamSpecification> streamSpecs = streamAdmin.listStreams(meta.getNamespaceId());
streams += streamSpecs.size();
for (StreamSpecification streamSpec : streamSpecs) {
StreamId streamId = meta.getNamespaceId().stream(streamSpec.getName());
streamViews += streamAdmin.listViews(streamId).size();
}
}
}
Aggregations