Search in sources :

Example 11 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class VirtualServer method addContext.

/**
 * Registers the given <tt>Context</tt> with this <tt>VirtualServer</tt> at the given context root.
 *
 * <p>
 * If this <tt>VirtualServer</tt> has already been started, the given <tt>context</tt> will be started as well.
 *
 * @throws org.glassfish.embeddable.GlassFishException
 */
@Override
public void addContext(Context context, String contextRoot) throws ConfigException, GlassFishException {
    _logger.fine(VS_ADDED_CONTEXT);
    if (!(context instanceof ContextFacade)) {
        // embedded context should always be created via ContextFacade
        return;
    }
    if (!contextRoot.startsWith("/")) {
        contextRoot = "/" + contextRoot;
    }
    ExtendedDeploymentContext deploymentContext = null;
    try {
        if (factory == null) {
            factory = services.getService(ArchiveFactory.class);
        }
        ContextFacade facade = (ContextFacade) context;
        File docRoot = facade.getDocRoot();
        ClassLoader classLoader = facade.getClassLoader();
        ReadableArchive archive = factory.openArchive(docRoot);
        if (report == null) {
            report = new PlainTextActionReporter();
        }
        ServerEnvironment env = services.getService(ServerEnvironment.class);
        DeployCommandParameters params = new DeployCommandParameters();
        params.contextroot = contextRoot;
        params.enabled = Boolean.FALSE;
        params.origin = OpsParams.Origin.deploy;
        params.virtualservers = getName();
        params.target = "server";
        ExtendedDeploymentContext initialContext = new DeploymentContextImpl(report, archive, params, env);
        if (deployment == null) {
            deployment = services.getService(Deployment.class);
        }
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
        if (archiveHandler == null) {
            throw new RuntimeException("Cannot find archive handler for source archive");
        }
        params.name = archiveHandler.getDefaultApplicationName(archive, initialContext);
        Applications apps = domain.getApplications();
        ApplicationInfo appInfo = deployment.get(params.name);
        ApplicationRef appRef = domain.getApplicationRefInServer(params.target, params.name);
        if (appInfo != null && appRef != null) {
            if (appRef.getVirtualServers().contains(getName())) {
                throw new ConfigException("Context with name " + params.name + " is already registered on virtual server " + getName());
            } else {
                String virtualServers = appRef.getVirtualServers();
                virtualServers = virtualServers + "," + getName();
                params.virtualservers = virtualServers;
                params.force = Boolean.TRUE;
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Virtual server " + getName() + " added to context " + params.name);
                }
                return;
            }
        }
        deploymentContext = deployment.getBuilder(_logger, params, report).source(archive).archiveHandler(archiveHandler).build(initialContext);
        Properties properties = new Properties();
        deploymentContext.getAppProps().putAll(properties);
        if (classLoader != null) {
            ClassLoader parentCL = classLoaderHierarchy.createApplicationParentCL(classLoader, deploymentContext);
            ClassLoader cl = archiveHandler.getClassLoader(parentCL, deploymentContext);
            deploymentContext.setClassLoader(cl);
        }
        ApplicationConfigInfo savedAppConfig = new ApplicationConfigInfo(apps.getModule(com.sun.enterprise.config.serverbeans.Application.class, params.name));
        Properties appProps = deploymentContext.getAppProps();
        String appLocation = DeploymentUtils.relativizeWithinDomainIfPossible(deploymentContext.getSource().getURI());
        appProps.setProperty(ServerTags.LOCATION, appLocation);
        appProps.setProperty(ServerTags.OBJECT_TYPE, "user");
        appProps.setProperty(ServerTags.CONTEXT_ROOT, contextRoot);
        savedAppConfig.store(appProps);
        Transaction t = deployment.prepareAppConfigChanges(deploymentContext);
        appInfo = deployment.deploy(deploymentContext);
        if (appInfo != null) {
            facade.setAppName(appInfo.getName());
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, LogFacade.VS_ADDED_CONTEXT, new Object[] { getName(), appInfo.getName() });
            }
            deployment.registerAppInDomainXML(appInfo, deploymentContext, t);
        } else {
            if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
                throw new ConfigException(report.getMessage());
            }
        }
        // Update web.xml with programmatically added servlets, filters, and listeners
        File file = null;
        boolean delete = true;
        com.sun.enterprise.config.serverbeans.Application appBean = apps.getApplication(params.name);
        if (appBean != null) {
            file = new File(deploymentContext.getSource().getURI().getPath(), "/WEB-INF/web.xml");
            if (file.exists()) {
                delete = false;
            }
            updateWebXml(facade, file);
        } else {
            _logger.log(Level.SEVERE, LogFacade.APP_NOT_FOUND);
        }
        ReadableArchive source = appInfo.getSource();
        UndeployCommandParameters undeployParams = new UndeployCommandParameters(params.name);
        undeployParams.origin = UndeployCommandParameters.Origin.undeploy;
        undeployParams.target = "server";
        ExtendedDeploymentContext undeploymentContext = deployment.getBuilder(_logger, undeployParams, report).source(source).build();
        deployment.undeploy(params.name, undeploymentContext);
        params.origin = DeployCommandParameters.Origin.load;
        params.enabled = Boolean.TRUE;
        archive = factory.openArchive(docRoot);
        deploymentContext = deployment.getBuilder(_logger, params, report).source(archive).build();
        if (classLoader != null) {
            ClassLoader parentCL = classLoaderHierarchy.createApplicationParentCL(classLoader, deploymentContext);
            archiveHandler = deployment.getArchiveHandler(archive);
            ClassLoader cl = archiveHandler.getClassLoader(parentCL, deploymentContext);
            deploymentContext.setClassLoader(cl);
        }
        deployment.deploy(deploymentContext);
        // Enable the app using the modified web.xml
        // We can't use Deployment.enable since it doesn't take DeploymentContext with custom class loader
        deployment.updateAppEnabledAttributeInDomainXML(params.name, params.target, true);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, LogFacade.VS_ENABLED_CONTEXT, new Object[] { getName(), params.name() });
        }
        if (delete) {
            if (file != null) {
                if (file.exists() && !file.delete()) {
                    String path = file.toString();
                    _logger.log(Level.WARNING, LogFacade.UNABLE_TO_DELETE, path);
                }
            }
        }
        if (contextRoot.equals("/")) {
            contextRoot = "";
        }
        WebModule wm = (WebModule) findChild(contextRoot);
        if (wm != null) {
            facade.setUnwrappedContext(wm);
            wm.setEmbedded(true);
            if (config != null) {
                wm.setDefaultWebXml(config.getDefaultWebXml());
            }
        } else {
            throw new ConfigException("Deployed app not found " + contextRoot);
        }
        if (deploymentContext != null) {
            deploymentContext.postDeployClean(true);
        }
    } catch (Exception ex) {
        if (deployment != null && deploymentContext != null) {
            deploymentContext.clean();
        }
        throw new GlassFishException(ex);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Deployment(org.glassfish.internal.deployment.Deployment) ConfigException(org.glassfish.embeddable.web.ConfigException) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Properties(java.util.Properties) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) PlainTextActionReporter(com.sun.enterprise.admin.report.PlainTextActionReporter) ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) Applications(com.sun.enterprise.config.serverbeans.Applications) LifecycleException(org.apache.catalina.LifecycleException) ConfigException(org.glassfish.embeddable.web.ConfigException) IOException(java.io.IOException) GlassFishException(org.glassfish.embeddable.GlassFishException) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) Transaction(org.jvnet.hk2.config.Transaction) ApplicationConfigInfo(org.glassfish.deployment.common.ApplicationConfigInfo) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File) Application(com.sun.enterprise.deployment.Application)

Example 12 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class WebContainer method updateHost.

/**
 * Updates a virtual-server element.
 *
 * @param vsBean the virtual-server config bean.
 */
public void updateHost(com.sun.enterprise.config.serverbeans.VirtualServer vsBean) throws LifecycleException {
    if (ADMIN_VS.equals(vsBean.getId())) {
        return;
    }
    VirtualServer virtualServer = (VirtualServer) getEngine().findChild(vsBean.getId());
    if (virtualServer == null) {
        logger.log(WARNING, CANNOT_UPDATE_NON_EXISTENCE_VS, vsBean.getId());
        return;
    }
    boolean updateListeners = false;
    // Only update connectors if virtual-server.http-listeners is changed dynamically
    if (virtualServer.getNetworkListeners() == null) {
        if (vsBean.getNetworkListeners() == null) {
            updateListeners = false;
        } else {
            updateListeners = true;
        }
    } else if (virtualServer.getNetworkListeners().equals(vsBean.getNetworkListeners())) {
        updateListeners = false;
    } else {
        List<String> vsList = StringUtils.parseStringList(virtualServer.getNetworkListeners(), ",");
        List<String> vsBeanList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
        for (String vsBeanName : vsBeanList) {
            if (!vsList.contains(vsBeanName)) {
                updateListeners = true;
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, LogFacade.UPDATE_LISTENER, new Object[] { vsBeanName, virtualServer.getNetworkListeners() });
                }
                break;
            }
        }
    }
    // Must retrieve the old default-web-module before updating the
    // virtual server with the new vsBean, because default-web-module is
    // read from vsBean
    String oldDefaultWebModule = virtualServer.getDefaultWebModuleID();
    virtualServer.setBean(vsBean);
    String vsLogFile = vsBean.getLogFile();
    virtualServer.setLogFile(vsLogFile, logLevel, logServiceFile);
    virtualServer.configureState();
    virtualServer.clearAliases();
    virtualServer.configureAliases();
    // support both docroot property and attribute
    String docroot = vsBean.getPropertyValue("docroot");
    if (docroot == null) {
        docroot = vsBean.getDocroot();
    }
    if (docroot != null) {
        // Only update docroot if it is modified
        if (!virtualServer.getDocRoot().getAbsolutePath().equals(docroot)) {
            updateDocroot(docroot, virtualServer, vsBean);
        }
    }
    List<Property> props = virtualServer.getProperties();
    for (Property prop : props) {
        updateHostProperties(vsBean, prop.getName(), prop.getValue(), securityService, virtualServer);
    }
    virtualServer.configureSingleSignOn(globalSSOEnabled, webContainerFeatureFactory, isSsoFailoverEnabled());
    virtualServer.reconfigureAccessLog(globalAccessLogBufferSize, globalAccessLogWriteInterval, serviceLocator, domain, globalAccessLoggingEnabled, globalAccessLogPrefix);
    // old listener names
    List<String> oldListenerList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
    String[] oldListeners = (oldListenerList != null) ? oldListenerList.toArray(new String[oldListenerList.size()]) : new String[0];
    // new listener config
    HashSet<NetworkListener> networkListeners = new HashSet<>();
    if (oldListenerList != null) {
        for (String listener : oldListeners) {
            boolean found = false;
            for (NetworkListener httpListener : serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener()) {
                if (httpListener.getName().equals(listener)) {
                    networkListeners.add(httpListener);
                    found = true;
                    break;
                }
            }
            if (!found) {
                String msg = rb.getString(LogFacade.LISTENER_REFERENCED_BY_HOST_NOT_EXIST);
                msg = MessageFormat.format(msg, listener, virtualServer.getName());
                logger.log(Level.SEVERE, msg);
            }
        }
        // Update the port numbers with which the virtual server is
        // associated
        configureHostPortNumbers(virtualServer, networkListeners);
    } else {
        // The virtual server is not associated with any http listeners
        virtualServer.setNetworkListenerNames(new String[0]);
    }
    // have been removed from its http-listeners attribute
    for (String oldListener : oldListeners) {
        boolean found = false;
        for (NetworkListener httpListener : networkListeners) {
            if (httpListener.getName().equals(oldListener)) {
                found = true;
            }
        }
        if (!found) {
            // http listener was removed
            Connector[] connectors = _embedded.findConnectors();
            for (Connector connector : connectors) {
                WebConnector conn = (WebConnector) connector;
                if (oldListener.equals(conn.getName())) {
                    try {
                        conn.getMapperListener().unregisterHost(virtualServer.getJmxName());
                    } catch (Exception e) {
                        throw new LifecycleException(e);
                    }
                }
            }
        }
    }
    // have been added to its http-listeners attribute
    for (NetworkListener httpListener : networkListeners) {
        boolean found = false;
        for (String oldListener : oldListeners) {
            if (httpListener.getName().equals(oldListener)) {
                found = true;
            }
        }
        if (!found) {
            // http listener was added
            Connector[] connectors = _embedded.findConnectors();
            for (Connector connector : connectors) {
                WebConnector conn = (WebConnector) connector;
                if (httpListener.getName().equals(conn.getName())) {
                    if (!conn.isAvailable()) {
                        conn.start();
                    }
                    try {
                        conn.getMapperListener().registerHost(virtualServer);
                    } catch (Exception e) {
                        throw new LifecycleException(e);
                    }
                }
            }
        }
    }
    // passing in "null" as the default context path
    if (oldDefaultWebModule != null) {
        updateDefaultWebModule(virtualServer, oldListeners, null);
    }
    /*
         * Add default web module if one has been configured for the virtual server. If the module declared as the default web
         * module has already been deployed at the root context, we don't have to do anything.
         */
    WebModuleConfig webModuleConfig = virtualServer.getDefaultWebModule(domain, serviceLocator.getService(WebArchivist.class), appRegistry);
    if ((webModuleConfig != null) && (webModuleConfig.getContextPath() != null) && !"".equals(webModuleConfig.getContextPath()) && !"/".equals(webModuleConfig.getContextPath())) {
        // Remove dummy context that was created off of docroot, if such
        // a context exists
        removeDummyModule(virtualServer);
        updateDefaultWebModule(virtualServer, virtualServer.getNetworkListenerNames(), webModuleConfig);
    } else {
        WebModuleConfig wmc = virtualServer.createSystemDefaultWebModuleIfNecessary(serviceLocator.<WebArchivist>getService(WebArchivist.class));
        if (wmc != null) {
            loadStandaloneWebModule(virtualServer, wmc);
        }
    }
    if (updateListeners) {
        if (logger.isLoggable(FINE)) {
            logger.log(FINE, VS_UPDATED_NETWORK_LISTENERS, new Object[] { virtualServer.getName(), virtualServer.getNetworkListeners(), vsBean.getNetworkListeners() });
        }
        /*
             * Need to update connector and mapper restart is required when virtual-server.http-listeners is changed dynamically
             */
        List<NetworkListener> httpListeners = serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener();
        if (httpListeners != null) {
            for (NetworkListener httpListener : httpListeners) {
                updateConnector(httpListener, serviceLocator.getService(HttpService.class));
            }
        }
    }
}
Also used : PECoyoteConnector(com.sun.enterprise.web.connector.coyote.PECoyoteConnector) Connector(org.apache.catalina.Connector) LifecycleException(org.apache.catalina.LifecycleException) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) WebArchivist(org.glassfish.web.deployment.archivist.WebArchivist) HttpService(com.sun.enterprise.config.serverbeans.HttpService) StringUtils.parseStringList(com.sun.enterprise.util.StringUtils.parseStringList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) HashSet(java.util.HashSet)

Example 13 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class DirectCreationTest method doTest.

public void doTest() throws TransactionFailure {
    AdminService service = habitat.getService(AdminService.class);
    ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(service);
    Class<?>[] subTypes = null;
    try {
        subTypes = ConfigSupport.getSubElementsTypes(serviceBean);
    } catch (ClassNotFoundException e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    ConfigSupport support = getBaseServiceLocator().getService(ConfigSupport.class);
    assertNotNull("ConfigSupport not found", support);
    for (Class<?> subType : subTypes) {
        // TODO:  JL force compilation error to mark this probably edit point for grizzly config
        if (subType.getName().endsWith("DasConfig")) {
            Map<String, String> configChanges = new HashMap<String, String>();
            configChanges.put("dynamic-reload-enabled", "true");
            configChanges.put("autodeploy-dir", "funky-dir");
            support.createAndSet(serviceBean, (Class<? extends ConfigBeanProxy>) subType, configChanges);
            break;
        }
    }
    support.createAndSet(serviceBean, DasConfig.class, (List) null);
    List<AttributeChanges> profilerChanges = new ArrayList<AttributeChanges>();
    String[] values = { "-Xmx512m", "-RFtrq", "-Xmw24" };
    ConfigSupport.MultipleAttributeChanges multipleChanges = new ConfigSupport.MultipleAttributeChanges("jvm-options", values);
    String[] values1 = { "profile" };
    ConfigSupport.MultipleAttributeChanges multipleChanges1 = new ConfigSupport.MultipleAttributeChanges("name", values1);
    profilerChanges.add(multipleChanges);
    profilerChanges.add(multipleChanges1);
    support.createAndSet((ConfigBean) ConfigBean.unwrap(habitat.<JavaConfig>getService(JavaConfig.class)), Profiler.class, profilerChanges);
}
Also used : AdminService(com.sun.enterprise.config.serverbeans.AdminService) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) AttributeChanges(org.jvnet.hk2.config.AttributeChanges) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConfigBean(org.jvnet.hk2.config.ConfigBean) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig)

Example 14 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class SetMonitoringConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    // obtain the correct configuration
    Config config = targetUtil.getConfig(target);
    MonitoringService monitorServiceConfig = config.getExtensionByType(MonitoringService.class);
    if (monitorServiceConfig != null) {
        try {
            ConfigSupport.apply((monitorServiceConfigProxy) -> {
                if (monitoringServiceEnabled != null) {
                    monitorServiceConfigProxy.setMonitoringEnabled(String.valueOf(monitoringServiceEnabled));
                }
                if (mbeansEnabled != null) {
                    monitorServiceConfigProxy.setMbeanEnabled(String.valueOf(mbeansEnabled));
                }
                if (dTraceEnabled != null) {
                    monitorServiceConfigProxy.setMbeanEnabled(String.valueOf(dTraceEnabled));
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return monitorServiceConfigProxy;
            }, monitorServiceConfig);
        } catch (TransactionFailure ex) {
            logger.log(Level.WARNING, "Exception during command ", ex);
            actionReport.setMessage(ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    CommandInvocation commandInvocation = commandRunner.getCommandInvocation("set-jmx-monitoring-configuration", actionReport, context.getSubject());
    ParameterMap commandParameters = new ParameterMap();
    if (jmxLogEnabled != null) {
        commandParameters.add("enabled", jmxLogEnabled.toString());
    }
    if (jmxLogFrequency != null) {
        commandParameters.add("logfrequency", jmxLogFrequency);
    }
    if (jmxLogFrequencyUnit != null) {
        commandParameters.add("logfrequencyunit", jmxLogFrequencyUnit);
    }
    if (attributesToAdd != null) {
        for (String attributeToAdd : attributesToAdd) {
            commandParameters.add("addattribute", attributeToAdd);
        }
    }
    if (attributesToRemove != null) {
        for (String attributeToRemove : attributesToRemove) {
            commandParameters.add("delattribute", attributeToRemove);
        }
    }
    if (dynamic) {
        commandParameters.add("dynamic", dynamic.toString());
    }
    commandParameters.add("target", target);
    commandInvocation.parameters(commandParameters);
    commandInvocation.execute();
    if (actionReport.getActionExitCode() != SUCCESS && actionReport.getActionExitCode() != WARNING) {
        // Command couldn't be execute
        failureMessage(actionReport);
        return;
    }
    if (amxEnabled != null) {
        commandInvocation = commandRunner.getCommandInvocation("set-amx-enabled", actionReport, context.getSubject());
        commandParameters = new ParameterMap();
        commandParameters.add("enabled", amxEnabled.toString());
        commandParameters.add("dynamic", dynamic.toString());
        commandParameters.add("target", target);
        commandInvocation.parameters(commandParameters);
        commandInvocation.execute();
        if (actionReport.getActionExitCode() != SUCCESS && actionReport.getActionExitCode() != WARNING) {
            // Command couldn't be execute
            failureMessage(actionReport);
            return;
        }
    }
    commandInvocation = commandRunner.getCommandInvocation("set-rest-monitoring-configuration", actionReport, context.getSubject());
    commandParameters = new ParameterMap();
    if (restMonitoringEnabled != null) {
        commandParameters.add("enabled", restMonitoringEnabled.toString());
    }
    if (restMonitoringContextRoot != null) {
        commandParameters.add("contextroot", restMonitoringContextRoot);
    }
    if (restMonitoringApplicationName != null) {
        commandParameters.add("applicationname", restMonitoringApplicationName);
    }
    if (restMonitoringSecurityEnabled != null) {
        commandParameters.add("securityenabled", restMonitoringSecurityEnabled.toString());
    }
    commandParameters.add("target", target);
    commandInvocation.parameters(commandParameters);
    commandInvocation.execute();
    if (actionReport.getActionExitCode() != SUCCESS && actionReport.getActionExitCode() != WARNING) {
        // Command couldn't be execute
        failureMessage(actionReport);
        return;
    }
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 15 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class SetMonitoringServiceConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    config = targetUtil.getConfig(target);
    if (config != null) {
        monitoringService = config.getMonitoringService();
    } else {
        actionReport.setMessage("Cound not find target: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {

            @Override
            public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure {
                if (monitoringEnabled != null) {
                    monitoringServiceProxy.setMonitoringEnabled(String.valueOf(monitoringEnabled));
                }
                if (mbeanEnabled != null) {
                    monitoringServiceProxy.setMbeanEnabled(String.valueOf(mbeanEnabled));
                }
                if (dtraceEnabled != null) {
                    monitoringServiceProxy.setDtraceEnabled(String.valueOf(dtraceEnabled));
                }
                if (amxEnabled != null) {
                    AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
                    ConfigSupport.apply(new SingleConfigCode<AMXConfiguration>() {

                        @Override
                        public Object run(final AMXConfiguration amxConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                            amxConfigurationProxy.setEnabled((String.valueOf(amxEnabled)));
                            return amxConfigurationProxy;
                        }
                    }, amxConfiguration);
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return monitoringServiceProxy;
            }
        }, monitoringService);
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Failed to execute the command set-monitoring-service-configuration: {0}", ex.getCause().getMessage());
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ActionReport(org.glassfish.api.ActionReport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)100 Config (com.sun.enterprise.config.serverbeans.Config)81 ActionReport (org.glassfish.api.ActionReport)79 PropertyVetoException (java.beans.PropertyVetoException)69 Property (org.jvnet.hk2.config.types.Property)53 Properties (java.util.Properties)24 CommandTarget (org.glassfish.config.support.CommandTarget)24 Target (org.glassfish.internal.api.Target)23 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)16 List (java.util.List)16 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)16 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)16 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 PropertyChangeEvent (java.beans.PropertyChangeEvent)14 Server (com.sun.enterprise.config.serverbeans.Server)13 IOException (java.io.IOException)12 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 File (java.io.File)10