Search in sources :

Example 46 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class ClusterConfigurationDUnitTest method executeAndVerifyCommand.

private CommandResult executeAndVerifyCommand(String commandString) {
    CommandResult cmdResult = executeCommand(commandString);
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Command : " + commandString);
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Command Result : " + commandResultToString(cmdResult));
    assertEquals(Status.OK, cmdResult.getStatus());
    assertFalse(cmdResult.failedToPersist());
    return cmdResult;
}
Also used : CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 47 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class ClusterConfigurationIndexWithFromClauseDUnitTest method verifyIndexRecreated.

private void verifyIndexRecreated(String indexName) throws Exception {
    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
    CommandResult commandResult = gfshShellConnectionRule.executeAndVerifyCommand(csb.toString());
    String resultAsString = commandResultToString(commandResult);
    assertEquals(Result.Status.OK, commandResult.getStatus());
    assertTrue(resultAsString.contains(indexName));
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 48 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class ConnectCommandWithHttpAndSSLDUnitTest method connect.

@Override
protected void connect(final String host, final int jmxPort, final int httpPort, final HeadlessGfsh shell) {
    assertNotNull(host);
    assertNotNull(shell);
    final CommandStringBuilder command = new CommandStringBuilder(CONNECT);
    String endpoint;
    // This is for testing purpose only. If we remove this piece of code we will
    // get a java.security.cert.CertificateException
    // as matching hostname can not be obtained in all test environment.
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String string, SSLSession ssls) {
            return true;
        }
    });
    endpoint = "https://" + host + ":" + httpPort + urlContext + "/v1";
    command.addOption(CONNECT__USE_HTTP, Boolean.TRUE.toString());
    command.addOption(CONNECT__URL, endpoint);
    command.addOption(CONNECT__USE_SSL, Boolean.TRUE.toString());
    if (sslInfoHolder.get().getProperty(CONNECT__KEY_STORE) != null) {
        command.addOption(CONNECT__KEY_STORE, sslInfoHolder.get().getProperty(CONNECT__KEY_STORE));
    }
    if (sslInfoHolder.get().getProperty(CONNECT__KEY_STORE_PASSWORD) != null) {
        command.addOption(CONNECT__KEY_STORE_PASSWORD, sslInfoHolder.get().getProperty(CONNECT__KEY_STORE_PASSWORD));
    }
    if (sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE) != null) {
        command.addOption(CONNECT__TRUST_STORE, sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE));
    }
    if (sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE_PASSWORD) != null) {
        command.addOption(CONNECT__TRUST_STORE_PASSWORD, sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE_PASSWORD));
    }
    if (sslInfoHolder.get().getProperty(CONNECT__SSL_PROTOCOLS) != null) {
        command.addOption(CONNECT__SSL_PROTOCOLS, sslInfoHolder.get().getProperty(CONNECT__SSL_PROTOCOLS));
    }
    if (sslInfoHolder.get().getProperty(CONNECT__SSL_CIPHERS) != null) {
        command.addOption(CONNECT__SSL_CIPHERS, sslInfoHolder.get().getProperty(CONNECT__SSL_CIPHERS));
    }
    CommandResult result = executeCommand(shell, command.toString());
    if (!shell.isConnectedAndReady()) {
        fail("Connect command failed to connect to manager " + endpoint + " result=" + commandResultToString(result));
    }
    info("Successfully connected to managing node using HTTPS");
    assertEquals(true, shell.isConnectedAndReady());
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) SSLSession(javax.net.ssl.SSLSession) HostnameVerifier(javax.net.ssl.HostnameVerifier) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 49 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class CliCommandTestBase method executeCommandWithoutClear.

/**
   * Execute a command in the provided shell. Useful for getting additional information from the
   * shell after the command has been executed (using getDefaultShell().???). Caller is responsible
   * for calling getDefaultShell().clearEvents() when done.
   *
   * @param shell Shell in which to execute the command.
   * @param command Command to execute
   * @return The result of the command execution
   */
protected CommandResult executeCommandWithoutClear(HeadlessGfsh shell, String command) {
    assert (shell != null);
    assert (command != null);
    shell.executeCommand(command);
    if (shell.hasError()) {
        error("executeCommand completed with error : " + shell.getError());
    }
    CommandResult result = null;
    try {
        // TODO: this can result in ClassCastException if
        result = (CommandResult) shell.getResult();
    // command resulted in error
    } catch (InterruptedException ex) {
        error("shell received InterruptedException");
    }
    if (result != null) {
        result.resetToFirstLine();
    }
    return result;
}
Also used : CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 50 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class CliCommandTestBase method connect.

protected void connect(final String host, final int jmxPort, final int httpPort, HeadlessGfsh shell, String username, String password) {
    final CommandStringBuilder command = new CommandStringBuilder(CliStrings.CONNECT);
    String endpoint;
    if (useHttpOnConnect) {
        endpoint = "http://" + host + ":" + httpPort + "/gemfire/v1";
        command.addOption(CliStrings.CONNECT__USE_HTTP, Boolean.TRUE.toString());
        command.addOption(CliStrings.CONNECT__URL, endpoint);
    } else {
        endpoint = host + "[" + jmxPort + "]";
        command.addOption(CliStrings.CONNECT__JMX_MANAGER, endpoint);
    }
    if (username != null) {
        command.addOption(CliStrings.CONNECT__USERNAME, username);
    }
    if (password != null) {
        command.addOption(CliStrings.CONNECT__PASSWORD, password);
    }
    System.out.println(getClass().getSimpleName() + " using endpoint: " + endpoint);
    CommandResult result = executeCommand(shell, command.toString());
    if (!shell.isConnectedAndReady()) {
        throw new AssertionError("Connect command failed to connect to manager " + endpoint + " result=" + commandResultToString(result));
    }
    info("Successfully connected to managing node using " + (useHttpOnConnect ? "HTTP" : "JMX"));
    assertEquals(true, shell.isConnectedAndReady());
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Aggregations

CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)270 Test (org.junit.Test)222 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)208 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)131 Properties (java.util.Properties)94 VM (org.apache.geode.test.dunit.VM)80 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)71 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)67 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)45 File (java.io.File)44 Cache (org.apache.geode.cache.Cache)43 Region (org.apache.geode.cache.Region)39 Category (org.junit.experimental.categories.Category)33 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)32 InternalCache (org.apache.geode.internal.cache.InternalCache)29 DistributedMember (org.apache.geode.distributed.DistributedMember)26 ArrayList (java.util.ArrayList)16 RegionFactory (org.apache.geode.cache.RegionFactory)15 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)15 Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)14