http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/GridTestMemcacheClient.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/GridTestMemcacheClient.java b/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/GridTestMemcacheClient.java deleted file mode 100644 index d0dd2d9..0000000 --- a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/GridTestMemcacheClient.java +++ /dev/null @@ -1,898 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.rest; - -import org.apache.ignite.*; -import org.apache.ignite.logger.java.*; -import org.apache.ignite.marshaller.*; -import org.apache.ignite.marshaller.jdk.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -/** - * Test client. - */ -final class GridTestMemcacheClient { - /** Header length. */ - private static final short HDR_LEN = 24; - - /** Serialized flag. */ - private static final short SERIALIZED_FLAG = 1; - - /** Boolean flag. */ - private static final short BOOLEAN_FLAG = (1 << 8); - - /** Integer flag. */ - private static final short INT_FLAG = (2 << 8); - - /** Long flag. */ - private static final short LONG_FLAG = (3 << 8); - - /** Date flag. */ - private static final short DATE_FLAG = (4 << 8); - - /** Byte flag. */ - private static final short BYTE_FLAG = (5 << 8); - - /** Float flag. */ - private static final short FLOAT_FLAG = (6 << 8); - - /** Double flag. */ - private static final short DOUBLE_FLAG = (7 << 8); - - /** Byte array flag. */ - private static final short BYTE_ARR_FLAG = (8 << 8); - - /** Logger. */ - private final IgniteLogger log = new IgniteJavaLogger(); - - /** JDK marshaller. */ - private final IgniteMarshaller jdkMarshaller = new IgniteJdkMarshaller(); - - /** Socket. */ - private final Socket sock; - - /** Opaque counter. */ - private final AtomicInteger opaqueCntr = new AtomicInteger(0); - - /** Response queue. */ - private final BlockingQueue<Response> queue = - new LinkedBlockingQueue<>(); - - /** Socket reader. */ - private final Thread rdr; - - /** Quit response. */ - private static final Response QUIT_RESP = new Response(0, false, null, null); - - /** - * Creates client. - * - * @param host Hostname. - * @param port Port number. - * @throws IgniteCheckedException In case of error. - */ - GridTestMemcacheClient(String host, int port) throws IgniteCheckedException { - assert host != null; - assert port > 0; - - try { - sock = new Socket(host, port); - } - catch (IOException e) { - throw new IgniteCheckedException("Failed to establish connection.", e); - } - - // Start socket reader thread. - rdr = new Thread(new Runnable() { - @SuppressWarnings("InfiniteLoopStatement") - @Override public void run() { - try { - InputStream in = sock.getInputStream(); - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - boolean running = true; - - while (running) { - byte opCode = 0; - byte extrasLength = 0; - int keyLength = 0; - boolean success = false; - int totalLength = 0; - int opaque = 0; - short keyFlags = 0; - short valFlags = 0; - Object obj = null; - Object key = null; - - int i = 0; - - while (true) { - int symbol = in.read(); - - if (symbol == -1) { - running = false; - - break; - } - - byte b = (byte)symbol; - - if (i == 1) - opCode = b; - if (i == 2 || i == 3) { - buf.write(b); - - if (i == 3) { - keyLength = U.bytesToShort(buf.toByteArray(), 0); - - buf.reset(); - } - } - else if (i == 4) - extrasLength = b; - else if (i == 6 || i == 7) { - buf.write(b); - - if (i == 7) { - success = U.bytesToShort(buf.toByteArray(), 0) == 0; - - buf.reset(); - } - } - else if (i >= 8 && i <= 11) { - buf.write(b); - - if (i == 11) { - totalLength = U.bytesToInt(buf.toByteArray(), 0); - - buf.reset(); - } - } - else if (i >= 12 && i <= 15) { - buf.write(b); - - if (i == 15) { - opaque = U.bytesToInt(buf.toByteArray(), 0); - - buf.reset(); - } - } - else if (i >= HDR_LEN && i < HDR_LEN + extrasLength) { - buf.write(b); - - if (i == HDR_LEN + extrasLength - 1) { - byte[] rawFlags = buf.toByteArray(); - - keyFlags = U.bytesToShort(rawFlags, 0); - valFlags = U.bytesToShort(rawFlags, 2); - - buf.reset(); - } - } - else if (i >= HDR_LEN + extrasLength && i < HDR_LEN + extrasLength + keyLength) { - buf.write(b); - - if (i == HDR_LEN + extrasLength + keyLength - 1) { - key = decode(buf.toByteArray(), keyFlags); - - buf.reset(); - } - } - else if (i >= HDR_LEN + extrasLength + keyLength && i < HDR_LEN + totalLength) { - buf.write(b); - - if (opCode == 0x05 || opCode == 0x06) - valFlags = LONG_FLAG; - - if (i == HDR_LEN + totalLength - 1) { - obj = decode(buf.toByteArray(), valFlags); - - buf.reset(); - } - } - - if (i == HDR_LEN + totalLength - 1) { - queue.add(new Response(opaque, success, key, obj)); - - break; - } - - i++; - } - } - } - catch (IOException e) { - if (!Thread.currentThread().isInterrupted()) - U.error(log, e); - } - catch (Exception e) { - U.error(log, e); - } - finally { - U.closeQuiet(sock); - - queue.add(QUIT_RESP); - } - } - }); - - rdr.start(); - } - - /** {@inheritDoc} */ - public void shutdown() throws IgniteCheckedException { - try { - if (rdr != null) { - rdr.interrupt(); - - U.closeQuiet(sock); - - rdr.join(); - } - } - catch (InterruptedException e) { - throw new IgniteCheckedException(e); - } - } - - /** - * Makes request to server and waits for response. - * - * @param cmd Command. - * @param cacheName Cache name. - * @param key Key. - * @param val Value. - * @param extras Extras. - * @return Response. - * @throws IgniteCheckedException In case of error. - */ - private Response makeRequest( - Command cmd, - @Nullable String cacheName, - @Nullable Object key, - @Nullable Object val, - @Nullable Long... extras - ) throws IgniteCheckedException { - assert cmd != null; - - int opaque = opaqueCntr.getAndIncrement(); - - // Send request. - try { - sock.getOutputStream().write(createPacket(cmd, cacheName, key, val, opaque, extras)); - } - catch (IOException e) { - throw new IgniteCheckedException("Failed to send packet.", e); - } - - // Wait for response. - while (true) { - try { - // Take response from queue. - Response res = queue.take(); - - if (res == QUIT_RESP) - return res; - - // Check opaque value. - if (res.getOpaque() == opaque) { - if (!res.isSuccess() && res.getObject() != null) - throw new IgniteCheckedException((String)res.getObject()); - else - return res; - } - else - // Return response to queue if opaque is incorrect. - queue.add(res); - } - catch (InterruptedException e) { - throw new IgniteCheckedException("Interrupted while waiting for response.", e); - } - } - } - - /** - * Makes request to server and waits for response. - * - * @param cmd Command. - * @param cacheName Cache name. - * @param key Key. - * @param val Value. - * @param extras Extras. - * @return Response. - * @throws IgniteCheckedException In case of error. - */ - private List<Response> makeMultiRequest( - Command cmd, - @Nullable String cacheName, - @Nullable Object key, - @Nullable Object val, - @Nullable Long... extras - ) throws IgniteCheckedException { - assert cmd != null; - - int opaque = opaqueCntr.getAndIncrement(); - - List<Response> resList = new LinkedList<>(); - - // Send request. - try { - sock.getOutputStream().write(createPacket(cmd, cacheName, key, val, opaque, extras)); - } - catch (IOException e) { - throw new IgniteCheckedException("Failed to send packet.", e); - } - - // Wait for response. - while (true) { - try { - // Take response from queue. - Response res = queue.take(); - - if (res == QUIT_RESP) - return resList; - - // Check opaque value. - if (res.getOpaque() == opaque) { - if (!res.isSuccess() && res.getObject() != null) - throw new IgniteCheckedException((String)res.getObject()); - else { - if (res.getObject() == null) - return resList; - - resList.add(res); - } - } - else - // Return response to queue if opaque is incorrect. - queue.add(res); - } - catch (InterruptedException e) { - throw new IgniteCheckedException("Interrupted while waiting for response.", e); - } - } - } - - /** - * Creates packet. - * - * @param cmd Command. - * @param cacheName Cache name. - * @param key Key. - * @param val Value. - * @param opaque Opaque. - * @param extras Extras. - * @throws IgniteCheckedException In case of error. - * @return Packet. - */ - private byte[] createPacket( - Command cmd, - @Nullable String cacheName, - @Nullable Object key, - @Nullable Object val, - int opaque, - @Nullable Long[] extras - ) throws IgniteCheckedException { - assert cmd != null; - assert opaque >= 0; - - byte[] cacheNameBytes = cacheName != null ? cacheName.getBytes() : null; - - Data keyData = encode(key); - - Data valData = encode(val); - - int cacheNameLength = cacheNameBytes != null ? cacheNameBytes.length : 0; - int extrasLength = cmd.extrasLength() + cacheNameLength; - - byte[] packet = new byte[HDR_LEN + extrasLength + keyData.length() + valData.length()]; - - packet[0] = (byte)0x80; - packet[1] = cmd.operationCode(); - - U.shortToBytes((short)keyData.length(), packet, 2); - - packet[4] = (byte)(extrasLength); - - U.intToBytes(extrasLength + keyData.length() + valData.length(), packet, 8); - U.intToBytes(opaque, packet, 12); - - if (extrasLength > 0) { - if (extras != null) { - int offset = HDR_LEN; - - for (Long extra : extras) { - if (extra != null) - U.longToBytes(extra, packet, offset); - - offset += 8; - } - } - else { - U.shortToBytes(keyData.getFlags(), packet, HDR_LEN); - U.shortToBytes(valData.getFlags(), packet, HDR_LEN + 2); - } - } - - if (cacheNameBytes != null) - U.arrayCopy(cacheNameBytes, 0, packet, HDR_LEN + cmd.extrasLength(), cacheNameLength); - - if (keyData.getBytes() != null) - U.arrayCopy(keyData.getBytes(), 0, packet, HDR_LEN + extrasLength, keyData.length()); - - if (valData.getBytes() != null) - U.arrayCopy(valData.getBytes(), 0, packet, HDR_LEN + extrasLength + keyData.length(), valData.length()); - - return packet; - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @param val Value. - * @return If value was actually put. - * @throws IgniteCheckedException In case of error. - */ - public <K, V> boolean cachePut(@Nullable String cacheName, K key, V val) - throws IgniteCheckedException { - assert key != null; - assert val != null; - - return makeRequest(Command.PUT, cacheName, key, val).isSuccess(); - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @return Value. - * @throws IgniteCheckedException In case of error. - */ - public <K, V> V cacheGet(@Nullable String cacheName, K key) - throws IgniteCheckedException { - assert key != null; - - return makeRequest(Command.GET, cacheName, key, null).getObject(); - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @return Whether entry was actually removed. - * @throws IgniteCheckedException In case of error. - */ - public <K> boolean cacheRemove(@Nullable String cacheName, K key) throws IgniteCheckedException { - assert key != null; - - return makeRequest(Command.REMOVE, cacheName, key, null).isSuccess(); - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @param val Value. - * @return Whether entry was added. - * @throws IgniteCheckedException In case of error. - */ - public <K, V> boolean cacheAdd(@Nullable String cacheName, K key, V val) - throws IgniteCheckedException { - assert key != null; - assert val != null; - - return makeRequest(Command.ADD, cacheName, key, val).isSuccess(); - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @param val Value. - * @return Whether value was actually replaced. - * @throws IgniteCheckedException In case of error. - */ - public <K, V> boolean cacheReplace(@Nullable String cacheName, K key, V val) - throws IgniteCheckedException { - assert key != null; - assert val != null; - - return makeRequest(Command.REPLACE, cacheName, key, val).isSuccess(); - } - - /** - * @param cacheName Cache name. - * @throws IgniteCheckedException In case of error. - */ - public <K> Map<String, Long> cacheMetrics(@Nullable String cacheName) throws IgniteCheckedException { - List<Response> raw = makeMultiRequest(Command.CACHE_METRICS, cacheName, null, null); - - Map<String, Long> res = new HashMap<>(raw.size()); - - for (Response resp : raw) - res.put((String)resp.key(), Long.parseLong(String.valueOf(resp.getObject()))); - - return res; - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @param init Initial value (optional). - * @param incr Amount to add. - * @return New value. - * @throws IgniteCheckedException In case of error. - */ - public <K> long cacheIncrement(@Nullable String cacheName, K key, @Nullable Long init, long incr) - throws IgniteCheckedException { - assert key != null; - - return makeRequest(Command.INCREMENT, cacheName, key, null, incr, init).<Long>getObject(); - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @param init Initial value (optional). - * @param decr Amount to subtract. - * @return New value. - * @throws IgniteCheckedException In case of error. - */ - public <K> long cacheDecrement(@Nullable String cacheName, K key, @Nullable Long init, long decr) - throws IgniteCheckedException { - assert key != null; - - return makeRequest(Command.DECREMENT, cacheName, key, null, decr, init).<Long>getObject(); - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @param val Value to append. - * @return Whether operation succeeded. - * @throws IgniteCheckedException In case of error. - */ - public <K> boolean cacheAppend(@Nullable String cacheName, K key, String val) - throws IgniteCheckedException { - assert key != null; - assert val != null; - - return makeRequest(Command.APPEND, cacheName, key, val).isSuccess(); - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @param val Value to prepend. - * @return Whether operation succeeded. - * @throws IgniteCheckedException In case of error. - */ - public <K> boolean cachePrepend(@Nullable String cacheName, K key, String val) - throws IgniteCheckedException { - assert key != null; - assert val != null; - - return makeRequest(Command.PREPEND, cacheName, key, val).isSuccess(); - } - - /** - * @return Version. - * @throws IgniteCheckedException In case of error. - */ - public String version() throws IgniteCheckedException { - return makeRequest(Command.VERSION, null, null, null).getObject(); - } - - /** - * @throws IgniteCheckedException In case of error. - */ - public void noop() throws IgniteCheckedException { - Response res = makeRequest(Command.NOOP, null, null, null); - - assert res != null; - assert res.isSuccess(); - assert res.getObject() == null; - } - - /** - * @throws IgniteCheckedException In case of error. - */ - public void quit() throws IgniteCheckedException { - makeRequest(Command.QUIT, null, null, null); - - assert sock.isClosed(); - } - - /** - * Encodes object. - * - * @param obj Object. - * @return Encoded data. - * @throws IgniteCheckedException In case of error. - */ - public Data encode(@Nullable Object obj) throws IgniteCheckedException { - if (obj == null) - return new Data(null, (short)0); - - byte[] bytes; - short flags = 0; - - if (obj instanceof String) - bytes = ((String)obj).getBytes(); - else if (obj instanceof Boolean) { - bytes = new byte[] {(byte)((Boolean)obj ? '1' : '0')}; - - flags |= BOOLEAN_FLAG; - } - else if (obj instanceof Integer) { - bytes = U.intToBytes((Integer)obj); - - flags |= INT_FLAG; - } - else if (obj instanceof Long) { - bytes = U.longToBytes((Long)obj); - - flags |= LONG_FLAG; - } - else if (obj instanceof Date) { - bytes = U.longToBytes(((Date)obj).getTime()); - - flags |= DATE_FLAG; - } - else if (obj instanceof Byte) { - bytes = new byte[] {(Byte)obj}; - - flags |= BYTE_FLAG; - } - else if (obj instanceof Float) { - bytes = U.intToBytes(Float.floatToIntBits((Float)obj)); - - flags |= FLOAT_FLAG; - } - else if (obj instanceof Double) { - bytes = U.longToBytes(Double.doubleToLongBits((Double)obj)); - - flags |= DOUBLE_FLAG; - } - else if (obj instanceof byte[]) { - bytes = (byte[])obj; - - flags |= BYTE_ARR_FLAG; - } - else { - bytes = jdkMarshaller.marshal(obj); - - flags |= SERIALIZED_FLAG; - } - - return new Data(bytes, flags); - } - - /** - * @param bytes Byte array to decode. - * @param flags Flags. - * @return Decoded value. - * @throws IgniteCheckedException In case of error. - */ - public Object decode(byte[] bytes, short flags) throws IgniteCheckedException { - assert bytes != null; - assert flags >= 0; - - if ((flags & SERIALIZED_FLAG) != 0) - return jdkMarshaller.unmarshal(bytes, getClass().getClassLoader()); - - int masked = flags & 0xff00; - - switch (masked) { - case BOOLEAN_FLAG: - return bytes[0] == '1'; - case INT_FLAG: - return U.bytesToInt(bytes, 0); - case LONG_FLAG: - return U.bytesToLong(bytes, 0); - case DATE_FLAG: - return new Date(U.bytesToLong(bytes, 0)); - case BYTE_FLAG: - return bytes[0]; - case FLOAT_FLAG: - return Float.intBitsToFloat(U.bytesToInt(bytes, 0)); - case DOUBLE_FLAG: - return Double.longBitsToDouble(U.bytesToLong(bytes, 0)); - case BYTE_ARR_FLAG: - return bytes; - default: - return new String(bytes); - } - } - - /** - * Response data. - */ - private static class Response { - /** Opaque. */ - private final int opaque; - - /** Success flag. */ - private final boolean success; - - /** Key. */ - private final Object key; - - /** Response object. */ - private final Object obj; - - /** - * @param opaque Opaque. - * @param success Success flag. - * @param key Key object. - * @param obj Response object. - */ - Response(int opaque, boolean success, @Nullable Object key, @Nullable Object obj) { - assert opaque >= 0; - - this.opaque = opaque; - this.success = success; - this.key = key; - this.obj = obj; - } - - /** - * @return Opaque. - */ - int getOpaque() { - return opaque; - } - - /** - * @return Success flag. - */ - boolean isSuccess() { - return success; - } - - Object key() { - return key; - } - - /** - * @return Response object. - */ - @SuppressWarnings("unchecked") - <T> T getObject() { - return (T)obj; - } - } - - - private static class Data { - /** Bytes. */ - private final byte[] bytes; - - /** Flags. */ - private final short flags; - - /** - * @param bytes Bytes. - * @param flags Flags. - */ - Data(@Nullable byte[] bytes, short flags) { - assert flags >= 0; - - this.bytes = bytes; - this.flags = flags; - } - - /** - * @return Bytes. - */ - @Nullable public byte[] getBytes() { - return bytes; - } - - /** - * @return Flags. - */ - public short getFlags() { - return flags; - } - - /** - * @return Length. - */ - public int length() { - return bytes != null ? bytes.length : 0; - } - } - - /** - * Command. - */ - private enum Command { - /** Get. */ - GET((byte)0x00, 4), - - /** Put. */ - PUT((byte)0x01, 8), - - /** Add. */ - ADD((byte)0x02, 8), - - /** Replace. */ - REPLACE((byte)0x03, 8), - - /** Remove. */ - REMOVE((byte)0x04, 4), - - /** Increment. */ - INCREMENT((byte)0x05, 20), - - /** Decrement. */ - DECREMENT((byte)0x06, 20), - - /** Quit. */ - QUIT((byte)0x07, 0), - - /** Cache metrics. */ - CACHE_METRICS((byte)0x10, 4), - - /** No-op. */ - NOOP((byte)0x0A, 0), - - /** Version. */ - VERSION((byte)0x0B, 0), - - /** Append. */ - APPEND((byte)0x0E, 4), - - /** Append. */ - PREPEND((byte)0x0F, 4); - - /** Operation code. */ - private final byte opCode; - - /** Extras length. */ - private final int extrasLength; - - /** - * @param opCode Operation code. - * @param extrasLength Extras length. - */ - Command(byte opCode, int extrasLength) { - this.opCode = opCode; - this.extrasLength = extrasLength; - } - - /** - * @return Operation code. - */ - public byte operationCode() { - return opCode; - } - - /** - * @return Extras length. - */ - public int extrasLength() { - return extrasLength; - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/TestTask1.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/TestTask1.java b/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/TestTask1.java deleted file mode 100644 index 31cea39..0000000 --- a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/TestTask1.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.rest; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.internal.util.typedef.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * - */ -class TestTask1 extends ComputeTaskSplitAdapter<String, String> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) throws IgniteCheckedException { - Collection<ComputeJob> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) - jobs.add(new ComputeJobAdapter() { - @Nullable - @Override public Object execute() { - X.println("Test task1."); - - return null; - } - }); - - return jobs; - } - - /** {@inheritDoc} */ - @Override public String reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/TestTask2.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/TestTask2.java b/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/TestTask2.java deleted file mode 100644 index 3f39303..0000000 --- a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/TestTask2.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.rest; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.internal.util.typedef.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * - */ -class TestTask2 extends ComputeTaskSplitAdapter<String, String> { - static final String RES = "Task 2 result."; - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) throws IgniteCheckedException { - Collection<ComputeJob> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) - jobs.add(new ComputeJobAdapter() { - @Nullable - @Override public Object execute() { - X.println("Test task2."); - - return null; - } - }); - - return jobs; - } - - /** {@inheritDoc} */ - @Override public String reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return RES; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/protocols/tcp/GridMockNioSession.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/protocols/tcp/GridMockNioSession.java b/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/protocols/tcp/GridMockNioSession.java deleted file mode 100644 index d3986da..0000000 --- a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/protocols/tcp/GridMockNioSession.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.rest.protocols.tcp; - -import org.apache.ignite.internal.util.lang.*; -import org.apache.ignite.internal.util.nio.*; -import org.jetbrains.annotations.*; - -import java.net.*; - -/** - * Mock nio session with disabled functionality for testing parser. - */ -public class GridMockNioSession extends GridMetadataAwareAdapter implements GridNioSession { - /** Local address */ - private InetSocketAddress locAddr = new InetSocketAddress(0); - - /** Remote address. */ - private InetSocketAddress rmtAddr = new InetSocketAddress(0); - - /** - * Creates empty mock session. - */ - public GridMockNioSession() { - // No-op. - } - - /** - * Creates new mock session with given addresses. - * - * @param locAddr Local address. - * @param rmtAddr Remote address. - */ - public GridMockNioSession(InetSocketAddress locAddr, InetSocketAddress rmtAddr) { - this(); - - this.locAddr = locAddr; - this.rmtAddr = rmtAddr; - } - - /** {@inheritDoc} */ - @Override public InetSocketAddress localAddress() { - return locAddr; - } - - /** {@inheritDoc} */ - @Override public InetSocketAddress remoteAddress() { - return rmtAddr; - } - - /** {@inheritDoc} */ - @Override public long bytesSent() { - return 0; - } - - /** {@inheritDoc} */ - @Override public long bytesReceived() { - return 0; - } - - /** {@inheritDoc} */ - @Override public long createTime() { - return 0; - } - - /** {@inheritDoc} */ - @Override public long closeTime() { - return 0; - } - - /** {@inheritDoc} */ - @Override public long lastReceiveTime() { - return 0; - } - - /** {@inheritDoc} */ - @Override public long lastSendTime() { - return 0; - } - - /** {@inheritDoc} */ - @Override public long lastSendScheduleTime() { - return 0; - } - - /** {@inheritDoc} */ - @Override public GridNioFuture<Boolean> close() { - return new GridNioFinishedFuture<>(true); - } - - /** {@inheritDoc} */ - @Override public GridNioFuture<?> send(Object msg) { - return new GridNioFinishedFuture<>(true); - } - - /** {@inheritDoc} */ - @Override public <T> T meta(int key) { - return meta(String.valueOf(key)); - } - - /** {@inheritDoc} */ - @Override public <T> T addMeta(int key, T val) { - return addMeta(String.valueOf(key), val); - } - - /** {@inheritDoc} */ - @Override public <T> T removeMeta(int key) { - return removeMeta(String.valueOf(key)); - } - - /** {@inheritDoc} */ - @Override public GridNioFuture<Object> resumeReads() { - return null; - } - - /** {@inheritDoc} */ - @Override public GridNioFuture<Object> pauseReads() { - return null; - } - - /** {@inheritDoc} */ - @Override public boolean accepted() { - return false; - } - - /** {@inheritDoc} */ - @Override public boolean readsPaused() { - return false; - } - - /** {@inheritDoc} */ - @Override public void recoveryDescriptor(GridNioRecoveryDescriptor recoveryDesc) { - // No-op. - } - - /** {@inheritDoc} */ - @Nullable @Override public GridNioRecoveryDescriptor recoveryDescriptor() { - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/protocols/tcp/GridTcpRestParserSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/protocols/tcp/GridTcpRestParserSelfTest.java b/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/protocols/tcp/GridTcpRestParserSelfTest.java deleted file mode 100644 index 31ee508..0000000 --- a/modules/clients/src/test/java/org/gridgain/grid/kernal/processors/rest/protocols/tcp/GridTcpRestParserSelfTest.java +++ /dev/null @@ -1,451 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.rest.protocols.tcp; - -import org.apache.ignite.client.marshaller.*; -import org.apache.ignite.client.marshaller.optimized.*; -import org.gridgain.grid.kernal.processors.rest.client.message.*; -import org.apache.ignite.internal.util.nio.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.gridgain.testframework.*; -import org.gridgain.testframework.junits.common.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.nio.*; -import java.util.*; -import java.util.concurrent.*; - -import static org.gridgain.grid.kernal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*; -import static org.gridgain.grid.kernal.processors.rest.protocols.tcp.GridMemcachedMessage.*; -import static org.apache.ignite.internal.util.nio.GridNioSessionMetaKey.*; - -/** - * This class tests that parser confirms memcache extended specification. - */ -@SuppressWarnings("TypeMayBeWeakened") -public class GridTcpRestParserSelfTest extends GridCommonAbstractTest { - /** Marshaller. */ - private GridClientMarshaller marshaller = new GridClientOptimizedMarshaller(); - - /** Extras value. */ - public static final byte[] EXTRAS = new byte[]{ - (byte)0xDE, 0x00, (byte)0xBE, 0x00, //Flags, string encoding. - 0x00, 0x00, 0x00, 0x00 // Expiration value. - }; - - /** - * @throws Exception If failed. - */ - public void testSimplePacketParsing() throws Exception { - GridNioSession ses = new GridMockNioSession(); - - GridTcpRestParser parser = new GridTcpRestParser(); - - byte hdr = MEMCACHE_REQ_FLAG; - - byte[] opCodes = {0x01, 0x02, 0x03}; - - byte[] opaque = new byte[] {0x01, 0x02, 0x03, (byte)0xFF}; - - String key = "key"; - - String val = "value"; - - for (byte opCode : opCodes) { - ByteBuffer raw = rawPacket(hdr, opCode, opaque, key.getBytes(), val.getBytes(), EXTRAS); - - GridClientMessage msg = parser.decode(ses, raw); - - assertTrue(msg instanceof GridMemcachedMessage); - - GridMemcachedMessage packet = (GridMemcachedMessage)msg; - - assertEquals("Parser leaved unparsed bytes", 0, raw.remaining()); - - assertEquals("Invalid opcode", opCode, packet.operationCode()); - assertEquals("Invalid key", key, packet.key()); - assertEquals("Invalid value", val, packet.value()); - } - } - - /** - * @throws Exception If failed. - */ - public void testIncorrectPackets() throws Exception { - final GridNioSession ses = new GridMockNioSession(); - - final GridTcpRestParser parser = new GridTcpRestParser(); - - final byte[] opaque = new byte[] {0x01, 0x02, 0x03, (byte)0xFF}; - - final String key = "key"; - - final String val = "value"; - - GridTestUtils.assertThrows(log(), new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - parser.decode(ses, rawPacket((byte)0x01, (byte)0x01, opaque, key.getBytes(), val.getBytes(), EXTRAS)); - - return null; - } - }, IOException.class, null); - - - GridTestUtils.assertThrows(log(), new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - parser.decode(ses, rawPacket(MEMCACHE_REQ_FLAG, (byte)0x01, opaque, key.getBytes(), val.getBytes(), null)); - - return null; - } - }, IOException.class, null); - - GridTestUtils.assertThrows(log(), new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - ByteBuffer fake = ByteBuffer.allocate(21); - - fake.put(GRIDGAIN_REQ_FLAG); - fake.put(U.intToBytes(-5)); - fake.put(U.longToBytes(0)); - fake.put(U.longToBytes(0)); - - fake.flip(); - - parser.decode(ses, fake); - - return null; - } - }, IOException.class, null); - } - - /** - * @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 GridMockNioSession(); - - ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); - - GridTcpRestParser parser = new GridTcpRestParser(); - - 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()); - } - - /** - * @throws Exception If failed. - */ - public void testMixedParsing() throws Exception { - GridNioSession ses1 = new GridMockNioSession(); - GridNioSession ses2 = new GridMockNioSession(); - - ses1.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); - ses2.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); - - GridTcpRestParser parser = new GridTcpRestParser(); - - GridClientCacheRequest req = new GridClientCacheRequest(CAS); - - req.key("key"); - - String val = "value"; - - req.value(val); - req.value2(val); - req.clientId(UUID.randomUUID()); - - byte[] opaque = new byte[]{0x01, 0x02, 0x03, (byte)0xFF}; - - String key = "key"; - - ByteBuffer raw1 = rawPacket(MEMCACHE_REQ_FLAG, (byte)0x01, opaque, key.getBytes(), val.getBytes(), EXTRAS); - - ByteBuffer raw2 = clientRequestPacket(req); - - raw1.mark(); - - raw2.mark(); - - int splits = Math.min(raw1.remaining(), raw2.remaining()); - - for (int i = 1; i < splits; i++) { - ByteBuffer[] packet1 = split(raw1, i); - - ByteBuffer[] packet2 = split(raw2, i); - - GridClientMessage msg = parser.decode(ses1, packet1[0]); - - assertNull(msg); - - msg = parser.decode(ses2, packet2[0]); - - assertNull(msg); - - msg = parser.decode(ses1, packet1[1]); - - assertTrue(msg instanceof GridMemcachedMessage); - - assertEquals(key, ((GridMemcachedMessage)msg).key()); - assertEquals(val, ((GridMemcachedMessage)msg).value()); - - msg = parser.decode(ses2, packet2[1]); - - assertTrue(msg instanceof GridClientCacheRequest); - - assertEquals(val, ((GridClientCacheRequest)msg).value()); - assertEquals(val, ((GridClientCacheRequest)msg).value2()); - - raw1.reset(); - - raw2.reset(); - } - } - - /** - * @throws Exception If failed. - */ - public void testParseContinuousSplit() throws Exception { - ByteBuffer tmp = ByteBuffer.allocate(10 * 1024); - - GridClientCacheRequest req = new GridClientCacheRequest(CAS); - - req.key("key"); - req.value(1); - req.value2(2); - req.clientId(UUID.randomUUID()); - - for (int i = 0; i < 5; i++) - tmp.put(clientRequestPacket(req)); - - tmp.flip(); - - for (int splitPos = 0; splitPos < tmp.remaining(); splitPos++) { - ByteBuffer[] split = split(tmp, splitPos); - - tmp.flip(); - - GridNioSession ses = new GridMockNioSession(); - - ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); - - GridTcpRestParser parser = new GridTcpRestParser(); - - Collection<GridClientCacheRequest> lst = new ArrayList<>(5); - - for (ByteBuffer buf : split) { - GridClientCacheRequest r; - - while (buf.hasRemaining() && (r = (GridClientCacheRequest)parser.decode(ses, buf)) != null) - lst.add(r); - - assertTrue("Parser has left unparsed bytes.", buf.remaining() == 0); - } - - assertEquals(5, lst.size()); - - for (GridClientCacheRequest res : lst) { - 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()); - } - } - } - - /** - * Tests correct parsing of client handshake packets. - * - * @throws Exception If failed. - */ - public void testParseClientHandshake() throws Exception { - for (int splitPos = 1; splitPos < 5; splitPos++) { - log.info("Checking split position: " + splitPos); - - ByteBuffer tmp = clientHandshakePacket(); - - ByteBuffer[] split = split(tmp, splitPos); - - GridNioSession ses = new GridMockNioSession(); - - ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); - - GridTcpRestParser parser = new GridTcpRestParser(); - - Collection<GridClientMessage> lst = new ArrayList<>(1); - - for (ByteBuffer buf : split) { - GridClientMessage r; - - while (buf.hasRemaining() && (r = parser.decode(ses, buf)) != null) - lst.add(r); - - assertTrue("Parser has left unparsed bytes.", buf.remaining() == 0); - } - - assertEquals(1, lst.size()); - - GridClientHandshakeRequest req = (GridClientHandshakeRequest)F.first(lst); - - assertNotNull(req); - assertEquals(U.bytesToShort(new byte[] {5, 0}, 0), req.version()); - } - } - - /** - * Splits given byte buffer into two byte buffers. - * - * @param original Original byte buffer. - * @param pos Position at which buffer should be split. - * @return Array of byte buffers. - */ - private ByteBuffer[] split(ByteBuffer original, int pos) { - - byte[] data = new byte[pos]; - - original.get(data); - - ByteBuffer[] res = new ByteBuffer[2]; - - res[0] = ByteBuffer.wrap(data); - - data = new byte[original.remaining()]; - - original.get(data); - - res[1] = ByteBuffer.wrap(data); - - return res; - } - - /** - * Assembles GridGain client packet. - * - * @param msg Message to serialize. - * @return Raw message bytes. - * @throws IOException If serialization failed. - */ - private ByteBuffer clientRequestPacket(GridClientMessage msg) throws IOException { - ByteBuffer res = marshaller.marshal(msg, 45); - - ByteBuffer slice = res.slice(); - - slice.put(GRIDGAIN_REQ_FLAG); - slice.putInt(res.remaining() - 5); - slice.putLong(msg.requestId()); - slice.put(U.uuidToBytes(msg.clientId())); - slice.put(U.uuidToBytes(msg.destinationId())); - - return res; - } - - /** - * Assembles GridGain client handshake packet. - * - * @return Raw message bytes. - */ - private ByteBuffer clientHandshakePacket() { - ByteBuffer res = ByteBuffer.allocate(6); - - res.put(new byte[] { - GRIDGAIN_HANDSHAKE_FLAG, 5, 0, 0, 0, 0 - }); - - res.flip(); - - return res; - } - - /** - * Assembles raw packet without any logical checks. - * - * @param magic Header for packet. - * @param opCode Operation code. - * @param opaque Opaque value. - * @param key Key data. - * @param val Value data. - * @param extras Extras data. - * @return Byte buffer containing assembled packet. - */ - private ByteBuffer rawPacket(byte magic, byte opCode, byte[] opaque, @Nullable byte[] key, @Nullable byte[] val, - @Nullable byte[] extras) { - // 1k should be enough. - ByteBuffer res = ByteBuffer.allocate(1024); - - res.put(magic); - res.put(opCode); - - int keyLen = key == null ? 0 : key.length; - int extrasLen = extras == null ? 0 : extras.length; - int valLen = val == null ? 0 : val.length; - - res.putShort((short)keyLen); - res.put((byte)extrasLen); - - // Data type is always 0. - res.put((byte)0); - - // Reserved. - res.putShort((short)0); - - // Total body. - res.putInt(keyLen + extrasLen + valLen); - - // Opaque. - res.put(opaque); - - // CAS - res.putLong(0); - - if (extrasLen > 0) - res.put(extras); - - if (keyLen > 0) - res.put(key); - - if (valLen > 0) - res.put(val); - - res.flip(); - - return res; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientMarshallerBenchmarkTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientMarshallerBenchmarkTest.java b/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientMarshallerBenchmarkTest.java index a51f6dd..4802d4f 100644 --- a/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientMarshallerBenchmarkTest.java +++ b/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientMarshallerBenchmarkTest.java @@ -20,7 +20,7 @@ package org.gridgain.loadtests.client; import org.apache.ignite.client.marshaller.*; import org.apache.ignite.client.marshaller.jdk.*; import org.apache.ignite.client.marshaller.optimized.*; -import org.gridgain.grid.kernal.processors.rest.client.message.*; +import org.apache.ignite.internal.processors.rest.client.message.*; import org.apache.ignite.internal.util.typedef.*; import org.gridgain.testframework.junits.common.*; @@ -28,7 +28,7 @@ import java.io.*; import java.nio.*; import java.util.*; -import static org.gridgain.grid.kernal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*; +import static org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*; /** * Tests basic performance of marshallers. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java index 79eecb2..8c07038 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java @@ -22,7 +22,7 @@ import org.apache.ignite.logger.java.*; import org.apache.ignite.client.*; import org.apache.ignite.client.impl.*; import org.apache.ignite.client.util.*; -import org.gridgain.grid.kernal.processors.rest.client.message.*; +import org.apache.ignite.internal.processors.rest.client.message.*; import org.apache.ignite.plugin.security.*; import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.nio.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java index 799925a..51da3d7 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java +++ b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java @@ -23,7 +23,7 @@ import org.apache.ignite.client.impl.*; import org.apache.ignite.client.marshaller.*; import org.apache.ignite.client.marshaller.jdk.*; import org.apache.ignite.client.marshaller.optimized.*; -import org.gridgain.grid.kernal.processors.rest.client.message.*; +import org.apache.ignite.internal.processors.rest.client.message.*; import org.apache.ignite.internal.util.nio.*; import org.apache.ignite.internal.util.nio.ssl.*; import org.apache.ignite.internal.util.typedef.*; @@ -42,7 +42,7 @@ import java.util.logging.*; import static org.apache.ignite.client.GridClientCacheFlag.*; import static org.apache.ignite.client.impl.connection.GridClientConnectionCloseReason.*; -import static org.gridgain.grid.kernal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*; +import static org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*; /** * This class performs request to grid over tcp protocol. Serialization is performed with marshaller http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/client/marshaller/optimized/GridClientOptimizedMarshaller.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/client/marshaller/optimized/GridClientOptimizedMarshaller.java b/modules/core/src/main/java/org/apache/ignite/client/marshaller/optimized/GridClientOptimizedMarshaller.java index 0324a8e..5f42828 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/marshaller/optimized/GridClientOptimizedMarshaller.java +++ b/modules/core/src/main/java/org/apache/ignite/client/marshaller/optimized/GridClientOptimizedMarshaller.java @@ -20,7 +20,7 @@ package org.apache.ignite.client.marshaller.optimized; import org.apache.ignite.*; import org.apache.ignite.marshaller.optimized.*; import org.apache.ignite.client.marshaller.*; -import org.gridgain.grid.kernal.processors.rest.client.message.*; +import org.apache.ignite.internal.processors.rest.client.message.*; import java.io.*; import java.nio.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java index 958ac8c..e0539b3 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java @@ -23,7 +23,7 @@ import org.apache.ignite.logger.java.*; import org.apache.ignite.client.*; import org.apache.ignite.client.router.*; import org.apache.ignite.client.ssl.*; -import org.gridgain.grid.kernal.processors.rest.client.message.*; +import org.apache.ignite.internal.processors.rest.client.message.*; import org.apache.ignite.internal.util.nio.*; import org.apache.ignite.internal.util.nio.ssl.*; import org.apache.ignite.internal.util.typedef.internal.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioListenerAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioListenerAdapter.java b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioListenerAdapter.java index 47065e8..0b56bf2 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioListenerAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioListenerAdapter.java @@ -22,7 +22,7 @@ import org.apache.ignite.client.*; import org.apache.ignite.client.marshaller.*; import org.apache.ignite.client.marshaller.jdk.*; import org.apache.ignite.client.marshaller.optimized.*; -import org.gridgain.grid.kernal.processors.rest.client.message.*; +import org.apache.ignite.internal.processors.rest.client.message.*; import org.apache.ignite.internal.util.nio.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.jetbrains.annotations.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java index c6fc2e2..3debc9c 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java +++ b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java @@ -19,15 +19,15 @@ package org.apache.ignite.client.router.impl; import org.apache.ignite.*; import org.apache.ignite.client.marshaller.*; -import org.gridgain.grid.kernal.processors.rest.client.message.*; -import org.gridgain.grid.kernal.processors.rest.protocols.tcp.*; +import org.apache.ignite.internal.processors.rest.client.message.*; +import org.apache.ignite.internal.processors.rest.protocols.tcp.*; import org.apache.ignite.internal.util.nio.*; import org.apache.ignite.internal.util.typedef.internal.*; import java.io.*; import java.nio.*; -import static org.gridgain.grid.kernal.processors.rest.protocols.tcp.GridMemcachedMessage.*; +import static org.apache.ignite.internal.processors.rest.protocols.tcp.GridMemcachedMessage.*; /** * http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/internal/GridKernal.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernal.java index 51637cf..f3461a4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernal.java @@ -64,7 +64,7 @@ import org.apache.ignite.internal.processors.port.*; import org.gridgain.grid.kernal.processors.portable.*; import org.apache.ignite.internal.processors.query.*; import org.apache.ignite.internal.processors.resource.*; -import org.gridgain.grid.kernal.processors.rest.*; +import org.apache.ignite.internal.processors.rest.*; import org.apache.ignite.internal.processors.segmentation.*; import org.apache.ignite.internal.processors.service.*; import org.apache.ignite.internal.processors.session.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java index 5c648aa..abee238 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java @@ -52,7 +52,7 @@ import org.apache.ignite.internal.processors.port.*; import org.gridgain.grid.kernal.processors.portable.*; import org.apache.ignite.internal.processors.query.*; import org.apache.ignite.internal.processors.resource.*; -import org.gridgain.grid.kernal.processors.rest.*; +import org.apache.ignite.internal.processors.rest.*; import org.apache.ignite.internal.processors.schedule.*; import org.apache.ignite.internal.processors.segmentation.*; import org.apache.ignite.internal.processors.service.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java index 28164f3..a7986d2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java @@ -54,7 +54,7 @@ import org.apache.ignite.internal.processors.port.*; import org.gridgain.grid.kernal.processors.portable.*; import org.apache.ignite.internal.processors.query.*; import org.apache.ignite.internal.processors.resource.*; -import org.gridgain.grid.kernal.processors.rest.*; +import org.apache.ignite.internal.processors.rest.*; import org.apache.ignite.internal.processors.schedule.*; import org.apache.ignite.internal.processors.segmentation.*; import org.apache.ignite.internal.processors.service.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java new file mode 100644 index 0000000..fce6332 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.rest; + +import org.jetbrains.annotations.*; + +import java.util.*; + +/** + * Supported commands. + */ +public enum GridRestCommand { + /* + * API commands. + * ============= + */ + + /** Get cached value. */ + CACHE_GET("get"), + + /** Get several cached values. */ + CACHE_GET_ALL("getall"), + + /** Store value in cache. */ + CACHE_PUT("put"), + + /** Store value in cache if it doesn't exist. */ + CACHE_ADD("add"), + + /** Store several values in cache. */ + CACHE_PUT_ALL("putall"), + + /** Remove value from cache. */ + CACHE_REMOVE("rmv"), + + /** Remove several values from cache. */ + CACHE_REMOVE_ALL("rmvall"), + + /** Replace cache value only if there is currently a mapping for it. */ + CACHE_REPLACE("rep"), + + /** Increment. */ + CACHE_INCREMENT("incr"), + + /** Decrement. */ + CACHE_DECREMENT("decr"), + + /** Compare and set. */ + CACHE_CAS("cas"), + + /** Append. */ + CACHE_APPEND("append"), + + /** Prepend. */ + CACHE_PREPEND("prepend"), + + /** Cache metrics. */ + CACHE_METRICS("cache"), + + /** Grid topology. */ + TOPOLOGY("top"), + + /** Single node info. */ + NODE("node"), + + /** Task execution .*/ + EXE("exe"), + + /** Task execution .*/ + RESULT("res"), + + /** Version. */ + VERSION("version"), + + /** Log. */ + LOG("log"), + + /** No-op. */ + NOOP("noop"), + + /** Quit. */ + QUIT("quit"), + + /** Start query execution. */ + CACHE_QUERY_EXECUTE("queryexecute"), + + /** Fetch query results. */ + CACHE_QUERY_FETCH("queryfetch"), + + /** Rebuild indexes. */ + CACHE_QUERY_REBUILD_INDEXES("rebuildqueryindexes"), + + /** Put portable metadata. */ + PUT_PORTABLE_METADATA("putportablemetadata"), + + /** Get portable metadata. */ + GET_PORTABLE_METADATA("getportablemetadata"); + + /** Enum values. */ + private static final GridRestCommand[] VALS = values(); + + /** Key to enum map. */ + private static final Map<String, GridRestCommand> cmds = new HashMap<>(); + + /** + * Map keys to commands. + */ + static { + for (GridRestCommand cmd : values()) + cmds.put(cmd.key(), cmd); + } + + /** Command key. */ + private final String key; + + /** + * @param key Key. + */ + GridRestCommand(String key) { + this.key = key; + } + + /** + * @param ord Byte to convert to enum. + * @return Enum. + */ + @Nullable public static GridRestCommand fromOrdinal(int ord) { + return ord >= 0 && ord < VALS.length ? VALS[ord] : null; + } + + /** + * @param key Key. + * @return Command. + */ + @Nullable public static GridRestCommand fromKey(String key) { + return cmds.get(key); + } + + /** + * @return Command key. + */ + public String key() { + return key; + } +}
