Search in sources :

Example 1 with LbReaderException

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

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

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

the class LoadbalancerReaderImpl method getClustersDataFromLBConfig.

public ClusterReader[] getClustersDataFromLBConfig() throws LbReaderException {
    List<Ref> serverOrClusters = _lbConfig.getClusterRefOrServerRef();
    ClusterReader[] cls = new ClusterReader[serverOrClusters.size()];
    Iterator<Ref> iter = serverOrClusters.iterator();
    int i = 0;
    while (iter.hasNext()) {
        Ref ref = iter.next();
        if (ref instanceof ServerRef) {
            cls[i++] = new StandAloneClusterReaderImpl(_domain, _appRegistry, (ServerRef) ref);
        } else if (ref instanceof ClusterRef) {
            cls[i++] = new ClusterReaderImpl(_domain, _appRegistry, (ClusterRef) ref);
        } else {
            String msg = LbLogUtil.getStringManager().getString("UnableToDetermineType", ref.getRef());
            throw new LbReaderException(msg);
        }
    }
    return cls;
}
Also used : ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) Ref(com.sun.enterprise.config.serverbeans.Ref) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) ClusterReader(org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)

Example 4 with LbReaderException

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

the class InstanceReaderImpl method getResolvedHostName.

private String getResolvedHostName(String address) throws LbReaderException {
    InetAddress addr = null;
    if (!address.equals(BIND_TO_ANY)) {
        try {
            addr = InetAddress.getByName(address);
        } catch (UnknownHostException ex) {
            String msg = LbLogUtil.getStringManager().getString("CannotResolveHostName", address);
            throw new LbReaderException(msg, ex);
        }
        if (!addr.isLoopbackAddress()) {
            return address;
        }
    }
    String nodeName = _server.getNodeRef();
    Node node = _domain.getNodes().getNode(nodeName);
    if (node == null) {
        String msg = LbLogUtil.getStringManager().getString("UnableToGetNode", _server.getName());
        throw new LbReaderException(msg);
    }
    if (node.getNodeHost() != null && !node.getNodeHost().equals(LOCALHOST)) {
        return node.getNodeHost();
    }
    return System.getProperty("com.sun.aas.hostName");
}
Also used : UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)

Example 5 with LbReaderException

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

the class InstanceReaderImpl method getListeners.

/**
 * Enlists both http and https listeners of this server instance
 * It will be form "http:<hostname>:<port> https:<hostname>:<port>"
 *
 * @return String   Listener(s) info.
 */
@Override
public String getListeners() throws LbReaderException {
    StringBuilder listenerStr = new StringBuilder();
    Config config = _domain.getConfigNamed(_server.getConfigRef());
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    NetworkListeners nls = networkConfig.getNetworkListeners();
    Iterator<NetworkListener> listenerIter = nls.getNetworkListener().iterator();
    int i = 0;
    PropertyResolver resolver = new PropertyResolver(_domain, _server.getName());
    while (listenerIter.hasNext()) {
        NetworkListener listener = listenerIter.next();
        NetworkListener rawListener = GlassFishConfigBean.getRawView(listener);
        if (rawListener.getName().equals(ADMIN_LISTENER)) {
            continue;
        }
        String prot = rawListener.getProtocol();
        Protocol protocol = protocols.findProtocol(prot);
        if (i > 0) {
            // space between listener names
            listenerStr.append(' ');
        }
        i++;
        if (Boolean.valueOf(protocol.getHttp().getJkEnabled())) {
            listenerStr.append(AJP_PROTO);
        } else {
            if (Boolean.valueOf(protocol.getSecurityEnabled()).booleanValue()) {
                listenerStr.append(HTTPS_PROTO);
            } else {
                listenerStr.append(HTTP_PROTO);
            }
        }
        String hostName = getResolvedHostName(rawListener.getAddress());
        listenerStr.append(hostName);
        listenerStr.append(':');
        // resolve the port name
        String port = rawListener.getPort();
        // If it is system variable, resolve it
        if ((port != null) && (port.length() > 1) && (port.charAt(0) == '$') && (port.charAt(1) == '{') && (port.charAt(port.length() - 1) == '}')) {
            String portVar = port.substring(2, port.length() - 1);
            port = resolver.getPropertyValue(portVar);
            if (port == null) {
                throw new LbReaderException(LbLogUtil.getStringManager().getString("UnableToResolveSystemProperty", portVar, _server.getName()));
            }
        }
        listenerStr.append(port);
    }
    return listenerStr.toString();
}
Also used : PropertyResolver(org.glassfish.config.support.PropertyResolver) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)

Aggregations

LbReaderException (org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)5 ClusterReader (org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader)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 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 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 PropertyResolver (org.glassfish.config.support.PropertyResolver)1