Search in sources :

Example 6 with ServerRef

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

the class LBCommandsBase method updateLBForCluster.

void updateLBForCluster(ActionReport report, String clusterName, String value, String timeout) {
    Cluster c = domain.getClusterNamed(clusterName);
    if (c == null) {
        report.setMessage("Cluster not defined");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    for (ServerRef sRef : c.getServerRef()) {
        try {
            updateLbEnabled(sRef, value, timeout);
        } catch (TransactionFailure ex) {
            report.setMessage("Failed to update lb-enabled");
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
}
Also used : Cluster(com.sun.enterprise.config.serverbeans.Cluster) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 7 with ServerRef

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

the class GMSAdapterImpl method generateDiscoveryUriList.

/*
     * Get existing nodes based on cluster element in domain.
     * Then check for DAS address in das.properties. When the
     * list is set to 'generate' then the gms listener port
     * must also be specified. So the same port is used for
     * each cluster member.
     */
private String generateDiscoveryUriList() {
    String clusterPort = null;
    Property gmsPortProp = cluster.getProperty("GMS_LISTENER_PORT");
    if (gmsPortProp == null || gmsPortProp.getValue() == null || gmsPortProp.getValue().trim().charAt(0) == '$') {
        clusterPort = "9090";
        GMS_LOGGER.log(LogLevel.WARNING, GMS_LISTENER_PORT_REQUIRED, new Object[] { cluster.getName(), clusterPort });
    } else {
        clusterPort = gmsPortProp.getValue();
        if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
            GMS_LOGGER.log(LogLevel.FINE, "will use gms listener port: " + clusterPort);
        }
    }
    // get cluster member server refs
    Set<String> instanceNames = new HashSet<String>();
    if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
        GMS_LOGGER.log(LogLevel.FINE, String.format("checking cluster.getServerRef() for '%s'", cluster.getName()));
    }
    for (ServerRef sRef : cluster.getServerRef()) {
        /*
             * When an instance (not DAS) starts up, it will add
             * its own address to the discovery list. This is ok
             * now. If we want to skip it, here's the place to
             * check.
             */
        if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
            GMS_LOGGER.log(LogLevel.FINE, String.format("adding server ref %s to set of instance names", sRef.getRef()));
        }
        instanceNames.add(sRef.getRef());
    }
    StringBuilder sb = new StringBuilder();
    final String SEP = ",";
    final String scheme = "tcp://";
    // use server refs to find matching nodes
    for (String name : instanceNames) {
        Server server = servers.getServer(name);
        if (server != null) {
            if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
                GMS_LOGGER.log(LogLevel.FINE, String.format("found server for name %s", name));
            }
            Node node = nodes.getNode(server.getNodeRef());
            if (node != null) {
                String host = scheme + node.getNodeHost() + ":" + clusterPort;
                if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
                    GMS_LOGGER.log(LogLevel.FINE, String.format("Adding host '%s' to discovery list", host));
                }
                sb.append(host).append(SEP);
            }
        }
    }
    // add das location from das.properties if needed
    if (server.isInstance()) {
        try {
            ServerDirs sDirs = new ServerDirs(env.getInstanceRoot());
            File dasPropsFile = sDirs.getDasPropertiesFile();
            if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
                GMS_LOGGER.log(LogLevel.FINE, String.format("found das.props file at %s", dasPropsFile.getAbsolutePath()));
            }
            Properties dasProps = getProperties(dasPropsFile);
            String host = scheme + dasProps.getProperty("agent.das.host") + ":" + clusterPort;
            if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
                GMS_LOGGER.log(LogLevel.FINE, String.format("adding '%s' from das.props file", host));
            }
            sb.append(host).append(SEP);
        } catch (IOException ioe) {
            GMS_LOGGER.log(LogLevel.WARNING, ioe.toString());
        }
    }
    // trim list if needed and return
    int lastCommaIndex = sb.lastIndexOf(SEP);
    if (lastCommaIndex != -1) {
        sb.deleteCharAt(lastCommaIndex);
    }
    if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
        GMS_LOGGER.log(LogLevel.FINE, String.format("returning discovery list '%s'", sb.toString()));
    }
    return sb.toString();
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Node(com.sun.enterprise.config.serverbeans.Node) IOException(java.io.IOException) Properties(java.util.Properties) ServerDirs(com.sun.enterprise.util.io.ServerDirs) Property(org.jvnet.hk2.config.types.Property) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) File(java.io.File) HashSet(java.util.HashSet)

Example 8 with ServerRef

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

the class ReferenceConstrainClusterTest method clusterServerRefInvalid.

@Test
public void clusterServerRefInvalid() throws TransactionFailure {
    Cluster cluster = habitat.getService(Cluster.class, "clusterA");
    assertNotNull(cluster);
    ServerRef sref = cluster.getServerRef().get(0);
    ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("ref", "server-nonexist");
    changes.put(serverConfig, configChanges);
    try {
        ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
        cs.apply(changes);
        fail("Can not reach this point");
    } catch (TransactionFailure tf) {
        ConstraintViolationException cv = findConstrViolation(tf);
        assertNotNull(cv);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ConstraintViolationException(javax.validation.ConstraintViolationException) ConfigBean(org.jvnet.hk2.config.ConfigBean) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) HashMap(java.util.HashMap) Map(java.util.Map) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 9 with ServerRef

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

the class ReferenceConstrainClusterTest method clusterServerRefValid.

@Test
public void clusterServerRefValid() throws TransactionFailure {
    Cluster cluster = habitat.getService(Cluster.class, "clusterA");
    assertNotNull(cluster);
    ServerRef sref = cluster.getServerRef().get(0);
    ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("ref", "server");
    changes.put(serverConfig, configChanges);
    try {
        ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
        cs.apply(changes);
    } catch (TransactionFailure tf) {
        fail("Can not reach this point");
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ConfigBean(org.jvnet.hk2.config.ConfigBean) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) HashMap(java.util.HashMap) Map(java.util.Map) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 10 with ServerRef

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

the class HealthHistory method changed.

@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    Object oldVal;
    Object newVal;
    for (PropertyChangeEvent event : events) {
        oldVal = event.getOldValue();
        newVal = event.getNewValue();
        if (oldVal instanceof ServerRef && newVal == null) {
            ServerRef instance = (ServerRef) oldVal;
            deleteInstance(instance.getRef());
        } else if (newVal instanceof ServerRef && oldVal == null) {
            ServerRef instance = (ServerRef) newVal;
            addInstance(instance.getRef());
        }
    }
    return null;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) 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