Search in sources :

Example 11 with DefaultDistributionLog

use of org.apache.sling.distribution.log.impl.DefaultDistributionLog in project sling by apache.

the class ImportingDistributionPackageProcessorTest method testGetPackagesSize.

@Test
public void testGetPackagesSize() 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);
    assertEquals(0, processor.getPackagesSize());
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) Test(org.junit.Test)

Example 12 with DefaultDistributionLog

use of org.apache.sling.distribution.log.impl.DefaultDistributionLog in project sling by apache.

the class AbstractDistributionAgentFactory method activate.

void activate(BundleContext context, Map<String, Object> config) {
    log.info("activating with config {}", OsgiUtils.osgiPropertyMapToString(config));
    // inject configuration
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    boolean enabled = PropertiesUtil.toBoolean(config.get(ENABLED), true);
    String triggersTarget = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(TRIGGERS_TARGET), null));
    triggersEnabled = triggersTarget != null && triggersTarget.trim().length() > 0;
    agentName = PropertiesUtil.toString(config.get(NAME), null);
    if (enabled && agentName != null) {
        for (Map.Entry<String, Object> entry : config.entrySet()) {
            // skip service and component related properties
            if (entry.getKey().startsWith("service.") || entry.getKey().startsWith("component.")) {
                continue;
            }
            props.put(entry.getKey(), entry.getValue());
        }
        if (componentReg == null) {
            DefaultDistributionLog distributionLog = null;
            try {
                String logLevel = PropertiesUtil.toString(config.get(LOG_LEVEL), DefaultDistributionLog.LogLevel.INFO.name());
                DefaultDistributionLog.LogLevel level = DefaultDistributionLog.LogLevel.valueOf(logLevel.trim().toUpperCase());
                if (level == null) {
                    level = DefaultDistributionLog.LogLevel.INFO;
                }
                distributionLog = new DefaultDistributionLog(DistributionComponentKind.AGENT, agentName, SimpleDistributionAgent.class, level);
                agent = createAgent(agentName, context, config, distributionLog);
            } catch (Throwable t) {
                if (distributionLog != null) {
                    distributionLog.error("Cannot create agent", t);
                }
                log.error("Cannot create agent {}", OsgiUtils.osgiPropertyMapToString(config), t);
            }
            if (agent != null) {
                // register agent service
                componentReg = context.registerService(DistributionAgent.class.getName(), agent, props);
                agent.enable();
                if (triggersEnabled) {
                    for (DistributionTrigger trigger : triggers) {
                        agent.enableTrigger(trigger);
                    }
                }
                Dictionary<String, String> mbeanProps = new Hashtable<String, String>();
                mbeanProps.put("jmx.objectname", "org.apache.sling.distribution:type=agent,id=" + ObjectName.quote(agentName));
                DistributionAgentMBeanType mbean = createMBeanAgent(agent, config);
                mbeanServiceRegistration = context.registerService(distributionAgentMBeanType.getName(), mbean, mbeanProps);
            }
            log.info("activated agent {}", agentName);
        }
    }
}
Also used : Hashtable(java.util.Hashtable) DistributionTrigger(org.apache.sling.distribution.trigger.DistributionTrigger) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) Map(java.util.Map)

Example 13 with DefaultDistributionLog

use of org.apache.sling.distribution.log.impl.DefaultDistributionLog in project sling by apache.

the class RemoteDistributionPackageImporterFactory method activate.

@Activate
protected void activate(Map<String, Object> config) {
    Map<String, String> endpoints = SettingsUtils.toUriMap(config.get(ENDPOINTS));
    String importerName = PropertiesUtil.toString(config.get(NAME), null);
    DefaultDistributionLog distributionLog = new DefaultDistributionLog(DistributionComponentKind.IMPORTER, importerName, RemoteDistributionPackageImporter.class, DefaultDistributionLog.LogLevel.ERROR);
    // default to 10s, we can expose it if needed
    HttpConfiguration httpConfiguration = new HttpConfiguration(10000);
    importer = new RemoteDistributionPackageImporter(distributionLog, transportSecretProvider, endpoints, httpConfiguration);
}
Also used : DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) Activate(org.apache.felix.scr.annotations.Activate)

Example 14 with DefaultDistributionLog

use of org.apache.sling.distribution.log.impl.DefaultDistributionLog in project sling by apache.

the class TriggerAgentRequestHandlerTest method testHandleActive.

@Test
public void testHandleActive() throws Exception {
    DistributionAgent agent = mock(DistributionAgent.class);
    SimpleDistributionAgentAuthenticationInfo authenticationInfo = mock(SimpleDistributionAgentAuthenticationInfo.class);
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    TriggerAgentRequestHandler triggerAgentRequestHandler = new TriggerAgentRequestHandler(agent, authenticationInfo, log, true);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionRequest request = mock(DistributionRequest.class);
    triggerAgentRequestHandler.handle(resourceResolver, request);
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) Test(org.junit.Test)

Aggregations

DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)14 Test (org.junit.Test)11 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)5 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)5 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)5 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)4 DistributionQueueDispatchingStrategy (org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy)4 SlingRepository (org.apache.sling.jcr.api.SlingRepository)4 Activate (org.apache.felix.scr.annotations.Activate)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 DistributionRequest (org.apache.sling.distribution.DistributionRequest)2 DistributionAgent (org.apache.sling.distribution.agent.DistributionAgent)2 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)2 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)2 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)2 HttpConfiguration (org.apache.sling.distribution.transport.impl.HttpConfiguration)2 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1