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