@Override public void run(Command<Serializable> command, AsyncCallback<Serializable> callback) { log.debug("Going send command {} to delegate coordinator", command); RemoteExecutor remoteExecutor = coordinator.getExecutor(node); remoteExecutor.run(command, Coordination.doNothing(), callback); } });
@Override public void registerNode(final NodeId node, Set<Qualifier<Command<Serializable>>> qualifiers) { log.debug("Register node {} with qualifiers {} requested", node, qualifiers); Worker worker = createProxyWorker(qualifiers); coordinator.registerNode(Coordination.emptyContext(node), Sets.newHashSet(worker), LOGGING_LISTENER); exchangers.put(node, createPackRunner(node)); log.debug("Node {} registered", node); }
@Override public Service distribute(final ExecutorService executor, final String sessionId, final String taskId, final Multimap<NodeType, NodeId> availableNodes, final Coordinator coordinator, final T task, final DistributionListener listener, NodeContext nodeContext) { Set<Qualifier<?>> qualifiers = getQualifiers(); final Map<NodeId, RemoteExecutor> remotes = Maps.newHashMap(); for (NodeId nodeId : availableNodes.get(NodeType.KERNEL)) { boolean canRunTheCommand = coordinator.canExecuteCommands(nodeId, qualifiers); if (canRunTheCommand) { remotes.put(nodeId, coordinator.getExecutor(nodeId)); } else { log.debug("command type {} are not supported by kernel {}", qualifiers, nodeId); } } if (remotes.isEmpty()) { throw new NodeNotFound("Nodes not found to distribute the task"); } final Service service = performDistribution(executor, sessionId, taskId, task, remotes, availableNodes, coordinator, nodeContext); return new ListenableService<T>(service, executor, sessionId, taskId, task, listener, remotes); }
private static void initCoordinator(ApplicationContext applicationContext) { final Coordinator coordinator = (Coordinator) applicationContext.getBean("coordinator"); coordinator.waitForReady(); coordinator.initialize(); }
private void processAgentManagement(String sessionId, Map<ManageAgent.ActionProp, Serializable> agentManagementProps) { for (NodeId agent : coordinator.getAvailableNodes(NodeType.AGENT)) { // async run coordinator.getExecutor(agent).run(new ManageAgent(sessionId, agentManagementProps), Coordination.<ManageAgent>doNothing()); } }
@Override public void run() { log.info("Starting Kernel"); ApplicationContext context = loadContext(directory, KERNEL_CONFIGURATION, environmentProperties); final CountDownLatch latch = new CountDownLatch(1); final Coordinator coordinator = (Coordinator) context.getBean("coordinator"); kernel = (Kernel) context.getBean("kernel"); toTerminate(kernel); Runnable kernelRunner = () -> { try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } kernel.run(); }; getExecutor().execute(kernelRunner); coordinator.waitForReady(); coordinator.waitForInitialization(); latch.countDown(); } };
do { for (NodeType nodeType : nodesCountDowns.keySet()) { Collection<NodeId> availableNodes = coordinator.getAvailableNodes(nodeType); for (NodeId availableNode : availableNodes) { if (!allNodes.get(nodeType).contains(availableNode)) {
public Map<NodeId,GeneralNodeInfo> getGeneralNodeInfo(String sessionId, Coordinator coordinator) { final String localSessionId = sessionId; Set<NodeId> nodes = new HashSet<NodeId>(); Map<NodeId,GeneralNodeInfo> result = new HashMap<NodeId, GeneralNodeInfo>(); nodes.addAll(coordinator.getAvailableNodes(NodeType.KERNEL)); nodes.addAll(coordinator.getAvailableNodes(NodeType.AGENT)); for (NodeId node : nodes) { try { final GeneralNodeInfo generalNodeInfo = coordinator.getExecutor(node).runSyncWithTimeout(new GetGeneralNodeInfo(sessionId), Coordination.<GetGeneralNodeInfo>doNothing(), nodeCollectInfoTime); generalNodeInfo.setNodeId(node.toString()); log.info("Got node info from node {}:\n {}", node, generalNodeInfo.toString()); getHibernateTemplate().execute(new HibernateCallback<Void>() { @Override public Void doInHibernate(Session session) throws HibernateException, SQLException { session.persist(new NodeInfoEntity(localSessionId,generalNodeInfo)); session.flush(); return null; } }); result.put(node,generalNodeInfo); } catch (Throwable e) { log.error("Get node info failed for node " + node + "\n" + Throwables.getStackTraceAsString(e)); } } return result; }
final String sessionId = sessionIdProvider.getSessionId(); Multimap<NodeType, NodeId> allNodes = HashMultimap.create(); allNodes.putAll(NodeType.MASTER, coordinator.getAvailableNodes(NodeType.MASTER)); NodeContext context = Coordination.contextBuilder(NodeId.masterNode()) .addService(LogWriter.class, getLogWriter())
public Map<NodeId, MonitoringStatus> getStatus() { Map<NodeId, MonitoringStatus> result = Maps.newHashMap(); for (NodeId nodeId : capableNodes) { RemoteExecutor remote = coordinator.getExecutor(nodeId); Collection<String> processes = activeProcesses.get(nodeId); for (String processId : processes) { remote.runSyncWithTimeout(PollMonitoringStatus.create(sessionId, processId), Coordination.<Command>doNothing(), ttl * 2); } } return result; }
while (!kernel.isConnected()) { try { this.coordinator.registerNode(kernel.getContext(), kernel.getWorkers(), new StatusChangeListener() { @Override public void onNodeStatusChanged(NodeId nodeId, NodeStatus status) {
public void startMonitoring() { log.debug("Start of monitoring requested. Task id {}", taskId); // todo use nodes on start Collection<NodeId> agents = availableNodes.get(NodeType.AGENT); log.debug("Available agents {}", agents); Iterator<NodeId> iterator = capableNodes.iterator(); for (NodeId agent : agents) { if (!iterator.hasNext()) { iterator = capableNodes.iterator(); } NodeId kernel = iterator.next(); RemoteExecutor remote = coordinator.getExecutor(kernel); log.info("Agent {} will be monitored by kernel {}", agent, kernel); log.debug("Start monitoring command is sending"); String processId = remote.runSyncWithTimeout(StartMonitoring.create(sessionId, agent, taskId), Coordination.<StartMonitoring>doNothing(), ttl * 2); log.debug("Start monitoring command is sent. Process with id {} started", processId); activeProcesses.put(kernel, processId); agentMapping.put(processId, agent); } }
@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; } });
alive = true; final RemoteExecutor remote = coordinator.getExecutor(agentId);