├── .gitignore ├── documentation ├── plugin_architecture.png ├── user_doc.md └── contributor_doc.md ├── license-header.txt ├── src └── main │ └── java │ └── com │ └── griddynamics │ └── cd │ └── nrp │ ├── internal │ ├── uploading │ │ ├── UploadEventListener.java │ │ ├── ArtifactUpdateApiClient.java │ │ ├── ConfigurationsManager.java │ │ └── impl │ │ │ ├── FileBlockingQueue.java │ │ │ ├── ConfigurationsManagerImpl.java │ │ │ ├── UploadEventListenerImpl.java │ │ │ └── ArtifactUpdateApiClientImpl.java │ ├── model │ │ ├── config │ │ │ ├── NexusServer.java │ │ │ └── ReplicationPluginConfiguration.java │ │ ├── api │ │ │ ├── RestResponse.java │ │ │ ├── ArtifactStatus.java │ │ │ └── ArtifactMetaInfo.java │ │ └── internal │ │ │ └── ArtifactMetaInfoQueueDump.java │ └── rest │ │ └── ArtifactUpdatePlexusResource.java │ └── plugin │ └── ReplicationPlugin.java ├── replication-plugin.xml ├── README.md ├── pom.xml └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | target/ 3 | *.iml 4 | -------------------------------------------------------------------------------- /documentation/plugin_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/griddynamics/nexus-replication-plugin/HEAD/documentation/plugin_architecture.png -------------------------------------------------------------------------------- /license-header.txt: -------------------------------------------------------------------------------- 1 | Copyright 2015, Grid Dynamics International, Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/uploading/UploadEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.uploading; 17 | 18 | import org.sonatype.nexus.proxy.events.RepositoryItemEventStore; 19 | 20 | public interface UploadEventListener { 21 | void onArtifactUploading(RepositoryItemEventStore event); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/uploading/ArtifactUpdateApiClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.uploading; 17 | 18 | import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; 19 | 20 | public interface ArtifactUpdateApiClient { 21 | void offerRequest(ArtifactMetaInfo artifactMetaInfo); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/uploading/ConfigurationsManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.uploading; 17 | 18 | import com.griddynamics.cd.nrp.internal.model.config.ReplicationPluginConfiguration; 19 | 20 | public interface ConfigurationsManager { 21 | ReplicationPluginConfiguration getConfiguration(); 22 | } 23 | -------------------------------------------------------------------------------- /replication-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | 23 | 24 | http://localhost:8083/nexus 25 | admin 26 | admin123 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/model/config/NexusServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.model.config; 17 | 18 | import lombok.*; 19 | 20 | import javax.xml.bind.annotation.XmlAccessType; 21 | import javax.xml.bind.annotation.XmlAccessorType; 22 | import javax.xml.bind.annotation.XmlElement; 23 | 24 | /** 25 | * DTO Class encapsulates replication nexus server api access configuration 26 | */ 27 | @NoArgsConstructor 28 | @RequiredArgsConstructor 29 | @XmlAccessorType(XmlAccessType.FIELD) 30 | public class NexusServer { 31 | @Getter 32 | @NonNull 33 | @XmlElement(name = "url") 34 | private String url; 35 | @Getter 36 | @NonNull 37 | @XmlElement(name = "user") 38 | private String user; 39 | @Getter 40 | @NonNull 41 | @XmlElement(name = "password") 42 | private String password; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/model/api/RestResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.model.api; 17 | 18 | import com.thoughtworks.xstream.annotations.XStreamAlias; 19 | import lombok.Data; 20 | import lombok.NoArgsConstructor; 21 | import lombok.NonNull; 22 | import lombok.RequiredArgsConstructor; 23 | 24 | import javax.xml.bind.annotation.XmlAccessType; 25 | import javax.xml.bind.annotation.XmlAccessorType; 26 | import javax.xml.bind.annotation.XmlRootElement; 27 | import java.io.Serializable; 28 | 29 | /** 30 | * DTO Class encapsulates response data sent from replication nexus servers back 31 | */ 32 | @Data 33 | @NoArgsConstructor 34 | @RequiredArgsConstructor 35 | @XmlAccessorType(XmlAccessType.FIELD) 36 | @XmlRootElement(name = RestResponse.NAME) 37 | @XStreamAlias(value = RestResponse.NAME) 38 | public class RestResponse implements Serializable { 39 | public static final String NAME = "rest-status"; 40 | 41 | @NonNull 42 | private boolean isSuccess; 43 | @NonNull 44 | private String message; 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/model/internal/ArtifactMetaInfoQueueDump.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.model.internal; 17 | 18 | import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; 19 | 20 | import javax.xml.bind.annotation.XmlElement; 21 | import javax.xml.bind.annotation.XmlElementWrapper; 22 | import javax.xml.bind.annotation.XmlRootElement; 23 | import java.util.HashSet; 24 | import java.util.Set; 25 | 26 | /** 27 | * DTO Class encapsulates artifact replication queue 28 | */ 29 | @XmlRootElement(name = "artifactMetaInfoBlockingQueueDump") 30 | public class ArtifactMetaInfoQueueDump { 31 | @XmlElement(name = "artifactMetaInfo") 32 | @XmlElementWrapper(name = "artifactMetaInfos") 33 | private final Set artifactMetaInfos = new HashSet<>(); 34 | 35 | public void addArtifactMetaInfo(ArtifactMetaInfo artifactMetaInfo) { 36 | artifactMetaInfos.add(artifactMetaInfo); 37 | } 38 | public void addAllArtifactMetaInfo(Set artifactMetaInfo) { 39 | artifactMetaInfos.addAll(artifactMetaInfo); 40 | } 41 | 42 | public Set getArtifactMetaInfos() { 43 | return artifactMetaInfos; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/model/api/ArtifactStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.model.api; 17 | 18 | import lombok.Data; 19 | import lombok.EqualsAndHashCode; 20 | 21 | import java.io.Serializable; 22 | 23 | @Data 24 | @EqualsAndHashCode(exclude = {"isSha1Received", "isFileReceived"}) 25 | public class ArtifactStatus implements Serializable { 26 | private final String groupId; 27 | private final String artifactId; 28 | private final String version; 29 | private final String classifier; 30 | private final String extension; 31 | private final String repositoryId; 32 | private final String nexusUrl; 33 | private boolean isSha1Received; 34 | private boolean isFileReceived; 35 | 36 | public ArtifactStatus(ArtifactMetaInfo artifactMetaInfo) { 37 | this.groupId = artifactMetaInfo.getGroupId(); 38 | this.artifactId = artifactMetaInfo.getArtifactId(); 39 | this.version = artifactMetaInfo.getVersion(); 40 | this.classifier = artifactMetaInfo.getClassifier(); 41 | this.extension = artifactMetaInfo.getExtension(); 42 | this.repositoryId = artifactMetaInfo.getRepositoryId(); 43 | this.nexusUrl = artifactMetaInfo.getNexusUrl(); 44 | } 45 | 46 | public boolean isReadyForReplication() { 47 | return isFileReceived && isSha1Received; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/plugin/ReplicationPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.plugin; 17 | 18 | import com.google.common.base.Preconditions; 19 | import com.griddynamics.cd.nrp.internal.uploading.UploadEventListener; 20 | import com.griddynamics.cd.nrp.internal.uploading.impl.UploadEventListenerImpl; 21 | import org.eclipse.sisu.EagerSingleton; 22 | import org.jetbrains.annotations.NonNls; 23 | import org.sonatype.nexus.plugin.PluginIdentity; 24 | import org.sonatype.sisu.goodies.eventbus.EventBus; 25 | 26 | import javax.inject.Inject; 27 | import javax.inject.Named; 28 | 29 | @Named 30 | @EagerSingleton 31 | public class ReplicationPlugin extends PluginIdentity { 32 | 33 | /** 34 | * Prefix for ID-like things. 35 | */ 36 | @NonNls 37 | public static final String ID_PREFIX = "replication"; 38 | 39 | /** 40 | * Expected groupId for plugin artifact. 41 | */ 42 | @NonNls 43 | public static final String GROUP_ID = "com.griddynamics.cd"; 44 | 45 | /** 46 | * Expected artifactId for plugin artifact. 47 | */ 48 | @NonNls 49 | public static final String ARTIFACT_ID = "nexus-" + ID_PREFIX + "-plugin"; 50 | 51 | /** 52 | * Initializes plugin and registers deploy event handler 53 | * @param eventBus Global nexus event bus 54 | * @param uploadEventListener Deploy event handler 55 | */ 56 | @Inject 57 | public ReplicationPlugin(EventBus eventBus, @Named(UploadEventListenerImpl.ID) UploadEventListener uploadEventListener) throws Exception { 58 | super(GROUP_ID, ARTIFACT_ID); 59 | eventBus.register(Preconditions.checkNotNull(uploadEventListener)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/model/config/ReplicationPluginConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.model.config; 17 | 18 | import lombok.Getter; 19 | import lombok.NoArgsConstructor; 20 | import lombok.NonNull; 21 | import lombok.RequiredArgsConstructor; 22 | 23 | import javax.xml.bind.annotation.XmlAttribute; 24 | import javax.xml.bind.annotation.XmlElement; 25 | import javax.xml.bind.annotation.XmlElementWrapper; 26 | import javax.xml.bind.annotation.XmlRootElement; 27 | import java.util.HashSet; 28 | import java.util.Set; 29 | 30 | /** 31 | * DTO Class encapsulates replication plugin configurations 32 | */ 33 | @NoArgsConstructor 34 | @RequiredArgsConstructor 35 | @XmlRootElement(name = "configurations") 36 | public class ReplicationPluginConfiguration { 37 | @XmlElement(name = "server") 38 | @XmlElementWrapper(name = "servers") 39 | private final Set servers = new HashSet<>(); 40 | @Getter 41 | @NonNull 42 | @XmlAttribute(name = "myUrl") 43 | private String myUrl; 44 | @XmlAttribute(name = "requestsQueueSize") 45 | private Integer requestsQueueSize = 500; 46 | @XmlAttribute(name = "requestsSendingThreadsCount") 47 | private Integer requestsSendingThreadsCount = 1; 48 | @XmlAttribute(name = "queueDumpFileName") 49 | private String queueDumpFileName; 50 | 51 | public void addServer(NexusServer server) { 52 | servers.add(server); 53 | } 54 | 55 | public Integer getRequestsQueueSize() { 56 | return requestsQueueSize; 57 | } 58 | 59 | public String getQueueDumpFileName() { 60 | return queueDumpFileName; 61 | } 62 | 63 | public Integer getRequestsSendingThreadsCount() { 64 | return requestsSendingThreadsCount; 65 | } 66 | 67 | public Set getServers() { 68 | return servers; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/model/api/ArtifactMetaInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.model.api; 17 | 18 | import com.thoughtworks.xstream.annotations.XStreamAlias; 19 | import lombok.*; 20 | 21 | import javax.xml.bind.annotation.XmlAccessType; 22 | import javax.xml.bind.annotation.XmlAccessorType; 23 | import javax.xml.bind.annotation.XmlRootElement; 24 | import java.io.Serializable; 25 | 26 | /** 27 | * DTO Class encapsulates data sent to replication nexus servers 28 | */ 29 | @ToString 30 | @EqualsAndHashCode 31 | @XmlAccessorType(XmlAccessType.FIELD) 32 | @XmlRootElement(name = ArtifactMetaInfo.NAME) 33 | @XStreamAlias(value = ArtifactMetaInfo.NAME) 34 | public class ArtifactMetaInfo implements Serializable { 35 | public static final String NAME = "artifact-meta-info"; 36 | 37 | @Getter 38 | @NonNull 39 | private final String groupId; 40 | @Getter 41 | @NonNull 42 | private final String artifactId; 43 | @Getter 44 | @NonNull 45 | private final String version; 46 | @Getter 47 | @Setter 48 | private String packaging; 49 | @Getter 50 | @Setter 51 | private String classifier; 52 | @Getter 53 | @NonNull 54 | private final String repositoryId; 55 | @Getter 56 | @Setter 57 | private String extension; 58 | @Getter 59 | @NonNull 60 | private final String nexusUrl; 61 | 62 | public ArtifactMetaInfo() { 63 | this(null, null, null, null, null); 64 | } 65 | 66 | public ArtifactMetaInfo(String nexusUrl, String groupId, String artifactId, String version, String repositoryId) { 67 | this.nexusUrl = nexusUrl; 68 | this.groupId = groupId; 69 | this.artifactId = artifactId; 70 | this.version = version; 71 | this.repositoryId = repositoryId; 72 | } 73 | 74 | public boolean isValid() { 75 | return nexusUrl != null && groupId != null && artifactId != null && version != null && repositoryId != null; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /documentation/user_doc.md: -------------------------------------------------------------------------------- 1 | # Sonatype Nexus Replication Plugin 2 | 3 | [https://github.com/griddynamics/nexus-replication-plugin](https://github.com/griddynamics/nexus-replication-plugin) 4 | 5 | This is Sonatype Nexus plugin that facilitates push-replication to remote proxy repositories when new (Maven) artifacts are stored in a hosted repository. 6 | Let's say you have 2 or more instances of Nexus. When artifact is uploaded to one of them, that Nexus will send notifications to its peers. Then the Receving Nexuses poll the artifact from the original instance. 7 | 8 | ## Setting up plugin 9 | 10 | Plugin should be installed into all Master and Peer Nexus servers. 11 | You may have multiple Nexus instances configured as Masters. They will poll artifacts from each other. 12 | 13 | ### Master instance 14 | 15 | 1. Download source from [https://github.com/griddynamics/nexus-replication-plugin](https://github.com/griddynamics/nexus-replication-plugin). 16 | 2. Run `mvn package` in root directory (project requires Apache Maven 3.0.4 -- 3.0.5 and JDK 1.7+). 17 | 3. Unzip the `target/nexus-replication-plugin-1.0-SNAPSHOT-bundle.zip` file into the plugin-repository directory (located in `$NEXUS_HOME/sonatype-work/nexus/plugin-repository`). 18 | 4. Download a sample of the configuration file from [https://github.com/griddynamics/nexus-replication-plugin/blob/master/replication-plugin.xml](https://github.com/griddynamics/nexus-replication-plugin/blob/master/replication-plugin.xml). 19 | 5. Copy the `replication-plugin.xml` file into the conf directory (located in `$NEXUS_HOME/sonatype-work/nexus/conf`). 20 | 6. Edit the config file to suit your needs (read instructions inside the file). 21 | 7. Restart Nexus. 22 | 23 | ### Peer instance 24 | 25 | You also should configure each Nexus peer instance otherwise they won't poll the uploaded artifact. 26 | 27 | 1. Reproduce points 1 - 3 from the previous list. 28 | 2. Create proxy repository for the each hosted repository (repositories that should be replicated and located in the master Nexus). 29 | 4. Restart Nexus. 30 | 31 | ## Plugin REST API 32 | 33 | Plugin REST API is available at `service/local/artifact/maven/update`. This resource receives POST request with a body like this: 34 | 35 | ```xml 36 | 37 | 38 | com.griddynamics.cd 39 | nexus-replication-plugin 40 | 1.0-20150519.140619-2 41 | snapshots 42 | jar 43 | http://localhost:8081/nexus 44 | 45 | ``` 46 | 47 | This method returns XML formatted response. If artifact was resolved successfully response will be: 48 | 49 | ```xml 50 | 51 | true 52 | Artifact is resolved. 53 | 54 | ``` 55 | 56 | otherwise `isSuccess` will be false and `message` will contain error description. 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nexus replication plugin 2 | 3 | As Nexus Admin I'd like to keep data (artifacts) even if Nexus was destroyed. 4 | For this I can setup 2 or more Nexus instances and pass artifacts to all of 5 | them when artifact is initially uploaded to one of them. 6 | 7 | The plugin is going to be installed on both sending side that wants to 8 | pass an artifact and receiving side that can accept the artifact. 9 | 10 | ## Documentation 11 | 12 | [User documentation](documentation/user_doc.md) 13 | 14 | [Contributor documentation](documentation/contributor_doc.md) 15 | 16 | ## Mechanism 17 | 18 | Given artifact is uploaded to one of the Nexus instances: 19 | - A request is sent to Nexus-Receiver with info about artifact and repo it was 20 | placed in 21 | - Nexus-Receiver must have a Proxy Repository configured to proxy Nexus-Sender. 22 | After Nexus-Receiver gets the request it fetches target artifact by means of 23 | Proxy Repo configured to fetch changes from Nexus-Sender. 24 | 25 | For this a REST service is implemented with path: 26 | `service/local/artifact/maven/update`. 27 | 28 | ## To be done 29 | 30 | - Plugin can be configured using Nexus Capabilities 31 | - In configuration it's possible to set: 32 | - Nexus-Receiver addresses and credentials to be authorized 33 | - A flag whether an integration for particular Nexus-Receiver is enabled. 34 | Nexus-Sender should not send updates to such integration, but must store 35 | them for future replay. 36 | - Multiple Nexus-Receivers may be configured 37 | - A queue of artifacts must form on Nexus-Sender side if some of 38 | Nexus-Receivers are not available (requests fail) or Nexus-Receivers are 39 | disabled in config file. The queue has to be flushed into a persistent storage 40 | (file) to keep it even if Nexus-Sender crashes. 41 | - There must be a limit for a queue length. Default is 100K, but would be nice 42 | to configure it. 43 | - Nexus performance in general and UI in particular must not suffer from 44 | replication. This implies that all events must be processed in an async manner 45 | both in Nexus-Sender & Nexus-Receiver. 46 | - Logs must show errors if replication doesn't happen due to Nexus-Receiver 47 | unavailability 48 | 49 | ## Nice to have 50 | 51 | - An email to send warnings can be configured. Notifications must be sent when 52 | artifacts queue is 100, 500, 1000, 10K, 100K long. 53 | 54 | ### Copyright and License 55 | 56 | Copyright 2015, Grid Dynamics International, Inc. 57 | 58 | Licensed under the Apache License, Version 2.0 (the "License"); 59 | you may not use this file except in compliance with the License. 60 | You may obtain a copy of the License at [Apache License, Version 2.0](LICENSE.txt) 61 | 62 | Unless required by applicable law or agreed to in writing, software 63 | distributed under the License is distributed on an "AS IS" BASIS, 64 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 65 | See the License for the specific language governing permissions and 66 | limitations under the License. 67 | -------------------------------------------------------------------------------- /documentation/contributor_doc.md: -------------------------------------------------------------------------------- 1 | # Sonatype Nexus Replication Plugin 2 | 3 | [https://github.com/griddynamics/nexus-replication-plugin](https://github.com/griddynamics/nexus-replication-plugin) 4 | 5 | This is Sonatype Nexus plugin that facilitates push-replication to remote proxy repositories when new (Maven) artifacts are stored in a hosted repository. 6 | Let's say you have 2 or more instances of Nexus. When artifact is uploaded to one of them, that Nexus will send notifications to its peers. Then the Receving Nexuses poll the artifact from the original instance. 7 | 8 | ## Setting up plugin 9 | 10 | See [user documentation](user_doc.md). 11 | 12 | ## Plugin Architecture 13 | 14 | ![Plugin architecture](plugin_architecture.png) 15 | 16 | Plugin consists of two main parts: 17 | 18 | * [Deploy event listener](https://github.com/griddynamics/nexus-replication-plugin/blob/master/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/UploadEventListenerImpl.java) 19 | * [REST API Resource](https://github.com/griddynamics/nexus-replication-plugin/blob/master/src/main/java/com/griddynamics/cd/nrp/internal/rest/ArtifactUpdatePlexusResource.java) 20 | 21 | Deploy event listener is registred in [ReplicationPlugin class](https://github.com/griddynamics/nexus-replication-plugin/blob/master/src/main/java/com/griddynamics/cd/nrp/plugin/ReplicationPlugin.java). Event bus executes (1) it when new artifact is received to any hosted repository. Listener [takes peers list from configuration file](https://github.com/griddynamics/nexus-replication-plugin/blob/master/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ConfigurationsManagerImpl.java) and POST HTTP async request (2) to the each peer instanse using [API client](https://github.com/griddynamics/nexus-replication-plugin/blob/master/src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImpl.java). 22 | 23 | Plugin REST API is available at `service/local/artifact/maven/update`. This resource receives POST request with a body like this: 24 | 25 | ```xml 26 | 27 | 28 | com.griddynamics.cd 29 | nexus-replication-plugin 30 | 1.0-20150519.140619-2 31 | snapshots 32 | jar 33 | http://localhost:8081/nexus 34 | 35 | ``` 36 | 37 | When plugin receives replication API request it takes repositories list and filters it by several conditions: 38 | 39 | * If repository has proxy type 40 | * If repository proxies remote repository (that received artifact) 41 | * If repository remote URL starts with `nexusUrl` 42 | 43 | If all points are true it means that matched repository proxies remote repositoty (Master Nexus repository that received artifact). 44 | After plugin activates (3) matched repositories to poll artifact. 45 | 46 | As soon as artifact pooled (4) API resource returns XML formatted response. 47 | If artifact was resolved successfully response will be: 48 | 49 | ```xml 50 | 51 | true 52 | Artifact is resolved. 53 | 54 | ``` 55 | 56 | otherwise `isSuccess` will be false and `message` will contain error description. 57 | 58 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/FileBlockingQueue.java: -------------------------------------------------------------------------------- 1 | package com.griddynamics.cd.nrp.internal.uploading.impl; 2 | 3 | import com.google.common.collect.Sets; 4 | import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; 5 | import com.griddynamics.cd.nrp.internal.model.internal.ArtifactMetaInfoQueueDump; 6 | import org.apache.commons.io.FileUtils; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import javax.xml.bind.JAXBContext; 11 | import javax.xml.bind.Marshaller; 12 | import java.io.File; 13 | import java.util.concurrent.BlockingQueue; 14 | import java.util.concurrent.TimeUnit; 15 | 16 | /** 17 | * Stores artifacts that Plugin failed to send to another Nexus instance. If that happens, we don't want 18 | * to loose the history of updates and therefore we'll retry sending the requests even if Nexus Sender 19 | * was restarted. 20 | */ 21 | public class FileBlockingQueue { 22 | 23 | private final BlockingQueue internalBlockingQueue; 24 | private final String blockingQueueDumpFileName; 25 | 26 | private final Logger log = LoggerFactory.getLogger(FileBlockingQueue.class); 27 | 28 | public FileBlockingQueue(BlockingQueue blockingQueue, String blockingQueueDumpFileName) { 29 | this.internalBlockingQueue = blockingQueue; 30 | this.blockingQueueDumpFileName = blockingQueueDumpFileName; 31 | } 32 | 33 | public boolean offer(ArtifactMetaInfo e, long timeout, TimeUnit timeUnit) throws InterruptedException { 34 | synchronized (internalBlockingQueue) { 35 | boolean retVal = internalBlockingQueue.offer(e, timeout, timeUnit); 36 | saveQueueToFile(); 37 | internalBlockingQueue.notify(); 38 | return retVal; 39 | } 40 | } 41 | 42 | public ArtifactMetaInfo peek() throws InterruptedException { 43 | synchronized (internalBlockingQueue) { 44 | while (internalBlockingQueue.isEmpty()) { 45 | internalBlockingQueue.wait(); 46 | } 47 | return internalBlockingQueue.peek(); 48 | } 49 | } 50 | 51 | public ArtifactMetaInfo take() throws InterruptedException { 52 | synchronized (internalBlockingQueue) { 53 | while (internalBlockingQueue.isEmpty()) { 54 | internalBlockingQueue.wait(); 55 | } 56 | ArtifactMetaInfo retVal = internalBlockingQueue.take(); 57 | saveQueueToFile(); 58 | return retVal; 59 | 60 | } 61 | } 62 | 63 | private synchronized void saveQueueToFile() { 64 | 65 | try { 66 | String backupBlockingQueueDumpFileName = blockingQueueDumpFileName + ".bak"; 67 | File blockingQueueDumpFile = new File(blockingQueueDumpFileName); 68 | if (blockingQueueDumpFile.exists() && !blockingQueueDumpFile.isDirectory()) { 69 | FileUtils.copyFile(blockingQueueDumpFile, new File(backupBlockingQueueDumpFileName)); 70 | } 71 | JAXBContext jaxbContext = JAXBContext.newInstance(ArtifactMetaInfoQueueDump.class); 72 | Marshaller marshaller = jaxbContext.createMarshaller(); 73 | ArtifactMetaInfoQueueDump artifactMetaInfoBlockingQueueDump = 74 | new ArtifactMetaInfoQueueDump(); 75 | artifactMetaInfoBlockingQueueDump.addAllArtifactMetaInfo(Sets.newHashSet(internalBlockingQueue)); 76 | marshaller.marshal(artifactMetaInfoBlockingQueueDump, blockingQueueDumpFile); 77 | } catch (Exception e) { 78 | log.error(e.getMessage(), e); 79 | } 80 | 81 | 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ConfigurationsManagerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.uploading.impl; 17 | 18 | import com.griddynamics.cd.nrp.internal.model.config.ReplicationPluginConfiguration; 19 | import com.griddynamics.cd.nrp.internal.uploading.ConfigurationsManager; 20 | import org.sonatype.nexus.configuration.application.NexusConfiguration; 21 | import org.sonatype.sisu.goodies.common.ComponentSupport; 22 | 23 | import javax.annotation.PostConstruct; 24 | import javax.inject.Inject; 25 | import javax.inject.Named; 26 | import javax.inject.Singleton; 27 | import javax.xml.bind.JAXBContext; 28 | import javax.xml.bind.JAXBException; 29 | import javax.xml.bind.Unmarshaller; 30 | import java.io.File; 31 | 32 | /** 33 | * Class provides access to plugin configurations 34 | * parsed from {@link ConfigurationsManagerImpl#CONFIG_FILENAME} file 35 | */ 36 | @Singleton 37 | @Named(value = ConfigurationsManagerImpl.ID) 38 | public class ConfigurationsManagerImpl extends ComponentSupport implements ConfigurationsManager { 39 | 40 | public static final String ID = "configurationsManager"; 41 | 42 | /** 43 | * Filename of the XML configuration file 44 | */ 45 | private static final String CONFIG_FILENAME = "replication-plugin.xml"; 46 | 47 | /** 48 | * Bean provides nexus server configurations 49 | */ 50 | private NexusConfiguration nexusConfiguration; 51 | 52 | /** 53 | * DTO contains plugin configurations 54 | */ 55 | private volatile ReplicationPluginConfiguration config; 56 | 57 | @Inject 58 | public ConfigurationsManagerImpl(NexusConfiguration nexusConfiguration) { 59 | this.nexusConfiguration = nexusConfiguration; 60 | } 61 | 62 | /** 63 | * Loads configurations 64 | * from {@link ConfigurationsManagerImpl#CONFIG_FILENAME} file 65 | */ 66 | @PostConstruct 67 | public void init() { 68 | log.trace("Initializing plugin configurations"); 69 | reloadConfigurations(); 70 | } 71 | 72 | /** 73 | * Provides access to plugin configurations DTO 74 | * @return Plugin configurations 75 | */ 76 | @Override 77 | public ReplicationPluginConfiguration getConfiguration() { 78 | if (config == null) { 79 | synchronized (this) { 80 | if (config == null) { 81 | reloadConfigurations(); 82 | } 83 | } 84 | } 85 | return config; 86 | } 87 | 88 | /** 89 | * Reloads {@link ConfigurationsManagerImpl#config} 90 | * from XML plugin configurations file 91 | */ 92 | public void reloadConfigurations() { 93 | File file = getConfigurationFile(); 94 | try { 95 | JAXBContext jaxbContext = JAXBContext.newInstance(ReplicationPluginConfiguration.class); 96 | 97 | Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 98 | config = (ReplicationPluginConfiguration) jaxbUnmarshaller.unmarshal(file); 99 | } catch (JAXBException e) { 100 | log.error("Can not deserialize xml configuration file: " + file.getAbsolutePath(), e); 101 | } 102 | } 103 | 104 | /** 105 | * Returns plugin configurations XML file 106 | */ 107 | private File getConfigurationFile() { 108 | return new File(nexusConfiguration.getConfigurationDirectory(), CONFIG_FILENAME); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/UploadEventListenerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.uploading.impl; 17 | 18 | import com.google.common.eventbus.AllowConcurrentEvents; 19 | import com.google.common.eventbus.Subscribe; 20 | import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; 21 | import com.griddynamics.cd.nrp.internal.model.api.ArtifactStatus; 22 | import com.griddynamics.cd.nrp.internal.uploading.ArtifactUpdateApiClient; 23 | import com.griddynamics.cd.nrp.internal.uploading.ConfigurationsManager; 24 | import com.griddynamics.cd.nrp.internal.uploading.UploadEventListener; 25 | import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenProxyRepository; 26 | import org.sonatype.nexus.proxy.events.RepositoryItemEventStore; 27 | import org.sonatype.nexus.proxy.maven.MavenRepository; 28 | import org.sonatype.nexus.proxy.maven.gav.Gav; 29 | import org.sonatype.sisu.goodies.common.ComponentSupport; 30 | 31 | import javax.inject.Inject; 32 | import javax.inject.Named; 33 | import javax.inject.Singleton; 34 | import java.util.Map; 35 | import java.util.concurrent.ConcurrentHashMap; 36 | 37 | /** 38 | * Artifact stored event hook 39 | */ 40 | @Singleton 41 | @Named(UploadEventListenerImpl.ID) 42 | public class UploadEventListenerImpl extends ComponentSupport implements UploadEventListener { 43 | 44 | public static final String ID = "uploadEventListener"; 45 | 46 | /** 47 | * Provides access to plugin the configurations 48 | */ 49 | private ConfigurationsManager configurationsManager; 50 | 51 | private ArtifactUpdateApiClient artifactUpdateApiClient; 52 | 53 | private Map receivedArtifacts = new ConcurrentHashMap<>(); 54 | 55 | @Inject 56 | public UploadEventListenerImpl(@Named(value = ConfigurationsManagerImpl.ID) ConfigurationsManager configurationsManager, 57 | @Named(value = ArtifactUpdateApiClientImpl.ID) ArtifactUpdateApiClient artifactUpdateApiClient) { 58 | this.configurationsManager = configurationsManager; 59 | this.artifactUpdateApiClient = artifactUpdateApiClient; 60 | } 61 | 62 | /** 63 | * Fired when new artifact deployed to nexus (proxy repositories are ignored) 64 | */ 65 | @Subscribe 66 | @AllowConcurrentEvents 67 | public void onArtifactUploading(RepositoryItemEventStore event) { 68 | if (event.getRepository() instanceof MavenRepository && 69 | !(event.getRepository() instanceof MavenProxyRepository)) { 70 | MavenRepository repo = (MavenRepository) event.getRepository(); 71 | Gav gav = repo.getGavCalculator().pathToGav(event.getItemUid().getPath()); 72 | if (null != gav) { 73 | ArtifactMetaInfo metaInfo = new ArtifactMetaInfo(configurationsManager.getConfiguration().getMyUrl(), gav.getGroupId(), gav.getArtifactId(), gav.getVersion(), repo.getId()); 74 | metaInfo.setClassifier(gav.getClassifier()); 75 | metaInfo.setExtension(gav.getExtension()); 76 | ArtifactStatus artifactStatus = null; 77 | if (!gav.isSignature() && !gav.isHash()) { 78 | artifactStatus = getArtifactStatus(metaInfo); 79 | artifactStatus.setFileReceived(true); 80 | log.debug("File received: " + metaInfo.toString()); 81 | } else if (gav.isHash() && gav.getHashType().equals(Gav.HashType.sha1)) { 82 | artifactStatus = getArtifactStatus(metaInfo); 83 | artifactStatus.setSha1Received(true); 84 | log.debug(gav.getHashType().name() + " hash file received for: " + metaInfo.toString()); 85 | } 86 | if (null != artifactStatus) { 87 | updateArtifactStatus(metaInfo, artifactStatus); 88 | if (artifactStatus.isReadyForReplication()) { 89 | log.debug("File with hashes received for: " + metaInfo.toString() + " Sending request"); 90 | artifactUpdateApiClient.offerRequest(metaInfo); 91 | clearStatus(metaInfo); 92 | } 93 | } 94 | } 95 | } 96 | } 97 | 98 | /** 99 | * Returns if binary / checksum files were deployed 100 | * @param metaInfo Meta info of the deployed artifact 101 | */ 102 | private ArtifactStatus getArtifactStatus(ArtifactMetaInfo metaInfo) { 103 | if (!receivedArtifacts.containsKey(metaInfo)) { 104 | receivedArtifacts.put(metaInfo, new ArtifactStatus(metaInfo)); 105 | } 106 | return receivedArtifacts.get(metaInfo); 107 | } 108 | 109 | /** 110 | * Executed when new file (binary or checksum) received 111 | * @param artifactMetaInfo Meta info of the deployed artifact 112 | * @param artifactStatus Information about received files for deployed artifact 113 | */ 114 | private void updateArtifactStatus(ArtifactMetaInfo artifactMetaInfo, ArtifactStatus artifactStatus) { 115 | receivedArtifacts.put(artifactMetaInfo, artifactStatus); 116 | } 117 | 118 | /** 119 | * Executed when bin and sha1 files received and nexus peer notifications sent 120 | * @param metaInfo Meta info of the deployed artifact 121 | */ 122 | private void clearStatus(ArtifactMetaInfo metaInfo) { 123 | receivedArtifacts.remove(metaInfo); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 4.0.0 23 | 24 | com.griddynamics.cd 25 | nexus-replication-plugin 26 | 1.0-SNAPSHOT 27 | nexus-plugin 28 | 29 | Nexus Replication Plugin 30 | Sonatype Nexus plugin to push updates to remote proxy repositories. 31 | https://github.com/griddynamics/nexus-replication-plugin 32 | 33 | 34 | The Apache License, Version 2.0 35 | http://www.apache.org/licenses/LICENSE-2.0.txt 36 | 37 | 38 | 39 | 40 | scm:git:git@github.com:griddynamics/nexus-replication-plugin.git 41 | scm:git:git@github.com:griddynamics/nexus-replication-plugin.git 42 | git@github.com:griddynamics/nexus-replication-plugin.git 43 | 44 | 45 | 46 | org.sonatype.nexus.plugins 47 | nexus-plugins 48 | 2.11.2-06 49 | 50 | 51 | 52 | ${project.name} 53 | Facilitates push-replication to remote proxy repositories. 54 | ${project.parent.version} 55 | 56 | 57 | 58 | 59 | org.sonatype.nexus 60 | nexus-plugin-api 61 | ${nexus.version} 62 | provided 63 | 64 | 65 | org.sonatype.nexus 66 | nexus-security 67 | ${nexus.version} 68 | provided 69 | 70 | 71 | org.sonatype.nexus 72 | nexus-plugin-testsupport 73 | ${nexus.version} 74 | test 75 | 76 | 77 | javax.servlet 78 | javax.servlet-api 79 | 80 | 81 | 82 | 83 | org.sonatype.nexus 84 | nexus-rest-api 85 | 2.2.1 86 | provided 87 | 88 | 89 | commons-logging 90 | commons-logging-api 91 | 92 | 93 | com.google.code.atinject 94 | atinject 95 | 96 | 97 | javax.servlet 98 | servlet-api 99 | 100 | 101 | org.sonatype.sisu 102 | sisu-velocity 103 | 104 | 105 | 106 | 107 | org.sonatype.nexus 108 | nexus-proxy 109 | 2.3.1-01 110 | provided 111 | 112 | 113 | org.sonatype.sisu 114 | sisu-velocity 115 | 116 | 117 | 118 | 119 | org.sonatype.nexus.plugins 120 | nexus-restlet1x-plugin 121 | ${nexus-plugin.type} 122 | provided 123 | 124 | 125 | com.sun.jersey 126 | jersey-client 127 | 1.19 128 | 129 | 130 | com.sun.jersey 131 | jersey-core 132 | 1.19 133 | 134 | 135 | org.codehaus.jackson 136 | jackson-jaxrs 137 | 1.9.13 138 | 139 | 140 | org.sonatype.nexus 141 | nexus-client-core 142 | ${nexus.version} 143 | 144 | 145 | org.projectlombok 146 | lombok 147 | 1.16.4 148 | 149 | 150 | 151 | 152 | 153 | 154 | org.sonatype.nexus 155 | nexus-plugin-bundle-maven-plugin 156 | true 157 | 158 | 159 | org.apache.maven.plugins 160 | maven-compiler-plugin 161 | 3.3 162 | 163 | 1.7 164 | 1.7 165 | 166 | 167 | 168 | 169 | 170 | org.sonatype.plugins 171 | app-lifecycle-nexus 172 | 1.7 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/rest/ArtifactUpdatePlexusResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.rest; 17 | 18 | import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; 19 | import com.griddynamics.cd.nrp.internal.model.api.RestResponse; 20 | import com.thoughtworks.xstream.XStream; 21 | import org.codehaus.enunciate.contract.jaxrs.ResourceMethodSignature; 22 | import org.codehaus.plexus.component.annotations.Component; 23 | import org.restlet.Context; 24 | import org.restlet.data.Request; 25 | import org.restlet.data.Response; 26 | import org.restlet.data.Status; 27 | import org.restlet.resource.ResourceException; 28 | import org.slf4j.Logger; 29 | import org.slf4j.LoggerFactory; 30 | import org.sonatype.nexus.proxy.AccessDeniedException; 31 | import org.sonatype.nexus.proxy.IllegalOperationException; 32 | import org.sonatype.nexus.proxy.ItemNotFoundException; 33 | import org.sonatype.nexus.proxy.StorageException; 34 | import org.sonatype.nexus.proxy.maven.ArtifactStoreHelper; 35 | import org.sonatype.nexus.proxy.maven.ArtifactStoreRequest; 36 | import org.sonatype.nexus.proxy.maven.MavenProxyRepository; 37 | import org.sonatype.nexus.proxy.repository.Repository; 38 | import org.sonatype.nexus.rest.artifact.AbstractArtifactPlexusResource; 39 | import org.sonatype.plexus.rest.resource.PathProtectionDescriptor; 40 | import org.sonatype.plexus.rest.resource.PlexusResource; 41 | 42 | import javax.inject.Inject; 43 | import javax.ws.rs.Consumes; 44 | import javax.ws.rs.POST; 45 | import javax.ws.rs.Path; 46 | import javax.ws.rs.Produces; 47 | import javax.ws.rs.core.MediaType; 48 | 49 | /** 50 | * REST resource force repository update artifact 51 | */ 52 | @Path(ArtifactUpdatePlexusResource.REQUEST_URI) 53 | @Produces({MediaType.APPLICATION_XML}) 54 | @Consumes({MediaType.APPLICATION_XML}) 55 | @Component(role = PlexusResource.class, hint = ArtifactUpdatePlexusResource.ID) 56 | public class ArtifactUpdatePlexusResource extends AbstractArtifactPlexusResource { 57 | public static final String ID = "artifactUpdatePlexusResource"; 58 | public static final String REQUEST_URI = "/artifact/maven/update"; 59 | 60 | private Logger log = LoggerFactory.getLogger(ArtifactUpdatePlexusResource.class); 61 | 62 | @Inject 63 | public ArtifactUpdatePlexusResource() { 64 | // Allows POST requests 65 | setModifiable(true); 66 | } 67 | 68 | /** 69 | * The location to attach this resource to. 70 | */ 71 | @Override 72 | public String getResourceUri() { 73 | return REQUEST_URI; 74 | } 75 | 76 | /** 77 | * A permission prefix to be applied when securing the resource. 78 | */ 79 | @Override 80 | public PathProtectionDescriptor getResourceProtection() { 81 | return new PathProtectionDescriptor(getResourceUri(), "authcBasic,perms[nexus:artifact]"); 82 | } 83 | 84 | /** 85 | * A factory method to create an instance of DTO (POST request body). 86 | */ 87 | @Override 88 | public Object getPayloadInstance() { 89 | return new ArtifactMetaInfo(); 90 | } 91 | 92 | /** 93 | * A Resource may add some configuration stuff to the XStream, and control the serialization of the payloads it 94 | * uses. 95 | */ 96 | @Override 97 | public void configureXStream(XStream xstream) { 98 | xstream.processAnnotations(ArtifactMetaInfo.class); 99 | xstream.processAnnotations(RestResponse.class); 100 | } 101 | 102 | /** 103 | * Update content of passed artifact in the proxy repositories of the passed repository 104 | */ 105 | @POST 106 | @Override 107 | @ResourceMethodSignature(input = ArtifactMetaInfo.class, output = RestResponse.class) 108 | public Object post(Context context, Request request, Response response, Object payload) throws ResourceException { 109 | ArtifactMetaInfo metaInfo = (ArtifactMetaInfo) payload; 110 | if (!metaInfo.isValid()) { 111 | throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 112 | "At least following request parameters have to be given: nexusUrl, groupId, artifactId, version, repositoryId!"); 113 | } 114 | boolean artifactResolved = false; 115 | for (Repository repository : getRepositoryRegistry().getRepositories()) { 116 | if (repository instanceof MavenProxyRepository) { 117 | MavenProxyRepository mavenProxyRepository = (MavenProxyRepository) repository; 118 | log.trace(String.format("Processing repository: %s. Remote url: %s", mavenProxyRepository.getId(), mavenProxyRepository.getRemoteUrl())); 119 | if (matchRepository(mavenProxyRepository, metaInfo)) { 120 | ArtifactStoreRequest gavRequest = getResourceStoreRequest(request, false, false, 121 | mavenProxyRepository.getId(), metaInfo.getGroupId(), metaInfo.getArtifactId(), 122 | metaInfo.getVersion(), metaInfo.getPackaging(), metaInfo.getClassifier(), metaInfo.getExtension()); 123 | try { 124 | ArtifactStoreHelper helper = mavenProxyRepository.getArtifactStoreHelper(); 125 | helper.retrieveArtifact(gavRequest); 126 | artifactResolved = true; 127 | } catch (ItemNotFoundException | IllegalOperationException | StorageException | AccessDeniedException e) { 128 | log.error("Can not resolve artifact", e); 129 | return new RestResponse(false, "Can not resolve artifact. " + e.getMessage()); 130 | } 131 | } 132 | } 133 | } 134 | if (artifactResolved) { 135 | return new RestResponse(true, "Artifact is resolved."); 136 | } else { 137 | return new RestResponse(false, "No proxies for this artifact."); 138 | } 139 | } 140 | 141 | /** 142 | * Checks if proxy repository should resolve remote artifact 143 | * @param mavenProxyRepository Proxy repository 144 | * @param metaInfo Information about artifact that was deployed to the master nexus 145 | * @return true if repository should resolve artifact 146 | */ 147 | private boolean matchRepository(MavenProxyRepository mavenProxyRepository, ArtifactMetaInfo metaInfo) { 148 | if (mavenProxyRepository.getRemoteUrl() == null) { 149 | return false; 150 | } 151 | boolean matchRepositoryName = mavenProxyRepository.getRemoteUrl().endsWith("/" + metaInfo.getRepositoryId() + "/") || 152 | mavenProxyRepository.getRemoteUrl().endsWith("/" + metaInfo.getRepositoryId()); 153 | boolean matchRemoteNexusUrl = mavenProxyRepository.getRemoteUrl().startsWith(metaInfo.getNexusUrl()); 154 | return matchRepositoryName && matchRemoteNexusUrl; 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/ArtifactUpdateApiClientImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Grid Dynamics International, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.griddynamics.cd.nrp.internal.uploading.impl; 17 | 18 | import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; 19 | import com.griddynamics.cd.nrp.internal.model.config.ReplicationPluginConfiguration; 20 | import com.griddynamics.cd.nrp.internal.model.internal.ArtifactMetaInfoQueueDump; 21 | import com.griddynamics.cd.nrp.internal.model.api.RestResponse; 22 | import com.griddynamics.cd.nrp.internal.model.config.NexusServer; 23 | import com.griddynamics.cd.nrp.internal.uploading.ArtifactUpdateApiClient; 24 | import com.griddynamics.cd.nrp.internal.uploading.ConfigurationsManager; 25 | import com.sun.jersey.api.client.AsyncWebResource; 26 | import com.sun.jersey.api.client.Client; 27 | import com.sun.jersey.api.client.GenericType; 28 | import com.sun.jersey.api.client.async.ITypeListener; 29 | import com.sun.jersey.api.client.config.ClientConfig; 30 | import com.sun.jersey.api.client.config.DefaultClientConfig; 31 | import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; 32 | import org.sonatype.sisu.goodies.common.ComponentSupport; 33 | 34 | import javax.inject.Inject; 35 | import javax.inject.Named; 36 | import javax.inject.Singleton; 37 | import javax.ws.rs.core.MediaType; 38 | import javax.ws.rs.core.UriBuilder; 39 | import javax.xml.bind.JAXBContext; 40 | import javax.xml.bind.Unmarshaller; 41 | import java.io.File; 42 | import java.util.concurrent.*; 43 | 44 | /** 45 | * Responsible to send request to other Nexus instances to notify them about new artifacts. 46 | * There are 2 separate thread pools working along: 47 | * - Usual sending threads that work when new artifacts are uploaded to Nexus Sender 48 | * - Threads that read queue of artifacts from file. That file is filled with new 49 | * artifacts if Nexus Receiver was not available and our Nexus was 50 | * shut down. It then reads artifacts from the file and tries to send them to Receiver 51 | */ 52 | 53 | @Singleton 54 | @Named(ArtifactUpdateApiClientImpl.ID) 55 | public class ArtifactUpdateApiClientImpl extends ComponentSupport implements ArtifactUpdateApiClient { 56 | 57 | public static final String ID = "artifactUpdateApiClient"; 58 | 59 | /** 60 | * Default value for request queue timeout 61 | * Timeout should be relatively low and should be lower than Jersey Client read timeout 62 | */ 63 | public static final int QUEUE_TIMEOUT_IN_SECOND = 1; 64 | 65 | /** 66 | * Provides access to the plugin configurations 67 | */ 68 | private final ConfigurationsManager configurationsManager; 69 | 70 | /** 71 | * ExecutorService shares between clients. All treads are created in the same executor 72 | */ 73 | private final ExecutorService jerseyHttpClientExecutor; 74 | private final FileBlockingQueue fileBlockingQueue; 75 | 76 | @Inject 77 | public ArtifactUpdateApiClientImpl(ConfigurationsManager configurationsManager) { 78 | this.configurationsManager = configurationsManager; 79 | this.fileBlockingQueue = initFileBlockingQueue(configurationsManager.getConfiguration()); 80 | this.jerseyHttpClientExecutor = new ThreadPoolExecutor( 81 | configurationsManager.getConfiguration().getRequestsSendingThreadsCount(), 82 | configurationsManager.getConfiguration().getRequestsSendingThreadsCount(), 83 | 30, 84 | TimeUnit.SECONDS, 85 | new LinkedBlockingQueue( 86 | configurationsManager.getConfiguration().getRequestsQueueSize()) 87 | ); 88 | initBackgroundWorkers(configurationsManager.getConfiguration()); 89 | } 90 | 91 | private void initBackgroundWorkers(ReplicationPluginConfiguration replicationPluginConfiguration) { 92 | int requestsSendingThreadsCount = replicationPluginConfiguration.getRequestsSendingThreadsCount(); 93 | ExecutorService executorService = Executors.newFixedThreadPool(requestsSendingThreadsCount); 94 | for (int i = 0; i < requestsSendingThreadsCount; i++) { 95 | executorService.submit(new Runnable() { 96 | @Override 97 | public void run() { 98 | while (!Thread.currentThread().isInterrupted()) { 99 | try { 100 | ArtifactMetaInfo artifactMetaInfo = fileBlockingQueue.peek(); 101 | sendRequest(artifactMetaInfo); 102 | fileBlockingQueue.take(); 103 | } catch (Exception e) { 104 | log.error(e.getMessage(), e); 105 | } 106 | } 107 | } 108 | }); 109 | } 110 | } 111 | 112 | private FileBlockingQueue initFileBlockingQueue(ReplicationPluginConfiguration replicationPluginConfiguration) { 113 | BlockingQueue blockingQueue = 114 | new LinkedBlockingQueue<>(replicationPluginConfiguration.getRequestsQueueSize()); 115 | String queueFileName = replicationPluginConfiguration.getQueueDumpFileName(); 116 | FileBlockingQueue retVal = new FileBlockingQueue(blockingQueue, 117 | queueFileName); 118 | try { 119 | File queueFile = new File(queueFileName); 120 | if (queueFile.exists()) { 121 | JAXBContext jaxbContext = JAXBContext.newInstance(ArtifactMetaInfoQueueDump.class); 122 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 123 | ArtifactMetaInfoQueueDump unmarshal = (ArtifactMetaInfoQueueDump) unmarshaller.unmarshal(queueFile); 124 | for (ArtifactMetaInfo artifactMetaInfo : unmarshal.getArtifactMetaInfos()) { 125 | offerRequest(artifactMetaInfo); 126 | } 127 | } 128 | } catch (Exception e) { 129 | log.error(e.getMessage(), e); 130 | } 131 | return retVal; 132 | } 133 | 134 | @Override 135 | public void offerRequest(ArtifactMetaInfo artifactMetaInfo) { 136 | try { 137 | fileBlockingQueue.offer(artifactMetaInfo, QUEUE_TIMEOUT_IN_SECOND, TimeUnit.SECONDS); 138 | } catch (Exception e) { 139 | log.error(e.getMessage(), e); 140 | } 141 | } 142 | 143 | /** 144 | * Sends replication requests to all nexus servers configured in XML file 145 | * 146 | * @param metaInfo Artifact information 147 | */ 148 | public void sendRequest(ArtifactMetaInfo metaInfo) { 149 | for (NexusServer server : configurationsManager.getConfiguration().getServers()) { 150 | AsyncWebResource.Builder service = getService(server.getUrl(), server.getUser(), server.getPassword()); 151 | try { 152 | service.post(new ITypeListener() { 153 | @Override 154 | public void onComplete(Future future) throws InterruptedException { 155 | RestResponse response = null; 156 | try { 157 | response = future.get(); 158 | } catch (ExecutionException e) { 159 | log.error("Can not get REST response", e); 160 | } 161 | if (response != null && !response.isSuccess()) { 162 | log.error("Can not send replication request: " + response.getMessage()); 163 | } 164 | } 165 | 166 | @Override 167 | public Class getType() { 168 | return RestResponse.class; 169 | } 170 | 171 | @Override 172 | public GenericType getGenericType() { 173 | return null; 174 | } 175 | 176 | }, metaInfo); 177 | } catch (RejectedExecutionException e) { 178 | log.warn("Requests queue is full. Request to " + server.getUrl() + " is rejected"); 179 | } 180 | } 181 | } 182 | 183 | /** 184 | * Returns jersey HTTP resource to access to the remote replication servers 185 | * 186 | * @param nexusUrl URL of the remote server 187 | * @param login Username on the remote server 188 | * @param password User's password 189 | * @return Jersey HTTP client 190 | */ 191 | private AsyncWebResource.Builder getService(String nexusUrl, String login, String password) { 192 | Client client = getClient(login, password); 193 | client.setExecutorService(jerseyHttpClientExecutor); 194 | AsyncWebResource webResource = client.asyncResource(UriBuilder.fromUri(nexusUrl).build()); 195 | webResource = webResource.path("service").path("local").path("artifact").path("maven").path("update"); 196 | return webResource.accept(MediaType.APPLICATION_XML_TYPE) 197 | .type(MediaType.APPLICATION_XML_TYPE); 198 | } 199 | 200 | /** 201 | * Creates jersey HTTP client 202 | * 203 | * @param login Username on the remote server 204 | * @param password User's password 205 | * @return HTTP client 206 | */ 207 | private Client getClient(String login, String password) { 208 | ClientConfig config = new DefaultClientConfig(); 209 | config.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, 1000); 210 | config.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, 2000); 211 | Client client = Client.create(config); 212 | client.setExecutorService(jerseyHttpClientExecutor); 213 | if (login != null && !login.isEmpty() && password != null) { 214 | log.debug("Creating HTTP client with authorized HTTPBasicAuthFilter."); 215 | client.addFilter(new HTTPBasicAuthFilter(login, password)); 216 | } else { 217 | log.debug("Creating HTTP client with anonymous HTTPBasicAuthFilter."); 218 | } 219 | return client; 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2015 Grid Dynamics http://www.griddynamics.com 191 | 192 | 193 | Licensed under the Apache License, Version 2.0 (the "License"); 194 | you may not use this file except in compliance with the License. 195 | You may obtain a copy of the License at 196 | 197 | http://www.apache.org/licenses/LICENSE-2.0 198 | 199 | Unless required by applicable law or agreed to in writing, software 200 | distributed under the License is distributed on an "AS IS" BASIS, 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | See the License for the specific language governing permissions and 203 | limitations under the License. 204 | --------------------------------------------------------------------------------