Search in sources :

Example 11 with Application

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);
}
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 12 with Application

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;
}
Also used : SystemApplications(com.sun.enterprise.config.serverbeans.SystemApplications) Application(com.sun.enterprise.config.serverbeans.Application)

Example 13 with 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;
}
Also used : Application(com.sun.enterprise.config.serverbeans.Application)

Example 14 with Application

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));
        }
    }
}
Also used : Application(com.sun.enterprise.config.serverbeans.Application)

Example 15 with Application

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;
}
Also used : AccessRequired(org.glassfish.api.admin.AccessRequired) ArrayList(java.util.ArrayList) Application(com.sun.enterprise.config.serverbeans.Application) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Aggregations

Application (com.sun.enterprise.config.serverbeans.Application)44 Module (com.sun.enterprise.config.serverbeans.Module)10 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)9 ActionReport (org.glassfish.api.ActionReport)9 ArrayList (java.util.ArrayList)8 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)7 Property (org.jvnet.hk2.config.types.Property)7 Applications (com.sun.enterprise.config.serverbeans.Applications)6 PropertyVetoException (java.beans.PropertyVetoException)6 HashMap (java.util.HashMap)5 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)5 Test (org.junit.Test)4 Server (com.sun.enterprise.config.serverbeans.Server)3 SystemApplications (com.sun.enterprise.config.serverbeans.SystemApplications)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Logger (java.util.logging.Logger)3 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)3 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)3