Search in sources :

Example 66 with TransactionFailure

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

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

the class DirectRemovalTest method doTest.

public void doTest() throws TransactionFailure {
    NetworkListeners listeners = habitat.getService(NetworkListeners.class);
    ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(listeners);
    for (NetworkListener listener : listeners.getNetworkListener()) {
        if (listener.getName().endsWith("http-listener-1")) {
            ConfigSupport.deleteChild(serviceBean, (ConfigBean) ConfigBean.unwrap(listener));
            break;
        }
    }
}
Also used : NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ConfigBean(org.jvnet.hk2.config.ConfigBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 68 with TransactionFailure

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

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

Example 70 with TransactionFailure

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

the class ExtensionPatternInvocationImpl method handleExtension.

@Override
public ConfigBeanProxy handleExtension(Object owner, Class ownerType, Object[] params) {
    if (((Class) params[0]).getName().equals("com.sun.enterprise.config.serverbeans.SystemProperty"))
        return null;
    ConfigBeanProxy configExtension = null;
    List<ConfigBeanProxy> extensions = configModularityUtils.getExtensions(((ConfigBean) owner).createProxy(ownerType));
    for (ConfigBeanProxy extension : extensions) {
        try {
            configExtension = (ConfigBeanProxy) ((Class) params[0]).cast(extension);
            return configExtension;
        } catch (Exception e) {
        // ignore, not the right type.
        }
    }
    try {
        ConfigBeanProxy pr = ((ConfigBean) owner).createProxy(ownerType);
        ConfigBeanProxy returnValue = moduleConfigurationLoader.createConfigBeanForType((Class) params[0], pr);
        return returnValue;
    } catch (TransactionFailure transactionFailure) {
        LogHelper.log(LOG, Level.INFO, "Cannot get extension type {0} for {1}.", transactionFailure, new Object[] { owner.getClass().getName(), ownerType.getName() });
        return null;
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigBean(org.jvnet.hk2.config.ConfigBean)

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