Class VinciCasProcessorDeployer

java.lang.Object
org.apache.uima.collection.impl.cpm.container.deployer.vinci.VinciCasProcessorDeployer
All Implemented Interfaces:
CasProcessorDeployer

public class VinciCasProcessorDeployer extends 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 Details

    • Constructor Details

      • VinciCasProcessorDeployer

        public VinciCasProcessorDeployer(CPEFactory aCpeFactory)
        Instantiaes the class and gives it access to CPE configuration.
        Parameters:
        aCpeFactory -
    • Method Details

      • deployCasProcessor

        public ProcessingContainer deployCasProcessor(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
        redeploy - - true when redeploying failed Cas Processor
        Returns:
        - ProcessingContainer containing pool of CasProcessors
        Throws:
        ResourceConfigurationException
      • deployCasProcessor

        public void deployCasProcessor(ProcessingContainer aProcessingContainer) throws ResourceConfigurationException
        Deploys CasProcessor using configuration from provided container. This method is used for re-launching failed Cas Processor.
        Specified by:
        deployCasProcessor in interface CasProcessorDeployer
        Parameters:
        aProcessingContainer - - container for deployed CasProcessor.
        Throws:
        ResourceConfigurationException - - failed to deploy Cas Processor
      • deployCasProcessor

        public ProcessingContainer deployCasProcessor(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 - - failed to deploy Cas Processor
      • 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:
        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 -
        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, String aServiceUri, int howMany, ProcessingContainer aProcessingContainer) throws 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:
        Exception - - error
      • getNextAvailable

        private VinciServiceInfo getNextAvailable(ArrayList aServiceList)
      • getNewServiceList

        private ArrayList getNewServiceList(String aServiceUri, CasProcessorConfiguration aCasProcessorConfig) throws 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:
        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
      • getServiceUri

        private String getServiceUri(CasProcessorConfiguration aCasProcessorConfig) throws ResourceConfigurationException
        Returns CasProcessor service name from a descriptor.
        Parameters:
        aCasProcessorConfig - - CasProcessor configuration containing service descriptor path
        Returns:
        - name of the service
        Throws:
        ResourceConfigurationException - if the uri is missing or empty
      • getURISpecifier

        private URISpecifier getURISpecifier(URL aDescriptorUrl) throws ResourceConfigurationException
        Returns URISpecifier
        Parameters:
        aFileName -
        Returns:
        URISpecifier
        Throws:
        ResourceConfigurationException - if the resource specifier in the URI is not a URISpecifier
      • getSpecifier

        private ResourceSpecifier getSpecifier(URL aUrl) throws ResourceConfigurationException
        Parses given service descriptor and returns initialized ResourceSpecifier
        Parameters:
        aUrl - - URL of the descriptor
        Returns:
        - ResourceSpecifier parsed from descriptor
        Throws:
        ResourceConfigurationException - wraps Exception
      • deployVNS

        private void deployVNS(CasProcessorConfiguration casProcessorConfig, boolean redeploy) throws CasProcessorDeploymentException
        Deploys internal VNS for use with local CasProcessor deployments
        Parameters:
        casProcessorConfig - - CasProcessor configuration
        redeploy - - flag indicating if VNS being redeployed
        Throws:
        CasProcessorDeploymentException - wraps Exception
      • activateProcessor

        private boolean activateProcessor(CasProcessorConfiguration aCasProcessorConfig, String aHost, int aPort, ProcessingContainer aProcessingContainer, boolean redeploy) throws ResourceConfigurationException, 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
        port - - port wher vinci service is listening
        Returns:
        Connected proxy to service
        Throws:
        ResourceConfigurationException - wraps Exception
        Exception - passthru
      • activateProcessor

        private boolean activateProcessor(CasProcessorConfiguration aCasProcessorConfig, String aService, ProcessingContainer aProcessingContainer, boolean redeploy) throws 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
        Returns:
        - connected Proxy
        Throws:
        Exception - passthru
      • bindProxyToNetworkCasProcessor

        private void bindProxyToNetworkCasProcessor(VinciTAP aTap, ProcessingContainer aProcessingContainer, boolean redeploy) throws Exception
        Associates connected proxy with an instance of CasProcessor.
        Parameters:
        aTap - - connected proxy
        Throws:
        Exception
      • getTextAnalysisProxy

        private VinciTAP getTextAnalysisProxy(CasProcessorConfiguration aCasProcessorConfig) throws ResourceConfigurationException
        Creates and initializes proxy that will be used to connect to Vinci service
        Parameters:
        aCasProcessorConfig - - CasProcessor configuration
        Returns:
        - new proxy (not yet connected to service)
        Throws:
        ResourceConfigurationException - wraps Exception
      • getVNSSettingFor

        private String getVNSSettingFor(String aVNSParamKey, CasProcessorConfiguration aCasProcessorConfig, 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 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:
        casProcessorConfig - - CasProcessor configuration
        redeploy - - flag indicating if if this is restart
        howMany - - indicates how many connections to make
        Throws:
        ConnectException - - unable to establish connection to Cas Processor
      • getPort

        private String getPort(BoundedWorkQueue portQueue) throws 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 portQueueinvalid input: '<'/>.
        Parameters:
        portQueue - - queue containing ports assigned to services by local VNS
        Returns:
        - port as String
        Throws:
        TimeLimitExceededException - timeout waiting for port
      • undeploy

        public void undeploy() throws CasProcessorDeploymentException
        Shutdown local VNS.
        Specified by:
        undeploy in interface CasProcessorDeployer
        Throws:
        CasProcessorDeploymentException
      • undeploy

        public void undeploy(URL aURL) throws CasProcessorDeploymentException
        Specified by:
        undeploy in interface CasProcessorDeployer
        Throws:
        CasProcessorDeploymentException