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);
}
}
use of com.sun.enterprise.config.serverbeans.Node 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(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(FAILURE);
report.setMessage(msg);
return;
}
CommandInvocation commandInvocation = commandRunner.getCommandInvocation("_delete-node", report, context.getSubject());
ParameterMap commandParameters = new ParameterMap();
commandParameters.add("DEFAULT", name);
commandInvocation.parameters(commandParameters);
commandInvocation.execute();
}
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);
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.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.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>() {
@Override
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);
} 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);
}
}
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 NodeAgentConfigUpgrade method postConstruct.
@Override
public void postConstruct() {
final NodeAgents nodeAgents = domain.getNodeAgents();
if (nodeAgents == null) {
createDefaultNodeList();
return;
}
final List<NodeAgent> agList = nodeAgents.getNodeAgent();
if (agList.isEmpty()) {
createDefaultNodeList();
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<Domain>() {
@Override
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.isEmpty())
return null;
for (Server s : serverList) {
s = t.enroll(s);
s.setNodeRef(s.getNodeAgentRef());
s.setNodeAgentRef(null);
}
// remove the node-agent element by setting to null
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);
}
}
Aggregations