Search in sources :

Example 1 with Servers

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

the class IiopFolbGmsClient method getClusterInstanceInfo.

// For addMember.
private ClusterInstanceInfo getClusterInstanceInfo(String instanceName) {
    fineLog("getClusterInstanceInfo: instanceName {0}", instanceName);
    final Servers servers = services.getService(Servers.class);
    fineLog("getClusterInstanceInfo: servers {0}", servers);
    final Server server = servers.getServer(instanceName);
    fineLog("getClusterInstanceInfo: server {0}", server);
    final Config config = getConfigForServer(server);
    fineLog("getClusterInstanceInfo: servers {0}", servers);
    // assumeInstanceIsRunning is set to true since this is
    // coming from addMember, because shoal just told us that the instance is up.
    ClusterInstanceInfo result = getClusterInstanceInfo(server, config, true);
    fineLog("getClusterInstanceInfo: result {0}", result);
    return result;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) Servers(com.sun.enterprise.config.serverbeans.Servers) ClusterInstanceInfo(com.sun.corba.ee.spi.folb.ClusterInstanceInfo)

Example 2 with Servers

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

the class AMXJ2EEStartupService method addListenerToServer.

private void addListenerToServer() {
    Servers servers = domain.getServers();
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl((ConfigBeanProxy) servers);
    bean.addListener(this);
}
Also used : Servers(com.sun.enterprise.config.serverbeans.Servers)

Example 3 with Servers

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

the class CreateJavaMailResourceTest method testExecuteSuccess.

/**
 * Test of execute method, of class CreateJavaMailResource.
 * asadmin create-javamail-resource --mailuser=test --mailhost=localhost
 * --fromaddress=test@sun.com mail/MyMailSession
 */
@Test
public void testExecuteSuccess() {
    parameters.set("mailhost", "localhost");
    parameters.set("mailuser", "test");
    parameters.set("fromaddress", "test@sun.com");
    parameters.set("jndi_name", "mail/MyMailSession");
    org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
    assertTrue(command != null);
    cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    boolean isCreated = false;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof MailResource) {
            MailResource r = (MailResource) resource;
            if (r.getJndiName().equals("mail/MyMailSession")) {
                assertEquals("localhost", r.getHost());
                assertEquals("test", r.getUser());
                assertEquals("test@sun.com", r.getFrom());
                assertEquals("true", r.getEnabled());
                assertEquals("false", r.getDebug());
                assertEquals("imap", r.getStoreProtocol());
                assertEquals("com.sun.mail.imap.IMAPStore", r.getStoreProtocolClass());
                assertEquals("smtp", r.getTransportProtocol());
                assertEquals("com.sun.mail.smtp.SMTPTransport", r.getTransportProtocolClass());
                isCreated = true;
                logger.fine("MailResource config bean mail/MyMailSession is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    logger.fine("msg: " + context.getActionReport().getMessage());
    Servers servers = habitat.getService(Servers.class);
    boolean isRefCreated = false;
    for (Server server : servers.getServer()) {
        if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            for (ResourceRef ref : server.getResourceRef()) {
                if (ref.getRef().equals("mail/MyMailSession")) {
                    assertEquals("true", ref.getEnabled());
                    isRefCreated = true;
                    break;
                }
            }
        }
    }
    assertTrue(isRefCreated);
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) MailResource(org.glassfish.resources.javamail.config.MailResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) Servers(com.sun.enterprise.config.serverbeans.Servers) MailResource(org.glassfish.resources.javamail.config.MailResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 4 with Servers

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

Example 5 with Servers

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

the class ConfigRefValidator method isValid.

@Override
public boolean isValid(final Named bean, final ConstraintValidatorContext constraintValidatorContext) {
    if (bean == null)
        return true;
    Server server = null;
    Cluster mycluster = null;
    String configRef = null;
    String serverName = null;
    if (bean instanceof Server) {
        server = (Server) bean;
        configRef = server.getConfigRef();
        serverName = server.getName();
    } else if (bean instanceof Cluster) {
        mycluster = (Cluster) bean;
        configRef = mycluster.getConfigRef();
        serverName = mycluster.getName();
    }
    // skip validation @NotNull is already on getConfigRef
    if (configRef == null)
        return true;
    // cannot use default-config
    if (configRef.equals(SystemPropertyConstants.TEMPLATE_CONFIG_NAME)) {
        logger.warning(ConfigApiLoggerInfo.configRefDefaultconfig);
        return false;
    }
    // cannot change config-ref of DAS
    if (server != null) {
        if (server.isDas() && !configRef.equals(SystemPropertyConstants.DAS_SERVER_CONFIG)) {
            logger.warning(ConfigApiLoggerInfo.configRefDASconfig);
            return false;
        }
        // cannot use server-config if not DAS
        if (!server.isDas() && configRef.equals(SystemPropertyConstants.DAS_SERVER_CONFIG)) {
            logger.warning(ConfigApiLoggerInfo.configRefServerconfig);
            return false;
        }
        final Servers servers = server.getParent(Servers.class);
        final Domain domain = servers.getParent(Domain.class);
        final Configs configs = domain.getConfigs();
        if (servers.getServer(serverName) != null) {
            // validate for set, not _register-instance
            // cannot change config ref of a clustered instance
            Cluster cluster = domain.getClusterForInstance(serverName);
            if (cluster != null) {
                // cluster is not null during create-local-instance --cluster c1 i1
                if (!cluster.getConfigRef().equals(configRef)) {
                    // During set when trying to change config-ref of a clustered instance,
                    // the value of desired config-ref will be different than the current config-ref.
                    // During _register-instance, (create-local-instance --cluster c1 i1)
                    // cluster.getConfigRef().equals(configRef) will be true and not come here.
                    logger.warning(ConfigApiLoggerInfo.configRefClusteredInstance);
                    return false;
                }
            }
            // cannot use a non-existent config  (Only used by set.  _register-instance will fail earlier)
            if (configs == null || configs.getConfigByName(configRef) == null) {
                logger.warning(ConfigApiLoggerInfo.configRefNonexistent);
                return false;
            }
        }
    }
    return true;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Configs(com.sun.enterprise.config.serverbeans.Configs) Cluster(com.sun.enterprise.config.serverbeans.Cluster) Servers(com.sun.enterprise.config.serverbeans.Servers) Domain(com.sun.enterprise.config.serverbeans.Domain)

Aggregations

Servers (com.sun.enterprise.config.serverbeans.Servers)5 Server (com.sun.enterprise.config.serverbeans.Server)4 Cluster (com.sun.enterprise.config.serverbeans.Cluster)2 ClusterInstanceInfo (com.sun.corba.ee.spi.folb.ClusterInstanceInfo)1 Config (com.sun.enterprise.config.serverbeans.Config)1 Configs (com.sun.enterprise.config.serverbeans.Configs)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 Node (com.sun.enterprise.config.serverbeans.Node)1 Nodes (com.sun.enterprise.config.serverbeans.Nodes)1 Resource (com.sun.enterprise.config.serverbeans.Resource)1 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)1 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)1 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 PropertyVetoException (java.beans.PropertyVetoException)1 ActionReport (org.glassfish.api.ActionReport)1 MailResource (org.glassfish.resources.javamail.config.MailResource)1 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)1 Test (org.junit.Test)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1