use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class CreateNodeConfigCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
// validate installdir if passed and running on localhost
if (StringUtils.ok(nodehost)) {
if (NetUtils.isThisHostLocal(nodehost) && StringUtils.ok(installdir)) {
TokenResolver resolver = null;
// Create a resolver that can replace system properties in strings
Map<String, String> systemPropsMap = new HashMap<String, String>((Map) (System.getProperties()));
resolver = new TokenResolver(systemPropsMap);
String resolvedInstallDir = resolver.resolve(installdir);
File actualInstallDir = new File(resolvedInstallDir + "/" + NodeUtils.LANDMARK_FILE);
if (!actualInstallDir.exists()) {
report.setMessage(Strings.get("invalid.installdir", installdir));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
CommandInvocation ci = cr.getCommandInvocation("_create-node", report, context.getSubject());
ParameterMap map = new ParameterMap();
map.add("DEFAULT", name);
if (StringUtils.ok(nodedir))
map.add(NodeUtils.PARAM_NODEDIR, nodedir);
if (StringUtils.ok(installdir))
map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
if (StringUtils.ok(nodehost))
map.add(NodeUtils.PARAM_NODEHOST, nodehost);
map.add(NodeUtils.PARAM_TYPE, "CONFIG");
ci.parameters(map);
ci.execute();
NodeUtils.sanitizeReport(report);
}
use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class CreateNodeImplicitCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
if (name == null)
name = nodehost;
if (nodes.getNode(name) != null) {
// already created nothing to do here
return;
}
CommandInvocation ci = cr.getCommandInvocation("_create-node", report, context.getSubject());
ParameterMap map = new ParameterMap();
map.add("DEFAULT", name);
map.add(NodeUtils.PARAM_NODEDIR, nodedir);
map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
map.add(NodeUtils.PARAM_NODEHOST, nodehost);
map.add(NodeUtils.PARAM_TYPE, "CONFIG");
ci.parameters(map);
ci.execute();
}
use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class CreateRemoteNodeCommand method executeInternal.
public final void executeInternal(AdminCommandContext context) {
ActionReport report = context.getActionReport();
StringBuilder msg = new StringBuilder();
logger = context.getLogger();
initialize();
populateBaseClass();
checkDefaults();
ParameterMap map = new ParameterMap();
populateParametersInternal(map);
try {
validate();
} catch (CommandValidationException ex) {
report.setMessage(ex.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
nodeUtils = new NodeUtils(habitat, logger);
nodeUtils.validate(map);
if (install) {
boolean s = installNode(context);
if (!s && !force) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
} catch (CommandValidationException e) {
String m1 = Strings.get("node.ssh.invalid.params");
if (!force) {
String m2 = Strings.get("create.node.ssh.or.dcom.not.created", getType().toString());
msg.append(StringUtils.cat(NL, m1, m2, e.getMessage()));
report.setMessage(msg.toString());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
} else {
String m2 = Strings.get("create.node.ssh.continue.force");
msg.append(StringUtils.cat(NL, m1, e.getMessage(), m2));
}
}
map.remove(NodeUtils.PARAM_INSTALL);
CommandInvocation ci = cr.getCommandInvocation("_create-node", report, context.getSubject());
ci.parameters(map);
ci.execute();
NodeUtils.sanitizeReport(report);
if (StringUtils.ok(report.getMessage())) {
if (msg.length() > 0) {
msg.append(NL);
}
msg.append(report.getMessage());
}
report.setMessage(msg.toString());
}
use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class DeleteNodeConfigCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
Logger logger = context.getLogger();
Node node = nodes.getNode(name);
if (node == null) {
// no node to delete nothing to do here
String msg = Strings.get("noSuchNode", name);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (!(node.getType().equals("CONFIG"))) {
// no node to delete nothing to do here
String msg = Strings.get("notConfigNodeType", name);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
CommandInvocation ci = cr.getCommandInvocation("_delete-node", report, context.getSubject());
ParameterMap map = new ParameterMap();
map.add("DEFAULT", name);
ci.parameters(map);
ci.execute();
}
use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class DeleteNodeRemoteCommand method executeInternal.
protected final void executeInternal(AdminCommandContext context) {
ActionReport report = context.getActionReport();
logger = context.getLogger();
Node node = nodes.getNode(name);
if (node == null) {
// no node to delete nothing to do here
String msg = Strings.get("noSuchNode", name);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
String type = node.getType();
if ((type == null) || (type.equals("CONFIG"))) {
// no node to delete nothing to do here
String msg = Strings.get("notRemoteNodeType", name);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
ParameterMap info = new ParameterMap();
if (uninstall) {
// store needed info for uninstall
SshConnector sshC = node.getSshConnector();
SshAuth sshAuth = sshC.getSshAuth();
if (sshAuth.getPassword() != null)
info.add(NodeUtils.PARAM_REMOTEPASSWORD, sshAuth.getPassword());
if (sshAuth.getKeyPassphrase() != null)
info.add(NodeUtils.PARAM_SSHKEYPASSPHRASE, sshAuth.getKeyPassphrase());
if (sshAuth.getKeyfile() != null)
info.add(NodeUtils.PARAM_SSHKEYFILE, sshAuth.getKeyfile());
info.add(NodeUtils.PARAM_INSTALLDIR, node.getInstallDir());
info.add(NodeUtils.PARAM_REMOTEPORT, sshC.getSshPort());
info.add(NodeUtils.PARAM_REMOTEUSER, sshAuth.getUserName());
info.add(NodeUtils.PARAM_NODEHOST, node.getNodeHost());
info.add(NodeUtils.PARAM_WINDOWS_DOMAIN, node.getWindowsDomain());
}
CommandInvocation ci = cr.getCommandInvocation("_delete-node", report, context.getSubject());
ParameterMap map = new ParameterMap();
map.add("DEFAULT", name);
ci.parameters(map);
ci.execute();
// uninstall GlassFish after deleting the node
if (uninstall) {
boolean s = uninstallNode(context, info, node);
if (!s && !force) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
Aggregations