Class VinciCasProcessorDeployer

  • All Implemented Interfaces:
    CasProcessorDeployer

    public class VinciCasProcessorDeployer
    extends java.lang.Object
    implements CasProcessorDeployer
    Reference implementation of CasProcessorDeployer This component enables the CPE to deploy Cas Processors running as a Vinci service. Two deployment models are supported in the current implementation:
    • managed deployment (aka local)
    • unmanaged deployment (aka remote)
    Managed deployment gives the CPE control over the life cycle of the Cas Processor. The CPE starts, restarts and shuts down the Cas Processor running as a Vinci service. This service is launched on the same machine as the CPE but in a seperate process. Unmanaged deployment does not provide the CPE control over the Cas Processor that may be running on a remote machine. The CPE assumes that such Cas Processor is managed by a separate application and is always available. For the managed deployment the CPE uses its internal VNS (Vinci Naming Service) to which Cas Processor must connect to. The VNS issues a port for the Cas Processor to run on and creates a proxy to it. For unmanaged Cas Processor the CPE creates a proxy to remote service. The remote Cas Processor service is discovered with help of VNS running on a host and port defined in the Cpe descriptor for this Cas Processor.
    • Field Detail

      • LOCAL_VNS

        public static final java.lang.String LOCAL_VNS
        The Constant LOCAL_VNS.
        See Also:
        Constant Field Values
      • MAX_WAIT_TRIES

        public static final int MAX_WAIT_TRIES
        The Constant MAX_WAIT_TRIES.
        See Also:
        Constant Field Values
      • CONN_RETRY_COUNT

        public static final java.lang.String CONN_RETRY_COUNT
        The Constant CONN_RETRY_COUNT.
        See Also:
        Constant Field Values
      • DEFAULT_VNS_PORT

        public static final java.lang.String DEFAULT_VNS_PORT
        The Constant DEFAULT_VNS_PORT.
        See Also:
        Constant Field Values
      • DEFAULT_SERVICE_PORT

        public static final int DEFAULT_SERVICE_PORT
        The Constant DEFAULT_SERVICE_PORT.
        See Also:
        Constant Field Values
      • DEFAULT_SERVICE_PORT_RANGE

        public static final int DEFAULT_SERVICE_PORT_RANGE
        The Constant DEFAULT_SERVICE_PORT_RANGE.
        See Also:
        Constant Field Values
      • SLEEP_TIME

        public static final int SLEEP_TIME
        The Constant SLEEP_TIME.
        See Also:
        Constant Field Values
      • casProcessorPool

        private ServiceProxyPool casProcessorPool
        The cas processor pool.
      • localVNSThread

        private java.lang.Thread localVNSThread
        The local VNS thread.
      • vns

        private static volatile LocalVNS vns
        The vns.
      • restartCount

        private int restartCount
        The restart count.
      • cpeFactory

        private CPEFactory cpeFactory
        The cpe factory.
      • monitor

        private final java.lang.Object monitor
        The monitor.
      • currentServiceList

        private java.util.ArrayList currentServiceList
        The current service list.
    • Constructor Detail

      • VinciCasProcessorDeployer

        public VinciCasProcessorDeployer​(CPEFactory aCpeFactory)
        Instantiaes the class and gives it access to CPE configuration.
        Parameters:
        aCpeFactory - the a cpe factory
    • Method Detail

      • deployCasProcessor

        public ProcessingContainer deployCasProcessor​(java.util.List aCasProcessorList,
                                                      CPMEngine aEngine,
                                                      boolean redeploy)
                                               throws ResourceConfigurationException
        Deploys integrated Cas Processor. Number of instances this routine actually deploys depends on number of processing threads defined in the CPE descriptor. There is one instance per processing thread created here. The aCasProcessorList contains instantiated Cas Processors. These are instantiated by the CPEFactory.
        Parameters:
        aCasProcessorList - - list containing instantiated Cas Processors
        aEngine - the a engine
        redeploy - - true when redeploying failed Cas Processor
        Returns:
        - ProcessingContainer containing pool of CasProcessors
        Throws:
        ResourceConfigurationException - the resource configuration exception
      • deployCasProcessor

        public ProcessingContainer deployCasProcessor​(java.util.List aCasProcessorList,
                                                      boolean redeploy)
                                               throws ResourceConfigurationException
        Deploys CasProcessors in a provided List. The List contains instances of Cas Processors that are not yet bound to a vinci service. To do anything usefull, the Cas Processor must be deployed first. The process of deploying a proxy depends on the deployment mode defined in the cpe descriptor. In case of managed Cas Processor, the deployment consists of launching the vinci service and creating a connection to it. For un-managed Cas Processor the CPE establishes the connection.
        Specified by:
        deployCasProcessor in interface CasProcessorDeployer
        Parameters:
        aCasProcessorList - - list of CasProcessors to deploy
        redeploy - - true if intent is to redeploy failed service
        Returns:
        ProcessinContainer - instance of Container
        Throws:
        ResourceConfigurationException - the resource configuration exception
      • deployBasedOnModel

        private void deployBasedOnModel​(ProcessingContainer aProcessingContainer,
                                        CasProcessorConfiguration aCasProcessorConfig,
                                        boolean redeploy)
                                 throws ResourceConfigurationException
        Deploys CasProcessor according to configured deployment mode.
        Parameters:
        aProcessingContainer - - container managing instances of CasProcessor
        aCasProcessorConfig - - CasProcessor configuration
        redeploy - - flag indicating if this re-deployment of CasProcessor that failed
        Throws:
        ResourceConfigurationException - if unknown deployment type
      • deployLocal

        private void deployLocal​(ProcessingContainer aProcessingContainer,
                                 boolean redeploy)
                          throws ResourceConfigurationException
        Deploys CasProcessor as a Local Vinci Service. The CPE will launch the Cas Processor in a separate process but on the same machine. The CPE will manage the life-cycle of the Cas Processor including shutdown. Shutdown command will be sent when the CPE completes processing. In this deployment mode the CPE uses its own VNS. The VNS information (host and port) will be added as command line arguments to the program being launched (Cas Processor application). It is the responsibility of the Cas Processor to to read this information and use it to locate VNS the CPE is managing.
        Parameters:
        aProcessingContainer - - container object that will hold proxies to Cas Processor when it is launched
        redeploy - - true if intent is to redeploy failed service
        Throws:
        ResourceConfigurationException - if the descriptor is invalid or for any internal Exception (wrapped)
      • associateMetadataWithContainer

        private void associateMetadataWithContainer​(ProcessingContainer aProcessingContainer)
        Retrieve the metadata from the service and add it to the container.
        Parameters:
        aProcessingContainer - - container where the metadata will be saved
      • launchLocalService

        private void launchLocalService​(ProcessingContainer aProcessingContainer,
                                        CasProcessorConfiguration casProcessorConfig,
                                        boolean redeploy,
                                        int howMany)
                                 throws CasProcessorDeploymentException
        Launches an application as a seperate process using java's Process object. Actually, it launches as many copies of the application as given in the howMany parameter.
        Parameters:
        aProcessingContainer - the a processing container
        casProcessorConfig - - Configuration containing start up command
        redeploy - - true if intent is to redeploy failed application
        howMany - - how many seperate process to spawn
        Throws:
        CasProcessorDeploymentException - wraps any exception
      • deployIntegrated

        private void deployIntegrated​(ProcessingContainer aProcessingContainer,
                                      boolean redeploy)
                               throws ResourceConfigurationException
        No-op for integrated deployment. Integrated CasProcessors are instantiated using UIMA framework factory in the CPEFactory.
        Parameters:
        aProcessingContainer - the a processing container
        redeploy - the redeploy
        Throws:
        ResourceConfigurationException - tbd
      • deployRemote

        private void deployRemote​(ProcessingContainer aProcessingContainer,
                                  boolean redeploy)
                           throws ResourceConfigurationException
        Deploys CasProcessor as a remote/network service. In this case, the CPE does not manage life-cycle of the Cas Processor. The CPE in this case simply creates a proxy to the remote Cas Processor via provided VNS. The exact VNS used here is defined on per Cas Processor in the cpe descriptor.
        Parameters:
        aProcessingContainer - - container that will manage instances of the CasProcessor
        redeploy - - flag indicating if this redeployment of failed CasProcessor
        Throws:
        ResourceConfigurationException - wraps exception
      • attachToServices

        private int attachToServices​(boolean redeploy,
                                     java.lang.String aServiceUri,
                                     int howMany,
                                     ProcessingContainer aProcessingContainer)
                              throws java.lang.Exception
        Create and attach a proxies to vinci services. For services with exclusive access, makes sure that there is only one proxy per service. Otherwise the services are shared.
        Parameters:
        redeploy - - true if the connection is made as part of the recovery due to previous service crash or termination.
        aServiceUri - - servie uri, this is a vinci service name
        howMany - - how many proxies to create and connect
        aProcessingContainer - - hosting container for the proxies. Proxies are assigned to a pool managed by the container.
        Returns:
        - how many proxies were created
        Throws:
        java.lang.Exception - - error
      • getNextAvailable

        private VinciServiceInfo getNextAvailable​(java.util.ArrayList aServiceList)
        Gets the next available.
        Parameters:
        aServiceList - the a service list
        Returns:
        the next available
      • getNewServiceList

        private java.util.ArrayList getNewServiceList​(java.lang.String aServiceUri,
                                                      CasProcessorConfiguration aCasProcessorConfig)
                                               throws java.lang.Exception
        Query configured VNS for a list of services with a given service URI.
        Parameters:
        aServiceUri - - named service endpoint
        aCasProcessorConfig - - Cas Processor configuration
        Returns:
        - List of services provided by VNS
        Throws:
        java.lang.Exception - passthru
      • handleMaxRestartThresholdReached

        private void handleMaxRestartThresholdReached​(ProcessingContainer aProcessingContainer)
                                               throws ResourceConfigurationException
        Handles situation when max restart threshold is reached while connecting to CasProcessor.
        Parameters:
        aProcessingContainer - - container holding CasProcessor configuration
        Throws:
        ResourceConfigurationException - when max restarts limit reached
      • activateProcessor

        private boolean activateProcessor​(CasProcessorConfiguration aCasProcessorConfig,
                                          java.lang.String aHost,
                                          int aPort,
                                          ProcessingContainer aProcessingContainer,
                                          boolean redeploy)
                                   throws ResourceConfigurationException,
                                          java.lang.Exception
        Creates a proxy and connects it to Vinci service running on a given port. Once connected the proxy is associated with Cas Processor.
        Parameters:
        aCasProcessorConfig - - CasProcessor configuration
        aHost - the a host
        aPort - the a port
        aProcessingContainer - the a processing container
        redeploy - the redeploy
        Returns:
        Connected proxy to service
        Throws:
        ResourceConfigurationException - wraps Exception
        java.lang.Exception - passthru
      • activateProcessor

        private boolean activateProcessor​(CasProcessorConfiguration aCasProcessorConfig,
                                          java.lang.String aService,
                                          ProcessingContainer aProcessingContainer,
                                          boolean redeploy)
                                   throws java.lang.Exception
        Creates a proxy and connects it to Vinci service. Uses VNS to locate service by name.
        Parameters:
        aCasProcessorConfig - - CasProcees configuration
        aService - - name of the vinci service
        aProcessingContainer - the a processing container
        redeploy - the redeploy
        Returns:
        - connected Proxy
        Throws:
        java.lang.Exception - passthru
      • bindProxyToNetworkCasProcessor

        private void bindProxyToNetworkCasProcessor​(VinciTAP aTap,
                                                    ProcessingContainer aProcessingContainer,
                                                    boolean redeploy)
                                             throws java.lang.Exception
        Associates connected proxy with an instance of CasProcessor.
        Parameters:
        aTap - - connected proxy
        aProcessingContainer - the a processing container
        redeploy - the redeploy
        Throws:
        java.lang.Exception - the exception
      • getVNSSettingFor

        private java.lang.String getVNSSettingFor​(java.lang.String aVNSParamKey,
                                                  CasProcessorConfiguration aCasProcessorConfig,
                                                  java.lang.String aDefault)
                                           throws ResourceConfigurationException
        Returns a value for a named VNS parameter (either VNS_HOST or VNS_PORT). The parameter is resolved with the following priority: 1) Find the parameter in the Service descriptor 2) Find the parameter in the CPE descriptor 3) Find the parameter as System.property (using -D on the command line) 4) Use Hardcoded default ( VNS_HOST=localhost VNS_PORT=9000)
        Parameters:
        aVNSParamKey - - name of the VNS parameter for which the value is sought
        aCasProcessorConfig - - CPE descriptor settings
        aDefault - - default value for the named parameter if parameter is not defined
        Returns:
        - value for a named VNS parameter
        Throws:
        ResourceConfigurationException - passthru
      • connectToServices

        private void connectToServices​(ProcessingContainer aProcessingContainer,
                                       CasProcessorConfiguration casProcessorConfig,
                                       boolean redeploy,
                                       int howMany)
                                throws java.net.ConnectException
        This method is used during a launch of the local or managed Cas Processor. Here connections to Cas Processors running as vinci services are made. Connections are established to services whose ports are provided in the portQueue. Whenever a managed Cas Processor starts up, it contacts local vns and is assigned a port to run on. The same port is added to the port queue and used here for establishing a connection.
        Parameters:
        aProcessingContainer - the a processing container
        casProcessorConfig - - CasProcessor configuration
        redeploy - - flag indicating if if this is restart
        howMany - - indicates how many connections to make
        Throws:
        java.net.ConnectException - - unable to establish connection to Cas Processor
      • getPort

        private java.lang.String getPort​(BoundedWorkQueue portQueue)
                                  throws javax.naming.TimeLimitExceededException
        Used during a launch of the managed (local) Cas Processor this method returns a port number on which the Cas Processor is waiting for requests. Each Cas Processor was a given a port by the local vns where it is expected to accept requests from clients. The ports assigned to Cas Processors are managed by the local instance of the VNS and available in the queue portQueue.
        Parameters:
        portQueue - - queue containing ports assigned to services by local VNS
        Returns:
        - port as String
        Throws:
        javax.naming.TimeLimitExceededException - timeout waiting for port