private void delay() { if (maxDelayMs != 0) { sleepMillis(minDelayMs + random.nextInt(maxDelayMs)); } }
@Override public void afterCompletion() { listeners.add(listener); sleepSeconds(PAUSE_FOR_LAST_EVENTS_SECONDS); } }
@Override public void close() { closeQuietly(connector); }
public static void exitWithError(Logger logger, String msg, Throwable throwable) { if (throwable instanceof CommandLineExitException) { String logMessage = throwable.getMessage(); if (throwable.getCause() != null) { String throwableString = throwableToString(throwable.getCause()); logMessage += NEW_LINE + throwableString; } logger.fatal(logMessage); } else { String throwableString = throwableToString(throwable); logger.fatal(msg + NEW_LINE + throwableString); } exit(1); }
public void shutdown() { messageQueue.add(POISON_PILL); SimulatorMessage message = messageQueue.peek(); while (message != null) { if (!POISON_PILL.equals(message)) { int queueSize = messageQueue.size(); LOGGER.debug(format("%d messages pending on messageQueue, first message: %s", queueSize, message)); } sleepMillis(WAIT_FOR_EMPTY_QUEUE_MILLIS); message = messageQueue.peek(); } joinThread(messageQueueThread); } }
static Properties getUserProperties() { FileInputStream inputStream = null; try { Properties properties = new Properties(); File userPropertiesFile = new File(SimulatorProperties.PROPERTIES_FILE_NAME).getAbsoluteFile(); if (!userPropertiesFile.exists()) { return properties; } inputStream = new FileInputStream(userPropertiesFile); properties.load(inputStream); return properties; } catch (IOException e) { throw rethrow(e); } finally { closeQuietly(inputStream); } }
private static void printHelpAndExit() { System.out.println( "Command Description \n" + "-------------------------- \n" + "download Downloads all artifacts from the workers \n" + "install Installs vendor software on the remote machines \n" + "print-layout Prints the cluster-layout \n" + "test-run Runs a test and wait for completion \n" + "test-start Starts a test asynchronously \n" + "test-stop Stops a test \n" + "test-status Checks the status of a test \n" + "stop Stops the Coordinator remote session \n" + "worker-kill Kills one or more workers \n" + "worker-script Executes a script on workers \n" + "worker-start Starts workers "); exitWithError(); }
public static void main(String[] args) throws Exception { CoordinatorRemoteCli cli = null; try { cli = new CoordinatorRemoteCli(args); cli.run(); } catch (Exception e) { System.err.print(e.getMessage()); exitWithError(LOGGER, e.getMessage(), e); } finally { closeQuietly(cli); } }
private void waitForWorkerShutdown(int expectedWorkerCount) { int timeoutSeconds = simulatorProperties.getWaitForWorkerShutdownTimeoutSeconds(); long started = System.nanoTime(); LOGGER.info(format("Waiting up to %d seconds for shutdown of %d Workers...", timeoutSeconds, expectedWorkerCount)); long expirationTimeMillis = System.currentTimeMillis() + SECONDS.toMillis(timeoutSeconds); while (componentRegistry.workerCount() > 0 && System.currentTimeMillis() < expirationTimeMillis) { sleepMillis(FINISHED_WORKERS_SLEEP_MILLIS); } List<WorkerData> remainingWorkers = componentRegistry.getWorkers(); if (remainingWorkers.isEmpty()) { LOGGER.info(format("Finished shutdown of all Workers (%d seconds)", getElapsedSeconds(started))); } else { LOGGER.warn(format("Aborted waiting for shutdown of all Workers (%d still running)...", remainingWorkers.size())); LOGGER.warn(format("Unfinished workers: %s", toString(remainingWorkers))); } }
private void rethrowExceptionIfAny() { if (storedException != null) { throw rethrow(storedException); } }
public static StringBuilder execute(String command) { StringBuilder sb = new StringBuilder(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing bash command: " + command); } try { // create a process for the shell ProcessBuilder pb = new ProcessBuilder("bash", "-c", command); pb = pb.redirectErrorStream(true); Process shell = pb.start(); new BashStreamGobbler(shell.getInputStream(), sb).start(); // wait for the shell to finish and get the return code int shellExitStatus = shell.waitFor(); if (shellExitStatus != 0) { LOGGER.error(format("Failed to execute [%s]", command)); LOGGER.error(sb.toString()); exitWithError(); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Bash output: " + NEW_LINE + sb); } } return sb; } catch (Exception e) { throw rethrow(e); } }
public static void main(String[] args) { LOGGER.info("Hazelcast Simulator Wizard"); LOGGER.info(format("Version: %s, Commit: %s, Build Time: %s", getSimulatorVersion(), getCommitIdAbbrev(), getBuildTime())); try { WizardCli cli = new WizardCli(args); cli.run(); } catch (Exception e) { exitWithError(LOGGER, "Could not execute command", e); } } }
task.run(); } catch (Exception e) { throw rethrow(e); sleepMillisThrowException(sleepMillis); sleepMillis *= ASSERT_TRUE_EVENTUALLY_SLEEP_FACTOR;
public static void exitWithError() { exit(1); }
@Override public void run() { sleepNanos(sleepNanos); callerThread.interrupt(); } }
public FailureOperation(String message, FailureType type, SimulatorAddress workerAddress, String agentAddress, Throwable cause) { this(message, type, workerAddress, agentAddress, null, null, null, throwableToString(cause)); }
public static void warmupPartitions(HazelcastInstance hazelcastInstance) { LOGGER.info("Waiting for partition warmup"); PartitionService partitionService = hazelcastInstance.getPartitionService(); long started = System.nanoTime(); for (Partition partition : partitionService.getPartitions()) { if (System.nanoTime() - started > PARTITION_WARMUP_TIMEOUT_NANOS) { throw new IllegalStateException("Partition warmup timeout. Partitions didn't get an owner in time"); } while (partition.getOwner() == null) { LOGGER.debug("Partition owner is not yet set for partitionId: " + partition.getPartitionId()); sleepMillisThrowException(PARTITION_WARMUP_SLEEP_INTERVAL_MILLIS); } } LOGGER.info("Partitions are warmed up successfully"); }
private EncodableHistogram getIntervalHistogram() { EncodableHistogram histogram = null; try { histogram = logReader.nextIntervalHistogram(config.rangeStartTimeSec, config.rangeEndTimeSec); } catch (RuntimeException ex) { System.err.println("Log file parsing error at line number " + lineNumber + ": line appears to be malformed."); if (config.verbose) { throw ex; } else { exitWithError(); } } lineNumber++; return histogram; }
public static void sleepMillisThrowException(int millis) { try { MILLISECONDS.sleep(millis); } catch (InterruptedException e) { throw rethrow(e); } }
void load(File file) { FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); properties.load(inputStream); if (containsKey("HAZELCAST_VERSION_SPEC")) { throw new IOException("'HAZELCAST_VERSION_SPEC' property is deprecated, Use 'VERSION_SPEC' instead."); } } catch (IOException e) { throw rethrow(e); } finally { closeQuietly(inputStream); } }