Search in sources :

Example 1 with WebModuleReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.WebModuleReader 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 = ".";
    StringBuffer buffer = new StringBuffer();
    LoadbalancerVisitor lbVstr = new LoadbalancerVisitor(_lb);
    lbRdr.accept(lbVstr);
    ClusterReader[] clusterReaders = lbRdr.getClusters();
    buffer.append("otd.properties");
    for (int i = 0; i < clusterReaders.length; i++) {
        StringBuffer clusterHostList = new StringBuffer();
        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 2 with WebModuleReader

use of org.glassfish.loadbalancer.admin.cli.reader.api.WebModuleReader 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";
    StringBuffer buffer = new StringBuffer();
    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)

Example 3 with WebModuleReader

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

the class ClusterReaderHelper method getWebModules.

/**
 * Returns the web module readers for a set of application refs.
 *
 * @param   _configCtx      Current Config context
 * @param   refs            Application ref(s) from cluster or stand alone
 *                          instance
 * @param   target          Name of the cluster or stand alone instance
 *
 * @return  WebModuleReader[]   Array of the corresponding web module
 *                              reader(s).
 *
 * @throws  LbReaderException   In case of any error(s).
 */
public static WebModuleReader[] getWebModules(Domain domain, ApplicationRegistry appRegistry, List<ApplicationRef> refs, String target) {
    List<WebModuleReader> list = new ArrayList<WebModuleReader>();
    Set<String> contextRoots = new HashSet<String>();
    Iterator<ApplicationRef> refAppsIter = refs.iterator();
    HashMap<String, ApplicationRef> refferedApps = new HashMap<String, ApplicationRef>();
    while (refAppsIter.hasNext()) {
        ApplicationRef appRef = refAppsIter.next();
        refferedApps.put(appRef.getRef(), appRef);
    }
    Applications applications = domain.getApplications();
    Set<Application> apps = new HashSet<Application>();
    apps.addAll(applications.getApplicationsWithSnifferType("web"));
    apps.addAll(applications.getApplicationsWithSnifferType("webservices"));
    Iterator<Application> appsIter = apps.iterator();
    while (appsIter.hasNext()) {
        Application app = appsIter.next();
        String appName = app.getName();
        if (!refferedApps.containsKey(appName)) {
            continue;
        }
        ApplicationInfo appInfo = appRegistry.get(appName);
        if (appInfo == null) {
            String msg = LbLogUtil.getStringManager().getString("UnableToGetAppInfo", appName);
            LbLogUtil.getLogger().log(Level.WARNING, msg);
            continue;
        }
        com.sun.enterprise.deployment.Application depApp = appInfo.getMetaData(com.sun.enterprise.deployment.Application.class);
        Iterator<BundleDescriptor> bundleDescriptorIter = depApp.getBundleDescriptors().iterator();
        while (bundleDescriptorIter.hasNext()) {
            BundleDescriptor bundleDescriptor = bundleDescriptorIter.next();
            try {
                if (bundleDescriptor instanceof WebBundleDescriptor) {
                    WebModuleReader wmr = new WebModuleReaderImpl(appName, refferedApps.get(appName), app, (WebBundleDescriptor) bundleDescriptor);
                    if (!contextRoots.contains(wmr.getContextRoot())) {
                        contextRoots.add(wmr.getContextRoot());
                        list.add(wmr);
                    }
                } else if (bundleDescriptor instanceof EjbBundleDescriptor) {
                    EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) bundleDescriptor;
                    if (!ejbBundleDescriptor.hasWebServices()) {
                        continue;
                    }
                    Iterator<WebServiceEndpoint> wsIter = ejbBundleDescriptor.getWebServices().getEndpoints().iterator();
                    while (wsIter.hasNext()) {
                        WebServiceEndpointReaderImpl wsr = new WebServiceEndpointReaderImpl(appName, refferedApps.get(appName), app, wsIter.next());
                        if (!contextRoots.contains(wsr.getContextRoot())) {
                            contextRoots.add(wsr.getContextRoot());
                            list.add(wsr);
                        }
                    }
                }
            } catch (LbReaderException ex) {
                String msg = LbLogUtil.getStringManager().getString("UnableToGetContextRoot", appName, ex.getMessage());
                LbLogUtil.getLogger().log(Level.WARNING, msg);
                if (LbLogUtil.getLogger().isLoggable(Level.FINE)) {
                    LbLogUtil.getLogger().log(Level.FINE, "Exception when getting context root for application", ex);
                }
            }
        }
    }
    contextRoots.clear();
    // returns the web module reader as array
    WebModuleReader[] webModules = new WebModuleReader[list.size()];
    return (WebModuleReader[]) list.toArray(webModules);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) Iterator(java.util.Iterator) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException) HashSet(java.util.HashSet) WebModuleReader(org.glassfish.loadbalancer.admin.cli.reader.api.WebModuleReader) Applications(com.sun.enterprise.config.serverbeans.Applications) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) Application(com.sun.enterprise.config.serverbeans.Application)

Example 4 with WebModuleReader

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

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

the class WebModuleVisitor 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 BaseReader) {
        WebModuleReader wRdr = (WebModuleReader) br;
        _w.setContextRoot(wRdr.getContextRoot());
        String url = wRdr.getErrorUrl();
        if ((url != null) && (!"".equals(url))) {
            // XXX start of bug fix for 6171814
            _c.createAttribute(Cluster.WEB_MODULE, "error-url", "ErrorUrl", AttrProp.CDATA, null, "");
            // XXX end of bug fix for 6171814
            _w.setErrorUrl(wRdr.getErrorUrl());
        }
        _w.setEnabled(Boolean.toString(wRdr.getLbEnabled()));
        _w.setDisableTimeoutInMinutes(wRdr.getDisableTimeoutInMinutes());
        IdempotentUrlPatternReader[] iRdrs = wRdr.getIdempotentUrlPattern();
        if ((iRdrs != null) && (iRdrs.length > 0)) {
            for (int i = 0; i < iRdrs.length; i++) {
                iRdrs[i].accept(new IdempotentUrlPatternVisitor(_w, i));
            }
        }
    }
}
Also used : BaseReader(org.glassfish.loadbalancer.admin.cli.reader.api.BaseReader) WebModuleReader(org.glassfish.loadbalancer.admin.cli.reader.api.WebModuleReader) IdempotentUrlPatternReader(org.glassfish.loadbalancer.admin.cli.reader.api.IdempotentUrlPatternReader)

Aggregations

WebModuleReader (org.glassfish.loadbalancer.admin.cli.reader.api.WebModuleReader)5 ClusterReader (org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader)3 InstanceReader (org.glassfish.loadbalancer.admin.cli.reader.api.InstanceReader)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 Application (com.sun.enterprise.config.serverbeans.Application)1 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 Applications (com.sun.enterprise.config.serverbeans.Applications)1 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)1 WebModule (org.glassfish.loadbalancer.admin.cli.beans.WebModule)1 BaseReader (org.glassfish.loadbalancer.admin.cli.reader.api.BaseReader)1