Search in sources :

Example 1 with DistributionPackageBuilder

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

the class SimpleHttpDistributionTransportTest method testRetrievePackagesRemotelyFailing.

@Test
public void testRetrievePackagesRemotelyFailing() throws Exception {
    DistributionTransportSecret secret = mock(DistributionTransportSecret.class);
    Map<String, String> credentialsMap = new HashMap<String, String>();
    credentialsMap.put("username", "foo");
    credentialsMap.put("password", "foo");
    when(secret.asCredentialsMap()).thenReturn(credentialsMap);
    DistributionTransportSecretProvider secretProvider = mock(DistributionTransportSecretProvider.class);
    when(secretProvider.getSecret(any(URI.class))).thenReturn(secret);
    Executor executor = mock(Executor.class);
    Response response = mock(Response.class);
    HttpResponse httpResponse = mock(HttpResponse.class);
    StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(404);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    when(response.returnResponse()).thenReturn(httpResponse);
    when(executor.execute(any(Request.class))).thenReturn(response);
    DistributionEndpoint endpoint = new DistributionEndpoint("http://127.0.0.1:8080/some/resource");
    DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
    SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), endpoint, packageBuilder, secretProvider, new HttpConfiguration(1000, 1000));
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    RemoteDistributionPackage retrievedPackage = simpleHttpDistributionTransport.retrievePackage(resourceResolver, distributionRequest, new DistributionTransportContext());
    assertNull(retrievedPackage);
}
Also used : HashMap(java.util.HashMap) Request(org.apache.http.client.fluent.Request) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) HttpResponse(org.apache.http.HttpResponse) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) URI(java.net.URI) HttpResponse(org.apache.http.HttpResponse) Response(org.apache.http.client.fluent.Response) StatusLine(org.apache.http.StatusLine) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionTransportSecret(org.apache.sling.distribution.transport.DistributionTransportSecret) Executor(org.apache.http.client.fluent.Executor) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 2 with DistributionPackageBuilder

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

the class SimpleHttpDistributionTransportTest method testRetrievePackagesRemotelyWorking.

@Test
public void testRetrievePackagesRemotelyWorking() throws Exception {
    DistributionTransportSecret secret = mock(DistributionTransportSecret.class);
    Map<String, String> credentialsMap = new HashMap<String, String>();
    credentialsMap.put("username", "foo");
    credentialsMap.put("password", "foo");
    when(secret.asCredentialsMap()).thenReturn(credentialsMap);
    DistributionTransportSecretProvider secretProvider = mock(DistributionTransportSecretProvider.class);
    when(secretProvider.getSecret(any(URI.class))).thenReturn(secret);
    Executor executor = mock(Executor.class);
    Response response = mock(Response.class);
    HttpResponse httpResponse = mock(HttpResponse.class);
    StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(200);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    HttpEntity entity = mock(HttpEntity.class);
    InputStream stream = new ByteArrayInputStream("package binary stuff".getBytes("UTF-8"));
    when(entity.getContent()).thenReturn(stream);
    when(httpResponse.getEntity()).thenReturn(entity);
    when(response.returnResponse()).thenReturn(httpResponse);
    when(executor.execute(any(Request.class))).thenReturn(response);
    DistributionEndpoint endpoint = new DistributionEndpoint("http://127.0.0.1:8080/some/resource");
    DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
    when(packageBuilder.readPackage(any(ResourceResolver.class), any(InputStream.class))).thenReturn(distributionPackage);
    SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), endpoint, packageBuilder, secretProvider, new HttpConfiguration(1000, 1000));
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    DistributionTransportContext distributionContext = mock(DistributionTransportContext.class);
    when(distributionContext.get(any(String.class), same(Executor.class))).thenReturn(executor);
    when(distributionContext.containsKey(any(String.class))).thenReturn(true);
    RemoteDistributionPackage retrievedPackage = simpleHttpDistributionTransport.retrievePackage(resourceResolver, distributionRequest, distributionContext);
    assertNotNull(retrievedPackage);
}
Also used : DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) URI(java.net.URI) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionTransportSecret(org.apache.sling.distribution.transport.DistributionTransportSecret) Executor(org.apache.http.client.fluent.Executor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(org.apache.http.client.fluent.Request) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) HttpResponse(org.apache.http.HttpResponse) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) HttpResponse(org.apache.http.HttpResponse) Response(org.apache.http.client.fluent.Response) StatusLine(org.apache.http.StatusLine) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 3 with DistributionPackageBuilder

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

the class KryoContentSerializerTest method testBuildAndInstallOnSingleDeepPath.

@Test
public void testBuildAndInstallOnSingleDeepPath() throws Exception {
    String type = "kryo";
    DistributionContentSerializer contentSerializer = new KryoContentSerializer(type);
    String tempFilesFolder = "target";
    String[] nodeFilters = new String[0];
    String[] propertyFilters = new String[0];
    DistributionPackageBuilder packageBuilder = new FileDistributionPackageBuilder(type, contentSerializer, tempFilesFolder, null, nodeFilters, propertyFilters);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, true, "/libs");
    DistributionPackage distributionPackage = packageBuilder.createPackage(resourceResolver, request);
    Resource resource = resourceResolver.getResource("/libs/sub");
    resourceResolver.delete(resource);
    resourceResolver.commit();
    assertTrue(packageBuilder.installPackage(resourceResolver, distributionPackage));
    assertNotNull(resourceResolver.getResource("/libs"));
    assertNotNull(resourceResolver.getResource("/libs/sub"));
    assertNotNull(resourceResolver.getResource("/libs/sameLevel"));
}
Also used : FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) Resource(org.apache.sling.api.resource.Resource) DistributionContentSerializer(org.apache.sling.distribution.serialization.DistributionContentSerializer) Test(org.junit.Test)

Example 4 with DistributionPackageBuilder

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

the class AgentDistributionPackageExporter method getPackage.

public DistributionPackage getPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull String distributionPackageId) {
    try {
        log.debug("getting package from queue {}", queueName);
        DistributionQueue queue = getQueueOrThrow(queueName);
        DistributionQueueEntry entry = queue.getItem(distributionPackageId);
        DistributionPackage distributionPackage;
        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());
                distributionPackage.getInfo().putAll(info);
                log.debug("item {} fetched from the queue", info);
                if (distributionPackage != null) {
                    return new AgentDistributionPackage(distributionPackage, queue, entry.getId());
                }
            } else {
                log.warn("cannot find package builder with type {}", info.getType());
            }
        }
    } catch (Exception ex) {
        log.error("Error exporting package", ex);
    }
    return null;
}
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) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) DistributionException(org.apache.sling.distribution.common.DistributionException)

Example 5 with DistributionPackageBuilder

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

the class VaultDistributionPackageBuilderFactory method activate.

@Activate
public void activate(BundleContext context, Map<String, Object> config) {
    String name = PropertiesUtil.toString(config.get(NAME), null);
    String type = PropertiesUtil.toString(config.get(TYPE), null);
    String importModeString = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(IMPORT_MODE), null));
    String aclHandlingString = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(ACL_HANDLING), null));
    String[] packageRoots = SettingsUtils.removeEmptyEntries(PropertiesUtil.toStringArray(config.get(PACKAGE_ROOTS), null));
    String[] packageNodeFilters = SettingsUtils.removeEmptyEntries(PropertiesUtil.toStringArray(config.get(PACKAGE_FILTERS), null));
    String[] packagePropertyFilters = SettingsUtils.removeEmptyEntries(PropertiesUtil.toStringArray(config.get(PROPERTY_FILTERS), null));
    long cleanupDelay = PropertiesUtil.toLong(config.get(PACKAGE_CLEANUP_DELAY), DEFAULT_PACKAGE_CLEANUP_DELAY);
    String tempFsFolder = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(TEMP_FS_FOLDER), null));
    boolean useBinaryReferences = PropertiesUtil.toBoolean(config.get(USE_BINARY_REFERENCES), false);
    int autosaveThreshold = PropertiesUtil.toInteger(config.get(AUTOSAVE_THRESHOLD), -1);
    String digestAlgorithm = PropertiesUtil.toString(config.get(DIGEST_ALGORITHM), DEFAULT_DIGEST_ALGORITHM);
    if (DEFAULT_DIGEST_ALGORITHM.equals(digestAlgorithm)) {
        digestAlgorithm = null;
    }
    ImportMode importMode = null;
    if (importModeString != null) {
        importMode = ImportMode.valueOf(importModeString.trim());
    }
    AccessControlHandling aclHandling = null;
    if (aclHandlingString != null) {
        aclHandling = AccessControlHandling.valueOf(aclHandlingString.trim());
    }
    DistributionContentSerializer contentSerializer = new FileVaultContentSerializer(name, packaging, importMode, aclHandling, packageRoots, packageNodeFilters, packagePropertyFilters, useBinaryReferences, autosaveThreshold);
    DistributionPackageBuilder wrapped;
    if ("filevlt".equals(type)) {
        wrapped = new FileDistributionPackageBuilder(name, contentSerializer, tempFsFolder, digestAlgorithm, packageNodeFilters, packagePropertyFilters);
    } else {
        final int fileThreshold = PropertiesUtil.toInteger(config.get(FILE_THRESHOLD), DEFAULT_FILE_THRESHOLD_VALUE);
        String memoryUnitName = PropertiesUtil.toString(config.get(MEMORY_UNIT), DEFAULT_MEMORY_UNIT);
        final MemoryUnit memoryUnit = MemoryUnit.valueOf(memoryUnitName);
        final boolean useOffHeapMemory = PropertiesUtil.toBoolean(config.get(USE_OFF_HEAP_MEMORY), DEFAULT_USE_OFF_HEAP_MEMORY);
        ResourceDistributionPackageBuilder resourceDistributionPackageBuilder = new ResourceDistributionPackageBuilder(contentSerializer.getName(), contentSerializer, tempFsFolder, fileThreshold, memoryUnit, useOffHeapMemory, digestAlgorithm, packageNodeFilters, packagePropertyFilters);
        Runnable cleanup = new ResourceDistributionPackageCleanup(resolverFactory, resourceDistributionPackageBuilder);
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(Scheduler.PROPERTY_SCHEDULER_CONCURRENT, false);
        props.put(Scheduler.PROPERTY_SCHEDULER_PERIOD, cleanupDelay);
        packageCleanup = context.registerService(Runnable.class.getName(), cleanup, props);
        wrapped = resourceDistributionPackageBuilder;
    }
    int monitoringQueueSize = PropertiesUtil.toInteger(config.get(MONITORING_QUEUE_SIZE), DEFAULT_MONITORING_QUEUE_SIZE);
    packageBuilder = new MonitoringDistributionPackageBuilder(monitoringQueueSize, wrapped, context);
}
Also used : ResourceDistributionPackageCleanup(org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageCleanup) AccessControlHandling(org.apache.jackrabbit.vault.fs.io.AccessControlHandling) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) MemoryUnit(org.apache.sling.distribution.util.impl.FileBackedMemoryOutputStream.MemoryUnit) ResourceDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageBuilder) Hashtable(java.util.Hashtable) DistributionContentSerializer(org.apache.sling.distribution.serialization.DistributionContentSerializer) MonitoringDistributionPackageBuilder(org.apache.sling.distribution.monitor.impl.MonitoringDistributionPackageBuilder) ImportMode(org.apache.jackrabbit.vault.fs.api.ImportMode) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageBuilder) MonitoringDistributionPackageBuilder(org.apache.sling.distribution.monitor.impl.MonitoringDistributionPackageBuilder)

Aggregations

DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)20 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)16 Test (org.junit.Test)15 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)12 DistributionRequest (org.apache.sling.distribution.DistributionRequest)11 FileDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder)10 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)9 DistributionContentSerializer (org.apache.sling.distribution.serialization.DistributionContentSerializer)7 Resource (org.apache.sling.api.resource.Resource)6 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)5 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)5 DistributionTransportSecretProvider (org.apache.sling.distribution.transport.DistributionTransportSecretProvider)5 InputStream (java.io.InputStream)3 URI (java.net.URI)3 HashMap (java.util.HashMap)3 HttpResponse (org.apache.http.HttpResponse)3 Executor (org.apache.http.client.fluent.Executor)3 Request (org.apache.http.client.fluent.Request)3 Response (org.apache.http.client.fluent.Response)3 DistributionException (org.apache.sling.distribution.common.DistributionException)3