if (!isHelping()) { switch (getCommand()) { case START: info(start()); waitOnLocator(); break; case STATUS: info(status()); break; case STOP: info(stop()); break; case VERSION: info(version()); break; default: usage(); help(getCommand());
public LocatorState(final LocatorLauncher launcher, final Status status) { // if status is NOT_RESPONDING then this is executing inside the JVM asking for the status; // pid etc will be set according to the caller's JVM instead this(status, launcher.statusMessage, System.currentTimeMillis(), launcher.getId(), identifyPid(), ManagementFactory.getRuntimeMXBean().getUptime(), launcher.getWorkingDirectory(), ManagementFactory.getRuntimeMXBean().getInputArguments(), System.getProperty("java.class.path"), GemFireVersion.getGemFireVersion(), System.getProperty("java.version"), getLogFileCanonicalPath(launcher), launcher.getBindAddressAsString(), launcher.getPortAsString(), launcher.getMemberName()); }
private LocatorState statusWithPort() { try { LocatorStatusResponse response = statusLocator(getPort(), getBindAddress()); return new LocatorState(this, Status.ONLINE, response); } catch (Exception handled) { return createNoResponseState(handled, "Failed to connect to locator " + getBindAddressAsString() + "[" + getPort() + "]"); } }
/** * Determines whether the Locator can be stopped in-process, such as when a Locator is embedded in * an application and the LocatorLauncher API is being used. * * @return a boolean indicating whether the Locator can be stopped in-process (the application's * process with an embedded Locator). */ protected boolean isStoppable() { return (isRunning() && getInternalLocator() != null); }
/** * Gets the port number represented as a String value. If the port number is null, the the default * Locator port (10334) is returned; * * @return the port number as a String value. * @see #getPort() */ public String getPortAsString() { Integer port = getPort(); return (port != null ? port : getDefaultLocatorPort()).toString(); }
if (isStartable()) { INSTANCE.compareAndSet(null, this); this.process = new ControllableProcess(this.controlHandler, new File(getWorkingDirectory()), ProcessType.LOCATOR, isForcing()); assertPortAvailable(getBindAddress(), getPort()); ProcessLauncherContext.set(isRedirectingOutput(), getOverriddenDefaults(), statusMessage -> LocatorLauncher.this.statusMessage = statusMessage); this.locator = InternalLocator.startLocator(getPort(), getLogFile(), null, null, getBindAddress(), true, getDistributedSystemProperties(), getHostnameForClients()); } finally { ProcessLauncherContext.remove(); debug("Running Locator on (%1$s) in (%2$s) as (%3$s)...", getId(), getWorkingDirectory(), getMember()); running.set(true); failOnStart(e); throw new RuntimeException( String.format("An IO error occurred while starting a %s in %s on %s: %s", getServiceName(), getWorkingDirectory(), getId(), e.getMessage()), e); } catch (FileAlreadyExistsException e) { failOnStart(e); throw new RuntimeException( String.format("A PID file already exists and a %s may be running in %s on %s.",
@Test public void buildCreatesLocatorLauncherWithBuilderValues() throws Exception { Builder builder = new Builder(); LocatorLauncher launcher = builder.setCommand(Command.START).setDebug(true) .setHostnameForClients("beanstock.vmware.com").setMemberName("Beanstock").setPort(8192) .setRedirectOutput(Boolean.TRUE).build(); assertThat(launcher.getCommand()).isEqualTo(builder.getCommand()); assertThat(launcher.isDebugging()).isTrue(); assertThat(launcher.getHostnameForClients()).isEqualTo(builder.getHostnameForClients()); assertThat(launcher.getMemberName()).isEqualTo(builder.getMemberName()); assertThat(launcher.getPort()).isEqualTo(builder.getPort()); assertThat(launcher.getWorkingDirectory()).isEqualTo(builder.getWorkingDirectory()); assertThat(launcher.isRedirectingOutput()).isTrue(); assertThat(launcher.isHelping()).isFalse(); assertThat(launcher.isRunning()).isFalse(); }
final LocatorLauncher launcher = getInstance(); debug( "Getting status from the LocatorLauncher instance that actually launched the GemFire Locator.%n"); return new LocatorState(this, Status.STARTING); else if (isRunning()) { debug("Getting Locator status using host (%1$s) and port (%2$s)%n", getBindAddressAsString(), getPortAsString()); return statusWithPort(); else if (isPidInProcess() && launcher != null) { return launcher.statusInProcess(); else if (getPid() != null) { debug("Getting Locator status using process ID (%1$s)%n", getPid()); return statusWithPid(); debug("Getting Locator status using working directory (%1$s)%n", getWorkingDirectory()); return statusWithWorkingDirectory(); debug("Getting Locator status using host (%1$s) and port (%2$s)%n", getBindAddressAsString(), getPortAsString()); return statusWithPort();
commandLine.add( "-Dsun.rmi.dgc.server.gcInterval".concat("=").concat(Long.toString(Long.MAX_VALUE - 1))); if (launcher.isRedirectingOutput()) { commandLine .add("-D".concat(OSProcess.DISABLE_REDIRECTION_CONFIGURATION_PROPERTY).concat("=true")); commandLine.add(LocatorLauncher.Command.START.getName()); if (StringUtils.isNotBlank(launcher.getMemberName())) { commandLine.add(launcher.getMemberName()); if (launcher.getBindAddress() != null) { commandLine.add("--bind-address=" + launcher.getBindAddress().getCanonicalHostName()); if (launcher.isDebugging() || isDebugging()) { commandLine.add("--debug"); if (launcher.isForcing()) { commandLine.add("--force"); if (StringUtils.isNotBlank(launcher.getHostnameForClients())) { commandLine.add("--hostname-for-clients=" + launcher.getHostnameForClients()); if (launcher.getPort() != null) { commandLine.add("--port=" + launcher.getPort()); if (launcher.isRedirectingOutput()) { commandLine.add("--redirect-output");
final LocatorLauncher launcher = getInstance(); if (isStoppable()) { return stopInProcess(); else if (isPidInProcess() && launcher != null) { return launcher.stopInProcess(); else if (getPid() != null) { return stopWithPid(); else if (getWorkingDirectory() != null) { return stopWithWorkingDirectory(); } else { return new LocatorState(this, Status.NOT_RESPONDING);
@Test public void testLocatorCommandLineWithRestAPI() throws Exception { LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.START) .setMemberName("testLocatorCommandLineWithRestAPI").setBindAddress("localhost") .setPort(11111).build(); Properties gemfireProperties = new Properties(); gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8089"); gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost"); String[] commandLineElements = startLocatorCommand.createStartLocatorCommandLine(locatorLauncher, null, null, gemfireProperties, null, false, new String[0], null, null); assertNotNull(commandLineElements); assertTrue(commandLineElements.length > 0); Set<String> expectedCommandLineElements = new HashSet<>(6); expectedCommandLineElements.add(locatorLauncher.getCommand().getName()); expectedCommandLineElements.add(locatorLauncher.getMemberName().toLowerCase()); expectedCommandLineElements.add(String.format("--port=%1$d", locatorLauncher.getPort())); expectedCommandLineElements .add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_PORT + "=" + "8089"); expectedCommandLineElements.add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_BIND_ADDRESS + "=" + "localhost"); for (String commandLineElement : commandLineElements) { expectedCommandLineElements.remove(commandLineElement.toLowerCase()); } assertTrue(String.format("Expected ([]); but was (%1$s)", expectedCommandLineElements), expectedCommandLineElements.isEmpty()); }
private static String getLocatorLocation(LocatorLauncher launcher) { if (launcher.getPort() == null) { return launcher.getId(); } if (launcher.getBindAddress() == null) { return HostUtils.getLocatorId(HostUtils.getLocalHost(), launcher.getPort()); } return HostUtils.getLocatorId(launcher.getBindAddressAsString(), launcher.getPort()); }
LocatorStatusResponse response = statusLocator(getPort(), getBindAddress()); return new LocatorState(this, Status.ONLINE, response); } catch (Exception handled) { timedWait(interval, timeUnit);
@Test public void buildUsesMemberNameSetInSystemPropertiesOnStart() { System.setProperty(DistributionConfig.GEMFIRE_PREFIX + NAME, "locatorXYZ"); LocatorLauncher launcher = new Builder().setCommand(LocatorLauncher.Command.START).build(); assertThat(launcher.getCommand()).isEqualTo(LocatorLauncher.Command.START); assertThat(launcher.getMemberName()).isNull(); } }
final ProcessController controller = new ProcessControllerFactory().createProcessController(this.controllerParameters, new File(getWorkingDirectory()), ProcessType.LOCATOR.getPidFileName()); parsedPid = controller.getProcessId(); LocatorLauncher runningLauncher = getInstance(); if (runningLauncher != null) { return runningLauncher.status(); return createNoResponseState(handled, "Failed to connect to locator with process id " + parsedPid); } catch (FileNotFoundException handled) { return createNoResponseState(handled, "Failed to find process file " + ProcessType.LOCATOR.getPidFileName() + " in " + getWorkingDirectory()); } catch (IOException | MBeanInvocationFailedException | UnableToControlProcessException | TimeoutException handled) { return createNoResponseState(handled, "Failed to communicate with locator with process id " + parsedPid); } catch (PidUnavailableException e) { return createNoResponseState(e, "Failed to find usable process id within file " + ProcessType.LOCATOR.getPidFileName() + " in " + getWorkingDirectory()); } catch (InterruptedException handled) { Thread.currentThread().interrupt(); return createNoResponseState(handled, "Interrupted while trying to communicate with locator with process id " + parsedPid);
final ProcessController controller = new ProcessControllerFactory().createProcessController(this.controllerParameters, new File(getWorkingDirectory()), ProcessType.LOCATOR.getPidFileName()); parsedPid = controller.getProcessId(); final LocatorLauncher runningLauncher = getInstance(); if (runningLauncher != null) { return runningLauncher.stopInProcess(); return createNoResponseState(handled, "Failed to connect to locator with process id " + parsedPid); } catch (FileNotFoundException handled) { return createNoResponseState(handled, "Failed to find process file " + ProcessType.LOCATOR.getPidFileName() + " in " + getWorkingDirectory()); } catch (IOException | MBeanInvocationFailedException | UnableToControlProcessException handled) { return createNoResponseState(handled, "Failed to communicate with locator with process id " + parsedPid); } catch (InterruptedException handled) { Thread.currentThread().interrupt(); return createNoResponseState(handled, "Interrupted while trying to communicate with locator with process id " + parsedPid); } catch (PidUnavailableException handled) { return createNoResponseState(handled, "Failed to find usable process id within file " + ProcessType.LOCATOR.getPidFileName() + " in " + getWorkingDirectory()); } catch (TimeoutException handled) { return createNoResponseState(handled,
@Test public void buildUsesMemberNameSetInApiProperties() { LocatorLauncher launcher = new Builder().setCommand(LocatorLauncher.Command.START).set(NAME, "locatorABC").build(); assertThat(launcher.getMemberName()).isNull(); assertThat(launcher.getProperties().getProperty(NAME)).isEqualTo("locatorABC"); }
.directory(new File(locatorLauncher.getWorkingDirectory())).start(); .tryGetCanonicalPathElseGetAbsolutePath(new File(locatorLauncher.getWorkingDirectory()))), null); exitValue, locatorLauncher.getWorkingDirectory(), message.toString())); InetAddress bindAddr = locatorLauncher.getBindAddress(); if (bindAddr != null) { locatorHostName = bindAddr.getCanonicalHostName(); } else { locatorHostName = StringUtils.defaultIfBlank(locatorLauncher.getHostnameForClients(), HostUtils.getLocalHost());
public LocatorState(final LocatorLauncher launcher, final Status status, final String errorMessage) { this(status, // status errorMessage, // statusMessage System.currentTimeMillis(), // timestamp getLocatorLocation(launcher), // locatorLocation null, // pid 0L, // uptime launcher.getWorkingDirectory(), // workingDirectory ManagementFactory.getRuntimeMXBean().getInputArguments(), // jvmArguments null, // classpath GemFireVersion.getGemFireVersion(), // gemfireVersion System.getProperty("java.version"), // javaVersion null, // logFile launcher.getBindAddressAsString(), // host launcher.getPortAsString(), // port null);// memberName }
/** * Gets the name of the log file used to log information about this Locator. * * @return a String value indicating the name of this Locator's log file. */ @Override public String getLogFileName() { return defaultIfBlank(getMemberName(), DEFAULT_LOCATOR_LOG_NAME) .concat(DEFAULT_LOCATOR_LOG_EXT); }