kaoto icon indicating copy to clipboard operation
kaoto copied to clipboard

Clean up `KameletResource` and `KameletVisualEntity` classes

Open lordrip opened this issue 6 months ago • 0 comments

Please describe the task that needs to be done

Context

As reported in #594, there's a situation that prevents the user from editing Kamelets.

This bug was caused due to a problem in the serialization of the KameletResource, because despite the Canvas Form editing the KameletVisualEntity correctly, what ultimately was serialized was the original Kamelet without changes. This is handled by #651.

This change opens up a more broad topic about Kamelets, at this moment, the KameletVisualEntity class knows the underlying flow (kamelet.spec.template.from) and its metadata (kamelet.metadata), and this shouldn't be the case.

Ideally, KameletVisualEntity would know the flow only but the issue with this is that it will close the possibility of renaming the flow, as the setId method is defined in the KameletVisualEntity class. A solution for this could be to create an intermediate setId functionality in the CamelResource interface itself which will later on delegate the change to the underlying VisualEntities.setId() method if necessary, this way, in case of Kamelets and Pipes, we have the chance to update its metadata and also the underlying flow.

In addition to that, it would be convenient to offer a mechanism to sort the properties of the underlying VisualEntities, this way we could sort the entire Kamelet in a kubernetes friendly way and also keep the underlying Camel Route sorted differently.

Proposed Changes

  • [ ] ~Create an intermediate method setId at the CamelResource class so we can apply the id change to the metadata properties and relay it to the underlying flow if applicable. This change will remove the need for the KameletVisualEntity class to know about the Kamelet's metadata and bring it closer to the original AbstractCamelVisualEntity class.~
  • [ ] ~Remove the metadata properties and other customizations of the KameletVisualEntity class and create a toJSON method that returns the from property so it can be better incorporated into the serializing flow.~
  • [ ] Receive the entire Kamelet definition in the KameletVisualEntity and adapt the toJSON method in the KameletResource class to accommodate if something is needed. The KameletVisualEntity class needs the entire definition to be able to provide a configuration panel for its different metadata properties.
  • [ ] Change the current "Rename a flow" path, from the existing "Rename the flow using the flow itself" towards "asking the Resource to change the name of one of its flows" instead. Note: This might not be needed if we have the entire kamelet definition in the KameletVisualEntity

lordrip avatar Jan 17 '24 10:01 lordrip