@Override public void stopHost(VerificationHost host) { URI publicUri = host.getPublicUri(); URI clusterUri = this.networkMapping.get(publicUri); String containerId = this.containerIdMapping.get(publicUri); log("Stop host %s(%s) and remove container id %s", publicUri, clusterUri, containerId); stopAndRemoveContainer(containerId); log("Host %s(%s) %s removed", publicUri, clusterUri, containerId); this.networkMapping.remove(publicUri); this.containerIdMapping.remove(publicUri); this.containerStatusMapping.remove(containerId); super.stopHost(host); }
@Override public void stopHostAndPreserveState(ServiceHost host) { URI publicUri = host.getPublicUri(); URI clusterUri = this.networkMapping.get(publicUri); String containerId = this.containerIdMapping.get(publicUri); log("Stopping host %s(%s) and pausing container id %s", publicUri, clusterUri, containerId); this.containerStatusMapping.put(containerId, ContainerStatus.PAUSING); this.dockerClient.pauseContainerCmd(containerId).exec(); this.networkMapping.remove(publicUri); this.containerIdMapping.remove(publicUri); super.stopHostAndPreserveState(host); }
/** * reference: {@Link https://github.com/moby/moby/blob/eb131c5383db8cac633919f82abad86c99bffbe5/cli/command/container/stats_helpers.go} * @return */ public static double calculateCpuPercentUnix(Statistics preCpuStats, Statistics curCpuStats) { Map<String, Object> preCpuStat = preCpuStats.getCpuStats(); long preSystemUsage = (Long) preCpuStat.get(SYSTEM_CPU_USAGE); Map<String, Object> preCpuUsage = (Map) preCpuStat.get(CPU_USAGE); long preTotalUsage = (Long) preCpuUsage.get(TOTAL_USAGE); int preCpuCount = (Integer) preCpuStat.get(ONLINE_CPUS); Map<String, Object> curCpuStat = curCpuStats.getCpuStats(); long curSystemUsage = (Long) curCpuStat.get(SYSTEM_CPU_USAGE); Map<String, Object> curCpuUsage = (Map) curCpuStat.get(CPU_USAGE); long curTotalUsage = (Long) curCpuUsage.get(TOTAL_USAGE); int curCpuCount = (Integer) curCpuStat.get(ONLINE_CPUS); double cpuPercent = 0.0; if (curCpuCount != preCpuCount) { logHost.log(Level.INFO, String.format("cpu count miss match pre: %d, cur: %d", preCpuCount, curCpuCount)); return cpuPercent; } double cpuDelta = curTotalUsage - preTotalUsage; double systemDelta = curSystemUsage - preSystemUsage; if (systemDelta > 0.0 && cpuDelta > 0.0) { cpuPercent = (cpuDelta / systemDelta) * curCpuCount * 100.0; } return cpuPercent; }
@Override public void onNext(Frame frame) { String logFrame = new String(frame.getPayload()); try { int timestamp = LogContainerCallback.parseTimeInSecond(logFrame).intValue(); if (timestamp > this.latestTimestamp) { this.latestTimestamp = timestamp; } // trim timestamp from docker, use timestamp in xenon logFrame = LogContainerCallback.trimTime(logFrame); } catch (Throwable t) { } try { logHost.log(Level.INFO, String.format("%s: %s", this.containerUri, logFrame)); } catch (UnknownFormatConversionException e) { } }
@Override public void joinNodeGroup(URI newNodeGroupService, URI nodeGroup, Integer quorum) { if (nodeGroup.equals(newNodeGroupService)) { return; } // map from public to cluster space URI publicUri = UriUtils.buildUri(nodeGroup.getScheme(), nodeGroup.getHost(), nodeGroup.getPort(), null, null, null); String nodeGroupService = nodeGroup.getPath(); URI clusterUri = this.networkMapping.get(publicUri); URI clusterNodeGroup = UriUtils.buildUri(clusterUri, nodeGroupService); // to become member of a group of nodes, you send a POST to self // (the local node group service) with the URI of the remote node // group you wish to join NodeGroupService.JoinPeerRequest joinBody = NodeGroupService.JoinPeerRequest.create(clusterNodeGroup, quorum); log("Joining %s through %s(%s)", newNodeGroupService, nodeGroup, clusterNodeGroup); // send the request to the node group instance we have picked as the // "initial" one send(Operation.createPost(newNodeGroupService) .setBody(joinBody) .setCompletion(getCompletion())); }
this.host.log(Level.INFO, "example services %d / %d", this.serviceCount - remain, this.serviceCount); this.host.createExampleServices(this.host.getPeerHost(), Thread.sleep(this.cacheCleanDelay); this.host.log(Level.INFO, "example services created"); for (int i = 0; i < this.iteration; i ++) { long start = Utils.getNowMicrosUtc(); waitForFactoryAvailable(); long end = Utils.getNowMicrosUtc(); this.host.log(Level.INFO, "iteration %d time cost %d millis\n", i, (end - start) / 1000);
@Override public void onNext(Statistics stats) { Map<String, Object> memStat = stats.getMemoryStats(); Map<String, Object> blkioStat = stats.getBlkioStats(); Map<String, Object> netStat = stats.getNetworks(); double cpuPercent = 0.0; if (this.preStats != null) { cpuPercent = calculateCpuPercentUnix(this.preStats, stats); } int[] netIO = calculateNetwork(netStat); int[] memUsageLimit = calculateMemory(memStat); int[] blockIo = calculateBlock(blkioStat); logHost.log(Level.INFO, "\n%s(%s)\nCPU %4.3f%% | MEM %4.3f%% (%d KB / %d KB) | NET %d KB / %d KB | BLOCK %d KB / %d KB", this.containerId, this.containerUri, cpuPercent, (memUsageLimit[0] * 1.0 / memUsageLimit[1] * 1.0) * 100, memUsageLimit[0] / 1024, memUsageLimit[1] / 1024, netIO[0] / 1024, netIO[1] / 1024, blockIo[0] / 1024, blockIo[1] / 1024); this.preStats = stats; this.countDownLatch.countDown(); }