Search in sources :

Example 1 with DistributionPackageImporter

use of org.apache.sling.distribution.packaging.DistributionPackageImporter in project sling by apache.

the class SyncDistributionAgentFactory 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);
    String[] passiveQueues = PropertiesUtil.toStringArray(config.get(PASSIVE_QUEUES), new String[0]);
    passiveQueues = SettingsUtils.removeEmptyEntries(passiveQueues, new String[0]);
    Object exporterEndpointsValue = config.get(EXPORTER_ENDPOINTS);
    Object importerEndpointsValue = config.get(IMPORTER_ENDPOINTS);
    String[] exporterEndpoints = PropertiesUtil.toStringArray(exporterEndpointsValue, new String[0]);
    exporterEndpoints = SettingsUtils.removeEmptyEntries(exporterEndpoints);
    Map<String, String> importerEndpointsMap = SettingsUtils.toUriMap(importerEndpointsValue);
    int pullItems = PropertiesUtil.toInteger(config.get(PULL_ITEMS), Integer.MAX_VALUE);
    DistributionQueueDispatchingStrategy exportQueueStrategy;
    DistributionQueueDispatchingStrategy importQueueStrategy = null;
    DistributionPackageImporter packageImporter;
    Set<String> processingQueues = new HashSet<String>();
    Set<String> queuesMap = new TreeSet<String>();
    queuesMap.addAll(importerEndpointsMap.keySet());
    queuesMap.addAll(Arrays.asList(passiveQueues));
    processingQueues.addAll(importerEndpointsMap.keySet());
    processingQueues.removeAll(Arrays.asList(passiveQueues));
    String[] queueNames = queuesMap.toArray(new String[queuesMap.size()]);
    exportQueueStrategy = new MultipleQueueDispatchingStrategy(queueNames);
    Integer timeout = PropertiesUtil.toInteger(HTTP, 10) * 1000;
    HttpConfiguration httpConfiguration = new HttpConfiguration(timeout);
    packageImporter = new RemoteDistributionPackageImporter(distributionLog, transportSecretProvider, importerEndpointsMap, httpConfiguration);
    DistributionPackageExporter packageExporter = new RemoteDistributionPackageExporter(distributionLog, packageBuilder, transportSecretProvider, exporterEndpoints, pullItems, httpConfiguration);
    DistributionQueueProvider queueProvider = new MonitoringDistributionQueueProvider(new JobHandlingDistributionQueueProvider(agentName, jobManager, context), context);
    DistributionRequestType[] allowedRequests = new DistributionRequestType[] { DistributionRequestType.PULL };
    String retryStrategy = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(RETRY_STRATEGY), null));
    int retryAttepts = PropertiesUtil.toInteger(config.get(RETRY_ATTEMPTS), 100);
    if ("errorQueue".equals(retryStrategy)) {
        importQueueStrategy = new ErrorQueueDispatchingStrategy(processingQueues.toArray(new String[processingQueues.size()]));
    }
    return new SimpleDistributionAgent(agentName, queueProcessingEnabled, processingQueues, serviceName, packageImporter, packageExporter, requestAuthorizationStrategy, queueProvider, exportQueueStrategy, importQueueStrategy, distributionEventFactory, resourceResolverFactory, slingRepository, distributionLog, allowedRequests, null, retryAttepts);
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) RemoteDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.RemoteDistributionPackageExporter) MultipleQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.MultipleQueueDispatchingStrategy) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) RemoteDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.RemoteDistributionPackageExporter) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionRequestType(org.apache.sling.distribution.DistributionRequestType) ErrorQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.ErrorQueueDispatchingStrategy) RemoteDistributionPackageImporter(org.apache.sling.distribution.packaging.impl.importer.RemoteDistributionPackageImporter) MonitoringDistributionQueueProvider(org.apache.sling.distribution.monitor.impl.MonitoringDistributionQueueProvider) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) RemoteDistributionPackageImporter(org.apache.sling.distribution.packaging.impl.importer.RemoteDistributionPackageImporter) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) MonitoringDistributionQueueProvider(org.apache.sling.distribution.monitor.impl.MonitoringDistributionQueueProvider)

Example 2 with DistributionPackageImporter

use of org.apache.sling.distribution.packaging.DistributionPackageImporter 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 DistributionPackageImporter

use of org.apache.sling.distribution.packaging.DistributionPackageImporter in project sling by apache.

the class SimpleDistributionAgentQueueProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
    DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
    int retryAttempts = 3;
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionEventFactory eventFactory = mock(DistributionEventFactory.class);
    SimpleDistributionAgentAuthenticationInfo authenticationInfo = mock(SimpleDistributionAgentAuthenticationInfo.class);
    String agentName = "dummy-a";
    SimpleDistributionAgentQueueProcessor queueProcessor = new SimpleDistributionAgentQueueProcessor(packageExporter, packageImporter, retryAttempts, null, log, queueProvider, eventFactory, authenticationInfo, agentName);
    String id = "123-456";
    DistributionQueueItem item = new DistributionQueueItem("pckg-123", new HashMap<String, Object>());
    String queueName = "queue-1";
    DistributionQueueItemStatus status = new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, queueName);
    DistributionQueueEntry entry = new DistributionQueueEntry(id, item, status);
    queueProcessor.process(queueName, entry);
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) Test(org.junit.Test)

Example 4 with DistributionPackageImporter

use of org.apache.sling.distribution.packaging.DistributionPackageImporter in project sling by apache.

the class SimpleDistributionAgentTest method testGetNonExistingNamedQueue.

@Test
public void testGetNonExistingNamedQueue() throws Exception {
    String name = "sample-agent";
    DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
    DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
    DistributionRequestAuthorizationStrategy packageExporterStrategy = mock(DistributionRequestAuthorizationStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueueDispatchingStrategy distributionHandler = mock(DistributionQueueDispatchingStrategy.class);
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", packageImporter, packageExporter, packageExporterStrategy, queueProvider, distributionHandler, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, null, 0);
    DistributionQueue queue = mock(DistributionQueue.class);
    when(queueProvider.getQueue("priority")).thenReturn(queue);
    assertNull(agent.getQueue("weird"));
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) SimpleDistributionQueue(org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueue) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) Test(org.junit.Test)

Example 5 with DistributionPackageImporter

use of org.apache.sling.distribution.packaging.DistributionPackageImporter in project sling by apache.

the class SimpleDistributionAgentTest method testDistributionWithDisallowedRoot.

@Test
public void testDistributionWithDisallowedRoot() throws Exception {
    String name = "sample-agent";
    DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
    DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
    DistributionRequestAuthorizationStrategy packageExporterStrategy = mock(DistributionRequestAuthorizationStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueueDispatchingStrategy queueDistributionStrategy = mock(DistributionQueueDispatchingStrategy.class);
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    when(queueDistributionStrategy.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, "default")));
    SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", packageImporter, packageExporter, packageExporterStrategy, queueProvider, queueDistributionStrategy, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, new String[] { "/content" }, 0);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/home");
    final DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionPackageInfo packageInfo = new DistributionPackageInfo("type");
    when(distributionPackage.getInfo()).thenReturn(packageInfo);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    queueDistributionStrategy.add(distributionPackage, queueProvider);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            ((DistributionPackageProcessor) args[2]).process(distributionPackage);
            return null;
        }
    }).when(packageExporter).exportPackages(any(ResourceResolver.class), any(DistributionRequest.class), any(DistributionPackageProcessor.class));
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(new SimpleDistributionQueue(name, "name"));
    DistributionResponse response = agent.execute(resourceResolver, request);
    assertFalse(response.isSuccessful());
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) SimpleDistributionQueue(org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueue) SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionPackageProcessor(org.apache.sling.distribution.packaging.DistributionPackageProcessor) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) DistributionResponse(org.apache.sling.distribution.DistributionResponse) Test(org.junit.Test)

Aggregations

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