Search in sources :

Example 41 with Resource

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

the class ResourcesDeployer method getResources.

/**
 * Retrieve connector and non-connector resources from the archive.
 *
 * @param archive Archieve from which the resources to be retrieved.
 * @param appName Name of the application
 * @param connectorResources Connector resources will be added to this list.
 * @param nonConnectorResources Non connector resources will be added to this list.
 * @param resourceXmlParsers Resource xml parsers corresponding to both connector and non connector resources will be stored in this.
 */
public void getResources(ReadableArchive archive, String appName, List<org.glassfish.resources.api.Resource> connectorResources, List<org.glassfish.resources.api.Resource> nonConnectorResources, Map<org.glassfish.resources.api.Resource, ResourcesXMLParser> resourceXmlParsers) {
    try {
        if (ResourceUtil.hasResourcesXML(archive, locator)) {
            Map<String, Map<String, List>> appScopedResources = new HashMap<String, Map<String, List>>();
            Map<String, String> fileNames = new HashMap<String, String>();
            // using appName as it is possible that "deploy --name=APPNAME" will
            // be different than the archive name.
            retrieveAllResourcesXMLs(fileNames, archive, appName);
            for (Map.Entry<String, String> entry : fileNames.entrySet()) {
                String moduleName = entry.getKey();
                String fileName = entry.getValue();
                debug("GlassFish Resources XML : " + fileName);
                moduleName = org.glassfish.resourcebase.resources.util.ResourceUtil.getActualModuleNameWithExtension(moduleName);
                String scope;
                if (appName.equals(moduleName)) {
                    scope = JAVA_APP_SCOPE_PREFIX;
                } else {
                    scope = JAVA_MODULE_SCOPE_PREFIX;
                }
                File file = new File(fileName);
                ResourcesXMLParser parser = new ResourcesXMLParser(file, scope);
                validateResourcesXML(file, parser);
                List<org.glassfish.resources.api.Resource> resources = parser.getResourcesList();
                if (nonConnectorResources != null) {
                    nonConnectorResources.addAll(ResourcesXMLParser.getNonConnectorResourcesList(resources, false, true));
                }
                if (connectorResources != null) {
                    connectorResources.addAll(ResourcesXMLParser.getConnectorResourcesList(resources, false, true));
                }
                if (resourceXmlParsers != null) {
                    for (org.glassfish.resources.api.Resource res : resources) {
                        resourceXmlParsers.put(res, parser);
                    }
                }
            }
        }
    } catch (Exception e) {
        // in the event notification infrastructure
        throw new DeploymentException("Failue while processing glassfish-resources.xml(s) in the archive ", e);
    }
}
Also used : ResourcesXMLParser(org.glassfish.resources.admin.cli.ResourcesXMLParser) Resource(com.sun.enterprise.config.serverbeans.Resource) Resource(org.glassfish.resources.api.Resource) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) DeploymentException(org.glassfish.deployment.common.DeploymentException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) Resource(org.glassfish.resources.api.Resource) DeploymentException(org.glassfish.deployment.common.DeploymentException) org.glassfish.resources.api(org.glassfish.resources.api) File(java.io.File)

Example 42 with Resource

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

the class JdbcRuntimeExtension method getDeferredResourceConfig.

@Override
public DeferredResourceConfig getDeferredResourceConfig(Object resource, Object pool, String resType, String raName) throws ConnectorRuntimeException {
    String resourceAdapterName;
    DeferredResourceConfig resConfig = null;
    // TODO V3 (not to hold specific resource types)
    if (resource instanceof JdbcResource || pool instanceof JdbcConnectionPool) {
        JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
        JdbcResource jdbcResource = (JdbcResource) resource;
        resourceAdapterName = getRANameofJdbcConnectionPool((JdbcConnectionPool) pool);
        resConfig = new DeferredResourceConfig(resourceAdapterName, null, jdbcPool, jdbcResource, null);
        Resource[] resourcesToload = new Resource[] { jdbcPool, jdbcResource };
        resConfig.setResourcesToLoad(resourcesToload);
    } else {
        throw new ConnectorRuntimeException("unsupported resource type : " + resource);
    }
    return resConfig;
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) JdbcResource(org.glassfish.jdbc.config.JdbcResource) DeferredResourceConfig(com.sun.enterprise.connectors.DeferredResourceConfig) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Resource(com.sun.enterprise.config.serverbeans.Resource) JdbcResource(org.glassfish.jdbc.config.JdbcResource)

Example 43 with Resource

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

the class DeleteJMSResource method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (jndiName == null) {
        report.setMessage(localStrings.getLocalString("delete.jms.resource.noJndiName", "No JNDI name defined for JMS Resource."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    jndiNameForConnectionPool = jndiName + JNDINAME_APPENDER;
    ActionReport subReport = report.addSubActionsReport();
    ConnectorResource cresource = null;
    Resource res = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
    if (res instanceof ConnectorResource) {
        cresource = (ConnectorResource) res;
    }
    /* for (ConnectorResource cr : connResources) {
         if (cr.getJndiName().equals(jndiName))
         cresource = cr;
         } */
    if (cresource == null) {
        ParameterMap params = new ParameterMap();
        params.set("jndi_name", jndiName);
        params.set("DEFAULT", jndiName);
        params.set("target", target);
        commandRunner.getCommandInvocation("delete-admin-object", subReport, context.getSubject()).parameters(params).execute();
        if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
            report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSAdminObject", "Unable to Delete Admin Object."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } else {
        if (!cascade) {
            Collection<ConnectorResource> connectorResources = domain.getResources().getResources(ConnectorResource.class);
            String connPoolName = jndiName + JNDINAME_APPENDER;
            int count = 0;
            for (ConnectorResource resource : connectorResources) {
                if (connPoolName.equals(resource.getPoolName())) {
                    count++;
                    if (count > 1)
                        break;
                }
            }
            if (count > 1) {
                report.setMessage(localStrings.getLocalString("found.more.connector.resources", "Some connector resources are referencing connection pool {0}. Use 'cascade' option to delete them", connPoolName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ActionReport listReport = habitat.getService(ActionReport.class);
        ParameterMap listParams = new ParameterMap();
        listParams.set("target", target);
        commandRunner.getCommandInvocation("list-jms-resources", listReport, context.getSubject()).parameters(listParams).execute();
        if (ActionReport.ExitCode.FAILURE.equals(listReport.getActionExitCode())) {
            report.setMessage(localStrings.getLocalString("list.jms.resources.fail", "Unable to list JMS Resources"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        Properties extraProps = listReport.getExtraProperties();
        if (extraProps != null && extraProps.size() > 0) {
            boolean resourceExist = false;
            for (int i = 0; i < extraProps.size(); i++) {
                List<Map<String, String>> nameList = (List) extraProps.get("jmsResources");
                for (Map<String, String> m : nameList) {
                    String jndi = (String) m.get("name");
                    if (jndiName.equals(jndi)) {
                        resourceExist = true;
                        break;
                    }
                }
                if (resourceExist)
                    break;
            }
            if (!resourceExist) {
                report.setMessage(localStrings.getLocalString("jms.resources.not.found", "JMS Resource {0} not found", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        // Delete the connector resource and connector connection pool
        String defPoolName = jndiNameForConnectionPool;
        String poolName = cresource.getPoolName();
        if (poolName != null && poolName.equals(defPoolName)) {
            ParameterMap params = new ParameterMap();
            params.set("DEFAULT", jndiName);
            params.set("connector_resource_name", jndiName);
            params.set("target", target);
            commandRunner.getCommandInvocation("delete-connector-resource", subReport, context.getSubject()).parameters(params).execute();
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSResource", "Unable to Delete Connector Resource."));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            params = new ParameterMap();
            params.set("poolname", jndiName);
            params.set("cascade", cascade.toString());
            params.set("DEFAULT", jndiNameForConnectionPool);
            commandRunner.getCommandInvocation("delete-connector-connection-pool", subReport, context.getSubject()).parameters(params).execute();
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSPool", "Unable to Delete Connector Connection Pool."));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            // clear the message set by the delete-connector-connection-pool command this is to prevent the 'connection pool deleted' message from displaying
            subReport.setMessage("");
        } else {
            // There is no connector pool with the default poolName.
            // However, no need to throw exception as the connector
            // resource might still be there. Try to delete the
            // connector-resource without touching the ref. as
            // ref. might have been deleted while deleting connector-connection-pool
            // as the ref. is the same.
            ParameterMap params = new ParameterMap();
            params.set("DEFAULT", jndiName);
            params.set("connector_resource_name", jndiName);
            params.set("target", target);
            commandRunner.getCommandInvocation("delete-connector-resource", subReport, context.getSubject()).parameters(params).execute();
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSResource", "Unable to Delete Connector Resource."));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    report.setActionExitCode(ec);
}
Also used : ConnectorResource(org.glassfish.connectors.config.ConnectorResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) List(java.util.List) Map(java.util.Map) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 44 with Resource

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

the class UniqueResourceNameValidator method isValid.

@Override
public boolean isValid(final Resource resource, final ConstraintValidatorContext constraintValidatorContext) {
    if (domain != null) {
        if (resource.getParent().getParent() instanceof Domain) {
            for (Resource res : domain.getResources().getResources()) {
                if (resource.getIdentity().equals(res.getIdentity())) {
                    Class[] resourceInterfaces = resource.getClass().getInterfaces();
                    Class[] resInterfaces = res.getClass().getInterfaces();
                    for (Class resourceClass : resourceInterfaces) {
                        for (Class resClass : resInterfaces) {
                            if (resClass.getName().equals(resourceClass.getName())) {
                                return true;
                            }
                        }
                    }
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Resource(com.sun.enterprise.config.serverbeans.Resource) Domain(com.sun.enterprise.config.serverbeans.Domain)

Aggregations

Resource (com.sun.enterprise.config.serverbeans.Resource)44 Resources (com.sun.enterprise.config.serverbeans.Resources)14 Test (org.junit.Test)14 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)13 ParameterMap (org.glassfish.api.admin.ParameterMap)10 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)9 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 Domain (com.sun.enterprise.config.serverbeans.Domain)6 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)6 JdbcResource (org.glassfish.jdbc.config.JdbcResource)6 MailResource (org.glassfish.resources.javamail.config.MailResource)6 ResourceException (javax.resource.ResourceException)5 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)5 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)5 Resource (org.glassfish.resources.api.Resource)5 CustomResource (org.glassfish.resources.config.CustomResource)5 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)5 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)4 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)4 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)4