Class VinciCasProcessorDeployer
java.lang.Object
org.apache.uima.collection.impl.cpm.container.deployer.vinci.VinciCasProcessorDeployer
- All Implemented Interfaces:
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)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ServiceProxyPool
The cas processor pool.static final String
The Constant CONN_RETRY_COUNT.private CPEFactory
The cpe factory.private ArrayList
The current service list.static final int
The Constant DEFAULT_SERVICE_PORT.static final int
The Constant DEFAULT_SERVICE_PORT_RANGE.static final String
The Constant DEFAULT_VNS_PORT.static final String
The Constant LOCAL_VNS.private Thread
The local VNS thread.static final int
The Constant MAX_WAIT_TRIES.private final Object
The monitor.private static BoundedWorkQueue
The port queue.private int
The restart count.static final int
The Constant SLEEP_TIME.private static LocalVNS
The vns.static final int
The Constant WAIT_TIME. -
Constructor Summary
ConstructorsConstructorDescriptionVinciCasProcessorDeployer
(CPEFactory aCpeFactory) Instantiaes the class and gives it access to CPE configuration. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
activateProcessor
(CasProcessorConfiguration aCasProcessorConfig, 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, 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, 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.deployCasProcessor
(List aCasProcessorList, boolean redeploy) Deploys CasProcessors in a provided List.deployCasProcessor
(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 ArrayList
getNewServiceList
(String aServiceUri, CasProcessorConfiguration aCasProcessorConfig) Query configured VNS for a list of services with a given service URI.private VinciServiceInfo
getNextAvailable
(ArrayList aServiceList) Gets the next available.private 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 String
getServiceUri
(CasProcessorConfiguration aCasProcessorConfig) Returns CasProcessor service name from a descriptor.private ResourceSpecifier
getSpecifier
(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
(URL aDescriptorUrl) Returns URISpecifier.private String
getVNSSettingFor
(String aVNSParamKey, CasProcessorConfiguration aCasProcessorConfig, 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
-
Field Details
-
LOCAL_VNS
The Constant LOCAL_VNS.- See Also:
-
WAIT_TIME
public static final int WAIT_TIMEThe Constant WAIT_TIME.- See Also:
-
MAX_WAIT_TRIES
public static final int MAX_WAIT_TRIESThe Constant MAX_WAIT_TRIES.- See Also:
-
CONN_RETRY_COUNT
The Constant CONN_RETRY_COUNT.- See Also:
-
DEFAULT_VNS_PORT
The Constant DEFAULT_VNS_PORT.- See Also:
-
DEFAULT_SERVICE_PORT
public static final int DEFAULT_SERVICE_PORTThe Constant DEFAULT_SERVICE_PORT.- See Also:
-
DEFAULT_SERVICE_PORT_RANGE
public static final int DEFAULT_SERVICE_PORT_RANGEThe Constant DEFAULT_SERVICE_PORT_RANGE.- See Also:
-
SLEEP_TIME
public static final int SLEEP_TIMEThe Constant SLEEP_TIME.- See Also:
-
casProcessorPool
The cas processor pool. -
localVNSThread
The local VNS thread. -
vns
The vns. -
restartCount
private int restartCountThe restart count. -
portQueue
The port queue. -
cpeFactory
The cpe factory. -
monitor
The monitor. -
currentServiceList
The current service list.
-
-
Constructor Details
-
VinciCasProcessorDeployer
Instantiaes the class and gives it access to CPE configuration.- Parameters:
aCpeFactory
- the a cpe factory
-
-
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 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(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
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, 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 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:
Exception
- - error
-
getNextAvailable
Gets the next available.- Parameters:
aServiceList
- the a service list- Returns:
- the next available
-
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 endpointaCasProcessorConfig
- - 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
Returns URISpecifier.- Parameters:
aDescriptorUrl
- the a descriptor url- Returns:
- URISpecifier
- Throws:
ResourceConfigurationException
- if the resource specifier in the URI is not a URISpecifier
-
getSpecifier
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, 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 configurationaHost
- the a hostaPort
- the a portaProcessingContainer
- the a processing containerredeploy
- the redeploy- Returns:
- Connected proxy to service
- Throws:
ResourceConfigurationException
- wraps ExceptionException
- 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 configurationaService
- - name of the vinci serviceaProcessingContainer
- the a processing containerredeploy
- the redeploy- 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 proxyaProcessingContainer
- the a processing containerredeploy
- the redeploy- Throws:
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 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 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 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:
ConnectException
- - unable to establish connection to Cas Processor
-
getPort
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:
TimeLimitExceededException
- timeout waiting for port
-
undeploy
Shutdown local VNS.- Specified by:
undeploy
in interfaceCasProcessorDeployer
- Throws:
CasProcessorDeploymentException
- the cas processor deployment exception
-
undeploy
- Specified by:
undeploy
in interfaceCasProcessorDeployer
- Throws:
CasProcessorDeploymentException
-