-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3358960
commit 4110ff6
Showing
18 changed files
with
575 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/main/java/com/griddynamics/cd/nrp/internal/ReplicationPluginConfigurationStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> masterServerURLPrefix = new AtomicReference<>(); | ||
private final AtomicReference<Integer> requestQueueSize = new AtomicReference<>(); | ||
private final AtomicReference<Integer> requestSendingThreadCount = new AtomicReference<>(); | ||
private final AtomicReference<String> requestQueueDumpFileName = new AtomicReference<>();; | ||
private final AtomicReference<Set<NexusServer>> servers = new AtomicReference<>(); | ||
|
||
@Inject | ||
public ReplicationPluginConfigurationStorage() { | ||
servers.set(new LinkedHashSet<NexusServer>()); | ||
} | ||
|
||
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<NexusServer> getServers() { | ||
Set<NexusServer> retVal = servers.get(); | ||
if(retVal == null){ | ||
throw new RuntimeException("Replication plugin configuration not ready yet!"); | ||
} | ||
return retVal; | ||
} | ||
|
||
public void setServers(Set<NexusServer> 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; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilitiesBooter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.<String,String>emptyMap()); | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapability.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<GridCapabilityConfiguration> { | ||
@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<String, String> properties) throws Exception { | ||
Map<String, String> 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"; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/com/griddynamics/cd/nrp/internal/capabilities/GridCapabilityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ReplicationPluginConfigurationStorage.NexusServer> nexusServers; | ||
|
||
public GridCapabilityConfiguration(final Map<String, String> 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<Map> servers = (List<Map>) 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<String, String> asMap() { | ||
final Map<String, String> 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<ReplicationPluginConfigurationStorage.NexusServer> getNexusServers() { | ||
return nexusServers; | ||
} | ||
} |
Oops, something went wrong.