use of org.glassfish.resources.admin.cli.CustomResourceManager in project Payara by payara.
the class JNDIConfigSource method setValue.
public boolean setValue(String propertyName, String propertyValue, String target) {
boolean result = false;
HashMap<String, String> attrList = new HashMap<>();
attrList.put("factory-class", "org.glassfish.resources.custom.factory.PrimitivesAndStringFactory");
attrList.put("res-type", "java.lang.String");
attrList.put(ResourceConstants.ENABLED, Boolean.TRUE.toString());
attrList.put(JNDI_NAME, propertyName);
attrList.put(ServerTags.DESCRIPTION, "MicroProfile Config property for " + propertyName);
Properties props = new Properties();
props.put("value", propertyValue);
try {
CustomResourceManager customResMgr = Globals.getDefaultHabitat().getService(CustomResourceManager.class);
ResourceStatus status = customResMgr.create(domainConfiguration.getResources(), attrList, props, target);
if (status.getStatus() == ResourceStatus.SUCCESS) {
result = true;
} else {
if (status.isAlreadyExists()) {
Logger.getLogger(JNDIConfigSource.class.getName()).log(Level.WARNING, "Unable to set MicroProfile JNDI Config property as it already exists please delete it using delete-config-property --source jndi --propertyname {0}", propertyName);
}
}
} catch (Exception ex) {
Logger.getLogger(JNDIConfigSource.class.getName()).log(Level.WARNING, "Unable to set MicroProfile JNDI Config property " + propertyName, ex);
}
return result;
}
Aggregations