Search in sources :

Example 41 with SingleConfigCode

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

the class GrizzlyConfigSchemaMigrator method promoteVirtualServerProperties.

private void promoteVirtualServerProperties(HttpService service) throws TransactionFailure {
    for (VirtualServer virtualServer : service.getVirtualServer()) {
        ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

            @Override
            public Object run(VirtualServer param) throws PropertyVetoException {
                if (param.getHttpListeners() != null && !"".equals(param.getHttpListeners())) {
                    param.setNetworkListeners(param.getHttpListeners());
                }
                param.setHttpListeners(null);
                final List<Property> propertyList = new ArrayList<Property>(param.getProperty());
                final Iterator<Property> it = propertyList.iterator();
                while (it.hasNext()) {
                    final Property property = it.next();
                    if ("docroot".equals(property.getName())) {
                        param.setDocroot(property.getValue());
                        it.remove();
                    } else if ("accesslog".equals(property.getName())) {
                        param.setAccessLog(property.getValue());
                        it.remove();
                    } else if ("sso-enabled".equals(property.getName())) {
                        param.setSsoEnabled(property.getValue());
                        it.remove();
                    }
                }
                param.getProperty().clear();
                param.getProperty().addAll(propertyList);
                return null;
            }
        }, virtualServer);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 42 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode 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>() {

            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 43 with SingleConfigCode

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

the class ConfigListenerTest method removeListenerTest.

@Test
public void removeListenerTest() throws TransactionFailure {
    Transactions transactions = getHabitat().getService(Transactions.class);
    HttpListenerContainer container = registerAndCreateHttpListenerContainer(habitat);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(container.httpListener);
    bean.removeListener(container);
    ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

        @Override
        public Object run(NetworkListener param) {
            param.setPort("8989");
            return null;
        }
    }, container.httpListener);
    transactions.waitForDrain();
    assertFalse(container.received);
    // put back the right values in the domain to avoid test collisions
    ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

        @Override
        public Object run(NetworkListener param) {
            param.setPort("8080");
            return null;
        }
    }, container.httpListener);
}
Also used : Transactions(org.jvnet.hk2.config.Transactions) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 44 with SingleConfigCode

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

the class DuplicateKeyedElementTest method identicalKeyTest.

@Test(expected = TransactionFailure.class)
public void identicalKeyTest() throws TransactionFailure {
    HttpService httpService = getHabitat().getService(HttpService.class);
    assertNotNull(httpService);
    // let's find a acceptable target.
    VirtualServer target = null;
    for (VirtualServer vs : httpService.getVirtualServer()) {
        if (!vs.getProperty().isEmpty()) {
            target = vs;
            break;
        }
    }
    assertNotNull(target);
    Property newProp = (Property) ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

        public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
            // first one is fine...
            Property firstProp = param.createChild(Property.class);
            firstProp.setName("foo");
            firstProp.setValue("bar");
            param.getProperty().add(firstProp);
            // this should fail...
            Property secondProp = param.createChild(Property.class);
            secondProp.setName("foo");
            secondProp.setValue("bar");
            param.getProperty().add(secondProp);
            return secondProp;
        }
    }, target);
    // if we arrive here, this is an error, we succeeded adding a property with
    // the same key name.
    assertTrue(false);
}
Also used : SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Test(org.junit.Test)

Example 45 with SingleConfigCode

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

the class HttpServiceTest method validTransaction.

@Test
public void validTransaction() throws TransactionFailure {
    final String max = listener.findHttpProtocol().getHttp().getMaxConnections();
    ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

        public Object run(NetworkListener okToChange) throws TransactionFailure {
            final Http http = okToChange.createChild(Http.class);
            http.setMaxConnections("100");
            http.setTimeoutSeconds("65");
            http.setFileCache(http.createChild(FileCache.class));
            ConfigSupport.apply(new SingleConfigCode<Protocol>() {

                @Override
                public Object run(Protocol param) {
                    param.setHttp(http);
                    return null;
                }
            }, okToChange.findHttpProtocol());
            return http;
        }
    }, listener);
    ConfigSupport.apply(new SingleConfigCode<Http>() {

        @Override
        public Object run(Http param) {
            param.setMaxConnections(max);
            return null;
        }
    }, listener.findHttpProtocol().getHttp());
    try {
        ConfigSupport.apply(new SingleConfigCode<Http>() {

            public Object run(Http param) throws TransactionFailure {
                param.setMaxConnections("7");
                throw new TransactionFailure("Sorry, changed my mind", null);
            }
        }, listener.findHttpProtocol().getHttp());
    } catch (TransactionFailure e) {
        logger.fine("good, got my exception about changing my mind");
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)139 PropertyVetoException (java.beans.PropertyVetoException)117 ActionReport (org.glassfish.api.ActionReport)66 Config (com.sun.enterprise.config.serverbeans.Config)37 Property (org.jvnet.hk2.config.types.Property)28 Resources (com.sun.enterprise.config.serverbeans.Resources)25 List (java.util.List)19 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)16 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Test (org.junit.Test)15 CommandTarget (org.glassfish.config.support.CommandTarget)14 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)14 Target (org.glassfish.internal.api.Target)14 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)12 Protocols (org.glassfish.grizzly.config.dom.Protocols)11 Resource (com.sun.enterprise.config.serverbeans.Resource)9 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)9 Properties (java.util.Properties)8 HttpService (com.sun.enterprise.config.serverbeans.HttpService)6