Search

Chapter 17. Implementing the HA CEP server with a Maven repository for updating the KJAR service

download PDF

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

  1. Download the rhpam-7.11.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.11.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

    Upload the resulting KJAR and any required dependencies to the Maven repository.

  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. In the springboot directory, edit the pom.xml file to remove the following dependency:

    <dependency>
          <groupId>org.kie</groupId>
          <artifactId>sample-hacep-project-kjar</artifactId>
    </dependency>
  10. 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
  11. 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}}'
  12. Open the kubernetes/deployment.yaml file in a text editor.
  13. Replace the existing image URL with the result of the previous command.
  14. 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
  15. Under the containers: line and the env: 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 the MAVEN_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”.

  16. Save the file.
  17. 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.

Note

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.

Table 17.1. Optional environment variables supported by the HA CEP server
NameDescriptionExample

MAVEN_LOCAL_REPO

Directory to use as the local Maven repository.

/root/.m2/repository

MAVEN_MIRROR_URL

The base URL of a Maven mirror that can be used for retrieving artifacts.

http://nexus3-my-kafka-project.192.168.99.133.nip.io/repository/maven-public/

MAVEN_MIRRORS

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 MAVEN_MIRROR_* variables must contain a prefix, for example, DEV_MAVEN_MIRROR_URL and QE_MAVEN_MIRROR_URL

DEV,QE

MAVEN_REPOS

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 MAVEN_REPO_* variables must contain a prefix, for example, DEV_MAVEN_REPO_URL and QE_MAVEN_REPO_URL.

DEV,QE

MAVEN_SETTINGS_XML

The location of a custom Maven settings.xml file to use

/root/.m2/settings.xml

prefix_MAVEN_MIRROR_ID

Identifier to be used for the specified mirror. If omitted, a unique ID is generated.

internal-mirror

prefix_MAVEN_MIRROR_OF

Repository IDs mirrored by this mirror. Defaults to external:*

external:*,!my-repo

prefix_MAVEN_MIRROR_URL

The URL of the mirror

http://10.0.0.1:8080/repository/internal

prefix_MAVEN_REPO_HOST

Maven repository host name

repo.example.com

prefix_MAVEN_REPO_ID

Maven repository ID

my-repo

prefix_MAVEN_REPO_LAYOUT

Maven repository layout

default

prefix_MAVEN_REPO_USERNAME

Maven repository username

mavenUser

prefix_MAVEN_REPO_PASSPHRASE

Maven repository passphrase

maven1!

prefix_MAVEN_REPO_PASSWORD

Maven repository password

maven1!

prefix_MAVEN_REPO_PATH

Maven repository path

/maven2/

prefix_MAVEN_REPO_PORT

Maven repository port

8080

prefix_MAVEN_REPO_PRIVATE_KEY

Local path to a private key for connecting to the Maven repository

${user.home}/.ssh/id_dsa

prefix_MAVEN_REPO_PROTOCOL

Maven repository protocol

http

prefix_MAVEN_REPO_RELEASES_ENABLED

Maven repository releases enabled

true

prefix_MAVEN_REPO_RELEASES_UPDATE_POLICY

Maven repository releases update policy

always

prefix_MAVEN_REPO_SERVICE

Maven repository OpenShift service. This value is used if a URL or host/port/protocol is not specified.

buscentr-myapp

prefix_MAVEN_REPO_SNAPSHOTS_ENABLED

Maven repository snapshots enabled

true

prefix_MAVEN_REPO_SNAPSHOTS_UPDATE_POLICY

Maven repository snapshots update policy

always

prefix_MAVEN_REPO_URL

Fully qualified URL for the Maven repository

http://repo.example.com:8080/maven2/

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.