use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class DeleteHTTPLBRefCommand method deleteServerFromLBConfig.
private void deleteServerFromLBConfig(LbConfigs lbconfigs, String configName, String serverName) {
LbConfig lbConfig = lbconfigs.getLbConfig(configName);
ServerRef sRef = lbConfig.getRefByRef(ServerRef.class, serverName);
if (sRef == null) {
// does not exist, just return from here
String msg = localStrings.getLocalString("ServerNotDefined", "Server {0} cannot be used as target", target);
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Server " + serverName + " does not exist in any cluster in the domain");
}
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (!Boolean.parseBoolean(force)) {
if (Boolean.parseBoolean(sRef.getLbEnabled())) {
String msg = localStrings.getLocalString("ServerNeedsToBeDisabled", "Server [{0}] needs to be disabled before it can be removed from the load balancer.", serverName);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
// check if its applications are LB disabled.
Server s = domain.getServerNamed(serverName);
if (s == null) {
String msg = localStrings.getLocalString("ServerNotDefined", "Server {0} cannot be used as target", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
List<ApplicationRef> appRefs = domain.getApplicationRefsInTarget(target);
if (appRefs == null) {
String msg = localStrings.getLocalString("AppRefsNotDefined", "Application refs does not exist in server {0}", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
boolean appLbEnabled = false;
for (ApplicationRef aRef : appRefs) {
if (Boolean.parseBoolean(aRef.getLbEnabled())) {
appLbEnabled = true;
break;
}
}
if (appLbEnabled) {
String msg = localStrings.getLocalString("AppsNotDisabled", "All referenced applications must be disabled in LB");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
removeServerRef(lbConfig, sRef);
}
use of com.sun.enterprise.config.serverbeans.ApplicationRef 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 com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class DeploymentCommandUtils method getAccessChecksForExistingApp.
/**
* Prepares AccessChecks for an application already deployed to one or
* more targets, returning an access check for the application itself and
* access checks for each matching version on whatever targets to which
* it is assigned.
* @param domain
* @param applications
* @param target
* @param matchedVersions
* @param appAction
* @param appRefAction
* @return
*/
public static Collection<? extends AccessRequired.AccessCheck> getAccessChecksForExistingApp(final Domain domain, final Applications applications, final String target, final Collection<String> matchedVersions, final String appAction, final String appRefAction) {
final List<AccessRequired.AccessCheck> accessChecks = new ArrayList<AccessRequired.AccessCheck>();
final List<String> targets = domain.getTargets(target);
for (String mv : matchedVersions) {
final Application app = applications.getApplication(mv);
if (app == null) {
continue;
}
accessChecks.add(new AccessRequired.AccessCheck(getResourceNameForExistingApp(domain, mv), appAction));
for (String t : targets) {
final ApplicationRef ar = domain.getApplicationRefInTarget(mv, t);
if (ar != null) {
accessChecks.add(new AccessRequired.AccessCheck(getTargetResourceNameForExistingAppRef(domain, t, mv), appRefAction));
}
}
}
return accessChecks;
}
use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class GetHostAndPortCommand method getHostAndPortForRequest.
private HostAndPort getHostAndPortForRequest(HttpService httpService) throws Exception {
if (moduleId == null) {
if (virtualServer == null) {
return getHostAndPort(httpService, securityEnabled);
} else {
VirtualServer vs = httpService.getVirtualServerByName(virtualServer);
if (vs == null) {
throw new Exception("Virtual server: " + virtualServer + " does not exist!");
}
return getHostAndPort(httpService, vs, securityEnabled);
}
}
ApplicationRef appRef = domain.getApplicationRefInTarget(moduleId, target);
List<String> vsList = null;
if (appRef != null) {
vsList = StringUtils.parseStringList(appRef.getVirtualServers(), " ,");
}
if (vsList == null) {
return getHostAndPort(httpService, securityEnabled);
}
for (String virtualServer : vsList) {
HostAndPort hp = getHostAndPort(httpService, httpService.getVirtualServerByName(virtualServer), securityEnabled);
if (hp != null) {
return hp;
}
}
return null;
}
use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class ListAppRefsCommand method getAccessChecks.
@Override
public Collection<? extends AccessCheck> getAccessChecks() {
final List<AccessCheck> accessChecks = new ArrayList<AccessCheck>();
appRefs = domain.getApplicationRefsInTarget(target);
for (ApplicationRef appRef : appRefs) {
accessChecks.add(new AccessCheck(AccessRequired.Util.resourceNameFromConfigBeanProxy(appRef), "read"));
}
return accessChecks;
}
Aggregations