Chapter 2. Implementing the HA CEP server

The high-availability (HA) CEP server runs on the Red Hat OpenShift Container Platform environment. It includes all necessary Drools rules and other code required to process events.

Prepare the source, build it, and then deploy it on Red Hat OpenShift Container Platform.

Alternatively, use a different process to deploy the HA CEP server where you can update the KJAR service at any time. For instructions about this process, see Chapter 3, Implementing the HA CEP server with a Maven repository for updating the KJAR service.

Prerequisites

  • You are logged into the project with administrator privilege using the oc command-line tool.

Procedure

  1. Download the rhpam-7.7.0-reference-implementation.zip product deliverable file from the Software Downloads page of the Red Hat Customer Portal.
  2. Extract the contents of the file and then uncompress the rhpam-7.7.0-openshift-drools-hacep-distribution.zip file.
  3. Change to the openshift-drools-hacep-distribution/sources directory.
  4. 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 the src/main/resources/org/drools/cep subdirectory.
  5. Build the project using the standard Maven command:

    mvn clean install -DskipTests
  6. 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.
  7. 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
  8. 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.

  9. Use the oc command to detect the valid values for the user ID and group ID that you must set in the Docker file. Enter the following command:

    oc describe project <projectname>

    In this command, replace <projectname> with the name of your project.

    In the output of the command, find lines that list supplemental-groups and uid-range, similar to the following example:

    openshift.io/sa.scc.supplemental-groups=1000160000/10000
    openshift.io/sa.scc.uid-range=1000160000/10000
  10. In the springboot directory, edit the Dockerfile file. Find the following line:

    RUN groupadd -r app -g <id_group> && useradd -u <id_user> -r -g app -m -d /app -s /sbin/nologin -c "App user" app && chmod 755 /app----

    In this line, replace <id_group> with a value in the supplemental-groups interval and <id_user> with a value in the uid-range interval:

    RUN groupadd -r app -g 1000160001 && useradd -u 1000160001 -r -g app -m -d /app -s /sbin/nologin -c "App user" app && chmod 755 /app
  11. 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
  12. 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}}'
  13. Open the kubernetes/deployment.yaml file in a text editor.
  14. Replace <id_user> with the user ID that you entered in the Docker file.
  15. Replace the existing image URL with the result of the previous command.
  16. 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
  17. Save the file.
  18. Enter the following command to deploy the image:

    oc apply -f kubernetes/deployment.yaml