Search in sources :

Example 1 with ClusterReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader in project Payara by payara.

the class ClusterVisitor method visit.

/**
 * Visit reader class
 */
@Override
public void visit(BaseReader br) throws Exception {
    // FIXME, make as assert here about no class cast exception
    if (br instanceof ClusterReader) {
        ClusterReader cRdr = (ClusterReader) br;
        _c.setName(cRdr.getName());
        _c.setPolicy(cRdr.getLbPolicy());
        _c.setPolicyModule(cRdr.getLbPolicyModule());
        InstanceReader[] iRdrs = null;
        iRdrs = cRdr.getInstances();
        if ((iRdrs != null) && (iRdrs.length > 0)) {
            boolean[] values = new boolean[iRdrs.length];
            // XXX check if setting to true is required and is ok.
            for (int i = 0; i < iRdrs.length; i++) {
                values[i] = true;
            }
            _c.setInstance(values);
            for (int i = 0; i < iRdrs.length; i++) {
                iRdrs[i].accept(new InstanceVisitor(_c, i));
            }
        }
        HealthCheckerReader hcRdr = cRdr.getHealthChecker();
        if (hcRdr != null) {
            hcRdr.accept(new HealthCheckerVisitor(_c));
        }
        WebModuleReader[] wRdrs = cRdr.getWebModules();
        if ((wRdrs != null) && (wRdrs.length > 0)) {
            WebModule[] wMods = new WebModule[wRdrs.length];
            for (int i = 0; i < wRdrs.length; i++) {
                wMods[i] = new WebModule();
                wRdrs[i].accept(new WebModuleVisitor(wMods[i], _c));
            }
            _c.setWebModule(wMods);
        }
    }
}
Also used : HealthCheckerReader(org.glassfish.loadbalancer.admin.cli.reader.api.HealthCheckerReader) WebModuleReader(org.glassfish.loadbalancer.admin.cli.reader.api.WebModuleReader) WebModule(org.glassfish.loadbalancer.admin.cli.beans.WebModule) InstanceReader(org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader) ClusterReader(org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader)

Example 2 with ClusterReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader in project Payara by payara.

the class LoadbalancerVisitor method visit.

/**
 * Visit reader class
 */
@Override
public void visit(BaseReader br) throws Exception {
    // FIXME, make as assert here about no class cast exception
    if (br instanceof LoadbalancerReader) {
        LoadbalancerReader lbRdr = (LoadbalancerReader) br;
        PropertyReader[] pRdrs = lbRdr.getProperties();
        if ((pRdrs != null) && (pRdrs.length > 0)) {
            Property[] props = new Property[pRdrs.length];
            for (int i = 0; i < pRdrs.length; i++) {
                props[i] = new Property();
                pRdrs[i].accept(new PropertyVisitor(props[i]));
            }
            _lb.setProperty2(props);
        }
        ClusterReader[] cRdrs = lbRdr.getClusters();
        if ((cRdrs != null) && (cRdrs.length > 0)) {
            Cluster[] cls = new Cluster[cRdrs.length];
            for (int i = 0; i < cRdrs.length; i++) {
                cls[i] = new Cluster();
                cRdrs[i].accept(new ClusterVisitor(cls[i]));
            }
            _lb.setCluster(cls);
        }
    }
}
Also used : ClusterReader(org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader) Cluster(org.glassfish.loadbalancer.admin.cli.beans.Cluster) LoadbalancerReader(org.glassfish.loadbalancer.admin.cli.reader.api.LoadbalancerReader) PropertyReader(org.glassfish.loadbalancer.admin.cli.reader.api.PropertyReader) Property(org.glassfish.loadbalancer.admin.cli.beans.Property)

Example 3 with ClusterReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader in project Payara by payara.

the class LoadbalancerReaderImpl method getClustersData.

public ClusterReader[] getClustersData() throws LbReaderException {
    ClusterReader[] cls = new ClusterReader[_clusters.size()];
    Iterator<String> iter = _clusters.iterator();
    int i = 0;
    boolean isFirstServer = false;
    while (iter.hasNext()) {
        String name = iter.next();
        boolean isServer = _domain.isServer(name);
        if (i == 0) {
            isFirstServer = isServer;
        } else {
            // Mix of standalone instances and clusters is not allowed
            if (isFirstServer ^ isServer) {
                String msg = LbLogUtil.getStringManager().getString("MixofServerAndClusterNotSupported");
                throw new LbReaderException(msg);
            }
        }
        if (isServer) {
            Server server = _domain.getServerNamed(name);
            // An instance within cluster is not allowed
            if (server.getCluster() != null) {
                String msg = LbLogUtil.getStringManager().getString("ServerPartofClusterNotSupported", name);
                throw new LbReaderException(msg);
            }
            cls[i++] = new StandAloneClusterReaderImpl(_domain, _appRegistry, server);
        } else {
            Cluster cluster = _domain.getClusterNamed(name);
            if (cluster == null) {
                String msg = LbLogUtil.getStringManager().getString("ClusterorInstanceNotFound", name);
                throw new LbReaderException(msg);
            }
            cls[i++] = new ClusterReaderImpl(_domain, _appRegistry, cluster);
        }
    }
    return cls;
}
Also used : ClusterReader(org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader) Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)

Example 4 with ClusterReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader in project Payara by payara.

the class LbConfigHelper method exportOtdProperties.

/**
 * exports the otd.properties from the config to the outputstream provided
 * @param ctx ConfigContext
 * @param lbConfigName name of lb-config
 */
public static void exportOtdProperties(LoadbalancerReader lbRdr, OutputStream out) throws Exception {
    // tranform the data using visitor pattern
    Loadbalancer _lb = new Loadbalancer();
    Properties props = new Properties();
    String CLUSTER = "cluster";
    String LISTENER = "listeners";
    String WEB = "web-modules";
    String SEPARATOR = ".";
    StringBuilder buffer = new StringBuilder();
    LoadbalancerVisitor lbVstr = new LoadbalancerVisitor(_lb);
    lbRdr.accept(lbVstr);
    ClusterReader[] clusterReaders = lbRdr.getClusters();
    buffer.append("otd.properties");
    for (int i = 0; i < clusterReaders.length; i++) {
        StringBuilder clusterHostList = new StringBuilder();
        String clusterWebList = "";
        ClusterReader clusterReader = clusterReaders[i];
        String clusterName = clusterReader.getName();
        WebModuleReader[] webmoduleReaders = clusterReader.getWebModules();
        InstanceReader[] instanceReaders = clusterReader.getInstances();
        for (int j = 0; j < instanceReaders.length; j++) {
            InstanceReader instanceReader = instanceReaders[j];
            String listenerHost = "";
            String listenerPort = "";
            StringTokenizer st = new StringTokenizer(instanceReader.getListeners(), " ");
            while (st.hasMoreElements()) {
                String listener = st.nextToken();
                if (listener.contains("http://")) {
                    listenerHost = listener.substring(listener.lastIndexOf('/') + 1, listener.lastIndexOf(':'));
                    listenerPort = listener.substring(listener.lastIndexOf(':') + 1, listener.length());
                    break;
                }
            }
            clusterHostList = clusterHostList.append(j > 0 ? "," : "").append(listenerHost).append(":").append(listenerPort);
        }
        props.setProperty(CLUSTER + SEPARATOR + clusterName + SEPARATOR + LISTENER, clusterHostList.toString());
        for (int m = 0; m < webmoduleReaders.length; m++) {
            clusterWebList = clusterWebList + (m > 0 ? "," : "") + webmoduleReaders[m].getContextRoot();
        }
        props.setProperty(CLUSTER + SEPARATOR + clusterName + SEPARATOR + WEB, clusterWebList);
    }
    try {
        props.store(out, buffer.toString());
    } finally {
        if (out != null) {
            out.close();
            out = null;
        }
    }
}
Also used : WebModuleReader(org.glassfish.loadbalancer.admin.cli.reader.api.WebModuleReader) Loadbalancer(org.glassfish.loadbalancer.admin.cli.beans.Loadbalancer) Properties(java.util.Properties) InstanceReader(org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader) StringTokenizer(java.util.StringTokenizer) ClusterReader(org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader) LoadbalancerVisitor(org.glassfish.loadbalancer.admin.cli.transform.LoadbalancerVisitor)

Example 5 with ClusterReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader in project Payara by payara.

the class LbConfigHelper method exportWorkerProperties.

/**
 * exports the workser.properties from the config to the outputstream provided
 * @param ctx ConfigContext
 * @param lbConfigName name of lb-config
 * @param out OutputStream into which the loadbalancer.xml is written
 */
public static void exportWorkerProperties(LoadbalancerReader lbRdr, OutputStream out) throws Exception {
    // tranform the data using visitor pattern
    Loadbalancer _lb = new Loadbalancer();
    Properties props = new Properties();
    String WORKER = "worker";
    String SEPARATOR = ".";
    String HOST = "host";
    String PORT = "port";
    String LIST = "list";
    String TYPE = "type";
    String TYPE_VALUE = "ajp13";
    String LBFACTOR = "lbfactor";
    String LBFACTOR_VALUE = "1";
    String SOCKET_KEEPALIVE = "socket_keepalive";
    String SOCKET_TIMEOUT = "socket_timeout";
    String SOCKET_KEEPALIVE_VALUE = "1";
    String SOCKET_TIMEOUT_VALUE = "300";
    String LOADBALANCER = "-lb";
    String BALANCER_WORKERS = "balance_workers";
    String LB = "lb";
    String CONTEXT_ROOT_MAPPING = "CONTEXT_ROOT_MAPPING";
    String APP = "APP";
    StringBuilder buffer = new StringBuilder();
    String workerList = "";
    LoadbalancerVisitor lbVstr = new LoadbalancerVisitor(_lb);
    lbRdr.accept(lbVstr);
    ClusterReader[] clusterReaders = lbRdr.getClusters();
    int c;
    buffer.append("worker.properties");
    for (int i = 0; i < clusterReaders.length; i++) {
        String clusterWorkerList = "";
        ClusterReader clusterReader = clusterReaders[i];
        String clusterName = clusterReader.getName();
        WebModuleReader[] webmoduleReaders = clusterReader.getWebModules();
        InstanceReader[] instanceReaders = clusterReader.getInstances();
        for (int j = 0; j < instanceReaders.length; j++) {
            InstanceReader instanceReader = instanceReaders[j];
            String listenerHost = "";
            String listenerPort = "";
            StringTokenizer st = new StringTokenizer(instanceReader.getListeners(), " ");
            while (st.hasMoreElements()) {
                String listener = st.nextToken();
                if (listener.contains("ajp://")) {
                    listenerHost = listener.substring(listener.lastIndexOf('/') + 1, listener.lastIndexOf(':'));
                    listenerPort = listener.substring(listener.lastIndexOf(':') + 1, listener.length());
                    break;
                }
            }
            String listenterName = instanceReader.getName();
            props.setProperty(WORKER + SEPARATOR + listenterName + SEPARATOR + HOST, listenerHost);
            props.setProperty(WORKER + SEPARATOR + listenterName + SEPARATOR + PORT, listenerPort);
            props.setProperty(WORKER + SEPARATOR + listenterName + SEPARATOR + TYPE, TYPE_VALUE);
            props.setProperty(WORKER + SEPARATOR + listenterName + SEPARATOR + LBFACTOR, LBFACTOR_VALUE);
            props.setProperty(WORKER + SEPARATOR + listenterName + SEPARATOR + SOCKET_KEEPALIVE, SOCKET_KEEPALIVE_VALUE);
            props.setProperty(WORKER + SEPARATOR + listenterName + SEPARATOR + SOCKET_TIMEOUT, SOCKET_TIMEOUT_VALUE);
            workerList = workerList + listenterName + ",";
            clusterWorkerList = clusterWorkerList + listenterName + ",";
        }
        workerList = workerList + clusterName + LOADBALANCER + ",";
        props.setProperty(WORKER + SEPARATOR + LIST, workerList.substring(0, workerList.length() - 1));
        props.setProperty(WORKER + SEPARATOR + clusterName + LOADBALANCER + SEPARATOR + TYPE, LB);
        props.setProperty(WORKER + SEPARATOR + clusterName + LOADBALANCER + SEPARATOR + BALANCER_WORKERS, clusterWorkerList.substring(0, clusterWorkerList.length() - 1));
        for (int m = 0; m < webmoduleReaders.length; m++) {
            buffer.append("\n" + CONTEXT_ROOT_MAPPING + SEPARATOR + webmoduleReaders[m].getContextRoot() + "=" + clusterName + LOADBALANCER);
        }
    }
    try {
        props.store(out, buffer.toString());
    } finally {
        if (out != null) {
            out.close();
            out = null;
        }
    }
}
Also used : WebModuleReader(org.glassfish.loadbalancer.admin.cli.reader.api.WebModuleReader) Loadbalancer(org.glassfish.loadbalancer.admin.cli.beans.Loadbalancer) Properties(java.util.Properties) InstanceReader(org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader) StringTokenizer(java.util.StringTokenizer) ClusterReader(org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader) LoadbalancerVisitor(org.glassfish.loadbalancer.admin.cli.transform.LoadbalancerVisitor)

Aggregations

ClusterReader (org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader)6 InstanceReader (org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader)3 WebModuleReader (org.glassfish.loadbalancer.admin.cli.reader.api.WebModuleReader)3 Properties (java.util.Properties)2 StringTokenizer (java.util.StringTokenizer)2 Loadbalancer (org.glassfish.loadbalancer.admin.cli.beans.Loadbalancer)2 LbReaderException (org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)2 LoadbalancerVisitor (org.glassfish.loadbalancer.admin.cli.transform.LoadbalancerVisitor)2 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 ClusterRef (com.sun.enterprise.config.serverbeans.ClusterRef)1 Ref (com.sun.enterprise.config.serverbeans.Ref)1 Server (com.sun.enterprise.config.serverbeans.Server)1 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)1 Cluster (org.glassfish.loadbalancer.admin.cli.beans.Cluster)1 Property (org.glassfish.loadbalancer.admin.cli.beans.Property)1 WebModule (org.glassfish.loadbalancer.admin.cli.beans.WebModule)1 HealthCheckerReader (org.glassfish.loadbalancer.admin.cli.reader.api.HealthCheckerReader)1 LoadbalancerReader (org.glassfish.loadbalancer.admin.cli.reader.api.LoadbalancerReader)1 PropertyReader (org.glassfish.loadbalancer.admin.cli.reader.api.PropertyReader)1