use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class JavaMailResourceManager method createConfigBean.
public Resource createConfigBean(Resources resources, HashMap attributes, Properties properties, boolean validate) throws Exception {
setAttributes(attributes, null);
ResourceStatus status = null;
if (!validate) {
status = new ResourceStatus(ResourceStatus.SUCCESS, "");
} else {
status = isValid(resources, false, null);
}
if (status.getStatus() == ResourceStatus.SUCCESS) {
return createConfigBean(resources, properties);
} else {
throw new ResourceException(status.getMessage());
}
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class CreateJndiResource method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
HashMap attrList = new HashMap();
attrList.put(FACTORY_CLASS, factoryClass);
attrList.put(RES_TYPE, resType);
attrList.put(JNDI_LOOKUP, jndiLookupName);
attrList.put(ENABLED, enabled.toString());
attrList.put(JNDI_NAME, jndiName);
attrList.put(ServerTags.DESCRIPTION, description);
ResourceStatus rs;
try {
rs = jndiResManager.create(domain.getResources(), attrList, properties, target);
} catch (Exception e) {
Logger.getLogger(CreateJndiResource.class.getName()).log(Level.SEVERE, "Unable to create jndi resource " + jndiName, e);
String def = "jndi resource: {0} could not be created, reason: {1}";
report.setMessage(localStrings.getLocalString("create.jndi.resource.fail", def, jndiName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
if (rs.getStatus() == ResourceStatus.FAILURE) {
ec = ActionReport.ExitCode.FAILURE;
if (rs.getMessage() == null) {
report.setMessage(localStrings.getLocalString("create.jndi.resource.fail", "jndi resource {0} creation failed", jndiName, ""));
}
if (rs.getException() != null)
report.setFailureCause(rs.getException());
}
if (rs.getMessage() != null) {
report.setMessage(rs.getMessage());
}
report.setActionExitCode(ec);
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class JndiResourceManager method createConfigBean.
public Resource createConfigBean(Resources resources, HashMap attributes, Properties properties, boolean validate) throws Exception {
setAttributes(attributes, null);
ResourceStatus status = null;
if (!validate) {
status = new ResourceStatus(ResourceStatus.SUCCESS, "");
} else {
status = isValid(resources, false, null);
}
if (status.getStatus() == ResourceStatus.SUCCESS) {
return createConfigBean(resources, properties);
} else {
throw new ResourceException(status.getMessage());
}
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class ResourcesManager method createResources.
/**
* Creating resources from sun-resources.xml file. This method is used by
* the admin framework when the add-resources command is used to create
* resources
*/
public static ArrayList createResources(Resources resources, File resourceXMLFile, String target, org.glassfish.resources.admin.cli.ResourceFactory resourceFactory) throws Exception {
ArrayList results = new ArrayList();
org.glassfish.resources.admin.cli.ResourcesXMLParser resourcesParser = new org.glassfish.resources.admin.cli.ResourcesXMLParser(resourceXMLFile);
List<Resource> vResources = resourcesParser.getResourcesList();
// First add all non connector resources.
Iterator<Resource> nonConnectorResources = org.glassfish.resources.admin.cli.ResourcesXMLParser.getNonConnectorResourcesList(vResources, false, false).iterator();
while (nonConnectorResources.hasNext()) {
Resource resource = (Resource) nonConnectorResources.next();
HashMap attrList = resource.getAttributes();
String desc = resource.getDescription();
if (desc != null)
attrList.put("description", desc);
Properties props = resource.getProperties();
ResourceStatus rs;
try {
org.glassfish.resources.admin.cli.ResourceManager rm = resourceFactory.getResourceManager(resource);
rs = rm.create(resources, attrList, props, target);
} catch (Exception e) {
String msg = e.getMessage();
rs = new ResourceStatus(ResourceStatus.FAILURE, msg);
}
results.add(rs);
}
// Now add all connector resources
Iterator connectorResources = org.glassfish.resources.admin.cli.ResourcesXMLParser.getConnectorResourcesList(vResources, false, false).iterator();
while (connectorResources.hasNext()) {
Resource resource = (Resource) connectorResources.next();
HashMap attrList = resource.getAttributes();
String desc = resource.getDescription();
if (desc != null)
attrList.put("description", desc);
Properties props = resource.getProperties();
ResourceStatus rs;
try {
org.glassfish.resources.admin.cli.ResourceManager rm = resourceFactory.getResourceManager(resource);
rs = rm.create(resources, attrList, props, target);
} catch (Exception e) {
String msg = e.getMessage();
rs = new ResourceStatus(ResourceStatus.FAILURE, msg);
}
results.add(rs);
}
return results;
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus 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