Search in sources :

Example 16 with ServerRef

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;
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) Node(com.sun.enterprise.config.serverbeans.Node) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) Servers(com.sun.enterprise.config.serverbeans.Servers) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) Nodes(com.sun.enterprise.config.serverbeans.Nodes) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Aggregations

ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)16 LbConfig (org.glassfish.loadbalancer.config.LbConfig)7 ClusterRef (com.sun.enterprise.config.serverbeans.ClusterRef)6 Cluster (com.sun.enterprise.config.serverbeans.Cluster)5 Server (com.sun.enterprise.config.serverbeans.Server)4 ActionReport (org.glassfish.api.ActionReport)4 LbConfigs (org.glassfish.loadbalancer.config.LbConfigs)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3 Node (com.sun.enterprise.config.serverbeans.Node)2 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)2 PropertyVetoException (java.beans.PropertyVetoException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Logger (java.util.logging.Logger)2 Test (org.junit.Test)2 ConfigBean (org.jvnet.hk2.config.ConfigBean)2 ConfigSupport (org.jvnet.hk2.config.ConfigSupport)2 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 HealthChecker (com.sun.enterprise.config.serverbeans.HealthChecker)1 Nodes (com.sun.enterprise.config.serverbeans.Nodes)1