Class VinciCasProcessorDeployer
java.lang.Object
org.apache.uima.collection.impl.cpm.container.deployer.vinci.VinciCasProcessorDeployer
- All Implemented Interfaces:
CasProcessorDeployer
Reference implementation of
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.
CasProcessorDeployer
This
component enables the CPE to deploy Cas Processors running as a Vinci service. Two deployment
models are supported in the current implementation:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ServiceProxyPool
static final String
private CPEFactory
private ArrayList
static final int
static final int
static final String
static final String
private Thread
static final int
private final Object
private static BoundedWorkQueue
private int
static final int
private static LocalVNS
static final int
-
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 containerprivate 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 deploymentsprivate ArrayList
getNewServiceList
(String aServiceUri, CasProcessorConfiguration aCasProcessorConfig) Query configured VNS for a list of services with a given service URIprivate VinciServiceInfo
getNextAvailable
(ArrayList aServiceList) 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 ResourceSpecifierprivate VinciTAP
getTextAnalysisProxy
(CasProcessorConfiguration aCasProcessorConfig) Creates and initializes proxy that will be used to connect to Vinci serviceprivate URISpecifier
getURISpecifier
(URL aDescriptorUrl) Returns URISpecifierprivate 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
- See Also:
-
WAIT_TIME
public static final int WAIT_TIME- See Also:
-
MAX_WAIT_TRIES
public static final int MAX_WAIT_TRIES- See Also:
-
CONN_RETRY_COUNT
- See Also:
-
DEFAULT_VNS_PORT
- See Also:
-
DEFAULT_SERVICE_PORT
public static final int DEFAULT_SERVICE_PORT- See Also:
-
DEFAULT_SERVICE_PORT_RANGE
public static final int DEFAULT_SERVICE_PORT_RANGE- See Also:
-
SLEEP_TIME
public static final int SLEEP_TIME- See Also:
-
casProcessorPool
-
localVNSThread
-
vns
-
restartCount
private int restartCount -
portQueue
-
cpeFactory
-
monitor
-
currentServiceList
-
-
Constructor Details
-
VinciCasProcessorDeployer
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 Processorsredeploy
- - 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 interfaceCasProcessorDeployer
- 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 interfaceCasProcessorDeployer
- Parameters:
aCasProcessorList
- - list of CasProcessors to deployredeploy
- - 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 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:
casProcessorConfig
- - 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
-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
-
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:
aFileName
-- 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 configurationport
- - port wher vinci service is listening- 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 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 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:
casProcessorConfig
- - 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
-
undeploy
- Specified by:
undeploy
in interfaceCasProcessorDeployer
- Throws:
CasProcessorDeploymentException
-