public String getAsString() { return fileAsText(propertiesFile); }
public static String fileAsText(String fileName) { return fileAsText(new File(fileName)); }
public static String fileAsText(String fileName) { return fileAsText(new File(fileName)); }
public static String loadClientHzConfig() { File file = getConfigurationFile("client-hazelcast.xml"); LOGGER.info("Loading Hazelcast client configuration: " + file.getAbsolutePath()); return fileAsText(file); }
public static String loadMemberHzConfig() { File file = getConfigurationFile("hazelcast.xml"); LOGGER.info("Loading Hazelcast member configuration: " + file.getAbsolutePath()); return fileAsText(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")); } } }
private String loadInitScript() { String initScript = fileAsText(initScriptFile); initScript = initScript.replaceAll(Pattern.quote("${version}"), getSimulatorVersion()); initScript = initScript.replaceAll(Pattern.quote("${user}"), properties.getUser()); initScript = initScript.replaceAll(Pattern.quote("${cloudprovider}"), properties.getCloudProvider()); return initScript; }
private String loadPropertyFromFile(String property) { String path = get(property); File file = newFile(path); if (!file.exists()) { throw new CommandLineExitException(format("File %s for property %s not found", file.getAbsolutePath(), property)); } if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Loading property value for %s from file: %s", property, file.getAbsolutePath())); } return fileAsText(file).trim(); }
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); }
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 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); }
public static void assertException(String content, int id) { File userDir = getUserDir(); if (!userDir.exists()) { fail("userDir " + userDir.getAbsolutePath() + " does not exist"); } File exceptionFile = new File(userDir, id + ".exception"); assertTrue(exceptionFile.getAbsolutePath() + " does not exist", exceptionFile.exists()); String text = fileAsText(exceptionFile); assertTrue(format("'%s' does not contains '%s'", text, content), text.contains(content)); } }
public static String loadWorkerScript(WorkerType workerType, String vendor) { List<File> files = new LinkedList<File>(); File confDir = new File(getSimulatorHome(), "conf"); files.add(new File("worker-" + vendor + "-" + workerType.name() + ".sh").getAbsoluteFile()); files.add(new File("worker-" + workerType + ".sh").getAbsoluteFile()); files.add(new File("worker-" + vendor + ".sh").getAbsoluteFile()); files.add(new File("worker.sh").getAbsoluteFile()); files.add(new File(confDir, "worker-" + vendor + "-" + workerType.name() + ".sh").getAbsoluteFile()); files.add(new File(confDir, "worker-" + vendor + ".sh").getAbsoluteFile()); files.add(new File(confDir, "worker.sh").getAbsoluteFile()); for (File file : files) { if (file.exists()) { LOGGER.info("Loading " + vendor + " " + workerType.name() + " worker script: " + file.getAbsolutePath()); return fileAsText(file); } } throw new CommandLineExitException("Failed to load worker script from the following locations:" + files); }
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")); } } }
@Override public String call() throws Exception { Map<String, Object> environment = new HashMap<String, Object>(); File pidFile = new File(getUserDir(), "worker.pid"); if (pidFile.exists()) { environment.put("PID", fileAsText(pidFile)); } return new BashCommand(command) .setDirectory(getUserDir()) .addEnvironment(environment) .setThrowsException(true) .execute(); } };
public static ComponentRegistry load(File agentFile) { ComponentRegistry componentRegistry = new ComponentRegistry(); String content = fileAsText(agentFile); String[] lines = content.split(NEW_LINE); int lineNumber = 0;
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!"); }
@Override protected SimulatorOperation newOperation() { int count = options.valueOf(countSpec); if (count <= 0) { throw new CommandLineExitException("--count can't be smaller than 1"); } LOGGER.info(format("Starting %s workers", count)); String hzConfig = null; if (options.has(configSpec)) { hzConfig = fileAsText(options.valueOf(configSpec)); } return new RcWorkerStartOperation() .setCount(count) .setVersionSpec(options.valueOf(versionSpecSpec)) .setWorkerType(options.valueOf(workerTypeSpec)) .setHzConfig(hzConfig) .setVmOptions(options.valueOf(vmOptionsSpec)) .setAgentAddresses(loadAddresses(options, agentsSpec, AddressLevel.AGENT)) .setTags(TagUtils.loadTags(options, tagsSpec)) .setAgentTags(TagUtils.loadTags(options, agentsTags)); } }