use of org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest in project ignite by apache.
the class TestBinaryClient method cacheAppend.
/**
* @param cacheName Cache name.
* @param key Key.
* @param val Value.
* @return Whether entry was appended.
* @throws IgniteCheckedException In case of error.
*/
public <K, V> boolean cacheAppend(@NotNull String cacheName, K key, V val) throws IgniteCheckedException {
assert key != null;
assert val != null;
GridClientCacheRequest add = new GridClientCacheRequest(APPEND);
add.requestId(idCntr.getAndIncrement());
add.cacheName(cacheName);
add.key(key);
add.value(val);
return makeRequest(add).<Boolean>getObject();
}
use of org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest in project ignite by apache.
the class TcpRestParserSelfTest method testCustomMessages.
/**
* @throws Exception If failed.
*/
public void testCustomMessages() throws Exception {
GridClientCacheRequest req = new GridClientCacheRequest(CAS);
req.key("key");
req.value(1);
req.value2(2);
req.clientId(UUID.randomUUID());
ByteBuffer raw = clientRequestPacket(req);
GridNioSession ses = new MockNioSession();
ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller());
GridTcpRestParser parser = new GridTcpRestParser(false);
GridClientMessage msg = parser.decode(ses, raw);
assertNotNull(msg);
assertEquals("Parser leaved unparsed bytes", 0, raw.remaining());
assertTrue(msg instanceof GridClientCacheRequest);
GridClientCacheRequest res = (GridClientCacheRequest) msg;
assertEquals("Invalid operation", req.operation(), res.operation());
assertEquals("Invalid clientId", req.clientId(), res.clientId());
assertEquals("Invalid key", req.key(), res.key());
assertEquals("Invalid value 1", req.value(), res.value());
assertEquals("Invalid value 2", req.value2(), res.value2());
}
use of org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest in project ignite by apache.
the class ClientMarshallerBenchmarkTest method testCacheRequestTime.
/**
* @throws Exception If failed.
*/
public void testCacheRequestTime() throws Exception {
GridClientCacheRequest req = new GridClientCacheRequest(CAS);
req.clientId(UUID.randomUUID());
req.cacheName("CacheName");
req.requestId(1024);
req.key("key");
req.value(1L);
req.value2(2L);
Map<Object, Object> additional = new HashMap<>();
for (int i = 0; i < 1000; i++) additional.put("key" + i, (long) i);
req.values(additional);
// Warm up.
for (GridClientMarshaller marshaller : marshallers) {
GridClientCacheRequest res = runMarshallUnmarshalLoop(req, 1, marshaller);
assertEquals(req.operation(), res.operation());
// requestId is not marshalled.
assertEquals(0, res.requestId());
// clientId is not marshalled.
assertEquals(null, res.clientId());
// destinationId is not marshalled.
assertEquals(null, res.destinationId());
assertEquals(req.cacheName(), res.cacheName());
assertEquals(req.key(), res.key());
assertEquals(req.value(), res.value());
assertEquals(req.value2(), res.value2());
for (Map.Entry<Object, Object> e : req.values().entrySet()) assertEquals(e.getValue(), res.values().get(e.getKey()));
}
// Now real test.
for (GridClientMarshaller marshaller : marshallers) runMarshallUnmarshalLoop(req, 1000, marshaller);
}
use of org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest in project ignite by apache.
the class GridTcpRestNioListener method createRestRequest.
/**
* Creates a REST request object from client TCP binary packet.
*
* @param ses NIO session.
* @param msg Request message.
* @return REST request object.
*/
@Nullable
private GridRestRequest createRestRequest(GridNioSession ses, GridClientMessage msg) {
GridRestRequest restReq = null;
if (msg instanceof GridClientAuthenticationRequest) {
GridClientAuthenticationRequest req = (GridClientAuthenticationRequest) msg;
restReq = new GridRestTaskRequest();
restReq.command(NOOP);
restReq.credentials(req.credentials());
} else if (msg instanceof GridClientCacheRequest) {
GridClientCacheRequest req = (GridClientCacheRequest) msg;
GridRestCacheRequest restCacheReq = new GridRestCacheRequest();
restCacheReq.cacheName(req.cacheName());
restCacheReq.cacheFlags(req.cacheFlagsOn());
restCacheReq.key(req.key());
restCacheReq.value(req.value());
restCacheReq.value2(req.value2());
Map vals = req.values();
if (vals != null)
restCacheReq.values(new HashMap<Object, Object>(vals));
restCacheReq.command(cacheCmdMap.get(req.operation()));
restReq = restCacheReq;
} else if (msg instanceof GridClientTaskRequest) {
GridClientTaskRequest req = (GridClientTaskRequest) msg;
GridRestTaskRequest restTaskReq = new GridRestTaskRequest();
restTaskReq.command(EXE);
restTaskReq.taskName(req.taskName());
restTaskReq.params(Arrays.asList(req.argument()));
restReq = restTaskReq;
} else if (msg instanceof GridClientTopologyRequest) {
GridClientTopologyRequest req = (GridClientTopologyRequest) msg;
GridRestTopologyRequest restTopReq = new GridRestTopologyRequest();
restTopReq.includeMetrics(req.includeMetrics());
restTopReq.includeAttributes(req.includeAttributes());
if (req.nodeId() != null) {
restTopReq.command(NODE);
restTopReq.nodeId(req.nodeId());
} else if (req.nodeIp() != null) {
restTopReq.command(NODE);
restTopReq.nodeIp(req.nodeIp());
} else
restTopReq.command(TOPOLOGY);
restReq = restTopReq;
} else if (msg instanceof GridClientStateRequest) {
GridClientStateRequest req = (GridClientStateRequest) msg;
GridRestChangeStateRequest restChangeReq = new GridRestChangeStateRequest();
if (req.isReqCurrentState()) {
restChangeReq.reqCurrentState();
restChangeReq.command(CLUSTER_CURRENT_STATE);
} else {
restChangeReq.active(req.active());
restChangeReq.command(req.active() ? CLUSTER_ACTIVE : CLUSTER_INACTIVE);
}
restReq = restChangeReq;
}
if (restReq != null) {
restReq.destinationId(msg.destinationId());
restReq.clientId(msg.clientId());
restReq.sessionToken(msg.sessionToken());
restReq.address(ses.remoteAddress());
}
return restReq;
}
Aggregations