use of com.sun.enterprise.config.serverbeans.ServerRef 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;
}
}
Aggregations