Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into virgil-rest-handler

  • Loading branch information...
commit 4ee1981f977c274fe1e87199d0dc5486aa34ece7 2 parents e07787f + 430c51b
Nate McCall authored
Showing with 1,255 additions and 569 deletions.
  1. +3 −0  README.md
  2. +10 −26 src/main/java/org/usergrid/vx/client/IntraClient2.java
  3. +23 −86 src/main/java/org/usergrid/vx/experimental/IntraHandlerJson.java
  4. +4 −1 src/main/java/org/usergrid/vx/experimental/IntraService.java
  5. +10 −6 src/main/java/org/usergrid/vx/experimental/IntraState.java
  6. +2 −2 src/main/java/org/usergrid/vx/experimental/Operations.java
  7. +122 −108 src/main/java/org/usergrid/vx/handler/http/OperationsRequestHandler.java
  8. +82 −54 src/main/java/org/usergrid/vx/server/IntravertCassandraServer.java
  9. +21 −0 src/main/java/org/usergrid/vx/server/operations/AutotimestampHandler.java
  10. +31 −0 src/main/java/org/usergrid/vx/server/operations/ComponentSelectHandler.java
  11. +21 −0 src/main/java/org/usergrid/vx/server/operations/ConsistencyHandler.java
  12. +43 −0 src/main/java/org/usergrid/vx/server/operations/CounterHandler.java
  13. +45 −0 src/main/java/org/usergrid/vx/server/operations/CreateFilterHandler.java
  14. +32 −0 src/main/java/org/usergrid/vx/server/operations/FilterHandler.java
  15. +36 −0 src/main/java/org/usergrid/vx/server/operations/FilterModeHandler.java
  16. +44 −59 src/main/java/org/usergrid/vx/server/operations/GetHandler.java
  17. +114 −25 src/main/java/org/usergrid/vx/server/operations/HandlerUtils.java
  18. +51 −0 src/main/java/org/usergrid/vx/server/operations/ReadHandler.java
  19. +9 −15 src/main/java/org/usergrid/vx/server/operations/SetHandler.java
  20. +43 −57 src/main/java/org/usergrid/vx/server/operations/SliceHandler.java
  21. +252 −0 src/main/resources/eclipseUima_code_style_prefs.xml
  22. +86 −83 src/test/java/org/usergrid/vx/experimental/IntraServiceITest.java
  23. +59 −11 src/test/java/org/usergrid/vx/experimental/RawJsonITest.java
  24. +39 −0 src/test/resources/org/usergrid/vx/experimental/counter_get.json
  25. +14 −0 src/test/resources/org/usergrid/vx/experimental/counter_get_response.json
  26. +22 −0 src/test/resources/org/usergrid/vx/experimental/counter_set.json
  27. +1 −2  src/test/resources/org/usergrid/vx/experimental/cql.json
  28. +34 −34 src/test/resources/org/usergrid/vx/experimental/filter_beers.json
  29. +2 −0  src/test/resources/org/usergrid/vx/experimental/filter_beers_response.json
3  README.md
View
@@ -16,6 +16,9 @@ Intravert is more then an RPC library, query language, or transport for Cassandr
* No more dealing with byte[] or ByteBuffers. Intravert lets users work with simple familiar objects like String or Integer. See [Types and Composites](https://github.com/zznate/intravert-ug/wiki/Composites).
## Motivations
+
+From an application standpoint, if you can't do sparse, wide rows, you break compatibility with 90% of Cassandra applications. So that rules out almost everything; if you can't provide the same data model, you're creating fragmentation, not pluggability.
+
Intravert was conceived of and designed by long time users of Cassandra who have written numerous real-world applications built on the existing Thrift API.
This API had it's warts for sure, but it was felt among us that the direction of the Cassandra project with regards to the introduction of CQL sidestepped some of the core reasons we chose Cassandra in the first place.
36 src/main/java/org/usergrid/vx/client/IntraClient2.java
View
@@ -1,18 +1,5 @@
package org.usergrid.vx.client;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.smile.SmileFactory;
import org.slf4j.Logger;
@@ -27,6 +14,10 @@
import org.vertx.java.core.http.HttpClientRequest;
import org.vertx.java.core.http.HttpClientResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.concurrent.CountDownLatch;
+
public class IntraClient2 {
private static Logger logger = LoggerFactory.getLogger(IntraClient.class);
private Vertx vertx;
@@ -43,12 +34,13 @@
public IntraClient2(String host,int port){
vertx = Vertx.newVertx();
- httpClient = vertx.createHttpClient().setHost("localhost")
- .setPort(8080).setMaxPoolSize(10).setKeepAlive(true);
+ httpClient = vertx.createHttpClient().setHost(host)
+ .setPort(port).setMaxPoolSize(10).setKeepAlive(true);
setTransport(Transport.JSON);
}
public IntraRes sendBlocking(IntraReq i) throws Exception {
+ final Buffer buffer = new Buffer();
final Buffer outRequest = new Buffer();
OutputStream st = new OutputStream(){
@Override
@@ -78,7 +70,7 @@ public void close() throws IOException {
};
mapper.writeValue( st, i);
final CountDownLatch doneSignal = new CountDownLatch(1);
- final AtomicReference<IntraRes> ref = new AtomicReference<IntraRes>();
+
HttpClientRequest req = httpClient.request(METHOD,
endpoint, new Handler<HttpClientResponse>() {
@@ -87,15 +79,7 @@ public void handle(HttpClientResponse resp) {
resp.dataHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer arg0) {
- IntraRes ir = null;
- try {
- ir = mapper.readValue(arg0.getBytes(), IntraRes.class);
- } catch (IOException e) {
- //TODO how do we signal exception
- //countdown on failed as well
- //e.printStackTrace();
- }
- ref.set(ir);
+ buffer.appendBuffer(arg0);
}
});
@@ -112,7 +96,7 @@ protected void handle() {
req.putHeader(CONTENT_LENGTH, outRequest.length());
req.end(outRequest);
doneSignal.await();
- return ref.get();
+ return mapper.readValue(buffer.getBytes(), IntraRes.class);
}
public Transport getTransport() {
109 src/main/java/org/usergrid/vx/experimental/IntraHandlerJson.java
View
@@ -15,113 +15,50 @@
*/
package org.usergrid.vx.experimental;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.ReentrantLock;
-
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.codehaus.jackson.map.ObjectMapper;
-import org.usergrid.vx.handler.http.OperationsRequestHandler;
-import org.usergrid.vx.handler.http.TimeoutHandler;
import org.vertx.java.core.Handler;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.http.HttpServerRequest;
-import org.vertx.java.core.json.JsonArray;
import org.vertx.java.core.json.JsonObject;
+import static org.jboss.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
+
public class IntraHandlerJson implements Handler<HttpServerRequest>{
- static IntraService is = new IntraService();
static ObjectMapper mapper = new ObjectMapper();
-
private Vertx vertx;
- public IntraHandlerJson(Vertx vertx){
+ public IntraHandlerJson(Vertx vertx) {
super();
- this.vertx=vertx;
- registerRequestHandler();
+ this.vertx = vertx;
}
@Override
public void handle(final HttpServerRequest request) {
- request.bodyHandler( new Handler<Buffer>() {
- public void handle(Buffer buffer) {
- /*
- * time to rip band aid
- boolean asyncRequestsEnabled = Boolean.valueOf(
- System.getProperty("async-requests-enabled", "false"));
-
- if (asyncRequestsEnabled || true) {
- handleRequestAsync(request, buffer);
- } else {
- handleRequest(request, buffer);
- }
- */
- handleRequestAsync(request, buffer);
- }
- });
+ request.bodyHandler(new Handler<Buffer>() {
+ public void handle(Buffer buffer) {
+ handleRequestAsync(request, buffer);
+ }
+ });
}
- private void handleRequest(HttpServerRequest request, Buffer buffer) {
- IntraRes res = new IntraRes();
- IntraReq req = null;
- try {
- req = mapper.readValue(buffer.getBytes(), IntraReq.class);
- } catch (IOException e) {
- e.printStackTrace();
+ private void handleRequestAsync(final HttpServerRequest request, Buffer buffer) {
+ IntraReq req = null;
+ try {
+ req = mapper.readValue(buffer.getBytes(), IntraReq.class);
+ vertx.eventBus().send("request.json", req.toJson(), new Handler<Message<JsonObject>>() {
+ @Override
+ public void handle(Message<JsonObject> event) {
+ request.response.end(event.body.toString());
}
- is.handleIntraReq(req,res,vertx);
- String value = null;
- try {
- value = mapper.writeValueAsString(res);
- } catch (IOException e) {
- e.printStackTrace();
- }
- request.response.end(value);
- }
-
- private void handleRequestAsync(final HttpServerRequest request, Buffer buffer) {
- IntraReq req = null;
- try {
- req = mapper.readValue(buffer.getBytes(), IntraReq.class);
- } catch (IOException e) {
- e.printStackTrace();
- }
- vertx.eventBus().send("request.json", req.toJson(), new Handler<Message<JsonObject>>() {
- @Override
- public void handle(Message<JsonObject> event) {
- request.response.end(event.body.toString());
- }
- });
- }
-
- private void registerRequestHandler() {
- vertx.eventBus().registerHandler("request.json", new Handler<Message<JsonObject>>() {
- @Override
- public void handle(Message<JsonObject> event) {
- AtomicInteger idGenerator = new AtomicInteger(0);
- JsonArray operations = event.body.getArray("e");
- JsonObject operation = (JsonObject) operations.get(idGenerator.get());
- operation.putNumber("id", idGenerator.get());
- operation.putObject("state", new JsonObject()
- .putArray("components", new JsonArray()
- .add("name")
- .add("value")));
- idGenerator.incrementAndGet();
-
- OperationsRequestHandler operationsRequestHandler = new OperationsRequestHandler(idGenerator,
- operations, event, vertx);
- TimeoutHandler timeoutHandler = new TimeoutHandler(operationsRequestHandler);
- long timerId = vertx.setTimer(10000, timeoutHandler);
- operationsRequestHandler.setTimerId(timerId);
-
- vertx.eventBus().send("request." + operation.getString("type").toLowerCase(), operation,
- operationsRequestHandler);
- }
- });
+ });
+ } catch (Exception e) {
+ request.response.statusCode = BAD_REQUEST.getCode();
+ request.response.end(ExceptionUtils.getFullStackTrace(e));
}
+ }
}
5 src/main/java/org/usergrid/vx/experimental/IntraService.java
View
@@ -33,6 +33,7 @@
import org.apache.cassandra.db.marshal.Int32Type;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.vertx.java.core.Vertx;
+import org.vertx.java.core.json.JsonArray;
public class IntraService {
@@ -82,7 +83,9 @@ public Boolean call() throws Exception {
// TODO remove unused method params
public static Object resolveObject(Object o, IntraReq req, IntraRes res,IntraState state, int i){
- if (o instanceof Object[]){
+ if (o instanceof JsonArray){
+ return ((JsonArray) o).toArray();
+ } else if (o instanceof Object[]){
return o;
} else if (o instanceof Integer){
return o;
16 src/main/java/org/usergrid/vx/experimental/IntraState.java
View
@@ -15,17 +15,17 @@
*/
package org.usergrid.vx.experimental;
+import org.apache.cassandra.db.ConsistencyLevel;
+import org.usergrid.vx.experimental.filter.Filter;
+import org.usergrid.vx.experimental.scan.ScanContext;
+import org.usergrid.vx.experimental.scan.ScanFilter;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.cassandra.db.ConsistencyLevel;
-import org.usergrid.vx.experimental.filter.Filter;
-import org.usergrid.vx.experimental.scan.ScanContext;
-import org.usergrid.vx.experimental.scan.ScanFilter;
-
/* class that holds properties for the request lifecycle */
public class IntraState {
@@ -47,7 +47,7 @@ public IntraState(){
Map<IntraMetaData,String> meta = new HashMap<IntraMetaData,String>();
//TODO separate per/request state from application/session state
static Map<String,Processor> processors = new HashMap<String,Processor>();
- static Map<String,Filter> filters = new HashMap<String,Filter>();
+ public static Map<String,Filter> filters = new HashMap<String,Filter>();
static Map<String,MultiProcessor> multiProcessors = new HashMap<String,MultiProcessor>();
static Map<String,ServiceProcessor> serviceProcessors = new HashMap<String,ServiceProcessor>();
Filter currentFilter;
@@ -79,4 +79,8 @@ public int openScanner(ScanContext context) {
openedScanners.put(id, context);
return id;
}
+
+ public ConsistencyLevel getConsistency() {
+ return consistency;
+ }
}
4 src/main/java/org/usergrid/vx/experimental/Operations.java
View
@@ -74,8 +74,8 @@ public static IntraOp setColumnFamilyOp(String columnFamily){
.set(COLUMN_FAMILY, columnFamily);
}
- public static IntraOp setAutotimestampOp(){
- return new IntraOp(IntraOp.Type.AUTOTIMESTAMP);
+ public static IntraOp setAutotimestampOp(boolean on){
+ return new IntraOp(IntraOp.Type.AUTOTIMESTAMP).set("autotimestamp", on);
}
public static IntraOp setOp(Object rowkey, Object columnName, Object columnValue){
230 src/main/java/org/usergrid/vx/handler/http/OperationsRequestHandler.java
View
@@ -1,136 +1,150 @@
package org.usergrid.vx.handler.http;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.ReentrantLock;
-
-
import org.vertx.java.core.Handler;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.json.JsonArray;
import org.vertx.java.core.json.JsonObject;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.ReentrantLock;
+
public class OperationsRequestHandler implements Handler<Message<JsonObject>> {
- private AtomicInteger idGenerator;
+ private AtomicInteger idGenerator;
- private JsonArray operations;
+ private JsonArray operations;
- private Message<JsonObject> originalMessage;
+ private Message<JsonObject> originalMessage;
- private JsonObject results;
+ private JsonObject results;
- private JsonObject state;
+ private JsonObject state;
- private boolean timedOut = false;
+ private boolean timedOut = false;
- private ReentrantLock timeoutLock = new ReentrantLock();
+ private ReentrantLock timeoutLock = new ReentrantLock();
- private long timerId;
-
- //TODO static ?
- private Vertx vertx;
+ private long timerId;
- public OperationsRequestHandler(AtomicInteger idGenerator, JsonArray operations,
- Message<JsonObject> originalMessage, Vertx vertx) {
- this.idGenerator = idGenerator;
- this.operations = operations;
- this.originalMessage = originalMessage;
- this.vertx = vertx;
+ //TODO static ?
+ private Vertx vertx;
- results = new JsonObject();
- results.putObject("opsRes", new JsonObject());
- results.putString("exception", null);
- results.putString("exceptionId", null);
+ public OperationsRequestHandler(AtomicInteger idGenerator, JsonArray operations,
+ Message<JsonObject> originalMessage, Vertx vertx) {
+ this.idGenerator = idGenerator;
+ this.operations = operations;
+ this.originalMessage = originalMessage;
+ this.vertx = vertx;
- state = new JsonObject();
- }
+ results = new JsonObject();
+ results.putObject("opsRes", new JsonObject());
+ results.putString("exception", null);
+ results.putString("exceptionId", null);
- public void setTimerId(long timerId) {
- this.timerId = timerId;
- }
+ state = new JsonObject();
+ }
+
+ public void setTimerId(long timerId) {
+ this.timerId = timerId;
+ }
+
+ @Override
+ public void handle(Message<JsonObject> event) {
+ vertx.cancelTimer(timerId);
+
+ Integer currentId = idGenerator.get();
+ Integer opId = currentId - 1;
- @Override
- public void handle(Message<JsonObject> event) {
- vertx.cancelTimer(timerId);
-
- Integer currentId = idGenerator.get();
- Integer opId = currentId - 1;
-
- String exceptionId = event.body.getString("exceptionId");
- String exception = event.body.getString("exception");
-
- if (exception != null || exceptionId != null) {
- results.putString("exception", exception);
- results.putString("exceptionId", exceptionId);
-
- sendResults();
- }
-
- Map<String, Object> map = event.body.toMap();
- Object opResult = map.get(opId.toString());
-
- // Doing the instanceof check here sucks but there are two reasons why it is
- // here at least for now. First, with this refactoring I do not want to change
- // behavior. To the greatest extent possible, I want integration tests to pass
- // as is. Secondly, I do not want to duplicate logic across each operation
- // handler. So far the operation handler does not need to worry about the
- // format of the response that is sent back to the client. That is done here.
- // The operation handler just provides its own specific response that is keyed
- // off of its operation id.
- //
- // John Sanda
- if (opResult instanceof String) {
- results.getObject("opsRes").putString(opId.toString(), (String) opResult);
- } else if (opResult instanceof Number) {
- results.getObject("opsRes").putNumber(opId.toString(), (Number) opResult);
- } else if (opResult instanceof JsonObject) {
- results.getObject("opsRes").putObject(opId.toString(), (JsonObject) opResult);
- } else if (opResult instanceof List) {
- results.getObject("opsRes").putArray(opId.toString(), new JsonArray((List) opResult));
- } else {
- throw new IllegalArgumentException(opResult.getClass() + " is not a supported result type");
- }
-
- if (idGenerator.get() < operations.size()) {
- JsonObject operation = (JsonObject) operations.get(idGenerator.get());
- operation.putNumber("id", idGenerator.get());
-
- if (event.body.getObject("state") != null) {
- state.mergeIn(event.body.getObject("state"));
- }
- operation.putObject("state", state.copy());
- idGenerator.incrementAndGet();
- TimeoutHandler timeoutHandler = new TimeoutHandler(this);
- timerId = vertx.setTimer(10000, timeoutHandler);
- vertx.eventBus().send("request." + operation.getString("type").toLowerCase(), operation, this);
- } else {
- sendResults();
- }
+ String exceptionId = event.body.getString("exceptionId");
+ String exception = event.body.getString("exception");
+
+ if (exception != null || exceptionId != null) {
+ results.putString("exception", exception);
+ results.putString("exceptionId", exceptionId);
+
+ sendResults();
}
- private void sendResults() {
- try {
- timeoutLock.lock();
- if (!timedOut) {
- originalMessage.reply(results);
- }
- } finally {
- timeoutLock.unlock();
- }
+ Map<String, Object> map = event.body.toMap();
+ Object opResult = map.get(opId.toString());
+
+ // Doing the instanceof check here sucks but there are two reasons why it is
+ // here at least for now. First, with this refactoring I do not want to change
+ // behavior. To the greatest extent possible, I want integration tests to pass
+ // as is. Secondly, I do not want to duplicate logic across each operation
+ // handler. So far the operation handler does not need to worry about the
+ // format of the response that is sent back to the client. That is done here.
+ // The operation handler just provides its own specific response that is keyed
+ // off of its operation id.
+ //
+ // John Sanda
+ if (opResult instanceof String) {
+ results.getObject("opsRes").putString(opId.toString(), (String) opResult);
+ } else if (opResult instanceof Number) {
+ results.getObject("opsRes").putNumber(opId.toString(), (Number) opResult);
+ } else if (opResult instanceof JsonObject) {
+ results.getObject("opsRes").putObject(opId.toString(), (JsonObject) opResult);
+ } else if (opResult instanceof List) {
+ results.getObject("opsRes").putArray(opId.toString(), new JsonArray((List) opResult));
+ } else {
+ throw new IllegalArgumentException(opResult.getClass() + " is not a supported result type");
}
- public void timeout() {
- try {
- timeoutLock.lock();
- timedOut = true;
- results.putString("exception", "Operation timed out.");
- results.putString("exceptionId", Integer.toString(idGenerator.get() - 1));
- originalMessage.reply(results);
- } finally {
- timeoutLock.unlock();
- }
+ if (idGenerator.get() < operations.size()) {
+ JsonObject operation = (JsonObject) operations.get(idGenerator.get());
+ operation.putNumber("id", idGenerator.get());
+
+ Long timeout = getOperationTimeout(operation);
+
+ if (event.body.getObject("state") != null) {
+ state.mergeIn(event.body.getObject("state"));
+ }
+ operation.putObject("state", state.copy());
+ idGenerator.incrementAndGet();
+ TimeoutHandler timeoutHandler = new TimeoutHandler(this);
+ timerId = vertx.setTimer(timeout, timeoutHandler);
+ vertx.eventBus().send("request." + operation.getString("type").toLowerCase(), operation, this);
+ } else {
+ sendResults();
+ }
+ }
+
+ // This method is currently duplicated in IntraHandlerJson. We could move it to
+ // HandlerUtils but I am holding off for now because if/when we start using strongly
+ // typed objects again for the request, response, etc., this method would make sense
+ // as a property if a parameters object if a such a class is introduced.
+ private Long getOperationTimeout(JsonObject operation) {
+ JsonObject params = operation.getObject("op");
+ Long timeout = params.getLong("timeout");
+ if (timeout == null) {
+ timeout = 10000L;
+ }
+ return timeout;
+ }
+
+ private void sendResults() {
+ try {
+ timeoutLock.lock();
+ if (!timedOut) {
+ originalMessage.reply(results);
+ }
+ } finally {
+ timeoutLock.unlock();
+ }
+ }
+
+ public void timeout() {
+ try {
+ timeoutLock.lock();
+ timedOut = true;
+ results.putString("exception", "Operation timed out.");
+ results.putString("exceptionId", Integer.toString(idGenerator.get() - 1));
+ originalMessage.reply(results);
+ } finally {
+ timeoutLock.unlock();
}
+ }
}
136 src/main/java/org/usergrid/vx/server/IntravertCassandraServer.java
View
@@ -12,11 +12,9 @@
* 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.usergrid.vx.server;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import org.apache.cassandra.service.CassandraDaemon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -24,72 +22,102 @@
import org.usergrid.vx.experimental.IntraHandlerJsonSmile;
import org.usergrid.vx.handler.http.HelloHandler;
import org.usergrid.vx.handler.http.NoMatchHandler;
-import org.usergrid.vx.server.operations.AssumeHandler;
-import org.usergrid.vx.server.operations.CqlQueryHandler;
-import org.usergrid.vx.server.operations.CreateColumnFamilyHandler;
-import org.usergrid.vx.server.operations.CreateKeyspaceHandler;
-import org.usergrid.vx.server.operations.GetHandler;
-import org.usergrid.vx.server.operations.ListKeyspacesHandler;
-import org.usergrid.vx.server.operations.SetColumnFamilyHandler;
-import org.usergrid.vx.server.operations.SetHandler;
-import org.usergrid.vx.server.operations.SetKeyspaceHandler;
-import org.usergrid.vx.server.operations.SliceHandler;
+import org.usergrid.vx.handler.http.OperationsRequestHandler;
+import org.usergrid.vx.handler.http.TimeoutHandler;
+import org.usergrid.vx.server.operations.*;
+import org.vertx.java.core.Handler;
import org.vertx.java.core.Vertx;
+import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.http.RouteMatcher;
+import org.vertx.java.core.json.JsonArray;
+import org.vertx.java.core.json.JsonObject;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
public class IntravertCassandraServer implements CassandraDaemon.Server {
-
- private final Logger logger = LoggerFactory.getLogger(IntravertCassandraServer.class);
- private static Vertx vertx;
- private static RouteMatcher rm;
+
+ private final Logger logger = LoggerFactory.getLogger(IntravertCassandraServer.class);
+ private static Vertx vertx;
+ private static RouteMatcher rm;
private static IntravertClusterNotifier intravertClusterNotifier;
private static final AtomicBoolean running = new AtomicBoolean(false);
-
- @Override
- public void start() {
- logger.debug("Starting IntravertCassandraServer...");
- // TODO may be more appropriate in setup() ?
- vertx = Vertx.newVertx();
-
- rm = new RouteMatcher();
- rm.put("/:appid/hello", new HelloHandler());
- rm.get("/:appid/hello", new HelloHandler());
- rm.post("/:appid/hello", new HelloHandler());
- rm.post("/:appid/intrareq-json", new IntraHandlerJson(vertx));
- rm.post("/:appid/intrareq-jsonsmile", new IntraHandlerJsonSmile(vertx));
- rm.noMatch(new NoMatchHandler());
-
- registerOperationHandlers();
- vertx.createHttpServer().requestHandler(rm).listen(8080);
- logger.info("IntravertCassandraServer started.");
+ @Override
+ public void start() {
+ logger.debug("Starting IntravertCassandraServer...");
+ vertx = Vertx.newVertx();
+ rm = new RouteMatcher();
+ rm.put("/:appid/hello", new HelloHandler());
+ rm.get("/:appid/hello", new HelloHandler());
+ rm.post("/:appid/hello", new HelloHandler());
+ rm.post("/:appid/intrareq-json", new IntraHandlerJson(vertx));
+ rm.post("/:appid/intrareq-jsonsmile", new IntraHandlerJsonSmile(vertx));
+ rm.noMatch(new NoMatchHandler());
+ registerOperationHandlers(vertx);
+ registerRequestHandler(vertx);
+ vertx.createHttpServer().requestHandler(rm).listen(8080);
+ logger.info("IntravertCassandraServer started.");
running.set(true);
intravertClusterNotifier = IntravertClusterNotifier.forServer(vertx);
- }
-
- @Override
- public void stop() {
- boolean stopped = running.compareAndSet(true,false);
- logger.info("stopServer...{}", stopped);
+ }
- }
+ @Override
+ public void stop() {
+ boolean stopped = running.compareAndSet(true, false);
+ logger.info("stopServer...{}", stopped);
+ }
@Override
public boolean isRunning() {
return running.get();
}
- private void registerOperationHandlers() {
- vertx.eventBus().registerHandler("request.createkeyspace", new CreateKeyspaceHandler());
- vertx.eventBus().registerHandler("request.setkeyspace", new SetKeyspaceHandler());
- vertx.eventBus().registerHandler("request.createcolumnfamily", new CreateColumnFamilyHandler());
- vertx.eventBus().registerHandler("request.listkeyspaces", new ListKeyspacesHandler());
- vertx.eventBus().registerHandler("request.set", new SetHandler());
- vertx.eventBus().registerHandler("request.setcolumnfamily", new SetColumnFamilyHandler());
- vertx.eventBus().registerHandler("request.assume", new AssumeHandler());
- vertx.eventBus().registerHandler("request.get", new GetHandler());
- vertx.eventBus().registerHandler("request.slice", new SliceHandler());
- vertx.eventBus().registerHandler("request.cqlquery", new CqlQueryHandler());
- }
+ public static void registerRequestHandler(final Vertx x) {
+ x.eventBus().registerHandler("request.json", new Handler<Message<JsonObject>>() {
+ @Override
+ public void handle(Message<JsonObject> event) {
+ AtomicInteger idGenerator = new AtomicInteger(0);
+ JsonArray operations = event.body.getArray("e");
+ JsonObject operation = (JsonObject) operations.get(idGenerator.get());
+ Long timeout = HandlerUtils.getOperationTime(operation);
+
+ operation.putNumber("id", idGenerator.get());
+ operation.putObject("state", new JsonObject()
+ .putArray("components", new JsonArray()
+ .add("name")
+ .add("value")));
+ idGenerator.incrementAndGet();
+
+ OperationsRequestHandler operationsRequestHandler = new OperationsRequestHandler(idGenerator,
+ operations, event, x);
+ TimeoutHandler timeoutHandler = new TimeoutHandler(operationsRequestHandler);
+ long timerId = x.setTimer(timeout, timeoutHandler);
+ operationsRequestHandler.setTimerId(timerId);
+
+ x.eventBus().send("request." + operation.getString("type").toLowerCase(), operation,
+ operationsRequestHandler);
+ }
+ });
+ }
+
+ public static void registerOperationHandlers(Vertx x) {
+ x.eventBus().registerHandler("request.autotimestamp", new AutotimestampHandler() );
+ x.eventBus().registerHandler("request.componentselect", new ComponentSelectHandler() );
+ x.eventBus().registerHandler("request.createkeyspace", new CreateKeyspaceHandler());
+ x.eventBus().registerHandler("request.setkeyspace", new SetKeyspaceHandler());
+ x.eventBus().registerHandler("request.createcolumnfamily", new CreateColumnFamilyHandler());
+ x.eventBus().registerHandler("request.listkeyspaces", new ListKeyspacesHandler());
+ x.eventBus().registerHandler("request.set", new SetHandler());
+ x.eventBus().registerHandler("request.setcolumnfamily", new SetColumnFamilyHandler());
+ x.eventBus().registerHandler("request.assume", new AssumeHandler());
+ x.eventBus().registerHandler("request.get", new GetHandler(x.eventBus()));
+ x.eventBus().registerHandler("request.slice", new SliceHandler(x.eventBus()));
+ x.eventBus().registerHandler("request.cqlquery", new CqlQueryHandler());
+ x.eventBus().registerHandler("request.counter", new CounterHandler());
+ x.eventBus().registerHandler("request.consistency", new ConsistencyHandler());
+ x.eventBus().registerHandler("request.createfilter", new CreateFilterHandler(x.eventBus()));
+ x.eventBus().registerHandler("request.filtermode", new FilterModeHandler());
+ }
}
21 src/main/java/org/usergrid/vx/server/operations/AutotimestampHandler.java
View
@@ -0,0 +1,21 @@
+package org.usergrid.vx.server.operations;
+
+import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.Message;
+import org.vertx.java.core.json.JsonObject;
+
+public class AutotimestampHandler implements Handler<Message<JsonObject>>{
+
+ @Override
+ public void handle(Message<JsonObject> event) {
+ Integer id = event.body.getInteger("id");
+ JsonObject params = event.body.getObject("op");
+ JsonObject state = event.body.getObject("state");
+ state.putBoolean("autotimestamp", params.getBoolean("autotimestamp"));
+ event.reply(new JsonObject()
+ .putString(id.toString(), "OK")
+ .putObject("state", state)
+ );
+ }
+
+}
31 src/main/java/org/usergrid/vx/server/operations/ComponentSelectHandler.java
View
@@ -0,0 +1,31 @@
+package org.usergrid.vx.server.operations;
+
+import java.util.Set;
+
+import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.Message;
+import org.vertx.java.core.json.JsonObject;
+
+public class ComponentSelectHandler implements Handler<Message<JsonObject>>{
+
+ /*
+ Set<String> parts = (Set<String>) op.getOp().get("components");
+ state.components = parts;
+ */
+
+ @Override
+ public void handle(Message<JsonObject> event) {
+ Integer id = event.body.getInteger("id");
+ JsonObject params = event.body.getObject("op");
+ JsonObject state = event.body.getObject("state");
+ //state.putBoolean("autotimestamp", params.getBoolean("autotimestamp"));
+ System.out.println ("components is "+params.getArray("components"));
+ state.putArray("components", params.getArray("components"));
+ event.reply(new JsonObject()
+ .putString(id.toString(), "OK")
+ .putObject("state", state)
+ );
+
+ }
+
+}
21 src/main/java/org/usergrid/vx/server/operations/ConsistencyHandler.java
View
@@ -0,0 +1,21 @@
+package org.usergrid.vx.server.operations;
+
+import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.Message;
+import org.vertx.java.core.json.JsonObject;
+/*
+ * The consistency verb changes the consistency level of the state.
+ */
+public class ConsistencyHandler implements Handler<Message<JsonObject>> {
+
+ @Override
+ public void handle(Message<JsonObject> event) {
+ Integer id = event.body.getInteger("id");
+ JsonObject params = event.body.getObject("op");
+ JsonObject state = event.body.getObject("state");
+ state.putString("consistency", params.getString("level") );
+ event.reply(new JsonObject().putString(id.toString(), "OK").putObject(
+ "state", state));
+ }
+
+}
43 src/main/java/org/usergrid/vx/server/operations/CounterHandler.java
View
@@ -0,0 +1,43 @@
+package org.usergrid.vx.server.operations;
+
+import org.apache.cassandra.db.ConsistencyLevel;
+import org.apache.cassandra.db.CounterMutation;
+import org.apache.cassandra.db.IMutation;
+import org.apache.cassandra.db.RowMutation;
+import org.apache.cassandra.db.filter.QueryPath;
+import org.usergrid.vx.experimental.IntraOp;
+import org.usergrid.vx.experimental.IntraService;
+import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.Message;
+import org.vertx.java.core.json.JsonObject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Handler class for counter writes
+ *
+ * @author zznate
+ */
+public class CounterHandler implements Handler<Message<JsonObject>> {
+
+ @Override
+ public void handle(Message<JsonObject> event) {
+ Integer id = event.body.getInteger("id");
+ JsonObject params = event.body.getObject("op");
+ JsonObject state = event.body.getObject("state");
+
+ RowMutation rm = new RowMutation(HandlerUtils.determineKs(params,state),
+ IntraService.byteBufferForObject(params.getString("rowkey")));
+
+ rm.addCounter(new QueryPath(
+ HandlerUtils.determineCf(params,state),
+ null,
+ IntraService.byteBufferForObject(params.getString("name"))),
+ Long.parseLong(params.toMap().get("value").toString()));
+ List<IMutation> mutations = new ArrayList(1);
+ // TODO fix hard-coded consistency
+ mutations.add(new CounterMutation(rm, ConsistencyLevel.ONE));
+ HandlerUtils.write(mutations, event, id);
+ }
+}
45 src/main/java/org/usergrid/vx/server/operations/CreateFilterHandler.java
View
@@ -0,0 +1,45 @@
+package org.usergrid.vx.server.operations;
+
+import org.usergrid.vx.experimental.IntraState;
+import org.usergrid.vx.experimental.filter.FactoryProvider;
+import org.usergrid.vx.experimental.filter.Filter;
+import org.usergrid.vx.experimental.filter.FilterFactory;
+import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.EventBus;
+import org.vertx.java.core.eventbus.Message;
+import org.vertx.java.core.json.JsonObject;
+
+public class CreateFilterHandler implements Handler<Message<JsonObject>> {
+
+ private EventBus eb;
+
+ public CreateFilterHandler(EventBus eb) {
+ this.eb = eb;
+ }
+
+ @Override
+ public void handle(Message<JsonObject> event) {
+ Integer id = event.body.getInteger("id");
+ JsonObject params = event.body.getObject("op");
+
+ String name = params.getString("name");
+ String lang = params.getString("spec");
+ String scriptSource = params.getString("value");
+
+ FactoryProvider factoryProvider = new FactoryProvider();
+ try {
+ FilterFactory filterFactory = factoryProvider.getFilterFactory(lang);
+ Filter filter = filterFactory.createFilter(scriptSource);
+ eb.registerHandler("filters." + name, new FilterHandler(filter));
+ IntraState.filters.put(name, filterFactory.createFilter(scriptSource));
+
+ event.reply(new JsonObject().putString(id.toString(), "OK"));
+ } catch (IllegalArgumentException e) {
+ event.reply(new JsonObject()
+ .putString(id.toString(), e.getClass().getName())
+ .putString("exception", e.getMessage())
+ .putString("exceptionId", id.toString()));
+ }
+ }
+
+}
32 src/main/java/org/usergrid/vx/server/operations/FilterHandler.java
View
@@ -0,0 +1,32 @@
+package org.usergrid.vx.server.operations;
+
+import org.usergrid.vx.experimental.filter.Filter;
+import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.Message;
+import org.vertx.java.core.json.JsonArray;
+import org.vertx.java.core.json.JsonObject;
+
+import java.util.Map;
+
+public class FilterHandler implements Handler<Message<JsonArray>> {
+
+ private Filter filter;
+
+ public FilterHandler(Filter filter) {
+ this.filter = filter;
+ }
+
+ @Override
+ public void handle(Message<JsonArray> event) {
+ JsonArray filteredArray = new JsonArray();
+ for (Object obj : event.body) {
+ JsonObject jsonObject = (JsonObject) obj;
+ Map filtered = filter.filter(jsonObject.toMap());
+ if (filtered != null) {
+ filteredArray.add(new JsonObject(filtered));
+ }
+ }
+ event.reply(filteredArray);
+ }
+
+}
36 src/main/java/org/usergrid/vx/server/operations/FilterModeHandler.java
View
@@ -0,0 +1,36 @@
+package org.usergrid.vx.server.operations;
+
+import org.usergrid.vx.experimental.IntraState;
+import org.usergrid.vx.experimental.filter.Filter;
+import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.Message;
+import org.vertx.java.core.json.JsonObject;
+
+public class FilterModeHandler implements Handler<Message<JsonObject>> {
+
+ @Override
+ public void handle(Message<JsonObject> event) {
+ Integer id = event.body.getInteger("id");
+ JsonObject params = event.body.getObject("op");
+ JsonObject state = event.body.getObject("state");
+
+ String filterName = params.getString("name");
+ Boolean enabled = params.getBoolean("on");
+
+ Filter filter = IntraState.filters.get(filterName);
+ if (enabled) {
+ if (filter == null) {
+ event.reply(new JsonObject()
+ .putString(id.toString(), "ERROR")
+ .putString("exception", "filter " + filterName + " not found"));
+ } else {
+ state.putString("currentFilter", filterName);
+ }
+ } else {
+ state.removeField("currentFilter");
+ }
+ event.reply(new JsonObject()
+ .putString(id.toString(), "OK")
+ .putObject("state", state));
+ }
+}
103 src/main/java/org/usergrid/vx/server/operations/GetHandler.java
View
@@ -1,76 +1,61 @@
package org.usergrid.vx.server.operations;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cassandra.db.ColumnFamily;
-import org.apache.cassandra.db.ConsistencyLevel;
-import org.apache.cassandra.db.IColumn;
-import org.apache.cassandra.db.ReadCommand;
-import org.apache.cassandra.db.Row;
-import org.apache.cassandra.db.SliceByNamesReadCommand;
+import org.apache.cassandra.db.*;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.exceptions.IsBootstrappingException;
import org.apache.cassandra.exceptions.ReadTimeoutException;
import org.apache.cassandra.exceptions.UnavailableException;
import org.apache.cassandra.service.StorageProxy;
import org.usergrid.vx.experimental.IntraService;
-import org.usergrid.vx.experimental.TypeHelper;
import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.EventBus;
import org.vertx.java.core.eventbus.Message;
-import org.vertx.java.core.json.JsonArray;
import org.vertx.java.core.json.JsonObject;
-public class GetHandler implements Handler<Message<JsonObject>> {
-
- @Override
- public void handle(Message<JsonObject> event) {
- Integer id = event.body.getInteger("id");
- JsonObject params = event.body.getObject("op");
- JsonObject state = event.body.getObject("state");
-
- Map<String, Object> paramsMap = params.toMap();
- Object rowKeyParam = paramsMap.get("rowkey");
- Object nameParam = paramsMap.get("name");
- List<Map> finalResults = new ArrayList<Map>();
-
- ByteBuffer rowkey = IntraService.byteBufferForObject(IntraService.resolveObject(rowKeyParam, null, null, null,
- id));
- ByteBuffer column = IntraService.byteBufferForObject(IntraService.resolveObject(nameParam, null, null, null,
- id));
- QueryPath path = new QueryPath(HandlerUtils.determineCf(params, state), null);
- List<ByteBuffer> nameAsList = Arrays.asList(column);
- ReadCommand command = new SliceByNamesReadCommand(HandlerUtils.determineKs(params, state), rowkey, path, nameAsList);
- List<Row> rows = null;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
- try {
- // We don't want to hard code the consistency level but letting it slide for
- // since it is also hard coded in IntraState
- rows = StorageProxy.read(Arrays.asList(command), ConsistencyLevel.ONE);
- ColumnFamily cf1 = rows.get(0).cf;
- if (cf1 == null) { // cf= null is no data
- } else {
- HandlerUtils.readCf(cf1, finalResults, state, params);
- }
+public class GetHandler implements Handler<Message<JsonObject>> {
- JsonObject response = new JsonObject();
- JsonArray array = new JsonArray();
- for (Map m : finalResults) {
- array.add(new JsonObject(m));
- }
- response.putArray(id.toString(), array);
- event.reply(response);
- } catch (ReadTimeoutException | UnavailableException | IsBootstrappingException | IOException e) {
- event.reply(new JsonObject().putString(id.toString(), e.getMessage()));
- }
+ private EventBus eb;
+
+ public GetHandler(EventBus eb) {
+ this.eb = eb;
+ }
+
+ @Override
+ public void handle(final Message<JsonObject> event) {
+ final Integer id = event.body.getInteger("id");
+ JsonObject params = event.body.getObject("op");
+ JsonObject state = event.body.getObject("state");
+
+ Map<String, Object> paramsMap = params.toMap();
+ Object rowKeyParam = paramsMap.get("rowkey");
+ Object nameParam = paramsMap.get("name");
+
+ ByteBuffer rowkey = IntraService.byteBufferForObject(IntraService.resolveObject(rowKeyParam, null, null, null,
+ id));
+ ByteBuffer column = IntraService.byteBufferForObject(IntraService.resolveObject(nameParam, null, null, null,
+ id));
+ QueryPath path = new QueryPath(HandlerUtils.determineCf(params, state), null);
+ List<ByteBuffer> nameAsList = Arrays.asList(column);
+ ReadCommand command = new SliceByNamesReadCommand(HandlerUtils.determineKs(params, state), rowkey, path, nameAsList);
+ List<Row> rows = null;
+
+ try {
+ // We don't want to hard code the consistency level but letting it slide for
+ // since it is also hard coded in IntraState
+ rows = StorageProxy.read(Arrays.asList(command), ConsistencyLevel.ONE);
+ ColumnFamily cf = rows.get(0).cf;
+
+ new ReadHandler(event, eb).handleRead(cf);
+
+ } catch (ReadTimeoutException | UnavailableException | IsBootstrappingException | IOException e) {
+ event.reply(new JsonObject().putString(id.toString(), e.getMessage()));
}
-
-
+ }
}
139 src/main/java/org/usergrid/vx/server/operations/HandlerUtils.java
View
@@ -1,15 +1,21 @@
package org.usergrid.vx.server.operations;
-import org.apache.cassandra.db.ColumnFamily;
-import org.apache.cassandra.db.IColumn;
+import org.apache.cassandra.db.*;
+import org.apache.cassandra.exceptions.OverloadedException;
+import org.apache.cassandra.exceptions.UnavailableException;
+import org.apache.cassandra.exceptions.WriteTimeoutException;
+import org.apache.cassandra.service.StorageProxy;
+import org.apache.cassandra.utils.ByteBufferUtil;
import org.usergrid.vx.experimental.TypeHelper;
+import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.EventBus;
+import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.json.JsonArray;
import org.vertx.java.core.json.JsonObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
/**
* @author zznate
@@ -36,32 +42,115 @@ public static String determineKs(JsonObject params, JsonObject state) {
return ks;
}
- public static void readCf(ColumnFamily columnFamily, List<Map> finalResults, JsonObject state, JsonObject params) {
- Iterator<IColumn> it = columnFamily.iterator();
- while (it.hasNext()) {
- IColumn ic = it.next();
- if (ic.isLive()) {
- HashMap m = new HashMap();
- JsonArray components = state.getArray("components");
+ public static JsonArray readCf(ColumnFamily columnFamily, JsonObject state, JsonObject params) {
+ JsonArray components = state.getArray("components");
+ JsonArray array = new JsonArray();
+ Iterator<IColumn> it = columnFamily.iterator();
+ while (it.hasNext()) {
+ IColumn ic = it.next();
+ if (ic.isLive()) {
+ HashMap m = new HashMap();
- if (components.contains("name")) {
- String clazz = state.getObject("meta").getObject("column").getString("clazz");
- m.put("name", TypeHelper.getTyped(clazz, ic.name()));
- }
- if (components.contains("value")) {
- String clazz = state.getObject("meta").getObject("value").getString("clazz");
- m.put("value", TypeHelper.getTyped(clazz, ic.value()));
- }
- if (components.contains("timestamp")) {
- m.put("timestamp", ic.timestamp());
- }
- if (components.contains("markeddelete")) {
- m.put("markeddelete", ic.getMarkedForDeleteAt());
- }
+ if (components.contains("name")) {
+ JsonObject columnMetadata = state.getObject("meta").getObject("column");
+ if (columnMetadata == null) {
+ m.put("name", ByteBufferUtil.getArray(ic.name()));
+ } else {
+ String clazz = columnMetadata.getString("clazz");
+ m.put("name", TypeHelper.getTyped(clazz, ic.name()));
+ }
+ }
+ if (components.contains("value")) {
+ if ( ic instanceof CounterColumn ) {
+ m.put("value", ((CounterColumn)ic).total());
+ } else {
+ JsonObject valueMetadata = state.getObject("meta").getObject("value");
+ if (valueMetadata == null) {
+ m.put("value", ByteBufferUtil.getArray(ic.value()));
+ } else {
+ String clazz = valueMetadata.getString("clazz");
+ m.put("value", TypeHelper.getTyped(clazz, ic.value()));
+ }
+ }
+ }
+ if (components.contains("timestamp")) {
+ m.put("timestamp", ic.timestamp());
+ }
+ if (components.contains("markeddelete")) {
+ m.put("markeddelete", ic.getMarkedForDeleteAt());
+ }
+ array.addObject(new JsonObject(m));
+ }
+ }
+ return array;
+ }
+
+public static void readCf(ColumnFamily columnFamily, JsonObject state, EventBus eb,
+ Handler<Message<JsonArray>> filterReplyHandler) {
+ JsonArray components = state.getArray("components");
+ JsonArray array = new JsonArray();
- finalResults.add(m);
+ for (IColumn column : columnFamily) {
+ if (column.isLive()) {
+ HashMap m = new HashMap();
+
+ if (components.contains("name")) {
+ JsonObject columnMetadata = state.getObject("meta").getObject("column");
+ if (columnMetadata == null) {
+ m.put("name", ByteBufferUtil.getArray(column.name()));
+ } else {
+ String clazz = columnMetadata.getString("clazz");
+ m.put("name", TypeHelper.getTyped(clazz, column.name()));
+ }
+ }
+ if (components.contains("value")) {
+ if (column instanceof CounterColumn ) {
+ m.put("value", ((CounterColumn)column).total());
+ } else {
+ JsonObject valueMetadata = state.getObject("meta").getObject("value");
+ if (valueMetadata == null) {
+ m.put("value", ByteBufferUtil.getArray(column.value()));
+ } else {
+ String clazz = valueMetadata.getString("clazz");
+ m.put("value", TypeHelper.getTyped(clazz, column.value()));
+ }
}
+ }
+ if (components.contains("timestamp")) {
+ m.put("timestamp", column.timestamp());
+ }
+ if (components.contains("markeddelete")) {
+ m.put("markeddelete", column.getMarkedForDeleteAt());
+ }
+ array.addObject(new JsonObject(m));
}
+ }
+
+ String filter = state.getString("currentFilter");
+ eb.send("filters." + filter, array, filterReplyHandler);
}
+ public static void write(List<IMutation> mutations, Message<JsonObject> event, Integer id) {
+ try {
+ // We don't want to hard code the consistency level but letting it slide for
+ // since it is also hard coded in IntraState
+ StorageProxy.mutate(mutations, ConsistencyLevel.ONE);
+
+ event.reply(new JsonObject().putString(id.toString(), "OK"));
+ } catch (WriteTimeoutException | UnavailableException | OverloadedException e) {
+ event.reply(new JsonObject()
+ .putString("exception", e.getMessage())
+ .putString("exceptionId", id.toString()));
+ }
+ }
+
+
+ public static Long getOperationTime(JsonObject operation) {
+ JsonObject params = operation.getObject("op");
+ Long timeout = params.getLong("timeout");
+ if (timeout == null) {
+ timeout = 10000L;
+ }
+ return timeout;
+ }
}
51 src/main/java/org/usergrid/vx/server/operations/ReadHandler.java
View
@@ -0,0 +1,51 @@
+package org.usergrid.vx.server.operations;
+
+import org.apache.cassandra.db.ColumnFamily;
+import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.EventBus;
+import org.vertx.java.core.eventbus.Message;
+import org.vertx.java.core.json.JsonArray;
+import org.vertx.java.core.json.JsonObject;
+
+public class ReadHandler {
+
+ private JsonObject params;
+
+ private JsonObject state;
+
+ private Message<JsonObject> event;
+
+ private EventBus eb;
+
+ public ReadHandler(Message<JsonObject> event, EventBus eb) {
+ this.event = event;
+ params = event.body.getObject("op");
+ state = event.body.getObject("state");
+ this.eb = eb;
+ }
+
+ public void handleRead(ColumnFamily cf) {
+ final Integer id = event.body.getInteger("id");
+ JsonArray array;
+
+ if (cf == null) {
+ event.reply(new JsonObject().putArray(id.toString(), new JsonArray()));
+ } else {
+ String filter = state.getString("currentFilter");
+ if (filter == null) {
+ array = HandlerUtils.readCf(cf, state, params);
+ JsonObject response = new JsonObject();
+ response.putArray(id.toString(), array);
+ event.reply(response);
+ } else {
+ HandlerUtils.readCf(cf, state, eb, new Handler<Message<JsonArray>>() {
+ @Override
+ public void handle(Message<JsonArray> filterEvent) {
+ event.reply(new JsonObject().putArray(id.toString(), filterEvent.body));
+ }
+ });
+ }
+ }
+ }
+
+}
24 src/main/java/org/usergrid/vx/server/operations/SetHandler.java
View
@@ -1,8 +1,11 @@
package org.usergrid.vx.server.operations;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import org.apache.cassandra.db.ConsistencyLevel;
+import org.apache.cassandra.db.IMutation;
import org.apache.cassandra.db.RowMutation;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.exceptions.OverloadedException;
@@ -21,14 +24,14 @@ public void handle(Message<JsonObject> event) {
Integer id = event.body.getInteger("id");
JsonObject params = event.body.getObject("op");
JsonObject state = event.body.getObject("state");
-
+ System.out.println(params);
RowMutation rm = new RowMutation(HandlerUtils.determineKs(params,state),
IntraService.byteBufferForObject(params.getString("rowkey")));
QueryPath qp = new QueryPath(HandlerUtils.determineCf(params,state),
null,
- IntraService.byteBufferForObject(params.getString("name")));
+ IntraService.byteBufferForObject(params.getField("name")));
- Object val = params.toMap().get("value");
+ Object val = params.getField("value");
Integer ttl = params.getInteger("ttl");
if (ttl == null) {
@@ -39,17 +42,8 @@ public void handle(Message<JsonObject> event) {
rm.add(qp, IntraService.byteBufferForObject(IntraService.resolveObject(val, null, null, null, id)),
System.nanoTime(), ttl);
}
-
- try {
- // We don't want to hard code the consistency level but letting it slide for
- // since it is also hard coded in IntraState
- StorageProxy.mutate(Arrays.asList(rm), ConsistencyLevel.ONE);
-
- event.reply(new JsonObject().putString(id.toString(), "OK"));
- } catch (WriteTimeoutException | UnavailableException | OverloadedException e) {
- event.reply(new JsonObject()
- .putString("exception", e.getMessage())
- .putString("exceptionId", id.toString()));
- }
+ List<IMutation> mutations = new ArrayList<IMutation>();
+ mutations.add(rm);
+ HandlerUtils.write(mutations, event, id);
}
}
100 src/main/java/org/usergrid/vx/server/operations/SliceHandler.java
View
@@ -1,81 +1,67 @@
package org.usergrid.vx.server.operations;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cassandra.db.ColumnFamily;
-import org.apache.cassandra.db.ConsistencyLevel;
-import org.apache.cassandra.db.IColumn;
-import org.apache.cassandra.db.ReadCommand;
-import org.apache.cassandra.db.Row;
-import org.apache.cassandra.db.SliceFromReadCommand;
+import org.apache.cassandra.db.*;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.exceptions.IsBootstrappingException;
import org.apache.cassandra.exceptions.ReadTimeoutException;
import org.apache.cassandra.exceptions.UnavailableException;
import org.apache.cassandra.service.StorageProxy;
-import org.apache.cassandra.thrift.ColumnPath;
import org.usergrid.vx.experimental.IntraService;
-import org.usergrid.vx.experimental.TypeHelper;
import org.vertx.java.core.Handler;
+import org.vertx.java.core.eventbus.EventBus;
import org.vertx.java.core.eventbus.Message;
-import org.vertx.java.core.json.JsonArray;
import org.vertx.java.core.json.JsonObject;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
public class SliceHandler implements Handler<Message<JsonObject>> {
- @Override
- public void handle(Message<JsonObject> event) {
- Integer id = event.body.getInteger("id");
- JsonObject params = event.body.getObject("op");
- JsonObject state = event.body.getObject("state");
+ private EventBus eb;
- List<Map> finalResults = new ArrayList<Map>();
- Map<String, Object> paramsMap = params.toMap();
- Object rowKeyParam = paramsMap.get("rowkey");
- Object startParam = paramsMap.get("start");
- Object endParam = paramsMap.get("end");
+ public SliceHandler(EventBus eb) {
+ this.eb = eb;
+ }
- ByteBuffer rowkey = IntraService
- .byteBufferForObject(IntraService.resolveObject(rowKeyParam, null, null, null, id));
- ByteBuffer start = IntraService.byteBufferForObject(IntraService.resolveObject(startParam, null, null, null, id));
- ByteBuffer end = IntraService.byteBufferForObject(IntraService.resolveObject(endParam, null, null, null, id));
+ @Override
+ public void handle(final Message<JsonObject> event) {
+ final Integer id = event.body.getInteger("id");
+ JsonObject params = event.body.getObject("op");
+ JsonObject state = event.body.getObject("state");
- List<ReadCommand> commands = new ArrayList<ReadCommand>(1);
+ Map<String, Object> paramsMap = params.toMap();
+ Object rowKeyParam = paramsMap.get("rowkey");
+ Object startParam = paramsMap.get("start");
+ Object endParam = paramsMap.get("end");
- QueryPath path = new QueryPath(HandlerUtils.determineCf(params, state), null);
+ ByteBuffer rowkey = IntraService
+ .byteBufferForObject(IntraService.resolveObject(rowKeyParam, null, null, null, id));
+ ByteBuffer start = IntraService.byteBufferForObject(IntraService.resolveObject(startParam, null, null, null, id));
+ ByteBuffer end = IntraService.byteBufferForObject(IntraService.resolveObject(endParam, null, null, null, id));
- SliceFromReadCommand sr = new SliceFromReadCommand(state.getString("currentKeyspace"), rowkey, path, start, end,
- false, 100);
- commands.add(sr);
+ List<ReadCommand> commands = new ArrayList<ReadCommand>(1);
- List<Row> results = null;
- try {
- // We don't want to hard code the consistency level but letting it slide for
- // since it is also hard coded in IntraState
- results = StorageProxy.read(commands, ConsistencyLevel.ONE);
- ColumnFamily cf = results.get(0).cf;
- if (cf == null){ //cf= null is no data
- } else {
- HandlerUtils.readCf(cf, finalResults, state, params);
- }
+ QueryPath path = new QueryPath(HandlerUtils.determineCf(params, state), null);
- JsonObject response = new JsonObject();
- JsonArray array = new JsonArray();
- for (Map m : finalResults) {
- array.add(new JsonObject(m));
- }
- response.putArray(id.toString(), array);
- event.reply(response);
- } catch (ReadTimeoutException | UnavailableException | IsBootstrappingException | IOException e) {
- event.reply(new JsonObject().putString(id.toString(), e.getMessage()));
- }
- }
+ SliceFromReadCommand sr = new SliceFromReadCommand(state.getString("currentKeyspace"), rowkey, path, start, end,
+ false, 100);
+ commands.add(sr);
+
+ List<Row> results = null;
+ try {
+ // We don't want to hard code the consistency level but letting it slide for
+ // since it is also hard coded in IntraState
+ results = StorageProxy.read(commands, ConsistencyLevel.ONE);
+ ColumnFamily cf = results.get(0).cf;
+ new ReadHandler(event, eb).handleRead(cf);
+
+ } catch (ReadTimeoutException | UnavailableException | IsBootstrappingException | IOException e) {
+ event.reply(new JsonObject().putString(id.toString(), e.getMessage()));
+ }
+ }
}
252 src/main/resources/eclipseUima_code_style_prefs.xml
View
@@ -0,0 +1,252 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<profiles version="10">
+<profile name="Apache UIMA Code Conventions" version="10">
+<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_comments" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="100"/>
+<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="4"/>
+<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
+<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="2"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="100"/>
+<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
+<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2"/>
+<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
+</profile>
+</profiles>
+
169 src/test/java/org/usergrid/vx/experimental/IntraServiceITest.java
View
@@ -48,6 +48,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usergrid.vx.client.IntraClient;
+import org.usergrid.vx.client.IntraClient2;
import org.vertx.java.core.Vertx;
@RunWith(CassandraRunner.class)
@@ -66,7 +67,7 @@ public void atest() throws CharacterCodingException{
IntraReq req = new IntraReq();
req.add( Operations.setKeyspaceOp("myks") ); //0
req.add( Operations.setColumnFamilyOp("mycf") ); //1
- req.add( Operations.setAutotimestampOp() ); //2
+ req.add( Operations.setAutotimestampOp(true) ); //2
req.add( Operations.setOp("rowa", "col1", "7")); //3
req.add( Operations.sliceOp("rowa", "col1", "z", 4)); //4
req.add( Operations.getOp("rowa", "col1")); //5
@@ -107,13 +108,15 @@ public void atest() throws CharacterCodingException{
}
@Test
- public void exceptionHandleTest() throws CharacterCodingException{
+ @Ignore
+ //Tis test now hangs.
+ public void exceptionHandleTest() throws Exception{
IntraReq req = new IntraReq();
req.add( Operations.createKsOp("makeksagain", 1)); //0
req.add( Operations.createKsOp("makeksagain", 1)); //1
req.add( Operations.createKsOp("makeksagain", 1)); //2
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
Assert.assertEquals ( "OK" , res.getOpsRes().get(0) );
Assert.assertEquals( 1, res.getOpsRes().size() );
Assert.assertNotNull( res.getException() );
@@ -121,30 +124,31 @@ public void exceptionHandleTest() throws CharacterCodingException{
}
@Test
- public void assumeTest() throws CharacterCodingException{
+ public void assumeTest() throws Exception{
IntraReq req = new IntraReq();
req.add( Operations.setKeyspaceOp("assks") ); //0
req.add( Operations.createKsOp("assks", 1)); //1
req.add( Operations.createCfOp("asscf")); //2
req.add( Operations.setColumnFamilyOp("asscf") ); //3
- req.add( Operations.setAutotimestampOp() ); //4
+ req.add( Operations.setAutotimestampOp(true) ); //4
req.add( Operations.assumeOp("assks", "asscf", "value", "UTF8Type"));//5
req.add( Operations.setOp("rowa", "col1", "wow")); //6
req.add( Operations.getOp("rowa", "col1")); //7
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
List<Map> x = (List<Map>) res.getOpsRes().get(7);
+ System.out.println(res);
Assert.assertEquals( "wow", x.get(0).get("value") );
}
@Test
- public void filterTest() throws CharacterCodingException {
+ public void filterTest() throws Exception {
IntraReq req = new IntraReq();
req.add(Operations.setKeyspaceOp("filterks")); // 0
req.add(Operations.createKsOp("filterks", 1)); // 1
req.add(Operations.createCfOp("filtercf")); // 2
req.add(Operations.setColumnFamilyOp("filtercf")); // 3
- req.add(Operations.setAutotimestampOp()); // 4
+ req.add(Operations.setAutotimestampOp(true)); // 4
req.add(Operations.assumeOp("filterks", "filtercf", "value", "UTF8Type"));// 5
req.add(Operations.setOp("rowa", "col1", "20")); // 6
req.add(Operations.setOp("rowa", "col2", "22")); // 7
@@ -153,8 +157,8 @@ public void filterTest() throws CharacterCodingException {
"{ row -> if (row['value'].toInteger() > 21) return row else return null }")); // 8
req.add(Operations.filterModeOp("over21", true)); // 9
req.add(Operations.sliceOp("rowa", "col1", "col3", 10)); // 10
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
System.out.println(res.getException());
List<Map> results = (List<Map>) res.getOpsRes().get(10);
Assert.assertEquals("22", results.get(0).get("value"));
@@ -178,13 +182,13 @@ public void filterTest() throws CharacterCodingException {
}
@Test
- public void executeJavaScriptFilter() throws CharacterCodingException {
+ public void executeJavaScriptFilter() throws Exception {
IntraReq req = new IntraReq();
req.add(Operations.setKeyspaceOp("jsFilterks")); //0
req.add(Operations.createKsOp("jsFilterks", 1)); //1
req.add(Operations.createCfOp("filtercf")); //2
req.add(Operations.setColumnFamilyOp("filtercf")); //3
- req.add(Operations.setAutotimestampOp()); //4
+ req.add(Operations.setAutotimestampOp(true)); //4
req.add(Operations.assumeOp("jsFilterks", "filtercf", "value", "UTF8Type"));//5
req.add(Operations.setOp("rowa", "col1", "20")); //6
req.add(Operations.setOp("rowa", "col2", "22")); //7
@@ -192,8 +196,8 @@ public void executeJavaScriptFilter() throws CharacterCodingException {
"function over21(row) { if (row['value'] > 21) return row; else return null; }")); // 8
req.add(Operations.filterModeOp("over21", true)); //9
req.add(Operations.sliceOp("rowa", "col1", "col3", 10)); //10
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
System.out.println(res.getException());
List<Map> results = (List<Map>) res.getOpsRes().get(10);
Assert.assertEquals("22", results.get(0).get("value"));
@@ -202,13 +206,13 @@ public void executeJavaScriptFilter() throws CharacterCodingException {
}
@Test
- public void processorTest() throws CharacterCodingException{
+ public void processorTest() throws Exception{
IntraReq req = new IntraReq();
req.add( Operations.setKeyspaceOp("procks") ); //0
req.add( Operations.createKsOp("procks", 1)); //1
req.add( Operations.createCfOp("proccf")); //2
req.add( Operations.setColumnFamilyOp("proccf") ); //3
- req.add( Operations.setAutotimestampOp() ); //4
+ req.add( Operations.setAutotimestampOp(true) ); //4
req.add( Operations.assumeOp("procks", "proccf", "value", "UTF8Type"));//5
req.add( Operations.setOp("rowa", "col1", "wow")); //6
req.add( Operations.getOp("rowa", "col1")); //7
@@ -227,8 +231,8 @@ public void processorTest() throws CharacterCodingException{
));//8
//TAKE THE RESULT OF STEP 7 AND APPLY THE PROCESSOR TO IT
req.add( Operations.processOp("capitalize", new HashMap(), 7));//9
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
List<Map> x = (List<Map>) res.getOpsRes().get(7);
Assert.assertEquals( "wow", x.get(0).get("value") );
System.out.println(res.getException() );
@@ -239,41 +243,41 @@ public void processorTest() throws CharacterCodingException{
@Test
- public void intTest() throws CharacterCodingException{
+ public void intTest() throws Exception{
IntraReq req = new IntraReq();
req.add( Operations.setKeyspaceOp("intks") ); //0
req.add( Operations.createKsOp("intks", 1)); //1
req.add( Operations.createCfOp("intcf")); //2
req.add( Operations.setColumnFamilyOp("intcf") ); //3
- req.add( Operations.setAutotimestampOp() ); //4
+ req.add( Operations.setAutotimestampOp(true) ); //4
req.add( Operations.assumeOp("intks", "intcf", "value", "UTF8Type"));//5
req.add( Operations.assumeOp("intks", "intcf", "column", "Int32Type"));//6
req.add( Operations.setOp("rowa", 1, "wow")); //7
req.add( Operations.getOp("rowa", 1)); //8
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
List<Map> x = (List<Map>) res.getOpsRes().get(8);
-
+ System.out.println(res);
Assert.assertEquals( "wow", x.get(0).get("value") );
Assert.assertEquals( 1, x.get(0).get("name") );
}
@Test
- public void ttlTest () {
+ public void ttlTest () throws Exception {
IntraReq req = new IntraReq();
req.add( Operations.setKeyspaceOp("ttlks") ); //0
req.add( Operations.createKsOp("ttlks", 1)); //1
req.add( Operations.createCfOp("ttlcf")); //2
req.add( Operations.setColumnFamilyOp("ttlcf") ); //3
- req.add( Operations.setAutotimestampOp() ); //4
+ req.add( Operations.setAutotimestampOp(true) ); //4
req.add( Operations.assumeOp("ttlks", "ttlcf", "value", "UTF8Type"));//5
req.add( Operations.assumeOp("ttlks", "ttlcf", "column", "Int32Type"));//6
req.add( Operations.setOp("rowa", 1, "wow")); //7
req.add( Operations.setOp("rowa", 2, "wow").set("ttl", 1)); //8
//req.add( Operations.sliceOp("rowa", 1, 5, 4) ); //9
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
Assert.assertEquals( "OK", res.getOpsRes().get(8));
try {
Thread.sleep(2000);
@@ -297,20 +301,20 @@ public void ttlTest () {
}
@Test
- public void compositeTest() throws CharacterCodingException {
+ public void compositeTest() throws Exception {
IntraReq req = new IntraReq();
req.add(Operations.setKeyspaceOp("compks")); //0
req.add(Operations.createKsOp("compks", 1)); //1
req.add(Operations.createCfOp("compcf")); //2
req.add(Operations.setColumnFamilyOp("compcf")); //3
- req.add(Operations.setAutotimestampOp()); //4
+ req.add(Operations.setAutotimestampOp(true)); //4
req.add(Operations.assumeOp("compks", "compcf", "value", "CompositeType(UTF8Type,Int32Type)"));//5
req.add(Operations.assumeOp("compks", "compcf", "column", "Int32Type"));//6
req.add(Operations.setOp("rowa", 1, new Object[]{"yo", 0, 2, 0})); //7
req.add(Operations.getOp("rowa", 1)); //8
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
List<Map> x = (List<Map>) res.getOpsRes().get(8);
Assert.assertEquals(1, x.get(0).get("name"));
@@ -330,21 +334,21 @@ public void compositeTest() throws CharacterCodingException {
@Test
- public void CqlTest() throws CharacterCodingException{
+ public void CqlTest() throws Exception{
IntraReq req = new IntraReq();
req.add( Operations.setKeyspaceOp("cqlks") ); //0
req.add( Operations.createKsOp("cqlks", 1)); //1
req.add( Operations.createCfOp("cqlcf")); //2
req.add( Operations.setColumnFamilyOp("cqlcf") ); //3
- req.add( Operations.setAutotimestampOp() ); //4
+ req.add( Operations.setAutotimestampOp(true) ); //4
req.add( Operations.assumeOp("cqlks", "cqlcf", "value", "Int32Type"));//5
req.add( Operations.assumeOp("cqlks", "cqlcf", "column", "Int32Type"));//6
req.add( Operations.setOp("rowa", 1, 2)); //7
req.add( Operations.getOp("rowa", 1)); //8
req.add( Operations.cqlQuery("select * from cqlcf", "3.0.0"));//9
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
List<Map> x = (List<Map>) res.getOpsRes().get(8);
Assert.assertEquals( 1, x.get(0).get("name") );
@@ -356,35 +360,35 @@ public void CqlTest() throws CharacterCodingException{
}
@Test
- public void CqlNoResultTest() throws CharacterCodingException {
+ public void CqlNoResultTest() throws Exception {
IntraReq req = new IntraReq();
req.add ( Operations.setKeyspaceOp("system") );
req.add(Operations
.cqlQuery(
"CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}",
"3.0.0"));// 0
- IntraRes res = new IntraRes();
- is.handleIntraReq(req, res, x);
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(req);
List<Map> x = (List<Map>) res.getOpsRes().get(1);
Assert.assertEquals(2, res.getOpsRes().size());
}
@Test
- public void clearTest() throws CharacterCodingException{