use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class CustomResourceDeployer method undeployResource.
/**
* {@inheritDoc}
*/
@Override
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
CustomResource customResource = (CustomResource) resource;
ResourceInfo resourceInfo = new ResourceInfo(customResource.getJndiName(), applicationName, moduleName);
deleteResource(customResource, resourceInfo);
}
use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class CustomResourceDeployer method toCustomJavaEEResource.
/**
* Returns a new instance of j2ee custom resource from the given
* config bean.
* <p/>
* This method gets called from the custom resource deployer
* to convert custom-resource config bean into custom j2ee resource.
*
* @param rbean custom-resource config bean
* @param resourceInfo the definition of the resources to create
* @return new instance of j2ee custom resource
*/
public static JavaEEResource toCustomJavaEEResource(CustomResource rbean, ResourceInfo resourceInfo) {
org.glassfish.resources.beans.CustomResource jr = new org.glassfish.resources.beans.CustomResource(resourceInfo);
// jr.setDescription(rbean.getDescription()); // FIXME: getting error
// sets the enable flag
jr.setEnabled(Boolean.valueOf(rbean.getEnabled()));
// sets the resource type
jr.setResType(rbean.getResType());
// sets the factory class name
jr.setFactoryClass(rbean.getFactoryClass());
// sets the properties
List<Property> properties = rbean.getProperty();
if (properties != null) {
for (Property property : properties) {
ResourceProperty rp = new ResourcePropertyImpl(property.getName(), property.getValue());
jr.addProperty(rp);
}
}
return jr;
}
use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class DeleteCustomResource method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
// ensure we already have this resource
if (domain.getResources().getResourceByName(CustomResource.class, jndiName) == null) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.notfound", "A custom resource named {0} does not exist.", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (environment.isDas()) {
if ("domain".equals(target)) {
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.resource-ref.exist", "custom-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} else {
if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.no.resource-ref", "custom-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.multiple.resource-refs", "custom-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
try {
// delete resource-ref
resourceUtil.deleteResourceRef(jndiName, target);
// delete custom-resource
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
CustomResource resource = (CustomResource) domain.getResources().getResourceByName(CustomResource.class, jndiName);
if (resource != null && resource.getJndiName().equals(jndiName)) {
return param.getResources().remove(resource);
}
return null;
}
}, domain.getResources());
report.setMessage(localStrings.getLocalString("delete.custom.resource.success", "Custom resource {0} deleted", jndiName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.fail", "Unable to delete custom resource {0}", jndiName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
}
use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class CustomResourceManager method createResource.
private Object createResource(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
CustomResource newResource = createConfigBean(param, properties);
param.getResources().add(newResource);
return newResource;
}
use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class ListCustomResources method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
try {
List<String> list = new ArrayList<String>();
Collection<CustomResource> customResources = domain.getResources().getResources(CustomResource.class);
for (CustomResource customResource : customResources) {
if (bindableResourcesHelper.resourceExists(customResource.getJndiName(), targetOperand)) {
list.add(customResource.getJndiName());
}
}
for (String jndiName : list) {
final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(jndiName);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("" + "list.custom.resources.fail", "Unable to list custom resources") + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
Aggregations