Search in sources :

Example 1 with CustomResourceManager

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;
}
Also used : CustomResourceManager(org.glassfish.resources.admin.cli.CustomResourceManager) HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Properties(java.util.Properties) NamingException(javax.naming.NamingException) PropertyVetoException(java.beans.PropertyVetoException)

Aggregations

PropertyVetoException (java.beans.PropertyVetoException)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 NamingException (javax.naming.NamingException)1 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)1 CustomResourceManager (org.glassfish.resources.admin.cli.CustomResourceManager)1