Search in sources :

Example 61 with TransactionFailure

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

the class GrizzlyConfigSchemaMigrator method postConstruct.

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 62 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure 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 63 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure 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 64 with TransactionFailure

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

the class ConfigPersistence method test.

@Test
public void test() throws TransactionFailure {
    final DomDocument document = getDocument(getHabitat());
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.reset();
    final ConfigurationPersistence testPersistence = new ConfigurationPersistence() {

        public void save(DomDocument doc) throws IOException, XMLStreamException {
            XMLOutputFactory factory = XMLOutputFactory.newInstance();
            XMLStreamWriter writer = factory.createXMLStreamWriter(baos);
            doc.writeTo(new IndentingXMLStreamWriter(writer));
            writer.close();
        }
    };
    TransactionListener testListener = new TransactionListener() {

        public void transactionCommited(List<PropertyChangeEvent> changes) {
            try {
                testPersistence.save(document);
            } catch (IOException e) {
                // To change body of catch statement use File | Settings | File Templates.
                e.printStackTrace();
            } catch (XMLStreamException e) {
                // To change body of catch statement use File | Settings | File Templates.
                e.printStackTrace();
            }
        }

        public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
        }
    };
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addTransactionsListener(testListener);
        doTest();
    } catch (TransactionFailure f) {
        f.printStackTrace();
        throw f;
    } finally {
        transactions.waitForDrain();
        transactions.removeTransactionsListener(testListener);
    }
    // now check if we persisted correctly...
    final String resultingXml = baos.toString();
    logger.fine(resultingXml);
    assertTrue("assertResult from " + getClass().getName() + " was false from " + resultingXml, assertResult(resultingXml));
}
Also used : TransactionListener(org.jvnet.hk2.config.TransactionListener) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) IndentingXMLStreamWriter(org.jvnet.hk2.config.IndentingXMLStreamWriter) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) ConfigurationPersistence(org.glassfish.config.support.ConfigurationPersistence) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DomDocument(org.jvnet.hk2.config.DomDocument) Transactions(org.jvnet.hk2.config.Transactions) XMLStreamException(javax.xml.stream.XMLStreamException) IndentingXMLStreamWriter(org.jvnet.hk2.config.IndentingXMLStreamWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) List(java.util.List) Test(org.junit.Test)

Example 65 with TransactionFailure

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

the class DirectAccessTest method doTest.

public void doTest() throws TransactionFailure {
    NetworkConfig networkConfig = habitat.getService(NetworkConfig.class);
    final NetworkListener listener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
    final Http http = listener.findHttpProtocol().getHttp();
    ConfigBean config = (ConfigBean) ConfigBean.unwrap(http.getFileCache());
    ConfigBean config2 = (ConfigBean) ConfigBean.unwrap(http);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("max-age-seconds", "12543");
    configChanges.put("max-cache-size-bytes", "1200");
    Map<String, String> config2Changes = new HashMap<String, String>();
    config2Changes.put("http2-enabled", "false");
    changes.put(config, configChanges);
    changes.put(config2, config2Changes);
    JavaConfig javaConfig = habitat.getService(JavaConfig.class);
    ConfigBean javaConfigBean = (ConfigBean) ConfigBean.unwrap(javaConfig);
    Map<String, String> javaConfigChanges = new HashMap<String, String>();
    javaConfigChanges.put("jvm-options", "-XFooBar=false");
    changes.put(javaConfigBean, javaConfigChanges);
    getHabitat().<ConfigSupport>getService(ConfigSupport.class).apply(changes);
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) ConfigBean(org.jvnet.hk2.config.ConfigBean) Map(java.util.Map) HashMap(java.util.HashMap) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)191 PropertyVetoException (java.beans.PropertyVetoException)132 ActionReport (org.glassfish.api.ActionReport)86 Property (org.jvnet.hk2.config.types.Property)61 Config (com.sun.enterprise.config.serverbeans.Config)52 HashMap (java.util.HashMap)30 Test (org.junit.Test)27 Resources (com.sun.enterprise.config.serverbeans.Resources)25 Map (java.util.Map)25 List (java.util.List)21 CommandTarget (org.glassfish.config.support.CommandTarget)21 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)21 Target (org.glassfish.internal.api.Target)21 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)20 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 ConfigBean (org.jvnet.hk2.config.ConfigBean)20 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)18 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)16 ParameterMap (org.glassfish.api.admin.ParameterMap)14