Search in sources :

Example 1 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class CreateManagedExecutorService 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();
    HashMap attrList = new HashMap();
    setAttributeList(attrList);
    ResourceStatus rs;
    try {
        rs = managedExecutorServiceMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("create.managed.executor.service.failed", "Managed executor service {0} creation failed", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    if (rs.getMessage() != null) {
        report.setMessage(rs.getMessage());
    }
    if (rs.getStatus() == ResourceStatus.FAILURE) {
        ec = ActionReport.ExitCode.FAILURE;
        if (rs.getException() != null)
            report.setFailureCause(rs.getException());
    }
    report.setActionExitCode(ec);
}
Also used : HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ActionReport(org.glassfish.api.ActionReport)

Example 2 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class CreateManagedScheduledExecutorService 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();
    HashMap attrList = new HashMap();
    setAttributeList(attrList);
    ResourceStatus rs;
    try {
        rs = managedScheduledExecutorServiceMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("create.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} creation failed", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    if (rs.getMessage() != null) {
        report.setMessage(rs.getMessage());
    }
    if (rs.getStatus() == ResourceStatus.FAILURE) {
        ec = ActionReport.ExitCode.FAILURE;
        if (rs.getException() != null)
            report.setFailureCause(rs.getException());
    }
    report.setActionExitCode(ec);
}
Also used : HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ActionReport(org.glassfish.api.ActionReport)

Example 3 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class ContextServiceManager method delete.

public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
    if (jndiName == null) {
        String msg = localStrings.getLocalString("context.service.noJndiName", "No JNDI name defined for context service.");
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    Resource resource = ConnectorsUtil.getResourceByName(resources, ContextService.class, jndiName);
    // ensure we already have this resource
    if (resource == null) {
        String msg = localStrings.getLocalString("delete.context.service.notfound", "A context service named {0} does not exist.", jndiName);
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    if (SYSTEM_ALL_REQ.equals(resource.getObjectType())) {
        String msg = localStrings.getLocalString("delete.concurrent.resource.notAllowed", "The {0} resource cannot be deleted as it is required to be configured in the system.", jndiName);
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    if (environment.isDas()) {
        if ("domain".equals(target)) {
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
                String msg = localStrings.getLocalString("delete.context.service.resource-ref.exist", "This context service [ {0} ] is referenced in an instance/cluster target, use delete-resource-ref on appropriate target", jndiName);
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
        } else {
            if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
                String msg = localStrings.getLocalString("delete.context.service.no.resource-ref", "This context service [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
                String msg = localStrings.getLocalString("delete.context.service.multiple.resource-refs", "This context service [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
        }
    }
    try {
        // delete resource-ref
        resourceUtil.deleteResourceRef(jndiName, target);
        // delete context-service
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ContextService resource = (ContextService) ConnectorsUtil.getResourceByName(resources, ContextService.class, jndiName);
                return param.getResources().remove(resource);
            }
        }, resources) == null) {
            String msg = localStrings.getLocalString("delete.context.service.failed", "Context service {0} deletion failed", jndiName);
            return new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("delete.context.service.failed", "Context service {0} deletion failed ", jndiName);
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("delete.context.service.success", "Context service {0} deleted successfully", jndiName);
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ContextService(org.glassfish.concurrent.config.ContextService) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 4 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class ContextServiceManager method createConfigBean.

public Resource createConfigBean(final Resources resources, HashMap attributes, final 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());
    }
}
Also used : ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ResourceException(javax.resource.ResourceException)

Example 5 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class ContextServiceManager method isValid.

private ResourceStatus isValid(Resources resources, boolean validateResourceRef, String target) {
    ResourceStatus status;
    if (jndiName == null) {
        String msg = localStrings.getLocalString("context.service.noJndiName", "No JNDI name defined for context service.");
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    status = resourcesHelper.validateBindableResourceForDuplicates(resources, jndiName, validateResourceRef, target, ContextService.class);
    return status;
}
Also used : ContextService(org.glassfish.concurrent.config.ContextService) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus)

Aggregations

ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)60 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)17 HashMap (java.util.HashMap)15 ActionReport (org.glassfish.api.ActionReport)15 Resources (com.sun.enterprise.config.serverbeans.Resources)14 PropertyVetoException (java.beans.PropertyVetoException)14 ResourceException (javax.resource.ResourceException)13 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)4 Resource (com.sun.enterprise.config.serverbeans.Resource)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 ContextService (org.glassfish.concurrent.config.ContextService)2 ManagedExecutorService (org.glassfish.concurrent.config.ManagedExecutorService)2 ManagedThreadFactory (org.glassfish.concurrent.config.ManagedThreadFactory)2 JdbcResource (org.glassfish.jdbc.config.JdbcResource)2 MailResource (org.glassfish.resources.javamail.config.MailResource)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 Module (com.sun.enterprise.config.serverbeans.Module)1 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)1