Search in sources :

Example 6 with ApplicationRef

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);
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) LbConfig(org.glassfish.loadbalancer.config.LbConfig) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 7 with ApplicationRef

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);
}
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 8 with ApplicationRef

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;
}
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)

Example 9 with ApplicationRef

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

Example 10 with ApplicationRef

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

Aggregations

ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)23 ActionReport (org.glassfish.api.ActionReport)11 Application (com.sun.enterprise.config.serverbeans.Application)9 Server (com.sun.enterprise.config.serverbeans.Server)8 ArrayList (java.util.ArrayList)6 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)5 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4 Applications (com.sun.enterprise.config.serverbeans.Applications)3 Cluster (com.sun.enterprise.config.serverbeans.Cluster)3 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)3 Iterator (java.util.Iterator)3 Logger (java.util.logging.Logger)3 ParameterMap (org.glassfish.api.admin.ParameterMap)3 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)3 ConfigCode (org.jvnet.hk2.config.ConfigCode)3 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)2 SystemApplications (com.sun.enterprise.config.serverbeans.SystemApplications)2 HTMLActionReporter (com.sun.enterprise.v3.common.HTMLActionReporter)2 DGServerRef (fish.payara.enterprise.config.serverbeans.DGServerRef)2