You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2018/03/04 23:01:24 UTC

[incubator-pulsar] branch master updated: Rename pulsar function api from V1 to V2 (#1325)

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

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new fb97446  Rename pulsar function api from V1 to V2 (#1325)
fb97446 is described below

commit fb974460ee16d709eb89964ea586f5ca350c5f4e
Author: Sijie Guo <gu...@gmail.com>
AuthorDate: Sun Mar 4 15:01:21 2018 -0800

    Rename pulsar function api from V1 to V2 (#1325)
    
    - rename the V1 to V2
    - change the way how the rest api was organized to allow it merged back to pulsar webservice and cli
---
 .../apache/pulsar/functions/worker/rest/Resources.java |  4 ++--
 .../pulsar/functions/worker/rest/WorkerServer.java     | 18 +++++++++++++++++-
 .../FunctionApiV2Resource.java}                        |  7 +++----
 .../FunctionApiV2ResourceTest.java}                    | 10 +++++-----
 4 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/Resources.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/Resources.java
index 26ad9c2..702ab4c 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/Resources.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/Resources.java
@@ -18,7 +18,7 @@
  */
 package org.apache.pulsar.functions.worker.rest;
 
-import org.apache.pulsar.functions.worker.rest.api.v1.FunctionApiV1Resource;
+import org.apache.pulsar.functions.worker.rest.api.v2.FunctionApiV2Resource;
 import org.glassfish.jersey.media.multipart.MultiPartFeature;
 
 import java.util.Arrays;
@@ -38,7 +38,7 @@ public final class Resources {
     private static List<Class<?>> getClasses() {
         return Arrays.asList(
                 ConfigurationResource.class,
-                FunctionApiV1Resource.class,
+                FunctionApiV2Resource.class,
                 MultiPartFeature.class
         );
     }
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/WorkerServer.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/WorkerServer.java
index a1b3292..0e897da 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/WorkerServer.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/WorkerServer.java
@@ -18,13 +18,19 @@
  */
 package org.apache.pulsar.functions.worker.rest;
 
+import java.util.ArrayList;
+import java.util.List;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.pulsar.functions.worker.WorkerConfig;
 import org.apache.pulsar.functions.worker.WorkerService;
+import org.eclipse.jetty.server.Handler;
 import org.eclipse.jetty.server.Server;
 
 import java.net.BindException;
 import java.net.URI;
+import org.eclipse.jetty.server.handler.ContextHandlerCollection;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
 
 @Slf4j
 public class WorkerServer implements Runnable {
@@ -49,7 +55,17 @@ public class WorkerServer implements Runnable {
     @Override
     public void run() {
         final Server server = new Server(this.workerConfig.getWorkerPort());
-        server.setHandler(WorkerService.newServletContextHandler("/", workerService));
+
+        List<Handler> handlers = new ArrayList<>(2);
+        handlers.add(WorkerService.newServletContextHandler("/admin", workerService));
+        handlers.add(WorkerService.newServletContextHandler("/admin/v2", workerService));
+        ContextHandlerCollection contexts = new ContextHandlerCollection();
+        contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
+        HandlerCollection handlerCollection = new HandlerCollection();
+        handlerCollection.setHandlers(new Handler[] {
+            contexts, new DefaultHandler()
+        });
+        server.setHandler(handlerCollection);
 
         try {
             server.start();
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v1/FunctionApiV1Resource.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2Resource.java
similarity index 99%
rename from pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v1/FunctionApiV1Resource.java
rename to pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2Resource.java
index fa6e59b..7227196 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v1/FunctionApiV1Resource.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2Resource.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.pulsar.functions.worker.rest.api.v1;
+package org.apache.pulsar.functions.worker.rest.api.v2;
 
 import com.google.gson.Gson;
 import javax.ws.rs.core.Response.Status;
@@ -38,7 +38,6 @@ import org.apache.pulsar.functions.worker.MembershipManager;
 import org.apache.pulsar.functions.worker.Utils;
 import org.apache.pulsar.functions.worker.request.RequestResult;
 import org.apache.pulsar.functions.worker.rest.FunctionApiResource;
-import org.apache.pulsar.functions.worker.WorkerConfig;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 import org.glassfish.jersey.media.multipart.FormDataParam;
 
@@ -62,8 +61,8 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 
 @Slf4j
-@Path("/admin/functions")
-public class FunctionApiV1Resource extends FunctionApiResource {
+@Path("/functions")
+public class FunctionApiV2Resource extends FunctionApiResource {
 
     @POST
     @Path("/{tenant}/{namespace}/{functionName}")
diff --git a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v1/FunctionApiV1ResourceTest.java b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java
similarity index 99%
rename from pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v1/FunctionApiV1ResourceTest.java
rename to pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java
index 28a68e6..fe75940 100644
--- a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v1/FunctionApiV1ResourceTest.java
+++ b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.pulsar.functions.worker.rest.api.v1;
+package org.apache.pulsar.functions.worker.rest.api.v2;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
@@ -67,11 +67,11 @@ import org.testng.annotations.ObjectFactory;
 import org.testng.annotations.Test;
 
 /**
- * Unit test of {@link FunctionApiV1Resource}.
+ * Unit test of {@link FunctionApiV2Resource}.
  */
 @PrepareForTest(Utils.class)
 @PowerMockIgnore({ "javax.management.*", "javax.ws.*", "org.apache.logging.log4j.*" })
-public class FunctionApiV1ResourceTest {
+public class FunctionApiV2ResourceTest {
 
     @ObjectFactory
     public IObjectFactory getObjectFactory() {
@@ -98,13 +98,13 @@ public class FunctionApiV1ResourceTest {
     private WorkerService mockedWorkerService;
     private FunctionMetaDataManager mockedManager;
     private Namespace mockedNamespace;
-    private FunctionApiV1Resource resource;
+    private FunctionApiV2Resource resource;
     private InputStream mockedInputStream;
     private FormDataContentDisposition mockedFormData;
 
     @BeforeMethod
     public void setup() {
-        this.resource = spy(new FunctionApiV1Resource());
+        this.resource = spy(new FunctionApiV2Resource());
         this.mockedManager = mock(FunctionMetaDataManager.class);
         this.mockedInputStream = mock(InputStream.class);
         this.mockedFormData = mock(FormDataContentDisposition.class);

-- 
To stop receiving notification emails like this one, please contact
mmerli@apache.org.