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);
}
}
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
}
}
}
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()));
}
}
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;
}
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;
}
Aggregations