Search in sources :

Example 16 with DistributionException

use of org.apache.sling.distribution.common.DistributionException in project sling by apache.

the class AvroContentSerializer method importFromStream.

@Override
public void importFromStream(ResourceResolver resourceResolver, InputStream stream) throws DistributionException {
    try {
        // TODO : avoid byte[] conversion
        byte[] bin = IOUtils.toByteArray(stream);
        Collection<AvroShallowResource> avroShallowResources = readAvroResources(bin);
        for (AvroShallowResource ar : avroShallowResources) {
            persistResource(resourceResolver, ar);
        }
        resourceResolver.commit();
    } catch (Exception e) {
        throw new DistributionException(e);
    }
}
Also used : DistributionException(org.apache.sling.distribution.common.DistributionException) DistributionException(org.apache.sling.distribution.common.DistributionException) PersistenceException(org.apache.sling.api.resource.PersistenceException) IOException(java.io.IOException)

Example 17 with DistributionException

use of org.apache.sling.distribution.common.DistributionException in project sling by apache.

the class AvroContentSerializer method exportToStream.

@Override
public void exportToStream(ResourceResolver resourceResolver, DistributionExportOptions options, OutputStream outputStream) throws DistributionException {
    DatumWriter<AvroShallowResource> datumWriter = new SpecificDatumWriter<AvroShallowResource>(AvroShallowResource.class);
    DataFileWriter<AvroShallowResource> writer = new DataFileWriter<AvroShallowResource>(datumWriter);
    try {
        writer.create(schema, outputStream);
    } catch (IOException e) {
        throw new DistributionException(e);
    }
    try {
        DistributionExportFilter filter = options.getFilter();
        for (DistributionExportFilter.TreeFilter treeFilter : filter.getNodeFilters()) {
            String path = treeFilter.getPath();
            Resource resource = resourceResolver.getResource(path);
            AvroShallowResource avroShallowResource = getAvroShallowResource(treeFilter, filter.getPropertyFilter(), resource);
            writer.append(avroShallowResource);
        }
        outputStream.flush();
    } catch (Exception e) {
        throw new DistributionException(e);
    } finally {
        try {
            writer.close();
        } catch (IOException e) {
        // do nothing
        }
    }
}
Also used : DataFileWriter(org.apache.avro.file.DataFileWriter) Resource(org.apache.sling.api.resource.Resource) DistributionException(org.apache.sling.distribution.common.DistributionException) DistributionExportFilter(org.apache.sling.distribution.serialization.DistributionExportFilter) IOException(java.io.IOException) DistributionException(org.apache.sling.distribution.common.DistributionException) PersistenceException(org.apache.sling.api.resource.PersistenceException) IOException(java.io.IOException) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter)

Example 18 with DistributionException

use of org.apache.sling.distribution.common.DistributionException 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 19 with DistributionException

use of org.apache.sling.distribution.common.DistributionException 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 20 with DistributionException

use of org.apache.sling.distribution.common.DistributionException in project sling by apache.

the class SimpleDistributionAgent method getQueue.

public DistributionQueue getQueue(@Nonnull final String queueName) {
    Set<String> queues = getQueueNames();
    if (!queues.contains(queueName)) {
        return null;
    }
    DistributionQueue queue = null;
    try {
        queue = queueProvider.getQueue(queueName);
    } catch (DistributionException e) {
        log.error("cannot get queue", e);
    }
    if (queue != null) {
        boolean isPausedQueue = !queueProcessingEnabled && (processingQueues != null && processingQueues.contains(queueName));
        queue = new SimpleAgentDistributionQueue(queue, isPausedQueue, name);
    }
    return queue;
}
Also used : SimpleAgentDistributionQueue(org.apache.sling.distribution.queue.impl.SimpleAgentDistributionQueue) SimpleAgentDistributionQueue(org.apache.sling.distribution.queue.impl.SimpleAgentDistributionQueue) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionException(org.apache.sling.distribution.common.DistributionException)

Aggregations

DistributionException (org.apache.sling.distribution.common.DistributionException)35 IOException (java.io.IOException)8 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)8 Session (javax.jcr.Session)6 Nonnull (javax.annotation.Nonnull)5 RepositoryException (javax.jcr.RepositoryException)5 PersistenceException (org.apache.sling.api.resource.PersistenceException)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)5 InputStream (java.io.InputStream)4 Resource (org.apache.sling.api.resource.Resource)4 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 DigestOutputStream (java.security.DigestOutputStream)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 LoginException (org.apache.sling.api.resource.LoginException)3 SimpleDistributionResponse (org.apache.sling.distribution.impl.SimpleDistributionResponse)3 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)3