Chapter 17. 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
oc
command-line tool. - You configured a Maven repository that is accessible from your Red Hat OpenShift Container Platform environment.
Procedure
-
Download the
rhpam-7.9.1-reference-implementation.zip
product deliverable file from the Software Downloads page of the Red Hat Customer Portal. -
Extract the contents of the file and then uncompress the
rhpam-7.9.1-openshift-drools-hacep-distribution.zip
file. -
Change to the
openshift-drools-hacep-distribution/sources
directory. -
Review and modify the server code based on the sample project in the
sample-hacep-project/sample-hacep-project-kjar
directory. The complex event processing logic is defined by the DRL rules in thesrc/main/resources/org/drools/cep
subdirectory. Build the project using the standard Maven command:
mvn clean install -DskipTests
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/sources
directory 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
In order to enable application access to the ConfigMap that is used in the leader election, configure role-based access control. Change to the
springboot
directory 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
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
springboot
directory, edit thepom.xml
file to remove the following dependency:<dependency> <groupId>org.kie</groupId> <artifactId>sample-hacep-project-kjar</artifactId> </dependency>
In the
springboot
directory, 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
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}}'
-
Open the
kubernetes/deployment.yaml
file 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:latest
to the line. For example:image: image-registry.openshift-image-registry.svc:5000/hacep/openshift-kie-springboot:latest
Under the
containers:
line and theenv:
line, set environment variables as in the following example:containers: - env: - name: UPDATABLEKJAR value: "true" - name: KJARGAV value: <GroupID>:<ArtifactID>:<Version> - name: MAVEN_LOCAL_REPO value: /app/.m2/repository - name: MAVEN_MIRROR_URL value: http://<nexus_url>/repository/maven-releases/ - name: MAVEN_SETTINGS_XML value: /app/.m2/settings.xml
In this example, replace the value of the
KJARGAV
variable with the group, artifact, and version (GAV) of your KJAR service and the value of theMAVEN_MIRROR_URL
variable 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 17.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
For instructions about triggering a KJAR update from the client code, see Chapter 18, Creating the HA CEP client.
17.1. Optional environment variables supported by the HA CEP server
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 17, 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 |
|