@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); } });
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); } }
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; }
@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; } });
@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); }
alive = true; final RemoteExecutor remote = coordinator.getExecutor(agentId);
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()); } }
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; }