use of org.glassfish.api.admin.SSHCommandExecutionException in project Payara by payara.
the class NodeRunnerDcom method runAdminCommandOnRemoteNode.
/*
* return 0 is success, otherwise failure
*/
public final int runAdminCommandOnRemoteNode(Node thisNode, StringBuilder output, List<String> args, List<String> stdinLines) throws SSHCommandExecutionException, IllegalArgumentException, UnsupportedOperationException {
String humanreadable = null;
try {
this.node = thisNode;
dcomInfo = new DcomInfo(node);
List<String> fullcommand = new ArrayList<String>();
WindowsRemoteAsadmin asadmin = dcomInfo.getAsadmin();
if (stdinLines != null && !stdinLines.isEmpty())
setupAuthTokenFile(fullcommand, stdinLines);
fullcommand.addAll(args);
humanreadable = dcomInfo.getNadminPath() + " " + commandListToString(fullcommand);
// This is where the rubber meets the road...
String out = asadmin.run(fullcommand);
output.append(out);
logger.info(Strings.get("remote.command.summary", humanreadable, out));
return determineStatus(args);
} catch (WindowsException ex) {
throw new SSHCommandExecutionException(Strings.get("remote.command.error", ex.getMessage(), humanreadable), ex);
} finally {
teardownAuthTokenFile();
}
}
use of org.glassfish.api.admin.SSHCommandExecutionException in project Payara by payara.
the class AddTruststoreEntryCommand method addToTrustStore.
/**
* Runs the 'add-to-truststore' command on the local instance.
* @param context The admin command context.
* @throws CommandException If there's an issue running the command.
*/
private void addToTrustStore(AdminCommandContext context) throws CommandException {
NodeRunner nodeRunner = new NodeRunner(serviceLocator, context.getLogger());
Node node = nodes.getNode(servers.getServer(serverEnvironment.getInstanceName()).getNodeRef());
// The DAS doesn't have a node-ref
if (node == null && serverEnvironment.isDas()) {
node = nodes.getDefaultLocalNode();
}
try {
StringBuilder stringBuilder = new StringBuilder();
nodeRunner.runAdminCommandOnNode(node, stringBuilder, createAddToStoreCommand("add-to-truststore", node, new File(filePath), alias), context);
if (stringBuilder.toString().contains("Command add-to-truststore failed")) {
throw new CommandException();
}
} catch (SSHCommandExecutionException | ProcessManagerException e) {
throw new CommandException(e);
}
}
use of org.glassfish.api.admin.SSHCommandExecutionException in project Payara by payara.
the class NodeRunnerSsh method runAdminCommandOnRemoteNode.
public int runAdminCommandOnRemoteNode(Node node, StringBuilder output, List<String> args, List<String> stdinLines) throws SSHCommandExecutionException, IllegalArgumentException, UnsupportedOperationException {
args.add(0, AsadminInput.CLI_INPUT_OPTION);
// specified to read from System.in
args.add(1, AsadminInput.SYSTEM_IN_INDICATOR);
if (!isSshNode(node)) {
throw new UnsupportedOperationException("Node is not of type SSH");
}
String installDir = node.getInstallDirUnixStyle() + "/" + SystemPropertyConstants.getComponentName();
if (!StringUtils.ok(installDir)) {
throw new IllegalArgumentException("Node does not have an installDir");
}
List<String> fullcommand = new ArrayList<String>();
// We can just use "nadmin" even on Windows since the SSHD provider
// will locate the command (.exe or .bat) for us
fullcommand.add(installDir + "/lib/nadmin");
fullcommand.addAll(args);
try {
lastCommandRun = commandListToString(fullcommand);
trace("Running command on " + node.getNodeHost() + ": " + lastCommandRun);
sshL = habitat.getService(SSHLauncher.class);
sshL.init(node, logger);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
commandStatus = sshL.runCommand(fullcommand, outStream, stdinLines);
output.append(outStream.toString());
return commandStatus;
} catch (IOException ex) {
String m1 = " Command execution failed. " + ex.getMessage();
String m2 = "";
Throwable e2 = ex.getCause();
if (e2 != null) {
m2 = e2.getMessage();
}
logger.severe("Command execution failed for " + lastCommandRun);
SSHCommandExecutionException cee = new SSHCommandExecutionException(StringUtils.cat(":", m1, m2));
cee.setSSHSettings(sshL.toString());
cee.setCommandRun(lastCommandRun);
throw cee;
} catch (java.lang.InterruptedException ei) {
ei.printStackTrace();
String m1 = ei.getMessage();
String m2 = "";
Throwable e2 = ei.getCause();
if (e2 != null) {
m2 = e2.getMessage();
}
logger.severe("Command interrupted " + lastCommandRun);
SSHCommandExecutionException cee = new SSHCommandExecutionException(StringUtils.cat(":", m1, m2));
cee.setSSHSettings(sshL.toString());
cee.setCommandRun(lastCommandRun);
throw cee;
}
}
use of org.glassfish.api.admin.SSHCommandExecutionException in project Payara by payara.
the class AddKeystoreEntryCommand method addToKeyStore.
/**
* Runs the 'add-to-keystore' command on the local instance.
* @param context The admin command context.
* @throws CommandException If there's an issue running the command.
*/
private void addToKeyStore(AdminCommandContext context) throws CommandException {
NodeRunner nodeRunner = new NodeRunner(serviceLocator, context.getLogger());
Node node = nodes.getNode(servers.getServer(serverEnvironment.getInstanceName()).getNodeRef());
// The DAS doesn't have a node-ref
if (node == null && serverEnvironment.isDas()) {
node = nodes.getDefaultLocalNode();
}
try {
StringBuilder stringBuilder = new StringBuilder();
nodeRunner.runAdminCommandOnNode(node, stringBuilder, createAddToStoreCommand("add-to-keystore", node, new File(filePath), alias), context);
if (stringBuilder.toString().contains("Command add-to-keystore failed")) {
throw new CommandException();
}
} catch (SSHCommandExecutionException | ProcessManagerException e) {
throw new CommandException(e);
}
}
Aggregations