Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFLY-1850] / [WFLY-1664] / [WFLY-2462] Enhancements to CLI configuration and address handling for resolving the 3 parts of a controllers address. #5435

Closed
wants to merge 6 commits into from
12 changes: 12 additions & 0 deletions build/src/main/resources/bin/jboss-cli.xml
Expand Up @@ -5,12 +5,24 @@
-->
<jboss-cli xmlns="urn:jboss:cli:2.0">

<default-protocol use-legacy-override="true">http-remoting</default-protocol>

<!-- The default controller to connect to when 'connect' command is executed w/o arguments -->
<default-controller>
<protocol>http-remoting</protocol>
<host>localhost</host>
<port>9990</port>
</default-controller>

<!-- Example controller alias named 'Test'
<controllers>
<controller name="Test">
<protocol>http-remoting</protocol>
<host>localhost</host>
<port>9990</port>
</controller>
</controllers>
-->

<validate-operation-requests>true</validate-operation-requests>

Expand Down
260 changes: 157 additions & 103 deletions build/src/main/resources/docs/schema/jboss-as-cli_2_0.xsd

Large diffs are not rendered by default.

43 changes: 36 additions & 7 deletions cli/src/main/java/org/jboss/as/cli/CliConfig.java
Expand Up @@ -29,27 +29,56 @@
*/
public interface CliConfig {

/**
* The default server controller protocol
*
* @return default server controller protocol
*/
String getDefaultControllerProtocol();

/**
* The default server controller host to connect to.
*
* @deprecated Use {@link CliConfig#getDefaultControllerAddress()} instead.
*
* @return default server controller host to connect to
*/
@Deprecated
String getDefaultControllerHost();

/**
* The default server controller port to connect to.
*
* @deprecated Use {@link CliConfig#getDefaultControllerAddress()} instead.
*
* @return default server controller port to connect to
*/
@Deprecated
int getDefaultControllerPort();

/**
* The default server controller protocol for addresses where no protocol is specified.
*
* @return default server controller protocol
*/
String getDefaultControllerProtocol();

/**
* If {@code true} then for addresses specified without a protocol but with a port number of 9999 the
* protocol should be assumed to be 'remoting://'
*
* @return use legacy override option.
*/
boolean isUseLegacyOverride();

/**
* The default address of the controller from the configuration.
*
* @return The default address.
*/
ControllerAddress getDefaultControllerAddress();

/**
* Obtain the {@link ControllerAddress} for a given alias.
*
* @param alias - The alias if the address mapping.
* @return The {@link ControllerAddress} if defined, otherwise {@code null}
*/
ControllerAddress getAliasedControllerAddress(String alias);

/**
* Whether the record the history of executed commands and operations.
*
Expand Down
62 changes: 44 additions & 18 deletions cli/src/main/java/org/jboss/as/cli/CommandContext.java
Expand Up @@ -117,57 +117,83 @@ public interface CommandContext {
*/
ModelControllerClient getModelControllerClient();

/**
* Connects the controller client using the default controller definition.
*
* The default controller will be identified as the default specified on starting the CLI will be used, if no controller was
* specified on start up then the default defined in the CLI configuration will be used, if no default is defined then a
* connection to http-remoting://localhost:9990 will be used instead.
*
* @throws CommandLineException in case the attempt to connect failed
*/
void connectController() throws CommandLineException;

/**
* Connects to the controller specified.
*
* If the controller is null then the default specified on starting the CLI will be used, if no controller was specified on
* start up then the default defined in the CLI configuration will be used, if no default is defined then a connection to
* http-remoting://localhost:9990 will be used instead.
*
* @param controller the controller to connect to
* @throws CommandLineException in case the attempt to connect failed
*/
void connectController(String controller) throws CommandLineException;

/**
* Connects the controller client using the host and the port.
* If the host is null, the default controller host will be used,
* which is localhost.
* If the port is less than zero, the default controller port will be used,
* which is 9999.
*
* @param protocol the protocol to connect with, either remote, http or https
* @deprecated Use {@link #connectController(String)} instead.
*
* @param host the host to connect with
* @param port the port to connect on
* @throws CommandLineException in case the attempt to connect failed
*/
void connectController(String protocol, String host, int port) throws CommandLineException;
@Deprecated
void connectController(String host, int port) throws CommandLineException;

/**
* Bind the controller to an existing, connected client.
*/
void bindClient(ModelControllerClient newClient);

/**
* Connects the controller client using the default host and the port.
* It simply calls connectController(null, -1).
*
* @throws CommandLineException in case the attempt to connect failed
*/
void connectController() throws CommandLineException;

/**
* Closes the previously established connection with the controller client.
* If the connection hasn't been established, the method silently returns.
*/
void disconnectController();

/**
* Returns the default host the controller client will be connected to
* in case the host argument isn't specified.
* Returns the default host the controller client will be connected to.
*
* @return the default host the controller client will be connected to
* in case the host argument isn't specified.
* @deprecated Use {@link CommandContext#getDefaultControllerAddress()} instead.
*
* @return the default host the controller client will be connected to.
*/
@Deprecated
String getDefaultControllerHost();

/**
* Returns the default port the controller client will be connected to
* in case the port argument isn't specified.
* Returns the default port the controller client will be connected to.
*
* @deprecated Use {@link CommandContext#getDefaultControllerAddress()} instead.
*
* @return the default port the controller client will be connected to
* in case the port argument isn't specified.
* @return the default port the controller client will be connected to.
*/
@Deprecated
int getDefaultControllerPort();

/**
* The default address of the default controller to connect to.
*
* @return The default address.
*/
ControllerAddress getDefaultControllerAddress();

/**
* Returns the host the controller client is connected to or
* null if the connection hasn't been established yet.
Expand Down
31 changes: 26 additions & 5 deletions cli/src/main/java/org/jboss/as/cli/CommandContextFactory.java
Expand Up @@ -54,16 +54,37 @@ protected CommandContextFactory() {}

public abstract CommandContext newCommandContext(String username, char[] password) throws CliInitializationException;

public abstract CommandContext newCommandContext(String controllerProtocol, String controllerHost, int controllerPort,
public abstract CommandContext newCommandContext(String controller, String username, char[] password) throws CliInitializationException;

public abstract CommandContext newCommandContext(String controller, String username, char[] password, boolean initConsole,
final int connectionTimeout) throws CliInitializationException;

public abstract CommandContext newCommandContext(String controller, String username, char[] password, boolean disableLocalAuth,
boolean initConsole, final int connectionTimeout) throws CliInitializationException;

public abstract CommandContext newCommandContext(String controller, String username, char[] password, InputStream consoleInput,
OutputStream consoleOutput) throws CliInitializationException;

/**
* @deprecated Use {@link #newCommandContext(String, String, char[])} instead.
*/
@Deprecated
public abstract CommandContext newCommandContext(String controllerHost, int controllerPort,
String username, char[] password) throws CliInitializationException;

public abstract CommandContext newCommandContext(String controllerProtocol, String controllerHost, int controllerPort,
/**
* @deprecated Use {@link #newCommandContext(String, int, String, char[], boolean, int)} instead.
*/
@Deprecated
public abstract CommandContext newCommandContext(String controllerHost, int controllerPort,
String username, char[] password, boolean initConsole, final int connectionTimeout) throws CliInitializationException;

public abstract CommandContext newCommandContext(String controllerProtocol, String controllerHost, int controllerPort,
String username, char[] password, boolean disableLocalAuth, boolean initConsole, final int connectionTimeout) throws CliInitializationException;

/**
* @deprecated Use {@link #newCommandContext(String, int, String, char[], InputStream, OutputStream)} instead.
*/
@Deprecated
public abstract CommandContext newCommandContext(String controllerHost, int controllerPort,
String username, char[] password,
InputStream consoleInput, OutputStream consoleOutput) throws CliInitializationException;

}
53 changes: 53 additions & 0 deletions cli/src/main/java/org/jboss/as/cli/ControllerAddress.java
@@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.cli;

/**
* A class used both by the {@link ControllerAddressResolver} and by the configuration to represent the address of a controller.
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
public class ControllerAddress {

private final String protocol;
private final String host;
private final int port;

public ControllerAddress(final String protocol, final String host, final int port) {
this.protocol = protocol;
this.host = host;
this.port = port;
}

public String getProtocol() {
return protocol;
}

public String getHost() {
return host;
}

public int getPort() {
return port;
}

}