Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Add Beans support #1721

Closed
igarashitm opened this issue May 2, 2023 · 2 comments · Fixed by #1827
Closed

Add Beans support #1721

igarashitm opened this issue May 2, 2023 · 2 comments · Fixed by #1827
Assignees
Labels
code editor Relates to the code editor enhancement Improve existing features
Milestone

Comments

@igarashitm
Copy link
Contributor

igarashitm commented May 2, 2023

Please describe the feature that you want to propose

Support loading this YAML route. Currently it's wiped out when sync button is clicked.

YAML source

- from:
    uri: 'netty-http:http://0.0.0.0:8080:'
    steps:
    - to:
        uri: sql:select * from actor
        parameters:
          dataSource: '#dataSource'
    - marshal:
        json:
          library: Jackson
- beans:
  - name: dataSource
    type: org.postgresql.ds.PGSimpleDataSource
    properties:
      serverName: 127.0.0.1
      portNumber: '5432'
      databaseName: dvdrental
      user: user
      password: password
  - name: someBean
    type: io.kaoto.test.backend.api.service.step.parser.camelroute.SomeBean
    properties:
      someProperty: someValue
      someObjectProperty:
        someObjectPropertyProperty: someObjectPropertyValue
        foo:
          bar: foobar

Returned Kaoto JSON

{
  "flows": [..snip..],
  "properties": {},
  "metadata": {
    "beans": [
      {
        "name": "dataSource",
        "type": "org.postgresql.ds.PGSimpleDataSource",
        "properties": {
          "serverName": "127.0.0.1",
          "portNumber": "5432",
          "databaseName": "dvdrental",
          "user": "user",
          "password": "password"
        }
      },
      {
        "name": "someBean",
        "type": "io.kaoto.test.backend.api.service.step.parser.camelroute.SomeBean",
        "properties": {
          "someProperty": "someValue",
          "someObjectProperty": {
            "someObjectPropertyProperty": "someObjectPropertyValue"
          }
        }
      }
    ]
  }
}

This issue is to just support the source code. UI for bean configuration has to be addressed in a separate issue (#1722). At this point the frontend needs to keep the beans in the background without rendering anything on the canvas, and use it only when it talks to the backend.

Note that the type of /beans/properties is object. It has to allow arbitrary properties including object, for example

- beans:
  - name: exampleBean
    type: org.example.some.Type
    properties:
      someProp: var
      someObject:
        some3rdObject:
          some3rdPbojectProp: foo
@igarashitm igarashitm added the enhancement Improve existing features label May 2, 2023
@igarashitm igarashitm self-assigned this May 2, 2023
@lhein lhein added this to the 1.1.0 milestone May 4, 2023
@igarashitm
Copy link
Contributor Author

igarashitm commented May 10, 2023

Compatibility issue: key/value style property on Kamelet and Integration

Although it is against schema, runtime allows key/value style of beans property. Even official Kamelets use this style ATM.
apache/camel-kamelets#1475

      - name: dsBean
        type: "#class:org.apache.commons.dbcp2.BasicDataSource"
        property:
          - key: username
            value: '{{username}}'
          - key: password
            value: '{{password}}'

We might go with what schema allows at a first step, then consider loading this old style property and convert to the valid one.

Currently Kaoto backend only supports key/value style for Kamelet beans

apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: telegram-text-source e"
spec:
  template: 
    beans:
      - name: myBean
        type: com.acme.MyBean
        property:
           - key: foo
             value: bar
    from:
      uri: direct:start
      steps:
        - process: "myBean"

It's in the metadata in Kaoto integration JSON

{
  "steps": [
    {
      "name": "direct",
      "type": "START",
      "id": "direct-consumer",
      "kind": "Camel-Connector",
      "icon": "...",
      "title": "Direct",
      "description": "Call another endpoint from the same Camel Context synchronously.",
      "group": "Camel-Component",
      "parameters": [
      ...
      ],
      "required": [
        "name"
      ],
      "branches": null,
      "minBranches": 0,
      "maxBranches": 0,
      "stepId": null,
      "UUID": null
    }
  ],
  "metadata": {
    "labels": {
      "camel.apache.org/kamelet.type": "action"
    },
    "annotations": {
      "camel.apache.org/kamelet.icon": "...",
      "icon": "..."
    },
    "additionalProperties": {},
    "name": "telegram-text-source e\"-action",
    "definition": {
      "title": null,
      "description": "",
      "required": null,
      "properties": {}
    },
    "beans": [
      {
        "name": "myBean",
        "type": "com.acme.MyBean",
        "property": [
          {
            "key": "foo",
            "value": "bar"
          }
        ]
      }
    ],
    "dependencies": [
      "camel:core",
      "camel:direct"
    ]
  },
  "parameters": [],
  "dsl": "Kamelet"
}

@igarashitm
Copy link
Contributor Author

igarashitm commented May 10, 2023

As opposed to the Kamelet which has beans locally to the Kamelet, on Camel Route, it's CamelContext level, which spans over multiple routes. We will need metadata right under FlowWrapper as well for this purpose.
https://github.com/KaotoIO/kaoto-backend/blob/main/api/src/main/java/io/kaoto/backend/api/resource/model/FlowsWrapper.java#L13

@lordrip lordrip added the code editor Relates to the code editor label May 10, 2023
Delawen pushed a commit to kaoto-archive/kaoto-backend that referenced this issue May 16, 2023
The backend side of source code level beans support for Camel Route. Verify frontend side once /v2/integrations is wired for source code sync.
igarashitm added a commit to igarashitm/kaoto-ui that referenced this issue May 22, 2023
With kaoto-archive/kaoto-backend#659, now the `beans` definition pasted in YAML code editor will be preserved.

Fixes: kaoto-archive#1721
igarashitm added a commit to igarashitm/kaoto-ui that referenced this issue May 22, 2023
With kaoto-archive/kaoto-backend#659, now the `beans` definition pasted in YAML code editor will be preserved.

Fixes: kaoto-archive#1721
igarashitm added a commit that referenced this issue May 23, 2023
With kaoto-archive/kaoto-backend#659, now the `beans` definition pasted in YAML code editor will be preserved.

Fixes: #1721
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
code editor Relates to the code editor enhancement Improve existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants