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