Search in sources :

Example 1 with Resources

use of com.sun.enterprise.config.serverbeans.Resources in project Payara by payara.

the class JdbcRuntimeExtension method getAllSystemRAResourcesAndPools.

@Override
public Collection<Resource> getAllSystemRAResourcesAndPools() {
    List<Resource> resources = new ArrayList<Resource>();
    Domain domain = domainProvider.get();
    if (domain != null) {
        Resources allResources = domain.getResources();
        for (Resource resource : allResources.getResources()) {
            if (resource instanceof JdbcConnectionPool) {
                resources.add(resource);
            } else if (resource instanceof JdbcResource) {
                resources.add(resource);
            }
        }
    }
    System.out.println("JdbcRuntimeExtension,  getAllSystemRAResourcesAndPools = " + resources);
    return resources;
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Resource(com.sun.enterprise.config.serverbeans.Resource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) ArrayList(java.util.ArrayList) Resources(com.sun.enterprise.config.serverbeans.Resources) Domain(com.sun.enterprise.config.serverbeans.Domain)

Example 2 with Resources

use of com.sun.enterprise.config.serverbeans.Resources in project Payara by payara.

the class ManagedExecutorServiceBaseManager method create.

public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
    setAttributes(attributes, target);
    ResourceStatus validationStatus = isValid(resources, true, target);
    if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
        return validationStatus;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                return createResource(param, properties);
            }
        }, resources);
        resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("create.managed.executor.service.failed", "Managed executor service {0} creation failed", jndiName) + " " + tfe.getLocalizedMessage();
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("create.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} creation failed", jndiName) + " " + tfe.getLocalizedMessage();
        }
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("create.managed.executor.service.success", "Managed executor service {0} created successfully", jndiName);
    if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
        msg = localStrings.getLocalString("create.managed.scheduled.executor.service.success", "Managed scheduled executor service {0} created successfully", jndiName);
    }
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 3 with Resources

use of com.sun.enterprise.config.serverbeans.Resources in project Payara by payara.

the class ManagedExecutorServiceBaseManager method delete.

public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
    if (jndiName == null) {
        String msg = localStrings.getLocalString("managed.executor.service.noJndiName", "No JNDI name defined for managed executor service.");
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("managed.scheduled.executor.service.noJndiName", "No JNDI name defined for managed scheduled executor service.");
        }
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    Resource resource = null;
    if (getResourceType().equals(ServerTags.MANAGED_EXECUTOR_SERVICE)) {
        resource = ConnectorsUtil.getResourceByName(resources, ManagedExecutorService.class, jndiName);
    } else if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
        resource = ConnectorsUtil.getResourceByName(resources, ManagedScheduledExecutorService.class, jndiName);
    }
    // ensure we already have this resource
    if (resource == null) {
        String msg = localStrings.getLocalString("delete.managed.executor.service.notfound", "A managed executor service named {0} does not exist.", jndiName);
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.notfound", "A managed scheduled executor 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.managed.executor.service.resource-ref.exist", "This managed executor service [ {0} ] is referenced in an instance/cluster target, use delete-resource-ref on appropriate target", jndiName);
                if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                    msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.resource-ref.exist", "This managed scheduled executor 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.managed.executor.service.no.resource-ref", "This managed executor service [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
                if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                    msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.no.resource-ref", "This managed scheduled executor 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.managed.executor.service.multiple.resource-refs", "This managed executor service [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
                if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                    msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.multiple.resource-refs", "This managed scheduled executor 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 managed executor service
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ManagedExecutorServiceBase resource = null;
                if (getResourceType().equals(ServerTags.MANAGED_EXECUTOR_SERVICE)) {
                    resource = (ManagedExecutorService) ConnectorsUtil.getResourceByName(resources, ManagedExecutorService.class, jndiName);
                } else {
                    resource = (ManagedScheduledExecutorService) ConnectorsUtil.getResourceByName(resources, ManagedScheduledExecutorService.class, jndiName);
                }
                return param.getResources().remove(resource);
            }
        }, resources) == null) {
            String msg = localStrings.getLocalString("delete.managed.executor.service.failed", "Managed executor service {0} deletion failed", jndiName);
            if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} deletion failed", jndiName);
            }
            return new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("delete.managed.executor.service.failed", "Managed executor service {0} deletion failed ", jndiName);
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} deletion failed ", jndiName);
        }
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("delete.managed.executor.service.success", "Managed executor service {0} deleted successfully", jndiName);
    if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
        msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.success", "Managed scheduled executor service {0} deleted successfully", jndiName);
    }
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ManagedExecutorService(org.glassfish.concurrent.config.ManagedExecutorService) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ManagedExecutorServiceBase(org.glassfish.concurrent.config.ManagedExecutorServiceBase) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 4 with Resources

use of com.sun.enterprise.config.serverbeans.Resources in project Payara by payara.

the class ManagedThreadFactoryManager method create.

public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
    setAttributes(attributes, target);
    ResourceStatus validationStatus = isValid(resources, true, target);
    if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
        return validationStatus;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                return createResource(param, properties);
            }
        }, resources);
        resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("create.managed.thread.factory.failed", "Managed thread factory {0} creation failed", jndiName) + " " + tfe.getLocalizedMessage();
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("create.managed.thread.factory.success", "Managed thread factory {0} created successfully", jndiName);
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 5 with Resources

use of com.sun.enterprise.config.serverbeans.Resources 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)

Aggregations

Resources (com.sun.enterprise.config.serverbeans.Resources)41 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)25 PropertyVetoException (java.beans.PropertyVetoException)18 Resource (com.sun.enterprise.config.serverbeans.Resource)14 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)14 Domain (com.sun.enterprise.config.serverbeans.Domain)7 ActionReport (org.glassfish.api.ActionReport)7 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)7 JdbcResource (org.glassfish.jdbc.config.JdbcResource)6 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)5 ParameterMap (org.glassfish.api.admin.ParameterMap)4 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)4 ResourceAdapterConfig (org.glassfish.connectors.config.ResourceAdapterConfig)4 JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)4 MailResource (org.glassfish.resources.javamail.config.MailResource)4 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)3 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)3 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)3 CommandRunner (org.glassfish.api.admin.CommandRunner)3 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)3