Search in sources :

Example 21 with GridClientCacheRequest

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();
}
Also used : GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)

Example 22 with GridClientCacheRequest

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());
}
Also used : GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridClientOptimizedMarshaller(org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller) GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest) ByteBuffer(java.nio.ByteBuffer) GridClientMessage(org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)

Example 23 with GridClientCacheRequest

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);
}
Also used : GridClientMarshaller(org.apache.ignite.internal.client.marshaller.GridClientMarshaller) HashMap(java.util.HashMap) GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with GridClientCacheRequest

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;
}
Also used : GridClientAuthenticationRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest) GridRestTopologyRequest(org.apache.ignite.internal.processors.rest.request.GridRestTopologyRequest) GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) GridRestChangeStateRequest(org.apache.ignite.internal.processors.rest.request.GridRestChangeStateRequest) GridRestTaskRequest(org.apache.ignite.internal.processors.rest.request.GridRestTaskRequest) GridClientStateRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientStateRequest) GridClientTopologyRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest) GridRestRequest(org.apache.ignite.internal.processors.rest.request.GridRestRequest) GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) GridClientTaskRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTaskRequest) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GridClientCacheRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)24 ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 GridClientOptimizedMarshaller (org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller)3 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)3 GridClientMessage (org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)2 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 GridClientMarshaller (org.apache.ignite.internal.client.marshaller.GridClientMarshaller)1 GridClientAuthenticationRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest)1 GridClientStateRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientStateRequest)1 GridClientTaskRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientTaskRequest)1 GridClientTopologyRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest)1 GridRestCacheRequest (org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest)1 GridRestChangeStateRequest (org.apache.ignite.internal.processors.rest.request.GridRestChangeStateRequest)1 GridRestRequest (org.apache.ignite.internal.processors.rest.request.GridRestRequest)1 GridRestTaskRequest (org.apache.ignite.internal.processors.rest.request.GridRestTaskRequest)1