Search in sources :

Example 1 with BatchingConsumer

use of io.cdap.cdap.common.utils.BatchingConsumer in project cdap by caskdata.

the class ApplicationLifecycleService method scanApplications.

/**
 * Scans all applications in the specified namespace, filtered to only include application details
 * which satisfy the filters
 *
 * @param request application scan request. Must name namespace filled
 * @param consumer a {@link Consumer} to consume each ApplicationDetail being scanned
 * @return if limit was reached (true) or all items were scanned before reaching the limit (false)
 * @throws IllegalArgumentException if scan request does not have namespace specified
 */
public boolean scanApplications(ScanApplicationsRequest request, Consumer<ApplicationDetail> consumer) {
    NamespaceId namespace = request.getNamespaceId();
    if (namespace == null) {
        throw new IllegalStateException("Application scan request without namespace");
    }
    accessEnforcer.enforceOnParent(EntityType.DATASET, namespace, authenticationContext.getPrincipal(), StandardPermission.LIST);
    try (BatchingConsumer<Entry<ApplicationId, ApplicationSpecification>> batchingConsumer = new BatchingConsumer<>(list -> processApplications(list, consumer), batchSize)) {
        return store.scanApplications(request, batchSize, (appId, appSpec) -> {
            batchingConsumer.accept(new SimpleEntry<>(appId, appSpec));
        });
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) BatchingConsumer(io.cdap.cdap.common.utils.BatchingConsumer) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Aggregations

BatchingConsumer (io.cdap.cdap.common.utils.BatchingConsumer)1 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Entry (java.util.Map.Entry)1 ZipEntry (java.util.zip.ZipEntry)1