diff --git a/pom.xml b/pom.xml index 9061665..8e5bc51 100644 --- a/pom.xml +++ b/pom.xml @@ -45,12 +45,12 @@ org.sonatype.nexus.plugins nexus-plugins - 2.11.2-06 + 2.11.3-01 ${project.name} - Facilitates push-replication to remote proxy repositories. + Facilitates push-replication to remote proxy repositories (6). ${project.parent.version} @@ -67,6 +67,13 @@ ${nexus.version} provided + + org.sonatype.nexus.plugins + nexus-capabilities-plugin + ${nexus-plugin.type} + ${nexus.version} + provided + org.sonatype.nexus nexus-plugin-testsupport @@ -136,6 +143,11 @@ jackson-jaxrs 1.9.13 + + org.codehaus.jackson + jackson-mapper-asl + 1.9.13 + org.sonatype.nexus nexus-client-core diff --git a/replication-plugin.xml b/replication-plugin.xml index 6c34fa2..80be65d 100644 --- a/replication-plugin.xml +++ b/replication-plugin.xml @@ -18,7 +18,10 @@ requestsQueueSize and requestsSendingThreadsCount attributes define thread pool requests from master to peers asynchronously. The default values are: 500 for requestsQueueSize and 1 for requestsSendingThreadsCount --> - + http://localhost:8083/nexus diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/ReplicationPluginConfigurationStorage.java b/src/main/java/com/griddynamics/cd/nrp/internal/ReplicationPluginConfigurationStorage.java new file mode 100644 index 0000000..4ea467c --- /dev/null +++ b/src/main/java/com/griddynamics/cd/nrp/internal/ReplicationPluginConfigurationStorage.java @@ -0,0 +1,135 @@ +package com.griddynamics.cd.nrp.internal; + +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.ToString; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; + +@Named(value = "replicationPluginConfigurationStorage") +@Singleton +public class ReplicationPluginConfigurationStorage { + + Logger logger = + LoggerFactory.getLogger(ReplicationPluginConfigurationStorage.class); + + private final AtomicReference masterServerURLPrefix = new AtomicReference<>(); + private final AtomicReference requestQueueSize = new AtomicReference<>(); + private final AtomicReference requestSendingThreadCount = new AtomicReference<>(); + private final AtomicReference requestQueueDumpFileName = new AtomicReference<>();; + private final AtomicReference> servers = new AtomicReference<>(); + + @Inject + public ReplicationPluginConfigurationStorage() { + servers.set(new LinkedHashSet()); + } + + public String getMasterServerURLPrefix() { + String retVal = masterServerURLPrefix.get(); + if(retVal == null){ + throw new RuntimeException("Replication plugin configuration not ready yet!"); + } + return retVal; + } + + public void setMasterServerURLPrefix(String masterServerURLPrefix) { + this.masterServerURLPrefix.set(masterServerURLPrefix); + logger.info(toString()); + } + + public String getRequestQueueDumpFileName() { + String retVal = requestQueueDumpFileName.get(); + if(retVal == null){ + throw new RuntimeException("Replication plugin configuration not ready yet!"); + } + return retVal; + } + + public void setRequestQueueDumpFileName(String requestQueueDumpFileName) { + this.requestQueueDumpFileName.set(requestQueueDumpFileName); + logger.info(toString()); + } + + public Set getServers() { + Set retVal = servers.get(); + if(retVal == null){ + throw new RuntimeException("Replication plugin configuration not ready yet!"); + } + return retVal; + } + + public void setServers(Set nexusServers) { + servers.get().clear(); + servers.get().addAll(nexusServers); + logger.info(toString()); + } + + public int getRequestSendingThreadCount() { + Integer retVal = requestSendingThreadCount.get(); + if(retVal == null){ + throw new RuntimeException("Replication plugin configuration not ready yet!"); + } + return retVal; + } + + public void setRequestSendingThreadCount(int requestSendingThreadCount) { + this.requestSendingThreadCount.set(requestSendingThreadCount); + logger.info(toString()); + } + + public int getRequestQueueSize() { + Integer retVal = requestQueueSize.get(); + if(retVal == null){ + throw new RuntimeException("Replication plugin configuration not ready yet!"); + } + return retVal; + } + + public void setRequestQueueSize(int requestQueueSize) { + this.requestQueueSize.set(requestQueueSize); + logger.info(toString()); + } + + @Override + public String toString() { + return "ReplicationPluginConfigurationStorage{" + + "masterServerURLPrefix='" + masterServerURLPrefix + '\'' + + ", requestQueueSize=" + requestQueueSize.get() + + ", requestSendingThreadCount=" + requestSendingThreadCount.get() + + ", requestQueueDumpFileName='" + requestQueueDumpFileName + '\'' + + ", servers=" + servers + + '}'; + } + + @NoArgsConstructor + @RequiredArgsConstructor + @ToString + public static class NexusServer { + @NonNull + private String url; + @NonNull + private String user; + @NonNull + private String password; + + public String getUrl() { + return url; + } + + public String getUser() { + return user; + } + + public String getPassword() { + return password; + } + } +} diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilitiesBooter.java b/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilitiesBooter.java new file mode 100644 index 0000000..53a576f --- /dev/null +++ b/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilitiesBooter.java @@ -0,0 +1,31 @@ +package com.griddynamics.cd.nrp.internal.capabilities; + +import javax.inject.Named; + +import com.google.common.collect.ImmutableMap; +import org.sonatype.nexus.plugins.capabilities.CapabilityRegistry; +import org.sonatype.nexus.plugins.capabilities.support.CapabilityBooterSupport; + +import org.eclipse.sisu.EagerSingleton; + +import java.util.Collections; + +@Named +@EagerSingleton +public class GridCapabilitiesBooter + extends CapabilityBooterSupport +{ + + @Override + protected void boot(final CapabilityRegistry registry) + throws Exception + { + maybeAddCapability( + registry, + GridCapabilityDescriptor.TYPE, + true, // enabled + null, // no notes + Collections.emptyMap()); + } + +} diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapability.java b/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapability.java new file mode 100644 index 0000000..ea14302 --- /dev/null +++ b/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapability.java @@ -0,0 +1,80 @@ +package com.griddynamics.cd.nrp.internal.capabilities; + +import com.griddynamics.cd.nrp.internal.ReplicationPluginConfigurationStorage; +import com.griddynamics.cd.nrp.internal.uploading.ArtifactUpdateApiClient; +import com.griddynamics.cd.nrp.internal.uploading.impl.factories.JerseyClientFactory; +import org.jetbrains.annotations.NonNls; +import org.sonatype.nexus.capability.support.CapabilitySupport; +import org.sonatype.nexus.plugins.capabilities.Condition; +import org.sonatype.nexus.plugins.capabilities.Evaluable; + +import javax.inject.Inject; +import javax.inject.Named; +import java.util.HashMap; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; + +@Named(GridCapabilityDescriptor.TYPE_ID) +public class GridCapability + extends CapabilitySupport { + @NonNls + public static final String NL = System.getProperty("line.separator"); + + private final ReplicationPluginConfigurationStorage gridRegistry; + private final ArtifactUpdateApiClient artifactUpdateApiClient; + private final JerseyClientFactory jerseyClientFactory; + + @Inject + public GridCapability(final ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage, + final ArtifactUpdateApiClient artifactUpdateApiClient, + final JerseyClientFactory jerseyClientFactory) { + this.gridRegistry = checkNotNull(replicationPluginConfigurationStorage); + this.artifactUpdateApiClient = artifactUpdateApiClient; + this.jerseyClientFactory = jerseyClientFactory; + } + + @Override + protected GridCapabilityConfiguration createConfig(final Map properties) throws Exception { + Map newProperties = new HashMap<>(properties); + return new GridCapabilityConfiguration(newProperties); + } + + @Override + public void configure(final GridCapabilityConfiguration config){ + gridRegistry.setMasterServerURLPrefix(config.getMasterServerURLPrefix()); + gridRegistry.setRequestQueueSize(config.getRequestQueueSize()); + gridRegistry.setRequestSendingThreadCount(config.getRequestSendingThreadCount()); + gridRegistry.setRequestQueueDumpFileName(config.getRequestQueueDumpFileName()); + gridRegistry.setServers(config.getNexusServers()); + jerseyClientFactory.onActivate(); + artifactUpdateApiClient.onActivate(); + } + + @Override + public Condition activationCondition() { + return conditions().capabilities().evaluable( + new Evaluable() { + @Override + public boolean isSatisfied() { + return true; + } + + @Override + public String explainSatisfied() { + return "\"createrepo\" and \"mergerepo\" are available"; + } + + @Override + public String explainUnsatisfied() { + return ""; + } + } + ); + } + + @Override + protected String renderStatus() { + return "Sample Nexus replication plugin status"; + } +} diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilityConfiguration.java b/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilityConfiguration.java new file mode 100644 index 0000000..da7eecc --- /dev/null +++ b/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilityConfiguration.java @@ -0,0 +1,84 @@ +package com.griddynamics.cd.nrp.internal.capabilities; + +import com.google.common.collect.Maps; +import com.griddynamics.cd.nrp.internal.ReplicationPluginConfigurationStorage; +import org.codehaus.jackson.map.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class GridCapabilityConfiguration { + + public static final String MASTER_SERVER_URL_PREFIX = "myUrl"; + public static final String REQUESTS_QUEUE_SIZE = "requestsQueueSize"; + public static final String REQUESTS_SENDING_THREADS_COUNT = "requestsSendingThreadsCount"; + public static final String QUEUE_DUMP_FILE_NAME = "queueDumpFileName"; + public static final String SERVERS = "servers"; + + Logger logger = + LoggerFactory.getLogger(GridCapabilityConfiguration.class); + + + private final String masterServerURLPrefix; + private final int requestQueueSize; + private final int requestSendingThreadCount; + private final String requestQueueDumpFileName; + private final Set nexusServers; + + public GridCapabilityConfiguration(final Map properties) { + this.masterServerURLPrefix = properties.get(MASTER_SERVER_URL_PREFIX); + this.requestQueueSize = Integer.parseInt(properties.get(REQUESTS_QUEUE_SIZE)); + this.requestSendingThreadCount = Integer.parseInt(properties.get(REQUESTS_SENDING_THREADS_COUNT)); + this.requestQueueDumpFileName = properties.get(QUEUE_DUMP_FILE_NAME); + this.nexusServers = new LinkedHashSet<>(); + try { + ObjectMapper objectMapper = new ObjectMapper(); + List servers = (List) objectMapper.readValue(properties.get(SERVERS), Map.class).get("servers"); + for (Map server : servers) { + this.nexusServers.add( + new ReplicationPluginConfigurationStorage.NexusServer( + (String) server.get("url"), + (String) server.get("user"), + (String) server.get("password") + ) + ); + } + + } catch (Exception e) { + logger.error(e.getMessage(),e); + } + } + + public Map asMap() { + final Map props = Maps.newHashMap(); + props.put(MASTER_SERVER_URL_PREFIX, masterServerURLPrefix); + props.put(REQUESTS_QUEUE_SIZE, String.valueOf(requestQueueSize)); + props.put(REQUESTS_SENDING_THREADS_COUNT, String.valueOf(requestSendingThreadCount)); + props.put(QUEUE_DUMP_FILE_NAME, requestQueueDumpFileName); + return props; + } + + public String getMasterServerURLPrefix() { + return masterServerURLPrefix; + } + + public int getRequestQueueSize() { + return requestQueueSize; + } + + public int getRequestSendingThreadCount() { + return requestSendingThreadCount; + } + + public String getRequestQueueDumpFileName() { + return requestQueueDumpFileName; + } + + public Set getNexusServers() { + return nexusServers; + } +} diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilityDescriptor.java b/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilityDescriptor.java new file mode 100644 index 0000000..da5f11e --- /dev/null +++ b/src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilityDescriptor.java @@ -0,0 +1,147 @@ +package com.griddynamics.cd.nrp.internal.capabilities; + +import com.google.common.collect.Lists; +import org.sonatype.nexus.capability.support.CapabilityDescriptorSupport; +import org.sonatype.nexus.formfields.FormField; +import org.sonatype.nexus.formfields.NumberTextFormField; +import org.sonatype.nexus.formfields.StringTextFormField; +import org.sonatype.nexus.formfields.TextAreaFormField; +import org.sonatype.nexus.plugins.capabilities.*; +import org.sonatype.nexus.plugins.capabilities.support.validator.Validators; +import org.sonatype.sisu.goodies.i18n.I18N; +import org.sonatype.sisu.goodies.i18n.MessageBundle; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; +import java.util.List; +import java.util.Set; + +import static org.sonatype.nexus.plugins.capabilities.CapabilityType.capabilityType; +import static org.sonatype.nexus.plugins.capabilities.Tag.categoryTag; +import static org.sonatype.nexus.plugins.capabilities.Tag.tags; + +@Singleton +@Named(GridCapabilityDescriptor.TYPE_ID) +public class GridCapabilityDescriptor + extends CapabilityDescriptorSupport + implements Taggable { + public static final String TYPE_ID = "nexus-replication-plugin"; + + public static final CapabilityType TYPE = capabilityType(TYPE_ID); + + private static interface Messages + extends MessageBundle { + @DefaultMessage("Nexus Replication Plugin Configuration") + String name(); + + @DefaultMessage("Master server's URL prefix") + String masterServerURLPrefixLabel(); + + @DefaultMessage("Master server's URL prefix (e.g. http://localhost:8081/nexus") + String masterServerURLPrefixHelp(); + + @DefaultMessage("Request queue size") + String requestQueueSizeLabel(); + + @DefaultMessage("Request queue size (default 500)") + String requestQueueSizeHelp(); + + @DefaultMessage("Request sending thread count") + String requestSendingThreadCountLabel(); + + @DefaultMessage("Request sending thread count (default 1)") + String requestSendingThreadCountHelp(); + + @DefaultMessage("Request queue dump file") + String requestQueueDumpFileNameLabel(); + + @DefaultMessage("Request queue dump file (default /tmp/nexus-replication-plugin-queue-backup)") + String requestQueueDumpFileNameHelp(); + + @DefaultMessage("Slave servers (in JSON)") + String serversLabel(); + + @DefaultMessage("Slave servers in JSON, like: {\"servers\":[{\"url\":\"http://localhost:8083/nexus\",\"user\":\"admin\",\"password\":\"admin123\"},{\"url\":\"http://localhost:8082/nexus\",\"user\":\"admin\",\"password\":\"admin123\"}]}") + String serversHelp(); + + } + + private static final Messages messages = I18N.create(Messages.class); + + private final Validators validators; + + private final List formFields; + + @Inject + public GridCapabilityDescriptor(final Validators validators) { + this.validators = validators; + + this.formFields = Lists.newArrayList( + new StringTextFormField( + GridCapabilityConfiguration.MASTER_SERVER_URL_PREFIX, + messages.masterServerURLPrefixLabel(), + messages.masterServerURLPrefixHelp(), + FormField.OPTIONAL + ).withInitialValue("http://localhost:8081/nexus"), + new NumberTextFormField( + GridCapabilityConfiguration.REQUESTS_QUEUE_SIZE, + messages.requestQueueSizeLabel(), + messages.requestQueueSizeHelp(), + FormField.OPTIONAL + ).withInitialValue(500), + new NumberTextFormField( + GridCapabilityConfiguration.REQUESTS_SENDING_THREADS_COUNT, + messages.requestSendingThreadCountLabel(), + messages.requestSendingThreadCountHelp(), + FormField.OPTIONAL + ).withInitialValue(1), + new StringTextFormField( + GridCapabilityConfiguration.QUEUE_DUMP_FILE_NAME, + messages.requestQueueDumpFileNameLabel(), + messages.requestQueueDumpFileNameHelp(), + FormField.OPTIONAL + ).withInitialValue("/tmp/nexus-replication-plugin-queue-backup"), + new TextAreaFormField( + GridCapabilityConfiguration.SERVERS, + messages.serversLabel(), + messages.serversHelp(), + FormField.OPTIONAL + ).withInitialValue("{\"servers\":[{\"url\":\"http://localhost:8083/nexus\",\"user\":\"admin\",\"password\":\"admin123\"},{\"url\":\"http://localhost:8082/nexus\",\"user\":\"admin\",\"password\":\"admin123\"}]}") + ); + } + + @Override + public Validator validator() { + return validators.logical().and( + validators.capability().uniquePer(TYPE) + ); + } + + @Override + public Validator validator(final CapabilityIdentity id) { + return validators.logical().and( + validators.capability().uniquePerExcluding(id, TYPE) + ); + } + + @Override + public CapabilityType type() { + return TYPE; + } + + @Override + public String name() { + return messages.name(); + } + + @Override + public List formFields() { + return formFields; + } + + @Override + public Set getTags() { + return tags(categoryTag("Grid")); + } +} diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/model/config/NexusServer.java b/src/main/java/com/griddynamics/cd/nrp/internal/model/config/NexusServer.java deleted file mode 100644 index a479160..0000000 --- a/src/main/java/com/griddynamics/cd/nrp/internal/model/config/NexusServer.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2015, Grid Dynamics International, Inc. - * - * 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.griddynamics.cd.nrp.internal.model.config; - -import lombok.*; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; - -/** - * DTO Class encapsulates replication nexus server api access configuration - */ -@NoArgsConstructor -@RequiredArgsConstructor -@XmlAccessorType(XmlAccessType.FIELD) -public class NexusServer { - @Getter - @NonNull - @XmlElement(name = "url") - private String url; - @Getter - @NonNull - @XmlElement(name = "user") - private String user; - @Getter - @NonNull - @XmlElement(name = "password") - private String password; -} diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/model/config/ReplicationPluginConfiguration.java b/src/main/java/com/griddynamics/cd/nrp/internal/model/config/ReplicationPluginConfiguration.java deleted file mode 100644 index 9251883..0000000 --- a/src/main/java/com/griddynamics/cd/nrp/internal/model/config/ReplicationPluginConfiguration.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2015, Grid Dynamics International, Inc. - * - * 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.griddynamics.cd.nrp.internal.model.config; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import java.util.LinkedHashSet; -import java.util.Set; - -/** - * DTO Class encapsulates replication plugin configurations - */ -@NoArgsConstructor -@RequiredArgsConstructor -@XmlRootElement(name = "configurations") -public class ReplicationPluginConfiguration { - @XmlElement(name = "server") - @XmlElementWrapper(name = "servers") - private final Set servers = new LinkedHashSet<>(); - @Getter - @NonNull - @XmlAttribute(name = "myUrl") - private String myUrl; - @Getter - @XmlAttribute(name = "requestsQueueSize") - private Integer requestsQueueSize = 500; - @XmlAttribute(name = "requestsSendingThreadsCount") - private Integer requestsSendingThreadsCount = 1; - @XmlAttribute(name = "queueDumpFileName") - @NonNull - private String queueDumpFileName; - - public void addServer(NexusServer server) { - servers.add(server); - } - - public String getQueueDumpFileName() { - return queueDumpFileName; - } - - public Integer getRequestsSendingThreadsCount() { - return requestsSendingThreadsCount; - } - - public Set getServers() { - return servers; - } -} diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/ArtifactUpdateApiClient.java b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/ArtifactUpdateApiClient.java index 5f6087a..b721b23 100644 --- a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/ArtifactUpdateApiClient.java +++ b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/ArtifactUpdateApiClient.java @@ -18,6 +18,8 @@ import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; public interface ArtifactUpdateApiClient { + void onActivate(); + void offerRequest(ArtifactMetaInfo artifactMetaInfo); } diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/ConfigurationsManager.java b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/ConfigurationsManager.java deleted file mode 100644 index 17f9c4a..0000000 --- a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/ConfigurationsManager.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2015, Grid Dynamics International, Inc. - * - * 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.griddynamics.cd.nrp.internal.uploading; - -import com.griddynamics.cd.nrp.internal.model.config.ReplicationPluginConfiguration; - -public interface ConfigurationsManager { - ReplicationPluginConfiguration getConfiguration(); -} diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImpl.java b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImpl.java index 9f54965..6ddb6d3 100644 --- a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImpl.java +++ b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImpl.java @@ -15,29 +15,22 @@ */ package com.griddynamics.cd.nrp.internal.uploading.impl; +import com.griddynamics.cd.nrp.internal.ReplicationPluginConfigurationStorage; import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; -import com.griddynamics.cd.nrp.internal.model.config.ReplicationPluginConfiguration; -import com.griddynamics.cd.nrp.internal.model.internal.ArtifactMetaInfoQueueDump; import com.griddynamics.cd.nrp.internal.model.api.RestResponse; -import com.griddynamics.cd.nrp.internal.model.config.NexusServer; +import com.griddynamics.cd.nrp.internal.model.internal.ArtifactMetaInfoQueueDump; import com.griddynamics.cd.nrp.internal.uploading.ArtifactUpdateApiClient; -import com.griddynamics.cd.nrp.internal.uploading.ConfigurationsManager; import com.griddynamics.cd.nrp.internal.uploading.impl.factories.AsyncWebResourceBuilderFactory; import com.griddynamics.cd.nrp.internal.uploading.impl.factories.FileBlockingQueueFactory; import com.sun.jersey.api.client.AsyncWebResource; -import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.async.ITypeListener; -import com.sun.jersey.api.client.config.ClientConfig; -import com.sun.jersey.api.client.config.DefaultClientConfig; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; import org.sonatype.sisu.goodies.common.ComponentSupport; +import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriBuilder; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; import java.io.File; @@ -64,30 +57,32 @@ public class ArtifactUpdateApiClientImpl extends ComponentSupport implements Art */ public static final int QUEUE_TIMEOUT_IN_SECOND = 1; - /** - * Provides access to the plugin configurations - */ - private final ConfigurationsManager configurationsManager; private final FileBlockingQueueFactory fileBlockingQueueFactory; private final AsyncWebResourceBuilderFactory asyncWebResourceBuilderFactory; + private final ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage; /** * ExecutorService shares between clients. All treads are created in the same executor */ - private final FileBlockingQueue fileBlockingQueue; + private FileBlockingQueue fileBlockingQueue; @Inject - public ArtifactUpdateApiClientImpl(ConfigurationsManager configurationsManager, - FileBlockingQueueFactory fileBlockingQueueFactory, - AsyncWebResourceBuilderFactory asyncWebResourceBuilderFactory) { - this.configurationsManager = configurationsManager; + public ArtifactUpdateApiClientImpl(FileBlockingQueueFactory fileBlockingQueueFactory, + AsyncWebResourceBuilderFactory asyncWebResourceBuilderFactory, + ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage) { this.fileBlockingQueueFactory = fileBlockingQueueFactory; this.asyncWebResourceBuilderFactory = asyncWebResourceBuilderFactory; - this.fileBlockingQueue = initFileBlockingQueue(configurationsManager.getConfiguration()); - initBackgroundWorkers(configurationsManager.getConfiguration()); + this.replicationPluginConfigurationStorage = replicationPluginConfigurationStorage; + } + + @Override + public void onActivate(){ + this.fileBlockingQueue = initFileBlockingQueue(replicationPluginConfigurationStorage); + initBackgroundWorkers(replicationPluginConfigurationStorage); } - private void initBackgroundWorkers(ReplicationPluginConfiguration replicationPluginConfiguration) { - int requestsSendingThreadsCount = replicationPluginConfiguration.getRequestsSendingThreadsCount(); + private void initBackgroundWorkers(ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage) { + int requestsSendingThreadsCount = replicationPluginConfigurationStorage + .getRequestSendingThreadCount(); ExecutorService executorService = Executors.newFixedThreadPool(requestsSendingThreadsCount); for (int i = 0; i < requestsSendingThreadsCount; i++) { executorService.submit(new Runnable() { @@ -107,8 +102,8 @@ public void run() { } } - private FileBlockingQueue initFileBlockingQueue(ReplicationPluginConfiguration replicationPluginConfiguration) { - String queueFileName = replicationPluginConfiguration.getQueueDumpFileName(); + private FileBlockingQueue initFileBlockingQueue(ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage) { + String queueFileName = replicationPluginConfigurationStorage.getRequestQueueDumpFileName(); FileBlockingQueue retVal = fileBlockingQueueFactory.getFileBlockingQueue(); try { File queueFile = new File(queueFileName); @@ -141,7 +136,7 @@ public void offerRequest(ArtifactMetaInfo artifactMetaInfo) { * @param metaInfo Artifact information */ public void sendRequest(ArtifactMetaInfo metaInfo) { - for (NexusServer server : configurationsManager.getConfiguration().getServers()) { + for (ReplicationPluginConfigurationStorage.NexusServer server : replicationPluginConfigurationStorage.getServers()) { AsyncWebResource.Builder service = asyncWebResourceBuilderFactory.getAsyncWebResourceBuilder( server.getUrl(), server.getUser(), server.getPassword()); diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ConfigurationsManagerImpl.java b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ConfigurationsManagerImpl.java deleted file mode 100644 index 4dc835b..0000000 --- a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ConfigurationsManagerImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2015, Grid Dynamics International, Inc. - * - * 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.griddynamics.cd.nrp.internal.uploading.impl; - -import com.griddynamics.cd.nrp.internal.model.config.ReplicationPluginConfiguration; -import com.griddynamics.cd.nrp.internal.uploading.ConfigurationsManager; -import org.sonatype.nexus.configuration.application.NexusConfiguration; -import org.sonatype.sisu.goodies.common.ComponentSupport; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import java.io.File; - -/** - * Class provides access to plugin configurations - * parsed from {@link ConfigurationsManagerImpl#CONFIG_FILENAME} file - */ -@Singleton -@Named(value = ConfigurationsManagerImpl.ID) -public class ConfigurationsManagerImpl extends ComponentSupport implements ConfigurationsManager { - - public static final String ID = "configurationsManager"; - - /** - * Filename of the XML configuration file - */ - private static final String CONFIG_FILENAME = "replication-plugin.xml"; - - /** - * Bean provides nexus server configurations - */ - private NexusConfiguration nexusConfiguration; - - /** - * DTO contains plugin configurations - */ - private volatile ReplicationPluginConfiguration config; - - @Inject - public ConfigurationsManagerImpl(NexusConfiguration nexusConfiguration) { - this.nexusConfiguration = nexusConfiguration; - } - - /** - * Loads configurations - * from {@link ConfigurationsManagerImpl#CONFIG_FILENAME} file - */ - @PostConstruct - public void init() { - log.trace("Initializing plugin configurations"); - reloadConfigurations(CONFIG_FILENAME); - } - - /** - * Provides access to plugin configurations DTO - * @return Plugin configurations - */ - @Override - public ReplicationPluginConfiguration getConfiguration() { - if (config == null) { - synchronized (this) { - if (config == null) { - reloadConfigurations(CONFIG_FILENAME); - } - } - } - return config; - } - - /** - * Reloads {@link ConfigurationsManagerImpl#config} - * from XML plugin configurations file - */ - public void reloadConfigurations(String filename) { - File file = getConfigurationFile(filename); - try { - JAXBContext jaxbContext = JAXBContext.newInstance(ReplicationPluginConfiguration.class); - - Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - config = (ReplicationPluginConfiguration) jaxbUnmarshaller.unmarshal(file); - } catch (JAXBException e) { - log.error("Can not deserialize xml configuration file: " + file.getAbsolutePath(), e); - } - } - - /** - * Returns plugin configurations XML file - */ - private File getConfigurationFile(String filename) { - return new File(nexusConfiguration.getConfigurationDirectory(), filename); - } -} diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/UploadEventListenerImpl.java b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/UploadEventListenerImpl.java index 8bad9be..61cb1c1 100644 --- a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/UploadEventListenerImpl.java +++ b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/UploadEventListenerImpl.java @@ -17,10 +17,10 @@ import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; +import com.griddynamics.cd.nrp.internal.ReplicationPluginConfigurationStorage; import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; import com.griddynamics.cd.nrp.internal.model.api.ArtifactStatus; import com.griddynamics.cd.nrp.internal.uploading.ArtifactUpdateApiClient; -import com.griddynamics.cd.nrp.internal.uploading.ConfigurationsManager; import com.griddynamics.cd.nrp.internal.uploading.UploadEventListener; import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenProxyRepository; import org.sonatype.nexus.proxy.events.RepositoryItemEventStore; @@ -46,17 +46,16 @@ public class UploadEventListenerImpl extends ComponentSupport implements UploadE /** * Provides access to plugin the configurations */ - private ConfigurationsManager configurationsManager; - - private ArtifactUpdateApiClient artifactUpdateApiClient; + private final ArtifactUpdateApiClient artifactUpdateApiClient; + private final ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage; private Map receivedArtifacts = new ConcurrentHashMap<>(); @Inject - public UploadEventListenerImpl(@Named(value = ConfigurationsManagerImpl.ID) ConfigurationsManager configurationsManager, - @Named(value = ArtifactUpdateApiClientImpl.ID) ArtifactUpdateApiClient artifactUpdateApiClient) { - this.configurationsManager = configurationsManager; + public UploadEventListenerImpl(@Named(value = ArtifactUpdateApiClientImpl.ID) ArtifactUpdateApiClient artifactUpdateApiClient, + ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage) { this.artifactUpdateApiClient = artifactUpdateApiClient; + this.replicationPluginConfigurationStorage = replicationPluginConfigurationStorage; } /** @@ -70,7 +69,12 @@ public void onArtifactUploading(RepositoryItemEventStore event) { MavenRepository repo = (MavenRepository) event.getRepository(); Gav gav = repo.getGavCalculator().pathToGav(event.getItemUid().getPath()); if (null != gav) { - ArtifactMetaInfo metaInfo = new ArtifactMetaInfo(configurationsManager.getConfiguration().getMyUrl(), gav.getGroupId(), gav.getArtifactId(), gav.getVersion(), repo.getId()); + ArtifactMetaInfo metaInfo = new ArtifactMetaInfo( + replicationPluginConfigurationStorage.getMasterServerURLPrefix(), + gav.getGroupId(), + gav.getArtifactId(), + gav.getVersion(), + repo.getId()); metaInfo.setClassifier(gav.getClassifier()); metaInfo.setExtension(gav.getExtension()); ArtifactStatus artifactStatus = null; diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/factories/FileBlockingQueueFactory.java b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/factories/FileBlockingQueueFactory.java index c76343a..ecdf89a 100644 --- a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/factories/FileBlockingQueueFactory.java +++ b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/factories/FileBlockingQueueFactory.java @@ -1,7 +1,7 @@ package com.griddynamics.cd.nrp.internal.uploading.impl.factories; +import com.griddynamics.cd.nrp.internal.ReplicationPluginConfigurationStorage; import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; -import com.griddynamics.cd.nrp.internal.uploading.ConfigurationsManager; import com.griddynamics.cd.nrp.internal.uploading.impl.FileBlockingQueue; import javax.inject.Inject; @@ -12,18 +12,20 @@ @Singleton public class FileBlockingQueueFactory { - private final ConfigurationsManager configurationsManager; + private final ReplicationPluginConfigurationStorage + replicationPluginConfigurationStorage; @Inject - public FileBlockingQueueFactory(ConfigurationsManager configurationsManager) { - this.configurationsManager = configurationsManager; + public FileBlockingQueueFactory(ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage) { + this.replicationPluginConfigurationStorage = replicationPluginConfigurationStorage; } public FileBlockingQueue getFileBlockingQueue() { BlockingQueue blockingQueue = - new LinkedBlockingQueue<>(configurationsManager. - getConfiguration().getRequestsQueueSize()); - String blockingQueueDumpFileName = configurationsManager.getConfiguration().getQueueDumpFileName(); + new LinkedBlockingQueue<>( + replicationPluginConfigurationStorage.getRequestQueueSize()); + String blockingQueueDumpFileName = + replicationPluginConfigurationStorage.getRequestQueueDumpFileName(); return new FileBlockingQueue(blockingQueue, blockingQueueDumpFileName); diff --git a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/factories/JerseyClientFactory.java b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/factories/JerseyClientFactory.java index df6b7c7..bd28a00 100644 --- a/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/factories/JerseyClientFactory.java +++ b/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/factories/JerseyClientFactory.java @@ -1,6 +1,6 @@ package com.griddynamics.cd.nrp.internal.uploading.impl.factories; -import com.griddynamics.cd.nrp.internal.uploading.ConfigurationsManager; +import com.griddynamics.cd.nrp.internal.ReplicationPluginConfigurationStorage; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; @@ -8,6 +8,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Singleton; import java.util.concurrent.ExecutorService; @@ -20,17 +21,27 @@ public class JerseyClientFactory { private Logger log = LoggerFactory.getLogger(JerseyClientFactory.class); - private final ExecutorService executorService; + private ExecutorService executorService; + private final ReplicationPluginConfigurationStorage + replicationPluginConfigurationStorage; @Inject - public JerseyClientFactory(ConfigurationsManager configurationsManager) { + public JerseyClientFactory( + ReplicationPluginConfigurationStorage + replicationPluginConfigurationStorage ) { + this.replicationPluginConfigurationStorage = replicationPluginConfigurationStorage; + + } + + public void onActivate(){ + int requestQueueSize = replicationPluginConfigurationStorage.getRequestQueueSize(); this.executorService = new ThreadPoolExecutor( - configurationsManager.getConfiguration().getRequestsSendingThreadsCount(), - configurationsManager.getConfiguration().getRequestsSendingThreadsCount(), + replicationPluginConfigurationStorage.getRequestSendingThreadCount(), + replicationPluginConfigurationStorage.getRequestSendingThreadCount(), 30, TimeUnit.SECONDS, new LinkedBlockingQueue( - configurationsManager.getConfiguration().getRequestsQueueSize())); + requestQueueSize)); } public Client getClient(String login, String password) { diff --git a/src/test/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImplTest.java b/src/test/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImplTest.java index 8e75af1..e991abc 100644 --- a/src/test/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImplTest.java +++ b/src/test/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImplTest.java @@ -1,11 +1,8 @@ package com.griddynamics.cd.nrp.internal.uploading.impl; +import com.griddynamics.cd.nrp.internal.ReplicationPluginConfigurationStorage; import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; -import com.griddynamics.cd.nrp.internal.model.config.NexusServer; -import com.griddynamics.cd.nrp.internal.model.config.ReplicationPluginConfiguration; -import com.griddynamics.cd.nrp.internal.uploading.ArtifactUpdateApiClient; -import com.griddynamics.cd.nrp.internal.uploading.ConfigurationsManager; import com.griddynamics.cd.nrp.internal.uploading.impl.factories.AsyncWebResourceBuilderFactory; import com.griddynamics.cd.nrp.internal.uploading.impl.factories.FileBlockingQueueFactory; import com.sun.jersey.api.client.AsyncWebResource; @@ -18,7 +15,9 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.LinkedBlockingQueue; import static org.junit.Assert.assertEquals; @@ -30,37 +29,41 @@ public class ArtifactUpdateApiClientImplTest { private AwaitableFIleBlockingQueue awaitableFIleBlockingQueue; @Mock - private ConfigurationsManager configurationsManagerMock; - @Mock private FileBlockingQueueFactory fileBlockingQueueFactory; @Mock private AsyncWebResourceBuilderFactory asyncWebResourceBuilderFactoryMock; @Mock AsyncWebResource.Builder asyncWebResourceBuilderMock; - private ArtifactUpdateApiClient underTest; + private ArtifactUpdateApiClientImpl underTest; @Before public void setUp() { - NexusServer nexusServer = new NexusServer("http://mock:8082","admin","admin123"); - NexusServer nexusServer2 = new NexusServer("http://mock:8083", "admin2", "admin456"); + ReplicationPluginConfigurationStorage.NexusServer nexusServer = new ReplicationPluginConfigurationStorage.NexusServer("http://mock:8082","admin","admin123"); + ReplicationPluginConfigurationStorage.NexusServer nexusServer2 = new ReplicationPluginConfigurationStorage.NexusServer("http://mock:8083", "admin2", "admin456"); awaitableFIleBlockingQueue = new AwaitableFIleBlockingQueue( new LinkedBlockingQueue(), "/tmp/queueDumpForTests", 2 ); - ReplicationPluginConfiguration replicationPluginConfiguration = - new ReplicationPluginConfiguration("http://mock:8081","/tmp/queueDumpForTests"); - replicationPluginConfiguration.addServer(nexusServer); - replicationPluginConfiguration.addServer(nexusServer2); - when(configurationsManagerMock.getConfiguration()).thenReturn(replicationPluginConfiguration); + ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage + = new ReplicationPluginConfigurationStorage(); + replicationPluginConfigurationStorage.setMasterServerURLPrefix("http://mock:8081"); + replicationPluginConfigurationStorage.setRequestQueueDumpFileName("/tmp/queueDumpForTests"); + Set servers = + new LinkedHashSet<>(); + servers.add(nexusServer); + servers.add(nexusServer2); + replicationPluginConfigurationStorage.setServers(servers); + replicationPluginConfigurationStorage.setRequestSendingThreadCount(1); when(fileBlockingQueueFactory.getFileBlockingQueue()).thenReturn(awaitableFIleBlockingQueue); when(asyncWebResourceBuilderFactoryMock.getAsyncWebResourceBuilder( anyString(), anyString(), anyString())). thenReturn(asyncWebResourceBuilderMock); underTest = new ArtifactUpdateApiClientImpl( - configurationsManagerMock, fileBlockingQueueFactory, - asyncWebResourceBuilderFactoryMock); + asyncWebResourceBuilderFactoryMock, + replicationPluginConfigurationStorage); + underTest.onActivate(); } @After diff --git a/src/test/java/com/griddynamics/cd/nrp/internal/uploading/impl/ConfigurationsManagerImplTest.java b/src/test/java/com/griddynamics/cd/nrp/internal/uploading/impl/ConfigurationsManagerImplTest.java deleted file mode 100644 index 276348c..0000000 --- a/src/test/java/com/griddynamics/cd/nrp/internal/uploading/impl/ConfigurationsManagerImplTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.griddynamics.cd.nrp.internal.uploading.impl; - -import com.griddynamics.cd.nrp.internal.model.config.NexusServer; -import com.griddynamics.cd.nrp.internal.model.config.ReplicationPluginConfiguration; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; -import org.sonatype.nexus.configuration.application.NexusConfiguration; - -import java.io.File; -import java.net.URL; -import java.util.Iterator; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class ConfigurationsManagerImplTest { - - private final String FIRST_CONFIGURATION_FILE = "replication-plugin.xml"; - private final String SECOND_CONFIGURATION_FILE = "replication-plugin-2.xml"; - - @Test - public void testGetConfiguration() throws Exception { - NexusConfiguration nexusConfiguration = mock(NexusConfiguration.class); - URL configFile = getClass().getClassLoader().getResource(FIRST_CONFIGURATION_FILE); - when(nexusConfiguration.getConfigurationDirectory()).thenReturn(new File(configFile.getFile()).getParentFile()); - ConfigurationsManagerImpl configurationsManager = spy(new ConfigurationsManagerImpl(nexusConfiguration)); - - ReplicationPluginConfiguration configuration = configurationsManager.getConfiguration(); - Assert.assertEquals("My url was written incorrectly", "http://localhost:8081/nexus", configuration.getMyUrl()); - Assert.assertEquals("Incorrect count of servers", 1, configuration.getServers().size()); - Iterator iterator = configuration.getServers().iterator(); - if (iterator.hasNext()) { - NexusServer nexusServer = iterator.next(); - Assert.assertEquals("Server url was written incorrectly", "http://localhost:8083/nexus", nexusServer.getUrl()); - Assert.assertEquals("User was written incorrectly", "admin", nexusServer.getUser()); - Assert.assertEquals("Password was written incorrectly", "admin123", nexusServer.getPassword()); - } - } - - @Test - public void testReloadConfigurations() throws Exception { - NexusConfiguration nexusConfiguration = mock(NexusConfiguration.class); - URL configFile = getClass().getClassLoader().getResource(FIRST_CONFIGURATION_FILE); - when(nexusConfiguration.getConfigurationDirectory()).thenReturn(new File(configFile.getFile()).getParentFile()); - ConfigurationsManagerImpl configurationsManager = spy(new ConfigurationsManagerImpl(nexusConfiguration)); - - ReplicationPluginConfiguration configuration = configurationsManager.getConfiguration(); - Assert.assertEquals("First file should contain one nexus server only", 1, configuration.getServers().size()); - - configurationsManager.reloadConfigurations(SECOND_CONFIGURATION_FILE); - configuration = configurationsManager.getConfiguration(); - Assert.assertEquals("Second file should contain two nexus servers", 2, configuration.getServers().size()); - } -} \ No newline at end of file