Search in sources :

Example 1 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider in project sling by apache.

the class SimpleDistributionAgentFactory method createAgent.

@Override
protected SimpleDistributionAgent createAgent(String agentName, BundleContext context, Map<String, Object> config, DefaultDistributionLog distributionLog) {
    String serviceName = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(SERVICE_NAME), null));
    boolean queueProcessingEnabled = PropertiesUtil.toBoolean(config.get(QUEUE_PROCESSING_ENABLED), true);
    DistributionQueueProvider queueProvider = new JobHandlingDistributionQueueProvider(agentName, jobManager, context);
    DistributionQueueDispatchingStrategy exportQueueStrategy = new SingleQueueDispatchingStrategy();
    DistributionQueueDispatchingStrategy importQueueStrategy = null;
    Set<String> processingQueues = new HashSet<String>();
    processingQueues.addAll(exportQueueStrategy.getQueueNames());
    return new SimpleDistributionAgent(agentName, queueProcessingEnabled, processingQueues, serviceName, packageImporter, packageExporter, requestAuthorizationStrategy, queueProvider, exportQueueStrategy, importQueueStrategy, distributionEventFactory, resourceResolverFactory, slingRepository, distributionLog, null, null, 0);
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) SingleQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.SingleQueueDispatchingStrategy) HashSet(java.util.HashSet)

Example 2 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider in project sling by apache.

the class ForwardDistributionAgentFactory method createAgent.

@Override
protected SimpleDistributionAgent createAgent(String agentName, BundleContext context, Map<String, Object> config, DefaultDistributionLog distributionLog) {
    String serviceName = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(SERVICE_NAME), null));
    String[] allowedRoots = PropertiesUtil.toStringArray(config.get(ALLOWED_ROOTS), null);
    allowedRoots = SettingsUtils.removeEmptyEntries(allowedRoots);
    boolean queueProcessingEnabled = PropertiesUtil.toBoolean(config.get(QUEUE_PROCESSING_ENABLED), true);
    String[] passiveQueues = PropertiesUtil.toStringArray(config.get(PASSIVE_QUEUES), new String[0]);
    passiveQueues = SettingsUtils.removeEmptyEntries(passiveQueues, new String[0]);
    Map<String, String> priorityQueues = PropertiesUtil.toMap(config.get(PRIORITY_QUEUES), new String[0]);
    priorityQueues = SettingsUtils.removeEmptyEntries(priorityQueues);
    Integer timeout = PropertiesUtil.toInteger(HTTP, 10) * 1000;
    HttpConfiguration httpConfiguration = new HttpConfiguration(timeout);
    DistributionPackageExporter packageExporter = new LocalDistributionPackageExporter(packageBuilder);
    DistributionQueueProvider queueProvider;
    String queueProviderName = PropertiesUtil.toString(config.get(QUEUE_PROVIDER), JobHandlingDistributionQueueProvider.TYPE);
    if (JobHandlingDistributionQueueProvider.TYPE.equals(queueProviderName)) {
        queueProvider = new JobHandlingDistributionQueueProvider(agentName, jobManager, context, configAdmin);
    } else if (SimpleDistributionQueueProvider.TYPE.equals(queueProviderName)) {
        queueProvider = new SimpleDistributionQueueProvider(scheduler, agentName, false);
    } else {
        queueProvider = new SimpleDistributionQueueProvider(scheduler, agentName, true);
    }
    queueProvider = new MonitoringDistributionQueueProvider(queueProvider, context);
    DistributionQueueDispatchingStrategy exportQueueStrategy;
    DistributionQueueDispatchingStrategy errorQueueStrategy = null;
    DistributionPackageImporter packageImporter;
    Map<String, String> importerEndpointsMap = SettingsUtils.toUriMap(config.get(IMPORTER_ENDPOINTS));
    Set<String> processingQueues = new HashSet<String>();
    Set<String> endpointNames = importerEndpointsMap.keySet();
    Set<String> endpointsAndPassiveQueues = new TreeSet<String>();
    endpointsAndPassiveQueues.addAll(endpointNames);
    endpointsAndPassiveQueues.addAll(Arrays.asList(passiveQueues));
    // names of all the queues
    String[] queueNames = endpointsAndPassiveQueues.toArray(new String[endpointsAndPassiveQueues.size()]);
    if (priorityQueues != null) {
        PriorityQueueDispatchingStrategy dispatchingStrategy = new PriorityQueueDispatchingStrategy(priorityQueues, queueNames);
        Map<String, String> queueAliases = dispatchingStrategy.getMatchingQueues(null);
        importerEndpointsMap = SettingsUtils.expandUriMap(importerEndpointsMap, queueAliases);
        exportQueueStrategy = dispatchingStrategy;
        endpointNames = importerEndpointsMap.keySet();
    } else {
        boolean asyncDelivery = PropertiesUtil.toBoolean(config.get(ASYNC_DELIVERY), false);
        if (asyncDelivery) {
            // delivery queues' names
            Map<String, String> deliveryQueues = new HashMap<String, String>();
            for (String e : endpointNames) {
                deliveryQueues.put(e, "delivery-" + e);
            }
            processingQueues.addAll(deliveryQueues.values());
            exportQueueStrategy = new AsyncDeliveryDispatchingStrategy(deliveryQueues);
        } else {
            exportQueueStrategy = new MultipleQueueDispatchingStrategy(endpointNames.toArray(new String[endpointNames.size()]));
        }
    }
    processingQueues.addAll(endpointNames);
    processingQueues.removeAll(Arrays.asList(passiveQueues));
    packageImporter = new RemoteDistributionPackageImporter(distributionLog, transportSecretProvider, importerEndpointsMap, httpConfiguration);
    DistributionRequestType[] allowedRequests = new DistributionRequestType[] { DistributionRequestType.ADD, DistributionRequestType.DELETE };
    String retryStrategy = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(RETRY_STRATEGY), null));
    int retryAttepts = PropertiesUtil.toInteger(config.get(RETRY_ATTEMPTS), 100);
    if ("errorQueue".equals(retryStrategy)) {
        errorQueueStrategy = new ErrorQueueDispatchingStrategy(processingQueues.toArray(new String[processingQueues.size()]));
    }
    return new SimpleDistributionAgent(agentName, queueProcessingEnabled, processingQueues, serviceName, packageImporter, packageExporter, requestAuthorizationStrategy, queueProvider, exportQueueStrategy, errorQueueStrategy, distributionEventFactory, resourceResolverFactory, slingRepository, distributionLog, allowedRequests, allowedRoots, retryAttepts);
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) HashMap(java.util.HashMap) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) PriorityQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.PriorityQueueDispatchingStrategy) DistributionRequestType(org.apache.sling.distribution.DistributionRequestType) ErrorQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.ErrorQueueDispatchingStrategy) TreeSet(java.util.TreeSet) RemoteDistributionPackageImporter(org.apache.sling.distribution.packaging.impl.importer.RemoteDistributionPackageImporter) SimpleDistributionQueueProvider(org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueueProvider) HashSet(java.util.HashSet) MultipleQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.MultipleQueueDispatchingStrategy) LocalDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.LocalDistributionPackageExporter) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) LocalDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.LocalDistributionPackageExporter) AsyncDeliveryDispatchingStrategy(org.apache.sling.distribution.queue.impl.AsyncDeliveryDispatchingStrategy) MonitoringDistributionQueueProvider(org.apache.sling.distribution.monitor.impl.MonitoringDistributionQueueProvider) SimpleDistributionQueueProvider(org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueueProvider) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) RemoteDistributionPackageImporter(org.apache.sling.distribution.packaging.impl.importer.RemoteDistributionPackageImporter) MonitoringDistributionQueueProvider(org.apache.sling.distribution.monitor.impl.MonitoringDistributionQueueProvider)

Example 3 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider in project sling by apache.

the class QueueDistributionAgentFactory method createAgent.

@Override
protected SimpleDistributionAgent createAgent(String agentName, BundleContext context, Map<String, Object> config, DefaultDistributionLog distributionLog) {
    String serviceName = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(SERVICE_NAME), null));
    String[] allowedRoots = PropertiesUtil.toStringArray(config.get(ALLOWED_ROOTS), null);
    allowedRoots = SettingsUtils.removeEmptyEntries(allowedRoots);
    Map<String, String> priorityQueues = PropertiesUtil.toMap(config.get(PRIORITY_QUEUES), new String[0]);
    priorityQueues = SettingsUtils.removeEmptyEntries(priorityQueues);
    DistributionQueueProvider queueProvider = new MonitoringDistributionQueueProvider(new JobHandlingDistributionQueueProvider(agentName, jobManager, context), context);
    DistributionQueueDispatchingStrategy exportQueueStrategy = null;
    if (priorityQueues != null) {
        exportQueueStrategy = new PriorityQueueDispatchingStrategy(priorityQueues, new String[] { DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME });
    } else {
        exportQueueStrategy = new SingleQueueDispatchingStrategy();
    }
    DistributionPackageExporter packageExporter = new LocalDistributionPackageExporter(packageBuilder);
    DistributionRequestType[] allowedRequests = new DistributionRequestType[] { DistributionRequestType.ADD, DistributionRequestType.DELETE };
    return new SimpleDistributionAgent(agentName, false, null, serviceName, null, packageExporter, requestAuthorizationStrategy, queueProvider, exportQueueStrategy, null, distributionEventFactory, resourceResolverFactory, slingRepository, distributionLog, allowedRequests, allowedRoots, 0);
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) SingleQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.SingleQueueDispatchingStrategy) PriorityQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.PriorityQueueDispatchingStrategy) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) LocalDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.LocalDistributionPackageExporter) LocalDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.LocalDistributionPackageExporter) DistributionRequestType(org.apache.sling.distribution.DistributionRequestType) MonitoringDistributionQueueProvider(org.apache.sling.distribution.monitor.impl.MonitoringDistributionQueueProvider) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) MonitoringDistributionQueueProvider(org.apache.sling.distribution.monitor.impl.MonitoringDistributionQueueProvider)

Example 4 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider in project sling by apache.

the class QueueingDistributionPackageProcessorTest method testGetPackagesCount.

@Test
public void testGetPackagesCount() throws Exception {
    String callingUser = "mr-who-cares";
    String requestId = "id231";
    long startTime = System.currentTimeMillis();
    DistributionEventFactory eventFactory = mock(DistributionEventFactory.class);
    DistributionQueueDispatchingStrategy scheduleQueueStrategy = mock(DistributionQueueDispatchingStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    String agentName = "dummy";
    QueueingDistributionPackageProcessor exporterProcessor = new QueueingDistributionPackageProcessor(callingUser, requestId, startTime, eventFactory, scheduleQueueStrategy, queueProvider, log, agentName);
    int packagesCount = exporterProcessor.getPackagesCount();
    assertEquals(0, packagesCount);
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) Test(org.junit.Test)

Example 5 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider in project sling by apache.

the class QueueingDistributionPackageProcessorTest method testGetPackagesSize.

@Test
public void testGetPackagesSize() throws Exception {
    String callingUser = "mr-who-cares";
    String requestId = "id231";
    long startTime = System.currentTimeMillis();
    DistributionEventFactory eventFactory = mock(DistributionEventFactory.class);
    DistributionQueueDispatchingStrategy scheduleQueueStrategy = mock(DistributionQueueDispatchingStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    String agentName = "dummy";
    QueueingDistributionPackageProcessor exporterProcessor = new QueueingDistributionPackageProcessor(callingUser, requestId, startTime, eventFactory, scheduleQueueStrategy, queueProvider, log, agentName);
    long packagesSize = exporterProcessor.getPackagesSize();
    assertEquals(0L, packagesSize);
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) Test(org.junit.Test)

Aggregations

DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)25 Test (org.junit.Test)20 DistributionQueueDispatchingStrategy (org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy)17 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)13 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)13 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)13 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)13 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)12 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)12 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)9 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)8 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)8 SlingRepository (org.apache.sling.jcr.api.SlingRepository)8 SimpleDistributionQueue (org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueue)7 HashMap (java.util.HashMap)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 DistributionRequest (org.apache.sling.distribution.DistributionRequest)5 DistributionResponse (org.apache.sling.distribution.DistributionResponse)5 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)5 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)5