Este conteúdo não está disponível no idioma selecionado.
Chapter 14. Implementing the HA CEP server with a Maven repository for updating the KJAR service
You can implement the HA CEP server that retrieves the KJAR service and all dependencies from a Maven repository that you provide. In this case, you can update the KJAR service at any time by updating it in the Maven repository and then making a call from the client code.
Prepare the source, build it, and then deploy it on Red Hat OpenShift Container Platform. Set certain environment variables in the deployment.yaml file before deploying the server. To use a Maven repository, you must set the UPDATABLEKJAR variable to true.
Prerequisites
-
You are logged into the project with administrator privilege using the
occommand-line tool. - You configured a Maven repository that is accessible from your Red Hat OpenShift Container Platform environment.
Procedure
-
Download the
rhdm-7.11.0-reference-implementation.zipproduct deliverable file from the Software Downloads page of the Red Hat Customer Portal. -
Extract the contents of the file and then uncompress the
rhdm-7.11.0-openshift-drools-hacep-distribution.zipfile. -
Change to the
openshift-drools-hacep-distribution/sourcesdirectory. -
Review and modify the server code based on the sample project in the
sample-hacep-project/sample-hacep-project-kjardirectory. The complex event processing logic is defined by the DRL rules in thesrc/main/resources/org/drools/cepsubdirectory. Build the project using the standard Maven command:
mvn clean install -DskipTests
mvn clean install -DskipTestsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Upload the resulting KJAR and any required dependencies to the Maven repository.
- Enable the OpenShift operator for Red Hat AMQ Streams and then create an AMQ Streams (kafka) cluster in the project. For information about installing Red Hat AMQ Streams, see Using AMQ Streams on OpenShift.
To create the kafka topics that are required for operation of the server, remain in the
openshift-drools-hacep-distribution/sourcesdirectory and run the following commands:oc apply -f kafka-topics/control.yaml oc apply -f kafka-topics/events.yaml oc apply -f kafka-topics/kiesessioninfos.yaml oc apply -f kafka-topics/snapshot.yaml
oc apply -f kafka-topics/control.yaml oc apply -f kafka-topics/events.yaml oc apply -f kafka-topics/kiesessioninfos.yaml oc apply -f kafka-topics/snapshot.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow In order to enable application access to the ConfigMap that is used in the leader election, configure role-based access control. Change to the
springbootdirectory and enter the following commands:oc create -f kubernetes/service-account.yaml oc create -f kubernetes/role.yaml oc create -f kubernetes/role-binding.yaml
oc create -f kubernetes/service-account.yaml oc create -f kubernetes/role.yaml oc create -f kubernetes/role-binding.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information about configuring role-based access control in Red Hat OpenShift Container Platform, see Using RBAC to define and apply permissions in the Red Hat OpenShift Container Platform product documentation.
In the
springbootdirectory, edit thepom.xmlfile to remove the following dependency:<dependency> <groupId>org.kie</groupId> <artifactId>sample-hacep-project-kjar</artifactId> </dependency><dependency> <groupId>org.kie</groupId> <artifactId>sample-hacep-project-kjar</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the
springbootdirectory, enter the following commands to create the image for deployment and push it into the repository configured for your OpenShift environment:oc new-build --binary --strategy=docker --name openshift-kie-springboot oc start-build openshift-kie-springboot --from-dir=. --follow
oc new-build --binary --strategy=docker --name openshift-kie-springboot oc start-build openshift-kie-springboot --from-dir=. --followCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enter the following command to detect the name of the image that was built:
oc get is/openshift-kie-springboot -o template --template='{{range .status.tags}}{{range .items}}{{.dockerImageReference}}{{end}}{{end}}'oc get is/openshift-kie-springboot -o template --template='{{range .status.tags}}{{range .items}}{{.dockerImageReference}}{{end}}{{end}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
kubernetes/deployment.yamlfile in a text editor. - Replace the existing image URL with the result of the previous command.
Remove all characters at the end of the line starting with the
@symbol, then add:latestto the line. For example:image: image-registry.openshift-image-registry.svc:5000/hacep/openshift-kie-springboot:latest
image: image-registry.openshift-image-registry.svc:5000/hacep/openshift-kie-springboot:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow Under the
containers:line and theenv:line, set environment variables as in the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, replace the value of the
KJARGAVvariable with the group, artifact, and version (GAV) of your KJAR service and the value of theMAVEN_MIRROR_URLvariable with the URL to the Maven repository that contains your KJAR service.Optionally, set other variables. For a list of supported environment variables, see Section 14.1, “Optional environment variables supported by the HA CEP server”.
- Save the file.
Enter the following command to deploy the image:
oc apply -f kubernetes/deployment.yaml
oc apply -f kubernetes/deployment.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
For instructions about triggering a KJAR update from the client code, see Chapter 15, Creating the HA CEP client.
14.1. Optional environment variables supported by the HA CEP server Copiar o linkLink copiado para a área de transferência!
The following table lists optional environment variables that you can set for an HA CEP server that is configured to use a Maven repository. Add these variables to the deployment.yaml file to set them at deployment time.
To use a Maven repository, ensure that you set the UPDATABLEKJAR and KJARGAV environment variables for the server, as described in Chapter 14, Implementing the HA CEP server with a Maven repository for updating the KJAR service.
| Name | Description | Example |
|---|---|---|
|
| Directory to use as the local Maven repository. |
|
|
| The base URL of a Maven mirror that can be used for retrieving artifacts. |
|
|
|
If set, multi-mirror support is enabled. The value contains a list of mirror prefixes, divided by commas. If this variable is set, the names of other |
|
|
|
If set, multi-repo support is enabled. The value contains a list of repo prefixes, divided by commas. If this variable is set, the names of other |
|
|
|
The location of a custom Maven |
|
|
| Identifier to be used for the specified mirror. If omitted, a unique ID is generated. |
|
|
|
Repository IDs mirrored by this mirror. Defaults to |
|
|
| The URL of the mirror |
|
|
| Maven repository host name |
|
|
| Maven repository ID |
|
|
| Maven repository layout |
|
|
| Maven repository username |
|
|
| Maven repository passphrase |
|
|
| Maven repository password |
|
|
| Maven repository path |
|
|
| Maven repository port |
|
|
| Local path to a private key for connecting to the Maven repository |
|
|
| Maven repository protocol |
|
|
| Maven repository releases enabled |
|
|
| Maven repository releases update policy |
|
|
| Maven repository OpenShift service. This value is used if a URL or host/port/protocol is not specified. |
|
|
| Maven repository snapshots enabled |
|
|
| Maven repository snapshots update policy |
|
|
| Fully qualified URL for the Maven repository |
|