diff --git a/CHANGELOG.md b/CHANGELOG.md index 5392a0591..a7fbc6bca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to AET will be documented in this file. ## Unreleased **List of changes that are finished but not yet released in any final version.** +- [PR-326](https://github.com/Cognifide/aet/pull/326) ([PR-308](https://github.com/Cognifide/aet/pull/308), [PR-310](https://github.com/Cognifide/aet/pull/310), [PR-311](https://github.com/Cognifide/aet/pull/311), [PR-312](https://github.com/Cognifide/aet/pull/312), [PR-313](https://github.com/Cognifide/aet/pull/313), [PR-314](https://github.com/Cognifide/aet/pull/314), [PR-315](https://github.com/Cognifide/aet/pull/315), [PR-316](https://github.com/Cognifide/aet/pull/316), [PR-322](https://github.com/Cognifide/aet/pull/322)) - updated OSGi annotations to 6.0.0 OSGi standard - [PR-293](https://github.com/Cognifide/aet/pull/293) Added error treshold in pixels and percentages for screen comparator - [PR-300](https://github.com/Cognifide/aet/pull/300) Added creating indexes for collection - [PR-289](https://github.com/Cognifide/aet/pull/289) User now stays on the same tab while navigating between URLs diff --git a/core/cleaner/pom.xml b/core/cleaner/pom.xml index a22e6cdb8..7c7bbd67c 100644 --- a/core/cleaner/pom.xml +++ b/core/cleaner/pom.xml @@ -56,8 +56,16 @@ - org.apache.felix - org.apache.felix.scr.annotations + org.osgi + org.osgi.service.component.annotations + + + org.osgi + org.osgi.annotation + + + org.osgi + org.osgi.service.metatype.annotations com.google.guava @@ -71,10 +79,6 @@ org.apache.activemq activemq-osgi - - org.apache.felix - org.apache.felix.configadmin - org.apache.servicemix.bundles org.apache.servicemix.bundles.quartz @@ -87,10 +91,6 @@ joda-time joda-time - - org.apache.sling - org.apache.sling.commons.osgi - junit diff --git a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/CleanerScheduler.java b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/CleanerScheduler.java index 51c84e488..23a621ef2 100644 --- a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/CleanerScheduler.java +++ b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/CleanerScheduler.java @@ -15,22 +15,20 @@ */ package com.cognifide.aet.cleaner; +import com.cognifide.aet.cleaner.configuration.CleanerSchedulerConf; import com.cognifide.aet.cleaner.route.MetadataCleanerRouteBuilder; import com.cognifide.aet.cleaner.validation.CleanerSchedulerValidator; import com.cognifide.aet.validation.ValidationResultBuilder; import com.cognifide.aet.validation.ValidationResultBuilderFactory; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; -import java.util.Map; import java.util.UUID; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.ConfigurationPolicy; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; import org.quartz.CronScheduleBuilder; import org.quartz.JobBuilder; import org.quartz.JobDataMap; @@ -44,47 +42,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(CleanerScheduler.class) -@Component(immediate = true, metatype = true, label = "AET Cleaning Scheduler Service", policy = ConfigurationPolicy.REQUIRE, configurationFactory = true) +@Component( + service = CleanerScheduler.class, + immediate = true, + configurationPolicy = ConfigurationPolicy.REQUIRE) +@Designate(ocd = CleanerSchedulerConf.class, factory = true) public class CleanerScheduler { private static final Logger LOGGER = LoggerFactory.getLogger(CleanerScheduler.class); - private static final String COMPANY_NAME = "companyName"; - - private static final String PROJECT_NAME = "projectName"; - - private static final String REMOVE_OLDER_THAN = "removeOlderThan"; - - private static final String KEEP_N_VERSIONS = "keepNVersions"; - - private static final String SCHEDULE_CRON = "schedule"; - - private static final String DRY_RUN = "dryRun"; - - private static final long DEFAULT_REMOVE_OLDER_THAN_PARAM = 10L; - - private static final long DEFAULT_KEEP_N_VERSIONS_PARAM = 1L; - private Scheduler scheduler; - @Property(name = SCHEDULE_CRON, label = "Schedule", description = "CRON notation of when the job is to be fired. [example: '0 0 21 ? * *' will trigger job daily at 21:00].") - private String schedule; - - @Property(name = KEEP_N_VERSIONS, label = "Last versions to keep", description = "Defines number of artifacts versions that will be left after clean operation [integer]. If left empty, only one version will be kept after cleaning operation.", longValue = DEFAULT_KEEP_N_VERSIONS_PARAM) - private Long keepNVersions; - - @Property(name = REMOVE_OLDER_THAN, label = "Remove artifacts older than", description = "Defines how old files should be removed [integer days]. Works as conjunction with last versions to keep.", longValue = DEFAULT_REMOVE_OLDER_THAN_PARAM) - private Long removeOlderThan; - - @Property(name = COMPANY_NAME, label = "Company Name", description = "Name of the company for which we wish cleaning to be performed. Leave blank if you wish to trigger this job for each company on database.") - private String companyName; - - @Property(name = PROJECT_NAME, label = "Project Name", description = "Name of the project for which we wish cleaning to be performed. Leave blank if you wish to trigger this job for each project on database.") - private String projectName; - - @Property(name = DRY_RUN, label = "Dry run", description = "Flag that says if operation should be run in 'dry run' mode. When checked, no changes will be performed on database.", boolValue = true) - private Boolean dryRun; + private CleanerSchedulerConf config; @Reference private MetadataCleanerRouteBuilder metadataCleanerRouteBuilder; @@ -98,21 +67,14 @@ public class CleanerScheduler { private String scheduledJob; @Activate - public void activate(Map properties) { + public void activate(CleanerSchedulerConf config) { LOGGER.info("Activating CleanerScheduler."); try { - schedule = PropertiesUtil.toString(properties.get(SCHEDULE_CRON), null); - removeOlderThan = PropertiesUtil - .toLong(properties.get(REMOVE_OLDER_THAN), DEFAULT_REMOVE_OLDER_THAN_PARAM); - keepNVersions = PropertiesUtil - .toLong(properties.get(KEEP_N_VERSIONS), DEFAULT_KEEP_N_VERSIONS_PARAM); - companyName = PropertiesUtil.toString(properties.get(COMPANY_NAME), ""); - projectName = PropertiesUtil.toString(properties.get(PROJECT_NAME), ""); - dryRun = PropertiesUtil.toBoolean(properties.get(DRY_RUN), true); + this.config = config; ValidationResultBuilder validationResultBuilder = validationResultBuilderFactory .createInstance(); - new CleanerSchedulerValidator(schedule, keepNVersions, removeOlderThan) + new CleanerSchedulerValidator(config.schedule(), config.keepNVersions(), config.removeOlderThan()) .validate(validationResultBuilder); if (!validationResultBuilder.hasErrors()) { scheduler = StdSchedulerFactory.getDefaultScheduler(); @@ -156,11 +118,11 @@ private String registerCleaningJob() throws SchedulerException { final ImmutableMap jobData = ImmutableMap.builder() .put(CleanerJob.KEY_ROUTE_BUILDER, metadataCleanerRouteBuilder) - .put(CleanerJob.KEY_KEEP_N_VERSIONS, keepNVersions) - .put(CleanerJob.KEY_REMOVE_OLDER_THAN, removeOlderThan) - .put(CleanerJob.KEY_COMPANY_FILTER, companyName) - .put(CleanerJob.KEY_PROJECT_FILTER, projectName) - .put(CleanerJob.KEY_DRY_RUN, dryRun) + .put(CleanerJob.KEY_KEEP_N_VERSIONS, config.keepNVersions()) + .put(CleanerJob.KEY_REMOVE_OLDER_THAN, config.removeOlderThan()) + .put(CleanerJob.KEY_COMPANY_FILTER, config.companyName()) + .put(CleanerJob.KEY_PROJECT_FILTER, config.projectName()) + .put(CleanerJob.KEY_DRY_RUN, config.dryRun()) .build(); JobDetail jobDetail = JobBuilder.newJob(CleanerJob.class) @@ -170,7 +132,7 @@ private String registerCleaningJob() throws SchedulerException { Trigger trigger = TriggerBuilder.newTrigger() .withIdentity(cleanerTriggerName) - .withSchedule(CronScheduleBuilder.cronSchedule(schedule)) + .withSchedule(CronScheduleBuilder.cronSchedule(config.schedule())) .build(); scheduler.scheduleJob(jobDetail, trigger); @@ -180,12 +142,12 @@ private String registerCleaningJob() throws SchedulerException { @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("schedule", schedule) - .add("keepNVersions", keepNVersions) - .add("removeOlderThan", removeOlderThan) - .add("companyName", companyName) - .add("projectName", projectName) - .add("dryRun", dryRun) + .add("schedule", config.schedule()) + .add("keepNVersions", config.keepNVersions()) + .add("removeOlderThan", config.removeOlderThan()) + .add("companyName", config.companyName()) + .add("projectName", config.projectName()) + .add("dryRun", config.dryRun()) .toString(); } } diff --git a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/configuration/CleanerSchedulerConf.java b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/configuration/CleanerSchedulerConf.java new file mode 100644 index 000000000..10e770e3a --- /dev/null +++ b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/configuration/CleanerSchedulerConf.java @@ -0,0 +1,77 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.cleaner.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.AttributeType; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "AET Cleaning Scheduler Service", description = "AET Cleaning Scheduler Service") +public @interface CleanerSchedulerConf { + + String COMPANY_NAME = "Company Name"; + + String PROJECT_NAME = "Project Name"; + + String REMOVE_OLDER_THAN = "Remove artifacts older than"; + + String KEEP_N_VERSIONS = "Last versions to keep"; + + String SCHEDULE_CRON = "Schedule"; + + String DRY_RUN = "Dry run"; + + long DEFAULT_REMOVE_OLDER_THAN_PARAM = 10L; + + long DEFAULT_KEEP_N_VERSIONS_PARAM = 1L; + + @AttributeDefinition( + name = SCHEDULE_CRON, + description = "CRON notation of when the job is to be fired. [example: '0 0 21 ? * *' will trigger job daily at 21:00].") + String schedule(); + + @AttributeDefinition( + name = KEEP_N_VERSIONS, + description = "Defines number of artifacts versions that will be left after clean operation [integer]. If left empty, only one version will be kept after cleaning operation.", + type = AttributeType.LONG) + long keepNVersions() default DEFAULT_KEEP_N_VERSIONS_PARAM; + + @AttributeDefinition( + name = REMOVE_OLDER_THAN, + description = "Defines how old files should be removed [integer days]. Works as conjunction with last versions to keep.", + type = AttributeType.LONG) + long removeOlderThan() default DEFAULT_REMOVE_OLDER_THAN_PARAM; + + @AttributeDefinition( + name = COMPANY_NAME, + description = "Name of the company for which we wish cleaning to be performed. Leave blank if you wish to trigger this job for each company on database.", + type = AttributeType.STRING) + String companyName(); + + @AttributeDefinition( + name = PROJECT_NAME, + description = "Name of the project for which we wish cleaning to be performed. Leave blank if you wish to trigger this job for each project on database.", + type = AttributeType.STRING) + String projectName(); + + @AttributeDefinition( + name = DRY_RUN, + description = "Flag that says if operation should be run in 'dry run' mode. When checked, no changes will be performed on database.", + type = AttributeType.BOOLEAN) + boolean dryRun() default true; + + +} diff --git a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/FetchAllProjectSuitesProcessor.java b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/FetchAllProjectSuitesProcessor.java index 85d97c77a..24cfc07ba 100644 --- a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/FetchAllProjectSuitesProcessor.java +++ b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/FetchAllProjectSuitesProcessor.java @@ -29,14 +29,12 @@ import java.util.Map; import org.apache.camel.Exchange; import org.apache.camel.Processor; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(FetchAllProjectSuitesProcessor.class) -@Component +@Component(service = FetchAllProjectSuitesProcessor.class) public class FetchAllProjectSuitesProcessor implements Processor { private static final Logger LOGGER = LoggerFactory diff --git a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/GetMetadataArtifactsProcessor.java b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/GetMetadataArtifactsProcessor.java index 20050ffa5..712b5f643 100644 --- a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/GetMetadataArtifactsProcessor.java +++ b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/GetMetadataArtifactsProcessor.java @@ -34,13 +34,11 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.commons.lang3.StringUtils; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(GetMetadataArtifactsProcessor.class) -@Component +@Component(service = GetMetadataArtifactsProcessor.class) public class GetMetadataArtifactsProcessor implements Processor { private static final Logger LOGGER = LoggerFactory.getLogger(GetMetadataArtifactsProcessor.class); diff --git a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/RemoveArtifactsProcessor.java b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/RemoveArtifactsProcessor.java index 8339af855..34a6a5808 100644 --- a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/RemoveArtifactsProcessor.java +++ b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/RemoveArtifactsProcessor.java @@ -21,14 +21,12 @@ import com.google.common.collect.Sets; import org.apache.camel.Exchange; import org.apache.camel.Processor; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(RemoveArtifactsProcessor.class) -@Component +@Component(service = RemoveArtifactsProcessor.class) public class RemoveArtifactsProcessor implements Processor { private static final Logger LOGGER = LoggerFactory.getLogger(RemoveArtifactsProcessor.class); diff --git a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/RemoveMetadataProcessor.java b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/RemoveMetadataProcessor.java index 33c45d3c8..849b87a66 100644 --- a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/RemoveMetadataProcessor.java +++ b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/RemoveMetadataProcessor.java @@ -21,14 +21,12 @@ import com.cognifide.aet.vs.MetadataDAO; import org.apache.camel.Exchange; import org.apache.camel.Processor; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(RemoveMetadataProcessor.class) -@Component +@Component(service = RemoveMetadataProcessor.class) public class RemoveMetadataProcessor implements Processor { private static final Logger LOGGER = LoggerFactory.getLogger(RemoveMetadataProcessor.class); diff --git a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/StartMetadataCleanupProcessor.java b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/StartMetadataCleanupProcessor.java index 884d02922..4f279a14e 100644 --- a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/StartMetadataCleanupProcessor.java +++ b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/StartMetadataCleanupProcessor.java @@ -26,17 +26,15 @@ import java.util.Collection; import org.apache.camel.Exchange; import org.apache.camel.Processor; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Query for all databases and passes them to split. */ -@Service(StartMetadataCleanupProcessor.class) -@Component +@Component(service = StartMetadataCleanupProcessor.class) public class StartMetadataCleanupProcessor implements Processor { private static final Logger LOGGER = LoggerFactory.getLogger(StartMetadataCleanupProcessor.class); diff --git a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/SuitesRemovePredicateProcessor.java b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/SuitesRemovePredicateProcessor.java index d6dd35ec8..6c9605ab0 100644 --- a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/SuitesRemovePredicateProcessor.java +++ b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/processors/SuitesRemovePredicateProcessor.java @@ -28,13 +28,11 @@ import java.util.Collection; import org.apache.camel.Exchange; import org.apache.camel.Processor; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(SuitesRemovePredicateProcessor.class) -@Component +@Component(service = SuitesRemovePredicateProcessor.class) public class SuitesRemovePredicateProcessor implements Processor { private static final Logger LOGGER = LoggerFactory diff --git a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/route/MetadataCleanerRouteBuilder.java b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/route/MetadataCleanerRouteBuilder.java index c97f92ba8..218c0c65b 100644 --- a/core/cleaner/src/main/java/com/cognifide/aet/cleaner/route/MetadataCleanerRouteBuilder.java +++ b/core/cleaner/src/main/java/com/cognifide/aet/cleaner/route/MetadataCleanerRouteBuilder.java @@ -26,12 +26,10 @@ import com.cognifide.aet.cleaner.processors.SuitesRemovePredicateProcessor; import com.cognifide.aet.communication.api.exceptions.AETException; import org.apache.camel.builder.RouteBuilder; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; -@Service(MetadataCleanerRouteBuilder.class) -@Component(label = "AET Metadata Cleaner Route Builder") +@Component(service = MetadataCleanerRouteBuilder.class) public class MetadataCleanerRouteBuilder extends RouteBuilder { private static final String ERROR_ENDPOINT = "seda:Error"; diff --git a/core/communication/pom.xml b/core/communication/pom.xml index 7b2fde580..958d816ba 100644 --- a/core/communication/pom.xml +++ b/core/communication/pom.xml @@ -40,8 +40,16 @@ - org.apache.felix - org.apache.felix.scr.annotations + org.osgi + org.osgi.service.component.annotations + + + org.osgi + org.osgi.annotation + + + org.osgi + org.osgi.service.metatype.annotations org.apache.activemq diff --git a/core/communication/src/main/java/com/cognifide/aet/queues/DefaultJmsConnection.java b/core/communication/src/main/java/com/cognifide/aet/queues/DefaultJmsConnection.java index 5cbbbaacf..54d3bfd41 100644 --- a/core/communication/src/main/java/com/cognifide/aet/queues/DefaultJmsConnection.java +++ b/core/communication/src/main/java/com/cognifide/aet/queues/DefaultJmsConnection.java @@ -17,35 +17,25 @@ import com.cognifide.aet.communication.api.queues.JmsConnection; import com.cognifide.aet.communication.api.queues.JmsEndpointConfig; -import java.util.Map; +import com.cognifide.aet.queues.configuration.DefaultJmsConnectionConf; import javax.jms.Connection; import javax.jms.JMSException; import javax.jms.Session; import org.apache.activemq.ActiveMQConnectionFactory; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; import org.osgi.service.cm.ConfigurationAdmin; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(immediate = true, metatype = true, description = "AET JMS Connection", label = "AET Default JMS Connection") +@Component(immediate = true) public class DefaultJmsConnection implements JmsConnection { private static final boolean SESSION_TRANSACTION_DEFAULT_SETTING = false; - @Property(name = "url", label = "brokerUrl", description = "URL of the broker, no trailing '/', see http://activemq.apache.org/uri-protocols.html", value = "failover:tcp://localhost:61616") - private String brokerURL; - - @Property(name = "username", label = "username", description = "ActiveMQ username", value = "karaf") - private String username; - - @Property(name = "password", label = "password", description = "ActiveMQ password", value = "karaf") - private String password; + private DefaultJmsConnectionConf config; @Reference private ConfigurationAdmin configurationAdmin; @@ -66,20 +56,20 @@ public Connection getJmsConnection() { @Override public JmsEndpointConfig getEndpointConfig() { - return new JmsEndpointConfig(brokerURL, username, password); + return new JmsEndpointConfig(config.brokerURL(), config.username(), config.password()); } @Activate - public void activate(Map properties) throws JMSException { - updateProperties(properties); + public void activate(DefaultJmsConnectionConf config) throws JMSException { + this.config = config; connect(); } public void connect() throws JMSException { - LOG.info("Connecting to broker {} on user {}", brokerURL, username); - final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerURL); - connectionFactory.setUserName(username); - connectionFactory.setPassword(password); + LOG.info("Connecting to broker {} on user {}", config.brokerURL(), config.username()); + final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(config.brokerURL()); + connectionFactory.setUserName(config.username()); + connectionFactory.setPassword(config.password()); connectionFactory.setTrustAllPackages(true); connection = connectionFactory.createConnection(); connection.start(); @@ -91,14 +81,8 @@ public void deactivate() { } public void disconnect() { - LOG.info("Disconnecting from broker {} on user {}", brokerURL, username); + LOG.info("Disconnecting from broker {} on user {}", config.brokerURL(), config.username()); JmsUtils.closeQuietly(connection); } - private void updateProperties(Map stringDictionary) { - username = (String) stringDictionary.get("username"); - password = (String) stringDictionary.get("password"); - brokerURL = (String) stringDictionary.get("url"); - } - } diff --git a/core/communication/src/main/java/com/cognifide/aet/queues/configuration/DefaultJmsConnectionConf.java b/core/communication/src/main/java/com/cognifide/aet/queues/configuration/DefaultJmsConnectionConf.java new file mode 100644 index 000000000..4af9aafa6 --- /dev/null +++ b/core/communication/src/main/java/com/cognifide/aet/queues/configuration/DefaultJmsConnectionConf.java @@ -0,0 +1,49 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.queues.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.AttributeType; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "AET JMS Connection", description = "AET JMS Connection") +public @interface DefaultJmsConnectionConf { + + String DEFAULT_BROKER_URL_PARAM = "failover:tcp://localhost:61616"; + + String DEFAULT_USERNAME_PARAM = "karaf"; + + String DEFAULT_PASSWORD_PARAM = "karaf"; + + @AttributeDefinition( + name = "brokerUrl", + description = "URL of the broker, no trailing '/', see http://activemq.apache.org/uri-protocols.html", + type = AttributeType.STRING) + String brokerURL() default DEFAULT_BROKER_URL_PARAM; + + @AttributeDefinition( + name = "username", + description = "ActiveMQ username", + type = AttributeType.STRING) + String username() default DEFAULT_USERNAME_PARAM; + + @AttributeDefinition( + name = "password", + description = "ActiveMQ password", + type = AttributeType.STRING) + String password() default DEFAULT_PASSWORD_PARAM; + +} diff --git a/core/datastorage/pom.xml b/core/datastorage/pom.xml index f0e0b270f..a16f35d97 100644 --- a/core/datastorage/pom.xml +++ b/core/datastorage/pom.xml @@ -60,8 +60,16 @@ commons-codec - org.apache.felix - org.apache.felix.scr.annotations + org.osgi + org.osgi.service.component.annotations + + + org.osgi + org.osgi.annotation + + + org.osgi + org.osgi.service.metatype.annotations com.google.code.gson @@ -87,10 +95,6 @@ org.mongodb mongo-java-driver - - org.apache.sling - org.apache.sling.commons.osgi - junit diff --git a/core/datastorage/src/main/java/com/cognifide/aet/vs/artifacts/ArtifactsDAOMongoDBImpl.java b/core/datastorage/src/main/java/com/cognifide/aet/vs/artifacts/ArtifactsDAOMongoDBImpl.java index 584fd2436..4ca483e6c 100644 --- a/core/datastorage/src/main/java/com/cognifide/aet/vs/artifacts/ArtifactsDAOMongoDBImpl.java +++ b/core/datastorage/src/main/java/com/cognifide/aet/vs/artifacts/ArtifactsDAOMongoDBImpl.java @@ -32,16 +32,14 @@ import java.util.Date; import java.util.Set; import org.apache.commons.io.IOUtils; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; import org.bson.Document; import org.bson.types.ObjectId; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(label = "AET Artifacts DAO implementation for MongoDB", immediate = true) +@Component(immediate = true) public class ArtifactsDAOMongoDBImpl implements ArtifactsDAO { private static final Logger LOGGER = LoggerFactory.getLogger(ArtifactsDAOMongoDBImpl.class); diff --git a/core/datastorage/src/main/java/com/cognifide/aet/vs/metadata/MetadataDAOMongoDBImpl.java b/core/datastorage/src/main/java/com/cognifide/aet/vs/metadata/MetadataDAOMongoDBImpl.java index e692f2a03..d963c311b 100644 --- a/core/datastorage/src/main/java/com/cognifide/aet/vs/metadata/MetadataDAOMongoDBImpl.java +++ b/core/datastorage/src/main/java/com/cognifide/aet/vs/metadata/MetadataDAOMongoDBImpl.java @@ -36,15 +36,13 @@ import java.util.Collection; import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; import org.bson.Document; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(label = "AET Metadata DAO implementation for MongoDB", immediate = true) +@Component(immediate = true) public class MetadataDAOMongoDBImpl implements MetadataDAO { private static final long serialVersionUID = 3031952772776598636L; diff --git a/core/datastorage/src/main/java/com/cognifide/aet/vs/mongodb/MongoDBClient.java b/core/datastorage/src/main/java/com/cognifide/aet/vs/mongodb/MongoDBClient.java index 273c65e13..2466bfef2 100644 --- a/core/datastorage/src/main/java/com/cognifide/aet/vs/mongodb/MongoDBClient.java +++ b/core/datastorage/src/main/java/com/cognifide/aet/vs/mongodb/MongoDBClient.java @@ -16,6 +16,7 @@ package com.cognifide.aet.vs.mongodb; import com.cognifide.aet.vs.metadata.MetadataDAOMongoDBImpl; +import com.cognifide.aet.vs.mongodb.configuration.MongoDBClientConf; import com.mongodb.DB; import com.mongodb.MongoClient; import com.mongodb.MongoClientURI; @@ -25,45 +26,30 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Map; import java.util.Set; import org.apache.commons.lang3.StringUtils; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; import org.bson.BsonDocument; import org.bson.BsonInt32; import org.bson.Document; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.metatype.annotations.Designate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(MongoDBClient.class) -@Component(immediate = true, metatype = true, label = "AET MongoDB Client", description = "AET MongoDB Client") +@Component(service = MongoDBClient.class, immediate = true) +@Designate(ocd = MongoDBClientConf.class) public class MongoDBClient { private static final Logger LOGGER = LoggerFactory.getLogger(MongoDBClient.class); - private static final String MONGO_URI = "MongoURI"; - - private static final String DEFAULT_MONGODB_URI = "mongodb://localhost"; - private static final int MAX_DB_NAME_LENGTH = 64; - private static final boolean DEFAULT_AUTOCREATE_VALUE = false; - public static final String DB_NAME_SEPARATOR = "_"; - @Property(name = MONGO_URI, label = "MongoURI", description = - "mongodb://[username:password@]host1[:port1][,host2[:port2]," - + "...[,hostN[:portN]]][/[database][?options]]", value = DEFAULT_MONGODB_URI) private String mongoUri; - private static final String ALLOW_AUTO_CREATE = "AllowAutoCreate"; - - @Property(name = ALLOW_AUTO_CREATE, label = "Allow automatic creation of DB", description = "Allows automatic creation of DB if set to true", boolValue = DEFAULT_AUTOCREATE_VALUE) private Boolean allowAutoCreate; private MongoClient mongoClient; @@ -73,8 +59,9 @@ public MongoClient getMongoClient() { } @Activate - public void activate(Map properties) { - setupProperties(properties); + public void activate(MongoDBClientConf config) { + this.mongoUri = config.mongoURI(); + this.allowAutoCreate = config.allowAutoCreate(); try { setupMongoDBConnection(); } catch (Exception e) { @@ -116,13 +103,7 @@ public Collection getCompanies() { return companies; } - - private void setupProperties(Map properties) { - this.mongoUri = PropertiesUtil.toString(properties.get(MONGO_URI), DEFAULT_MONGODB_URI); - this.allowAutoCreate = PropertiesUtil.toBoolean(properties.get(ALLOW_AUTO_CREATE), - DEFAULT_AUTOCREATE_VALUE); - } - + private void setupMongoDBConnection() throws UnknownHostException { mongoClient = new MongoClient(new MongoClientURI(mongoUri)); testConnection(); diff --git a/core/datastorage/src/main/java/com/cognifide/aet/vs/mongodb/configuration/MongoDBClientConf.java b/core/datastorage/src/main/java/com/cognifide/aet/vs/mongodb/configuration/MongoDBClientConf.java new file mode 100644 index 000000000..734cf1ce0 --- /dev/null +++ b/core/datastorage/src/main/java/com/cognifide/aet/vs/mongodb/configuration/MongoDBClientConf.java @@ -0,0 +1,43 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.vs.mongodb.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.AttributeType; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "AET MongoDB Client", description = "AET MongoDB Client") +public @interface MongoDBClientConf { + + String MONGO_URI_PROPERTY_NAME = "MongoURI"; + + String MONGO_URI_PROPERTY_DESCRIPTION = "mongodb://[username:password@]host1[:port1][,host2[:port2]," + + "...[,hostN[:portN]]][/[database][?options]]"; + + String DEFAULT_MONGODB_URI = "mongodb://localhost"; + + String ALLOW_AUTO_CREATE_PROPERTY_NAME = "Allow automatic creation of DB"; + + String ALLOW_AUTO_CREATE_PROPERTY_DESCRIPTION = "Allows automatic creation of DB if set to true"; + + boolean DEFAULT_AUTOCREATE_VALUE = false; + + @AttributeDefinition(name = MONGO_URI_PROPERTY_NAME, description = MONGO_URI_PROPERTY_DESCRIPTION, type = AttributeType.STRING) + String mongoURI() default DEFAULT_MONGODB_URI; + + @AttributeDefinition(name = ALLOW_AUTO_CREATE_PROPERTY_NAME, description = ALLOW_AUTO_CREATE_PROPERTY_DESCRIPTION, type = AttributeType.BOOLEAN) + boolean allowAutoCreate() default DEFAULT_AUTOCREATE_VALUE; +} diff --git a/core/jobs/pom.xml b/core/jobs/pom.xml index 2347e6c57..afc6dd5b3 100644 --- a/core/jobs/pom.xml +++ b/core/jobs/pom.xml @@ -35,6 +35,18 @@ + + org.osgi + org.osgi.service.component.annotations + + + org.osgi + org.osgi.annotation + + + org.osgi + org.osgi.service.metatype.annotations + com.cognifide.aet communication-api @@ -78,10 +90,6 @@ com.googlecode.java-diff-utils diffutils - - org.apache.sling - org.apache.sling.commons.osgi - org.apache.httpcomponents fluent-hc @@ -96,11 +104,6 @@ slf4j-api - - org.apache.felix - org.apache.felix.scr.annotations - - junit diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/accessibility/AccessibilityCollectorFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/accessibility/AccessibilityCollectorFactory.java index 0d8ec20ca..ba2a0b5db 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/accessibility/AccessibilityCollectorFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/accessibility/AccessibilityCollectorFactory.java @@ -22,14 +22,12 @@ import com.cognifide.aet.job.api.exceptions.ParametersException; import com.cognifide.aet.vs.ArtifactsDAO; import java.util.Map; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; import org.osgi.framework.BundleContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; @Component -@Service public class AccessibilityCollectorFactory implements CollectorFactory { @Reference diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/cookie/CookieCollectorFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/cookie/CookieCollectorFactory.java index 2bfae12b9..eff21fbbd 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/cookie/CookieCollectorFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/cookie/CookieCollectorFactory.java @@ -22,12 +22,10 @@ import com.cognifide.aet.job.api.exceptions.ParametersException; import com.cognifide.aet.vs.ArtifactsDAO; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; @Component -@Service public class CookieCollectorFactory implements CollectorFactory { @Reference diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/jserrors/JsErrorsCollectorFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/jserrors/JsErrorsCollectorFactory.java index 87a23cced..f0ccead64 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/jserrors/JsErrorsCollectorFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/jserrors/JsErrorsCollectorFactory.java @@ -22,12 +22,10 @@ import com.cognifide.aet.job.api.exceptions.ParametersException; import com.cognifide.aet.vs.ArtifactsDAO; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; @Component -@Service public class JsErrorsCollectorFactory implements CollectorFactory { @Reference diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/open/OpenPageFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/open/OpenPageFactory.java index d4123f41d..c04f50e2e 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/open/OpenPageFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/open/OpenPageFactory.java @@ -21,11 +21,9 @@ import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; @Component -@Service public class OpenPageFactory implements CollectorFactory { @Override diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/performance/clientside/ClientSidePerformanceCollectorFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/performance/clientside/ClientSidePerformanceCollectorFactory.java index a4f147f8e..2bab04bff 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/performance/clientside/ClientSidePerformanceCollectorFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/performance/clientside/ClientSidePerformanceCollectorFactory.java @@ -22,14 +22,12 @@ import com.cognifide.aet.job.api.exceptions.ParametersException; import com.cognifide.aet.vs.ArtifactsDAO; import java.util.Map; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; import org.osgi.framework.BundleContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; @Component -@Service public class ClientSidePerformanceCollectorFactory implements CollectorFactory { private BundleContext context; diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorFactory.java index 48771238b..705e984a4 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorFactory.java @@ -22,12 +22,10 @@ import com.cognifide.aet.job.api.exceptions.ParametersException; import com.cognifide.aet.vs.ArtifactsDAO; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; -@Component(description = "AET Screen Collector Factory", label = "AET Screen Collector Factory") -@Service +@Component public class ScreenCollectorFactory implements CollectorFactory { @Reference diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/source/SourceCollectorFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/source/SourceCollectorFactory.java index 559886bfe..0099fe954 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/source/SourceCollectorFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/source/SourceCollectorFactory.java @@ -20,25 +20,19 @@ import com.cognifide.aet.job.api.collector.CollectorProperties; import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; +import com.cognifide.aet.job.common.collectors.source.configuration.SourceCollectorFactoryConf; import com.cognifide.aet.vs.ArtifactsDAO; import java.util.Map; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; -@Component(metatype = true, description = "AET Source Collector Factory", label = "AET Source Collector Factory") -@Service +@Component +@Designate(ocd = SourceCollectorFactoryConf.class) public class SourceCollectorFactory implements CollectorFactory { - private static final String SOURCE_COLLECTOR_TIMEOUT_VALUE = "sourceCollectorTimeoutValue"; - - private static final int DEFAULT_TIMEOUT = 20000; - - @Property(name = SOURCE_COLLECTOR_TIMEOUT_VALUE, label = "Timeout value for source collector [ms]", intValue = DEFAULT_TIMEOUT, description = "Timeout value for source collector [ms]") - private int timeoutValue; + SourceCollectorFactoryConf config; @Reference private ArtifactsDAO artifactsDAO; @@ -53,13 +47,12 @@ public CollectorJob createInstance(CollectorProperties properties, Map properties) { + protected void activate(ExternalSnippetHttpClientConf config) { LOGGER.info("Activating ExternalSnippetHttpClient - {}", this); - - Long connectionTtl = PropertiesUtil - .toLong(properties.get(CONNECTION_TTL_PARAMETER), DEFAULT_CONNECTION_TTL); - Integer maxConcurrentConnections = PropertiesUtil - .toInteger(properties.get(MAX_CONCURRENT_CONNECTIONS_PARAMETER), - DEFAULT_MAX_CONCURRENT_CONNECTIONS); + this.config = config; final PoolingHttpClientConnectionManager poolingConnManager = - new PoolingHttpClientConnectionManager(connectionTtl, TimeUnit.SECONDS); - poolingConnManager.setMaxTotal(maxConcurrentConnections); + new PoolingHttpClientConnectionManager(config.connectionTtl(), TimeUnit.SECONDS); + poolingConnManager.setMaxTotal(config.maxConcurrentConnections()); httpClient = HttpClients.custom().setConnectionManager(poolingConnManager).build(); } diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/executejavascript/configuration/ExternalSnippetHttpClientConf.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/executejavascript/configuration/ExternalSnippetHttpClientConf.java new file mode 100644 index 000000000..6ca1a92e3 --- /dev/null +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/executejavascript/configuration/ExternalSnippetHttpClientConf.java @@ -0,0 +1,42 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.job.common.modifiers.executejavascript.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.AttributeType; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "External Snippet Http Client Configuration") +public @interface ExternalSnippetHttpClientConf { + + long DEFAULT_CONNECTION_TTL = 60L; + + int DEFAULT_MAX_CONCURRENT_CONNECTIONS = 50; + + @AttributeDefinition( + name = "Connection TTL", + description = "Time in seconds that defines maximum life span of persistent connections regardless of their expiration setting", + type = AttributeType.LONG) + long connectionTtl() default DEFAULT_CONNECTION_TTL; + + @AttributeDefinition( + name = "Maximum Concurrent Connections", + description = "The maximal number of concurrent connections this service can provide. Connections over this limit are rejected.", + type = AttributeType.INTEGER) + int maxConcurrentConnections() default DEFAULT_MAX_CONCURRENT_CONNECTIONS; + + +} diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/header/HeaderModifierFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/header/HeaderModifierFactory.java index aa61452d9..a77b962af 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/header/HeaderModifierFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/header/HeaderModifierFactory.java @@ -21,11 +21,9 @@ import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; @Component -@Service public class HeaderModifierFactory implements CollectorFactory { @Override diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/hide/HideModifierFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/hide/HideModifierFactory.java index 0607711e6..acb13582f 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/hide/HideModifierFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/hide/HideModifierFactory.java @@ -21,11 +21,9 @@ import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; @Component -@Service public class HideModifierFactory implements CollectorFactory { @Override diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/login/LoginModifierFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/login/LoginModifierFactory.java index 72d1a1b48..b8cea68cd 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/login/LoginModifierFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/login/LoginModifierFactory.java @@ -22,16 +22,12 @@ import com.cognifide.aet.job.api.exceptions.ParametersException; import com.cognifide.aet.validation.ValidationResultBuilderFactory; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; - -@Service @Component public class LoginModifierFactory implements CollectorFactory { - @Reference private ValidationResultBuilderFactory validationResultBuilderFactory; diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/replacetext/ReplaceTextFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/replacetext/ReplaceTextFactory.java index 9c884c7b0..e3dc15da7 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/replacetext/ReplaceTextFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/replacetext/ReplaceTextFactory.java @@ -21,11 +21,9 @@ import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; @Component -@Service public class ReplaceTextFactory implements CollectorFactory { @Override diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifierFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifierFactory.java index 6da70c7d3..c31626efc 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifierFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifierFactory.java @@ -21,11 +21,9 @@ import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; @Component -@Service public class ResolutionModifierFactory implements CollectorFactory { @Override diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/sleep/SleepModifierFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/sleep/SleepModifierFactory.java index 65c9bd8b1..edc30e68f 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/sleep/SleepModifierFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/sleep/SleepModifierFactory.java @@ -21,11 +21,9 @@ import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; @Component -@Service public class SleepModifierFactory implements CollectorFactory { @Override diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitfor/elementtobevisible/WaitForElementToBeVisibleModifierCollectorFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitfor/elementtobevisible/WaitForElementToBeVisibleModifierCollectorFactory.java index c8399fd2f..0d8ad04bc 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitfor/elementtobevisible/WaitForElementToBeVisibleModifierCollectorFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitfor/elementtobevisible/WaitForElementToBeVisibleModifierCollectorFactory.java @@ -21,11 +21,9 @@ import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; @Component -@Service public class WaitForElementToBeVisibleModifierCollectorFactory implements CollectorFactory { @Override diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitfor/imagecompletion/WaitForImageCompletionModifierCollectorFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitfor/imagecompletion/WaitForImageCompletionModifierCollectorFactory.java index 540fda14b..730088919 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitfor/imagecompletion/WaitForImageCompletionModifierCollectorFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitfor/imagecompletion/WaitForImageCompletionModifierCollectorFactory.java @@ -21,11 +21,9 @@ import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; @Component -@Service public class WaitForImageCompletionModifierCollectorFactory implements CollectorFactory { @Override diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitforpageloaded/WaitForPageLoadedModifierFactory.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitforpageloaded/WaitForPageLoadedModifierFactory.java index 7a87dc2d9..f7cc4978c 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitforpageloaded/WaitForPageLoadedModifierFactory.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/waitforpageloaded/WaitForPageLoadedModifierFactory.java @@ -21,11 +21,9 @@ import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.job.api.exceptions.ParametersException; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; @Component -@Service public class WaitForPageLoadedModifierFactory implements CollectorFactory { @Override diff --git a/core/pom.xml b/core/pom.xml index 8c827d7ca..a91622f45 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -42,21 +42,4 @@ validation worker - - - - - org.apache.felix - maven-scr-plugin - - - generate-scr-descriptor - - scr - - - - - - diff --git a/core/runner/pom.xml b/core/runner/pom.xml index 7efa8cc83..2e93ada17 100644 --- a/core/runner/pom.xml +++ b/core/runner/pom.xml @@ -74,12 +74,16 @@ validation-api - org.apache.felix - org.apache.felix.scr.annotations + org.osgi + org.osgi.service.component.annotations - org.apache.sling - org.apache.sling.commons.osgi + org.osgi + org.osgi.annotation + + + org.osgi + org.osgi.service.metatype.annotations @@ -102,14 +106,6 @@ com.googlecode.zohhak zohhak - - org.powermock - powermock-api-mockito - - - org.powermock - powermock-module-junit4 - diff --git a/core/runner/src/main/java/com/cognifide/aet/runner/MessagesManager.java b/core/runner/src/main/java/com/cognifide/aet/runner/MessagesManager.java index 7bf49b9c8..1fd752e43 100644 --- a/core/runner/src/main/java/com/cognifide/aet/runner/MessagesManager.java +++ b/core/runner/src/main/java/com/cognifide/aet/runner/MessagesManager.java @@ -16,9 +16,9 @@ package com.cognifide.aet.runner; import com.cognifide.aet.communication.api.exceptions.AETException; +import com.cognifide.aet.runner.configuration.MessagesManagerConf; import java.io.IOException; import java.util.HashSet; -import java.util.Map; import java.util.Set; import javax.management.MBeanServerConnection; import javax.management.ObjectName; @@ -26,22 +26,16 @@ import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import org.apache.commons.lang3.StringUtils; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.metatype.annotations.Designate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(MessagesManager.class) -@Component(immediate = true, metatype = true, description = "AET Messages Manager", label = "AET Messages Manager") +@Component(service = MessagesManager.class, immediate = true) +@Designate(ocd = MessagesManagerConf.class) public class MessagesManager { - private static final String JMX_URL_PROPERTY_NAME = "jxm-url"; - - private static final String DEFAULT_JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:11199/jmxrmi"; - private static final String REMOVE_OPERATION_NAME = "removeMatchingMessages"; private static final String JMS_CORRELATION_ID = "JMSCorrelationID"; @@ -58,12 +52,11 @@ public class MessagesManager { static final String DESTINATION_NAME_PROPERTY = "destinationName"; - @Property(name = JMX_URL_PROPERTY_NAME, label = "ActiveMQ JMX endpoint URL", description = "ActiveMQ JMX endpoint URL", value = DEFAULT_JMX_URL) - private String jmxUrl; + private MessagesManagerConf config; @Activate - public void activate(Map properties) { - jmxUrl = PropertiesUtil.toString(properties.get(JMX_URL_PROPERTY_NAME), DEFAULT_JMX_URL); + public void activate(MessagesManagerConf config) { + this.config = config; } /** @@ -76,7 +69,7 @@ public void remove(String correlationID) throws AETException { Object[] removeSelector = {JMS_CORRELATION_ID + "='" + correlationID + "'"}; String[] signature = {STRING_SIGNATURE}; - try (JMXConnector jmxc = getJmxConnection(jmxUrl)) { + try (JMXConnector jmxc = getJmxConnection(config.jmxUrl())) { MBeanServerConnection connection = jmxc.getMBeanServerConnection(); for (ObjectName queue : getAetQueuesObjects(connection)) { String queueName = queue.getKeyProperty(DESTINATION_NAME_PROPERTY); @@ -97,10 +90,6 @@ public static String createFullQueueName(String name) { return AET_QUEUE_DOMAIN + name; } - protected String getJmxUrl() { - return jmxUrl; - } - protected Set getAetQueuesObjects(MBeanServerConnection connection) throws AETException { ObjectName[] queues; diff --git a/core/runner/src/main/java/com/cognifide/aet/runner/RunnerConfiguration.java b/core/runner/src/main/java/com/cognifide/aet/runner/RunnerConfiguration.java index baaf6487a..4c3b0f128 100644 --- a/core/runner/src/main/java/com/cognifide/aet/runner/RunnerConfiguration.java +++ b/core/runner/src/main/java/com/cognifide/aet/runner/RunnerConfiguration.java @@ -15,13 +15,11 @@ */ package com.cognifide.aet.runner; -import java.util.Map; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.ConfigurationPolicy; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; +import com.cognifide.aet.runner.configuration.RunnerConfigurationConf; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; +import org.osgi.service.metatype.annotations.Designate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,88 +27,30 @@ * Runner is an entry point for whole application, it main goal is to coordinate JMS communication * between workers. This class contains all necessary configuration for the runner bundle. */ -@Service(RunnerConfiguration.class) -@Component(metatype = true, description = "AET Runner Configuration", label = "AET Runner Configuration", policy = ConfigurationPolicy.REQUIRE) +@Component(service = RunnerConfiguration.class, configurationPolicy = ConfigurationPolicy.REQUIRE) +@Designate(ocd = RunnerConfigurationConf.class) public class RunnerConfiguration { private static final Logger LOGGER = LoggerFactory.getLogger(RunnerConfiguration.class); - private static final int DEFAULT_TASK_RUN_FAILURE_TIMEOUT_SECONDS = 120; - - private static final String PARAM_FAILURE_TIMEOUT = "ft"; - - private static final String PARAM_MESSAGE_TTL = "mttl"; - - private static final String PARAM_URL_PACKAGE_SIZE = "urlPackageSize"; - - private static final String PARAM_MAX_MESSAGES_IN_COLLECTOR_QUEUE = "maxMessagesInCollectorQueue"; - - private static final String PARAM_MAX_CONCURRENT_SUITES_PROCESSED_COUNT = "maxConcurrentSuitesCount"; - - private static final int DEFAULT_MAX_CONCURRENT_SUITES_PROCESSED_COUNT = 5; - - @Property(name = PARAM_FAILURE_TIMEOUT, label = "Failure timeout", description = - "Time in seconds, after which suite processing will be interrupted if no notification was received in duration of this parameter. Default: " - + DEFAULT_TASK_RUN_FAILURE_TIMEOUT_SECONDS - + " sec", longValue = DEFAULT_TASK_RUN_FAILURE_TIMEOUT_SECONDS) - private long ft = DEFAULT_TASK_RUN_FAILURE_TIMEOUT_SECONDS; - - private static final int DEFAULT_MESSAGE_TIME_TO_LIVE_SECONDS = 300; - - @Property(name = PARAM_MESSAGE_TTL, label = "Message ttl", description = - "Time in seconds after which messages will be thrown out of queues, default: " - + DEFAULT_MESSAGE_TIME_TO_LIVE_SECONDS - + " sec", longValue = DEFAULT_MESSAGE_TIME_TO_LIVE_SECONDS) - private long mttl = DEFAULT_MESSAGE_TIME_TO_LIVE_SECONDS; - - private static final int DEFAULT_URL_PACKAGE_SIZE = 5; - - @Property(name = PARAM_URL_PACKAGE_SIZE, label = "URL Package Size", description = - "Defines how many links are being sent in one message. Each message is being processed by single CollectorListener. Default: " - + DEFAULT_URL_PACKAGE_SIZE + " items", intValue = DEFAULT_URL_PACKAGE_SIZE) - private int urlPackageSize = DEFAULT_URL_PACKAGE_SIZE; - - private static final int DEFAULT_MAX_MESSAGES_IN_COLLECTOR_QUEUE = 20; - - @Property(name = PARAM_MAX_MESSAGES_IN_COLLECTOR_QUEUE, label = "Max Messages in Collector Queue", description = - "Defines the maximum amount of messages in the collector queue. Default: " - + DEFAULT_MAX_MESSAGES_IN_COLLECTOR_QUEUE - + " messages", intValue = DEFAULT_MAX_MESSAGES_IN_COLLECTOR_QUEUE) - private int maxMessagesInCollectorQueue = DEFAULT_MAX_MESSAGES_IN_COLLECTOR_QUEUE; - - @Property(name = PARAM_MAX_CONCURRENT_SUITES_PROCESSED_COUNT, label = "Max Concurrent Suites Count", description = - "Defines the maximum number of suites processed concurrently byt the Runner. Default: " - + DEFAULT_MAX_CONCURRENT_SUITES_PROCESSED_COUNT - + " messages", intValue = DEFAULT_MAX_CONCURRENT_SUITES_PROCESSED_COUNT) - private int maxConcurrentSuitesCount = DEFAULT_MAX_CONCURRENT_SUITES_PROCESSED_COUNT; + private static RunnerConfigurationConf config; @Activate - public void activate(Map properties) { - ft = PropertiesUtil.toLong(properties.get(PARAM_FAILURE_TIMEOUT), - DEFAULT_TASK_RUN_FAILURE_TIMEOUT_SECONDS); - mttl = PropertiesUtil - .toLong(properties.get(PARAM_MESSAGE_TTL), DEFAULT_MESSAGE_TIME_TO_LIVE_SECONDS) * 1000; - urlPackageSize = PropertiesUtil.toInteger(properties.get(PARAM_URL_PACKAGE_SIZE), - DEFAULT_URL_PACKAGE_SIZE); - maxMessagesInCollectorQueue = PropertiesUtil.toInteger( - properties.get(PARAM_MAX_MESSAGES_IN_COLLECTOR_QUEUE), - DEFAULT_MAX_MESSAGES_IN_COLLECTOR_QUEUE); - maxConcurrentSuitesCount = PropertiesUtil.toInteger( - properties.get(PARAM_MAX_CONCURRENT_SUITES_PROCESSED_COUNT), - DEFAULT_MAX_CONCURRENT_SUITES_PROCESSED_COUNT); - + public void activate(RunnerConfigurationConf config) { + this.config = config; LOGGER.info( "Runner configured with parameters: [ft: {} sec ; mttl: {} ; urlPackageSize: {} ; maxMessagesInCollectorQueue: {}; maxConcurrentSuitesCount: {}.]", - ft, mttl, urlPackageSize, maxMessagesInCollectorQueue, maxConcurrentSuitesCount); - } + config.ft(), config.mttl(), config.urlPackageSize(), config.maxMessagesInCollectorQueue(), + config.maxConcurrentSuitesCount()); + } /** * @return time in seconds, test run will be interrupted if no response was received in duration * of this parameter. */ public long getFt() { - return ft; + return config.ft(); } @@ -118,7 +58,7 @@ public long getFt() { * @return time in seconds after which messages will be thrown out of queues. */ public long getMttl() { - return mttl; + return config.mttl(); } @@ -126,7 +66,7 @@ public long getMttl() { * @return the maximum amount of messages in the collector queue. */ public int getMaxMessagesInCollectorQueue() { - return maxMessagesInCollectorQueue; + return config.maxMessagesInCollectorQueue(); } /** @@ -134,13 +74,13 @@ public int getMaxMessagesInCollectorQueue() { * CollectorListener. */ public int getUrlPackageSize() { - return urlPackageSize; + return config.urlPackageSize(); } /** * @return how many suites can be processed concurrently byt the Runner. */ public int getMaxConcurrentSuitesCount() { - return maxConcurrentSuitesCount; + return config.maxConcurrentSuitesCount(); } } diff --git a/core/runner/src/main/java/com/cognifide/aet/runner/RunnerMessageListener.java b/core/runner/src/main/java/com/cognifide/aet/runner/RunnerMessageListener.java index b3f5af50f..890e1fdc0 100644 --- a/core/runner/src/main/java/com/cognifide/aet/runner/RunnerMessageListener.java +++ b/core/runner/src/main/java/com/cognifide/aet/runner/RunnerMessageListener.java @@ -22,7 +22,6 @@ import com.cognifide.aet.communication.api.queues.JmsConnection; import com.cognifide.aet.queues.JmsUtils; import com.cognifide.aet.runner.scheduler.CollectorJobSchedulerService; -import java.util.Map; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; @@ -30,17 +29,17 @@ import javax.jms.MessageListener; import javax.jms.MessageProducer; import javax.jms.Session; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Listens to incoming runner queue messages. When message received, schedules suite processing. */ -@Component(immediate = true, description = "Runner Messages Listener", label = "Runner Messages Listener") +@Component(immediate = true) public class RunnerMessageListener implements MessageListener { private static final Logger LOGGER = LoggerFactory.getLogger(RunnerMessageListener.class); @@ -69,10 +68,8 @@ public class RunnerMessageListener implements MessageListener { @Reference private CollectorJobSchedulerService collectorJobSchedulerService; - @Activate - public void activate(Map properties) { - + public void activate() { LOGGER.debug("Activating RunnerMessageListener"); try { session = jmsConnection.getJmsSession(); diff --git a/core/runner/src/main/java/com/cognifide/aet/runner/SuiteExecutorService.java b/core/runner/src/main/java/com/cognifide/aet/runner/SuiteExecutorService.java index 30c0e8cea..3c446afda 100644 --- a/core/runner/src/main/java/com/cognifide/aet/runner/SuiteExecutorService.java +++ b/core/runner/src/main/java/com/cognifide/aet/runner/SuiteExecutorService.java @@ -25,27 +25,27 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; -import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import javax.jms.Destination; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(SuiteExecutorService.class) -@Component(immediate = true, description = "Runner Suite Executor Service", label = "Runner Suite Executor Service") + +@Component(service = SuiteExecutorService.class, immediate = true) public class SuiteExecutorService { private static final Logger LOGGER = LoggerFactory.getLogger(SuiteExecutorService.class); private ListeningExecutorService executor; + private ExecutorService callbackExecutor; + private Set scheduledSuites; @Reference @@ -58,7 +58,7 @@ public class SuiteExecutorService { private SuiteExecutionFactory suiteExecutionFactory; @Activate - public void activate(Map properties) { + public void activate() { LOGGER.debug("Activating SuiteExecutorService"); executor = MoreExecutors.listeningDecorator( Executors.newFixedThreadPool(runnerConfiguration.getMaxConcurrentSuitesCount())); diff --git a/core/runner/src/main/java/com/cognifide/aet/runner/configuration/MessagesManagerConf.java b/core/runner/src/main/java/com/cognifide/aet/runner/configuration/MessagesManagerConf.java new file mode 100644 index 000000000..892ae0045 --- /dev/null +++ b/core/runner/src/main/java/com/cognifide/aet/runner/configuration/MessagesManagerConf.java @@ -0,0 +1,31 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.runner.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.AttributeType; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "Messages Manager Configuration", description = "Service Configuration") +public @interface MessagesManagerConf { + + String DEFAULT_JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:11199/jmxrmi"; + + @AttributeDefinition(name = "JMX_URL_PROPERTY_NAME", description = "ActiveMQ JMX endpoint URL", + type = AttributeType.STRING) + String jmxUrl() default DEFAULT_JMX_URL; + +} diff --git a/core/runner/src/main/java/com/cognifide/aet/runner/configuration/RunnerConfigurationConf.java b/core/runner/src/main/java/com/cognifide/aet/runner/configuration/RunnerConfigurationConf.java new file mode 100644 index 000000000..2973b8ad2 --- /dev/null +++ b/core/runner/src/main/java/com/cognifide/aet/runner/configuration/RunnerConfigurationConf.java @@ -0,0 +1,74 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.runner.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.AttributeType; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "AET Runner configuration", description = "AET Runner configuration") +public @interface RunnerConfigurationConf { + + int DEFAULT_TASK_RUN_FAILURE_TIMEOUT_SECONDS = 120; + + String PARAM_FAILURE_TIMEOUT = "Failure timeout"; + + String PARAM_MESSAGE_TTL = "Message TTL"; + + String PARAM_URL_PACKAGE_SIZE = "Url package size"; + + String PARAM_MAX_MESSAGES_IN_COLLECTOR_QUEUE = "Max messages in collector queue"; + + String PARAM_MAX_CONCURRENT_SUITES_PROCESSED_COUNT = "Max concurrent suites count"; + + int DEFAULT_MAX_CONCURRENT_SUITES_PROCESSED_COUNT = 5; + + int DEFAULT_MESSAGE_TIME_TO_LIVE_SECONDS = 300; + + int DEFAULT_URL_PACKAGE_SIZE = 5; + + int DEFAULT_MAX_MESSAGES_IN_COLLECTOR_QUEUE = 20; + + @AttributeDefinition(name = PARAM_FAILURE_TIMEOUT, description = + "Time in seconds, after which suite processing will be interrupted if no notification was received in duration of this parameter. Default: " + + DEFAULT_TASK_RUN_FAILURE_TIMEOUT_SECONDS + " sec", type = AttributeType.LONG) + long ft() default DEFAULT_TASK_RUN_FAILURE_TIMEOUT_SECONDS; + + @AttributeDefinition(name = PARAM_MESSAGE_TTL, description = + "Time in seconds after which messages will be thrown out of queues, default: " + + DEFAULT_MESSAGE_TIME_TO_LIVE_SECONDS + + " sec", type = AttributeType.LONG) + long mttl() default DEFAULT_MESSAGE_TIME_TO_LIVE_SECONDS; + + + @AttributeDefinition(name = PARAM_URL_PACKAGE_SIZE, description = + "Defines how many links are being sent in one message. Each message is being processed by single CollectorListener. Default: " + + DEFAULT_URL_PACKAGE_SIZE + " items", type = AttributeType.INTEGER) + int urlPackageSize() default DEFAULT_URL_PACKAGE_SIZE; + + @AttributeDefinition(name = PARAM_MAX_MESSAGES_IN_COLLECTOR_QUEUE, description = + "Defines the maximum amount of messages in the collector queue. Default: " + + DEFAULT_MAX_MESSAGES_IN_COLLECTOR_QUEUE + + " messages", type = AttributeType.INTEGER) + int maxMessagesInCollectorQueue() default DEFAULT_MAX_MESSAGES_IN_COLLECTOR_QUEUE; + + @AttributeDefinition(name = PARAM_MAX_CONCURRENT_SUITES_PROCESSED_COUNT, description = + "Defines the maximum number of suites processed concurrently byt the Runner. Default: " + + DEFAULT_MAX_CONCURRENT_SUITES_PROCESSED_COUNT + + " messages", type = AttributeType.INTEGER) + int maxConcurrentSuitesCount() default DEFAULT_MAX_CONCURRENT_SUITES_PROCESSED_COUNT; + +} diff --git a/core/runner/src/main/java/com/cognifide/aet/runner/processing/SuiteExecutionFactory.java b/core/runner/src/main/java/com/cognifide/aet/runner/processing/SuiteExecutionFactory.java index 40f9e6ce3..f378ea75e 100644 --- a/core/runner/src/main/java/com/cognifide/aet/runner/processing/SuiteExecutionFactory.java +++ b/core/runner/src/main/java/com/cognifide/aet/runner/processing/SuiteExecutionFactory.java @@ -25,12 +25,10 @@ import com.cognifide.aet.runner.scheduler.CollectorJobSchedulerService; import javax.jms.Destination; import javax.jms.JMSException; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; -@Service(SuiteExecutionFactory.class) -@Component(description = "Suite Execution Factory", label = "Suite Execution Factory") +@Component(service = SuiteExecutionFactory.class) public class SuiteExecutionFactory { @Reference diff --git a/core/runner/src/main/java/com/cognifide/aet/runner/processing/data/SuiteDataService.java b/core/runner/src/main/java/com/cognifide/aet/runner/processing/data/SuiteDataService.java index c48274fff..5a367171f 100644 --- a/core/runner/src/main/java/com/cognifide/aet/runner/processing/data/SuiteDataService.java +++ b/core/runner/src/main/java/com/cognifide/aet/runner/processing/data/SuiteDataService.java @@ -20,12 +20,10 @@ import com.cognifide.aet.vs.MetadataDAO; import com.cognifide.aet.vs.SimpleDBKey; import com.cognifide.aet.vs.StorageException; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; -@Service(SuiteDataService.class) -@Component(label = "Internal Runner service for Suite data operations") +@Component(service = SuiteDataService.class) public class SuiteDataService { @Reference diff --git a/core/runner/src/main/java/com/cognifide/aet/runner/scheduler/CollectorJobSchedulerService.java b/core/runner/src/main/java/com/cognifide/aet/runner/scheduler/CollectorJobSchedulerService.java index 22e8f6104..74419080d 100644 --- a/core/runner/src/main/java/com/cognifide/aet/runner/scheduler/CollectorJobSchedulerService.java +++ b/core/runner/src/main/java/com/cognifide/aet/runner/scheduler/CollectorJobSchedulerService.java @@ -18,37 +18,37 @@ import com.cognifide.aet.communication.api.queues.JmsConnection; import com.cognifide.aet.runner.MessagesManager; import com.cognifide.aet.runner.RunnerConfiguration; -import java.util.Map; import java.util.Queue; import java.util.concurrent.Executors; import java.util.concurrent.Future; import javax.jms.JMSException; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service(CollectorJobSchedulerService.class) -@Component(description = "Collector Job Scheduler Service", label = "Collector Job Scheduler Service") +@Component(service = CollectorJobSchedulerService.class) public class CollectorJobSchedulerService { private static final Logger LOGGER = LoggerFactory.getLogger(CollectorJobSchedulerService.class); @Reference private JmsConnection jmsConnection; + @Reference private MessagesManager messagesManager; + @Reference private RunnerConfiguration runnerConfiguration; private CollectorJobScheduler collectorJobScheduler; + private Future collectorJobSchedulerFeature; @Activate - public void activate(Map properties) throws JMSException { + public void activate() throws JMSException { LOGGER.debug("Activating CollectorJobSchedulerService"); collectorJobScheduler = new CollectorJobScheduler(jmsConnection, runnerConfiguration.getMaxMessagesInCollectorQueue(), messagesManager); diff --git a/core/runner/src/test/java/com/cognifide/aet/runner/MessagesManagerTest.java b/core/runner/src/test/java/com/cognifide/aet/runner/MessagesManagerTest.java index 280c0d079..43efece64 100644 --- a/core/runner/src/test/java/com/cognifide/aet/runner/MessagesManagerTest.java +++ b/core/runner/src/test/java/com/cognifide/aet/runner/MessagesManagerTest.java @@ -24,19 +24,23 @@ import static org.mockito.Mockito.when; import com.cognifide.aet.communication.api.exceptions.AETException; -import java.util.Collections; +import com.cognifide.aet.runner.configuration.MessagesManagerConf; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Matchers; +import org.mockito.Mock; import org.mockito.Mockito; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.runners.MockitoJUnitRunner; -@RunWith(PowerMockRunner.class) +@RunWith(MockitoJUnitRunner.class) public class MessagesManagerTest { + @Mock + private MessagesManagerConf config; + @Test(expected = IllegalArgumentException.class) public void createFullQueueName_whenNameIsNull_expectException() throws Exception { MessagesManager.createFullQueueName(null); @@ -53,21 +57,6 @@ public void createFullQueueName_expectFullName() throws Exception { assertThat(fullQueueName, is("AET.test")); } - @Test - public void activate_whenUrlNotSet_expectDefaultJmxUrlSetup() throws Exception { - MessagesManager messagesManager = new MessagesManager(); - messagesManager.activate(Collections.emptyMap()); - assertThat(messagesManager.getJmxUrl(), - is("service:jmx:rmi:///jndi/rmi://localhost:11199/jmxrmi")); - } - - @Test - public void activate_whenUrlSet_expectProvidedJmxUrlSetup() throws Exception { - MessagesManager messagesManager = new MessagesManager(); - messagesManager.activate(Collections.singletonMap("jxm-url", "localhost:111999")); - assertThat(messagesManager.getJmxUrl(), is("localhost:111999")); - } - @Test public void remove_ExpectRemovingInvoked() throws Exception { MessagesManager messagesManager = new MessagesManager(); @@ -90,7 +79,7 @@ public void remove_ExpectRemovingInvoked() throws Exception { org.mockito.Matchers.any(), org.mockito.Matchers.any())) .thenReturn(10); - messagesManager.activate(Collections.emptyMap()); + messagesManager.activate(config); messagesManager.remove("correlation-company-correlation-12345"); verify(mockedConnection, times(1)).invoke(objectName, "removeMatchingMessages", diff --git a/core/validation/pom.xml b/core/validation/pom.xml index 3a39b813d..46ff7dfe1 100644 --- a/core/validation/pom.xml +++ b/core/validation/pom.xml @@ -41,9 +41,18 @@ - org.apache.felix - org.apache.felix.scr.annotations + org.osgi + org.osgi.service.component.annotations + + org.osgi + org.osgi.annotation + + + org.osgi + org.osgi.service.metatype.annotations + + org.apache.commons commons-lang3 diff --git a/core/validation/src/main/java/com/cognifide/aet/validation/impl/ValidationResultBuilderFactoryImpl.java b/core/validation/src/main/java/com/cognifide/aet/validation/impl/ValidationResultBuilderFactoryImpl.java index e7bb2585a..645cd35ab 100644 --- a/core/validation/src/main/java/com/cognifide/aet/validation/impl/ValidationResultBuilderFactoryImpl.java +++ b/core/validation/src/main/java/com/cognifide/aet/validation/impl/ValidationResultBuilderFactoryImpl.java @@ -17,16 +17,11 @@ import com.cognifide.aet.validation.ValidationResultBuilder; import com.cognifide.aet.validation.ValidationResultBuilderFactory; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; -@Service -@Component( - label = "AET Validation Result Builder Factory", - description = "AET Validation Result Builder Factory") +@Component public class ValidationResultBuilderFactoryImpl implements ValidationResultBuilderFactory { - - @Override + public ValidationResultBuilder createInstance() { return new ValidationResultBuilderImpl(); } diff --git a/core/worker/pom.xml b/core/worker/pom.xml index 30df9e274..30fa480bc 100644 --- a/core/worker/pom.xml +++ b/core/worker/pom.xml @@ -72,16 +72,20 @@ org.osgi.core - org.apache.sling - org.apache.sling.commons.osgi + org.osgi + org.osgi.service.component.annotations - javax.validation - validation-api + org.osgi + org.osgi.annotation - org.apache.felix - org.apache.felix.scr.annotations + org.osgi + org.osgi.service.metatype.annotations + + + javax.validation + validation-api org.apache.httpcomponents diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/HttpRequestExecutorFactoryImpl.java b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/HttpRequestExecutorFactoryImpl.java index 21e3c6898..5abb16860 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/HttpRequestExecutorFactoryImpl.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/HttpRequestExecutorFactoryImpl.java @@ -17,10 +17,8 @@ import com.cognifide.aet.job.api.collector.HttpRequestExecutor; import com.cognifide.aet.job.api.collector.HttpRequestExecutorFactory; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; -@Service @Component public class HttpRequestExecutorFactoryImpl implements HttpRequestExecutorFactory { diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/WebDriverHelper.java b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/WebDriverHelper.java index 57090d243..bf6a4ad6f 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/WebDriverHelper.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/WebDriverHelper.java @@ -18,8 +18,6 @@ import com.cognifide.aet.job.api.collector.ProxyServerWrapper; import com.cognifide.aet.worker.exceptions.WorkerException; import java.net.UnknownHostException; -import java.util.Map; -import org.apache.sling.commons.osgi.PropertiesUtil; import org.openqa.selenium.Proxy; /** @@ -39,8 +37,6 @@ public final class WebDriverHelper { public static final String PATH_DESC = "Custom path to driver binary"; - public static final String SELENIUM_GRID_URL = "seleniumGridUrl"; - public static final String SELENIUM_GRID_URL_LABEL = "Selenium grid URL"; public static final String DEFAULT_SELENIUM_GRID_URL = "http://localhost:4444/wd/hub"; @@ -49,10 +45,6 @@ private WebDriverHelper() { // restrict instantiation } - public static String getProp(Map properties, String name, String defaultValue) { - return PropertiesUtil.toString(properties.get(name), defaultValue); - } - public static Proxy setupProxy(ProxyServerWrapper proxyServer) throws WorkerException { proxyServer.setCaptureContent(true); proxyServer.setCaptureHeaders(true); diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/WebDriverProvider.java b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/WebDriverProvider.java index 940d16ef4..2e36723ba 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/WebDriverProvider.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/WebDriverProvider.java @@ -19,46 +19,50 @@ import com.cognifide.aet.job.api.exceptions.ProxyException; import com.cognifide.aet.proxy.ProxyServerProvider; import com.cognifide.aet.worker.api.WebDriverFactory; +import com.cognifide.aet.worker.drivers.configuration.WebDriverProviderConf; import com.cognifide.aet.worker.exceptions.WorkerException; import com.google.common.base.Joiner; import com.google.common.collect.Maps; import java.util.Map; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.ReferencePolicy; -import org.apache.felix.scr.annotations.Service; import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; +import org.osgi.service.metatype.annotations.Designate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author lukasz.wieczorek */ -@Service(WebDriverProvider.class) -@Component(label = "AET WebDriver Provider", description = "AET WebDriver Provider", immediate = true, metatype = true) -@Properties({@Property(name = Constants.SERVICE_VENDOR, value = "Cognifide Ltd")}) +@Component( + service = WebDriverProvider.class, + property = {"name = " + Constants.SERVICE_VENDOR, "value = Cognifide Ltd"}, + immediate = true +) +@Designate(ocd = WebDriverProviderConf.class) public class WebDriverProvider { private static final Logger LOG = LoggerFactory.getLogger(WebDriverProvider.class); - private static final String DEFAULT_WEB_DRIVER_NAME = "defaultWebDriverName"; + private WebDriverProviderConf config; - @Property(name = DEFAULT_WEB_DRIVER_NAME, label = "Default Web Driver name", value = "ff") - private String defaultWebDriverName; - - @Reference(referenceInterface = WebDriverFactory.class, policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, bind = "bindWebDriverFactory", unbind = "unbindWebDriverFactory") + @Reference( + service = WebDriverFactory.class, + policy = ReferencePolicy.DYNAMIC, + cardinality = ReferenceCardinality.MULTIPLE, + bind = "bindWebDriverFactory", + unbind = "unbindWebDriverFactory") private final Map collectorFactories = Maps.newConcurrentMap(); @Reference private ProxyServerProvider proxyServerProvider; @Activate - void activate(Map properties) { - defaultWebDriverName = properties.get(DEFAULT_WEB_DRIVER_NAME); + void activate(WebDriverProviderConf config) { + this.config = config; } public WebCommunicationWrapper createWebDriverWithProxy(String preferredWebDriver, String proxyName) @@ -94,7 +98,8 @@ protected void unbindWebDriverFactory(WebDriverFactory webDriverFactory) { */ private WebDriverFactory findWebDriverFactory(String preferredWebDriver) throws WorkerException { final WebDriverFactory webDriverFactory; - String id = preferredWebDriver == null ? defaultWebDriverName : preferredWebDriver; + String id = preferredWebDriver == null ? + config.defaultWebDriverName() : preferredWebDriver; webDriverFactory = collectorFactories.get(id); if (webDriverFactory == null) { String webDrivers = Joiner.on(", ").join(collectorFactories.keySet()); diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/chrome/ChromeWebDriverFactory.java b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/chrome/ChromeWebDriverFactory.java index aa405a2bd..4040708a9 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/chrome/ChromeWebDriverFactory.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/chrome/ChromeWebDriverFactory.java @@ -15,33 +15,19 @@ */ package com.cognifide.aet.worker.drivers.chrome; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.DEFAULT_SELENIUM_GRID_URL; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.NAME; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.NAME_DESC; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.NAME_LABEL; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.SELENIUM_GRID_URL; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.SELENIUM_GRID_URL_LABEL; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.getProp; import static com.cognifide.aet.worker.drivers.WebDriverHelper.setupProxy; import com.cognifide.aet.job.api.collector.HttpRequestExecutorFactory; import com.cognifide.aet.job.api.collector.ProxyServerWrapper; import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.worker.api.WebDriverFactory; +import com.cognifide.aet.worker.drivers.chrome.configuration.ChromeWebDriverFactoryConf; import com.cognifide.aet.worker.exceptions.WorkerException; import java.net.MalformedURLException; import java.net.URL; -import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import org.apache.commons.lang3.StringUtils; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.ConfigurationPolicy; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; @@ -52,37 +38,28 @@ import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; + -@Service @Component( - policy = ConfigurationPolicy.REQUIRE, - description = "AET Chrome WebDriver Factory", - label = "AET Chrome WebDriver Factory", - metatype = true) -@Properties({@Property(name = Constants.SERVICE_VENDOR, value = "Cognifide Ltd")}) + configurationPolicy = ConfigurationPolicy.REQUIRE, + property = {"name = " + Constants.SERVICE_VENDOR, "value = Cognifide Ltd"} +) +@Designate(ocd = ChromeWebDriverFactoryConf.class) public class ChromeWebDriverFactory implements WebDriverFactory { - private static final String DEFAULT_BROWSER_NAME = "chrome"; - @Reference private HttpRequestExecutorFactory requestExecutorFactory; - @Property(name = NAME, - label = NAME_LABEL, - description = NAME_DESC, - value = DEFAULT_BROWSER_NAME) - private String name; - - @Property(name = SELENIUM_GRID_URL, - label = SELENIUM_GRID_URL_LABEL, - description = "Url to selenium grid hub. When null local Chrome driver will be used. Local Chrome driver does not work on Linux", - value = DEFAULT_SELENIUM_GRID_URL) - private String seleniumGridUrl; + private ChromeWebDriverFactoryConf config; @Activate - public void activate(Map properties) { - this.name = getProp(properties, NAME, DEFAULT_BROWSER_NAME); - this.seleniumGridUrl = getProp(properties, SELENIUM_GRID_URL, DEFAULT_SELENIUM_GRID_URL); + public void activate(ChromeWebDriverFactoryConf config) { + this.config = config; } @Override @@ -104,7 +81,7 @@ public WebCommunicationWrapper createWebDriver(ProxyServerWrapper proxyServer) @Override public String getName() { - return name; + return config.name(); } private WebCommunicationWrapper createWebDriver(DesiredCapabilities capabilities, @@ -120,8 +97,10 @@ private WebCommunicationWrapper createWebDriver(DesiredCapabilities capabilities private WebDriver getChromeDriver(DesiredCapabilities capabilities) throws MalformedURLException { - WebDriver driver = StringUtils.isNotBlank(seleniumGridUrl) ? new RemoteWebDriver( - new URL(seleniumGridUrl), capabilities) : new ChromeDriver(capabilities); + WebDriver driver = + StringUtils.isNotBlank(config.seleniumGridUrl()) ? + new RemoteWebDriver(new URL(config.seleniumGridUrl()), capabilities) + : new ChromeDriver(capabilities); driver.manage().timeouts().pageLoadTimeout(5L, TimeUnit.MINUTES); return driver; } diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/chrome/configuration/ChromeWebDriverFactoryConf.java b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/chrome/configuration/ChromeWebDriverFactoryConf.java new file mode 100644 index 000000000..6548587ee --- /dev/null +++ b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/chrome/configuration/ChromeWebDriverFactoryConf.java @@ -0,0 +1,42 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.worker.drivers.chrome.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +import static com.cognifide.aet.worker.drivers.WebDriverHelper.DEFAULT_SELENIUM_GRID_URL; +import static com.cognifide.aet.worker.drivers.WebDriverHelper.NAME_LABEL; +import static com.cognifide.aet.worker.drivers.WebDriverHelper.NAME_DESC; +import static com.cognifide.aet.worker.drivers.WebDriverHelper.SELENIUM_GRID_URL_LABEL; + +@ObjectClassDefinition(name = "AET Chrome WebDriver Factory", description = "AET Chrome WebDriver Factory") +public @interface ChromeWebDriverFactoryConf { + + String DEFAULT_BROWSER_NAME = "chrome"; + + @AttributeDefinition( + name = NAME_LABEL, + description = NAME_DESC, + defaultValue = DEFAULT_BROWSER_NAME) + String name(); + + @AttributeDefinition( + name = SELENIUM_GRID_URL_LABEL, + description = SELENIUM_GRID_URL_LABEL, + defaultValue = DEFAULT_SELENIUM_GRID_URL) + String seleniumGridUrl(); +} diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/configuration/WebDriverProviderConf.java b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/configuration/WebDriverProviderConf.java new file mode 100644 index 000000000..edff1c208 --- /dev/null +++ b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/configuration/WebDriverProviderConf.java @@ -0,0 +1,28 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.worker.drivers.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "AET WebDriver Provider", description = "AET WebDriver Provider") +public @interface WebDriverProviderConf { + + String DEFAULT_WEB_DRIVER_NAME_LABEL = "Default Web Driver name"; + + @AttributeDefinition(name = DEFAULT_WEB_DRIVER_NAME_LABEL, defaultValue = "ff") + String defaultWebDriverName(); +} diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/firefox/local/FirefoxWebDriverFactory.java b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/firefox/local/FirefoxWebDriverFactory.java index 08f7c6497..f370b595f 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/firefox/local/FirefoxWebDriverFactory.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/firefox/local/FirefoxWebDriverFactory.java @@ -15,28 +15,16 @@ */ package com.cognifide.aet.worker.drivers.firefox.local; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.NAME; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.NAME_LABEL; -import static com.cognifide.aet.worker.drivers.WebDriverHelper.PATH; - import com.cognifide.aet.worker.drivers.firefox.FirefoxCommunicationWrapperImpl; import com.cognifide.aet.worker.drivers.firefox.FirefoxProfileBuilder; import com.cognifide.aet.job.api.collector.HttpRequestExecutorFactory; import com.cognifide.aet.job.api.collector.ProxyServerWrapper; import com.cognifide.aet.job.api.collector.WebCommunicationWrapper; import com.cognifide.aet.worker.api.WebDriverFactory; +import com.cognifide.aet.worker.drivers.firefox.local.configuration.FirefoxWebDriverFactoryConf; import com.cognifide.aet.worker.exceptions.WorkerException; import java.io.File; -import java.util.Map; import java.util.concurrent.TimeUnit; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.ConfigurationPolicy; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; @@ -44,38 +32,26 @@ import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; + -@Service @Component( - description = "AET Firefox WebDriver Factory", - label = "AET Firefox WebDriver Factory", - metatype = true) -@Properties({@Property(name = Constants.SERVICE_VENDOR, value = "Cognifide Ltd")}) + property = {"name = " + Constants.SERVICE_VENDOR, "value = Cognifide Ltd"} +) +@Designate(ocd = FirefoxWebDriverFactoryConf.class) public class FirefoxWebDriverFactory implements WebDriverFactory { - private static final String DEFAULT_FIREFOX_BINARY_PATH = "/usr/bin/firefox"; - - private static final String DEFAULT_FIREFOX_ERROR_LOG_FILE_PATH = "/opt/aet/firefox/log/stderr.log"; - - private static final String LOG_FILE_PATH = "logFilePath"; - - private static final String DEFAULT_FF_NAME = "ff"; - @Reference private HttpRequestExecutorFactory requestExecutorFactory; - @Property(name = NAME, label = NAME_LABEL, value = DEFAULT_FF_NAME) - private String name; - - @Property(name = PATH, label = "Custom path to Firefox binary", value = DEFAULT_FIREFOX_BINARY_PATH) - private String path; - - @Property(name = LOG_FILE_PATH, label = "Path to firefox error log", value = DEFAULT_FIREFOX_ERROR_LOG_FILE_PATH) - private String logFilePath; + private FirefoxWebDriverFactoryConf config; @Override public String getName() { - return name; + return config.name(); } @Override @@ -122,7 +98,7 @@ public WebCommunicationWrapper createWebDriver() throws WorkerException { private FirefoxProfile getFirefoxProfile() { final FirefoxProfile firefoxProfile = FirefoxProfileBuilder.newInstance() .withUnstableAndFastLoadStrategy() - .withLogfilePath(logFilePath) + .withLogfilePath(config.logFilePath()) .withFlashSwitchedOff() .withForcedAliasing() .withJavaScriptErrorCollectorPlugin() @@ -131,7 +107,7 @@ private FirefoxProfile getFirefoxProfile() { .withRandomPort() .withUpdateDisabled() .build(); - System.setProperty("webdriver.firefox.logfile", logFilePath); + System.setProperty("webdriver.firefox.logfile", config.logFilePath()); System.setProperty("webdriver.load.strategy", "unstable"); return firefoxProfile; } @@ -139,7 +115,7 @@ private FirefoxProfile getFirefoxProfile() { private void setCommonCapabilities(DesiredCapabilities capabilities, FirefoxProfile fp) { capabilities.setCapability(FirefoxDriver.PROFILE, fp); capabilities.setCapability("marionette", false); - capabilities.setCapability("firefox_binary", new File(path).getAbsolutePath()); + capabilities.setCapability("firefox_binary", new File(config.path()).getAbsolutePath()); } private WebDriver getFirefoxDriver(DesiredCapabilities capabilities) { @@ -149,11 +125,8 @@ private WebDriver getFirefoxDriver(DesiredCapabilities capabilities) { } @Activate - public void activate(Map properties) { - this.name = PropertiesUtil.toString(properties.get(NAME), DEFAULT_FF_NAME); - this.path = PropertiesUtil.toString(properties.get(PATH), DEFAULT_FIREFOX_BINARY_PATH); - this.logFilePath = PropertiesUtil - .toString(properties.get(LOG_FILE_PATH), DEFAULT_FIREFOX_ERROR_LOG_FILE_PATH); + public void activate(FirefoxWebDriverFactoryConf config) { + this.config = config; } } diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/drivers/firefox/local/configuration/FirefoxWebDriverFactoryConf.java b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/firefox/local/configuration/FirefoxWebDriverFactoryConf.java new file mode 100644 index 000000000..6980c68e0 --- /dev/null +++ b/core/worker/src/main/java/com/cognifide/aet/worker/drivers/firefox/local/configuration/FirefoxWebDriverFactoryConf.java @@ -0,0 +1,44 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.worker.drivers.firefox.local.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +import static com.cognifide.aet.worker.drivers.WebDriverHelper.NAME_LABEL; + +@ObjectClassDefinition(name = "AET Firefox WebDriver Factory", description = "AET Firefox WebDriver Factory") +public @interface FirefoxWebDriverFactoryConf { + + String PATH_LABEL = "Custom path to Firefox binary"; + + String DEFAULT_FF_NAME = "ff"; + + String DEFAULT_FIREFOX_BINARY_PATH = "/usr/bin/firefox"; + + String LOG_FILE_PATH_LABEL = "Path to firefox error log"; + + String DEFAULT_FIREFOX_ERROR_LOG_FILE_PATH = "/opt/aet/firefox/log/stderr.log"; + + @AttributeDefinition(name = NAME_LABEL, defaultValue = DEFAULT_FF_NAME) + String name(); + + @AttributeDefinition(name = PATH_LABEL, defaultValue = DEFAULT_FIREFOX_BINARY_PATH) + String path(); + + @AttributeDefinition(name = LOG_FILE_PATH_LABEL, defaultValue = DEFAULT_FIREFOX_ERROR_LOG_FILE_PATH) + String logFilePath(); +} diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/impl/CollectorDispatcherImpl.java b/core/worker/src/main/java/com/cognifide/aet/worker/impl/CollectorDispatcherImpl.java index 1bad32015..17aece7b1 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/impl/CollectorDispatcherImpl.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/impl/CollectorDispatcherImpl.java @@ -29,14 +29,12 @@ import com.cognifide.aet.worker.api.JobRegistry; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(immediate = true, label = "AET Collector Dispatcher", description = "Collector Dispatcher") +@Component(immediate = true) public class CollectorDispatcherImpl implements CollectorDispatcher { private static final Logger LOGGER = LoggerFactory.getLogger(CollectorDispatcherImpl.class); diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/impl/ComparatorDispatcherImpl.java b/core/worker/src/main/java/com/cognifide/aet/worker/impl/ComparatorDispatcherImpl.java index a6b5b4891..877a8d118 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/impl/ComparatorDispatcherImpl.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/impl/ComparatorDispatcherImpl.java @@ -35,14 +35,12 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(label = "AET Comparator Dispatcher", description = "Comparator Dispatcher", immediate = true) +@Component(immediate = true) public class ComparatorDispatcherImpl implements ComparatorDispatcher { private static final Logger LOGGER = LoggerFactory.getLogger(ComparatorDispatcherImpl.class); diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/impl/JobRegistryImpl.java b/core/worker/src/main/java/com/cognifide/aet/worker/impl/JobRegistryImpl.java index 5afe4eba6..80b3dd6ea 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/impl/JobRegistryImpl.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/impl/JobRegistryImpl.java @@ -21,31 +21,44 @@ import com.cognifide.aet.worker.api.JobRegistry; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.ReferencePolicy; -import org.apache.felix.scr.annotations.Service; import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(immediate = true, description = "AET JMS Registry", label = "AET Job Registry Implementation") -@Properties({@Property(name = Constants.SERVICE_VENDOR, value = "Cognifide Ltd")}) +@Component( + immediate = true, + property = {"name = " + Constants.SERVICE_VENDOR, "value = Cognifide Ltd"} +) public class JobRegistryImpl implements JobRegistry { private static final Logger LOGGER = LoggerFactory.getLogger(JobRegistryImpl.class); - @Reference(referenceInterface = CollectorFactory.class, policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, bind = "bindCollectorFactory", unbind = "unbindCollectorFactory") + @Reference( + service = CollectorFactory.class, + policy = ReferencePolicy.DYNAMIC, + cardinality = ReferenceCardinality.MULTIPLE, + bind = "bindCollectorFactory", + unbind = "unbindCollectorFactory") private Map collectorFactories = new ConcurrentHashMap<>(); - @Reference(referenceInterface = ComparatorFactory.class, policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, bind = "bindComparatorFactory", unbind = "unbindComparatorFactory") + @Reference( + service = ComparatorFactory.class, + policy = ReferencePolicy.DYNAMIC, + cardinality = ReferenceCardinality.MULTIPLE, + bind = "bindComparatorFactory", + unbind = "unbindComparatorFactory") private Map comparatorFactoryMap = new ConcurrentHashMap<>(); - @Reference(referenceInterface = DataFilterFactory.class, policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, bind = "bindDataModifierFactory", unbind = "unbindDataModifierFactory") + @Reference( + service = DataFilterFactory.class, + policy = ReferencePolicy.DYNAMIC, + cardinality = ReferenceCardinality.MULTIPLE, + bind = "bindDataModifierFactory", + unbind = "unbindDataModifierFactory") private Map dataModifierFactoryMap = new ConcurrentHashMap<>(); private Map defaultComparatorMap = new ConcurrentHashMap<>(); diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/listeners/AbstractTaskMessageListener.java b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/AbstractTaskMessageListener.java index 91c9346ca..5b3892a68 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/listeners/AbstractTaskMessageListener.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/AbstractTaskMessageListener.java @@ -18,45 +18,20 @@ import com.cognifide.aet.communication.api.queues.JmsConnection; import com.cognifide.aet.queues.JmsUtils; import com.cognifide.aet.worker.results.FeedbackQueue; -import java.util.Map; import javax.jms.JMSException; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.Session; -import org.apache.commons.lang3.StringUtils; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Property; -@Component public abstract class AbstractTaskMessageListener implements MessageListener { - protected static final String LISTENER_NAME = "name"; + private Session jmsSession; - protected static final String CONSUMER_QUEUE_NAME = "consumerQueueName"; + private MessageConsumer consumer; - protected static final String PRODUCER_QUEUE_NAME = "producerQueueName"; + FeedbackQueue feedbackQueue; - protected static final String PREFETCH_SIZE_NAME = "pf"; - - protected static final String PREFETCH_SIZE_DEFAULT_VALUE = "1"; - - protected Session jmsSession; - - protected MessageConsumer consumer; - - protected FeedbackQueue feedbackQueue; - - @Property(name = PREFETCH_SIZE_NAME, label = "Prefetch size", description = "http://activemq.apache.org/what-is-the-prefetch-limit-for.html", value = PREFETCH_SIZE_DEFAULT_VALUE) - private String prefetchSize; - - protected void doActivate(Map properties) { - setName(properties.get(LISTENER_NAME)); - this.prefetchSize = StringUtils.defaultString(properties.get(PREFETCH_SIZE_NAME), - PREFETCH_SIZE_DEFAULT_VALUE); - String consumerQueueName = properties.get(CONSUMER_QUEUE_NAME); - setConsumerQueueName(consumerQueueName); - String producerQueueName = properties.get(PRODUCER_QUEUE_NAME); - setProducerQueueName(producerQueueName); + void doActivate(String consumerQueueName, String producerQueueName, String prefetchSize) { String queueName = consumerQueueName + "?consumer.prefetchSize=" + prefetchSize; try { @@ -69,7 +44,7 @@ protected void doActivate(Map properties) { } } - protected void doDeactivate() { + void doDeactivate() { if (feedbackQueue != null) { feedbackQueue.close(); } @@ -77,12 +52,6 @@ protected void doDeactivate() { JmsUtils.closeQuietly(jmsSession); } - protected abstract void setName(String name); - - protected abstract void setConsumerQueueName(String consumerQueueName); - - protected abstract void setProducerQueueName(String producerQueueName); - protected abstract JmsConnection getJmsConnection(); } diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/listeners/CollectorMessageListenerImpl.java b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/CollectorMessageListenerImpl.java index 276bfc203..a9c04e5fb 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/listeners/CollectorMessageListenerImpl.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/CollectorMessageListenerImpl.java @@ -28,35 +28,25 @@ import com.cognifide.aet.worker.api.CollectorDispatcher; import com.cognifide.aet.worker.drivers.WebDriverProvider; import com.cognifide.aet.worker.exceptions.WorkerException; -import java.util.Map; import javax.jms.JMSException; import javax.jms.Message; import org.apache.commons.lang3.StringUtils; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.ConfigurationPolicy; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(immediate = true, metatype = true, label = "AET Collector Message Listener", policy = ConfigurationPolicy.REQUIRE, configurationFactory = true) +@Component( + service = CollectorMessageListenerImpl.class, + immediate = true) +@Designate(ocd = CollectorMessageListenerImplConfig.class, factory = true) public class CollectorMessageListenerImpl extends AbstractTaskMessageListener { private static final Logger LOGGER = LoggerFactory.getLogger(CollectorMessageListenerImpl.class); - @Property(name = LISTENER_NAME, label = "Collector name", description = "Name of collector. Used in logs only", value = "Collector") - private String name; - - @Property(name = CONSUMER_QUEUE_NAME, label = "Consumer queue name", value = "AET.collectorJobs") - private String consumerQueueName; - - @Property(name = PRODUCER_QUEUE_NAME, label = "Producer queue name", value = "AET.collectorResults") - private String producerQueueName; - @Reference private JmsConnection jmsConnection; @@ -66,9 +56,12 @@ public class CollectorMessageListenerImpl extends AbstractTaskMessageListener { @Reference private WebDriverProvider webDriverProvider; + private CollectorMessageListenerImplConfig config; + @Activate - void activate(Map properties) { - super.doActivate(properties); + void activate(CollectorMessageListenerImplConfig config) { + this.config = config; + super.doActivate(config.consumerQueueName(), config.producerQueueName(), config.pf()); } @Deactivate @@ -90,7 +83,8 @@ public void onMessage(final Message message) { && requestMessageId != null) { LOGGER.info( "CollectorJobData [{}] message arrived with {} urls. CorrelationId: {} RequestMessageId: {}", - name, collectorJobData.getUrls().size(), correlationId, requestMessageId); + config.name(), collectorJobData.getUrls().size(), correlationId, + requestMessageId); WebCommunicationWrapper webCommunicationWrapper = null; int collected = 0; String preferredWebDriver = collectorJobData.getPreferredBrowserId(); @@ -181,21 +175,6 @@ private void quitWebDriver(WebCommunicationWrapper webCommunicationWrapper) { } } - @Override - protected void setName(String name) { - this.name = name; - } - - @Override - protected void setConsumerQueueName(String consumerQueueName) { - this.consumerQueueName = consumerQueueName; - } - - @Override - protected void setProducerQueueName(String producerQueueName) { - this.producerQueueName = producerQueueName; - } - @Override protected JmsConnection getJmsConnection() { return jmsConnection; diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/listeners/CollectorMessageListenerImplConfig.java b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/CollectorMessageListenerImplConfig.java new file mode 100644 index 000000000..fb4fcc39a --- /dev/null +++ b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/CollectorMessageListenerImplConfig.java @@ -0,0 +1,59 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.worker.listeners; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "AET Collector Message Listener") +public @interface CollectorMessageListenerImplConfig { + + String LISTENER_NAME_LABEL = "Collector name"; + String LISTENER_NAME_DESC = "Name of collector. Used in logs only"; + String LISTENER_NAME_DEFAULT_VALUE = "Collector"; + + String CONSUMER_QUEUE_NAME_LABEL = "Consumer queue name"; + String CONSUMER_QUEUE_NAME_DEFAULT_VALUE = "AET.collectorJobs"; + + String PRODUCER_QUEUE_NAME_LABEL = "Producer queue name"; + String PRODUCER_QUEUE_NAME_DEFAULT_VALUE = "AET.collectorResults"; + + String PREFETCH_SIZE_LABEL = "Prefetch size"; + String PREFETCH_SIZE_DESC = "http://activemq.apache.org/what-is-the-prefetch-limit-for.html"; + String PREFETCH_SIZE_DEFAULT_VALUE = "1"; + + @AttributeDefinition( + name = LISTENER_NAME_LABEL, + description = LISTENER_NAME_DESC, + defaultValue = LISTENER_NAME_DEFAULT_VALUE) + String name(); + + @AttributeDefinition( + name = CONSUMER_QUEUE_NAME_LABEL, + defaultValue = CONSUMER_QUEUE_NAME_DEFAULT_VALUE) + String consumerQueueName(); + + @AttributeDefinition( + name = PRODUCER_QUEUE_NAME_LABEL, + defaultValue = PRODUCER_QUEUE_NAME_DEFAULT_VALUE) + String producerQueueName(); + + @AttributeDefinition( + name = PREFETCH_SIZE_LABEL, + description = PREFETCH_SIZE_DESC, + defaultValue = PREFETCH_SIZE_DEFAULT_VALUE) + String pf(); +} diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/listeners/ComparatorMessageListenerImpl.java b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/ComparatorMessageListenerImpl.java index 1ab6bca17..2ec477be1 100644 --- a/core/worker/src/main/java/com/cognifide/aet/worker/listeners/ComparatorMessageListenerImpl.java +++ b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/ComparatorMessageListenerImpl.java @@ -26,44 +26,37 @@ import com.cognifide.aet.job.api.comparator.ComparatorProperties; import com.cognifide.aet.queues.JmsUtils; import com.cognifide.aet.worker.api.ComparatorDispatcher; -import java.util.Map; import javax.jms.JMSException; import javax.jms.Message; import org.apache.commons.lang3.StringUtils; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.ConfigurationPolicy; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(immediate = true, metatype = true, label = "AET Comparator Message Listener", policy = ConfigurationPolicy.REQUIRE, configurationFactory = true) +@Component( + service = ComparatorMessageListenerImpl.class, + immediate = true) +@Designate(ocd = ComparatorMessageListenerImplConfig.class, factory = true) public class ComparatorMessageListenerImpl extends AbstractTaskMessageListener { private static final Logger LOGGER = LoggerFactory.getLogger(ComparatorMessageListenerImpl.class); - @Property(name = LISTENER_NAME, label = "Comparator name", description = "Name of comparator. Used in logs only", value = "Comparator") - private String name; - - @Property(name = CONSUMER_QUEUE_NAME, label = "Consumer queue name", value = "AET.comparatorJobs") - private String consumerQueueName; - - @Property(name = PRODUCER_QUEUE_NAME, label = "Producer queue name", value = "AET.comparatorResults") - private String producerQueueName; - @Reference private JmsConnection jmsConnection; @Reference private ComparatorDispatcher dispatcher; + private ComparatorMessageListenerImplConfig config; + @Activate - void activate(Map properties) { - super.doActivate(properties); + void activate(ComparatorMessageListenerImplConfig config) { + this.config = config; + super.doActivate(config.consumerQueueName(), config.producerQueueName(), config.pf()); } @Deactivate @@ -124,21 +117,6 @@ public void onMessage(final Message message) { } } - @Override - protected void setName(String name) { - this.name = name; - } - - @Override - protected void setConsumerQueueName(String consumerQueueName) { - this.consumerQueueName = consumerQueueName; - } - - @Override - protected void setProducerQueueName(String producerQueueName) { - this.producerQueueName = producerQueueName; - } - @Override protected JmsConnection getJmsConnection() { return jmsConnection; diff --git a/core/worker/src/main/java/com/cognifide/aet/worker/listeners/ComparatorMessageListenerImplConfig.java b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/ComparatorMessageListenerImplConfig.java new file mode 100644 index 000000000..45f9f3749 --- /dev/null +++ b/core/worker/src/main/java/com/cognifide/aet/worker/listeners/ComparatorMessageListenerImplConfig.java @@ -0,0 +1,59 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.worker.listeners; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "AET Comparator Message Listener") +public @interface ComparatorMessageListenerImplConfig { + + String LISTENER_NAME_LABEL = "Comparator name"; + String LISTENER_NAME_DESC = "Name of comparator. Used in logs only"; + String LISTENER_NAME_DEFAULT_VALUE = "Comparator"; + + String CONSUMER_QUEUE_NAME_LABEL = "Consumer queue name"; + String CONSUMER_QUEUE_NAME_DEFAULT_VALUE = "AET.comparatorJobs"; + + String PRODUCER_QUEUE_NAME_LABEL = "Producer queue name"; + String PRODUCER_QUEUE_NAME_DEFAULT_VALUE = "AET.comparatorResults"; + + String PREFETCH_SIZE_LABEL = "Prefetch size"; + String PREFETCH_SIZE_DESC = "http://activemq.apache.org/what-is-the-prefetch-limit-for.html"; + String PREFETCH_SIZE_DEFAULT_VALUE = "1"; + + @AttributeDefinition( + name = LISTENER_NAME_LABEL, + description = LISTENER_NAME_DESC, + defaultValue = LISTENER_NAME_DEFAULT_VALUE) + String name(); + + @AttributeDefinition( + name = CONSUMER_QUEUE_NAME_LABEL, + defaultValue = CONSUMER_QUEUE_NAME_DEFAULT_VALUE) + String consumerQueueName(); + + @AttributeDefinition( + name = PRODUCER_QUEUE_NAME_LABEL, + defaultValue = PRODUCER_QUEUE_NAME_DEFAULT_VALUE) + String producerQueueName(); + + @AttributeDefinition( + name = PREFETCH_SIZE_LABEL, + description = PREFETCH_SIZE_DESC, + defaultValue = PREFETCH_SIZE_DEFAULT_VALUE) + String pf(); +} diff --git a/documentation/src/main/wiki/HowToExtendAET.md b/documentation/src/main/wiki/HowToExtendAET.md index 2d6ecfa11..4161b573a 100644 --- a/documentation/src/main/wiki/HowToExtendAET.md +++ b/documentation/src/main/wiki/HowToExtendAET.md @@ -101,9 +101,22 @@ be available on the Karaf instance that AET are running at. - org.apache.felix - org.apache.felix.scr.annotations - ${felix.version} + org.osgi + org.osgi.service.component.annotations + 1.3.0 + provided + + + org.osgi + org.osgi.annotation + 6.0.0 + provided + + + org.osgi + org.osgi.service.metatype.annotations + 1.3.0 + provided @@ -119,11 +132,6 @@ be available on the Karaf instance that AET are running at. org.apache.felix maven-bundle-plugin - - - org.apache.felix - maven-scr-plugin - @@ -145,19 +153,6 @@ be available on the Karaf instance that AET are running at. true - - org.apache.felix - maven-scr-plugin - 1.15.0 - - - generate-scr-scrdescriptor - - scr - - - - diff --git a/documentation/src/main/wiki/UpgradeNotes.md b/documentation/src/main/wiki/UpgradeNotes.md index f27c6d17f..a62195d93 100644 --- a/documentation/src/main/wiki/UpgradeNotes.md +++ b/documentation/src/main/wiki/UpgradeNotes.md @@ -7,3 +7,27 @@ You may see all changes in the [Changelog](https://github.com/Cognifide/aet/blob ## Unreleased +### [PR-326](https://github.com/Cognifide/aet/pull/326) Upgrade OSGI annotations to 6.0.0 version + +With the OSGI annotations update to 6.0.0 version we had to change a little bit variable names. Currently, your config could have old names and you have to update them. Please follow instruction below: + +Modify following OSGi config files (by default they should be located in `/opt/aet/karaf/aet_configs/current`): + +|File name|Way to change variable names| +|---|---| +|`com.cognifide.aet.rest.helpers.ReportConfigurationManager.cfg`|`report-domain -> reportDomain`| +|`com.cognifide.aet.runner.MessagesManager.cfg`|`jxm-url -> jxmUrl`| +|`com.cognifide.aet.vs.mongodb.MongoDBClient.cfg`|`MongoURI -> mongoURI`
`AllowAutoCreate -> allowAutoCreate`| + +For example in `com.cognifide.aet.vs.mongodb.MongoDBClient.cfg`: +``` +MongoURI=mongodb://localhost +AllowAutoCreate=true +``` + +Please replace it by: +``` +mongoURI=mongodb://localhost +allowAutoCreate=true +``` + diff --git a/osgi-dependencies/aet-features.xml b/osgi-dependencies/aet-features.xml index 97fdf52f8..1508cce78 100644 --- a/osgi-dependencies/aet-features.xml +++ b/osgi-dependencies/aet-features.xml @@ -79,7 +79,6 @@ mvn:com.google.guava/guava/25.1-jre mvn:org.jsoup/jsoup/1.11.3 mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.quartz/2.3.0_2 - mvn:org.apache.sling/org.apache.sling.commons.osgi/2.2.2 diff --git a/osgi-dependencies/configs/src/main/resources/com.cognifide.aet.vs.mongodb.MongoDBClient.cfg b/osgi-dependencies/configs/src/main/resources/com.cognifide.aet.vs.mongodb.MongoDBClient.cfg index 223908d7d..bd7f253ed 100644 --- a/osgi-dependencies/configs/src/main/resources/com.cognifide.aet.vs.mongodb.MongoDBClient.cfg +++ b/osgi-dependencies/configs/src/main/resources/com.cognifide.aet.vs.mongodb.MongoDBClient.cfg @@ -16,5 +16,5 @@ # limitations under the License. # -MongoURI=mongodb://localhost -AllowAutoCreate=true +mongoURI=mongodb://localhost +allowAutoCreate=true diff --git a/osgi-dependencies/proxy/pom.xml b/osgi-dependencies/proxy/pom.xml index 542f956b8..daf6c8e4b 100644 --- a/osgi-dependencies/proxy/pom.xml +++ b/osgi-dependencies/proxy/pom.xml @@ -48,13 +48,23 @@ org.osgi org.osgi.core
+ - org.json - json + org.osgi + org.osgi.service.component.annotations + + + org.osgi + org.osgi.annotation + + + org.osgi + org.osgi.service.metatype.annotations + - org.apache.sling - org.apache.sling.commons.osgi + org.json + json com.google.code.gson @@ -64,12 +74,7 @@ org.apache.httpcomponents httpclient - - - org.apache.felix - org.apache.felix.scr.annotations - - + com.github.detro @@ -79,18 +84,6 @@ - - org.apache.felix - maven-scr-plugin - - - generate-scr-descriptor - - scr - - - - org.apache.felix maven-bundle-plugin diff --git a/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/ProxyServerProvider.java b/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/ProxyServerProvider.java index 91cf2da3d..7c09c045c 100644 --- a/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/ProxyServerProvider.java +++ b/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/ProxyServerProvider.java @@ -19,22 +19,21 @@ import com.cognifide.aet.job.api.exceptions.ProxyException; import com.google.common.collect.Maps; import java.util.Map; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.ReferencePolicy; -import org.apache.felix.scr.annotations.Service; import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; -@Service(ProxyServerProvider.class) -@Component(immediate = true, label = "AET Proxy Server Provider", description = "AET Proxy Server Provider") -@Properties({@Property(name = Constants.SERVICE_VENDOR, value = "Cognifide Ltd")}) +@Component( + service = ProxyServerProvider.class, + immediate = true, + property = {"name = " + Constants.SERVICE_VENDOR, "value = Cognifide Ltd"} +) public class ProxyServerProvider { - @Reference(referenceInterface = ProxyManager.class, policy = ReferencePolicy.DYNAMIC, - cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, bind = "bindProxyManager", + @Reference(service = ProxyManager.class, policy = ReferencePolicy.DYNAMIC, + cardinality = ReferenceCardinality.MULTIPLE, bind = "bindProxyManager", unbind = "unbindProxyManager") private final Map collectorManagers = Maps.newConcurrentMap(); diff --git a/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/RestProxyManager.java b/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/RestProxyManager.java index e0e545d5e..0c3c552f9 100644 --- a/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/RestProxyManager.java +++ b/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/RestProxyManager.java @@ -16,60 +16,32 @@ package com.cognifide.aet.proxy; import com.cognifide.aet.job.api.exceptions.ProxyException; +import com.cognifide.aet.proxy.configuration.RestProxyManagerConf; import com.github.detro.browsermobproxyclient.BMPCProxy; import com.github.detro.browsermobproxyclient.exceptions.BMPCUnableToConnectException; import com.github.detro.browsermobproxyclient.manager.BMPCDefaultManager; import com.google.common.collect.Sets; -import java.util.Map; import java.util.Set; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.metatype.annotations.Designate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(immediate = true, metatype = true, description = "AET REST Proxy Manager", label = "AET REST Proxy Manager") +@Component(immediate = true) +@Designate(ocd = RestProxyManagerConf.class) public class RestProxyManager implements ProxyManager { public static final String CREATE_PROXY_EXCEPTION_FORMAT = "Unable to create proxy! Reached max attempts: %d"; private static final String NAME = "rest"; - private static final String SERVER_PROPERTY_NAME = "server"; - - private static final String PORT_PROPERTY_NAME = "port"; - - private static final String MAX_ATTEMPTS_PROPERTY_NAME = "maxAttempts"; - - private static final String ATTEMPTS_INTERVAL_PROPERTY_NAME = "attemptsInterval"; - - private static final String DEFAULT_SERVER = "localhost"; - - private static final int DEFAULT_PORT = 9272; - - private static final int DEFAULT_MAX_ATTEMPTS = 3; - - private static final int DEFAULT_ATTEMPTS_INTERVAL = 50; - private static final Logger LOG = LoggerFactory.getLogger(RestProxyManager.class); private final Set proxies = Sets.newHashSet(); - @Property(name = SERVER_PROPERTY_NAME, label = "Server", description = "BrowserMob server address", value = DEFAULT_SERVER) - private String server; - - @Property(name = PORT_PROPERTY_NAME, label = "Port", description = "BrowserMob API port", intValue = 8080) - private int port; - - @Property(name = MAX_ATTEMPTS_PROPERTY_NAME, label = "Max attempts", description = "Maximum number of attempts that will be performed to create single proxy", intValue = 3) - private int maxAttempts; - - @Property(name = ATTEMPTS_INTERVAL_PROPERTY_NAME, label = "Attempts interval", description = "Wait interval for failed Attempts", intValue = 50) - private int attemptsInterval; + private RestProxyManagerConf config; private BMPCDefaultManager manager; @@ -79,13 +51,8 @@ public String getName() { } @Activate - public void activate(Map properties) { - port = PropertiesUtil.toInteger(properties.get(PORT_PROPERTY_NAME), DEFAULT_PORT); - server = PropertiesUtil.toString(properties.get(SERVER_PROPERTY_NAME), DEFAULT_SERVER); - maxAttempts = PropertiesUtil - .toInteger(properties.get(MAX_ATTEMPTS_PROPERTY_NAME), DEFAULT_MAX_ATTEMPTS); - attemptsInterval = PropertiesUtil - .toInteger(properties.get(ATTEMPTS_INTERVAL_PROPERTY_NAME), DEFAULT_ATTEMPTS_INTERVAL); + public void activate(RestProxyManagerConf config) { + this.config = config; } @Deactivate @@ -99,7 +66,7 @@ public void deactivate() { public RestProxyServer createProxy() throws ProxyException { RestProxyServer proxy; if (manager == null) { - manager = new BMPCDefaultManager(server, port); + manager = new BMPCDefaultManager(config.server(), config.port()); } proxy = new RestProxyServer(getBmpcProxy(), this); proxies.add(proxy); @@ -114,13 +81,15 @@ private BMPCProxy getBmpcProxy() throws ProxyException { try { bmpcProxy = manager.createProxy(); } catch (BMPCUnableToConnectException e) { - if (++attempt >= maxAttempts) { - throw new ProxyException(String.format(CREATE_PROXY_EXCEPTION_FORMAT, maxAttempts), e); + if (++attempt >= config.maxAttempts()) { + throw new ProxyException( + String.format(CREATE_PROXY_EXCEPTION_FORMAT, config.maxAttempts()), e); } - LOG.warn(String.format("Failed to create Proxy attempt %d/%d", attempt, maxAttempts)); + LOG.warn( + String.format("Failed to create Proxy attempt %d/%d", attempt, config.maxAttempts())); try { - Thread.sleep(attemptsInterval); + Thread.sleep(config.attemptsInterval()); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); } @@ -135,11 +104,11 @@ public void detach(RestProxyServer proxy) { } public String getServer() { - return server; + return config.server(); } public int getPort() { - return port; + return config.port(); } } diff --git a/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/configuration/RestProxyManagerConf.java b/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/configuration/RestProxyManagerConf.java new file mode 100644 index 000000000..fd154cef5 --- /dev/null +++ b/osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/configuration/RestProxyManagerConf.java @@ -0,0 +1,45 @@ +/** + * AET + * + * Copyright (C) 2013 Cognifide Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.cognifide.aet.proxy.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.AttributeType; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(description = "AET REST Proxy Manager", name = "AET REST Proxy Manager") +public @interface RestProxyManagerConf { + String SERVER_PROPERTY_NAME = "server"; + + String PORT_PROPERTY_NAME = "port"; + + String MAX_ATTEMPTS_PROPERTY_NAME = "maxAttempts"; + + String ATTEMPTS_INTERVAL_PROPERTY_NAME = "attemptsInterval"; + + String DEFAULT_SERVER = "localhost"; + + @AttributeDefinition(name = SERVER_PROPERTY_NAME, description = "BrowserMob server address", type = AttributeType.STRING) + String server() default DEFAULT_SERVER; + + @AttributeDefinition(name = PORT_PROPERTY_NAME, description = "BrowserMob API port", type = AttributeType.INTEGER) + int port() default 8080; + + @AttributeDefinition(name = MAX_ATTEMPTS_PROPERTY_NAME, description = "Maximum number of attempts that will be performed to create single proxy", type = AttributeType.INTEGER) + int maxAttempts() default 3; + + @AttributeDefinition(name = ATTEMPTS_INTERVAL_PROPERTY_NAME, description = "Wait interval for failed Attempts", type = AttributeType.INTEGER) + int attemptsInterval() default 50; +} diff --git a/pom.xml b/pom.xml index 0d78e339e..509f076b0 100644 --- a/pom.xml +++ b/pom.xml @@ -174,6 +174,25 @@ + + + org.osgi + org.osgi.service.component.annotations + 1.3.0 + provided + + + org.osgi + org.osgi.annotation + 6.0.0 + provided + + + org.osgi + org.osgi.service.metatype.annotations + 1.3.0 + provided + org.osgi org.osgi.core @@ -288,12 +307,6 @@ 3.8.0 provided - - org.apache.sling - org.apache.sling.commons.osgi - 2.2.2 - provided - org.json json @@ -345,13 +358,6 @@ provided - - org.apache.felix - org.apache.felix.scr.annotations - 1.12.0 - provided - -