curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [1/4] git commit: development continues
Date Tue, 18 Feb 2014 09:48:42 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-88 ce456d2df -> b4c76c79b


development continues


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/4ab6476c
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/4ab6476c
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/4ab6476c

Branch: refs/heads/CURATOR-88
Commit: 4ab6476c090383dd8b411c21a56d497b226938ce
Parents: ce456d2
Author: randgalt <randgalt@apache.org>
Authored: Mon Feb 17 13:28:19 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Mon Feb 17 13:28:19 2014 -0500

----------------------------------------------------------------------
 .../curator/x/rest/CuratorRestContext.java      |  23 ++++
 .../curator/x/rest/api/ClientResource.java      |  96 ++++++++++++++---
 .../apache/curator/x/rest/api/Constants.java    |   1 +
 .../x/rest/api/RestBackgroundCallback.java      |   7 +-
 .../org/apache/curator/x/rest/api/Session.java  |   6 +-
 .../x/rest/dropwizard/CuratorApplication.java   |  52 +++++++++
 .../x/rest/dropwizard/CuratorConfiguration.java | 105 +++++++++++++++++++
 .../x/rest/dropwizard/CuratorHealthCheck.java   |  45 ++++++++
 .../x/rest/dropwizard/CuratorRestBundle.java    |  36 +++++--
 .../curator/x/rest/entities/LeaderSpec.java     |   3 +
 .../curator/x/rest/entities/PathAndId.java      |  60 +++++++++++
 .../entities/PersistentEphemeralNodeSpec.java   |   2 +
 curator-x-rest/src/main/resources/maven/pom.xml |  85 +++++++++++++++
 .../src/site/confluence/index.confluence        |   4 +-
 curator-x-rest/src/site/site.xml                |  38 +++----
 .../x/rest/dropwizard/DropwizardRunner.java     |  29 +----
 16 files changed, 514 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
index a07197e..68cb939 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
@@ -20,6 +20,8 @@ package org.apache.curator.x.rest;
 
 import com.google.common.base.Preconditions;
 import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.state.ConnectionState;
+import org.apache.curator.framework.state.ConnectionStateListener;
 import org.apache.curator.utils.ThreadUtils;
 import org.apache.curator.x.rest.api.Session;
 import org.codehaus.jackson.map.ObjectMapper;
@@ -38,6 +40,19 @@ public class CuratorRestContext implements Closeable
     private final int sessionLengthMs;
     private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
     private final ScheduledExecutorService executorService = ThreadUtils.newSingleThreadScheduledExecutor("CuratorRestContext");
+    private final AtomicReference<ConnectionState> connectionState = new AtomicReference<ConnectionState>();
+    private final ConnectionStateListener connectionStateListener = new ConnectionStateListener()
+    {
+        @Override
+        public void stateChanged(CuratorFramework client, ConnectionState newState)
+        {
+            if ( newState == ConnectionState.RECONNECTED )
+            {
+                newState = ConnectionState.CONNECTED;
+            }
+            connectionState.set(newState);
+        }
+    };
 
     private enum State
     {
@@ -58,6 +73,11 @@ public class CuratorRestContext implements Closeable
         return client;
     }
 
+    public ConnectionState getConnectionState()
+    {
+        return connectionState.get();
+    }
+
     public Session getSession()
     {
         Preconditions.checkState(state.get() == State.STARTED, "Not started");
@@ -77,6 +97,8 @@ public class CuratorRestContext implements Closeable
             }
         };
         executorService.scheduleAtFixedRate(runner, sessionLengthMs, sessionLengthMs, TimeUnit.MILLISECONDS);
+        client.getConnectionStateListenable().addListener(connectionStateListener);
+        connectionState.set(client.getZookeeperClient().isConnected() ? ConnectionState.CONNECTED
: ConnectionState.SUSPENDED);
     }
 
     @Override
@@ -84,6 +106,7 @@ public class CuratorRestContext implements Closeable
     {
         if ( state.compareAndSet(State.STARTED, State.CLOSED) )
         {
+            client.getConnectionStateListenable().removeListener(connectionStateListener);
             executorService.shutdownNow();
             session.close();
         }

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/ClientResource.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/ClientResource.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/ClientResource.java
index 26708cf..2321fa0 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/ClientResource.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/ClientResource.java
@@ -19,6 +19,8 @@
 package org.apache.curator.x.rest.api;
 
 import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.api.*;
 import org.apache.curator.x.rest.CuratorRestContext;
 import org.apache.curator.x.rest.entities.CreateSpec;
@@ -26,15 +28,18 @@ import org.apache.curator.x.rest.entities.DeleteSpec;
 import org.apache.curator.x.rest.entities.ExistsSpec;
 import org.apache.curator.x.rest.entities.GetChildrenSpec;
 import org.apache.curator.x.rest.entities.GetDataSpec;
+import org.apache.curator.x.rest.entities.PathAndId;
 import org.apache.curator.x.rest.entities.SetDataSpec;
+import org.apache.zookeeper.CreateMode;
 import org.codehaus.jackson.node.ObjectNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -46,6 +51,7 @@ import java.util.List;
 @Path("/curator/v1/client")
 public class ClientResource
 {
+    private final Logger log = LoggerFactory.getLogger(getClass());
     private final CuratorRestContext context;
 
     public ClientResource(@Context CuratorRestContext context)
@@ -58,22 +64,25 @@ public class ClientResource
     @Path("/status")
     public Response getStatus() throws IOException
     {
-        ObjectNode node = context.getMapper().createObjectNode();
-        node.put("state", context.getClient().getState().name());
-        node.putPOJO("messages", context.getSession().drainMessages());
-
-        return Response.ok(context.getWriter().writeValueAsString(node)).build();
+        return getStatusWithTouch(ImmutableList.<String>of());
     }
 
-    @GET
-    @Path("/touch/{id}")
-    public Response touchThing(@PathParam("id") String id)
+    @POST
+    @Produces(MediaType.APPLICATION_JSON)
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Path("/status")
+    public Response getStatusWithTouch(List<String> ids) throws IOException
     {
-        if ( !context.getSession().updateThingLastUse(id) )
+        ObjectNode node = context.getMapper().createObjectNode();
+        node.put("state", context.getConnectionState().name());
+        node.putPOJO("messages", context.getSession().drainMessages());
+
+        for ( String id : ids )
         {
-            return Response.status(Response.Status.NOT_FOUND).build();
+            context.getSession().updateThingLastUse(id);
         }
-        return Response.ok().build();
+
+        return Response.ok(context.getWriter().writeValueAsString(node)).build();
     }
 
     @POST
@@ -185,17 +194,47 @@ public class ClientResource
         }
         builder = castBuilder(builder, CreateModable.class).withMode(createSpec.getMode());
 
+        final String id = Constants.newId();
         if ( createSpec.isAsync() )
         {
-            BackgroundCallback backgroundCallback = new RestBackgroundCallback(context, Constants.CLIENT_CREATE_ASYNC,
createSpec.getAsyncId());
+            BackgroundCallback backgroundCallback = new RestBackgroundCallback(context, Constants.CLIENT_CREATE_ASYNC,
createSpec.getAsyncId())
+            {
+                @Override
+                public void processResult(CuratorFramework client, CuratorEvent event) throws
Exception
+                {
+                    if ( event.getResultCode() == 0 )
+                    {
+                        checkEphemeralCreate(createSpec, id, event.getName());
+                    }
+                    super.processResult(client, event);
+                }
+
+                @Override
+                protected String getMessage(CuratorEvent event)
+                {
+                    if ( event.getResultCode() != 0 )
+                    {
+                        return Constants.ERROR;
+                    }
+                    return event.getName();
+                }
+
+                @Override
+                protected String getDetails(CuratorEvent event)
+                {
+                    if ( event.getResultCode() != 0 )
+                    {
+                        return super.getDetails(event);
+                    }
+                    return id;
+                }
+            };
             builder = castBuilder(builder, Backgroundable.class).inBackground(backgroundCallback);
         }
 
         String returnPath = String.valueOf(castBuilder(builder, PathAndBytesable.class).forPath(createSpec.getPath(),
createSpec.getData().getBytes()));
-
-        ObjectNode node = context.getMapper().createObjectNode();
-        node.put("path", returnPath);
-        return Response.ok(context.getWriter().writeValueAsString(node)).build();
+        checkEphemeralCreate(createSpec, id, returnPath);
+        return Response.ok(new PathAndId(returnPath, id)).build();
     }
 
     @POST
@@ -275,4 +314,27 @@ public class ClientResource
         throw new WebApplicationException(Response.Status.BAD_REQUEST);
     }
 
+    private void checkEphemeralCreate(CreateSpec createSpec, String id, String ephemeralPath)
+    {
+        if ( (createSpec.getMode() == CreateMode.EPHEMERAL) || (createSpec.getMode() == CreateMode.EPHEMERAL_SEQUENTIAL)
)
+        {
+            Closer<String> closer = new Closer<String>()
+            {
+                @Override
+                public void close(String path)
+                {
+                    log.warn("Ephemeral node has expired and is being deleted: " + path);
+                    try
+                    {
+                        context.getClient().delete().guaranteed().inBackground().forPath(path);
+                    }
+                    catch ( Exception e )
+                    {
+                        log.error("Could not delete expired ephemeral node: " + path);
+                    }
+                }
+            };
+            context.getSession().addThing(id, ephemeralPath, closer);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java
index 5ee1982..a516322 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java
@@ -34,6 +34,7 @@ class Constants
     static final String CLIENT_SET_DATA_ASYNC = "client-set-data-async";
     static final String CLIENT_EXISTS_ASYNC = "client-exists-async";
     static final String CLIENT_DELETE_ASYNC = "client-delete-async";
+    static final String ERROR = "error";
     static final String WATCH = "watch";
     static final String PATH_CACHE = "path-cache";
     static final String NODE_CACHE = "node-cache";

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/RestBackgroundCallback.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/RestBackgroundCallback.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/RestBackgroundCallback.java
index 482576b..a5e2284 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/RestBackgroundCallback.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/RestBackgroundCallback.java
@@ -40,7 +40,12 @@ class RestBackgroundCallback implements BackgroundCallback
     @Override
     public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
     {
-        context.getSession().pushMessage(new StatusMessage(type, asyncId, getMessage(event),
Integer.toString(event.getResultCode())));
+        context.getSession().pushMessage(new StatusMessage(type, asyncId, getMessage(event),
getDetails(event)));
+    }
+
+    protected String getDetails(CuratorEvent event)
+    {
+        return Integer.toString(event.getResultCode());
     }
 
     protected String getMessage(CuratorEvent event)

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Session.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Session.java b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Session.java
index 16478ce..36a2654 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Session.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Session.java
@@ -113,7 +113,11 @@ public class Session implements Closeable
 
     <T> String addThing(T thing, Closer<T> closer)
     {
-        String id = Constants.newId();
+        return addThing(Constants.newId(), thing, closer);
+    }
+
+    <T> String addThing(String id, T thing, Closer<T> closer)
+    {
         things.put(id, new Entry(thing, closer));
         return id;
     }

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorApplication.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorApplication.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorApplication.java
new file mode 100644
index 0000000..539097d
--- /dev/null
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorApplication.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.x.rest.dropwizard;
+
+import io.dropwizard.Application;
+import io.dropwizard.setup.Bootstrap;
+import io.dropwizard.setup.Environment;
+
+public class CuratorApplication
+{
+    public static void main(String[] args) throws Exception
+    {
+        Application application = new Application<CuratorConfiguration>()
+        {
+            @Override
+            public void initialize(Bootstrap<CuratorConfiguration> bootstrap)
+            {
+                bootstrap.addBundle(new CuratorRestBundle());
+            }
+
+            @Override
+            public void run(CuratorConfiguration configuration, Environment environment)
throws Exception
+            {
+                // NOP
+            }
+        };
+
+        if ( args.length == 0 )
+        {
+            args = new String[]{"server"};
+        }
+
+        application.run(args);
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorConfiguration.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorConfiguration.java
new file mode 100644
index 0000000..0ca30ac
--- /dev/null
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorConfiguration.java
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.x.rest.dropwizard;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.dropwizard.Configuration;
+import javax.validation.Valid;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import java.util.concurrent.TimeUnit;
+
+public class CuratorConfiguration extends Configuration
+{
+    @Valid
+    @NotNull
+    @JsonProperty("connection-string")
+    private String zooKeeperConnectionString = "localhost:2181";
+
+    @Valid
+    @Min(1)
+    @JsonProperty("session-length-ms")
+    private int sessionLengthMs = (int)TimeUnit.MINUTES.toMillis(1);
+
+    @Valid
+    @Min(1)
+    @JsonProperty("connection-timeout-ms")
+    private int connectionTimeoutMs = (int)TimeUnit.SECONDS.toMillis(15);
+
+    @Valid
+    @Min(1)
+    @JsonProperty("retry-base-sleep-ms")
+    private int retryBaseSleepMs = 100;
+
+    @Valid
+    @Min(1)
+    @JsonProperty("retry-qty")
+    private int retryQty = 3;
+
+    public String getZooKeeperConnectionString()
+    {
+        return zooKeeperConnectionString;
+    }
+
+    public void setZooKeeperConnectionString(String zooKeeperConnectionString)
+    {
+        this.zooKeeperConnectionString = zooKeeperConnectionString;
+    }
+
+    public int getSessionLengthMs()
+    {
+        return sessionLengthMs;
+    }
+
+    public void setSessionLengthMs(int sessionLengthMs)
+    {
+        this.sessionLengthMs = sessionLengthMs;
+    }
+
+    public int getConnectionTimeoutMs()
+    {
+        return connectionTimeoutMs;
+    }
+
+    public void setConnectionTimeoutMs(int connectionTimeoutMs)
+    {
+        this.connectionTimeoutMs = connectionTimeoutMs;
+    }
+
+    public int getRetryBaseSleepMs()
+    {
+        return retryBaseSleepMs;
+    }
+
+    public void setRetryBaseSleepMs(int retryBaseSleepMs)
+    {
+        this.retryBaseSleepMs = retryBaseSleepMs;
+    }
+
+    public int getRetryQty()
+    {
+        return retryQty;
+    }
+
+    public void setRetryQty(int retryQty)
+    {
+        this.retryQty = retryQty;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorHealthCheck.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorHealthCheck.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorHealthCheck.java
new file mode 100644
index 0000000..594574d
--- /dev/null
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorHealthCheck.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.x.rest.dropwizard;
+
+import com.codahale.metrics.health.HealthCheck;
+import org.apache.curator.framework.state.ConnectionState;
+import org.apache.curator.x.rest.CuratorRestContext;
+
+public class CuratorHealthCheck extends HealthCheck
+{
+    private final CuratorRestContext context;
+
+    public CuratorHealthCheck(CuratorRestContext context)
+    {
+        this.context = context;
+    }
+
+    @Override
+    protected Result check() throws Exception
+    {
+        ConnectionState state = context.getConnectionState();
+        if ( state != ConnectionState.CONNECTED )
+        {
+            return Result.unhealthy(state.name());
+        }
+        return Result.healthy();
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorRestBundle.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorRestBundle.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorRestBundle.java
index 250b285..2edc06f 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorRestBundle.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorRestBundle.java
@@ -20,25 +20,20 @@
 package org.apache.curator.x.rest.dropwizard;
 
 import com.sun.jersey.spi.inject.SingletonTypeInjectableProvider;
-import io.dropwizard.Bundle;
+import io.dropwizard.ConfiguredBundle;
 import io.dropwizard.setup.Bootstrap;
 import io.dropwizard.setup.Environment;
 import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
 import org.apache.curator.x.rest.CuratorRestClasses;
 import org.apache.curator.x.rest.CuratorRestContext;
 import org.eclipse.jetty.util.component.AbstractLifeCycle;
 import org.eclipse.jetty.util.component.LifeCycle;
 import javax.ws.rs.core.Context;
 
-public class CuratorRestBundle implements Bundle
+public class CuratorRestBundle implements ConfiguredBundle<CuratorConfiguration>
 {
-    private final CuratorRestContext context;
-
-    public CuratorRestBundle(CuratorFramework client, int sessionLengthMs)
-    {
-        this.context = new CuratorRestContext(client, sessionLengthMs);
-    }
-
     @Override
     public void initialize(Bootstrap<?> bootstrap)
     {
@@ -46,8 +41,10 @@ public class CuratorRestBundle implements Bundle
     }
 
     @Override
-    public void run(Environment environment)
+    public void run(CuratorConfiguration configuration, Environment environment) throws Exception
     {
+        final CuratorRestContext context = newCuratorRestContext(configuration);
+
         SingletonTypeInjectableProvider<Context, CuratorRestContext> injectable = new
SingletonTypeInjectableProvider<Context, CuratorRestContext>(CuratorRestContext.class,
context){};
         environment.jersey().register(injectable);
         for ( Class<?> clazz : CuratorRestClasses.getClasses() )
@@ -70,5 +67,24 @@ public class CuratorRestBundle implements Bundle
             }
         };
         environment.lifecycle().addLifeCycleListener(listener);
+
+        environment.healthChecks().register("Curator", new CuratorHealthCheck(context));
+    }
+
+    protected CuratorRestContext newCuratorRestContext(CuratorConfiguration configuration)
+    {
+        CuratorFramework client = newCuratorClient(configuration);
+        return new CuratorRestContext(client, configuration.getSessionLengthMs());
+    }
+
+    protected CuratorFramework newCuratorClient(CuratorConfiguration configuration)
+    {
+        ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(configuration.getRetryBaseSleepMs(),
configuration.getRetryQty());
+        return CuratorFrameworkFactory.newClient
+        (
+            configuration.getZooKeeperConnectionString(),
+            configuration.getSessionLengthMs(),
+            configuration.getConnectionTimeoutMs(), retryPolicy
+        );
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/LeaderSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/LeaderSpec.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/LeaderSpec.java
index ad7fa90..fde9701 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/LeaderSpec.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/LeaderSpec.java
@@ -18,6 +18,9 @@
  */
 package org.apache.curator.x.rest.entities;
 
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
 public class LeaderSpec
 {
     private String path;

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/PathAndId.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/PathAndId.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/PathAndId.java
new file mode 100644
index 0000000..ed27938
--- /dev/null
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/PathAndId.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.x.rest.entities;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class PathAndId
+{
+    private String path;
+    private String id;
+
+    public PathAndId()
+    {
+        this("/", "");
+    }
+
+    public PathAndId(String path, String id)
+    {
+        this.path = path;
+        this.id = id;
+    }
+
+    public String getPath()
+    {
+        return path;
+    }
+
+    public void setPath(String path)
+    {
+        this.path = path;
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public void setId(String id)
+    {
+        this.id = id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/PersistentEphemeralNodeSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/PersistentEphemeralNodeSpec.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/PersistentEphemeralNodeSpec.java
index 691e77c..5f70112 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/PersistentEphemeralNodeSpec.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/PersistentEphemeralNodeSpec.java
@@ -19,7 +19,9 @@
 package org.apache.curator.x.rest.entities;
 
 import org.apache.curator.framework.recipes.nodes.PersistentEphemeralNode;
+import javax.xml.bind.annotation.XmlRootElement;
 
+@XmlRootElement
 public class PersistentEphemeralNodeSpec
 {
     private String path;

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/main/resources/maven/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/resources/maven/pom.xml b/curator-x-rest/src/main/resources/maven/pom.xml
new file mode 100644
index 0000000..9b2e707
--- /dev/null
+++ b/curator-x-rest/src/main/resources/maven/pom.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.curator</groupId>
+    <artifactId>curator-rest-application</artifactId>
+    <version>2.4.1-SNAPSHOT</version>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-x-rest</artifactId>
+            <version>2.4.1-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>io.dropwizard</groupId>
+            <artifactId>dropwizard-core</artifactId>
+            <version>0.7.0-rc1</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>2.2</version>
+                <configuration>
+                    <createDependencyReducedPom>false</createDependencyReducedPom>
+                    <filters>
+                        <filter>
+                            <artifact>*:*</artifact>
+                            <excludes>
+                                <exclude>META-INF/*.SF</exclude>
+                                <exclude>META-INF/*.DSA</exclude>
+                                <exclude>META-INF/*.RSA</exclude>
+                            </excludes>
+                        </filter>
+                    </filters>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <transformers>
+                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
+                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                                    <mainClass>org.apache.curator.x.rest.dropwizard.CuratorApplication</mainClass>
+                                </transformer>
+                            </transformers>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/site/confluence/index.confluence
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/site/confluence/index.confluence b/curator-x-rest/src/site/confluence/index.confluence
index 5303b40..d81c9a8 100644
--- a/curator-x-rest/src/site/confluence/index.confluence
+++ b/curator-x-rest/src/site/confluence/index.confluence
@@ -1,8 +1,6 @@
 h1. Curator REST Proxy
 
-h2. Packaging
-Curator REST Proxy is in its own package in Maven Central: {{curator-x-rest}}
+NOTE: Curator REST Proxy is in its own package in Maven Central: {{curator-x-rest}}
 
-h2. Description
 The Curator REST module implements a proxy that bridges non-java environments with the Curator
framework and recipes. *TBD*
 

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/site/site.xml
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/site/site.xml b/curator-x-rest/src/site/site.xml
index fe42cef..5f9c307 100644
--- a/curator-x-rest/src/site/site.xml
+++ b/curator-x-rest/src/site/site.xml
@@ -1,22 +1,24 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--~
-  ~ Licensed to the Apache Software Foundation (ASF) under one
-  ~ or more contributor license agreements.  See the NOTICE file
-  ~ distributed with this work for additional information
-  ~ regarding copyright ownership.  The ASF licenses this file
-  ~ to you under the Apache License, Version 2.0 (the
-  ~ "License"); you may not use this file except in compliance
-  ~ with the License.  You may obtain a copy of the License at
-  ~
-  ~   http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~ Unless required by applicable law or agreed to in writing,
-  ~ software distributed under the License is distributed on an
-  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-  ~ KIND, either express or implied.  See the License for the
-  ~ specific language governing permissions and limitations
-  ~ under the License.
-  -->
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
 <project xmlns="http://maven.apache.org/DECORATION/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.1.0 http://maven.apache.org/xsd/decoration-1.1.0.xsd"
name="Discovery Service Server">
     <body>
         <head>

http://git-wip-us.apache.org/repos/asf/curator/blob/4ab6476c/curator-x-rest/src/test/java/org/apache/curator/x/rest/dropwizard/DropwizardRunner.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/test/java/org/apache/curator/x/rest/dropwizard/DropwizardRunner.java
b/curator-x-rest/src/test/java/org/apache/curator/x/rest/dropwizard/DropwizardRunner.java
index 44e2194..4d81ae9 100644
--- a/curator-x-rest/src/test/java/org/apache/curator/x/rest/dropwizard/DropwizardRunner.java
+++ b/curator-x-rest/src/test/java/org/apache/curator/x/rest/dropwizard/DropwizardRunner.java
@@ -19,37 +19,10 @@
 
 package org.apache.curator.x.rest.dropwizard;
 
-import io.dropwizard.Application;
-import io.dropwizard.Configuration;
-import io.dropwizard.setup.Bootstrap;
-import io.dropwizard.setup.Environment;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-
 public class DropwizardRunner
 {
     public static void main(String[] args) throws Exception
     {
-        Application<Configuration> application = new Application<Configuration>()
-        {
-            @Override
-            public void initialize(Bootstrap<Configuration> bootstrap)
-            {
-                CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181",
new ExponentialBackoffRetry(100, 3));
-                client.start();
-                bootstrap.addBundle(new CuratorRestBundle(client, 60000));
-            }
-
-            @Override
-            public void run(Configuration configuration, Environment environment) throws
Exception
-            {
-            }
-        };
-        if ( args.length == 0 )
-        {
-            args = new String[]{"server"};
-        }
-        application.run(args);
+        CuratorApplication.main(args);
     }
 }


Mime
View raw message