Setup Java local profile

Prerequisites

At this point it is assumed, that the initial setup and the mandatory commands of the Solution CLI have been performed and executed as described here.

Follow the steps below if you want to test a Java project locally:

There are two configuration approaches to start your project locally:

  • Have a valid deployed project and use its k8s configuration maps to load bindings for MongoDB and Kafka

  • Provide configuration values to connect to your local MongoDB and Kafka broker

Attention: If you choose to use deployed project k8s configuration maps, you need to log in to your OpenShift cluster via oc CLI and run proper oc proxy command to be able to connect to your OpenShift namespace MongoDB and Kafka clusters.

Local Setup

  1. Use application-local.template.yaml to create an application-local.yaml file and override properties needed for the local profile.

  2. Depending on which configuration approach from above add either your OpenShift k5-project namespace or a dummy namespace mock value

    de:
      knowis:
        cp:
          consumer:
            kubernetes:
              namespace: <k5-Project>
  3. Add your service project acronym

    solution:
       acronym : "project acronym"
  4. To enable / disable some auto configuration features

      feature:
        kafka-events:
          enabled: true
        mongo:
          enabled: true
        security:
          enabled: true
        openapi:
          enabled: true
        webmvc:
          enabled: true
  5. Load MongoDB configuration from k8s configuration map

    spring:
      data:
        mongodb:
           secretName: # read from kubernetes secret
  6. To access local MongoDB, you can set the spring.data.mongodb.uri property to change the URL and configure additional settings such as the replica set, as shown in the following example:

    spring:
      data:
        mongodb:
          uri: mongodb://<username>:<secret>@<host>:<port>/<database>

    Alternatively, you can specify connection details using discrete properties. For example, you might declare the following settings as shown below:

    spring:
      data:
        mongodb:
          host: <host>
          port: <port>
          database: <database>
          username: <username>
          password: <password>
  7. Load event topic binding configuration from k8s secret(s)

    1. You need to add your k5-project name in step 2.

    2. You need to have proper oc proxy and oc port forwarding to be able to access your OpenShift k5 project event topic binding secret(s) and their configured Kafka cluster.

  8. Alternatively, you can configure to use your Kafka broker and your own local topic binding secret(s).

    1. Install and configure your Kafka broker see https://kafka.apache.org/quickstart

    2. For each topic add proper event topic binding configuration like below

    de.knowis.cp.binding.topic:
      topicBindings:
        <Topic 1>: 
          topicName: "<Kafka topic name>"
          kafkaBinding: "<Kafka-Secret-1>"
        <Topic 2>: 
          topicName: "<Kafka topic name>"
          kafkaBinding: "<Kafka-Secret-2>"
      kafkaBindings:
        <Kafka-Secret-1>:
          kafka_brokers_sasl: ""
          password: ""
          user: ""
        <Kafka-Secret-2>:
          kafka_brokers_sasl: ""
          password: ""
          user: ""  
Note: Kafka broker user and password are optional if your Kafka broker is not secured.
  1. To configure Swagger UI for local development, use the settings below:

    springdoc:
      api-docs:
        enabled: true
        path: /<solutionAcronym>/api-docs
      swagger-ui:
        oauth:
          clientId: <client-id>
  2. If you have spring-security-oauth2-client on your classpath, you can take advantage of some autoconfiguration to set up an OAuth2/Open ID Connect client, as shown in the following example:

    spring:
      security:
        oauth2:
          client:
            registration:
              my-client-1:
                client-id: <client-id>
                client-secret: <secret>
                client-name: <client-for-user-scope>
            provider: 
              <provider-name>:
                scope: <scope>
                redirect-uri: <redirect-url>
                client-authentication-method: <authentication-type>
                authorization-grant-type: <grant-type>
            provider:
              oidc-provider:
                issuer-uri: <issuer-url>
  3. Build and run the code. Pass the configuration below in jvm arguments to use the local profile.

    -Dspring.profiles.active=local
Note: Refer to Spring Boot's official documentation for more details on MongoDB and Kafka additional configuration.