private void writeHeader() { String columns = "epoch,timestamp,operations,operations-delta,operations/second,number-of-tests,total-tests\n"; appendText(columns, file); }
/** * Copies a directory recursively. * * @param source the source directory * @param target the target directory */ public static void copyDirectory(File source, File target) { for (File srcFile : source.listFiles()) { if (srcFile.isDirectory()) { File targetChild = new File(target, srcFile.getName()); ensureExistingDirectory(targetChild); copyDirectory(srcFile, targetChild); } else { copyFileToDirectory(srcFile, target); } } }
private void createPidFile() { deleteQuiet(pidFile); writeText("" + getPID(), pidFile); }
public File getSessionDirectory() { String sessionId = this.sessionId; if (sessionId == null) { throw new IllegalStateException("no session active"); } File workersDir = ensureExistingDirectory(getSimulatorHome(), "workers"); return ensureExistingDirectory(workersDir, sessionId); }
public static String loadClientHzConfig() { File file = getConfigurationFile("client-hazelcast.xml"); LOGGER.info("Loading Hazelcast client configuration: " + file.getAbsolutePath()); return fileAsText(file); }
static void copyResourceFile(File workDir, String targetName, String sourceName) { File runScript = ensureExistingFile(workDir, targetName); writeText(getResourceFile(sourceName), runScript); execute(format("chmod u+x %s", runScript.getAbsolutePath())); }
ensureExistingDirectory(workDir); ensureExistingFile(workDir, AgentsFile.NAME); File simulatorPropertiesFile = ensureExistingFile(workDir, SimulatorProperties.PROPERTIES_FILE_NAME); writeText(format("%s=%s%n", PROPERTY_CLOUD_PROVIDER, cloudProvider), simulatorPropertiesFile); if (isEC2(cloudProvider)) { appendText(format( "%n# These files contain your AWS access key ID and secret access key (change if needed)%n#%s=%s%n#%s=%s%n", PROPERTY_CLOUD_IDENTITY, simulatorProperties.get(PROPERTY_CLOUD_IDENTITY), PROPERTY_CLOUD_CREDENTIAL, simulatorProperties.get(PROPERTY_CLOUD_CREDENTIAL)), simulatorPropertiesFile); appendText(format( "%n# Machine specification used for AWS (change if needed)%n#MACHINE_SPEC=%s%n", simulatorProperties.get("MACHINE_SPEC")), simulatorPropertiesFile); appendText(format( "%n# These files contain your GCE credentials (change if needed)%n%s=%s%n%s=%s%n", PROPERTY_CLOUD_IDENTITY, "~/gce.id", PROPERTY_CLOUD_CREDENTIAL, "~/gce.pem"), simulatorPropertiesFile); appendText(format( "%nGROUP_NAME=simulator-agent%nUSER=%s%n", currentUser), simulatorPropertiesFile); appendText(format( "%n# Machine specification used for GCE (change if needed)%nMACHINE_SPEC=%s%n", GCE_DEFAULT_MACHINE_SPEC), simulatorPropertiesFile); appendText(format( "%n# SSH options used for GCE (change if needed)%nSSH_OPTIONS=%s %s%n",
private void executeInitScript(String ip) { File initFile = newFile("init-" + newUnsecureUuidString() + ".sh"); writeText(loadInitScript(), initFile); bash.scpToRemote(ip, initFile, "init.sh"); bash.sshTTY(ip, "bash init.sh"); deleteQuiet(initFile); }
void createSshCopyIdScript(SimulatorProperties simulatorProperties) { ComponentRegistry componentRegistry = loadComponentRegister(agentFile, true); String userName = simulatorProperties.getUser(); ensureExistingFile(SSH_COPY_ID_FILE); writeText("#!/bin/bash" + NEW_LINE + NEW_LINE, SSH_COPY_ID_FILE); for (AgentData agentData : componentRegistry.getAgents()) { String publicAddress = agentData.getPublicAddress(); appendText(format("ssh-copy-id -i ~/.ssh/id_rsa.pub %s@%s%n", userName, publicAddress), SSH_COPY_ID_FILE); } execute(format("chmod u+x %s", SSH_COPY_ID_FILE.getAbsoluteFile())); echo("Please execute './%s' to copy your public RSA key to all remote machines.", SSH_COPY_ID_FILE.getName()); }
private void detectExceptions(WorkerProcess workerProcess) { File workerHome = workerProcess.getWorkerHome(); if (!workerHome.exists()) { return; } File[] exceptionFiles = ExceptionExtensionFilter.listFiles(workerHome); for (File exceptionFile : exceptionFiles) { String content = fileAsText(exceptionFile); int indexOf = content.indexOf(NEW_LINE); String testId = content.substring(0, indexOf); String cause = content.substring(indexOf + 1); if (testId.isEmpty() || "null".equals(testId)) { testId = null; } // we delete or rename the exception file so that we don't detect the same exception again boolean send = failureHandler.handle("Worked ran into an unhandled exception", WORKER_EXCEPTION, workerProcess, testId, cause); if (send) { deleteQuiet(exceptionFile); } else { rename(exceptionFile, new File(exceptionFile.getParentFile(), exceptionFile.getName() + ".sendFailure")); } } }
public static String getFileAsTextFromWorkingDirOrBaseDir(File baseDir, String fileName, String desc) { File file = newFile(fileName); if (!file.exists()) { file = newFile(baseDir + File.separator + "conf" + File.separator + fileName); } if (!file.exists()) { throw new UncheckedIOException(format("%s [%s] does not exist", desc, file.getAbsolutePath())); } LOGGER.info("Loading " + desc + ": " + file.getAbsolutePath()); return fileAsText(file); }
File dir = getUserDir(); File tmpFile = new File(dir, targetFileName + ".tmp"); try { writeText(testId + NEW_LINE + throwableToString(cause), tmpFile); rename(tmpFile, file);
public static File getConfigurationFile(String filename) { File file = new File(filename).getAbsoluteFile(); if (file.exists()) { return file; } else { return newFile(getSimulatorHome(), "conf", filename).getAbsoluteFile(); } } }
private String readAddress(WorkerProcess workerProcess) { File file = new File(workerProcess.getWorkerHome(), "worker.address"); if (!file.exists()) { return null; } String address = fileAsText(file); deleteQuiet(file); return address; }
public static File newFile(String... items) { File file = newFile(items[0]); for (int i = 1; i < items.length; i++) { file = new File(file, items[i]); } return file; }
public static void assertNoExceptions() { File userDir = getUserDir(); if (userDir.exists()) { for (File file : userDir.listFiles()) { if (file.isDirectory()) { continue; } assertFalse("exception found: " + file + " content: " + fileAsText(file), file.getName().endsWith(".exception")); } } }
public String getAsString() { return fileAsText(propertiesFile); }
public static File ensureExistingDirectory(String dirName) { File dir = new File(dirName); ensureExistingDirectory(dir); return dir; }
void install(String simulatorPath, File profileFile) { echoImportant("Hazelcast Simulator Installation"); echo("Found Simulator in the following directory: %s", simulatorPath); echo("Found the following profile file: %s", profileFile.getAbsolutePath()); String profile = fileAsText(profileFile); if (profile.contains("SIMULATOR_HOME")) { throw new CommandLineExitException("Hazelcast Simulator seems to be already installed on this system!"); } String config = NEW_LINE + "# Hazelcast Simulator configuration" + NEW_LINE + "export SIMULATOR_HOME=" + simulatorPath + NEW_LINE + "PATH=$SIMULATOR_HOME/bin:$PATH" + NEW_LINE; echo("Will append the following configuration to your profile file:%n%s", config); appendText(config, profileFile); echo("Done!%n%nNOTE: Don't forget to start a new terminal to make changes effective!"); }