IGNITE-5649: Get meta for the specified cache via REST. - Fixes #2292.

Signed-off-by: shroman <rsht...@yahoo.com>


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

Branch: refs/heads/ignite-5578-locJoin
Commit: 621b0ede7c75260f820ba5fe43850da871541e98
Parents: b95c261
Author: shroman <rsht...@yahoo.com>
Authored: Sat Jul 15 10:11:09 2017 +0900
Committer: shroman <rsht...@yahoo.com>
Committed: Sat Jul 15 10:11:09 2017 +0900

----------------------------------------------------------------------
 .../JettyRestProcessorAbstractSelfTest.java     | 50 ++++++++----
 .../ignite/compute/ComputeJobAdapter.java       |  2 +-
 .../cache/query/GridCacheQueryManager.java      | 11 +--
 .../handlers/cache/GridCacheCommandHandler.java | 82 +++++++++++++++-----
 4 files changed, 105 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/621b0ede/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git 
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
index 97321a7..7bc26cd 100644
--- 
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
@@ -1040,11 +1040,8 @@ public abstract class JettyRestProcessorAbstractSelfTest 
extends AbstractRestPro
      * @param metas Metadata for Ignite caches.
      * @throws Exception If failed.
      */
-    private void testMetadata(Collection<GridCacheSqlMetadata> metas, String 
ret) throws Exception {
-        JsonNode arr = jsonResponse(ret);
-
+    private void testMetadata(Collection<GridCacheSqlMetadata> metas, JsonNode 
arr) throws Exception {
         assertTrue(arr.isArray());
-        assertEquals(metas.size(), arr.size());
 
         for (JsonNode item : arr) {
             JsonNode cacheNameNode = item.get("cacheName");
@@ -1127,17 +1124,32 @@ public abstract class 
JettyRestProcessorAbstractSelfTest extends AbstractRestPro
 
         Collection<GridCacheSqlMetadata> metas = 
cache.context().queries().sqlMetadata();
 
-        String ret = content(F.asMap("cacheName", DEFAULT_CACHE_NAME, "cmd", 
GridRestCommand.CACHE_METADATA.key()));
+        assertEquals(5, metas.size());
+
+        String ret = content(F.asMap("cacheName", "", "cmd", 
GridRestCommand.CACHE_METADATA.key()));
 
         info("Cache metadata: " + ret);
 
-        testMetadata(metas, ret);
+        JsonNode arrResponse = jsonResponse(ret);
 
-        ret = content(F.asMap("cacheName", DEFAULT_CACHE_NAME, "cmd", 
GridRestCommand.CACHE_METADATA.key(), "cacheName", "person"));
+        assertEquals(5, arrResponse.size());
 
-        info("Cache metadata with cacheName parameter: " + ret);
+        testMetadata(metas, arrResponse);
+
+        Collection<GridCacheSqlMetadata> dfltCacheMeta = 
cache.context().queries().sqlMetadata();
+
+        ret = content(F.asMap("cacheName", DEFAULT_CACHE_NAME, "cmd", 
GridRestCommand.CACHE_METADATA.key()));
+
+        info("Cache metadata: " + ret);
+
+        arrResponse = jsonResponse(ret);
 
-        testMetadata(metas, ret);
+        assertEquals(1, arrResponse.size());
+
+        testMetadata(dfltCacheMeta, arrResponse);
+
+        assertResponseContainsError(content(
+            F.asMap("cacheName", "nonExistingCacheName", "cmd", 
GridRestCommand.CACHE_METADATA.key())));
     }
 
     /**
@@ -1153,17 +1165,29 @@ public abstract class 
JettyRestProcessorAbstractSelfTest extends AbstractRestPro
 
         Collection<GridCacheSqlMetadata> metas = 
c.context().queries().sqlMetadata();
 
-        String ret = content(F.asMap("cacheName", DEFAULT_CACHE_NAME, "cmd", 
GridRestCommand.CACHE_METADATA.key()));
+        String ret = content(F.asMap("cacheName", "", "cmd", 
GridRestCommand.CACHE_METADATA.key()));
 
         info("Cache metadata: " + ret);
 
-        testMetadata(metas, ret);
+        JsonNode arrResponse = jsonResponse(ret);
+
+        assertEquals(6, arrResponse.size());
+
+        testMetadata(metas, arrResponse);
 
-        ret = content(F.asMap("cacheName", DEFAULT_CACHE_NAME, "cmd", 
GridRestCommand.CACHE_METADATA.key(), "cacheName", "person"));
+        ret = content(F.asMap("cacheName", DEFAULT_CACHE_NAME,
+            "cmd", GridRestCommand.CACHE_METADATA.key(), "cacheName", 
"person"));
 
         info("Cache metadata with cacheName parameter: " + ret);
 
-        testMetadata(metas, ret);
+        arrResponse = jsonResponse(ret);
+
+        assertEquals(1, arrResponse.size());
+
+        testMetadata(metas, arrResponse);
+
+        assertResponseContainsError(content(
+            F.asMap("cacheName", "nonExistingCacheName", "cmd", 
GridRestCommand.CACHE_METADATA.key())));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/621b0ede/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAdapter.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAdapter.java 
b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAdapter.java
index 43465a6..3d1c308 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAdapter.java
@@ -123,7 +123,7 @@ public abstract class ComputeJobAdapter implements 
ComputeJob, Callable<Object>
      *
      * @return Array of job arguments.
      */
-    @Nullable Object[] arguments() {
+    @Nullable protected Object[] arguments() {
         return args;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/621b0ede/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
index f8342b3..0f47b7f 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
@@ -1,4 +1,4 @@
- /*
+/*
  * 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.
@@ -209,7 +209,6 @@ public abstract class GridCacheQueryManager<K, V> extends 
GridCacheManagerAdapte
     /** */
     private boolean qryProcEnabled;
 
-
     /** */
     private AffinityTopologyVersion qryTopVer;
 
@@ -355,6 +354,7 @@ public abstract class GridCacheQueryManager<K, V> extends 
GridCacheManagerAdapte
 
     /**
      * Checks if IndexinSPI is enabled.
+     *
      * @return IndexingSPI enabled flag.
      */
     private boolean isIndexingSpiEnabled() {
@@ -412,7 +412,7 @@ public abstract class GridCacheQueryManager<K, V> extends 
GridCacheManagerAdapte
                 cctx.kernalContext().indexing().store(cacheName, key0, val0, 
expirationTime);
             }
 
-            if(qryProcEnabled)
+            if (qryProcEnabled)
                 qryProc.store(cacheName, key, partId, prevVal, prevVer, val, 
ver, expirationTime, link);
         }
         finally {
@@ -430,7 +430,8 @@ public abstract class GridCacheQueryManager<K, V> extends 
GridCacheManagerAdapte
      * @throws IgniteCheckedException Thrown in case of any errors.
      */
     @SuppressWarnings("SimplifiableIfStatement")
-    public void remove(KeyCacheObject key, int partId, CacheObject val, 
GridCacheVersion ver) throws IgniteCheckedException {
+    public void remove(KeyCacheObject key, int partId, CacheObject val,
+        GridCacheVersion ver) throws IgniteCheckedException {
         assert key != null;
 
         if (!QueryUtils.isEnabled(cctx.config()) && !(key instanceof 
GridCacheInternal))
@@ -447,7 +448,7 @@ public abstract class GridCacheQueryManager<K, V> extends 
GridCacheManagerAdapte
             }
 
             // val may be null if we have no previous value. We should not 
call processor in this case.
-            if(qryProcEnabled && val != null)
+            if (qryProcEnabled && val != null)
                 qryProc.remove(cacheName, key, partId, val, ver);
         }
         finally {

http://git-wip-us.apache.org/repos/asf/ignite/blob/621b0ede/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
index bfc5282..c2ca587 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
@@ -53,7 +53,6 @@ import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
 import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
 import org.apache.ignite.internal.processors.cache.query.GridCacheSqlMetadata;
 import org.apache.ignite.internal.processors.rest.GridRestCommand;
@@ -360,7 +359,7 @@ public class GridCacheCommandHandler extends 
GridRestCommandHandlerAdapter {
 
         GridRestCacheRequest req0 = (GridRestCacheRequest)req;
 
-        final String cacheName = req0.cacheName() == null ? DFLT_CACHE_NAME: 
req0.cacheName();
+        final String cacheName = req0.cacheName() == null ? DFLT_CACHE_NAME : 
req0.cacheName();
 
         final Object key = req0.key();
 
@@ -408,7 +407,7 @@ public class GridCacheCommandHandler extends 
GridRestCommandHandlerAdapter {
                 }
 
                 case CACHE_METADATA: {
-                    fut = ctx.task().execute(MetadataTask.class, null);
+                    fut = ctx.task().execute(MetadataTask.class, 
req0.cacheName());
 
                     break;
                 }
@@ -927,7 +926,7 @@ public class GridCacheCommandHandler extends 
GridRestCommandHandlerAdapter {
 
     /** */
     @GridInternal
-    private static class MetadataTask extends ComputeTaskAdapter<Void, 
GridRestResponse> {
+    private static class MetadataTask extends ComputeTaskAdapter<String, 
GridRestResponse> {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -937,29 +936,48 @@ public class GridCacheCommandHandler extends 
GridRestCommandHandlerAdapter {
 
         /** {@inheritDoc} */
         @Nullable @Override public Map<? extends ComputeJob, ClusterNode> 
map(List<ClusterNode> subgrid,
-            @Nullable Void arg) throws IgniteException {
+            String cacheName) throws IgniteException {
 
             GridDiscoveryManager discovery = ignite.context().discovery();
 
-            boolean sameCaches = true;
+            Map<ComputeJob, ClusterNode> map = 
U.newHashMap(F.isEmpty(cacheName) ? subgrid.size() : 1);
 
-            Set<String> caches = 
discovery.nodePublicCaches(F.first(subgrid)).keySet();
+            if (!F.isEmpty(cacheName)) {
+                for (int i = 1; i < subgrid.size(); i++) {
+                    if 
(discovery.nodePublicCaches(subgrid.get(i)).keySet().contains(cacheName)) {
+                        MetadataJob job = new MetadataJob();
 
-            for (int i = 1; i < subgrid.size(); i++) {
-                if 
(!caches.equals(discovery.nodePublicCaches(subgrid.get(i)).keySet())) {
-                    sameCaches = false;
+                        job.setArguments(cacheName);
 
-                    break;
+                        map.put(job, subgrid.get(i));
+
+                        break;
+                    }
                 }
+
+                if (map.isEmpty())
+                    throw new IgniteException("Failed to request meta data. " 
+ cacheName + " is not found");
             }
+            else {
+                // get meta for all caches.
+                boolean sameCaches = true;
 
-            Map<ComputeJob, ClusterNode> map = U.newHashMap(sameCaches ? 1 : 
subgrid.size());
+                Set<String> caches = 
discovery.nodePublicCaches(F.first(subgrid)).keySet();
 
-            if (sameCaches)
-                map.put(new MetadataJob(), ignite.localNode());
-            else {
-                for (ClusterNode node : subgrid)
-                    map.put(new MetadataJob(), node);
+                for (int i = 1; i < subgrid.size(); i++) {
+                    if 
(!caches.equals(discovery.nodePublicCaches(subgrid.get(i)).keySet())) {
+                        sameCaches = false;
+
+                        break;
+                    }
+                }
+
+                if (sameCaches)
+                    map.put(new MetadataJob(), ignite.localNode());
+                else {
+                    for (ClusterNode node : subgrid)
+                        map.put(new MetadataJob(), node);
+                }
             }
 
             return map;
@@ -1003,13 +1021,35 @@ public class GridCacheCommandHandler extends 
GridRestCommandHandlerAdapter {
 
         /** {@inheritDoc} */
         @Override public Collection<GridCacheSqlMetadata> execute() {
-            IgniteCacheProxy<?, ?> cache = 
F.first(ignite.context().cache().publicCaches());
+            String cacheName = null;
+            IgniteInternalCache<?, ?> cache;
 
-            if (cache == null)
-                return Collections.emptyList();
+            if (!F.isEmpty(arguments())) {
+                cacheName = argument(0);
+
+                cache = ignite.context().cache().publicCache(cacheName);
+
+                assert cache != null;
+            }
+            else {
+                cache = 
F.first(ignite.context().cache().publicCaches()).internalProxy();
+
+                if (cache == null)
+                    return Collections.emptyList();
+            }
 
             try {
-                return cache.context().queries().sqlMetadata();
+                Collection<GridCacheSqlMetadata> metas = 
cache.context().queries().sqlMetadata();
+
+                if (cacheName != null) {
+                    for (GridCacheSqlMetadata meta : metas)
+                        if (meta.cacheName().equals(cacheName))
+                            return Collections.singleton(meta);
+
+                    throw new IgniteException("No meta data for " + cacheName 
+ " can be found");
+                }
+
+                return metas;
             }
             catch (IgniteCheckedException e) {
                 throw U.convertException(e);

Reply via email to