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);
}
});
}
}
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));
}
}
Aggregations