curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [02/14] git commit: wip
Date Tue, 27 May 2014 13:57:24 GMT
wip


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

Branch: refs/heads/curator-rpc
Commit: 10e52ad0051f839e0349d728b22254a42e91924e
Parents: b949f57
Author: randgalt <randgalt@apache.org>
Authored: Mon May 26 00:05:49 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Mon May 26 00:05:49 2014 -0500

----------------------------------------------------------------------
 .../apache/curator/x/rpc/idl/CreateMode.java    |   9 ++
 .../apache/curator/x/rpc/idl/CreateSpec.java    | 105 +++++++++++++++++
 .../x/rpc/idl/CuratorProjectionService.java     | 118 +++++++++++++++++++
 curator-x-rpc/src/main/scripts/generate.sh      |  13 +-
 curator-x-rpc/src/main/thrift/curator.thrift    |  14 +++
 5 files changed, 255 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/10e52ad0/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CreateMode.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CreateMode.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CreateMode.java
new file mode 100644
index 0000000..f35e32b
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CreateMode.java
@@ -0,0 +1,9 @@
+package org.apache.curator.x.rpc.idl;
+
+public enum CreateMode
+{
+    PERSISTENT,
+    PERSISTENT_SEQUENTIAL,
+    EPHEMERAL,
+    EPHEMERAL_SEQUENTIAL
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/10e52ad0/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CreateSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CreateSpec.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CreateSpec.java
new file mode 100644
index 0000000..f401fb5
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CreateSpec.java
@@ -0,0 +1,105 @@
+package org.apache.curator.x.rpc.idl;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class CreateSpec
+{
+    private String path;
+    private String data;
+    private CreateMode mode;
+    private boolean async;
+    private String asyncId;
+    private boolean compressed;
+    private boolean creatingParentsIfNeeded;
+    private boolean withProtection;
+
+    @ThriftField(1)
+    public String getPath()
+    {
+        return path;
+    }
+
+    @ThriftField(2)
+    public String getAsyncId()
+    {
+        return asyncId;
+    }
+
+    public void setAsyncId(String asyncId)
+    {
+        this.asyncId = asyncId;
+    }
+
+    public void setPath(String path)
+    {
+        this.path = path;
+    }
+
+    @ThriftField(3)
+    public String getData()
+    {
+        return data;
+    }
+
+    public void setData(String data)
+    {
+        this.data = data;
+    }
+
+    @ThriftField(4)
+    public CreateMode getMode()
+    {
+        return mode;
+    }
+
+    public void setMode(CreateMode mode)
+    {
+        this.mode = mode;
+    }
+
+    @ThriftField(5)
+    public boolean isAsync()
+    {
+        return async;
+    }
+
+    public void setAsync(boolean async)
+    {
+        this.async = async;
+    }
+
+    @ThriftField(6)
+    public boolean isCompressed()
+    {
+        return compressed;
+    }
+
+    public void setCompressed(boolean compressed)
+    {
+        this.compressed = compressed;
+    }
+
+    @ThriftField(7)
+    public boolean isCreatingParentsIfNeeded()
+    {
+        return creatingParentsIfNeeded;
+    }
+
+    public void setCreatingParentsIfNeeded(boolean creatingParentsIfNeeded)
+    {
+        this.creatingParentsIfNeeded = creatingParentsIfNeeded;
+    }
+
+    @ThriftField(8)
+    public boolean isWithProtection()
+    {
+        return withProtection;
+    }
+
+    public void setWithProtection(boolean withProtection)
+    {
+        this.withProtection = withProtection;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/10e52ad0/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionService.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionService.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionService.java
index dd5bf33..8acfd0f 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionService.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionService.java
@@ -5,6 +5,10 @@ import com.facebook.swift.service.ThriftService;
 import com.google.common.collect.Maps;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.Compressible;
+import org.apache.curator.framework.api.CreateBuilder;
+import org.apache.curator.framework.api.CreateModable;
+import org.apache.curator.framework.api.PathAndBytesable;
 import org.apache.curator.retry.RetryOneTime;
 import java.util.Map;
 import java.util.UUID;
@@ -33,4 +37,118 @@ public class CuratorProjectionService
             client.close();
         }
     }
+
+    //@ThriftMethod
+    public String create(CuratorProjection projection, CreateSpec createSpec) throws Exception
+    {
+        CuratorFramework client = getClient(projection);
+
+        Object builder = client.create();
+        if ( createSpec.isCreatingParentsIfNeeded() )
+        {
+            builder = castBuilder(builder, CreateBuilder.class).creatingParentsIfNeeded();
+        }
+        if ( createSpec.isCompressed() )
+        {
+            builder = castBuilder(builder, Compressible.class).compressed();
+        }
+        if ( createSpec.isWithProtection() )
+        {
+            builder = castBuilder(builder, CreateBuilder.class).withProtection();
+        }
+        builder = castBuilder(builder, CreateModable.class).withMode(getRealMode(createSpec.getMode()));
+
+        if ( createSpec.isAsync() )
+        {
+/*
+TODO
+            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)
+                {
+                    PathAndId pathAndId = new PathAndId(String.valueOf(event.getName()),
id);
+                    try
+                    {
+                        return context.getWriter().writeValueAsString(pathAndId);
+                    }
+                    catch ( IOException e )
+                    {
+                        log.error("Could not serialize PathAndId", e);
+                    }
+                    return "{}";
+                }
+
+                @Override
+                protected String getDetails(CuratorEvent event)
+                {
+                    if ( event.getResultCode() != 0 )
+                    {
+                        return super.getDetails(event);
+                    }
+                    return id;
+                }
+            };
+            builder = castBuilder(builder, Backgroundable.class).inBackground(backgroundCallback);
+*/
+        }
+
+        return String.valueOf(castBuilder(builder, PathAndBytesable.class).forPath(createSpec.getPath(),
createSpec.getData().getBytes()));
+    }
+
+    private org.apache.zookeeper.CreateMode getRealMode(CreateMode mode)
+    {
+        switch ( mode )
+        {
+            case PERSISTENT:
+            {
+                return org.apache.zookeeper.CreateMode.PERSISTENT;
+            }
+
+            case PERSISTENT_SEQUENTIAL:
+            {
+                return org.apache.zookeeper.CreateMode.PERSISTENT_SEQUENTIAL;
+            }
+
+            case EPHEMERAL:
+            {
+                return org.apache.zookeeper.CreateMode.EPHEMERAL;
+            }
+
+            case EPHEMERAL_SEQUENTIAL:
+            {
+                return org.apache.zookeeper.CreateMode.EPHEMERAL_SEQUENTIAL;
+            }
+        }
+        throw new UnsupportedOperationException("Bad mode: " + mode.toString());
+    }
+
+    private CuratorFramework getClient(CuratorProjection projection) throws Exception
+    {
+        CuratorFramework client = projections.get(projection.getId());
+        if ( client == null )
+        {
+            throw new Exception("No client found with id: " + projection.getId());
+        }
+        return client;
+    }
+
+    private static <T> T castBuilder(Object createBuilder, Class<T> clazz) throws
Exception
+    {
+        if ( clazz.isAssignableFrom(createBuilder.getClass()) )
+        {
+            return clazz.cast(createBuilder);
+        }
+        throw new Exception("That operation is not available"); // TODO
+    }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/10e52ad0/curator-x-rpc/src/main/scripts/generate.sh
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/scripts/generate.sh b/curator-x-rpc/src/main/scripts/generate.sh
index ae3d575..b094336 100755
--- a/curator-x-rpc/src/main/scripts/generate.sh
+++ b/curator-x-rpc/src/main/scripts/generate.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-if (( $# != 1 )); then
-    echo "missing argument: path to swift2thrift-generator-cli-N.N.N-standalone.jar"
+if (( $# != 2 )); then
+    echo "usage:\ngenerate.sh <path to swift2thrift-generator-cli-N.N.N-standalone.jar>
<path to zookeeper-N.N.N.jar>"
     exit
 fi
 
@@ -10,11 +10,16 @@ BASE_DIR="$( cd "$DIR/../../../.." && pwd )"
 
 RPC_PATH="$BASE_DIR/curator-x-rpc/target/classes"
 CLASSES=""
-for f in `ls -m1 $RPC_PATH/org/apache/curator/x/rpc/idl/*.class | xargs -n 1 basename | sed
s/\.[^\.]*$//`; do CLASSES="$CLASSES $f"; done;
+for f in `ls -m1 $RPC_PATH/org/apache/curator/x/rpc/idl/*.class | xargs -n 1 basename | sed
s/\.[^\.]*$//`;
+    do
+        if [[ $f != *[\$]* ]]; then
+            CLASSES="$CLASSES $f";
+        fi;
+done;
 
 THRIFT_DIR="$BASE_DIR/curator-x-rpc/src/main/thrift"
 
-PATHS="$1"
+PATHS="$1:$2"
 PATHS="$PATHS:$BASE_DIR/curator-client/target/classes"
 PATHS="$PATHS:$BASE_DIR/curator-framework/target/classes"
 PATHS="$PATHS:$BASE_DIR/curator-recipes/target/classes"

http://git-wip-us.apache.org/repos/asf/curator/blob/10e52ad0/curator-x-rpc/src/main/thrift/curator.thrift
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/thrift/curator.thrift b/curator-x-rpc/src/main/thrift/curator.thrift
index 754002f..5662949 100644
--- a/curator-x-rpc/src/main/thrift/curator.thrift
+++ b/curator-x-rpc/src/main/thrift/curator.thrift
@@ -2,6 +2,20 @@ namespace java.swift org.apache.curator.x.rpc.idl
 namespace cpp org.apache.curator
 
 
+enum CreateMode {
+  PERSISTENT, PERSISTENT_SEQUENTIAL, EPHEMERAL, EPHEMERAL_SEQUENTIAL
+}
+
+struct CreateSpec {
+  1: string path;
+  2: string asyncId;
+  3: string data;
+  4: CreateMode mode;
+  5: bool async;
+  6: bool compressed;
+  7: bool creatingParentsIfNeeded;
+  8: bool withProtection;
+}
 
 struct CuratorProjection {
   1: string id;


Mime
View raw message