Search in sources :

Example 11 with CustomResource

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);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) CustomResource(org.glassfish.resources.config.CustomResource)

Example 12 with CustomResource

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;
}
Also used : ResourceProperty(com.sun.enterprise.repository.ResourceProperty) CustomResource(org.glassfish.resources.config.CustomResource) ResourceProperty(com.sun.enterprise.repository.ResourceProperty) Property(org.jvnet.hk2.config.types.Property)

Example 13 with CustomResource

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);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) CustomResource(org.glassfish.resources.config.CustomResource) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Example 14 with CustomResource

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;
}
Also used : CustomResource(org.glassfish.resources.config.CustomResource)

Example 15 with CustomResource

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);
    }
}
Also used : CustomResource(org.glassfish.resources.config.CustomResource) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport)

Aggregations

CustomResource (org.glassfish.resources.config.CustomResource)16 Resource (com.sun.enterprise.config.serverbeans.Resource)5 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)4 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)4 Test (org.junit.Test)4 PropertyVetoException (java.beans.PropertyVetoException)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)2 Resources (com.sun.enterprise.config.serverbeans.Resources)2 ActionReport (org.glassfish.api.ActionReport)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2 Property (org.jvnet.hk2.config.types.Property)2 ResourceProperty (com.sun.enterprise.repository.ResourceProperty)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ResourceUtil (org.glassfish.resourcebase.resources.admin.cli.ResourceUtil)1 After (org.junit.After)1