Search in sources :

Example 1 with SimpleDistributionResponse

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

the class ImportingDistributionPackageProcessor method process.

@Override
public void process(DistributionPackage distributionPackage) {
    final long startTime = System.currentTimeMillis();
    try {
        // set up original calling RR
        ResourceResolver resourceResolver = DistributionUtils.getResourceResolver(callingUser, authenticationInfo.getAgentService(), authenticationInfo.getSlingRepository(), authenticationInfo.getSubServiceName(), authenticationInfo.getResourceResolverFactory());
        // perform importing
        distributionPackageImporter.importPackage(resourceResolver, distributionPackage);
        // collect stats
        packagesSize.addAndGet(distributionPackage.getSize());
        packagesCount.incrementAndGet();
        DistributionResponse response = new SimpleDistributionResponse(DistributionRequestState.ACCEPTED, "package imported");
        allResponses.add(response);
        final long endTime = System.currentTimeMillis();
        log.debug("PACKAGE-IMPORTED {}: packageId={}, paths={}, responses={}", requestId, distributionPackage.getId(), distributionPackage.getInfo().getPaths(), endTime - startTime, response);
    } catch (DistributionException e) {
        log.error("an error happened during package import", e);
        allResponses.add(new SimpleDistributionResponse(DistributionRequestState.DROPPED, e.toString()));
    }
}
Also used : SimpleDistributionResponse(org.apache.sling.distribution.impl.SimpleDistributionResponse) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionException(org.apache.sling.distribution.common.DistributionException) DistributionResponse(org.apache.sling.distribution.DistributionResponse) SimpleDistributionResponse(org.apache.sling.distribution.impl.SimpleDistributionResponse)

Example 2 with SimpleDistributionResponse

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

the class QueueingDistributionPackageProcessor method scheduleImportPackage.

private Collection<SimpleDistributionResponse> scheduleImportPackage(DistributionPackage distributionPackage, String callingUser, String requestId, long startTime) {
    Collection<SimpleDistributionResponse> distributionResponses = new LinkedList<SimpleDistributionResponse>();
    // dispatch the distribution package to one or more queues
    try {
        // add metadata to the package
        distributionPackage.getInfo().put(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_USER, callingUser);
        distributionPackage.getInfo().put(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_ID, requestId);
        distributionPackage.getInfo().put(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_START_TIME, startTime);
        // put the package in the queue
        Iterable<DistributionQueueItemStatus> states = scheduleQueueStrategy.add(distributionPackage, queueProvider);
        for (DistributionQueueItemStatus state : states) {
            DistributionRequestState requestState = getRequestStateFromQueueState(state.getItemState());
            distributionResponses.add(new SimpleDistributionResponse(requestState, state.getItemState().toString()));
        }
        distributionEventFactory.generatePackageEvent(DistributionEventTopics.AGENT_PACKAGE_QUEUED, DistributionComponentKind.AGENT, agentName, distributionPackage.getInfo());
    } catch (DistributionException e) {
        log.error("an error happened during dispatching items to the queue(s)", e);
        distributionResponses.add(new SimpleDistributionResponse(DistributionRequestState.DROPPED, e.toString()));
    }
    return distributionResponses;
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) SimpleDistributionResponse(org.apache.sling.distribution.impl.SimpleDistributionResponse) DistributionRequestState(org.apache.sling.distribution.DistributionRequestState) DistributionException(org.apache.sling.distribution.common.DistributionException) LinkedList(java.util.LinkedList)

Example 3 with SimpleDistributionResponse

use of org.apache.sling.distribution.impl.SimpleDistributionResponse 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

DistributionException (org.apache.sling.distribution.common.DistributionException)3 SimpleDistributionResponse (org.apache.sling.distribution.impl.SimpleDistributionResponse)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 LinkedList (java.util.LinkedList)1 Nonnull (javax.annotation.Nonnull)1 DistributionRequestState (org.apache.sling.distribution.DistributionRequestState)1 DistributionResponse (org.apache.sling.distribution.DistributionResponse)1 CompositeDistributionResponse (org.apache.sling.distribution.impl.CompositeDistributionResponse)1 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)1