You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by iv...@apache.org on 2015/07/21 13:25:23 UTC

[29/29] incubator-ignite git commit: Merge remote-tracking branch 'remotes/origin/ignite-961-master' into ignite-961

Merge remote-tracking branch 'remotes/origin/ignite-961-master' into ignite-961

Conflicts:
	modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
	modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
	modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
	modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
	modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
	modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4699dd88
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4699dd88
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4699dd88

Branch: refs/heads/ignite-961
Commit: 4699dd88496de54d6cb95ccd669d7738ce036dc3
Parents: 4e2f26b cab277b
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jul 21 14:24:30 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jul 21 14:24:30 2015 +0300

----------------------------------------------------------------------
 .../JettyRestProcessorAbstractSelfTest.java     | 489 ++++++++++---------
 .../apache/ignite/internal/IgniteKernal.java    |  42 +-
 .../processors/rest/GridRestProcessor.java      |  13 +
 .../handlers/cache/GridCacheCommandHandler.java |  70 +--
 .../handlers/query/QueryCommandHandler.java     |  80 ++-
 .../http/jetty/GridJettyRestHandler.java        |  57 +++
 6 files changed, 414 insertions(+), 337 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4699dd88/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --cc modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
index 5baab05,55d60d2..4734ecc
--- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
@@@ -72,6 -70,6 +72,12 @@@ public abstract class JettyRestProcesso
      }
  
      /**
++     * @return Signature.
++     * @throws Exception If failed.
++     */
++    protected abstract String signature() throws Exception;
++
++    /**
       * @return Port to use for rest. Needs to be changed over time
       *      because Jetty has some delay before port unbind.
       */
@@@ -380,132 -311,37 +385,238 @@@
          assertNull(grid(0).cache("testCache"));
      }
  
++
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testGetPost() throws Exception {
 +        jcache().put("key0", "val0");
 +
 +        String val = "{\"key\":\"key0\"}";
 +        String ret = makePostRequest(F.asMap("cmd", "get"), val);
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        info("Get command result: " + ret);
 +
 +        jsonEquals(ret, cachePattern("val0", true));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testReplacePost() throws Exception {
 +        jcache().put("key0", "val0");
 +
 +        String val = "{\"key\":\"key0\", \"val\":\"val2\", \"oldVal\":\"val1\"}";
 +        String ret = makePostRequest(F.asMap("cmd", "repval"), val);
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        info("Get command result: " + ret);
 +
 +        jsonEquals(ret, cachePattern(false, true));
 +
 +        val = "{\"key\":\"key0\", \"val\":\"val2\"}";
 +        ret = makePostRequest(F.asMap("cmd", "getandreplace"), val);
 +
 +        jsonEquals(ret, cachePattern("val0", true));
 +
 +        assertEquals("val2", grid(0).cache(null).get("key0"));
 +
 +        val = "{\"key\":\"key0\", \"val\":\"val3\"}";
 +        ret = makePostRequest(F.asMap("cmd", "rep"), val);
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        info("Get command result: " + ret);
 +
 +        assertEquals("val3", grid(0).cache(null).get("key0"));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testRemovePost() throws Exception {
 +        jcache().put("key0", "val0");
 +
 +        String val = "{\"key\":\"key0\", \"val\":\"val2\"}";
 +        String ret = makePostRequest(F.asMap("cmd", "rmvvalue"), val);
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        info("Get command result: " + ret);
 +
 +        jsonEquals(ret, cachePattern(false, true));
 +
 +        assertEquals("val0", grid(0).cache(null).get("key0"));
 +
 +        val = "{\"key\":\"key0\"}";
 +        ret = makePostRequest(F.asMap("cmd", "getandrmv"), val);
 +
 +        jsonEquals(ret, cachePattern("val0", true));
 +
 +        assertNull(grid(0).cache(null).get("key0"));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testRemoveAllPost() throws Exception {
 +        jcache().put("key0", "val0");
 +        jcache().put("key1", "val1");
 +
 +        String val = "{\"keys\": [\"key0\", \"key1\"]}";
 +        String ret = makePostRequest(F.asMap("cmd", "rmvall"), val);
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        assertEquals(0, grid(0).cache(null).size());
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testPutPost() throws Exception {
 +        String val = "{\"key\":\"key0\",\"val\":\"val0\"}";
 +        String ret = makePostRequest(F.asMap("cmd", "put"), val);
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        assertNotNull(grid(0).cache(null).get("key0"));
 +
 +        val = "{\"key\":\"key0\"}";
 +        ret = makePostRequest(F.asMap("cmd", "containskey"), val);
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        jsonEquals(ret, cachePattern(true, true));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testIncorrectPutPost() throws Exception {
 +        String val = "{\"key\":\"key0\"}";
 +        String ret = makePostRequest(F.asMap("cmd", "put"), val);
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +        jsonEquals(ret, errorPattern("Failed to find mandatory parameter in request: val"));
 +    }
 +
++
++    /**
++     * @throws Exception If failed.
++     */
++    public void testGetAndPutPost() throws Exception {
++        String val = "{\"key\":\"key0\", \"val\":\"val0\"}";
++        String ret = makePostRequest(F.asMap("cmd", "getandput"), val);
++
++        assertNotNull(ret);
++        assertTrue(!ret.isEmpty());
++
++        jsonEquals(ret, cacheNullPattern(true));
++
++        assertNotNull(grid(0).cache(null).get("key0"));
++
++        val = "{\"key\": \"key0\", \"val\":\"val1\"}";
++        ret = makePostRequest(F.asMap("cmd", "getandputifabsent"), val);
++
++        assertNotNull(ret);
++        assertTrue(!ret.isEmpty());
++
++        jsonEquals(ret, cachePattern("val0", true));
++
++        assertEquals("val0", grid(0).cache(null).get("key0"));
++
++        val = "{\"key\": \"key0\"}";
++        ret = makePostRequest(F.asMap("cmd", "rmv"), val);
++
++        assertNotNull(ret);
++        assertTrue(!ret.isEmpty());
++
++        assertNull(grid(0).cache(null).get("key0"));
++
++        val = "{\"key\": \"key0\", \"val\":\"val1\"}";
++        ret = makePostRequest(F.asMap("cmd", "putifabsent"), val);
++
++        assertNotNull(ret);
++        assertTrue(!ret.isEmpty());
++
++        jsonEquals(ret, cachePattern(true, true));
++
++        assertEquals("val1", grid(0).cache(null).get("key0"));
++    }
++
++    /**
++     * @throws Exception If failed.
++     */
++    public void testPutAllPost() throws Exception {
++        String val = "{\"entries\": [{\"key\":\"key0\", \"value\": \"val0\"}, {\"key\":\"key1\", \"value\":\"val1\"}]}";
++        String ret = makePostRequest(F.asMap("cmd", "putAll"), val);
++
++        assertNotNull(ret);
++        assertTrue(!ret.isEmpty());
++
++        assertNotNull(grid(0).cache(null).get("key0"));
++
++        val = "{\"keys\": [\"key0\",\"key1\"]}";
++        ret = makePostRequest(F.asMap("cmd", "containskeys"), val);
++
++        assertNotNull(ret);
++        assertTrue(!ret.isEmpty());
++
++        jsonEquals(ret, cacheBulkPattern(true, true));
++
++        ret = makePostRequest(F.asMap("cmd", "getAll"), val);
++
++        assertNotNull(ret);
++        assertTrue(!ret.isEmpty());
++
++        jsonEquals(ret, cacheBulkPattern(
++            "\\[\\{\\\"key\\\":\\\"key0\\\",\\\"value\\\":\\\"val0\\\"\\}," +
++                "\\{\\\"key\\\":\\\"key1\\\",\\\"value\\\":\\\"val1\\\"\\}\\]", true));
++    }
++
+     /**
+      * @throws Exception If failed.
+      */
+     public void testGetAll() throws Exception {
+         jcache().put("getKey1", "getVal1");
+         jcache().put("getKey2", "getVal2");
+ 
+         String ret = content(F.asMap("cmd", "getall", "k1", "getKey1", "k2", "getKey2"));
+ 
+         assertNotNull(ret);
+         assertTrue(!ret.isEmpty());
+ 
+         info("Get all command result: " + ret);
+ 
+         jsonEquals(ret,
+             // getKey[12] is used since the order is not determined.
+             cacheBulkPattern("\\{\\\"getKey[12]\\\":\\\"getVal[12]\\\"\\,\\\"getKey[12]\\\":\\\"getVal[12]\\\"\\}",
+                 true));
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testIncorrectPut() throws Exception {
+         String ret = content(F.asMap("cmd", "put", "key", "key0"));
+ 
+         assertNotNull(ret);
+         assertTrue(!ret.isEmpty());
+         jsonEquals(ret, errorPattern("Failed to find mandatory parameter in request: val"));
+     }
+ 
      /**
       * @throws Exception If failed.
       */
@@@ -1243,271 -986,154 +1261,324 @@@
      /**
       * @throws Exception If failed.
       */
+     public void testQueryArgs() throws Exception {
+         String qry = "salary > ? and salary <= ?";
+ 
+         Map<String, String> params = new HashMap<>();
+         params.put("cmd", "qryexecute");
+         params.put("type", "Person");
+         params.put("psz", "10");
+         params.put("cacheName", "person");
+         params.put("qry", URLEncoder.encode(qry));
+         params.put("arg1", "1000");
+         params.put("arg2", "2000");
+ 
+         String ret = content(params);
+ 
+         assertNotNull(ret);
+         assertTrue(!ret.isEmpty());
+ 
+         JSONObject json = JSONObject.fromObject(ret);
+ 
+         List items = (List)((Map)json.get("response")).get("items");
+ 
+         assertEquals(2, items.size());
+ 
+         assertFalse(queryCursorFound());
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testQuery() throws Exception {
+         grid(0).cache(null).put("1", "1");
+         grid(0).cache(null).put("2", "2");
+         grid(0).cache(null).put("3", "3");
+ 
+         Map<String, String> params = new HashMap<>();
+         params.put("cmd", "qryexecute");
+         params.put("type", "String");
+         params.put("psz", "1");
+         params.put("qry", URLEncoder.encode("select * from String"));
+ 
+         String ret = content(params);
+ 
+         assertNotNull(ret);
+         assertTrue(!ret.isEmpty());
+ 
+         JSONObject json = JSONObject.fromObject(ret);
+ 
+         Integer qryId = (Integer)((Map)json.get("response")).get("queryId");
+ 
+         assertNotNull(qryId);
+ 
+         ret = content(F.asMap("cmd", "qryfetch", "psz", "1", "qryId", String.valueOf(qryId)));
+ 
+         json = JSONObject.fromObject(ret);
+ 
+         Integer qryId0 = (Integer)((Map)json.get("response")).get("queryId");
+ 
+         Boolean last = (Boolean)((Map)json.get("response")).get("last");
+ 
+         assertEquals(qryId0, qryId);
+         assertFalse(last);
+ 
+         ret = content(F.asMap("cmd", "qryfetch", "psz", "1", "qryId", String.valueOf(qryId)));
+ 
+         json = JSONObject.fromObject(ret);
+ 
+         qryId0 = (Integer)((Map)json.get("response")).get("queryId");
+ 
+         last = (Boolean)((Map)json.get("response")).get("last");
+ 
+         assertEquals(qryId0, qryId);
+         assertTrue(last);
+ 
+         assertFalse(queryCursorFound());
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testSqlFieldsQuery() throws Exception {
+         String qry = "select concat(firstName, ' ', lastName) from Person";
+ 
+         Map<String, String> params = new HashMap<>();
+         params.put("cmd", "qryfieldsexecute");
+         params.put("psz", "10");
+         params.put("cacheName", "person");
+         params.put("qry", URLEncoder.encode(qry));
+ 
+         String ret = content(params);
+ 
+         assertNotNull(ret);
+         assertTrue(!ret.isEmpty());
+ 
+         JSONObject json = JSONObject.fromObject(ret);
+ 
+         List items = (List)((Map)json.get("response")).get("items");
+ 
+         assertEquals(4, items.size());
+ 
+         assertFalse(queryCursorFound());
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testQueryClose() throws Exception {
+         String qry = "salary > ? and salary <= ?";
+ 
+         Map<String, String> params = new HashMap<>();
+         params.put("cmd", "qryexecute");
+         params.put("type", "Person");
+         params.put("psz", "1");
+         params.put("cacheName", "person");
+         params.put("qry", URLEncoder.encode(qry));
+         params.put("arg1", "1000");
+         params.put("arg2", "2000");
+ 
+         String ret = content(params);
+ 
+         assertNotNull(ret);
+         assertTrue(!ret.isEmpty());
+ 
+         JSONObject json = JSONObject.fromObject(ret);
+ 
+         List items = (List)((Map)json.get("response")).get("items");
+ 
+         assertEquals(1, items.size());
+ 
+         assertTrue(queryCursorFound());
+ 
+         Integer qryId = (Integer)((Map)json.get("response")).get("queryId");
+ 
+         assertNotNull(qryId);
+ 
+         ret = content(F.asMap("cmd", "qryclose", "cacheName", "person", "qryId", String.valueOf(qryId)));
+ 
+         assertNotNull(ret);
+         assertTrue(!ret.isEmpty());
+ 
+         assertFalse(queryCursorFound());
+     }
+ 
 -    protected abstract String signature() throws Exception;
++
++
++    /**
++     * @throws Exception If failed.
++     */
 +    public void testRunScriptPost() throws Exception {
 +        String f = "function(param){return param;}";
 +        String ret = makePostRequest(F.asMap("cmd", "runscript", "func", URLEncoder.encode(f)), "{\"arg\":\"hello\"}");
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        jsonEquals(ret, stringPattern("hello", true));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testRunScript() throws Exception {
 +        String f = "function(param){return param;}";
 +        String ret = content(F.asMap("cmd", "runscript", "func", URLEncoder.encode(f), "arg", "hello"));
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        jsonEquals(ret, stringPattern("hello", true));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testRunAffinityScriptPost() throws Exception {
 +        ClusterNode node = grid(0).affinity(null).mapKeyToNode("key0");
 +
 +        Ignite ignite = null;
 +
 +        for (int i = 0; i < GRID_CNT; ++i) {
 +            if (grid(i).localNode().equals(node))
 +                ignite = grid(i);
 +        }
 +
 +        assertNotNull(ignite);
 +
 +        String f = "function(expName){"+
 +            "if (expName !== \"hello\") {" +
 +            "throw \"Not correct arg.\"" +
 +            "}" +
 +            "return ignite.name();}";
 +
 +        String ret = makePostRequest(F.asMap("cmd", "affrun", "func", URLEncoder.encode(f)),
 +            "{\"arg\":\"" + "hello" + "\",\"key\":\"key0\"}");
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        jsonEquals(ret, stringPattern(ignite.name(), true));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testRunAffinityScript() throws Exception {
 +        ClusterNode node = grid(0).affinity(null).mapKeyToNode("key0");
 +
 +        Ignite ignite = null;
 +
 +        for (int i = 0; i < GRID_CNT; ++i) {
 +            if (grid(i).localNode().equals(node))
 +                ignite = grid(i);
 +        }
 +
 +        assertNotNull(ignite);
 +
 +        String f = "function(expName){"+
 +            "if (expName !== \"hello\") {" +
 +            "throw \"Not correct arg.\"" +
 +            "}" +
 +            "return ignite.name();}";
 +
 +        String ret = content(F.asMap("cmd", "affrun", "func", URLEncoder.encode(f),
 +            "key", "key0", "arg", "hello"));
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        jsonEquals(ret, stringPattern(ignite.name(), true));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testMapReduceScriptPost() throws Exception {
 +        String map = "function(nodes, arg) {" +
 +            "var words = arg.split(\" \");" +
 +            "for (var i = 0; i < words.length; i++) {" +
 +            "var f = function(word) {" +
 +            "return word.length;" +
 +            "};" +
 +            "emit(f, words[i], nodes[i %  nodes.length]);" +
 +            "}"+
 +            "};";
 +
 +        String reduce =  "function(results) {"+
 +            "var sum = 0;"+
 +            "for (var i = 0; i < results.size(); ++i) {"+
 +            "sum += results.get(i).intValue();"+
 +            "}" +
 +            "return sum;" +
 +            "};";
 +
 +        String ret = makePostRequest(F.asMap("cmd", "excmapreduce", "map", URLEncoder.encode(map),
 +            "reduce", URLEncoder.encode(reduce)), "{\"arg\": \"Hello world!\"}");
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        jsonEquals(ret, integerPattern(11, true));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testMapReduceScript() throws Exception {
 +        String map = "function(nodes, arg) {" +
 +            "var words = arg.split(\" \");" +
 +            "for (var i = 0; i < words.length; i++) {" +
 +            "var f = function(word) {" +
 +            "return word.length;" +
 +            "};" +
 +            "emit(f, words[i], nodes[i %  nodes.length]);" +
 +            "}"+
 +            "};";
 +
 +        String reduce =  "function(results) {"+
 +            "var sum = 0;"+
 +            "for (var i = 0; i < results.size(); ++i) {"+
 +            "sum += results.get(i).intValue();"+
 +            "}" +
 +            "return sum;" +
 +            "};";
 +
 +        String ret = content(F.asMap("cmd", "excmapreduce", "map", URLEncoder.encode(map),
 +            "reduce", URLEncoder.encode(reduce), "arg", URLEncoder.encode("Hello world!")));
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        jsonEquals(ret, integerPattern(11, true));
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
-     public void testQuery() throws Exception {
-         grid(0).cache(null).put("1", "1");
-         grid(0).cache(null).put("2", "2");
-         grid(0).cache(null).put("3", "3");
- 
-         String ret = makePostRequest(F.asMap("cmd", "qryexecute", "type", "String", "psz", "1",
-                 "qry", URLEncoder.encode("select * from String")),
-             "{\"arg\": []}");
- 
-         assertNotNull(ret);
-         assertTrue(!ret.isEmpty());
- 
-         JSONObject json = JSONObject.fromObject(ret);
- 
-         Integer qryId = (Integer)((Map)json.get("response")).get("queryId");
- 
-         assertNotNull(qryId);
- 
-         ret = content(F.asMap("cmd", "qryfetch", "psz", "1", "qryId", String.valueOf(qryId)));
- 
-         json = JSONObject.fromObject(ret);
- 
-         Integer qryId0 = (Integer)((Map)json.get("response")).get("queryId");
- 
-         assertEquals(qryId0, qryId);
- 
-         ret = content(F.asMap("cmd", "qryclose", "qryId", String.valueOf(qryId)));
-     }
- 
-     /**
-      * @throws Exception If failed.
-      */
 +    public void testQueryArgsPost() throws Exception {
 +        String qry = "salary > ? and salary <= ?";
 +
 +        String ret = makePostRequest(F.asMap("cmd", "qryexecute", "type", "Person", "psz", "10", "cacheName", "person",
 +                "qry", URLEncoder.encode(qry)),
 +            "{\"arg\": [1000, 2000]}");
 +
 +        assertNotNull(ret);
 +        assertTrue(!ret.isEmpty());
 +
 +        JSONObject json = JSONObject.fromObject(ret);
 +
 +        List items = (List)((Map)json.get("response")).get("items");
 +
 +        assertEquals(2, items.size());
 +
-         for (int i = 0; i < GRID_CNT; ++i) {
-             Map<GridRestCommand, GridRestCommandHandler> handlers =
-                 GridTestUtils.getFieldValue(grid(i).context().rest(), "handlers");
- 
-             GridRestCommandHandler qryHnd = handlers.get(GridRestCommand.CLOSE_SQL_QUERY);
- 
-             ConcurrentHashMap<Long, Iterator> its = GridTestUtils.getFieldValue(qryHnd, "curs");
- 
-             assertEquals(0, its.size());
-         }
-     }
- 
-     /**
-      * @throws Exception If failed.
-      */
-     public void testQueryArgs() throws Exception {
-         String qry = "salary > ? and salary <= ?";
- 
-         Map<String, String> params = new HashMap<>();
-         params.put("cmd", "qryexecute");
-         params.put("type", "Person");
-         params.put("psz", "10");
-         params.put("cacheName", "person");
-         params.put("qry", URLEncoder.encode(qry));
-         params.put("arg1", "1000");
-         params.put("arg2", "2000");
- 
-         String ret = content(params);
- 
-         assertNotNull(ret);
-         assertTrue(!ret.isEmpty());
- 
-         JSONObject json = JSONObject.fromObject(ret);
- 
-         List items = (List)((Map)json.get("response")).get("items");
- 
-         assertEquals(2, items.size());
- 
-         for (int i = 0; i < GRID_CNT; ++i) {
-             Map<GridRestCommand, GridRestCommandHandler> handlers =
-                 GridTestUtils.getFieldValue(grid(i).context().rest(), "handlers");
- 
-             GridRestCommandHandler qryHnd = handlers.get(GridRestCommand.CLOSE_SQL_QUERY);
- 
-             ConcurrentHashMap<Long, Iterator> its = GridTestUtils.getFieldValue(qryHnd, "curs");
- 
-             assertEquals(0, its.size());
-         }
++        assertFalse(queryCursorFound());
 +    }
  
      /**
-      * @throws Exception If failed.
+      * @return True if any query cursor is available.
       */
-     public void testQueryClose() throws Exception {
-         String qry = "salary > ? and salary <= ?";
- 
-         String ret = makePostRequest(F.asMap("cmd", "qryexecute", "type", "Person", "psz", "1", "cacheName", "person",
-                 "qry", URLEncoder.encode(qry)),
-             "{\"arg\": [1000, 2000]}");
- 
-         assertNotNull(ret);
-         assertTrue(!ret.isEmpty());
- 
-         JSONObject json = JSONObject.fromObject(ret);
- 
-         List items = (List)((Map)json.get("response")).get("items");
- 
-         assertEquals(1, items.size());
- 
+     private boolean queryCursorFound() {
          boolean found = false;
  
          for (int i = 0; i < GRID_CNT; ++i) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4699dd88/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4699dd88/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4699dd88/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
index 6eb2e20,defca37..1f92bf3
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
@@@ -188,8 -178,8 +178,8 @@@ public class QueryCommandHandler extend
  
          /** {@inheritDoc} */
          @Override public GridRestResponse call() throws Exception {
--            try {
-                 QueryCursor cur = qryCurs.get(req.queryId());
++            try { 
+                 QueryCursor cur = qryCurs.get(req.queryId()).get1();
  
                  if (cur == null)
                      return new GridRestResponse(GridRestResponse.STATUS_FAILED,

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4699dd88/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --cc modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index 2d8fa3e,bf0f2c8..ebe2119
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@@ -576,112 -469,63 +576,169 @@@ public class GridJettyRestHandler exten
                  break;
              }
  
+             case EXECUTE_SQL_QUERY:
+             case EXECUTE_SQL_FIELDS_QUERY: {
+                 RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
+ 
+                 restReq0.sqlQuery((String) params.get("qry"));
+ 
+                 restReq0.arguments(values("arg", params).toArray());
+ 
+                 restReq0.typeName((String) params.get("type"));
+ 
+                 String psz = (String) params.get("psz");
+ 
+                 if (psz != null)
+                     restReq0.pageSize(Integer.parseInt(psz));
+ 
+                 restReq0.cacheName((String)params.get("cacheName"));
+ 
+                 restReq = restReq0;
+ 
+                 break;
+             }
+ 
+             case FETCH_SQL_QUERY: {
+                 RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
+ 
+                 String qryId = (String) params.get("qryId");
+ 
+                 if (qryId != null)
+                     restReq0.queryId(Long.parseLong(qryId));
+ 
+                 String psz = (String) params.get("psz");
+ 
+                 if (psz != null)
+                     restReq0.pageSize(Integer.parseInt(psz));
+ 
+                 restReq0.cacheName((String)params.get("cacheName"));
+ 
+                 restReq = restReq0;
+ 
+                 break;
+             }
+ 
+             case CLOSE_SQL_QUERY: {
+                 RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
+ 
+                 String qryId = (String) params.get("qryId");
+ 
+                 if (qryId != null)
+                     restReq0.queryId(Long.parseLong(qryId));
+ 
+                 restReq0.cacheName((String)params.get("cacheName"));
+ 
+                 restReq = restReq0;
+ 
+                 break;
+             }
+ 
 +            case RUN_SCRIPT: {
 +                RestRunScriptRequest restReq0 = new RestRunScriptRequest();
 +
 +                restReq0.script((String)params.get("func"));
 +
 +                if (req.getHeader("Content-Type") != null && req.getHeader("Content-Type").contains("json")) {
 +                    Map o = parseRequest(req);
 +                    restReq0.argument(ctx.scripting().toJavaObject(o.get("arg")));
 +                }
 +                else
 +                    restReq0.argument(params.get("arg"));
 +
 +                restReq = restReq0;
 +
 +                break;
 +            }
 +
 +            case AFFINITY_RUN_SCRIPT: {
 +                RestRunScriptRequest restReq0 = new RestRunScriptRequest();
 +
 +                restReq0.script((String)params.get("func"));
 +                restReq0.cacheName((String) params.get("cacheName"));
 +
 +                if (req.getHeader("Content-Type") != null && req.getHeader("Content-Type").contains("json")) {
 +                    Map o = parseRequest(req);
 +                    restReq0.argument(ctx.scripting().toJavaObject(o.get("arg")));
 +
 +                    Object cacheObj = ctx.scripting().toJavaObject(o.get("key"));
 +                    restReq0.affinityKey(cacheObj);
 +                }
 +                else {
 +                    restReq0.argument(params.get("arg"));
 +                    restReq0.affinityKey(params.get("key"));
 +                }
 +
 +                restReq = restReq0;
 +
 +                break;
 +            }
 +
 +            case EXECUTE_MAP_REDUCE_SCRIPT: {
 +                RestMapReduceScriptRequest restReq0 = new RestMapReduceScriptRequest();
 +
 +                restReq0.mapFunction((String) params.get("map"));
 +
 +
 +                if (req.getHeader("Content-Type") != null && req.getHeader("Content-Type").contains("json")) {
 +                    Map o = parseRequest(req);
 +                    restReq0.argument(ctx.scripting().toJavaObject(o.get("arg")));
 +                }
 +                else
 +                    restReq0.argument(params.get("arg"));
 +
 +                restReq0.reduceFunction((String) params.get("reduce"));
 +
 +                restReq = restReq0;
 +
 +                break;
 +            }
 +
 +            case EXECUTE_SQL_QUERY:
 +            case EXECUTE_SQL_FIELDS_QUERY: {
 +                RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
 +
 +                restReq0.sqlQuery((String) params.get("qry"));
 +
 +                if (req.getHeader("Content-Type") != null && req.getHeader("Content-Type").contains("json")) {
 +                    Map o = parseRequest(req);
 +                    List args = (List) ctx.scripting().toJavaObject(o.get("arg"));
 +                    restReq0.arguments(args.toArray());
 +                }
 +                else
 +                    restReq0.arguments(values("arg", params).toArray());
 +
 +                restReq0.typeName((String)params.get("type"));
 +                restReq0.pageSize(Integer.parseInt((String) params.get("psz")));
 +                restReq0.cacheName((String)params.get("cacheName"));
 +
 +                restReq = restReq0;
 +
 +                break;
 +            }
 +
 +            case FETCH_SQL_QUERY: {
 +                RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
 +
 +                restReq0.queryId(Long.parseLong((String)params.get("qryId")));
 +                restReq0.pageSize(Integer.parseInt((String)params.get("psz")));
 +                restReq0.cacheName((String)params.get("cacheName"));
 +
 +                restReq = restReq0;
 +
 +                break;
 +            }
 +
 +            case CLOSE_SQL_QUERY: {
 +                RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
 +
 +                restReq0.queryId(Long.parseLong((String)params.get("qryId")));
 +                restReq0.cacheName((String)params.get("cacheName"));
 +
 +                restReq = restReq0;
 +
 +                break;
 +            }
 +
              default:
                  throw new IgniteCheckedException("Invalid command: " + cmd);
          }