ReplSet(IFeatureAwareVersion serverVersion, String replicaSetName, boolean silent, Integer... serverPorts) { this.serverVersion = serverVersion; this.replicaSetName = replicaSetName; this.serverPorts = defaultPortsIfRequired(serverPorts); this.configServerPorts = defaultPortsIfRequired(null); this.configServerReplicaSetName = DEFAULT_CONFIG_SERVER_REPLICA_SET_NAME; this.mongosPort = randomOrDefaultServerPort(); if (silent) { outputFunction = it -> new ProcessOutput(Processors.silent(), Processors.namedConsole("[ " + it.commandName() + " error]"), Processors.console()); } else { outputFunction = it -> ProcessOutput.getDefaultInstance(it.commandName()); } }
public static ProcessOutput getDefaultInstance(String label) { return new ProcessOutput(Processors.namedConsole("["+label+" output]"), Processors.namedConsole("["+label+" error]"), Processors.console()); }
protected void onAfterProcessStart(ProcessControl process, RuntimeConfig runtimeConfig) { ProcessOutput outputConfig = runtimeConfig.getProcessOutput(); Processors.connect(process.getReader(), outputConfig.getOutput()); Processors.connect(process.getError(), StreamToLineProcessor.wrap(outputConfig.getError())); }
public static ProcessOutput getInstance(String label, java.util.logging.Logger logger) { return new ProcessOutput(Processors.named("["+label+" output]", Processors.logTo(logger, Level.INFO)), Processors.named("["+label+" error]", Processors.logTo(logger, Level.SEVERE)), Processors.logTo(logger, Level.FINE)); }
public static boolean isProcessRunning(Platform platform, long pid) { try { final Process pidof; if (platform.isUnixLike()) { pidof = Runtime.getRuntime().exec( new String[] { "kill", "-0", "" + pid }); return pidof.waitFor() == 0; } else { // windows // process might be in either NOT RESPONDING due to // firewall blocking, or could be RUNNING final String[] cmd = { "tasklist.exe", "/FI", "PID eq " + pid ,"/FO", "CSV" }; logger.trace("Command: {}", Arrays.asList(cmd)); ProcessBuilder processBuilder = ProcessControl .newProcessBuilder(Arrays.asList(cmd), true); Process process = processBuilder.start(); // look for the PID in the output, pass it in for 'success' state LogWatchStreamProcessor logWatch = new LogWatchStreamProcessor(""+pid, new HashSet<String>(), StreamToLineProcessor.wrap(Processors.silent())); Processors.connect(new InputStreamReader(process.getInputStream()), logWatch); logWatch.waitForResult(2000); logger.trace("logWatch output: {}", logWatch.getOutput()); return logWatch.isInitWithSuccess(); } } catch (IOException | InterruptedException e) { logger.error("Trying to get process status", e); } return false; }
IStreamProcessor mongodOutput = Processors.named("[mongod>]", new FileStreamProcessor(File.createTempFile("mongod", "log"))); IStreamProcessor mongodError = new FileStreamProcessor(File.createTempFile("mongod-error", "log")); IStreamProcessor commandsOutput = Processors.namedConsole("[console>]");
public static ProcessOutput getDefaultInstance(String label) { return new ProcessOutput(Processors.namedConsole("["+label+" output]"), Processors.namedConsole("["+label+" error]"), Processors.console()); }
protected void onAfterProcessStart(ProcessControl process, IRuntimeConfig runtimeConfig) throws IOException { ProcessOutput outputConfig = runtimeConfig.getProcessOutput(); Processors.connect(process.getReader(), outputConfig.getOutput()); Processors.connect(process.getError(), StreamToLineProcessor.wrap(outputConfig.getError())); }
public static ProcessOutput getInstance(String label, java.util.logging.Logger logger) { return new ProcessOutput(Processors.named("["+label+" output]", Processors.logTo(logger, Level.INFO)), Processors.named("["+label+" error]", Processors.logTo(logger, Level.SEVERE)), Processors.logTo(logger, Level.FINE)); }
format(isMongo3() ? REPLSET_OK_TOKEN_3 : REPLSET_OK_TOKEN_2), Collections.<String>emptySet(), namedConsole("[mongod output]")); runtimeConfig = new RuntimeConfigBuilder() .defaults(Command.MongoD) .processOutput(new ProcessOutput( mongodOutput, namedConsole("[mongod error]"), console())) .build(); runtime = MongodStarter.getInstance(runtimeConfig);
void run(Process p, IRuntimeConfig runtimeConfig, long timeoutNanos) throws IOException { CollectingAndForwardingStreamProcessor wrapped = new CollectingAndForwardingStreamProcessor(runtimeConfig.getProcessOutput().getOutput()); IStreamProcessor loggingWatch = StreamToLineProcessor.wrap(wrapped); try { ReaderProcessor processorOne = Processors.connect(new InputStreamReader(p.getInputStream()), loggingWatch); ReaderProcessor processorTwo = Processors.connect(new InputStreamReader(p.getErrorStream()), loggingWatch); int retCode = tope.waitFor(p, timeoutNanos); if (retCode != 0) { processorOne.join(10000); processorTwo.join(10000); resolveException(retCode, wrapped.getOutput()); } } catch (InterruptedException e) { throw new RuntimeException(e); } }
public static ProcessOutput getInstance(String label, org.slf4j.Logger logger) { return new ProcessOutput(Processors.named("["+label+" output]", Processors.logTo(logger, Slf4jLevel.INFO)), Processors.named("["+label+" error]", Processors.logTo(logger, Slf4jLevel.ERROR)), Processors.logTo(logger, Slf4jLevel.DEBUG)); } }
format(isMongo3() ? REPLSET_OK_TOKEN_3 : REPLSET_OK_TOKEN_2), Collections.<String>emptySet(), namedConsole("[mongod output]")); runtimeConfig = new RuntimeConfigBuilder() .defaults(Command.MongoD) .processOutput(new ProcessOutput( mongodOutput, namedConsole("[mongod error]"), console())) .build(); runtime = MongodStarter.getInstance(runtimeConfig);
public static boolean executeCommandLine(ISupportConfig support, String label, ProcessConfig processConfig) { boolean ret = false; List<String> commandLine = processConfig.getCommandLine(); try { ProcessControl process = fromCommandLine(support, processConfig.getCommandLine(), processConfig.getError() == null); Processors.connect(process.getReader(), processConfig.getOutput()); Thread.sleep(SLEEPT_TIMEOUT); ret = process.stop() == 0; logger.info("execSuccess: {} {}", ret, commandLine); return ret; } catch (IOException e) { logger.error("" + commandLine, e); } catch (InterruptedException e) { logger.error("" + commandLine, e); } return false; }