@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 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 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 void tick(WorkloadExecutionStatus status, WorkloadAdjuster adjuster) { // spare qps between Nodes Set<NodeId> nodes = status.getNodes(); BigDecimal currentQps = desiredQps.get(System.currentTimeMillis()); log.debug("current qps value to schedule = {} ", currentQps); if (currentQps.compareTo(ONE_TENTH) < 0) { currentQps = ONE_TENTH; log.debug("new calculated qps : " + currentQps); } // period per node in milliseconds long periodPerNode = BigDecimal.valueOf(1000L).divide(currentQps, BigDecimal.ROUND_DOWN).longValue() * nodes.size(); log.debug("period per node = {}", periodPerNode); for(NodeId node : status.getNodes()) { WorkloadConfiguration workloadConfiguration = WorkloadConfiguration.with( periodPerNode, maxThreads); log.debug("adjust workload configuration {} to node with identifier {}", workloadConfiguration, node.getIdentifier()); adjuster.adjustConfiguration(node, workloadConfiguration); } }
throw new CoordinatorException("Node " + nodeId.getIdentifier() + " hasn't registered");
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 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))); }
@Override public void process(String sessionId, String taskId, NodeId agentId, NodeContext nodeContext, SystemInfo systemInfo) { String serviceId = getKey(sessionId, taskId); if (!metricServiceMap.containsKey(serviceId)){ metricServiceMap.put(serviceId, new DefaultMetricService(sessionId, taskId, nodeContext)); } long timeStamp = systemInfo.getTime(); // save sigar metrics saveMonitoringValues(serviceId, agentId.getIdentifier(), systemInfo.getSysInfo(), timeStamp); // save jmx metrics if (systemInfo.getSysUnderTest() != null){ for (Map.Entry<String, SystemUnderTestInfo> entry : systemInfo.getSysUnderTest().entrySet()){ saveMonitoringValues(serviceId, entry.getKey(), entry.getValue().getSysUTInfo(), timeStamp); } } log.trace("System info {} received from agent {} and has been written to FileStorage", systemInfo, agentId); }
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(); } });
private <C extends Command<R>, R extends Serializable> CommandExecutor<C, R> getCommandExecutor(C command){ for (CommandExecutor<?, ?> commandExecutor : nodePair.getSecond()) { final CommandExecutor<C, R> executor = (CommandExecutor<C, R>) commandExecutor; if (executor.getQualifier().equals(Qualifier.of(command))) { return executor; } } throw new CoordinatorException("Command " + command + " is not available on " + nodeId.getIdentifier()); } };
} else { log.debug("got collected profiler from agent {} from kernel {}", agentId, nodeContext.getId()); logWriter.log(sessionId, taskId + "/" + PROFILER_MARKER, agentId.getIdentifier(), SerializationUtils.toString(profileDTO)); log.debug("Profiler {} received from agent {} and has been written to FileStorage", profileDTO, agentId); logWriter.flush();
if (typeNode.hasChild(nodeContext.getId().getIdentifier())) { typeNode.child(nodeContext.getId().getIdentifier()).removeWithChildren(); ZNode node = typeNode.createChild(znode().withPath(nodeContext.getId().getIdentifier()));
@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");
@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; }