Search in sources :

Example 16 with DistributionPackageInfo

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

the class ImportingDistributionPackageProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    DistributionPackageImporter importer = mock(DistributionPackageImporter.class);
    SlingRepository repository = mock(SlingRepository.class);
    String agentService = "agentService";
    ResourceResolverFactory resourceResolverFactory = mock(ResourceResolverFactory.class);
    String subServiceName = "ssn";
    SimpleDistributionAgentAuthenticationInfo authInfo = new SimpleDistributionAgentAuthenticationInfo(repository, agentService, resourceResolverFactory, subServiceName);
    String callingUser = "foo";
    String requestId = "123";
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    ImportingDistributionPackageProcessor processor = new ImportingDistributionPackageProcessor(importer, authInfo, callingUser, requestId, log);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, "/");
    map.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.TEST);
    DistributionPackageInfo info = new DistributionPackageInfo("foo", map);
    when(distributionPackage.getInfo()).thenReturn(info);
    processor.process(distributionPackage);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) Test(org.junit.Test)

Example 17 with DistributionPackageInfo

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

the class DistributionPackageMBeanTest method verifyMBeanExposedValues.

@Test
public void verifyMBeanExposedValues() {
    String type = "jcrvlt";
    long processingTime = 2000L;
    Map<String, Object> base = new HashMap<String, Object>();
    base.put(PROPERTY_REQUEST_PATHS, new String[] { "a", "b", "c" });
    base.put(PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD);
    DistributionPackageInfo distributionPackageInfo = new DistributionPackageInfo(type, base);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getId()).thenReturn("#distributionPackage");
    when(distributionPackage.getSize()).thenReturn(1000L);
    when(distributionPackage.getInfo()).thenReturn(distributionPackageInfo);
    DistributionPackageMBean mBean = new DistributionPackageMBeanImpl(distributionPackage, type, processingTime);
    assertEquals(distributionPackage.getId(), mBean.getId());
    assertEquals(type, mBean.getType());
    assertArrayEquals(distributionPackageInfo.getPaths(), mBean.getPaths());
    assertEquals(distributionPackageInfo.getRequestType().name().toLowerCase(), mBean.getRequestType());
    assertEquals(distributionPackage.getSize(), mBean.getSize());
    assertEquals(processingTime, mBean.getProcessingTime());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 18 with DistributionPackageInfo

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

the class PriorityQueueDispatchingStrategyTest method testNoMatchingDispatching.

@Test
public void testNoMatchingDispatching() throws Exception {
    PriorityQueueDispatchingStrategy dispatchingStrategy = new PriorityQueueDispatchingStrategy(selectors, queueNames);
    DistributionPackage distributionPackage = mock(SharedDistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/content/other" });
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("vlt", properties));
    DistributionQueue other1 = mock(DistributionQueue.class);
    when(other1.getName()).thenReturn("publish1");
    when(queueProvider.getQueue("publish1")).thenReturn(other1);
    DistributionQueue other2 = mock(DistributionQueue.class);
    when(other2.getName()).thenReturn("publish2");
    when(queueProvider.getQueue("publish2")).thenReturn(other2);
    dispatchingStrategy.add(distributionPackage, queueProvider);
    verify(queueProvider).getQueue("publish1");
    verify(queueProvider).getQueue("publish2");
    verifyNoMoreInteractions(queueProvider);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) SharedDistributionPackage(org.apache.sling.distribution.packaging.impl.SharedDistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) Test(org.junit.Test)

Example 19 with DistributionPackageInfo

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

the class AgentDistributionPackageExporter method exportPackages.

public void exportPackages(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest, @Nonnull DistributionPackageProcessor packageProcessor) throws DistributionException {
    if (DistributionRequestType.TEST.equals(distributionRequest.getRequestType())) {
        packageProcessor.process(new SimpleDistributionPackage(distributionRequest, PACKAGE_TYPE));
        return;
    }
    if (!DistributionRequestType.PULL.equals(distributionRequest.getRequestType())) {
        throw new DistributionException("request type not supported " + distributionRequest.getRequestType());
    }
    DistributionPackage distributionPackage = null;
    try {
        log.debug("getting packages from queue {}", queueName);
        DistributionQueue queue = getQueueOrThrow(queueName);
        DistributionQueueEntry entry = queue.getHead();
        if (entry != null) {
            DistributionQueueItem queueItem = entry.getItem();
            DistributionPackageInfo info = DistributionPackageUtils.fromQueueItem(queueItem);
            DistributionPackageBuilder packageBuilder = packageBuilderProvider.getPackageBuilder(info.getType());
            if (packageBuilder != null) {
                distributionPackage = packageBuilder.getPackage(resourceResolver, queueItem.getPackageId());
                if (distributionPackage != null) {
                    distributionPackage.getInfo().putAll(info);
                    log.debug("item {} fetched from the queue", info);
                    packageProcessor.process(new AgentDistributionPackage(distributionPackage, queue, entry.getId()));
                } else {
                    log.warn("cannot get package {}", info);
                }
            } else {
                log.warn("cannot find package builder with type {}", info.getType());
            }
        }
    } catch (Exception ex) {
        log.error("Error exporting package", ex);
    } finally {
        DistributionPackageUtils.closeSafely(distributionPackage);
    }
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) DistributionException(org.apache.sling.distribution.common.DistributionException) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) DistributionException(org.apache.sling.distribution.common.DistributionException)

Example 20 with DistributionPackageInfo

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

the class LocalDistributionPackageImporter method importStream.

@Override
@Nonnull
public DistributionPackageInfo importStream(@Nonnull ResourceResolver resourceResolver, @Nonnull InputStream stream) throws DistributionException {
    if (!stream.markSupported()) {
        stream = new BufferedInputStream(stream);
    }
    Map<String, Object> headerInfo = new HashMap<String, Object>();
    DistributionPackageUtils.readInfo(stream, headerInfo);
    log.debug("header info: {}", headerInfo);
    Object o = headerInfo.get(DistributionPackageUtils.PROPERTY_REMOTE_PACKAGE_ID);
    String reference = o != null ? String.valueOf(o) : null;
    if (reference != null) {
        if (ReferencePackage.isReference(reference)) {
            String actualPackageId = ReferencePackage.idFromReference(reference);
            if (actualPackageId != null) {
                log.info("installing from reference {}", actualPackageId);
                DistributionPackage distributionPackage = packageBuilder.getPackage(resourceResolver, actualPackageId);
                if (distributionPackage != null) {
                    if (packageBuilder.installPackage(resourceResolver, distributionPackage)) {
                        DistributionPackageInfo info = distributionPackage.getInfo();
                        log.info("package installed {}", info);
                        eventFactory.generatePackageEvent(DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED, DistributionComponentKind.IMPORTER, name, info);
                        return info;
                    } else {
                        throw new DistributionException("could not install package {}" + distributionPackage);
                    }
                } else {
                    throw new DistributionException("could not install package from reference " + actualPackageId);
                }
            } else {
                throw new DistributionException("could not install package from invalid reference " + reference);
            }
        } else {
            try {
                // TODO : see if this can be removed entirely
                stream.reset();
            } catch (IOException e) {
            // do nothing
            }
            DistributionPackageInfo packageInfo;
            Object rr = headerInfo.get("reference-required");
            boolean store = rr != null && Boolean.valueOf(rr.toString());
            if (store) {
                log.debug("storing actual package");
                DistributionPackage distributionPackage = packageBuilder.readPackage(resourceResolver, stream);
                packageInfo = distributionPackage.getInfo();
                log.info("package stored {}", packageInfo);
            } else {
                packageInfo = packageBuilder.installPackage(resourceResolver, stream);
                log.info("package installed {}", packageInfo);
            }
            eventFactory.generatePackageEvent(DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED, DistributionComponentKind.IMPORTER, name, packageInfo);
            return packageInfo;
        }
    } else {
        DistributionPackageInfo packageInfo = packageBuilder.installPackage(resourceResolver, stream);
        log.info("package installed");
        eventFactory.generatePackageEvent(DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED, DistributionComponentKind.IMPORTER, name, packageInfo);
        return packageInfo;
    }
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) BufferedInputStream(java.io.BufferedInputStream) HashMap(java.util.HashMap) DistributionException(org.apache.sling.distribution.common.DistributionException) IOException(java.io.IOException) Nonnull(javax.annotation.Nonnull)

Aggregations

DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)35 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)25 Test (org.junit.Test)25 HashMap (java.util.HashMap)12 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)10 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)9 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)9 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)9 DistributionRequest (org.apache.sling.distribution.DistributionRequest)8 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)7 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)7 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)7 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)7 InputStream (java.io.InputStream)6 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)6 DistributionException (org.apache.sling.distribution.common.DistributionException)6 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)6 DistributionQueueDispatchingStrategy (org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy)6 SlingRepository (org.apache.sling.jcr.api.SlingRepository)6 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)5