@Override public boolean isCeOperational() { return call(IS_OPERATIONAL, ProcessId.COMPUTE_ENGINE.getIpcIndex()); }
private boolean isOperational() { try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(sharedDir, ProcessId.WEB_SERVER.getIpcIndex())) { return processCommands.isOperational(); } }
private File buildPropertiesFile(JavaCommand javaCommand) { File propertiesFile = null; try { propertiesFile = File.createTempFile("sq-process", "properties", tempDir); Properties props = new Properties(); props.putAll(javaCommand.getArguments()); props.setProperty(PROPERTY_PROCESS_KEY, javaCommand.getProcessId().getKey()); props.setProperty(PROPERTY_PROCESS_INDEX, Integer.toString(javaCommand.getProcessId().getIpcIndex())); props.setProperty(PROPERTY_TERMINATION_TIMEOUT_MS, "60000"); props.setProperty(PROPERTY_SHARED_PATH, tempDir.getAbsolutePath()); try (OutputStream out = new FileOutputStream(propertiesFile)) { props.store(out, format("Temporary properties file for command [%s]", javaCommand.getProcessId().getKey())); } return propertiesFile; } catch (Exception e) { throw new IllegalStateException("Cannot write temporary settings to " + propertiesFile, e); } }
public static StopRequestWatcherImpl create(AppSettings settings, Scheduler scheduler, FileSystem fs) { DefaultProcessCommands commands = DefaultProcessCommands.secondary(fs.getTempDir(), ProcessId.APP.getIpcIndex()); return new StopRequestWatcherImpl(settings, scheduler, commands); }
@Test public void test_constants() { assertThat(ProcessId.COMPUTE_ENGINE.getKey()).isEqualTo("ce"); assertThat(ProcessId.COMPUTE_ENGINE.getIpcIndex()).isEqualTo(3); }
private <T> T call(ActionClient<T> actionClient) { try (DefaultProcessCommands commands = DefaultProcessCommands.secondary(ipcSharedDir, COMPUTE_ENGINE.getIpcIndex())) { if (commands.isUp()) { return actionClient.call(commands.getHttpUrl() + "/" + actionClient.getPath()); } return actionClient.getDefault(); } catch (Exception e) { throw new IllegalStateException("Failed to call HTTP server of process " + COMPUTE_ENGINE, e); } }
private Properties getProperties() throws IOException { Properties properties = ProcessProperties.defaults(); File homeDir = tempFolder.newFolder(); File dataDir = new File(homeDir, "data"); dataDir.mkdirs(); File tmpDir = new File(homeDir, "tmp"); tmpDir.mkdirs(); properties.setProperty(PATH_HOME.getKey(), homeDir.getAbsolutePath()); properties.setProperty(PATH_DATA.getKey(), dataDir.getAbsolutePath()); properties.setProperty(PATH_TEMP.getKey(), tmpDir.getAbsolutePath()); properties.setProperty(PROPERTY_PROCESS_INDEX, valueOf(ProcessId.COMPUTE_ENGINE.getIpcIndex())); properties.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath()); properties.setProperty(JDBC_URL.getKey(), db.getUrl()); properties.setProperty(JDBC_USERNAME.getKey(), "sonar"); properties.setProperty(JDBC_PASSWORD.getKey(), "sonar"); return properties; }
@Test public void all_values_are_unique() { Set<Integer> ipcIndices = new HashSet<>(); Set<String> keys = new HashSet<>(); for (ProcessId processId : ProcessId.values()) { ipcIndices.add(processId.getIpcIndex()); keys.add(processId.getKey()); } assertThat(ipcIndices).hasSize(ProcessId.values().length); assertThat(keys).hasSize(ProcessId.values().length); }
return new EsProcessMonitor(process, processId, esConnector); } else { ProcessCommands commands = allProcessesCommands.createAfterClean(processId.getIpcIndex()); return new ProcessCommandsProcessMonitor(process, processId, commands);
private void setUpWithHttpUrl(ProcessId processId) { try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(ipcSharedDir, processId.getIpcIndex())) { processCommands.setUp(); processCommands.setHttpUrl(format("http://%s:%d", server.getHostName(), server.getPort())); } } }
@Test public void properties_are_passed_to_command_via_a_temporary_properties_file() throws Exception { File tempDir = temp.newFolder(); TestProcessBuilder processBuilder = new TestProcessBuilder(); ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder); JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.WEB_SERVER, temp.newFolder()); command.setReadsArgumentsFromFile(true); command.setArgument("foo", "bar"); command.setArgument("baz", "woo"); command.setJvmOptions(new JvmOptions<>()); underTest.launch(command); String propsFilePath = processBuilder.commands.get(processBuilder.commands.size() - 1); File file = new File(propsFilePath); assertThat(file).exists().isFile(); try (FileReader reader = new FileReader(file)) { Properties props = new Properties(); props.load(reader); assertThat(props).containsOnly( entry("foo", "bar"), entry("baz", "woo"), entry("process.terminationTimeout", "60000"), entry("process.key", ProcessId.WEB_SERVER.getKey()), entry("process.index", String.valueOf(ProcessId.WEB_SERVER.getIpcIndex())), entry("process.sharedDir", tempDir.getAbsolutePath())); } }
@Override public boolean isCeOperational() { return call(IS_OPERATIONAL, ProcessId.COMPUTE_ENGINE.getIpcIndex()); }
private boolean isOperational() { try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(sharedDir, ProcessId.WEB_SERVER.getIpcIndex())) { return processCommands.isOperational(); } }
private File buildPropertiesFile(JavaCommand javaCommand) { File propertiesFile = null; try { propertiesFile = File.createTempFile("sq-process", "properties", tempDir); Properties props = new Properties(); props.putAll(javaCommand.getArguments()); props.setProperty(PROPERTY_PROCESS_KEY, javaCommand.getProcessId().getKey()); props.setProperty(PROPERTY_PROCESS_INDEX, Integer.toString(javaCommand.getProcessId().getIpcIndex())); props.setProperty(PROPERTY_TERMINATION_TIMEOUT_MS, "60000"); props.setProperty(PROPERTY_SHARED_PATH, tempDir.getAbsolutePath()); try (OutputStream out = new FileOutputStream(propertiesFile)) { props.store(out, format("Temporary properties file for command [%s]", javaCommand.getProcessId().getKey())); } return propertiesFile; } catch (Exception e) { throw new IllegalStateException("Cannot write temporary settings to " + propertiesFile, e); } }
public static StopRequestWatcherImpl create(AppSettings settings, Scheduler scheduler, FileSystem fs) { DefaultProcessCommands commands = DefaultProcessCommands.secondary(fs.getTempDir(), ProcessId.APP.getIpcIndex()); return new StopRequestWatcherImpl(settings, scheduler, commands); }
private <T> T call(ActionClient<T> actionClient) { try (DefaultProcessCommands commands = DefaultProcessCommands.secondary(ipcSharedDir, COMPUTE_ENGINE.getIpcIndex())) { if (commands.isUp()) { return actionClient.call(commands.getHttpUrl() + "/" + actionClient.getPath()); } return actionClient.getDefault(); } catch (Exception e) { throw new IllegalStateException("Failed to call HTTP server of process " + COMPUTE_ENGINE, e); } }
public ProcessMonitor launch(AbstractCommand command) { EsInstallation fileSystem = command.getEsInstallation(); if (fileSystem != null) { cleanupOutdatedEsData(fileSystem); writeConfFiles(fileSystem); } Process process; if (command instanceof EsScriptCommand) { process = launchExternal((EsScriptCommand) command); } else if (command instanceof JavaCommand) { process = launchJava((JavaCommand) command); } else { throw new IllegalStateException("Unexpected type of command: " + command.getClass()); } ProcessId processId = command.getProcessId(); try { if (processId == ProcessId.ELASTICSEARCH) { return new EsProcessMonitor(process, processId, command.getEsInstallation(), new EsConnectorImpl()); } else { ProcessCommands commands = allProcessesCommands.createAfterClean(processId.getIpcIndex()); return new ProcessCommandsProcessMonitor(process, processId, commands); } } catch (Exception e) { // just in case if (process != null) { process.destroyForcibly(); } throw new IllegalStateException(format("Fail to launch monitor of process [%s]", processId.getKey()), e); } }