Search in sources :

Example 6 with ApplicationRecord

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()));
        }
    }));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) ArrayList(java.util.ArrayList) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord) Predicate(co.cask.cdap.api.Predicate) EntityId(co.cask.cdap.proto.id.EntityId) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Principal(co.cask.cdap.proto.security.Principal) HashSet(java.util.HashSet)

Example 7 with ApplicationRecord

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);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) HashSet(java.util.HashSet) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 8 with ApplicationRecord

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();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 9 with ApplicationRecord

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();
        }
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) ProgramType(co.cask.cdap.proto.ProgramType) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Aggregations

ApplicationRecord (co.cask.cdap.proto.ApplicationRecord)9 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3 ApplicationClient (co.cask.cdap.client.ApplicationClient)2 HashSet (java.util.HashSet)2 Config (co.cask.cdap.api.Config)1 Predicate (co.cask.cdap.api.Predicate)1 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)1 StreamSpecification (co.cask.cdap.api.data.stream.StreamSpecification)1 RowMaker (co.cask.cdap.cli.util.RowMaker)1 Table (co.cask.cdap.cli.util.table.Table)1 ArtifactClient (co.cask.cdap.client.ArtifactClient)1 FakeApp (co.cask.cdap.client.app.FakeApp)1 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)1 DatasetSpecificationSummary (co.cask.cdap.proto.DatasetSpecificationSummary)1 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)1 ProgramRecord (co.cask.cdap.proto.ProgramRecord)1 ProgramType (co.cask.cdap.proto.ProgramType)1 StreamDetail (co.cask.cdap.proto.StreamDetail)1