public static void writeCSVResult(LoadTestConfigModel model, long resTime) throws IOException { FileWriter writer = new FileWriter("loadTestResults.csv", true); writer.append(String.valueOf(model.getNodeCount())); writer.append(","); writer.append(String.valueOf(model.getFileCount())); writer.append(","); writer.append(String.valueOf(model.getFileSize())); writer.append(","); writer.append(String.valueOf(resTime)); writer.append("\n"); writer.flush(); writer.close(); }
public boolean startDockerSlave(LoadTestConfigModel ltModel) throws InterruptedException, IOException { String fileCount = String.valueOf(ltModel.getFileCount()); if (runInDockerCluster) { HashMap<String, Integer> dockerNodes = getDockerNodes(); Entry<String, Integer> entry = this.getLowestDockerHost(); startedClusterContainer.put(entry.getKey(), entry.getValue() + 1); String dockerCommand = "{" + "\"Hostname\":\"\"," + "\"User\":\"\"," + "\"Entrypoint\":[\"/bin/bash\",\"/pieShare/pieShareAppIntegrationTests/src/test/resources/docker/internal.sh\"]," + "\"Cmd\":[\"slave\",\"" + fileCount.toString() + "\"]," + "\"Memory\":0," + "\"MemorySwap\":0," + "\"AttachStdin\":false," + "\"AttachStdout\":false," + "\"AttachStderr\":false," + "\"PortSpecs\":null," + "\"Privileged\": false," + "\"Tty\":false," + "\"OpenStdin\":false," + "\"StdinOnce\":false," + "\"Env\":null," + "\"Dns\":null," + "\"Image\":\"vauvenal5/loadtest\"," + "\"Volumes\":{}," + "\"VolumesFrom\":\"\"," + "\"WorkingDir\":\"\"}"; String url = entry.getKey() + "/containers/create"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-type", "application/json"); con.setDoOutput(true); con.getOutputStream().write(dockerCommand.getBytes()); con.getOutputStream().flush(); con.getOutputStream().close(); int responseCode = con.getResponseCode(); if (responseCode != 201) { return false; } BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String line = null; String msg = ""; while ((line = in.readLine()) != null) { msg += line; } ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree(msg); String containerId = node.get("Id").asText(); con.disconnect(); url = entry.getKey() + "/containers/" + containerId + "/start"; obj = new URL(url); con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-type", "application/json"); responseCode = con.getResponseCode(); if (responseCode != 204) { return false; } if (!this.runningContainers.containsKey(entry.getKey())) { this.runningContainers.put(entry.getKey(), new ArrayList<>()); } this.runningContainers.get(entry.getKey()).add(containerId); return true; } ProcessBuilder processBuilder = new ProcessBuilder("docker", "run", "vauvenal5/loadtest", "slave", fileCount); Process proc = processBuilder.start(); this.slaves.add(proc); return true; }