Search in sources :

Example 36 with Resources

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

the class JndiResourceManager 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.jndi.resource.fail", "Unable to create jndi resource {0}.", jndiName) + " " + tfe.getLocalizedMessage();
        return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
    }
    String msg = localStrings.getLocalString("create.jndi.resource.success", "jndi resource {0} created.", jndiName);
    return new ResourceStatus(ResourceStatus.SUCCESS, msg, true);
}
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 37 with Resources

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

the class ListJavaMailResourcesTest method setUp.

@Before
public void setUp() {
    habitat = getHabitat();
    parameters = new ParameterMap();
    cr = habitat.getService(CommandRunner.class);
    assertTrue(cr != null);
    Resources resources = habitat.<Domain>getService(Domain.class).getResources();
    context = new AdminCommandContextImpl(LogDomains.getLogger(ListJavaMailResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    for (Resource resource : resources.getResources()) {
        if (resource instanceof MailResource) {
            origNum = origNum + 1;
        }
    }
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) MailResource(org.glassfish.resources.javamail.config.MailResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) Resources(com.sun.enterprise.config.serverbeans.Resources) Domain(com.sun.enterprise.config.serverbeans.Domain) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) CommandRunner(org.glassfish.api.admin.CommandRunner) MailResource(org.glassfish.resources.javamail.config.MailResource) Before(org.junit.Before)

Example 38 with Resources

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

the class DeleteJndiResource 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 (!doesResourceExist(domain.getResources(), jndiName)) {
        report.setMessage(localStrings.getLocalString("delete.jndi.resource.notfound", "A jndi 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.jndi.resource.resource-ref.exist", "external-jndi-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.jndi.resource.no.resource-ref", "external-jndi-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.jndi.resource.multiple.resource-refs", "external-jndi-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 external-jndi-resource
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ExternalJndiResource resource = (ExternalJndiResource) domain.getResources().getResourceByName(ExternalJndiResource.class, jndiName);
                if (resource.getJndiName().equals(jndiName)) {
                    return param.getResources().remove(resource);
                }
                return null;
            }
        }, domain.getResources());
        report.setMessage(localStrings.getLocalString("" + "delete.jndi.resource.success", "Jndi resource {0} deleted.", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("" + "delete.jndi.resource.fail", "Unable to delete jndi 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) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource)

Example 39 with Resources

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

the class JdbcConnectionPoolDeployer method handlePoolRecreationForExistingProxies.

private void handlePoolRecreationForExistingProxies(ConnectorConnectionPool connConnPool) {
    recreatePool(connConnPool);
    Collection<BindableResource> resourcesList;
    if (!connConnPool.isApplicationScopedResource()) {
        resourcesList = JdbcResourcesUtil.getResourcesOfPool(domain.getResources(), connConnPool.getName());
    } else {
        PoolInfo poolInfo = connConnPool.getPoolInfo();
        Resources resources = ResourcesUtil.createInstance().getResources(poolInfo);
        resourcesList = JdbcResourcesUtil.getResourcesOfPool(resources, connConnPool.getName());
    }
    for (BindableResource bindableResource : resourcesList) {
        ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(bindableResource);
        ConnectorRegistry.getInstance().updateResourceInfoVersion(resourceInfo);
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 40 with Resources

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

the class JdbcRecoveryResourceHandler method getAllJdbcResources.

private Collection<JdbcResource> getAllJdbcResources() {
    Collection<JdbcResource> allResources = new ArrayList<JdbcResource>();
    Collection<JdbcResource> jdbcResources = domain.getResources().getResources(JdbcResource.class);
    allResources.addAll(jdbcResources);
    for (Application app : applications.getApplications()) {
        if (ResourcesUtil.createInstance().isEnabled(app)) {
            Resources appScopedResources = app.getResources();
            if (appScopedResources != null && appScopedResources.getResources() != null) {
                allResources.addAll(appScopedResources.getResources(JdbcResource.class));
            }
            List<Module> modules = app.getModule();
            if (modules != null) {
                for (Module module : modules) {
                    Resources msr = module.getResources();
                    if (msr != null && msr.getResources() != null) {
                        allResources.addAll(msr.getResources(JdbcResource.class));
                    }
                }
            }
        }
    }
    return allResources;
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) ArrayList(java.util.ArrayList) Resources(com.sun.enterprise.config.serverbeans.Resources) Module(com.sun.enterprise.config.serverbeans.Module) Application(com.sun.enterprise.config.serverbeans.Application)

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