use of org.jvnet.hk2.config 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);
}
use of org.jvnet.hk2.config 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 in project Payara by payara.
the class ConfigModularityUtils method getOwningObject.
public ConfigBeanProxy getOwningObject(String location) {
if (!location.startsWith("domain/configs")) {
if (!location.startsWith("domain")) {
// Sorry only know domain and below :D
return null;
}
StringTokenizer tokenizer = new StringTokenizer(location, "/", false);
// something directly inside the domain itself as we know one token is domain for sure
if (tokenizer.countTokens() == 1) {
return serviceLocator.getService(Domain.class);
}
location = location.substring(location.indexOf("/", "domain".length()) + 1);
tokenizer = new StringTokenizer(location, "/", false);
ConfigBeanProxy parent = serviceLocator.getService(Domain.class);
// skipping the domain itself as a token, we know it and took it away.
String parentElement = "domain";
String childElement = null;
while (tokenizer.hasMoreTokens()) {
try {
childElement = tokenizer.nextToken();
parent = getOwner(parent, parentElement, childElement);
parentElement = childElement;
} catch (Exception e) {
LogHelper.log(LOG, Level.INFO, cannotGetParentConfigBean, e, childElement);
}
}
return parent;
} else {
Class typeToFindGetter = getOwningClassForLocation(location);
if (typeToFindGetter == null) {
return null;
}
// Check if config object is where the location or it goes deeper in the config layers.
StringTokenizer tokenizer = new StringTokenizer(location, "/", false);
// something directly inside the config itself
if (tokenizer.countTokens() == 3) {
String expression = location.substring(location.lastIndexOf("[") + 1, location.length() - 1);
String configName = resolveExpression(expression);
return serviceLocator.<Domain>getService(Domain.class).getConfigNamed(configName);
}
location = location.substring(location.indexOf("/", "domain/configs".length()) + 1);
tokenizer = new StringTokenizer(location, "/", false);
String curLevel = tokenizer.nextToken();
String expression;
if (curLevel.contains("[")) {
expression = curLevel.substring(curLevel.lastIndexOf("[") + 1, curLevel.length() - 1);
} else {
expression = curLevel;
}
String configName = resolveExpression(expression);
ConfigBeanProxy parent = serviceLocator.<Domain>getService(Domain.class).getConfigNamed(configName);
String childElement;
String parentElement = "Config";
while (tokenizer.hasMoreTokens()) {
try {
childElement = tokenizer.nextToken();
parent = getOwner(parent, parentElement, childElement);
parentElement = childElement;
} catch (Exception e) {
LogHelper.log(LOG, Level.INFO, cannotGetParentConfigBean, e, configName);
}
}
return parent;
}
}
use of org.jvnet.hk2.config in project Payara by payara.
the class ConfigModularityUtils method getOwner.
public ConfigBeanProxy getOwner(ConfigBeanProxy parent, String parentElement, String childElement) throws InvocationTargetException, IllegalAccessException {
if (childElement.contains("CURRENT_INSTANCE_CONFIG_NAME")) {
return serviceLocator.<Config>getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
}
if (childElement.contains("CURRENT_INSTANCE_SERVER_NAME")) {
return serviceLocator.<Server>getService(Server.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
}
if (childElement.endsWith("]")) {
String componentName;
String elementName;
elementName = childElement.substring(childElement.lastIndexOf("/") + 1, childElement.indexOf("["));
componentName = childElement.substring(childElement.lastIndexOf("[") + 1, childElement.indexOf("]"));
Class childClass = getClassFor(elementName);
Class parentClass = getClassFor(parentElement);
Method m = findSuitableCollectionGetter(parentClass, childClass);
if (m != null) {
try {
Collection col = (Collection) m.invoke(parent);
componentName = resolveExpression(componentName);
return getNamedConfigBeanFromCollection(col, componentName, childClass);
} catch (Exception e) {
LogHelper.log(LOG, Level.INFO, invalidPath, e, childElement, componentName);
}
}
return null;
} else {
Class clz = getClassFor(childElement);
if (parent == null)
return null;
Method m = getMatchingGetterMethod(parent.getClass(), clz);
if (m != null) {
return (ConfigBeanProxy) m.invoke(parent);
} else {
try {
m = parent.getClass().getMethod("getExtensionByType", java.lang.Class.class);
} catch (NoSuchMethodException e) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Cannot find getExtensionByType", e);
}
}
if (m != null) {
return (ConfigBeanProxy) m.invoke(parent, clz);
}
return null;
}
}
}
use of org.jvnet.hk2.config in project Payara by payara.
the class CopyConfig method copyConfig.
public Config copyConfig(Configs configs, Config config, String destConfigName, Logger logger) throws PropertyVetoException, TransactionFailure {
final Config destCopy = (Config) config.deepCopy(configs);
if (systemproperties != null) {
final Properties properties = GenericCrudCommand.convertStringToProperties(systemproperties, ':');
for (final Object key : properties.keySet()) {
final String propName = (String) key;
// cannot update a system property so remove it first
List<SystemProperty> sysprops = destCopy.getSystemProperty();
for (SystemProperty sysprop : sysprops) {
if (propName.equals(sysprop.getName())) {
sysprops.remove(sysprop);
break;
}
}
SystemProperty newSysProp = destCopy.createChild(SystemProperty.class);
newSysProp.setName(propName);
newSysProp.setValue(properties.getProperty(propName));
destCopy.getSystemProperty().add(newSysProp);
}
}
final String configName = destConfigName;
destCopy.setName(configName);
configs.getConfig().add(destCopy);
copyOfConfig = destCopy;
String srcConfig = "";
srcConfig = config.getName();
File configConfigDir = new File(env.getConfigDirPath(), configName);
for (Config c : configs.getConfig()) {
File existingConfigConfigDir = new File(env.getConfigDirPath(), c.getName());
if (!c.getName().equals(configName) && configConfigDir.equals(existingConfigConfigDir)) {
throw new TransactionFailure(localStrings.getLocalString("config.duplicate.dir", "Config {0} is trying to use the same directory as config {1}", configName, c.getName()));
}
}
try {
if (!(new File(configConfigDir, "docroot").mkdirs() && new File(configConfigDir, "lib/ext").mkdirs())) {
throw new IOException(localStrings.getLocalString("config.mkdirs", "error creating config specific directories"));
}
String srcConfigLoggingFile = env.getInstanceRoot().getAbsolutePath() + File.separator + "config" + File.separator + srcConfig + File.separator + ServerEnvironmentImpl.kLoggingPropertiesFileName;
File src = new File(srcConfigLoggingFile);
if (!src.exists()) {
src = new File(env.getConfigDirPath(), ServerEnvironmentImpl.kLoggingPropertiesFileName);
}
File dest = new File(configConfigDir, ServerEnvironmentImpl.kLoggingPropertiesFileName);
FileUtils.copy(src, dest);
} catch (Exception e) {
logger.log(Level.WARNING, ConfigApiLoggerInfo.copyConfigError, e.getLocalizedMessage());
}
return destCopy;
}
Aggregations