Class ConnectorConnectionPoolAdminServiceImpl

  • All Implemented Interfaces:
    ConnectorConstants, ResourceConstants

    public class ConnectorConnectionPoolAdminServiceImpl
    extends ConnectorService
    Connector connection pool admin service performs the functionality of creation, deletion, recreation, testing of the pools.
    Author:
    Srikanth P and Aditya Gore
    • Constructor Detail

      • ConnectorConnectionPoolAdminServiceImpl

        public ConnectorConnectionPoolAdminServiceImpl()
        Default constructor
    • Method Detail

      • createConnectorConnectionPool

        public void createConnectorConnectionPool​(ConnectorConnectionPool connectorPoolObj)
                                           throws ConnectorRuntimeException
        Creates connector connection pool in the connector container.
        Parameters:
        connectorPoolObj - ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
        Throws:
        ConnectorRuntimeException - When creation of pool fails.
      • deleteConnectorConnectionPool

        public void deleteConnectorConnectionPool​(PoolInfo poolInfo,
                                                  boolean cascade)
                                           throws ConnectorRuntimeException
        Deletes connector Connection pool. Here check in made whether resources pertaining to pool are present in domain.xml.
        Parameters:
        poolInfo - Name of the pool to delete
        cascade - If true all the resources associed with that are also deleted from connector container If false and if some resources pertaining to pool are present deletion operation fails . If no resources are present pool is deleted.
        Throws:
        ConnectorRuntimeException - if pool deletion operation fails
      • killPool

        public void killPool​(PoolInfo poolInfo)
        Kills a specific pool
        Parameters:
        poolInfo - poolName to kill
      • getConnectionDefinitionPropertiesAndDefaults

        public static Map<String,​Object> getConnectionDefinitionPropertiesAndDefaults​(String connectionDefinitionClassName,
                                                                                            String resType)
        Gets the properties of the Java bean connection definition class that have setter methods defined and the default values as provided by the Connection Definition java bean developer.
        Parameters:
        connectionDefinitionClassName - The Connection Definition Java bean class for which overrideable properties are required.
        Returns:
        Map String represents property name and Object is the defaultValue that is a primitive type or String
      • testConnectionPool

        public boolean testConnectionPool​(PoolInfo poolInfo)
                                   throws jakarta.resource.ResourceException
        asadmin test-connection-pool This method is used to provide backend functionality for the test-connection-pool asadmin command. Briefly the design is as follows:
        1. obtainManagedConnection for the poolname
        2. lookup ConnectorDescriptorInfo from InitialContext using poolname
        3. from cdi get username and password
        4. create ResourcePrincipal using default username and password
        5. create a Subject from this (doPriveleged)
        6. createManagedConnection using above subject
        7. getConnection from the ManagedConnection with above subject
        Parameters:
        poolInfo - connection-pool name
        Returns:
        true if the connection pool is healthy. false otherwise
        Throws:
        jakarta.resource.ResourceException - if pool is not usable
      • getDefaultSubject

        protected Subject getDefaultSubject​(PoolInfo poolInfo,
                                            jakarta.resource.spi.ManagedConnectionFactory mcf,
                                            ResourcePrincipal prin)
                                     throws jakarta.resource.ResourceException
        Utility method that is used to get the default subject for the specified mcf and resource principal.
        Parameters:
        poolInfo -
        mcf -
        prin -
        Returns:
        Throws:
        jakarta.resource.ResourceException
      • getManagedConnection

        protected jakarta.resource.spi.ManagedConnection getManagedConnection​(jakarta.resource.spi.ManagedConnectionFactory mcf,
                                                                              Subject defaultSubject,
                                                                              jakarta.resource.spi.ConnectionRequestInfo cReqInfo)
                                                                       throws jakarta.resource.ResourceException
        Utility method to get Managed connection from the supplied mcf and default subject.
        Parameters:
        mcf -
        defaultSubject -
        Returns:
        Throws:
        jakarta.resource.ResourceException
      • getUnpooledConnection

        public Object getUnpooledConnection​(PoolInfo poolInfo,
                                            ResourcePrincipal principal,
                                            boolean returnConnectionHandle)
                                     throws jakarta.resource.ResourceException
        This method is used to provide backend functionality for the ping-connection-pool asadmin command. Briefly the design is as follows:
        1. obtainManagedConnectionFactory for the poolname
        2. lookup ConnectorDescriptorInfo from InitialContext using poolname
        3. from cdi get username and password
        4. create ResourcePrincipal using default username and password
        5. create a Subject from this (doPriveleged)
        6. createManagedConnection using above subject
        7. add a dummy ConnectionEventListener to the mc that simply handles connectionClosed 8. getConnection from the ManagedConnection with above subject
        Parameters:
        poolInfo - The poolname from whose MCF to obtain the unpooled mc
        principal - The ResourcePrincipal to use for authenticating the request if not null. If null, the pool's default authentication mechanism is used
        returnConnectionHandle - If true will return the logical connection handle derived from the Managed Connection, else will only return mc
        Returns:
        an unPooled connection
        Throws:
        jakarta.resource.ResourceException - for various error conditions
      • getPropertyValue

        public String getPropertyValue​(String prop,
                                       ConnectorConnectionPool connectorConnectionPool)
        Utility method to get property value from ConnectorDescriptorInfo.
        Parameters:
        prop -
        Returns:
      • switchOnMatching

        public void switchOnMatching​(PoolInfo poolInfo)
                              throws ConnectorRuntimeException
        Rebinds the connection pool with matchning flag set.
        Parameters:
        poolInfo - pool for which matching need to be switched on
        Throws:
        ConnectorRuntimeException - , if a Naming error occurs.
      • obtainManagedConnectionFactories

        public jakarta.resource.spi.ManagedConnectionFactory[] obtainManagedConnectionFactories​(PoolInfo poolInfo)
                                                                                         throws ConnectorRuntimeException
        Returns the MCF instances.
        Parameters:
        poolInfo - Name of the pool.MCF pertaining to this pool is created/returned.
        Returns:
        created/already present MCF instance
        Throws:
        ConnectorRuntimeException - if creation/retrieval of MCF fails
      • obtainManagedConnectionFactory

        public jakarta.resource.spi.ManagedConnectionFactory obtainManagedConnectionFactory​(PoolInfo poolInfo,
                                                                                            Hashtable env)
                                                                                     throws ConnectorRuntimeException
        Returns the MCF instance. If the MCF is already created and present in connectorRegistry that instance is returned. Otherwise it is created explicitly and added to ConnectorRegistry.
        Parameters:
        poolInfo - Name of the pool.MCF pertaining to this pool is created/returned.
        Returns:
        created/already present MCF instance
        Throws:
        ConnectorRuntimeException - if creation/retrieval of MCF fails
      • isConnectorConnectionPoolDeployed

        public boolean isConnectorConnectionPoolDeployed​(PoolInfo poolInfo)
        Checks if a conncetor connection pool has been deployed to this server instance
        Parameters:
        poolInfo -
        Returns:
      • reconfigureConnectorConnectionPool

        public boolean reconfigureConnectorConnectionPool​(ConnectorConnectionPool ccp,
                                                          Set excludedProps)
                                                   throws ConnectorRuntimeException
        Reconfigure a connection pool. This method compares the passed connector connection pool with the one in memory. If the pools are unequal and the MCF properties are changed a pool recreate is required. However if the pools are unequal and the MCF properties are not changed a recreate is not required
        Parameters:
        ccp - - the Updated connector connection pool object that admin hands over
        excludedProps - - A set of excluded property names that we want to be excluded in the comparison check while comparing MCF properties
        Returns:
        true - if a pool restart is required, false otherwise
        Throws:
        ConnectorRuntimeException
      • recreateConnectorConnectionPool

        public void recreateConnectorConnectionPool​(ConnectorConnectionPool ccp)
                                             throws ConnectorRuntimeException
        Recreate a connector connection pool. This method essentially does the following things: 1. Delete the said connector connection pool
        2. Bind the pool to JNDI
        3. Create an MCF for this pool and register with the connector registry
        Parameters:
        ccp - - the ConnectorConnectionPool to publish
        Throws:
        ConnectorRuntimeException
      • createConnectorConnectionPool

        public void createConnectorConnectionPool​(ConnectorConnectionPool ccp,
                                                  String connectionDefinitionName,
                                                  String rarName,
                                                  List<Property> props,
                                                  List<SecurityMap> securityMaps)
                                           throws ConnectorRuntimeException
        Creates connector connection pool in the connector container.
        Parameters:
        ccp - ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
        connectionDefinitionName - Connection definition name against which connection pool is being created
        rarName - Name of the resource adapter
        props - Properties of MCF which are present in domain.xml These properties override the ones present in ra.xml
        securityMaps - Array fo security maps.
        Throws:
        ConnectorRuntimeException - When creation of pool fails.
      • getConnection

        public Connection getConnection​(ResourceInfo resourceInfo,
                                        String user,
                                        String password)
                                 throws SQLException
        Get a sql connection from the DataSource specified by the jdbcJndiName. This API is intended to be used in the DAS. The motivation for having this API is to provide the CMP backend a means of acquiring a connection during the codegen phase. If a user is trying to deploy an app on a remote server, without this API, a resource reference has to be present both in the DAS and the server instance. This makes the deployment more complex for the user since a resource needs to be forcibly created in the DAS Too. This API will mitigate this need.
        Parameters:
        resourceInfo - the jndi name of the resource being used to get Connection from This resource can either be a pmf resource or a jdbc resource
        user - the user used to authenticate this request
        password - the password used to authenticate this request
        Returns:
        a java.sql.Connection
        Throws:
        SQLException - in case of errors
      • getConnection

        public Connection getConnection​(ResourceInfo resourceInfo)
                                 throws SQLException
        Get a sql connection from the DataSource specified by the jdbcJndiName. This API is intended to be used in the DAS. The motivation for having this API is to provide the CMP backend a means of acquiring a connection during the codegen phase. If a user is trying to deploy an app on a remote server, without this API, a resource reference has to be present both in the DAS and the server instance. This makes the deployment more complex for the user since a resource needs to be forcibly created in the DAS Too. This API will mitigate this need.
        Parameters:
        resourceInfo - the jndi name of the resource being used to get Connection from This resource can either be a pmf resource or a jdbc resource
        Returns:
        a java.sql.Connection
        Throws:
        SQLException - in case of errors