-
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 dfed1fa
Showing
20 changed files
with
599 additions
and
416 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
30 changes: 30 additions & 0 deletions
30
...va/com/griddynamics/cd/nrp/internal/capabilities/ReplicationPluginCapabilitiesBooter.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,30 @@ | ||
package com.griddynamics.cd.nrp.internal.capabilities; | ||
|
||
import javax.inject.Named; | ||
|
||
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 ReplicationPluginCapabilitiesBooter | ||
extends CapabilityBooterSupport | ||
{ | ||
|
||
@Override | ||
protected void boot(final CapabilityRegistry registry) | ||
throws Exception | ||
{ | ||
maybeAddCapability( | ||
registry, | ||
ReplicationPluginCapabilityDescriptor.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/ReplicationPluginCapability.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.model.config.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(ReplicationPluginCapabilityDescriptor.TYPE_ID) | ||
public class ReplicationPluginCapability | ||
extends CapabilitySupport<ReplicationPluginCapabilityConfiguration> { | ||
@NonNls | ||
public static final String NL = System.getProperty("line.separator"); | ||
|
||
private final ReplicationPluginConfigurationStorage gridRegistry; | ||
private final ArtifactUpdateApiClient artifactUpdateApiClient; | ||
private final JerseyClientFactory jerseyClientFactory; | ||
|
||
@Inject | ||
public ReplicationPluginCapability(final ReplicationPluginConfigurationStorage replicationPluginConfigurationStorage, | ||
final ArtifactUpdateApiClient artifactUpdateApiClient, | ||
final JerseyClientFactory jerseyClientFactory) { | ||
this.gridRegistry = checkNotNull(replicationPluginConfigurationStorage); | ||
this.artifactUpdateApiClient = artifactUpdateApiClient; | ||
this.jerseyClientFactory = jerseyClientFactory; | ||
} | ||
|
||
@Override | ||
protected ReplicationPluginCapabilityConfiguration createConfig(final Map<String, String> properties) throws Exception { | ||
Map<String, String> newProperties = new HashMap<>(properties); | ||
return new ReplicationPluginCapabilityConfiguration(newProperties); | ||
} | ||
|
||
@Override | ||
public void configure(final ReplicationPluginCapabilityConfiguration 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
...m/griddynamics/cd/nrp/internal/capabilities/ReplicationPluginCapabilityConfiguration.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.model.config.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 ReplicationPluginCapabilityConfiguration { | ||
|
||
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(ReplicationPluginCapabilityConfiguration.class); | ||
|
||
|
||
private final String masterServerURLPrefix; | ||
private final int requestQueueSize; | ||
private final int requestSendingThreadCount; | ||
private final String requestQueueDumpFileName; | ||
private final Set<ReplicationPluginConfigurationStorage.NexusServer> nexusServers; | ||
|
||
public ReplicationPluginCapabilityConfiguration(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; | ||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
.../com/griddynamics/cd/nrp/internal/capabilities/ReplicationPluginCapabilityDescriptor.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,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(ReplicationPluginCapabilityDescriptor.TYPE_ID) | ||
public class ReplicationPluginCapabilityDescriptor | ||
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<FormField> formFields; | ||
|
||
@Inject | ||
public ReplicationPluginCapabilityDescriptor(final Validators validators) { | ||
this.validators = validators; | ||
|
||
this.formFields = Lists.<FormField>newArrayList( | ||
new StringTextFormField( | ||
ReplicationPluginCapabilityConfiguration.MASTER_SERVER_URL_PREFIX, | ||
messages.masterServerURLPrefixLabel(), | ||
messages.masterServerURLPrefixHelp(), | ||
FormField.OPTIONAL | ||
).withInitialValue("http://localhost:8081/nexus"), | ||
new NumberTextFormField( | ||
ReplicationPluginCapabilityConfiguration.REQUESTS_QUEUE_SIZE, | ||
messages.requestQueueSizeLabel(), | ||
messages.requestQueueSizeHelp(), | ||
FormField.OPTIONAL | ||
).withInitialValue(500), | ||
new NumberTextFormField( | ||
ReplicationPluginCapabilityConfiguration.REQUESTS_SENDING_THREADS_COUNT, | ||
messages.requestSendingThreadCountLabel(), | ||
messages.requestSendingThreadCountHelp(), | ||
FormField.OPTIONAL | ||
).withInitialValue(1), | ||
new StringTextFormField( | ||
ReplicationPluginCapabilityConfiguration.QUEUE_DUMP_FILE_NAME, | ||
messages.requestQueueDumpFileNameLabel(), | ||
messages.requestQueueDumpFileNameHelp(), | ||
FormField.OPTIONAL | ||
).withInitialValue("/tmp/nexus-replication-plugin-queue-backup"), | ||
new TextAreaFormField( | ||
ReplicationPluginCapabilityConfiguration.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<FormField> formFields() { | ||
return formFields; | ||
} | ||
|
||
@Override | ||
public Set<Tag> getTags() { | ||
return tags(categoryTag("Grid")); | ||
} | ||
} |
Oops, something went wrong.