use of com.sun.enterprise.config.serverbeans.Node in project Payara by payara.
the class InstanceRegisterInstanceCommand method execute.
@Override
public void execute(AdminCommandContext ctxt) {
final ActionReport report = ctxt.getActionReport();
try {
// create node if it doesn't exist
Node n = domain.getNodes().getNode(node);
if (n == null) {
ConfigSupport.apply(new SingleConfigCode<Nodes>() {
@Override
public Object run(Nodes param) throws PropertyVetoException, TransactionFailure {
Node newNode = param.createChild(Node.class);
newNode.setName(node);
if (installdir != null && !"".equals(installdir))
newNode.setInstallDir(installdir);
if (nodedir != null && !"".equals(nodedir))
newNode.setNodeDir(nodedir);
if (nodehost != null && !"".equals(nodehost))
newNode.setNodeHost(nodehost);
newNode.setType(type);
// comment out - not needed
/*if (type.equals("SSH")) {
SshConnector sshC = param.createChild(SshConnector.class);
if (sshHost != null && sshHost != "") {
sshC.setSshHost(sshHost);
}
if (sshPort != "-1" && sshPort != "") {
sshC.setSshPort(sshPort);
}
if (sshuser != null || sshkeyfile != null || sshpassword != null
|| sshkeypassphrase != null) {
SshAuth sshA = sshC.createChild(SshAuth.class);
if (sshuser != null && sshuser != "") {
sshA.setUserName(sshuser);
}
if (sshkeyfile != null && sshkeyfile != "") {
sshA.setKeyfile(sshkeyfile);
}
if (sshpassword != null && sshpassword != "") {
sshA.setPassword(sshpassword);
}
if (sshkeypassphrase != null && sshkeypassphrase != "") {
sshA.setKeyPassphrase(sshkeypassphrase);
}
sshC.setSshAuth(sshA);
}
if (sshC != null) {
newNode.setSshConnector(sshC);
}
}*/
param.getNode().add(newNode);
return newNode;
}
}, domain.getNodes());
}
// create server if it doesn't exist
Server s = domain.getServers().getServer(instanceName);
if (s == null) {
ConfigSupport.apply(new SingleConfigCode<Servers>() {
public Object run(Servers param) throws PropertyVetoException, TransactionFailure {
Server newServer = param.createChild(Server.class);
newServer.setConfigRef(config);
// newServer.setLbWeight(lbWeight);
newServer.setName(instanceName);
newServer.setNodeRef(node);
if (systemProperties != null) {
for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
final String propName = (String) entry.getKey();
final String propValue = (String) entry.getValue();
SystemProperty newSP = newServer.createChild(SystemProperty.class);
// newSP.setDescription(sp.getDescription());
newSP.setName(propName);
newSP.setValue(propValue);
newServer.getSystemProperty().add(newSP);
}
}
param.getServer().add(newServer);
return newServer;
}
}, domain.getServers());
// create server-ref on cluster
Cluster thisCluster = domain.getClusterNamed(clusterName);
if (thisCluster != null) {
ConfigSupport.apply(new SingleConfigCode<Cluster>() {
public Object run(Cluster param) throws PropertyVetoException, TransactionFailure {
ServerRef newServerRef = param.createChild(ServerRef.class);
newServerRef.setRef(instanceName);
newServerRef.setLbEnabled(lbEnabled);
param.getServerRef().add(newServerRef);
return param;
}
}, thisCluster);
}
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("register.instance.failed", "Instance {0} registration failed on {1}", instanceName, server.getName()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
return;
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("register.instance.failed", "Instance {0} registration failed on {1}", instanceName, server.getName()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
}
use of com.sun.enterprise.config.serverbeans.Node in project Payara by payara.
the class NodeAgentConfigUpgrade method postConstruct.
public void postConstruct() {
final NodeAgents nodeAgents = domain.getNodeAgents();
if (nodeAgents == null) {
createDefaultNodeList();
return;
}
final List<NodeAgent> agList = nodeAgents.getNodeAgent();
if (agList.size() == 0) {
createDefaultNodeList();
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<Domain>() {
public Object run(Domain d) throws PropertyVetoException, TransactionFailure {
Nodes nodes = d.createChild(Nodes.class);
Transaction t = Transaction.getTransaction(d);
if (t == null)
return null;
for (NodeAgent na : agList) {
String host = null;
Node node = nodes.createChild(Node.class);
node.setName(na.getName());
node.setType("CONFIG");
JmxConnector jc = na.getJmxConnector();
if (jc != null) {
// get the properties and see if host name is specified
List<Property> agentProp = jc.getProperty();
for (Property p : agentProp) {
String name = p.getName();
if (name.equals("client-hostname")) {
// create the node with a host name
node.setNodeHost(p.getValue());
node.setInstallDir("${com.sun.aas.productRoot}");
}
}
}
nodes.getNode().add(node);
}
// Now add the builtin localhost node
createDefaultNode(d, nodes);
d.setNodes(nodes);
List<Server> serverList = servers.getServer();
if (serverList.size() <= 0)
return null;
for (Server s : serverList) {
s = t.enroll(s);
s.setNodeRef(s.getNodeAgentRef());
s.setNodeAgentRef(null);
}
// remove the node-agent element
// d.getNodeAgents().getNodeAgent().clear();
d.setNodeAgents(null);
return null;
}
}, domain);
} catch (Exception e) {
Logger.getAnonymousLogger().log(Level.SEVERE, "Failure while upgrading node-agent from V2 to V3", e);
throw new RuntimeException(e);
}
}
use of com.sun.enterprise.config.serverbeans.Node in project Payara by payara.
the class NodeAgentConfigUpgrade method createDefaultNode.
private void createDefaultNode(Domain d, Nodes nodes) throws TransactionFailure, PropertyVetoException {
Property domainProp = d.getProperty("administrative.domain.name");
String domainName = domainProp.getValue();
Node node = nodes.createChild(Node.class);
node.setName("localhost" + "-" + domainName);
node.setType("CONFIG");
node.setNodeHost("localhost");
node.setInstallDir("${com.sun.aas.productRoot}");
nodes.getNode().add(node);
}
use of com.sun.enterprise.config.serverbeans.Node in project Payara by payara.
the class PingNodeRemoteCommand method executeInternal.
protected final void executeInternal(AdminCommandContext context) {
ActionReport report = context.getActionReport();
StringBuilder msg = new StringBuilder();
Node theNode = null;
logger = context.getLogger();
NodeUtils nodeUtils = new NodeUtils(habitat, logger);
// Make sure Node is valid
theNode = nodes.getNode(name);
if (theNode == null) {
String m = Strings.get("noSuchNode", name);
logger.warning(m);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(m);
return;
}
String err = validateSubType(theNode);
if (err != null) {
logger.warning(err);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(err);
return;
}
try {
String version = "";
if (validate) {
// Validates all parameters
nodeUtils.validate(theNode);
version = Strings.get("ping.glassfish.version", theNode.getInstallDir(), nodeUtils.getGlassFishVersionOnNode(theNode, context));
} else {
// Just does a basic connection check
nodeUtils.pingRemoteConnection(theNode);
}
String m1 = Strings.get("ping.node.success", name, theNode.getNodeHost(), theNode.getType());
if (StringUtils.ok(version)) {
m1 = m1 + NL + version;
}
report.setMessage(m1);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (CommandValidationException e) {
String m1 = Strings.get("ping.node.failure", name, theNode.getNodeHost(), theNode.getType());
msg.append(StringUtils.cat(NL, m1, e.getMessage()));
report.setMessage(msg.toString());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
use of com.sun.enterprise.config.serverbeans.Node in project Payara by payara.
the class RestartInstanceCommand method synchronizeInstance.
private void synchronizeInstance() {
NodeUtils nodeUtils = new NodeUtils(habitat, logger);
ArrayList<String> command = new ArrayList<>();
String humanCommand;
command.add("_synchronize-instance");
if (sync != null) {
command.add("--sync");
command.add(sync);
}
if (instanceName != null) {
command.add(instanceName);
}
// Convert the command into a string representing the command a human should run.
humanCommand = makeCommandHuman(command);
String noderef = instance.getNodeRef();
String msg;
String nodeHost;
Node node = nodes.getNode(noderef);
if (node != null) {
nodeHost = node.getNodeHost();
} else {
msg = Strings.get("missingNode", noderef);
logger.severe(msg);
report.setMessage(msg);
return;
}
// First error message displayed if we fail
String firstErrorMessage = Strings.get("restart.instance.syncFailed", instanceName, noderef, nodeHost);
StringBuilder output = new StringBuilder();
// There is a problem on Windows waiting for IO to complete on a
// child process which runs a long running grandchild. See IT 12777.
boolean waitForReaderThreads = true;
if (OS.isWindows()) {
waitForReaderThreads = false;
}
// Run the command on the node and handle errors.
nodeUtils.runAdminCommandOnNode(node, command, context, firstErrorMessage, humanCommand, output, waitForReaderThreads);
if (report.getActionExitCode() == ActionReport.ExitCode.SUCCESS) {
// If it was successful say so and display the command output
msg = Strings.get("restart.instance.success", instanceName);
report.setMessage(msg);
}
}
Aggregations