Search in sources :

Example 11 with DistributionPackageExporter

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

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

the class ReverseDistributionAgentFactory 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[] exporterEndpoints = PropertiesUtil.toStringArray(config.get(EXPORTER_ENDPOINTS), new String[0]);
    exporterEndpoints = SettingsUtils.removeEmptyEntries(exporterEndpoints);
    int pullItems = PropertiesUtil.toInteger(config.get(PULL_ITEMS), Integer.MAX_VALUE);
    Integer timeout = PropertiesUtil.toInteger(HTTP, 10) * 1000;
    HttpConfiguration httpConfiguration = new HttpConfiguration(timeout);
    DistributionPackageExporter packageExporter = new RemoteDistributionPackageExporter(distributionLog, packageBuilder, transportSecretProvider, exporterEndpoints, pullItems, httpConfiguration);
    DistributionPackageImporter packageImporter = new LocalDistributionPackageImporter(agentName, distributionEventFactory, packageBuilder);
    DistributionQueueProvider queueProvider = new MonitoringDistributionQueueProvider(new JobHandlingDistributionQueueProvider(agentName, jobManager, context), context);
    DistributionQueueDispatchingStrategy exportQueueStrategy = new SingleQueueDispatchingStrategy();
    DistributionQueueDispatchingStrategy importQueueStrategy = null;
    DistributionRequestType[] allowedRequests = new DistributionRequestType[] { DistributionRequestType.PULL };
    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, allowedRequests, null, 0);
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) LocalDistributionPackageImporter(org.apache.sling.distribution.packaging.impl.importer.LocalDistributionPackageImporter) RemoteDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.RemoteDistributionPackageExporter) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) SingleQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.SingleQueueDispatchingStrategy) RemoteDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.RemoteDistributionPackageExporter) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) 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) LocalDistributionPackageImporter(org.apache.sling.distribution.packaging.impl.importer.LocalDistributionPackageImporter) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) MonitoringDistributionQueueProvider(org.apache.sling.distribution.monitor.impl.MonitoringDistributionQueueProvider) HashSet(java.util.HashSet)

Example 13 with DistributionPackageExporter

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

the class SimpleDistributionAgentTest method testDistribution.

@Test
public void testDistribution() throws Exception {
    String name = "sample-agent";
    DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
    DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
    DistributionRequestAuthorizationStrategy requestAuthorizationStrategy = mock(DistributionRequestAuthorizationStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueueDispatchingStrategy dispatchingStrategy = mock(DistributionQueueDispatchingStrategy.class);
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    when(dispatchingStrategy.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(new ArrayList<DistributionQueueItemStatus>());
    SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", packageImporter, packageExporter, requestAuthorizationStrategy, queueProvider, dispatchingStrategy, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, null, 0);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    final DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionPackageInfo packageInfo = new DistributionPackageInfo("type");
    when(distributionPackage.getInfo()).thenReturn(packageInfo);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    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"));
    agent.execute(resourceResolver, request);
}
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) Test(org.junit.Test)

Example 14 with DistributionPackageExporter

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

the class SimpleDistributionAgentTest method testDistributionWithFailingDistributionStrategy.

@Test
public void testDistributionWithFailingDistributionStrategy() 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);
    Iterable<DistributionQueueItemStatus> states = Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME));
    when(distributionHandler.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(states);
    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);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    final DistributionPackage distributionPackage = mock(DistributionPackage.class);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
    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);
    assertNotNull(response);
    assertEquals("[ERROR]", response.getMessage());
    assertEquals(DistributionRequestState.DROPPED, response.getState());
}
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)

Example 15 with DistributionPackageExporter

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

the class SimpleDistributionAgentTest method testDistributionWithWorkingDistributionStrategy.

@Test
public void testDistributionWithWorkingDistributionStrategy() 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, "subServiceName", packageImporter, packageExporter, packageExporterStrategy, queueProvider, distributionHandler, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, null, 0);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    final DistributionPackage distributionPackage = mock(DistributionPackage.class);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
    Iterable<DistributionQueueItemStatus> states = Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME));
    when(distributionHandler.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(states);
    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);
    assertNotNull(response);
    assertEquals("[QUEUED]", response.getMessage());
    assertEquals(DistributionRequestState.ACCEPTED, response.getState());
}
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

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