Search in sources :

Example 1 with IgniteDiagnosticMessage

use of org.apache.ignite.internal.IgniteDiagnosticMessage in project ignite by apache.

the class ClusterProcessor method initDiagnosticListeners.

/**
 * @throws IgniteCheckedException If failed.
 */
public void initDiagnosticListeners() throws IgniteCheckedException {
    ctx.event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt instanceof DiscoveryEvent;
            assert evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT;
            DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
            UUID nodeId = discoEvt.eventNode().id();
            ConcurrentHashMap<Long, InternalDiagnosticFuture> futs = diagnosticFutMap.get();
            if (futs != null) {
                for (InternalDiagnosticFuture fut : futs.values()) {
                    if (fut.nodeId.equals(nodeId))
                        fut.onDone(new IgniteDiagnosticInfo("Target node failed: " + nodeId));
                }
            }
            allNodesMetrics.remove(nodeId);
        }
    }, EVT_NODE_FAILED, EVT_NODE_LEFT);
    ctx.io().addMessageListener(TOPIC_INTERNAL_DIAGNOSTIC, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            if (msg instanceof IgniteDiagnosticMessage) {
                IgniteDiagnosticMessage msg0 = (IgniteDiagnosticMessage) msg;
                if (msg0.request()) {
                    ClusterNode node = ctx.discovery().node(nodeId);
                    if (node == null) {
                        if (diagnosticLog.isDebugEnabled()) {
                            diagnosticLog.debug("Skip diagnostic request, sender node left " + "[node=" + nodeId + ", msg=" + msg + ']');
                        }
                        return;
                    }
                    byte[] diagRes;
                    IgniteClosure<GridKernalContext, IgniteDiagnosticInfo> c;
                    try {
                        c = msg0.unmarshal(marsh);
                        diagRes = marsh.marshal(c.apply(ctx));
                    } catch (Exception e) {
                        U.error(diagnosticLog, "Failed to run diagnostic closure: " + e, e);
                        try {
                            IgniteDiagnosticInfo errInfo = new IgniteDiagnosticInfo("Failed to run diagnostic closure: " + e);
                            diagRes = marsh.marshal(errInfo);
                        } catch (Exception e0) {
                            U.error(diagnosticLog, "Failed to marshal diagnostic closure result: " + e, e);
                            diagRes = null;
                        }
                    }
                    IgniteDiagnosticMessage res = IgniteDiagnosticMessage.createResponse(diagRes, msg0.futureId());
                    try {
                        ctx.io().sendToGridTopic(node, TOPIC_INTERNAL_DIAGNOSTIC, res, GridIoPolicy.SYSTEM_POOL);
                    } catch (ClusterTopologyCheckedException e) {
                        if (diagnosticLog.isDebugEnabled()) {
                            diagnosticLog.debug("Failed to send diagnostic response, node left " + "[node=" + nodeId + ", msg=" + msg + ']');
                        }
                    } catch (IgniteCheckedException e) {
                        U.error(diagnosticLog, "Failed to send diagnostic response [msg=" + msg0 + "]", e);
                    }
                } else {
                    InternalDiagnosticFuture fut = diagnosticFuturesMap().get(msg0.futureId());
                    if (fut != null) {
                        IgniteDiagnosticInfo res;
                        try {
                            res = msg0.unmarshal(marsh);
                            if (res == null)
                                res = new IgniteDiagnosticInfo("Remote node failed to marshal response.");
                        } catch (Exception e) {
                            U.error(diagnosticLog, "Failed to unmarshal diagnostic response: " + e, e);
                            res = new IgniteDiagnosticInfo("Failed to unmarshal diagnostic response: " + e);
                        }
                        fut.onResponse(res);
                    } else
                        U.warn(diagnosticLog, "Failed to find diagnostic message future [msg=" + msg0 + ']');
                }
            } else
                U.warn(diagnosticLog, "Received unexpected message: " + msg);
        }
    });
    if (sndMetrics) {
        ctx.io().addMessageListener(TOPIC_METRICS, new GridMessageListener() {

            @Override
            public void onMessage(UUID nodeId, Object msg, byte plc) {
                if (msg instanceof ClusterMetricsUpdateMessage)
                    processMetricsUpdateMessage(nodeId, (ClusterMetricsUpdateMessage) msg);
                else
                    U.warn(log, "Received unexpected message for TOPIC_METRICS: " + msg);
            }
        });
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) IgniteClosure(org.apache.ignite.lang.IgniteClosure) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) JMException(javax.management.JMException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteDiagnosticMessage(org.apache.ignite.internal.IgniteDiagnosticMessage) IgniteDiagnosticInfo(org.apache.ignite.internal.IgniteDiagnosticInfo) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) UUID(java.util.UUID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 2 with IgniteDiagnosticMessage

use of org.apache.ignite.internal.IgniteDiagnosticMessage in project ignite by apache.

the class ClusterProcessor method sendDiagnosticMessage.

/**
 * @param nodeId Target node ID.
 * @param c Message closure.
 * @return Message future.
 */
private IgniteInternalFuture<IgniteDiagnosticInfo> sendDiagnosticMessage(UUID nodeId, IgniteClosure<GridKernalContext, IgniteDiagnosticInfo> c) {
    try {
        IgniteDiagnosticMessage msg = IgniteDiagnosticMessage.createRequest(marsh, c, diagFutId.getAndIncrement());
        InternalDiagnosticFuture fut = new InternalDiagnosticFuture(nodeId, msg.futureId());
        diagnosticFuturesMap().put(msg.futureId(), fut);
        ctx.io().sendToGridTopic(nodeId, TOPIC_INTERNAL_DIAGNOSTIC, msg, GridIoPolicy.SYSTEM_POOL);
        return fut;
    } catch (Exception e) {
        U.error(diagnosticLog, "Failed to send diagnostic message: " + e);
        return new GridFinishedFuture<>(new IgniteDiagnosticInfo("Failed to send diagnostic message: " + e));
    }
}
Also used : IgniteDiagnosticMessage(org.apache.ignite.internal.IgniteDiagnosticMessage) IgniteDiagnosticInfo(org.apache.ignite.internal.IgniteDiagnosticInfo) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) JMException(javax.management.JMException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

JMException (javax.management.JMException)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteDiagnosticInfo (org.apache.ignite.internal.IgniteDiagnosticInfo)2 IgniteDiagnosticMessage (org.apache.ignite.internal.IgniteDiagnosticMessage)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ClusterTagUpdatedEvent (org.apache.ignite.events.ClusterTagUpdatedEvent)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 Event (org.apache.ignite.events.Event)1 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)1 IgniteClusterNode (org.apache.ignite.internal.managers.discovery.IgniteClusterNode)1 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)1 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)1 IgniteClosure (org.apache.ignite.lang.IgniteClosure)1