use of com.sun.enterprise.config.serverbeans.Application 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.Application in project Payara by payara.
the class RestMonitoringAdapter method getApplicationWithMatchingContextRoot.
/**
* Helper method that searches through all system applications for one with a matching context root.
* @param contextRoot The context root fo the application.
* @return The application config, or null if there are no applications with a matching context root.
*/
private Application getApplicationWithMatchingContextRoot(String contextRoot) {
Application application = null;
SystemApplications systemApplications = domain.getSystemApplications();
for (Application systemApplication : systemApplications.getApplications()) {
if (systemApplication.getContextRoot().equals(contextRoot)) {
application = systemApplication;
break;
}
}
return application;
}
use of com.sun.enterprise.config.serverbeans.Application in project Payara by payara.
the class RestMonitoringAdapter method isAppRegistered.
/**
* Overloaded method that checks if an application with the provided context root has been registered to this instance.
* @param contextRoot The context root to match.
* @return True if an application has been registered to this instance.
*/
public boolean isAppRegistered(String contextRoot) {
boolean registered = false;
Application application = getSystemApplicationConfig(contextRoot);
// Check if we've found an application with a matching context root, and that it's registered to this instance
if (application != null && (domain.getSystemApplicationReferencedFrom(env.getInstanceName(), application.getName()) != null)) {
registered = true;
}
return registered;
}
use of com.sun.enterprise.config.serverbeans.Application in project Payara by payara.
the class CreateLifecycleModuleCommand method validateTarget.
private void validateTarget(String target, String name) {
List<String> referencedTargets = domain.getAllReferencedTargetsForApplication(name);
Application app = apps.getApplication(name);
if (app != null && !app.isLifecycleModule()) {
throw new IllegalArgumentException(localStrings.getLocalString("application_withsamename_exists", "Application with same name {0} already exists, please pick a different name for the lifecycle module.", name));
}
if (referencedTargets.isEmpty()) {
if (deployment.isRegistered(name)) {
throw new IllegalArgumentException(localStrings.getLocalString("lifecycle.use.create_app_ref_2", "Lifecycle module {0} is already created in this domain. Please use create application ref to create application reference on target {1}", name, target));
}
} else {
if (referencedTargets.contains(target)) {
throw new IllegalArgumentException(localStrings.getLocalString("lifecycle.alreadyreg", "Lifecycle module {0} is already created on this target {1}", name, target));
} else {
throw new IllegalArgumentException(localStrings.getLocalString("lifecycle.use.create_app_ref", "Lifecycle module {0} is already referenced by other target(s). Please use create application ref to create application reference on target {1}", name, target));
}
}
}
use of com.sun.enterprise.config.serverbeans.Application 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;
}
Aggregations