@Override public String toString() { String line = "---------------------------------------------------------------------------------------------------------------------------------------------------\n"; String format = "|%1$-40s|%2$-20s|%3$-20s|%4$-20s|%5$-20s|%6$-20s|\n"; String report = String.format(this.task.getTaskName() + '\n' + line + format + line, "IDENTIFIER", "THREADS", "STARTED", "SAMPLES", "DELAYS", "DURATION,s"); Set<NodeId> nodes = Sets.newHashSet(this.threads.keySet()); nodes.addAll(this.startedSamples.keySet()); nodes.addAll(this.delays.keySet()); for (NodeId node : nodes) { report += String.format(format, node.getIdentifier(), this.threads.get(node), this.startedSamples.get(node), this.finishedSamples.get(node), this.delays.get(node), this.durationTime.get(node)/1000); } return report + line; } }
@Override public boolean apply(NodeId input) { return input.getType().equals(type); } });
public static NodeId kernelNode(){ return kernelNode(NodeType.KERNEL.toString() + "-" + new Random().nextInt() + " [" + getLocalHostAddress() + "]"); }
public static NodeId masterNode() { return NodeId.of(NodeType.MASTER, "MASTER ["+getLocalHostAddress()+"]"); }
@Override public boolean canExecuteCommands(NodeId nodeId, Set<Qualifier<?>> qualifiers) { ZNode typeNode = rootNode.child(CoordinationUtil.nodeNameOf(nodeId.getType())); String identifier = nodeId.getIdentifier(); if (!typeNode.hasChild(identifier)) { throw new CoordinatorException("Node with id " + nodeId + " is not found"); } ZNode node = typeNode.child(identifier); if (!node.hasChild(CoordinationUtil.AVAILABLE_NODE_NAME)) { return false; } for (Qualifier<?> qualifier : qualifiers) { if (!node.hasChild(nodeNameOf(qualifier))) { return false; } } return true; }
public static NodeId agentNode(String identifier) { return NodeId.of(NodeType.AGENT, identifier); }
public SimpleKernel(Coordinator coordinator) { super(coordinator); lock = new CountDownLatch(1); this.nodeId = NodeId.kernelNode(); }
@Override public int hashCode() { int result = node.hashCode(); result = 31 * result + qualifiers.hashCode(); return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; RegistrationPack that = (RegistrationPack) o; if (!node.equals(that.node)) return false; if (!qualifiers.equals(that.qualifiers)) return false; return true; }
public static NodeId of(NodeType type, String identifier) { Preconditions.checkNotNull(type); Preconditions.checkNotNull(identifier); return new NodeId(type, identifier); }
String name = ((AgentConfig) context.getBean("agentConfig")).getName(); Agent agent = (Agent) context.getBean("agent"); agent.setNodeContext(Coordination.emptyContext(NodeId.agentNode(name))); agent.init();
@Override public <C extends Command<R>, R extends Serializable> void run(final C command, final NodeCommandExecutionListener<C> listener, final AsyncCallback<R> callback) { ZNode commandNode = rootNode.child(nodeId.getType().name().toLowerCase()).child(nodeId.getIdentifier()).child(command.getClass().getName()); ZNode queueNode = commandNode.child("queue"); ZNode resultNode = commandNode.child("result");
public static NodeId kernelNode(String identifier) { return NodeId.of(NodeType.KERNEL, identifier); }
@Override public int hashCode() { int result = node != null ? node.hashCode() : 0; result = 31 * result + (pack != null ? pack.hashCode() : 0); return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PackRequest packRequest = (PackRequest) o; if (node != null ? !node.equals(packRequest.node) : packRequest.node != null) return false; if (pack != null ? !pack.equals(packRequest.pack) : packRequest.pack != null) return false; return true; }
@Override public Void call() throws Exception { try { RemoteExecutor remote = coordinator.getExecutor(kernel); log.info("Going to send stop monitoring command to kernel {}", kernel); remote.runSyncWithTimeout(StopMonitoring.create(sessionId, processId), Coordination.doNothing(), 2*ttl); log.info("Command stop monitoring successfully sent"); NodeId agent = agentMapping.get(processId); log.info("Agent {} monitoring is stopped on kernel {}", agent, kernel); } catch (Throwable e) { log.error("Stop monitoring failed for kernel {}, process {}", kernel.getIdentifier(), processId); return null; } return null; } });
log.info("Going to register node {} with {} workers", nodeContext.getId(), workers.size()); ZNode typeNode = rootNode.child(CoordinationUtil.nodeNameOf(nodeContext.getId().getType())); if (typeNode.hasChild(nodeContext.getId().getIdentifier())) { typeNode.child(nodeContext.getId().getIdentifier()).removeWithChildren(); ZNode node = typeNode.createChild(znode().withPath(nodeContext.getId().getIdentifier()));
public static NodeId masterNode(String identifier) { return NodeId.of(NodeType.MASTER, identifier); }
@Override public void saveValue(String metricId, Number value, long timeStamp) { LogWriter logWriter = context.getService(LogWriter.class); try { metricId = URLEncoder.encode(metricId, "UTF-8"); logWriter.log(sessionId, taskId + File.separatorChar + METRIC_MARKER + File.separatorChar + metricId, context.getId().getIdentifier(), new MetricLogEntry(timeStamp, metricId, value)); } catch (UnsupportedEncodingException e) { log.error("Can't save metric value with id={}", metricId, e); } }
@Override public Set<NodeId> getAvailableNodes(NodeType type) { Set<NodeId> result = Sets.newHashSet(); ZNode typeNode = rootNode.child(CoordinationUtil.nodeNameOf(type)); for (ZNode node : typeNode.children()) { if (node.hasChild(CoordinationUtil.AVAILABLE_NODE_NAME)) { result.add(NodeId.of(type, node.getShortPath())); } } return result; }