use of org.smartdata.server.cluster.NodeCmdletMetrics in project SSM by Intel-bigdata.
the class CmdletDispatcher method getNodeCmdletMetrics.
public Collection<NodeCmdletMetrics> getNodeCmdletMetrics() {
ActiveServerNodeCmdletMetrics metrics = (ActiveServerNodeCmdletMetrics) regNodeInfos.get(ActiveServerInfo.getInstance().getId());
if (metrics != null) {
metrics.setNumPendingDispatch(pendingCmdlets.size());
metrics.setMaxPendingDispatch(getTotalSlotsLeft() + (int) (getTotalSlots() * 0.2));
metrics.setMaxInExecution(getTotalSlots());
metrics.setNumInExecution(getTotalSlots() - getTotalSlotsLeft());
cmdletManager.updateNodeCmdletMetrics(metrics);
}
// TODO: temp implementation
List<NodeCmdletMetrics> ret = new LinkedList<>();
ret.addAll(regNodeInfos.values());
Collections.sort(ret, new Comparator<NodeCmdletMetrics>() {
@Override
public int compare(NodeCmdletMetrics a, NodeCmdletMetrics b) {
int tp = a.getNodeInfo().getExecutorType().ordinal() - b.getNodeInfo().getExecutorType().ordinal();
return tp == 0 ? a.getNodeInfo().getId().compareToIgnoreCase(b.getNodeInfo().getId()) : tp;
}
});
return ret;
}
use of org.smartdata.server.cluster.NodeCmdletMetrics in project SSM by Intel-bigdata.
the class CmdletDispatcher method onCmdletFinished.
public void onCmdletFinished(long cmdletId) {
synchronized (dispatchedToSrvs) {
if (dispatchedToSrvs.containsKey(cmdletId)) {
LaunchCmdlet cmdlet = idToLaunchCmdlet.get(cmdletId);
if (cmdlet == null) {
return;
}
if (regNodes.get(cmdlet.getNodeId()) != null) {
regNodes.get(cmdlet.getNodeId()).incrementAndGet();
}
NodeCmdletMetrics metrics = regNodeInfos.get(cmdlet.getNodeId());
if (metrics != null) {
metrics.finishCmdlet();
}
ExecutorType t = dispatchedToSrvs.remove(cmdletId);
updateSlotsLeft(t.ordinal(), 1);
completeOn[t.ordinal()] = cmdlet.getNodeId();
}
}
}
use of org.smartdata.server.cluster.NodeCmdletMetrics in project SSM by Intel-bigdata.
the class CmdletDispatcher method onNodeMessage.
/**
* Maintain SSM cluster nodes. Add the node if {@code isAdd} is true.
* Otherwise, remove the node.
* If local executor is disabled, we will not tackle the node message
* for active server. And the metrics for it will be set at {@link
* #start start}
*/
public void onNodeMessage(NodeMessage msg, boolean isAdd) {
// executing start-standby-server.sh.
if (msg.getNodeInfo().getExecutorType() == ExecutorType.REMOTE_SSM) {
conf.addServerHosts(msg.getNodeInfo().getHost());
}
// start-agent.sh.
if (msg.getNodeInfo().getExecutorType() == ExecutorType.AGENT) {
conf.addAgentHost(msg.getNodeInfo().getHost());
}
synchronized (cmdExecSrvInsts) {
String nodeId = msg.getNodeInfo().getId();
if (isAdd) {
if (regNodes.containsKey(nodeId)) {
LOG.warn("Skip duplicate add node for {}", msg.getNodeInfo());
return;
}
regNodes.put(nodeId, new AtomicInteger(defaultSlots));
NodeCmdletMetrics metrics = msg.getNodeInfo().getExecutorType() == ExecutorType.LOCAL ? new ActiveServerNodeCmdletMetrics() : new NodeCmdletMetrics();
// Here, we consider all nodes have same configuration for executorsNum.
int actualExecutorsNum = metrics instanceof ActiveServerNodeCmdletMetrics && disableLocalExec ? 0 : executorsNum;
metrics.setNumExecutors(actualExecutorsNum);
metrics.setRegistTime(System.currentTimeMillis());
metrics.setNodeInfo(msg.getNodeInfo());
regNodeInfos.put(nodeId, metrics);
} else {
if (!regNodes.containsKey(nodeId)) {
LOG.warn("Skip duplicate remove node for {}", msg.getNodeInfo());
return;
}
regNodes.remove(nodeId);
regNodeInfos.remove(nodeId);
}
// Ignore local executor if it is disabled.
if (disableLocalExec && msg.getNodeInfo().getExecutorType() == ExecutorType.LOCAL) {
return;
}
// Maintain executor service in the below code.
if (isAdd) {
cmdExecSrvNodeIds.get(msg.getNodeInfo().getExecutorType().ordinal()).add(nodeId);
} else {
cmdExecSrvNodeIds.get(msg.getNodeInfo().getExecutorType().ordinal()).remove(nodeId);
}
int v = isAdd ? 1 : -1;
int idx = msg.getNodeInfo().getExecutorType().ordinal();
cmdExecSrvInsts[idx] += v;
cmdExecSrvTotalInsts += v;
updateSlotsLeft(idx, v * defaultSlots);
}
LOG.info(String.format("Node " + msg.getNodeInfo() + (isAdd ? " added." : " removed.")));
}
Aggregations