Search in sources :

Example 41 with org.jvnet.hk2.config

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

the class GrizzlyConfigSchemaMigrator method addAsadminProtocol.

private void addAsadminProtocol(NetworkConfig config) throws TransactionFailure {
    ensureAdminThreadPool();
    final Protocols protocols = getProtocols(config);
    Protocol adminProtocol = protocols.findProtocol(ASADMIN_LISTENER);
    if (adminProtocol == null) {
        adminProtocol = (Protocol) ConfigSupport.apply(new SingleConfigCode<Protocols>() {

            @Override
            public Object run(Protocols param) throws TransactionFailure {
                final Protocol protocol = param.createChild(Protocol.class);
                param.getProtocol().add(protocol);
                protocol.setName(ASADMIN_LISTENER);
                Http http = protocol.createChild(Http.class);
                http.setFileCache(http.createChild(FileCache.class));
                protocol.setHttp(http);
                http.setDefaultVirtualServer(ASADMIN_VIRTUAL_SERVER);
                http.setMaxConnections("250");
                return protocol;
            }
        }, protocols);
    }
    for (NetworkListener listener : adminProtocol.findNetworkListeners()) {
        ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

            @Override
            public Object run(NetworkListener param) {
                param.setThreadPool("admin-thread-pool");
                return null;
            }
        }, listener);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 42 with org.jvnet.hk2.config

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

the class GrizzlyConfigSchemaMigrator method postConstruct.

@Override
public void postConstruct() {
    for (Config config : configs.getConfig()) {
        currentConfig = config;
        try {
            final NetworkConfig networkConfig = currentConfig.getNetworkConfig();
            if (networkConfig == null) {
                createFromScratch();
            }
            normalizeThreadPools();
            if (currentConfig.getHttpService() != null) {
                promoteHttpServiceProperties(currentConfig.getHttpService());
                promoteVirtualServerProperties(currentConfig.getHttpService());
            } else {
                // this only happens during some unit tests
                LOGGER.log(Level.WARNING, ConfigApiLoggerInfo.nullHttpService, new String[] { currentConfig.getName() });
            }
            promoteSystemProperties();
            addAsadminProtocol(currentConfig.getNetworkConfig());
        } catch (TransactionFailure tf) {
            LOGGER.log(Level.SEVERE, ConfigApiLoggerInfo.failUpgradeDomain, tf);
            throw new RuntimeException(tf);
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig)

Example 43 with org.jvnet.hk2.config

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

the class TargetBasedResolver method getTarget.

private <T extends ConfigBeanProxy> T getTarget(Class<? extends ConfigBeanProxy> targetType, Class<T> type) throws ClassNotFoundException {
    // when using the target based parameter, we look first for a configuration of that name,
    // then we look for a cluster of that name and finally we look for a subelement of the right type
    final String name = getName();
    ConfigBeanProxy config = habitat.getService(targetType, target);
    if (config != null) {
        try {
            return type.cast(config);
        } catch (ClassCastException e) {
        // ok we need to do more work to find which object is really requested.
        }
        Dom parentDom = Dom.unwrap(config);
        String elementName = GenericCrudCommand.elementName(parentDom.document, targetType, type);
        if (elementName == null) {
            return null;
        }
        ConfigModel.Property property = parentDom.model.getElement(elementName);
        if (property.isCollection()) {
            Collection<Dom> collection;
            synchronized (parentDom) {
                collection = parentDom.nodeElements(elementName);
            }
            if (collection == null) {
                return null;
            }
            for (Dom child : collection) {
                if (name.equals(child.attribute("ref"))) {
                    return type.cast(child.<ConfigBeanProxy>createProxy());
                }
            }
        }
    }
    return null;
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel)

Example 44 with org.jvnet.hk2.config

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

the class BasicModularityTest method serializeConfigBean.

@Test
public void serializeConfigBean() {
    Config config = habitat.<Config>getService(Config.class, ServerEnvironmentImpl.DEFAULT_INSTANCE_NAME);
    ConfigBeanProxy prox = config.getExtensionByType(ConfigExtensionZero.class);
    String content = configModularityUtils.serializeConfigBean(prox);
    assertEquals("Cannot serialize config beans properly", "<config-extension-zero dummy=\"dummy-value\"></config-extension-zero>", content);
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Config(com.sun.enterprise.config.serverbeans.Config) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 45 with org.jvnet.hk2.config

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

the class DeleteIiopListener method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final Target targetUtil = services.getService(Target.class);
    final Config config = targetUtil.getConfig(target);
    ActionReport report = context.getActionReport();
    IiopService iiopService = config.getExtensionByType(IiopService.class);
    if (!isIIOPListenerExists(iiopService)) {
        report.setMessage(localStrings.getLocalString("delete.iiop.listener" + ".notexists", "IIOP Listener {0} does not exist.", listener_id));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<IiopService>() {

            @Override
            public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
                List<IiopListener> listenerList = param.getIiopListener();
                for (IiopListener listener : listenerList) {
                    String currListenerId = listener.getId();
                    if (currListenerId != null && currListenerId.equals(listener_id)) {
                        listenerList.remove(listener);
                        break;
                    }
                }
                return listenerList;
            }
        }, iiopService);
        report.setActionExitCode(ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        String actual = e.getMessage();
        report.setMessage(localStrings.getLocalString("delete.iiop.listener.fail", "failed", listener_id, actual));
        report.setActionExitCode(ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) IiopListener(org.glassfish.orb.admin.config.IiopListener) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) IiopService(org.glassfish.orb.admin.config.IiopService) List(java.util.List) ActionReport(org.glassfish.api.ActionReport)

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