ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ira...@apache.org
Subject ignite git commit: IGNITE-8603 Add JMX-metric to cluster: baseline nodes - Fixes #4060.
Date Fri, 01 Jun 2018 15:41:05 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 4b351b6bf -> 1f6266c97


IGNITE-8603 Add JMX-metric to cluster: baseline nodes - Fixes #4060.

Signed-off-by: Ivan Rakov <irakov@apache.org>


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

Branch: refs/heads/master
Commit: 1f6266c978b4e6c5ced3594f292cdbbf668244ad
Parents: 4b351b6
Author: dgladkikh <dgladkikh@gridgain.com>
Authored: Fri Jun 1 18:34:50 2018 +0300
Committer: Ivan Rakov <irakov@apache.org>
Committed: Fri Jun 1 18:34:50 2018 +0300

----------------------------------------------------------------------
 .../ClusterLocalNodeMetricsMXBeanImpl.java      |  21 +++
 .../internal/ClusterMetricsMXBeanImpl.java      |  32 ++++
 .../ignite/mxbean/ClusterMetricsMXBean.java     |  16 ++
 .../ClusterBaselineNodesMetricsSelfTest.java    | 178 +++++++++++++++++++
 .../testsuites/IgniteComputeGridTestSuite.java  |   2 +
 5 files changed, 249 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1f6266c9/modules/core/src/main/java/org/apache/ignite/internal/ClusterLocalNodeMetricsMXBeanImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/ClusterLocalNodeMetricsMXBeanImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/ClusterLocalNodeMetricsMXBeanImpl.java
index a242345..eed501a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/ClusterLocalNodeMetricsMXBeanImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/ClusterLocalNodeMetricsMXBeanImpl.java
@@ -18,9 +18,11 @@
 package org.apache.ignite.internal;
 
 import java.util.Collections;
+import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.UUID;
+import org.apache.ignite.cluster.BaselineNode;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
 import org.apache.ignite.internal.util.typedef.internal.S;
@@ -333,6 +335,25 @@ public class ClusterLocalNodeMetricsMXBeanImpl implements ClusterMetricsMXBean
{
     }
 
     /** {@inheritDoc} */
+    @Override public int getTotalBaselineNodes() {
+        if (!node.isClient() && !node.isDaemon()) {
+            List<? extends BaselineNode> baselineNodes = discoMgr.baselineNodes(discoMgr.topologyVersionEx());
+
+            if (baselineNodes != null)
+                for (BaselineNode baselineNode : baselineNodes)
+                    if (baselineNode.consistentId().equals(node.consistentId()))
+                        return 1;
+        }
+
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getActiveBaselineNodes() {
+        return getTotalBaselineNodes();
+    }
+
+    /** {@inheritDoc} */
     @Override public int getTotalServerNodes() {
         return !node.isClient() ? 1 : 0;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1f6266c9/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsMXBeanImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsMXBeanImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsMXBeanImpl.java
index e09ad3c..1efb590 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsMXBeanImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsMXBeanImpl.java
@@ -18,10 +18,13 @@
 package org.apache.ignite.internal;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.UUID;
+import org.apache.ignite.cluster.BaselineNode;
 import org.apache.ignite.cluster.ClusterGroup;
 import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.cluster.ClusterNode;
@@ -359,6 +362,35 @@ public class ClusterMetricsMXBeanImpl implements ClusterMetricsMXBean
{
     }
 
     /** {@inheritDoc} */
+    @Override public int getTotalBaselineNodes() {
+        Collection<BaselineNode> baselineNodes = cluster.ignite().cluster().currentBaselineTopology();
+
+        return baselineNodes != null ? baselineNodes.size() : 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getActiveBaselineNodes() {
+        Collection<BaselineNode> baselineNodes = cluster.ignite().cluster().currentBaselineTopology();
+
+        if (baselineNodes != null && !baselineNodes.isEmpty()) {
+            Set<Object> bltIds = new HashSet<>(baselineNodes.size());
+
+            for (BaselineNode baselineNode : baselineNodes)
+                bltIds.add(baselineNode.consistentId());
+
+            int count = 0;
+
+            for (ClusterNode node : cluster.forServers().nodes())
+                if (bltIds.contains(node.consistentId()))
+                    count++;
+
+            return count;
+        }
+
+        return 0;
+    }
+
+    /** {@inheritDoc} */
     @Override public int getTotalServerNodes() {
         return cluster.forServers().nodes().size();
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1f6266c9/modules/core/src/main/java/org/apache/ignite/mxbean/ClusterMetricsMXBean.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/mxbean/ClusterMetricsMXBean.java
b/modules/core/src/main/java/org/apache/ignite/mxbean/ClusterMetricsMXBean.java
index 6385604..537cef7 100644
--- a/modules/core/src/main/java/org/apache/ignite/mxbean/ClusterMetricsMXBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/mxbean/ClusterMetricsMXBean.java
@@ -258,6 +258,22 @@ public interface ClusterMetricsMXBean extends ClusterMetrics {
     public int getTotalNodes();
 
     /**
+     * Get count of total baseline nodes.
+     *
+     * @return Count of total baseline nodes.
+     */
+    @MXBeanDescription("Total baseline nodes count.")
+    public int getTotalBaselineNodes();
+
+    /**
+     * Get count of active baseline nodes.
+     *
+     * @return Count of active baseline nodes.
+     */
+    @MXBeanDescription("Active baseline nodes count.")
+    public int getActiveBaselineNodes();
+
+    /**
      * Get count of server nodes.
      *
      * @return Count of server nodes.

http://git-wip-us.apache.org/repos/asf/ignite/blob/1f6266c9/modules/core/src/test/java/org/apache/ignite/internal/ClusterBaselineNodesMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/ClusterBaselineNodesMetricsSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/ClusterBaselineNodesMetricsSelfTest.java
new file mode 100644
index 0000000..5653177
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/ClusterBaselineNodesMetricsSelfTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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;
+
+import java.lang.management.ManagementFactory;
+import java.util.Collection;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cluster.BaselineNode;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.WALMode;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.mxbean.ClusterMetricsMXBean;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+
+/**
+ * Baseline nodes metrics self test.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class ClusterBaselineNodesMetricsSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBaselineNodes() throws Exception {
+        // Start 2 server nodes.
+        IgniteEx ignite0 = startGrid(0);
+        startGrid(1);
+
+        // Cluster metrics.
+        ClusterMetricsMXBean mxBeanCluster = mxBean(0, ClusterMetricsMXBeanImpl.class);
+
+        ignite0.cluster().active(true);
+
+        // Added 2 server nodes to baseline.
+        resetBlt();
+
+        // Add server node outside of the baseline.
+        startGrid(2);
+
+        // Start client node.
+        Ignition.setClientMode(true);
+        startGrid(3);
+        Ignition.setClientMode(false);
+
+        Collection<BaselineNode> baselineNodes;
+
+        // State #0: 3 server nodes (2 total baseline nodes, 2 active baseline nodes), 1
client node
+        log.info(String.format(">>> State #0: topology version = %d", ignite0.cluster().topologyVersion()));
+
+        assertEquals(3, mxBeanCluster.getTotalServerNodes());
+        assertEquals(1, mxBeanCluster.getTotalClientNodes());
+        assertEquals(2, mxBeanCluster.getTotalBaselineNodes());
+        assertEquals(2, mxBeanCluster.getActiveBaselineNodes());
+        assertEquals(2, (baselineNodes = ignite0.cluster().currentBaselineTopology()) !=
null
+            ? baselineNodes.size()
+            : 0);
+
+        stopGrid(1, true);
+
+        // State #1: 2 server nodes (2 total baseline nodes, 1 active baseline node), 1 client
node
+        log.info(String.format(">>> State #1: topology version = %d", ignite0.cluster().topologyVersion()));
+
+        assertEquals(2, mxBeanCluster.getTotalServerNodes());
+        assertEquals(1, mxBeanCluster.getTotalClientNodes());
+        assertEquals(2, mxBeanCluster.getTotalBaselineNodes());
+        assertEquals(1, mxBeanCluster.getActiveBaselineNodes());
+        assertEquals(2, (baselineNodes = ignite0.cluster().currentBaselineTopology()) !=
null
+            ? baselineNodes.size()
+            : 0);
+
+        startGrid(1);
+
+        ClusterMetricsMXBean mxBeanLocalNode1 = mxBean(1, ClusterLocalNodeMetricsMXBeanImpl.class);
+
+        // State #2: 3 server nodes (2 total baseline nodes, 2 active baseline nodes), 1
client node
+        log.info(String.format(">>> State #2: topology version = %d", ignite0.cluster().topologyVersion()));
+
+        assertEquals(3, mxBeanCluster.getTotalServerNodes());
+        assertEquals(1, mxBeanCluster.getTotalClientNodes());
+        assertEquals(2, mxBeanCluster.getTotalBaselineNodes());
+        assertEquals(2, mxBeanCluster.getActiveBaselineNodes());
+        assertEquals(1, mxBeanLocalNode1.getTotalBaselineNodes());
+        assertEquals(2, (baselineNodes = ignite0.cluster().currentBaselineTopology()) !=
null
+            ? baselineNodes.size()
+            : 0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String name) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(name);
+
+        cfg.setConsistentId(name);
+
+        String storePath = getClass().getSimpleName().toLowerCase() + "/" + getName();
+
+        cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
+
+        cfg.setDataStorageConfiguration(
+            new DataStorageConfiguration()
+                .setWalMode(WALMode.LOG_ONLY)
+                .setStoragePath(storePath)
+                .setWalPath(storePath + "/wal")
+                .setWalArchivePath(storePath + "/archive")
+                .setDefaultDataRegionConfiguration(
+                    new DataRegionConfiguration()
+                        .setPersistenceEnabled(true)
+                        .setMaxSize(2L * 1024 * 1024 * 1024)
+                )
+        );
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void resetBlt() throws Exception {
+        resetBaselineTopology();
+
+        waitForRebalancing();
+        awaitPartitionMapExchange();
+    }
+
+    /**
+     * Gets ClusterMetricsMXBean for given node.
+     *
+     * @param nodeIdx Node index.
+     * @param clazz Class of ClusterMetricsMXBean implementation.
+     * @return MBean instance.
+     */
+    private ClusterMetricsMXBean mxBean(int nodeIdx, Class<? extends ClusterMetricsMXBean>
clazz)
+        throws MalformedObjectNameException {
+
+        ObjectName mbeanName = U.makeMBeanName(
+            getTestIgniteInstanceName(nodeIdx),
+            "Kernal",
+            clazz.getSimpleName());
+
+        MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer();
+
+        if (!mbeanSrv.isRegistered(mbeanName))
+            fail("MBean is not registered: " + mbeanName.getCanonicalName());
+
+        return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, ClusterMetricsMXBean.class,
true);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1f6266c9/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
index 14eb296..bab7099 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
+import org.apache.ignite.internal.ClusterBaselineNodesMetricsSelfTest;
 import org.apache.ignite.internal.ClusterNodeMetricsSelfTest;
 import org.apache.ignite.internal.ClusterNodeMetricsUpdateTest;
 import org.apache.ignite.internal.GridAffinityNoCacheSelfTest;
@@ -124,6 +125,7 @@ public class IgniteComputeGridTestSuite {
         suite.addTestSuite(GridTaskInstanceExecutionSelfTest.class);
         suite.addTestSuite(ClusterNodeMetricsSelfTest.class);
         suite.addTestSuite(ClusterNodeMetricsUpdateTest.class);
+        suite.addTestSuite(ClusterBaselineNodesMetricsSelfTest.class);
         suite.addTestSuite(GridNonHistoryMetricsSelfTest.class);
         suite.addTestSuite(GridCancelledJobsMetricsSelfTest.class);
         suite.addTestSuite(GridCollisionJobsContextSelfTest.class);


Mime
View raw message