Search in sources :

Example 1 with IgniteClusterNode

use of org.apache.ignite.internal.managers.discovery.IgniteClusterNode in project ignite by apache.

the class CacheMetricsForClusterGroupSelfTest method testMetricsStatisticsDisabled.

/**
 * Test cluster group metrics in case of statistics disabled.
 *
 * @throws Exception If failed.
 */
@Test
public void testMetricsStatisticsDisabled() throws Exception {
    startGrids();
    try {
        createCaches(false);
        populateCacheData(cache1, ENTRY_CNT_CACHE1);
        populateCacheData(cache2, ENTRY_CNT_CACHE2);
        readCacheData(cache1, ENTRY_CNT_CACHE1);
        readCacheData(cache2, ENTRY_CNT_CACHE2);
        awaitMetricsUpdate(1);
        Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
        for (ClusterNode node : nodes) {
            Map<Integer, CacheMetrics> metrics = ((IgniteClusterNode) node).cacheMetrics();
            assertNotNull(metrics);
            assertTrue(metrics.isEmpty());
        }
        assertMetrics(cache1, false);
        assertMetrics(cache2, false);
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) CacheMetrics(org.apache.ignite.cache.CacheMetrics) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with IgniteClusterNode

use of org.apache.ignite.internal.managers.discovery.IgniteClusterNode in project ignite by apache.

the class VisorBaselineTaskResult method toMapWithResolvedAddresses.

/**
 * @param nodes Nodes to process.
 * @return Map of DTO objects, with resolved ip->hostname pairs.
 */
private static Map<String, VisorBaselineNode> toMapWithResolvedAddresses(Collection<? extends BaselineNode> nodes) {
    if (F.isEmpty(nodes))
        return null;
    Map<String, VisorBaselineNode> map = new TreeMap<>();
    for (BaselineNode node : nodes) {
        Collection<VisorBaselineNode.ResolvedAddresses> addrs = new ArrayList<>();
        if (node instanceof IgniteClusterNode) {
            for (InetAddress inetAddress : resolveInetAddresses((ClusterNode) node)) addrs.add(new VisorBaselineNode.ResolvedAddresses(inetAddress));
        }
        VisorBaselineNode dto = new VisorBaselineNode(node, addrs);
        map.put(dto.getConsistentId(), dto);
    }
    return map;
}
Also used : IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) InetAddress(java.net.InetAddress) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Example 3 with IgniteClusterNode

use of org.apache.ignite.internal.managers.discovery.IgniteClusterNode in project ignite by apache.

the class ClusterProcessor method updateMetrics.

/**
 */
private void updateMetrics() {
    if (ctx.isStopping() || ctx.clientDisconnected())
        return;
    ClusterNode oldest = ctx.discovery().oldestAliveServerNode(AffinityTopologyVersion.NONE);
    if (oldest == null)
        return;
    if (ctx.localNodeId().equals(oldest.id())) {
        IgniteClusterNode locNode = (IgniteClusterNode) ctx.discovery().localNode();
        locNode.setMetrics(metricsProvider.metrics());
        locNode.setCacheMetrics(metricsProvider.cacheMetrics());
        ClusterNodeMetrics metrics = new ClusterNodeMetrics(locNode.metrics(), locNode.cacheMetrics());
        try {
            byte[] metricsBytes = U.zip(U.marshal(ctx.config().getMarshaller(), metrics));
            allNodesMetrics.put(ctx.localNodeId(), metricsBytes);
        } catch (IgniteCheckedException e) {
            U.warn(log, "Failed to marshal local node metrics: " + e, e);
        }
        ctx.discovery().metricsUpdateEvent(ctx.discovery().discoCache(), locNode);
        Collection<ClusterNode> allNodes = ctx.discovery().allNodes();
        ClusterMetricsUpdateMessage msg = new ClusterMetricsUpdateMessage(new HashMap<>(allNodesMetrics));
        for (ClusterNode node : allNodes) {
            if (ctx.localNodeId().equals(node.id()) || !ctx.discovery().alive(node.id()))
                continue;
            try {
                ctx.io().sendToGridTopic(node, TOPIC_METRICS, msg, GridIoPolicy.SYSTEM_POOL);
            } catch (ClusterTopologyCheckedException e) {
                if (log.isDebugEnabled())
                    log.debug("Failed to send metrics update, node failed: " + e);
            } catch (IgniteCheckedException e) {
                U.warn(log, "Failed to send metrics update: " + e, e);
            }
        }
    } else {
        ClusterNodeMetrics metrics = new ClusterNodeMetrics(metricsProvider.metrics(), metricsProvider.cacheMetrics());
        try {
            byte[] metricsBytes = U.zip(U.marshal(ctx.config().getMarshaller(), metrics));
            ClusterMetricsUpdateMessage msg = new ClusterMetricsUpdateMessage(metricsBytes);
            ctx.io().sendToGridTopic(oldest, TOPIC_METRICS, msg, GridIoPolicy.SYSTEM_POOL);
        } catch (ClusterTopologyCheckedException e) {
            if (log.isDebugEnabled())
                log.debug("Failed to send metrics update to oldest, node failed: " + e);
        } catch (IgniteCheckedException e) {
            LT.warn(log, e, "Failed to send metrics update to oldest: " + e, false, false);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 4 with IgniteClusterNode

use of org.apache.ignite.internal.managers.discovery.IgniteClusterNode in project ignite by apache.

the class ClusterProcessor method updateNodeMetrics.

/**
 * @param discoCache Discovery data cache.
 * @param nodeId Node ID.
 * @param metricsBytes Marshalled metrics.
 */
private void updateNodeMetrics(DiscoCache discoCache, UUID nodeId, byte[] metricsBytes) {
    ClusterNode node = discoCache.node(nodeId);
    if (node == null || !discoCache.alive(nodeId))
        return;
    try {
        ClusterNodeMetrics metrics = U.unmarshalZip(ctx.config().getMarshaller(), metricsBytes, null);
        assert node instanceof IgniteClusterNode : node;
        IgniteClusterNode node0 = (IgniteClusterNode) node;
        node0.setMetrics(ClusterMetricsSnapshot.deserialize(metrics.metrics(), 0));
        node0.setCacheMetrics(metrics.cacheMetrics());
        ctx.discovery().metricsUpdateEvent(discoCache, node0);
    } catch (IgniteCheckedException e) {
        U.warn(log, "Failed to unmarshal node metrics: " + e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 5 with IgniteClusterNode

use of org.apache.ignite.internal.managers.discovery.IgniteClusterNode in project ignite by apache.

the class CacheMetricsForClusterGroupSelfTest method testMetricsStatisticsEnabled.

/**
 * Test cluster group metrics in case of statistics enabled.
 */
@Test
public void testMetricsStatisticsEnabled() throws Exception {
    startGrids();
    try {
        createCaches(true);
        populateCacheData(cache1, ENTRY_CNT_CACHE1);
        populateCacheData(cache2, ENTRY_CNT_CACHE2);
        readCacheData(cache1, ENTRY_CNT_CACHE1);
        readCacheData(cache2, ENTRY_CNT_CACHE2);
        awaitMetricsUpdate(1);
        Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
        for (ClusterNode node : nodes) {
            Map<Integer, CacheMetrics> metrics = ((IgniteClusterNode) node).cacheMetrics();
            assertNotNull(metrics);
            assertFalse(metrics.isEmpty());
        }
        assertMetrics(cache1, true);
        assertMetrics(cache2, true);
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) CacheMetrics(org.apache.ignite.cache.CacheMetrics) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteClusterNode (org.apache.ignite.internal.managers.discovery.IgniteClusterNode)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 CacheMetrics (org.apache.ignite.cache.CacheMetrics)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 Test (org.junit.Test)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 BaselineNode (org.apache.ignite.cluster.BaselineNode)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1