@Override public ArrayList<SystemInfo> execute(GetSystemInfo command, NodeContext nodeContext) { long startTime = System.currentTimeMillis(); log.debug("start GetSystemInfo on agent {}", nodeContext.getId()); ArrayList<SystemInfo> systemInfo = getSystemInfo(); log.debug("finish GetSystemInfo on agent {} time {} ms", nodeContext.getId(), System.currentTimeMillis() - startTime); return systemInfo; } });
@Override public GeneralNodeInfo execute(GetGeneralNodeInfo command, NodeContext nodeContext) { long startTime = System.currentTimeMillis(); log.debug("start GetGeneralNodeInfo on agent {}", nodeContext.getId()); GeneralNodeInfo generalNodeInfo = generalInfoCollector.getGeneralNodeInfo(); log.debug("finish GetGeneralNodeInfo on agent {} time {} ms", nodeContext.getId(), System.currentTimeMillis() - startTime); return generalNodeInfo; } });
@Override public GeneralNodeInfo doExecute(GetGeneralNodeInfo command, NodeContext nodeContext) { long startTime = System.currentTimeMillis(); log.debug("start GetGeneralNodeInfo on kernel {}", nodeContext.getId()); GeneralNodeInfo generalNodeInfo = generalInfoCollector.getGeneralNodeInfo(); log.debug("finish GetGeneralNodeInfo on kernel {} time {} ms", nodeContext.getId(), System.currentTimeMillis() - startTime); return generalNodeInfo; } });
@Override public void stop() { log.info("Stop of monitoring requested. agent {}", agentId); if (alive) { latch = new CountDownLatch(1); alive = false; try { latch.await(); } catch (InterruptedException e) { log.warn("Interrupted {}", e); } log.info("Kernel {} has stopped monitoring on agent {}", nodeContext.getId(), agentId); } else { log.warn("Monitoring on agent {} is not running. Skipping StopMonitoring", agentId); } }
@Override public R execute(C command, NodeContext nodeContext) { LogWriter logWriter = nodeContext.getService(LogWriter.class); try { log.debug("Execute command {} on {}", command, nodeContext.getId()); return delegate.execute(command, nodeContext); } finally { log.debug("Flushing results execution command {} on {}", command, nodeContext.getId()); logWriter.flush(); } } }
@Override public Nothing execute(StopMonitoring command, NodeContext nodeContext) { log.debug("StopMonitoring command received on node {}", nodeContext.getId()); String processId = command.getProcessId(); MonitorProcess process = processes.get(processId); log.debug("Going to stop MonitorProcess with id {}", processId); process.stop(); return Nothing.INSTANCE; } });
@Override public void registerNode(NodeContext nodeContext, Set<Worker> workers, final StatusChangeListener listener) { log.info("Going to register node {} with {} workers", nodeContext.getId(), workers.size()); Set<CommandExecutor<?, ?>> executors = Sets.newHashSet(); Set<Qualifier<?>> qualifiers = Sets.newHashSet(); for (Worker worker : workers) { for (CommandExecutor<?, ?> executor : worker.getExecutors()) { Qualifier<?> qualifier = executor.getQualifier(); if (qualifiers.contains(qualifier)) { throw new CoordinatorException("Executor for qualifier " + qualifier + " is already registered"); } executors.add(executor); } } nodes.put(nodeContext.getId(), Pair.of(nodeContext, executors)); }
@Override public ProfileDTO execute(GetCollectedProfileFromSuT command, NodeContext nodeContext) { String hostAddress; long startTime = System.currentTimeMillis(); try { hostAddress = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { hostAddress = "UNKNOWN"; } ProfileDTO profileDTO = new ProfileDTO(hostAddress, Collections.EMPTY_MAP); if (profilerEnabled) { log.debug("start GetCollectedProfileFromSuT on agent {}", nodeContext.getId()); Map<String, RuntimeGraph> runtimeGraphs = profiler.getSamplingProfiler().getRuntimeGraph(); profileDTO = new ProfileDTO(hostAddress, runtimeGraphs); log.debug("finish GetCollectedProfileFromSuT on agent {} time {} ms", nodeContext.getId(), System.currentTimeMillis() - startTime); } return profileDTO; } });
private ArrayList<SystemInfo> getSystemInfo() { SystemInfo systemInfo = this.monitoringInfoService.getSystemInfo(); systemInfo.setNodeId(this.agent.getNodeContext().getId()); return new ArrayList<SystemInfo>(Collections.singletonList(systemInfo)); }
private Namespace namespace() { return Namespace.of(sessionId, taskId, "ValidationCollector", kernelContext.getId().toString()); }
private Namespace namespace() { return Namespace.of(sessionId, taskId, "ValidationCollector", kernelContext.getId().toString()); }
private Namespace namespace() { return Namespace.of(sessionId, taskId, "InformationCollector", kernelContext.getId().toString()); }
@Override public VoidResult execute(final ManageCollectionProfileFromSuT command, NodeContext nodeContext) { VoidResult voidResult = new VoidResult(); if (profilerEnabled) { long startTime = System.currentTimeMillis(); log.debug("start ManageCollectionProfileFromSuT on agent {}", nodeContext.getId()); try { profiler.manageRuntimeGraphsCollection(command.getAction(), Collections.<String, Object>singletonMap(Profiler.POLL_INTERVAL, command.getProfilerPollingInterval())); } catch (Exception e) { voidResult.setException(e); } log.debug("finish ManageCollectionProfileFromSuT on agent {} time {} ms", nodeContext.getId(), System.currentTimeMillis() - startTime); } return voidResult; } });
@Override protected Serializable handleCommand(Command<Serializable> command, NodeContext nodeContext) { log.debug("Handling command {} for node {}", command, nodeContext); AsyncRunner<Command<Serializable>, Serializable> packExchanger = exchangers.get(nodeContext.getId()); FutureAsyncCallback<Serializable> callback = FutureAsyncCallback.create(); packExchanger.run(command, callback); SettableFuture<Serializable> future = callback.getFuture(); try { log.debug("Waiting for command completion"); return future.get(); } catch (InterruptedException e) { throw Throwables.propagate(e); } catch (ExecutionException e) { throw Throwables.propagate(e); } } };
@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); } }
private void rememberDuration(long duration) { Long endTime = System.currentTimeMillis(); double durationSeconds = (double) duration / 1000; totalDuration = totalDuration + durationSeconds; totalDurationSqr = totalDurationSqr + (durationSeconds * durationSeconds); LogWriter logWriter = kernelContext.getService(LogWriter.class); long startTime = endTime - duration; logWriter.log(sessionId, taskId + File.separatorChar + DURATION_MARKER, kernelContext.getId().getIdentifier(), new DurationLogEntry(startTime, duration)); }
@Override public void flush() { Namespace namespace = Namespace.of(sessionId, taskId, "DurationCollector", kernelContext.getId().toString()); kernelContext.getService(KeyValueStorage.class).put(namespace, TOTAL_DURATION, totalDuration); log.debug("saved total_duration for namespace {}", namespace); kernelContext.getService(KeyValueStorage.class).put(namespace, TOTAL_SQR_DURATION, totalDurationSqr); log.debug("saved total_sqr_duration for namespace {}", namespace); }
@Override public void onSuccess(Q query, E endpoint, R result, long duration) { Long endTime = System.currentTimeMillis(); LogWriter logWriter = kernelContext.getService(LogWriter.class); long startTime = endTime - duration; logWriter.log(sessionId, taskId + File.separatorChar + METRIC_MARKER + File.separatorChar + name, kernelContext.getId().getIdentifier(), new MetricLogEntry(startTime, name, metricCalculator.calculate(result))); }
private void log(long result) { LogWriter logWriter = kernelContext.getService(LogWriter.class); logWriter.log(sessionId, taskId + File.separatorChar + METRIC_MARKER + File.separatorChar + name, kernelContext.getId().getIdentifier(), new MetricLogEntry(startTime, name, result)); } }
@Override public WorkloadStatus doExecute(StopWorkloadProcess command, NodeContext nodeContext) { log.debug("Going to stop process {} on kernel {}", command.getProcessId(), nodeContext.getId().getIdentifier()); Preconditions.checkArgument(command.getProcessId() != null, "Process id cannot be null"); WorkloadProcess process = getProcess(command.getProcessId()); process.stop(); processes.remove(command.getProcessId()); logWriter.flush(); return process.getStatus(); } });