Class VinciCasProcessorDeployer
- java.lang.Object
-
- org.apache.uima.collection.impl.cpm.container.deployer.vinci.VinciCasProcessorDeployer
-
- All Implemented Interfaces:
CasProcessorDeployer
public class VinciCasProcessorDeployer extends java.lang.Object implements CasProcessorDeployer
Reference implementation ofCasProcessorDeployer
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)
-
-
Field Summary
Fields Modifier and Type Field Description private ServiceProxyPool
casProcessorPool
The cas processor pool.static java.lang.String
CONN_RETRY_COUNT
The Constant CONN_RETRY_COUNT.private CPEFactory
cpeFactory
The cpe factory.private java.util.ArrayList
currentServiceList
The current service list.static int
DEFAULT_SERVICE_PORT
The Constant DEFAULT_SERVICE_PORT.static int
DEFAULT_SERVICE_PORT_RANGE
The Constant DEFAULT_SERVICE_PORT_RANGE.static java.lang.String
DEFAULT_VNS_PORT
The Constant DEFAULT_VNS_PORT.static java.lang.String
LOCAL_VNS
The Constant LOCAL_VNS.private java.lang.Thread
localVNSThread
The local VNS thread.static int
MAX_WAIT_TRIES
The Constant MAX_WAIT_TRIES.private java.lang.Object
monitor
The monitor.private static BoundedWorkQueue
portQueue
The port queue.private int
restartCount
The restart count.static int
SLEEP_TIME
The Constant SLEEP_TIME.private static LocalVNS
vns
The vns.static int
WAIT_TIME
The Constant WAIT_TIME.
-
Constructor Summary
Constructors Constructor Description VinciCasProcessorDeployer(CPEFactory aCpeFactory)
Instantiaes the class and gives it access to CPE configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
activateProcessor(CasProcessorConfiguration aCasProcessorConfig, java.lang.String aHost, int aPort, ProcessingContainer aProcessingContainer, boolean redeploy)
Creates a proxy and connects it to Vinci service running on a given port.private boolean
activateProcessor(CasProcessorConfiguration aCasProcessorConfig, java.lang.String aService, ProcessingContainer aProcessingContainer, boolean redeploy)
Creates a proxy and connects it to Vinci service.private void
associateMetadataWithContainer(ProcessingContainer aProcessingContainer)
Retrieve the metadata from the service and add it to the container.private int
attachToServices(boolean redeploy, java.lang.String aServiceUri, int howMany, ProcessingContainer aProcessingContainer)
Create and attach a proxies to vinci services.private void
bindProxyToNetworkCasProcessor(VinciTAP aTap, ProcessingContainer aProcessingContainer, boolean redeploy)
Associates connected proxy with an instance of CasProcessor.private void
connectToServices(ProcessingContainer aProcessingContainer, CasProcessorConfiguration casProcessorConfig, boolean redeploy, int howMany)
This method is used during a launch of the local or managed Cas Processor.private void
deployBasedOnModel(ProcessingContainer aProcessingContainer, CasProcessorConfiguration aCasProcessorConfig, boolean redeploy)
Deploys CasProcessor according to configured deployment mode.ProcessingContainer
deployCasProcessor(java.util.List aCasProcessorList, boolean redeploy)
Deploys CasProcessors in a provided List.ProcessingContainer
deployCasProcessor(java.util.List aCasProcessorList, CPMEngine aEngine, boolean redeploy)
Deploys integrated Cas Processor.void
deployCasProcessor(ProcessingContainer aProcessingContainer)
Deploys CasProcessor using configuration from provided container.private void
deployIntegrated(ProcessingContainer aProcessingContainer, boolean redeploy)
No-op for integrated deployment.private void
deployLocal(ProcessingContainer aProcessingContainer, boolean redeploy)
Deploys CasProcessor as a Local Vinci Service.private void
deployRemote(ProcessingContainer aProcessingContainer, boolean redeploy)
Deploys CasProcessor as a remote/network service.private void
deployVNS(CasProcessorConfiguration casProcessorConfig, boolean redeploy)
Deploys internal VNS for use with local CasProcessor deployments.private java.util.ArrayList
getNewServiceList(java.lang.String aServiceUri, CasProcessorConfiguration aCasProcessorConfig)
Query configured VNS for a list of services with a given service URI.private VinciServiceInfo
getNextAvailable(java.util.ArrayList aServiceList)
Gets the next available.private java.lang.String
getPort(BoundedWorkQueue portQueue)
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.private java.lang.String
getServiceUri(CasProcessorConfiguration aCasProcessorConfig)
Returns CasProcessor service name from a descriptor.private ResourceSpecifier
getSpecifier(java.net.URL aUrl)
Parses given service descriptor and returns initialized ResourceSpecifier.private VinciTAP
getTextAnalysisProxy(CasProcessorConfiguration aCasProcessorConfig)
Creates and initializes proxy that will be used to connect to Vinci service.private URISpecifier
getURISpecifier(java.net.URL aDescriptorUrl)
Returns URISpecifier.private java.lang.String
getVNSSettingFor(java.lang.String aVNSParamKey, CasProcessorConfiguration aCasProcessorConfig, java.lang.String aDefault)
Returns a value for a named VNS parameter (either VNS_HOST or VNS_PORT).private void
handleMaxRestartThresholdReached(ProcessingContainer aProcessingContainer)
Handles situation when max restart threshold is reached while connecting to CasProcessor.private void
launchLocalService(ProcessingContainer aProcessingContainer, CasProcessorConfiguration casProcessorConfig, boolean redeploy, int howMany)
Launches an application as a seperate process using java's Process object.void
undeploy()
Shutdown local VNS.void
undeploy(java.net.URL aURL)
-
-
-
Field Detail
-
LOCAL_VNS
public static final java.lang.String LOCAL_VNS
The Constant LOCAL_VNS.- See Also:
- Constant Field Values
-
WAIT_TIME
public static final int WAIT_TIME
The Constant WAIT_TIME.- 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.
-
portQueue
private static BoundedWorkQueue portQueue
The port queue.
-
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 ProcessorsaEngine
- the a engineredeploy
- - true when redeploying failed Cas Processor- Returns:
- - ProcessingContainer containing pool of CasProcessors
- Throws:
ResourceConfigurationException
- the resource configuration exception
-
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 interfaceCasProcessorDeployer
- Parameters:
aProcessingContainer
- - container for deployed CasProcessor.- 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 interfaceCasProcessorDeployer
- Parameters:
aCasProcessorList
- - list of CasProcessors to deployredeploy
- - 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 CasProcessoraCasProcessorConfig
- - CasProcessor configurationredeploy
- - 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 launchedredeploy
- - 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 containercasProcessorConfig
- - Configuration containing start up commandredeploy
- - true if intent is to redeploy failed applicationhowMany
- - 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 containerredeploy
- 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 CasProcessorredeploy
- - 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 namehowMany
- - how many proxies to create and connectaProcessingContainer
- - 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 endpointaCasProcessorConfig
- - 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
-
getServiceUri
private java.lang.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(java.net.URL aDescriptorUrl) throws ResourceConfigurationException
Returns URISpecifier.- Parameters:
aDescriptorUrl
- the a descriptor url- Returns:
- URISpecifier
- Throws:
ResourceConfigurationException
- if the resource specifier in the URI is not a URISpecifier
-
getSpecifier
private ResourceSpecifier getSpecifier(java.net.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 configurationredeploy
- - flag indicating if VNS being redeployed- Throws:
CasProcessorDeploymentException
- wraps Exception
-
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 configurationaHost
- the a hostaPort
- the a portaProcessingContainer
- the a processing containerredeploy
- the redeploy- Returns:
- Connected proxy to service
- Throws:
ResourceConfigurationException
- wraps Exceptionjava.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 configurationaService
- - name of the vinci serviceaProcessingContainer
- the a processing containerredeploy
- 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 proxyaProcessingContainer
- the a processing containerredeploy
- the redeploy- Throws:
java.lang.Exception
- the 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 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 soughtaCasProcessorConfig
- - CPE descriptor settingsaDefault
- - 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 containercasProcessorConfig
- - CasProcessor configurationredeploy
- - flag indicating if if this is restarthowMany
- - 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
-
undeploy
public void undeploy() throws CasProcessorDeploymentException
Shutdown local VNS.- Specified by:
undeploy
in interfaceCasProcessorDeployer
- Throws:
CasProcessorDeploymentException
- the cas processor deployment exception
-
undeploy
public void undeploy(java.net.URL aURL) throws CasProcessorDeploymentException
- Specified by:
undeploy
in interfaceCasProcessorDeployer
- Throws:
CasProcessorDeploymentException
-
-