ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [15/28] incubator-ignite git commit: # IGNITE-639 Review.
Date Thu, 09 Apr 2015 06:04:00 GMT
# IGNITE-639 Review.


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

Branch: refs/heads/ignite-694
Commit: 43fa7148b37bbd3cdd0c4b406075d98491072b8a
Parents: 349c200
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Tue Apr 7 10:26:43 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Tue Apr 7 10:26:43 2015 +0700

----------------------------------------------------------------------
 .../ignite/internal/visor/cache/VisorCache.java |  6 +--
 .../cache/VisorCacheAggregatedMetrics.java      | 35 +++++++------
 .../internal/visor/cache/VisorCacheMetrics.java | 53 ++++++++++++++++++--
 .../cache/VisorCacheMetricsCollectorTask.java   | 33 +++++-------
 .../commands/cache/VisorCacheCommand.scala      | 29 ++++++-----
 5 files changed, 99 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43fa7148/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
index 98f602f..d57d19a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
@@ -97,9 +97,9 @@ public class VisorCache implements Serializable {
      * @param cacheName Cache name.
      * @param sample Sample size.
      * @return Data transfer object for given cache.
-     * @throws IgniteCheckedException
+     * @throws IgniteCheckedException If failed collect metrics.
      */
-    public static VisorCache from(Ignite ignite, String cacheName, int sample) throws IgniteCheckedException
{
+    public static VisorCache from(IgniteEx ignite, String cacheName, int sample) throws IgniteCheckedException
{
         assert ignite != null;
 
         GridCacheAdapter ca = ((IgniteKernal)ignite).internalCache(cacheName);
@@ -226,7 +226,7 @@ public class VisorCache implements Serializable {
         cache.partitions = ca.affinity().partitions();
         cache.primaryPartitions = pps;
         cache.backupPartitions = bps;
-        cache.metrics = VisorCacheMetrics.from(ca);
+        cache.metrics = VisorCacheMetrics.from(ignite, ca);
         cache.partitionsMap = partsMap;
 
         return cache;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43fa7148/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java
index c8d3a8d..af68e9f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java
@@ -31,13 +31,13 @@ public class VisorCacheAggregatedMetrics implements Serializable {
     private static final long serialVersionUID = 0L;
 
     /** Cache name. */
-    private final String cacheName;
+    private String name;
 
     /** Cache mode. */
-    private final CacheMode cacheMode;
+    private CacheMode mode;
 
     /** Cache system state. */
-    private final Boolean system;
+    private boolean sys;
 
     /** Node IDs with cache metrics. */
     private final Map<UUID, VisorCacheMetrics> metrics = new HashMap<>();
@@ -106,31 +106,36 @@ public class VisorCacheAggregatedMetrics implements Serializable {
     private transient Integer failsQry;
 
     /**
-     * Create data transfer object with given parameters.
+     * Create data transfer object for aggregated cache metrics.
      *
-     * @param cacheName Cache name.
+     * @param cm Source cache metrics.
+     * @return Data transfer object for aggregated cache metrics.
      */
-    public VisorCacheAggregatedMetrics(String cacheName, CacheMode cacheMode, Boolean system)
{
-        this.cacheName = cacheName;
-        this.cacheMode = cacheMode;
-        this.system = system;
+    public static VisorCacheAggregatedMetrics from(VisorCacheMetrics cm) {
+        VisorCacheAggregatedMetrics acm = new VisorCacheAggregatedMetrics();
+
+        acm.name = cm.name();
+        acm.mode = cm.mode();
+        acm.sys = cm.system();
+
+        return acm;
     }
 
     /**
      * @return Cache name.
      */
-    public String cacheName() {
-        return cacheName;
+    public String name() {
+        return name;
     }
 
     /** @return Cache mode. */
-    public CacheMode cacheMode() {
-        return cacheMode;
+    public CacheMode mode() {
+        return mode;
     }
 
     /** @return Cache system state. */
-    public Boolean system() {
-        return system;
+    public boolean system() {
+        return sys;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43fa7148/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java
index 77db2f4..fc30392 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java
@@ -18,13 +18,14 @@
 package org.apache.ignite.internal.visor.cache;
 
 import org.apache.ignite.cache.*;
+import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 
 import java.io.*;
 
 /**
- * Data transfer object for {@link org.apache.ignite.cache.CacheMetrics}.
+ * Data transfer object for {@link CacheMetrics}.
  */
 public class VisorCacheMetrics implements Serializable {
     /** */
@@ -33,6 +34,15 @@ public class VisorCacheMetrics implements Serializable {
     /** */
     private static final long serialVersionUID = 0L;
 
+    /** Cache name. */
+    private String name;
+
+    /** Cache mode. */
+    private CacheMode mode;
+
+    /** Cache system state. */
+    private boolean sys;
+
     /** Number of non-{@code null} values in the cache. */
     private int size;
 
@@ -147,7 +157,14 @@ public class VisorCacheMetrics implements Serializable {
     /** Number of cached rolled back DHT transaction IDs. */
     private int txDhtRolledbackVersionsSize;
 
-    /** Calculate rate of metric per second. */
+    /**
+     * Calculate rate of metric per second.
+     *
+     * @param metric Metric value.
+     * @param time Metric finish time.
+     * @param createTime Metric start time.
+     * @return Metric per second.
+     */
     private static int perSecond(int metric, long time, long createTime) {
         long seconds = (time - createTime) / 1000;
 
@@ -155,14 +172,21 @@ public class VisorCacheMetrics implements Serializable {
     }
 
     /**
+     * @param ignite Ignite.
      * @param c Cache.
      * @return Data transfer object for given cache metrics.
      */
-    public static VisorCacheMetrics from(GridCache c) {
+    public static VisorCacheMetrics from(IgniteEx ignite, GridCache c) {
         VisorCacheMetrics cm = new VisorCacheMetrics();
 
         CacheMetrics m = c.metrics();
 
+        GridCacheProcessor cacheProcessor = ignite.context().cache();
+
+        cm.name = c.name();
+        cm.mode = cacheProcessor.cacheMode(c.name());
+        cm.sys = cacheProcessor.systemCache(c.name());
+
         cm.size = m.getSize();
         cm.keySize = m.getKeySize();
 
@@ -214,6 +238,27 @@ public class VisorCacheMetrics implements Serializable {
     }
 
     /**
+     * @return Cache name.
+     */
+    public String name() {
+        return name;
+    }
+
+    /**
+     *  @return Cache mode.
+     */
+    public CacheMode mode() {
+        return mode;
+    }
+
+    /**
+     * @return Cache system state.
+     */
+    public boolean system() {
+        return sys;
+    }
+
+    /**
      * @return Total number of reads of the owning entity (either cache or entry).
      */
     public long reads() {
@@ -396,7 +441,7 @@ public class VisorCacheMetrics implements Serializable {
     }
 
     /**
-     * Committed transaction queue size.
+     * @return Committed transaction queue size.
      */
     public int txCommitQueueSize() {
         return txCommitQueueSize;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43fa7148/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetricsCollectorTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetricsCollectorTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetricsCollectorTask.java
index 99b29c0..b4b850b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetricsCollectorTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetricsCollectorTask.java
@@ -32,7 +32,7 @@ import java.util.*;
  */
 @GridInternal
 public class VisorCacheMetricsCollectorTask extends VisorMultiNodeTask<IgniteBiTuple<Boolean,
Collection<String>>,
-    Iterable<VisorCacheAggregatedMetrics>, Map<String, IgniteBiTuple<Boolean,
VisorCacheMetrics>>> {
+    Iterable<VisorCacheAggregatedMetrics>, Collection<VisorCacheMetrics>>
{
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -47,23 +47,18 @@ public class VisorCacheMetricsCollectorTask extends VisorMultiNodeTask<IgniteBiT
 
         for (ComputeJobResult res : results) {
             if (res.getException() == null && res.getData() instanceof Map<?,
?>) {
-                Map<String, IgniteBiTuple<Boolean, VisorCacheMetrics>> cms =
res.getData();
+                Collection<VisorCacheMetrics> cms = res.getData();
 
-                for (Map.Entry<String, IgniteBiTuple<Boolean, VisorCacheMetrics>>
entry : cms.entrySet()) {
-                    VisorCacheAggregatedMetrics am = grpAggrMetrics.get(entry.getKey());
+                for (VisorCacheMetrics cm : cms) {
+                    VisorCacheAggregatedMetrics am = grpAggrMetrics.get(cm.name());
 
                     if (am == null) {
-                        String cacheName = entry.getKey();
+                        am = VisorCacheAggregatedMetrics.from(cm);
 
-                        GridCacheProcessor proc = ignite.context().cache();
-
-                        am = new VisorCacheAggregatedMetrics(cacheName, proc.cacheMode(cacheName),
-                            entry.getValue().get1());
-
-                        grpAggrMetrics.put(entry.getKey(), am);
+                        grpAggrMetrics.put(cm.name(), am);
                     }
 
-                    am.metrics().put(res.getNode().id(), entry.getValue().get2());
+                    am.metrics().put(res.getNode().id(), cm);
                 }
             }
         }
@@ -76,7 +71,7 @@ public class VisorCacheMetricsCollectorTask extends VisorMultiNodeTask<IgniteBiT
      * Job that collect cache metrics from node.
      */
     private static class VisorCacheMetricsCollectorJob
-        extends VisorJob<IgniteBiTuple<Boolean, Collection<String>>, Map<String,
IgniteBiTuple<Boolean, VisorCacheMetrics>>> {
+        extends VisorJob<IgniteBiTuple<Boolean, Collection<String>>, Collection<VisorCacheMetrics>>
{
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -91,8 +86,7 @@ public class VisorCacheMetricsCollectorTask extends VisorMultiNodeTask<IgniteBiT
         }
 
         /** {@inheritDoc} */
-        @Override protected Map<String, IgniteBiTuple<Boolean, VisorCacheMetrics>>
run(
-            final IgniteBiTuple<Boolean, Collection<String>> arg) {
+        @Override protected Collection<VisorCacheMetrics> run(final IgniteBiTuple<Boolean,
Collection<String>> arg) {
             assert arg != null;
 
             Boolean showSysCaches = arg.get1();
@@ -107,17 +101,16 @@ public class VisorCacheMetricsCollectorTask extends VisorMultiNodeTask<IgniteBiT
 
             Collection<GridCacheAdapter<?, ?>> caches = cacheProcessor.internalCaches();
 
-            Map<String, IgniteBiTuple<Boolean, VisorCacheMetrics>> res = U.newHashMap(caches.size());
+            Collection<VisorCacheMetrics> res = new ArrayList<>(caches.size());
 
             boolean allCaches = cacheNames.isEmpty();
 
             for (GridCacheAdapter ca : caches) {
                 if (ca.context().started()) {
-                    String name = ca.name();
+                    VisorCacheMetrics cm = VisorCacheMetrics.from(ignite, ca);
 
-                    if ((showSysCaches && cacheProcessor.systemCache(name)) || allCaches
|| cacheNames.contains(name))
-                        res.put(name, new IgniteBiTuple<Boolean, VisorCacheMetrics>(
-                            ignite.context().cache().systemCache(name), VisorCacheMetrics.from(ca)));
+                    if ((showSysCaches && cm.system()) || allCaches || cacheNames.contains(ca.name()))
+                        res.add(cm);
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43fa7148/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
index 33a2a16..4d35b35 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
@@ -19,7 +19,6 @@ package org.apache.ignite.visor.commands.cache
 
 import org.apache.ignite._
 import org.apache.ignite.cluster.ClusterNode
-import org.apache.ignite.internal.processors.cache.{GridCacheUtils => CU}
 import org.apache.ignite.internal.util.typedef._
 import org.apache.ignite.lang.IgniteBiTuple
 import org.apache.ignite.visor.VisorTag
@@ -277,7 +276,7 @@ class VisorCacheCommand {
                     if (hasArgFlag("scan", argLst))
                         VisorCacheScanCommand().scan(argLst, node)
                     else {
-                        if (!aggrData.exists(cache => cache.cacheName() == name &&
cache.system())) {
+                        if (!aggrData.exists(cache => safeEquals(cache.name(), name) &&
cache.system())) {
                             if (hasArgFlag("clear", argLst))
                                 VisorCacheClearCommand().clear(argLst, node)
                             else if (hasArgFlag("swap", argLst))
@@ -319,11 +318,11 @@ class VisorCacheCommand {
             sortAggregatedData(aggrData, sortType.getOrElse("cn"), reversed).foreach(
                 ad => {
                     // Add cache host as visor variable.
-                    registerCacheName(ad.cacheName)
+                    registerCacheName(ad.name())
 
                     sumT += (
-                        mkCacheName(ad.cacheName),
-                        ad.cacheMode(),
+                        mkCacheName(ad.name()),
+                        ad.mode(),
                         ad.nodes,
                         (
                             "min: " + ad.minimumSize,
@@ -358,11 +357,11 @@ class VisorCacheCommand {
 
             if (all) {
                 val sorted = aggrData.sortWith((k1, k2) => {
-                    if (k1.cacheName == null)
+                    if (k1.name() == null)
                         true
-                    else if (k2.cacheName == null)
+                    else if (k2.name() == null)
                         false
-                    else k1.cacheName.compareTo(k2.cacheName) < 0
+                    else k1.name().compareTo(k2.name()) < 0
                 })
 
                 val gCfg = node.map(config).collect {
@@ -370,7 +369,7 @@ class VisorCacheCommand {
                 }
 
                 sorted.foreach(ad => {
-                    val cacheNameVar = mkCacheName(ad.cacheName)
+                    val cacheNameVar = mkCacheName(ad.name())
 
                     println("\nCache '" + cacheNameVar + "':")
 
@@ -428,7 +427,7 @@ class VisorCacheCommand {
                     println("  Total number of executions: " + ad.execsQuery)
                     println("  Total number of failures:   " + ad.failsQuery)
 
-                    gCfg.foreach(_.caches().find(_.name() == ad.cacheName()).foreach(cfg
=> {
+                    gCfg.foreach(_.caches().find(_.name() == ad.name()).foreach(cfg =>
{
                         nl()
 
                         showCacheConfiguration("Cache configuration:", cfg)
@@ -580,7 +579,7 @@ class VisorCacheCommand {
             case "rd" => data.toList.sortBy(_.averageReads)
             case "wr" => data.toList.sortBy(_.averageWrites)
             case "cn" => data.toList.sortWith((x, y) =>
-                x.cacheName == null || (y.cacheName != null && x.cacheName.toLowerCase
< y.cacheName.toLowerCase))
+                x.name() == null || (y.name() != null && x.name().toLowerCase <
y.name().toLowerCase))
 
             case _ =>
                 assert(false, "Unknown sorting type: " + arg)
@@ -619,12 +618,12 @@ class VisorCacheCommand {
             val ad = sortedAggrData(i)
 
             // Add cache host as visor variable.
-            registerCacheName(ad.cacheName)
+            registerCacheName(ad.name())
 
             sumT += (
                 i,
-                mkCacheName(ad.cacheName),
-                ad.cacheMode(),
+                mkCacheName(ad.name()),
+                ad.mode(),
                 ad.nodes,
                 (
                     "min: " + ad.minimumSize,
@@ -641,7 +640,7 @@ class VisorCacheCommand {
             None
         else {
             try
-                Some(sortedAggrData(a.toInt).cacheName)
+                Some(sortedAggrData(a.toInt).name())
             catch {
                 case e: Throwable =>
                     warn("Invalid selection: " + a)


Mime
View raw message