Search in sources :

Example 1 with LocatorLauncher

use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.

the class LauncherLifecycleCommandsDUnitTest method test009StatusLocatorUsingMemberId.

@Test
public void test009StatusLocatorUsingMemberId() throws Exception {
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    final int jmxManagerPort = ports[0];
    final int locatorPort = ports[1];
    String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
    File workingDirectory = temporaryFolder.newFolder(pathname);
    assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
    try {
        CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
        command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
        command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
        command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
        command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
        command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION, Boolean.FALSE.toString());
        command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
        command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
        command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
        CommandResult result = executeCommand(command.toString());
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STATUS).setBindAddress(null).setPort(locatorPort).setWorkingDirectory(workingDirectory.getPath()).build();
        assertNotNull(locatorLauncher);
        LocatorState expectedLocatorState = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
        assertNotNull(expectedLocatorState);
        assertEquals(Status.ONLINE, expectedLocatorState.getStatus());
        result = executeCommand(String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STATUS_LOCATOR, getMemberId(jmxManagerPort, pathname)));
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        assertTrue(serviceStateStatusStringNormalized(toString(result)).contains(serviceStateStatusStringNormalized(expectedLocatorState)));
    } finally {
        stopLocator(workingDirectory);
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 2 with LocatorLauncher

use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.

the class LauncherLifecycleCommandsDUnitTest method test008StatusLocatorUsingMemberName.

@Test
public void test008StatusLocatorUsingMemberName() throws IOException {
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    final int jmxManagerPort = ports[0];
    final int locatorPort = ports[1];
    String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
    File workingDirectory = temporaryFolder.newFolder(pathname);
    assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
    try {
        CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
        command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
        command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
        command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
        command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
        command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION, Boolean.FALSE.toString());
        command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
        command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
        command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
        CommandResult result = executeCommand(command.toString());
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STATUS).setBindAddress(null).setPort(locatorPort).setWorkingDirectory(workingDirectory.getPath()).build();
        assertNotNull(locatorLauncher);
        LocatorState expectedLocatorState = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
        assertNotNull(expectedLocatorState);
        assertEquals(Status.ONLINE, expectedLocatorState.getStatus());
        result = executeCommand(String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        result = executeCommand(String.format("%1$s --name=invalidLocatorMemberName", CliStrings.STATUS_LOCATOR));
        assertNotNull(result);
        assertEquals(Result.Status.ERROR, result.getStatus());
        assertEquals(CliStrings.format(CliStrings.STATUS_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, "invalidLocatorMemberName"), StringUtils.trim(toString(result)));
        result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STATUS_LOCATOR, pathname));
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        assertTrue(serviceStateStatusStringNormalized(toString(result)).contains(serviceStateStatusStringNormalized(expectedLocatorState)));
    } finally {
        stopLocator(workingDirectory);
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 3 with LocatorLauncher

use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.

the class StopLocatorCommand method stopLocator.

@CliCommand(value = CliStrings.STOP_LOCATOR, help = CliStrings.STOP_LOCATOR__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_LOCATOR, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result stopLocator(@CliOption(key = CliStrings.STOP_LOCATOR__MEMBER, optionContext = ConverterHint.LOCATOR_MEMBER_IDNAME, help = CliStrings.STOP_LOCATOR__MEMBER__HELP) final String member, @CliOption(key = CliStrings.STOP_LOCATOR__PID, help = CliStrings.STOP_LOCATOR__PID__HELP) final Integer pid, @CliOption(key = CliStrings.STOP_LOCATOR__DIR, help = CliStrings.STOP_LOCATOR__DIR__HELP) final String workingDirectory) {
    LocatorLauncher.LocatorState locatorState;
    try {
        if (StringUtils.isNotBlank(member)) {
            if (isConnectedAndReady()) {
                final MemberMXBean locatorProxy = getMemberMXBean(member);
                if (locatorProxy != null) {
                    if (!locatorProxy.isLocator()) {
                        throw new IllegalStateException(CliStrings.format(CliStrings.STOP_LOCATOR__NOT_LOCATOR_ERROR_MESSAGE, member));
                    }
                    if (locatorProxy.isServer()) {
                        throw new IllegalStateException(CliStrings.format(CliStrings.STOP_LOCATOR__LOCATOR_IS_CACHE_SERVER_ERROR_MESSAGE, member));
                    }
                    locatorState = LocatorLauncher.LocatorState.fromJson(locatorProxy.status());
                    locatorProxy.shutDownMember();
                } else {
                    return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STOP_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
                }
            } else {
                return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STOP_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, LOCATOR_TERM_NAME));
            }
        } else {
            final LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STOP).setDebug(isDebugging()).setPid(pid).setWorkingDirectory(workingDirectory).build();
            locatorState = locatorLauncher.status();
            locatorLauncher.stop();
        }
        if (AbstractLauncher.Status.ONLINE.equals(locatorState.getStatus())) {
            getGfsh().logInfo(String.format(CliStrings.STOP_LOCATOR__STOPPING_LOCATOR_MESSAGE, locatorState.getWorkingDirectory(), locatorState.getServiceLocation(), locatorState.getMemberName(), locatorState.getPid(), locatorState.getLogFile()), null);
            StopWatch stopWatch = new StopWatch(true);
            while (locatorState.isVmWithProcessIdRunning()) {
                Gfsh.print(".");
                if (stopWatch.elapsedTimeMillis() > WAITING_FOR_STOP_TO_MAKE_PID_GO_AWAY_TIMEOUT_MILLIS) {
                    break;
                }
                synchronized (this) {
                    TimeUnit.MILLISECONDS.timedWait(this, 500);
                }
            }
            return ResultBuilder.createInfoResult(StringUtils.EMPTY);
        } else {
            return ResultBuilder.createUserErrorResult(locatorState.toString());
        }
    } catch (IllegalArgumentException | IllegalStateException e) {
        return ResultBuilder.createUserErrorResult(e.getMessage());
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.STOP_LOCATOR__GENERAL_ERROR_MESSAGE, toString(t, getGfsh().getDebug())));
    } finally {
        Gfsh.redirectInternalJavaLoggers();
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) MemberMXBean(org.apache.geode.management.MemberMXBean) MXBeanProvider.getMemberMXBean(org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean) StopWatch(org.apache.geode.internal.util.StopWatch) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 4 with LocatorLauncher

use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.

the class LauncherLifecycleCommands method startLocator.

@CliCommand(value = CliStrings.START_LOCATOR, help = CliStrings.START_LOCATOR__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_LOCATOR, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result startLocator(@CliOption(key = CliStrings.START_LOCATOR__MEMBER_NAME, help = CliStrings.START_LOCATOR__MEMBER_NAME__HELP) String memberName, @CliOption(key = CliStrings.START_LOCATOR__BIND_ADDRESS, help = CliStrings.START_LOCATOR__BIND_ADDRESS__HELP) final String bindAddress, @CliOption(key = CliStrings.START_LOCATOR__CLASSPATH, help = CliStrings.START_LOCATOR__CLASSPATH__HELP) final String classpath, @CliOption(key = CliStrings.START_LOCATOR__FORCE, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.START_LOCATOR__FORCE__HELP) final Boolean force, @CliOption(key = CliStrings.START_LOCATOR__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.START_LOCATOR__GROUP__HELP) final String group, @CliOption(key = CliStrings.START_LOCATOR__HOSTNAME_FOR_CLIENTS, help = CliStrings.START_LOCATOR__HOSTNAME_FOR_CLIENTS__HELP) final String hostnameForClients, @CliOption(key = CliStrings.START_LOCATOR__INCLUDE_SYSTEM_CLASSPATH, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.START_LOCATOR__INCLUDE_SYSTEM_CLASSPATH__HELP) final Boolean includeSystemClasspath, @CliOption(key = CliStrings.START_LOCATOR__LOCATORS, optionContext = ConverterHint.LOCATOR_DISCOVERY_CONFIG, help = CliStrings.START_LOCATOR__LOCATORS__HELP) final String locators, @CliOption(key = CliStrings.START_LOCATOR__LOG_LEVEL, optionContext = ConverterHint.LOG_LEVEL, help = CliStrings.START_LOCATOR__LOG_LEVEL__HELP) final String logLevel, @CliOption(key = CliStrings.START_LOCATOR__MCAST_ADDRESS, help = CliStrings.START_LOCATOR__MCAST_ADDRESS__HELP) final String mcastBindAddress, @CliOption(key = CliStrings.START_LOCATOR__MCAST_PORT, help = CliStrings.START_LOCATOR__MCAST_PORT__HELP) final Integer mcastPort, @CliOption(key = CliStrings.START_LOCATOR__PORT, help = CliStrings.START_LOCATOR__PORT__HELP) final Integer port, @CliOption(key = CliStrings.START_LOCATOR__DIR, help = CliStrings.START_LOCATOR__DIR__HELP) String workingDirectory, @CliOption(key = CliStrings.START_LOCATOR__PROPERTIES, optionContext = ConverterHint.FILE_PATH, help = CliStrings.START_LOCATOR__PROPERTIES__HELP) String gemfirePropertiesPathname, @CliOption(key = CliStrings.START_LOCATOR__SECURITY_PROPERTIES, optionContext = ConverterHint.FILE_PATH, help = CliStrings.START_LOCATOR__SECURITY_PROPERTIES__HELP) String gemfireSecurityPropertiesPathname, @CliOption(key = CliStrings.START_LOCATOR__INITIALHEAP, help = CliStrings.START_LOCATOR__INITIALHEAP__HELP) final String initialHeap, @CliOption(key = CliStrings.START_LOCATOR__MAXHEAP, help = CliStrings.START_LOCATOR__MAXHEAP__HELP) final String maxHeap, @CliOption(key = CliStrings.START_LOCATOR__J, optionContext = GfshParser.J_OPTION_CONTEXT, help = CliStrings.START_LOCATOR__J__HELP) final String[] jvmArgsOpts, @CliOption(key = CliStrings.START_LOCATOR__CONNECT, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true", help = CliStrings.START_LOCATOR__CONNECT__HELP) final boolean connect, @CliOption(key = CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true", help = CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION__HELP) final boolean enableSharedConfiguration, @CliOption(key = CliStrings.START_LOCATOR__LOAD__SHARED_CONFIGURATION__FROM__FILESYSTEM, unspecifiedDefaultValue = "false", help = CliStrings.START_LOCATOR__LOAD__SHARED_CONFIGURATION__FROM__FILESYSTEM__HELP) final boolean loadSharedConfigurationFromDirectory, @CliOption(key = CliStrings.START_LOCATOR__CLUSTER__CONFIG__DIR, unspecifiedDefaultValue = "", help = CliStrings.START_LOCATOR__CLUSTER__CONFIG__DIR__HELP) final String clusterConfigDir, @CliOption(key = CliStrings.START_LOCATOR__HTTP_SERVICE_PORT, help = CliStrings.START_LOCATOR__HTTP_SERVICE_PORT__HELP) final Integer httpServicePort, @CliOption(key = CliStrings.START_LOCATOR__HTTP_SERVICE_BIND_ADDRESS, help = CliStrings.START_LOCATOR__HTTP_SERVICE_BIND_ADDRESS__HELP) final String httpServiceBindAddress) {
    try {
        if (StringUtils.isBlank(memberName)) {
            // when the user doesn't give us a name, we make one up!
            memberName = nameGenerator.generate('-');
        }
        workingDirectory = resolveWorkingDir(workingDirectory, memberName);
        gemfirePropertiesPathname = CliUtil.resolvePathname(gemfirePropertiesPathname);
        if (StringUtils.isNotBlank(gemfirePropertiesPathname) && !IOUtils.isExistingPathname(gemfirePropertiesPathname)) {
            return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, StringUtils.EMPTY, gemfirePropertiesPathname));
        }
        gemfireSecurityPropertiesPathname = CliUtil.resolvePathname(gemfireSecurityPropertiesPathname);
        if (StringUtils.isNotBlank(gemfireSecurityPropertiesPathname) && !IOUtils.isExistingPathname(gemfireSecurityPropertiesPathname)) {
            return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, "Security ", gemfireSecurityPropertiesPathname));
        }
        File locatorPidFile = new File(workingDirectory, ProcessType.LOCATOR.getPidFileName());
        final int oldPid = readPid(locatorPidFile);
        Properties gemfireProperties = new Properties();
        gemfireProperties.setProperty(GROUPS, StringUtils.defaultString(group));
        gemfireProperties.setProperty(LOCATORS, StringUtils.defaultString(locators));
        gemfireProperties.setProperty(LOG_LEVEL, StringUtils.defaultString(logLevel));
        gemfireProperties.setProperty(MCAST_ADDRESS, StringUtils.defaultString(mcastBindAddress));
        gemfireProperties.setProperty(MCAST_PORT, StringUtils.defaultString(mcastPort));
        gemfireProperties.setProperty(ENABLE_CLUSTER_CONFIGURATION, StringUtils.defaultString(enableSharedConfiguration));
        gemfireProperties.setProperty(LOAD_CLUSTER_CONFIGURATION_FROM_DIR, StringUtils.defaultString(loadSharedConfigurationFromDirectory));
        gemfireProperties.setProperty(CLUSTER_CONFIGURATION_DIR, StringUtils.defaultString(clusterConfigDir));
        gemfireProperties.setProperty(HTTP_SERVICE_PORT, StringUtils.defaultString(httpServicePort));
        gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, StringUtils.defaultString(httpServiceBindAddress));
        // read the OSProcess enable redirect system property here -- TODO: replace with new GFSH
        // argument
        final boolean redirectOutput = Boolean.getBoolean(OSProcess.ENABLE_OUTPUT_REDIRECTION_PROPERTY);
        LocatorLauncher.Builder locatorLauncherBuilder = new LocatorLauncher.Builder().setBindAddress(bindAddress).setForce(force).setPort(port).setRedirectOutput(redirectOutput).setWorkingDirectory(workingDirectory);
        if (hostnameForClients != null) {
            locatorLauncherBuilder.setHostnameForClients(hostnameForClients);
        }
        if (memberName != null) {
            locatorLauncherBuilder.setMemberName(memberName);
        }
        LocatorLauncher locatorLauncher = locatorLauncherBuilder.build();
        String[] locatorCommandLine = createStartLocatorCommandLine(locatorLauncher, gemfirePropertiesPathname, gemfireSecurityPropertiesPathname, gemfireProperties, classpath, includeSystemClasspath, jvmArgsOpts, initialHeap, maxHeap);
        final Process locatorProcess = new ProcessBuilder(locatorCommandLine).directory(new File(locatorLauncher.getWorkingDirectory())).start();
        locatorProcess.getInputStream().close();
        locatorProcess.getOutputStream().close();
        // fix TRAC bug #51967 by using NON_BLOCKING on Windows
        final ReadingMode readingMode = SystemUtils.isWindows() ? ReadingMode.NON_BLOCKING : ReadingMode.BLOCKING;
        // need thread-safe StringBuffer
        final StringBuffer message = new StringBuffer();
        InputListener inputListener = new InputListener() {

            @Override
            public void notifyInputLine(String line) {
                message.append(line);
                if (readingMode == ReadingMode.BLOCKING) {
                    message.append(StringUtils.LINE_SEPARATOR);
                }
            }
        };
        ProcessStreamReader stderrReader = new ProcessStreamReader.Builder(locatorProcess).inputStream(locatorProcess.getErrorStream()).inputListener(inputListener).readingMode(readingMode).continueReadingMillis(2 * 1000).build().start();
        LocatorState locatorState;
        String previousLocatorStatusMessage = null;
        LauncherSignalListener locatorSignalListener = new LauncherSignalListener();
        final boolean registeredLocatorSignalListener = getGfsh().getSignalHandler().registerListener(locatorSignalListener);
        try {
            getGfsh().logInfo(String.format(CliStrings.START_LOCATOR__RUN_MESSAGE, IOUtils.tryGetCanonicalPathElseGetAbsolutePath(new File(locatorLauncher.getWorkingDirectory()))), null);
            locatorState = LocatorState.fromDirectory(workingDirectory, memberName);
            do {
                if (locatorProcess.isAlive()) {
                    Gfsh.print(".");
                    synchronized (this) {
                        TimeUnit.MILLISECONDS.timedWait(this, 500);
                    }
                    locatorState = LocatorState.fromDirectory(workingDirectory, memberName);
                    String currentLocatorStatusMessage = locatorState.getStatusMessage();
                    if (locatorState.isStartingOrNotResponding() && !(StringUtils.isBlank(currentLocatorStatusMessage) || currentLocatorStatusMessage.equalsIgnoreCase(previousLocatorStatusMessage) || currentLocatorStatusMessage.trim().toLowerCase().equals("null"))) {
                        Gfsh.println();
                        Gfsh.println(currentLocatorStatusMessage);
                        previousLocatorStatusMessage = currentLocatorStatusMessage;
                    }
                } else {
                    final int exitValue = locatorProcess.exitValue();
                    return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.START_LOCATOR__PROCESS_TERMINATED_ABNORMALLY_ERROR_MESSAGE, exitValue, locatorLauncher.getWorkingDirectory(), message.toString()));
                }
            } while (!(registeredLocatorSignalListener && locatorSignalListener.isSignaled()) && locatorState.isStartingOrNotResponding());
        } finally {
            // stop will close
            stderrReader.stopAsync(PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS);
            // ErrorStream
            getGfsh().getSignalHandler().unregisterListener(locatorSignalListener);
        }
        Gfsh.println();
        final boolean asyncStart = (registeredLocatorSignalListener && locatorSignalListener.isSignaled() && ServerState.isStartingNotRespondingOrNull(locatorState));
        InfoResultData infoResultData = ResultBuilder.createInfoResultData();
        if (asyncStart) {
            infoResultData.addLine(String.format(CliStrings.ASYNC_PROCESS_LAUNCH_MESSAGE, LOCATOR_TERM_NAME));
        } else {
            infoResultData.addLine(locatorState.toString());
            String locatorHostName;
            InetAddress bindAddr = locatorLauncher.getBindAddress();
            if (bindAddr != null) {
                locatorHostName = bindAddr.getCanonicalHostName();
            } else {
                locatorHostName = StringUtils.defaultIfBlank(locatorLauncher.getHostnameForClients(), HostUtils.getLocalHost());
            }
            int locatorPort = Integer.parseInt(locatorState.getPort());
            // Else, ask the user to use the "connect" command to connect to the Locator.
            if (shouldAutoConnect(connect)) {
                doAutoConnect(locatorHostName, locatorPort, gemfirePropertiesPathname, gemfireSecurityPropertiesPathname, infoResultData);
            }
            // Report on the state of the Shared Configuration service if enabled...
            if (enableSharedConfiguration) {
                infoResultData.addLine(ClusterConfigurationStatusRetriever.fromLocator(locatorHostName, locatorPort));
            }
        }
        return ResultBuilder.buildResult(infoResultData);
    } catch (IllegalArgumentException e) {
        String message = e.getMessage();
        if (message != null && message.matches(LocalizedStrings.Launcher_Builder_UNKNOWN_HOST_ERROR_MESSAGE.toLocalizedString(".+"))) {
            message = CliStrings.format(CliStrings.LAUNCHERLIFECYCLECOMMANDS__MSG__FAILED_TO_START_0_REASON_1, LOCATOR_TERM_NAME, message);
        }
        return ResultBuilder.createUserErrorResult(message);
    } catch (IllegalStateException e) {
        return ResultBuilder.createUserErrorResult(e.getMessage());
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        String errorMessage = String.format(CliStrings.START_LOCATOR__GENERAL_ERROR_MESSAGE, StringUtils.defaultIfBlank(workingDirectory, memberName), getLocatorId(bindAddress, port), toString(t, getGfsh().getDebug()));
        getGfsh().logToFile(errorMessage, t);
        return ResultBuilder.createShellClientErrorResult(errorMessage);
    } finally {
        Gfsh.redirectInternalJavaLoggers();
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) ResultBuilder(org.apache.geode.management.internal.cli.result.ResultBuilder) OSProcess(org.apache.geode.internal.OSProcess) Properties(java.util.Properties) ConnectionEndpoint(org.apache.geode.management.internal.cli.util.ConnectionEndpoint) ConverterHint(org.apache.geode.management.cli.ConverterHint) InputListener(org.apache.geode.internal.process.ProcessStreamReader.InputListener) ProcessStreamReader(org.apache.geode.internal.process.ProcessStreamReader) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) InetAddress(java.net.InetAddress) ReadingMode(org.apache.geode.internal.process.ProcessStreamReader.ReadingMode) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 5 with LocatorLauncher

use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.

the class ShellCommandsDUnitTest method testConnectToLocatorBecomesManager.

// GEODE-989: random ports, suspect string: DiskAccessException, disk
@Category(FlakyTest.class)
// pollution, HeadlessGfsh, time sensitive
@Test
public void testConnectToLocatorBecomesManager() {
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    final int jmxManagerPort = ports[0];
    final int locatorPort = ports[1];
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port", String.valueOf(jmxManagerPort));
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-http-port", "0");
    assertEquals(String.valueOf(jmxManagerPort), System.getProperty(DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port"));
    assertEquals("0", System.getProperty(DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-http-port"));
    final String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
    final File workingDirectory = new File(pathname);
    workingDirectory.mkdir();
    assertTrue(workingDirectory.isDirectory());
    final LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setBindAddress(null).setForce(true).setMemberName(pathname).setPort(locatorPort).setWorkingDirectory(IOUtils.tryGetCanonicalPathElseGetAbsolutePath(workingDirectory)).build();
    assertNotNull(locatorLauncher);
    assertEquals(locatorPort, locatorLauncher.getPort().intValue());
    try {
        // fix for bug 46729
        locatorLauncher.start();
        final LocatorState locatorState = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
        assertNotNull(locatorState);
        assertEquals(Status.ONLINE, locatorState.getStatus());
        final Result result = connectToLocator(locatorPort);
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
    } finally {
        assertEquals(Status.STOPPED, locatorLauncher.stop().getStatus());
        assertEquals(Status.NOT_RESPONDING, locatorLauncher.status().getStatus());
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Result(org.apache.geode.management.cli.Result) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Aggregations

LocatorLauncher (org.apache.geode.distributed.LocatorLauncher)11 File (java.io.File)7 LocatorState (org.apache.geode.distributed.LocatorLauncher.LocatorState)7 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)6 Test (org.junit.Test)6 Builder (org.apache.geode.distributed.LocatorLauncher.Builder)5 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 CliMetaData (org.apache.geode.management.cli.CliMetaData)3 CliCommand (org.springframework.shell.core.annotation.CliCommand)3 Properties (java.util.Properties)2 MemberMXBean (org.apache.geode.management.MemberMXBean)2 MXBeanProvider.getMemberMXBean (org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2 InetAddress (java.net.InetAddress)1 HashSet (java.util.HashSet)1 Status (org.apache.geode.distributed.AbstractLauncher.Status)1 OSProcess (org.apache.geode.internal.OSProcess)1 ProcessStreamReader (org.apache.geode.internal.process.ProcessStreamReader)1 InputListener (org.apache.geode.internal.process.ProcessStreamReader.InputListener)1