Search in sources :

Example 91 with Server

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

Example 92 with Server

use of com.sun.enterprise.config.serverbeans.Server 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);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) Node(com.sun.enterprise.config.serverbeans.Node) NodeAgent(com.sun.enterprise.config.serverbeans.NodeAgent) JmxConnector(com.sun.enterprise.config.serverbeans.JmxConnector) NodeAgents(com.sun.enterprise.config.serverbeans.NodeAgents) Nodes(com.sun.enterprise.config.serverbeans.Nodes) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) Domain(com.sun.enterprise.config.serverbeans.Domain) Property(org.jvnet.hk2.config.types.Property)

Example 93 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class CLIUtil method chooseRefContainer.

static RefContainer chooseRefContainer(final Domain domain, final String target, final ConfigBeansUtilities configBeansUtilities) {
    Config config = domain.getConfigs().getConfigByName(target);
    if (config != null) {
        return config;
    }
    Server server = configBeansUtilities.getServerNamed(target);
    if (server != null) {
        return server;
    }
    Cluster cluster = domain.getClusterNamed(target);
    if (cluster != null) {
        return cluster;
    }
    return domain.getDeploymentGroupNamed(target);
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Example 94 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class PostRegisterInstanceCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    final InstanceRegisterInstanceCommandParameters suppInfo = context.getActionReport().getResultType(InstanceRegisterInstanceCommandParameters.class);
    if (suppInfo != null && clusterName != null) {
        try {
            ParameterMapExtractor pme = new ParameterMapExtractor(suppInfo, this);
            final ParameterMap paramMap = pme.extract();
            List<String> targets = new ArrayList<String>();
            List<Server> instances = target.getInstances(this.clusterName);
            for (Server s : instances) {
                targets.add(s.getName());
            }
            ClusterOperationUtil.replicateCommand("_register-instance-at-instance", FailurePolicy.Warn, FailurePolicy.Warn, FailurePolicy.Ignore, targets, context, paramMap, habitat);
        } catch (Exception e) {
            report.failure(logger, e.getMessage());
        }
    }
}
Also used : InstanceRegisterInstanceCommandParameters(com.sun.enterprise.config.util.InstanceRegisterInstanceCommandParameters) ParameterMapExtractor(org.glassfish.common.util.admin.ParameterMapExtractor) Server(com.sun.enterprise.config.serverbeans.Server) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger)

Example 95 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class AddInstanceToDeploymentGroupCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    DeploymentGroup deploymentGroup = domain.getDeploymentGroupNamed(deploymentGroupName);
    if (deploymentGroup == null && env.isDas()) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage("Deployment Group " + deploymentGroup + " does not exist");
        return;
    }
    List<String> instances = Arrays.asList(instanceName.split(","));
    for (String instance : instances) {
        Server server = domain.getServerNamed(instance);
        if (server == null && env.isDas()) {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage("Instance " + instance + " does not exist");
            return;
        }
        // OK set up the reference
        try {
            ConfigSupport.apply((DeploymentGroup dg1) -> {
                DGServerRef deploymentGroupServerRef = dg1.createChild(DGServerRef.class);
                deploymentGroupServerRef.setRef(instance);
                dg1.getDGServerRef().add(deploymentGroupServerRef);
                return deploymentGroupServerRef;
            }, deploymentGroup);
        } catch (TransactionFailure e) {
            report.setMessage("Failed to add instance to deployment group");
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
        }
        // now run the command to add application ref to the instance
        for (ApplicationRef applicationRef : deploymentGroup.getApplicationRef()) {
            CommandInvocation inv = commandRunner.getCommandInvocation("create-application-ref", report, context.getSubject());
            ParameterMap parameters = new ParameterMap();
            parameters.add("target", instance);
            parameters.add("name", applicationRef.getRef());
            String virtualServers = applicationRef.getVirtualServers();
            if (virtualServers == null || virtualServers.isEmpty()) {
                virtualServers = getVirtualServers(server);
            }
            parameters.add("virtualservers", virtualServers);
            parameters.add("enabled", applicationRef.getEnabled());
            parameters.add("lbenabled", applicationRef.getLbEnabled());
            inv.parameters(parameters).execute();
        }
        // for all resource refs add resource ref to instance
        for (ResourceRef resourceRef : deploymentGroup.getResourceRef()) {
            CommandInvocation inv = commandRunner.getCommandInvocation("create-resource-ref", report, context.getSubject());
            ParameterMap parameters = new ParameterMap();
            parameters.add("target", instance);
            parameters.add("reference_name", resourceRef.getRef());
            parameters.add("enabled", resourceRef.getEnabled());
            inv.parameters(parameters).execute();
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Server(com.sun.enterprise.config.serverbeans.Server) DGServerRef(fish.payara.enterprise.config.serverbeans.DGServerRef) ParameterMap(org.glassfish.api.admin.ParameterMap) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Aggregations

Server (com.sun.enterprise.config.serverbeans.Server)101 ActionReport (org.glassfish.api.ActionReport)32 Cluster (com.sun.enterprise.config.serverbeans.Cluster)25 Domain (com.sun.enterprise.config.serverbeans.Domain)15 Node (com.sun.enterprise.config.serverbeans.Node)15 Config (com.sun.enterprise.config.serverbeans.Config)14 Properties (java.util.Properties)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 PropertyVetoException (java.beans.PropertyVetoException)11 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)9 ParameterMap (org.glassfish.api.admin.ParameterMap)9 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)8 File (java.io.File)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)8 Logger (java.util.logging.Logger)7 Map (java.util.Map)6 ServerContext (org.glassfish.internal.api.ServerContext)6