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);
}
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;
}
}
}
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);
}
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");
}
}
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;
}
}
Aggregations