You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2017/12/09 08:41:31 UTC

[karaf-cave] branch master updated: [KARAF-5108] Improve the deployer service

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf-cave.git


The following commit(s) were added to refs/heads/master by this push:
     new cf33e96  [KARAF-5108] Improve the deployer service
cf33e96 is described below

commit cf33e9604ec74b64b5718ba02bbc95a3f76ce629
Author: Jean-Baptiste Onofré <jb...@apache.org>
AuthorDate: Sat Dec 9 09:41:19 2017 +0100

    [KARAF-5108] Improve the deployer service
---
 .../apache/karaf/cave/deployer/api/Deployer.java   | 25 +++++++++-----
 .../karaf/cave/deployer/rest/DeployerRest.java     | 40 ++++++++++++----------
 .../karaf/cave/deployer/rest/DeployerRestTest.java |  6 ++--
 .../cave/deployer/service/impl/DeployerImpl.java   | 29 ++++++++++------
 .../deployer/service/impl/DeployerImplTest.java    |  6 ++--
 5 files changed, 63 insertions(+), 43 deletions(-)

diff --git a/deployer/api/src/main/java/org/apache/karaf/cave/deployer/api/Deployer.java b/deployer/api/src/main/java/org/apache/karaf/cave/deployer/api/Deployer.java
index de1f1a7..f7dc97b 100644
--- a/deployer/api/src/main/java/org/apache/karaf/cave/deployer/api/Deployer.java
+++ b/deployer/api/src/main/java/org/apache/karaf/cave/deployer/api/Deployer.java
@@ -22,22 +22,31 @@ import java.util.Map;
 public interface Deployer {
 
     /**
-     * Explode a KAR file and upload the content on a Maven repository.
+     * Explode a file (KAR or zip) and upload the content on a Maven repository.
      *
-     * @param karUrl The location of the KAR file.
-     * @param repositoryUrl The location of the Maven repository where to upload.
+     * @param url The location of the file.
+     * @param repository The location of the Maven repository where to upload.
+     * @throws Exception in case of failure.
+     */
+    void explode(String url, String repository) throws Exception;
+
+    /**
+     * Extract a file (KAR or zip) to a local Karaf directory.
+     *
+     * @param url The location of the file.
+     * @param directory The location of the directory where to extract.
      * @throws Exception in case of failure.
      */
-    void explodeKar(String karUrl, String repositoryUrl) throws Exception;
+    void extract(String url, String directory) throws Exception;
 
     /**
      * Download an artifact from a given URL and copy it on a local filesystem.
      *
-     * @param artifactUrl The artifact URL.
-     * @param localUrl The local filesystem URL.
+     * @param artifact The artifact URL.
+     * @param directory The local directory.
      * @throws Exception in case of failure.
      */
-    void downloadArtifact(String artifactUrl, String localUrl) throws Exception;
+    void download(String artifact, String directory) throws Exception;
 
     /**
      * Upload an artifact to a Maven repository using the provided Maven coordinates.
@@ -49,7 +58,7 @@ public interface Deployer {
      * @param repositoryUrl The location of the Maven repository where to upload.
      * @throws Exception in case of failure.
      */
-    void uploadArtifact(String groupId, String artifactId, String version, String artifactUrl, String repositoryUrl)
+    void upload(String groupId, String artifactId, String version, String artifactUrl, String repositoryUrl)
         throws Exception;
 
     /**
diff --git a/deployer/rest/src/main/java/org/apache/karaf/cave/deployer/rest/DeployerRest.java b/deployer/rest/src/main/java/org/apache/karaf/cave/deployer/rest/DeployerRest.java
index 81b093a..715ea02 100644
--- a/deployer/rest/src/main/java/org/apache/karaf/cave/deployer/rest/DeployerRest.java
+++ b/deployer/rest/src/main/java/org/apache/karaf/cave/deployer/rest/DeployerRest.java
@@ -21,10 +21,7 @@ import org.apache.karaf.cave.deployer.api.Deployer;
 import org.apache.karaf.cave.deployer.api.Feature;
 import org.apache.karaf.cave.deployer.api.FeaturesRepository;
 
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
+import javax.ws.rs.*;
 import java.util.List;
 import java.util.Map;
 
@@ -33,18 +30,25 @@ public class DeployerRest {
 
     private Deployer deployer;
 
-    @Path("/kar/explode")
+    @Path("/artifact/explode")
     @Consumes("application/json")
     @POST
-    public void explodeKar(KarExplodeRequest request) throws Exception {
-        deployer.explodeKar(request.getArtifactUrl(), request.getRepositoryUrl());
+    public void explode(KarExplodeRequest request) throws Exception {
+        deployer.explode(request.getArtifactUrl(), request.getRepositoryUrl());
+    }
+
+    @Path("/artifact/extract")
+    @Consumes("application/json")
+    @POST
+    public void extract(String artifactUrl, String directory) throws Exception {
+        deployer.extract(artifactUrl, directory);
     }
 
     @Path("/artifact/upload")
     @Consumes("application/json")
     @POST
-    public void uploadArtifact(UploadRequest request) throws Exception {
-        deployer.uploadArtifact(request.getGroupId(),
+    public void upload(UploadRequest request) throws Exception {
+        deployer.upload(request.getGroupId(),
                 request.getArtifactId(),
                 request.getVersion(),
                 request.getArtifactUrl(),
@@ -54,8 +58,8 @@ public class DeployerRest {
     @Path("/artifact/download")
     @Consumes("application/json")
     @POST
-    public void downloadArtifact(String artifactUrl, String localPath) throws Exception {
-        deployer.downloadArtifact(artifactUrl, localPath);
+    public void download(String artifactUrl, String localPath) throws Exception {
+        deployer.download(artifactUrl, localPath);
     }
 
     @Path("/bundle/deploy")
@@ -138,7 +142,7 @@ public class DeployerRest {
     @Path("/kars")
     @Consumes("application/json")
     @Produces("application/json")
-    @POST
+    @GET
     public List<String> listKars(BasicRequest request) throws Exception {
         return deployer.listKars(request.getJmxUrl(),
                 request.getKarafName(),
@@ -186,7 +190,7 @@ public class DeployerRest {
     @Path("/feature/repositories")
     @Consumes("application/json")
     @Produces("application/json")
-    @POST
+    @GET
     public List<FeaturesRepository> listFeaturesRepositories(BasicRequest request) throws Exception {
         return deployer.listFeaturesRepositories(request.getJmxUrl(),
                 request.getKarafName(),
@@ -219,7 +223,7 @@ public class DeployerRest {
     @Path("/features")
     @Consumes("application/json")
     @Produces("application/json")
-    @POST
+    @GET
     public List<Feature> listFeatures(BasicRequest request) throws Exception {
         return deployer.listFeatures(request.getJmxUrl(),
                 request.getKarafName(),
@@ -252,7 +256,7 @@ public class DeployerRest {
     @Path("/config/properties")
     @Consumes("application/json")
     @Produces("application/json")
-    @POST
+    @GET
     public Map<String, String> getConfigProperties(ConfigRequest request) throws Exception {
         return deployer.getConfigProperties(request.getPid(),
                 request.getJmxUrl(),
@@ -287,7 +291,7 @@ public class DeployerRest {
 
     @Path("/config/property/get")
     @Consumes("application/json")
-    @POST
+    @GET
     public String getConfigProperty(ConfigPropertyKeyRequest request) throws Exception {
         return deployer.getConfigProperty(request.getPid(),
                 request.getKey(),
@@ -372,7 +376,7 @@ public class DeployerRest {
     @Path("/cluster/nodes")
     @Consumes("application/json")
     @Produces("application/json")
-    @POST
+    @GET
     public List<String> clusterNodes(DeployRequest request) throws Exception {
         return deployer.clusterNodes(request.getJmxUrl(),
                 request.getKarafName(),
@@ -383,7 +387,7 @@ public class DeployerRest {
     @Path("/cluster/groups")
     @Consumes("application/json")
     @Produces("application/json")
-    @POST
+    @GET
     public Map<String, List<String>> clusterGroups(DeployRequest request) throws Exception {
         return deployer.clusterGroups(request.getJmxUrl(),
                 request.getKarafName(),
diff --git a/deployer/rest/src/test/java/org/apache/karaf/cave/deployer/rest/DeployerRestTest.java b/deployer/rest/src/test/java/org/apache/karaf/cave/deployer/rest/DeployerRestTest.java
index 557f480..1a9330c 100644
--- a/deployer/rest/src/test/java/org/apache/karaf/cave/deployer/rest/DeployerRestTest.java
+++ b/deployer/rest/src/test/java/org/apache/karaf/cave/deployer/rest/DeployerRestTest.java
@@ -49,7 +49,7 @@ public class DeployerRestTest {
         uploadRequest.setGroupId("kar-test");
         uploadRequest.setArtifactId("kar-test");
         uploadRequest.setVersion("1.0-SNAPSHOT");
-        rest.uploadArtifact(uploadRequest);
+        rest.upload(uploadRequest);
 
         DeployRequest request = new DeployRequest();
         request.setArtifactUrl("mvn:kar-test/kar-test/1.0-SNAPSHOT/kar");
@@ -73,14 +73,14 @@ public class DeployerRestTest {
         uploadRequest.setGroupId("kar-test");
         uploadRequest.setArtifactId("kar-test");
         uploadRequest.setVersion("1.0-SNAPSHOT");
-        rest.uploadArtifact(uploadRequest);
+        rest.upload(uploadRequest);
 
         KarExplodeRequest karExplodeRequest = new KarExplodeRequest();
         // TODO: the artifact URL should be the one on Maven repository
         // To simplify we use test resources location directly
         karExplodeRequest.setArtifactUrl("file:src/test/resources/test.kar");
         karExplodeRequest.setRepositoryUrl("file:target/test/repository");
-        rest.explodeKar(karExplodeRequest);
+        rest.explode(karExplodeRequest);
     }
 
     @Test
diff --git a/deployer/service/src/main/java/org/apache/karaf/cave/deployer/service/impl/DeployerImpl.java b/deployer/service/src/main/java/org/apache/karaf/cave/deployer/service/impl/DeployerImpl.java
index 56561db..56c8393 100644
--- a/deployer/service/src/main/java/org/apache/karaf/cave/deployer/service/impl/DeployerImpl.java
+++ b/deployer/service/src/main/java/org/apache/karaf/cave/deployer/service/impl/DeployerImpl.java
@@ -61,20 +61,27 @@ public class DeployerImpl implements Deployer {
     private final static Pattern mvnPattern = Pattern.compile("mvn:([^/ ]+)/([^/ ]+)/([^/ ]*)(/([^/ ]+)(/([^/ ]+))?)?");
 
     @Override
-    public void downloadArtifact(String artifactUrl, String localUrl) throws Exception {
-        InputStream is = new URI(artifactUrl).toURL().openStream();
-        File file = new File(localUrl);
+    public void download(String artifact, String directory) throws Exception {
+        InputStream is = new URI(artifact).toURL().openStream();
+        File file = new File(directory);
         file.getParentFile().mkdirs();
         FileOutputStream os = new FileOutputStream(file);
         copyStream(is, os);
     }
 
     @Override
-    public void explodeKar(String karUrl, String repositoryUrl) throws Exception {
+    public void explode(String artifact, String repository) throws Exception {
         File tempDirectory = Files.createTempDir();
-        extract(karUrl, tempDirectory);
+        extract(artifact, tempDirectory);
         File karRepository = new File(tempDirectory, "repository");
-        browseKar(karRepository, karRepository.getPath(), repositoryUrl);
+        browseKar(karRepository, karRepository.getPath(), repository);
+    }
+
+    @Override
+    public void extract(String artifact, String directory) throws Exception {
+        File directoryFile = new File(directory);
+        directoryFile.mkdirs();
+        extract(artifact, directoryFile);
     }
 
     protected void browseKar(File entry, String basePath, String repositoryUrl) {
@@ -189,11 +196,11 @@ public class DeployerImpl implements Deployer {
     }
 
     @Override
-    public void uploadArtifact(String groupId,
-                               String artifactId,
-                               String version,
-                               String artifactUrl,
-                               String repositoryUrl) throws Exception {
+    public void upload(String groupId,
+                       String artifactId,
+                       String version,
+                       String artifactUrl,
+                       String repositoryUrl) throws Exception {
 
         Map<String, String> coordonates = new HashMap<String, String>();
         if (isMavenUrl(artifactUrl)) {
diff --git a/deployer/service/src/test/java/org/apache/karaf/cave/deployer/service/impl/DeployerImplTest.java b/deployer/service/src/test/java/org/apache/karaf/cave/deployer/service/impl/DeployerImplTest.java
index afc71ce..dfc279c 100644
--- a/deployer/service/src/test/java/org/apache/karaf/cave/deployer/service/impl/DeployerImplTest.java
+++ b/deployer/service/src/test/java/org/apache/karaf/cave/deployer/service/impl/DeployerImplTest.java
@@ -39,17 +39,17 @@ public class DeployerImplTest {
 
     @Test
     public void downloadArtifactTest() throws Exception {
-        deployer.downloadArtifact("mvn:commons-lang/commons-lang/2.6", "target/test/commons-lang-2.6.jar");
+        deployer.download("mvn:commons-lang/commons-lang/2.6", "target/test/commons-lang-2.6.jar");
     }
 
     @Test
     public void explodeKarTest() throws Exception {
-        deployer.explodeKar("mvn:org.apache.karaf.features/framework/4.1.3/kar", "file:target/test/repository/kar");
+        deployer.explode("mvn:org.apache.karaf.features/framework/4.1.3/kar", "file:target/test/repository/kar");
     }
 
     @Test
     public void uploadArtifactTest() throws Exception {
-        deployer.uploadArtifact("test", "test", "1.0-SNAPSHOT", "mvn:commons-lang/commons-lang/2.6", "file:target/test/repository");
+        deployer.upload("test", "test", "1.0-SNAPSHOT", "mvn:commons-lang/commons-lang/2.6", "file:target/test/repository");
     }
 
     @Test

-- 
To stop receiving notification emails like this one, please contact
['"commits@karaf.apache.org" <co...@karaf.apache.org>'].