use of com.mks.api.CmdRunner in project maven-scm by apache.
the class APISession method runCommand.
/**
* This function executes a generic API Command
*
* @param cmd MKS API Command Object representing an API command
* @return MKS API Response Object
* @throws APIException
*/
public Response runCommand(Command cmd) throws APIException {
CmdRunner cmdRunner = session.createCmdRunner();
cmdRunner.setDefaultHostname(hostName);
cmdRunner.setDefaultPort(port);
cmdRunner.setDefaultUsername(userName);
if (null != password && password.length() > 0) {
cmdRunner.setDefaultPassword(password);
}
Response res = cmdRunner.execute(cmd);
logger.debug(res.getCommandString() + " returned exit code " + res.getExitCode());
cmdRunner.release();
return res;
}
use of com.mks.api.CmdRunner in project maven-scm by apache.
the class APISession method runCommandAs.
/**
* This function executes a generic API Command impersonating another user
*
* @param cmd MKS API Command Object representing a API command
* @param impersonateUser The user to impersonate
* @return MKS API Response Object
* @throws APIException
*/
public Response runCommandAs(Command cmd, String impersonateUser) throws APIException {
CmdRunner cmdRunner = session.createCmdRunner();
cmdRunner.setDefaultHostname(hostName);
cmdRunner.setDefaultPort(port);
cmdRunner.setDefaultUsername(userName);
if (null != password && password.length() > 0) {
cmdRunner.setDefaultPassword(password);
}
cmdRunner.setDefaultImpersonationUser(impersonateUser);
Response res = cmdRunner.execute(cmd);
logger.debug(res.getCommandString() + " returned exit code " + res.getExitCode());
cmdRunner.release();
return res;
}
use of com.mks.api.CmdRunner in project maven-scm by apache.
the class APISession method connect.
/**
* Establishes a connection with the MKS Integrity Server
*
* @param host Hostname or IP address for the MKS Integrity Server
* @param portNum Port number for the MKS Integrity Server
* @param user Username to connect to the MKS Integrity Server
* @param paswd Password for the User connecting to the server
* @throws APIException
*/
public Response connect(String host, int portNum, String user, String paswd) throws APIException {
// Initialize our termination flag...
terminated = false;
// Create a local integration point
ip = IntegrationPointFactory.getInstance().createLocalIntegrationPoint(MAJOR_VERSION, MINOR_VERSION);
// Set the flag to automatically start the MKS Integrity Client, if not running
ip.setAutoStartIntegrityClient(true);
// Use a common session, which means we don't have to manage the password
if (null != paswd && paswd.length() > 0) {
logger.info("Creating session for " + user + "/" + StringUtils.repeat("*", paswd.length()));
session = ip.createSession(user, paswd);
logger.info("Attempting to establish connection using " + user + "@" + host + ":" + portNum);
} else {
logger.info("Using a common session. Connection information is obtained from client preferences");
session = ip.getCommonSession();
}
// Test the connection to the MKS Integrity Server
Command ping = new Command(Command.SI, "connect");
CmdRunner cmdRunner = session.createCmdRunner();
// Initialize the command runner with valid connection information
if (null != host && host.length() > 0) {
cmdRunner.setDefaultHostname(host);
}
if (portNum > 0) {
cmdRunner.setDefaultPort(portNum);
}
if (null != user && user.length() > 0) {
cmdRunner.setDefaultUsername(user);
}
if (null != paswd && paswd.length() > 0) {
cmdRunner.setDefaultPassword(paswd);
}
// Execute the connection
Response res = cmdRunner.execute(ping);
logger.debug(res.getCommandString() + " returned exit code " + res.getExitCode());
// Initialize class variables based on the connection information
hostName = res.getConnectionHostname();
port = res.getConnectionPort();
userName = res.getConnectionUsername();
password = paswd;
cmdRunner.release();
logger.info("Successfully established connection " + userName + "@" + hostName + ":" + port);
return res;
}