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;
}
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);
}
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;
}
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");
}
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();
}
Aggregations