Search in sources :

Example 1 with CompositeDistributionResponse

use of org.apache.sling.distribution.impl.CompositeDistributionResponse in project sling by apache.

the class SimpleDistributionAgent method exportPackages.

private CompositeDistributionResponse exportPackages(ResourceResolver agentResourceResolver, DistributionRequest distributionRequest, String callingUser, String requestId) throws DistributionException {
    final long startTime = System.currentTimeMillis();
    // callback function
    DistributionPackageProcessor packageProcessor;
    if (DistributionRequestType.TEST.equals(distributionRequest.getRequestType())) {
        // test packages do not get passed to the queues and get imported immediately
        packageProcessor = new ImportingDistributionPackageProcessor(distributionPackageImporter, agentAuthenticationInfo, callingUser, requestId, log);
    } else {
        packageProcessor = new QueueingDistributionPackageProcessor(callingUser, requestId, startTime, distributionEventFactory, scheduleQueueStrategy, queueProvider, log, name);
    }
    // export packages
    distributionPackageExporter.exportPackages(agentResourceResolver, distributionRequest, packageProcessor);
    final long endTime = System.currentTimeMillis();
    generatePackageEvent(DistributionEventTopics.AGENT_PACKAGE_CREATED);
    // create response
    List<DistributionResponse> distributionResponses = packageProcessor.getAllResponses();
    int packagesCount = packageProcessor.getPackagesCount();
    long packagesSize = packageProcessor.getPackagesSize();
    return new CompositeDistributionResponse(distributionResponses, packagesCount, packagesSize, endTime - startTime);
}
Also used : DistributionPackageProcessor(org.apache.sling.distribution.packaging.DistributionPackageProcessor) CompositeDistributionResponse(org.apache.sling.distribution.impl.CompositeDistributionResponse) DistributionResponse(org.apache.sling.distribution.DistributionResponse) SimpleDistributionResponse(org.apache.sling.distribution.impl.SimpleDistributionResponse) CompositeDistributionResponse(org.apache.sling.distribution.impl.CompositeDistributionResponse)

Example 2 with CompositeDistributionResponse

use of org.apache.sling.distribution.impl.CompositeDistributionResponse in project sling by apache.

the class SimpleDistributionAgent method execute.

@Nonnull
public DistributionResponse execute(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest) throws DistributionException {
    ResourceResolver agentResourceResolver = null;
    final String requestId = "DSTRQ" + nextRequestId.incrementAndGet();
    String callingUser = resourceResolver.getUserID();
    try {
        // check if the request type can be executed by this agent
        if (!isAcceptedRequestType(distributionRequest)) {
            log.debug("request type not accepted {}", distributionRequest.getRequestType());
            return new SimpleDistributionResponse(DistributionRequestState.DROPPED, "Request type not accepted");
        }
        // check if the request paths can be distributed via this agent
        if (!isAcceptedRequestRoot(distributionRequest)) {
            log.debug("request paths not accepted {}", Arrays.toString(distributionRequest.getPaths()));
            return new SimpleDistributionResponse(DistributionRequestState.DROPPED, "Request paths not accepted");
        }
        boolean silent = DistributionRequestType.PULL.equals(distributionRequest.getRequestType());
        log.info(silent, "REQUEST-START {}: {} paths={}, user={}", requestId, distributionRequest.getRequestType(), distributionRequest.getPaths(), callingUser);
        // check permissions
        distributionRequestAuthorizationStrategy.checkPermission(resourceResolver, distributionRequest);
        agentResourceResolver = DistributionUtils.getResourceResolver(callingUser, agentAuthenticationInfo.getAgentService(), agentAuthenticationInfo.getSlingRepository(), agentAuthenticationInfo.getSubServiceName(), agentAuthenticationInfo.getResourceResolverFactory());
        // export packages
        CompositeDistributionResponse distributionResponse = exportPackages(agentResourceResolver, distributionRequest, callingUser, requestId);
        log.debug("REQUEST-STARTED {}: {} paths={}, success={}, state={}, exportTime={}ms, noPackages={}, size={}B, noQueues={}", requestId, distributionRequest.getRequestType(), distributionRequest.getPaths(), distributionResponse.isSuccessful(), distributionResponse.getState(), distributionResponse.getExportTime(), distributionResponse.getPackagesCount(), distributionResponse.getPackagseSize(), distributionResponse.getQueuesCount());
        return distributionResponse;
    } catch (DistributionException e) {
        log.error("REQUEST-FAIL {}: {} paths={}, user={}, message={}", requestId, distributionRequest.getRequestType(), distributionRequest.getPaths(), callingUser, e.getMessage());
        throw e;
    } finally {
        DistributionUtils.ungetResourceResolver(agentResourceResolver);
    }
}
Also used : SimpleDistributionResponse(org.apache.sling.distribution.impl.SimpleDistributionResponse) CompositeDistributionResponse(org.apache.sling.distribution.impl.CompositeDistributionResponse) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionException(org.apache.sling.distribution.common.DistributionException) Nonnull(javax.annotation.Nonnull)

Aggregations

CompositeDistributionResponse (org.apache.sling.distribution.impl.CompositeDistributionResponse)2 SimpleDistributionResponse (org.apache.sling.distribution.impl.SimpleDistributionResponse)2 Nonnull (javax.annotation.Nonnull)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 DistributionResponse (org.apache.sling.distribution.DistributionResponse)1 DistributionException (org.apache.sling.distribution.common.DistributionException)1 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)1