Search in sources :

Example 1 with InstanceReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader 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 InstanceReader

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

the class InstanceVisitor 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 InstanceReader) {
        InstanceReader iRdr = (InstanceReader) br;
        _c.setInstanceName(_i, iRdr.getName());
        _c.setInstanceEnabled(_i, "" + iRdr.getLbEnabled());
        _c.setInstanceDisableTimeoutInMinutes(_i, iRdr.getDisableTimeoutInMinutes());
        _c.setInstanceListeners(_i, iRdr.getListeners());
        _c.setInstanceWeight(_i, iRdr.getWeight());
    }
}
Also used : InstanceReader(org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader)

Example 3 with InstanceReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader 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 4 with InstanceReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader 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

InstanceReader (org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader)4 ClusterReader (org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader)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 LoadbalancerVisitor (org.glassfish.loadbalancer.admin.cli.transform.LoadbalancerVisitor)2 WebModule (org.glassfish.loadbalancer.admin.cli.beans.WebModule)1 HealthCheckerReader (org.glassfish.loadbalancer.admin.cli.reader.api.HealthCheckerReader)1