ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.68k stars 752 forks source link

[Task]: Implement sample Synapse API to Ballerina service mapping #43527

Open HindujaB opened 2 weeks ago

HindujaB commented 2 weeks ago

Description

$subject

Describe your task(s)

No response

Related area

-> Runtime

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

HindujaB commented 1 week ago

Update: A sample implementation was done to generate a Ballerina HTTP service from synapse API with the use of following.

Identified concerns:

HindujaB commented 5 days ago

[Update on 08/11/2024]

listener http:Listener HealthcareAPI = new (8290, config = {host: "localhost"});

service /healthcare on HealthcareAPI { resource function post categories/[string category]/reserve(http:Caller caller, http:Request req) returns error? { json payload = check req.getJsonPayload(); string Hospital = check payload.hospital; http:Response res; match Hospital { "grand oak community hospital" => { log:printInfo("", message = "Routing to " + Hospital); http:Client GrandOakEP = check new (string http://localhost:9090/grandoaks/categories/${category}/reserve); res = check GrandOakEP->post("", req); } "pine valley community hospital" => { log:printInfo("", message = "Routing to " + Hospital); http:Client PineValleyEP = check new (string http://localhost:9090/pinevalley/categories/${category}/reserve); res = check PineValleyEP->post("", req); } "clemency medical center" => { log:printInfo("", message = "Routing to " + Hospital); http:Client ClemencyEP = check new (string http://localhost:9090/clemency/categories/${category}/reserve); res = check ClemencyEP->post("", req); } _ => { log:printInfo("", message = "Invalid hospital - " + Hospital); res = new; res.setPayload(payload); } } check caller->respond(res); } }


- Verified the mappability of the `Property` mediator & `Log` mediator
- Analysed the expression configuration and equivalent Ballerina functionality

| Expressions          | Reference                                                                                         | Ballerina construct                               |
|----------------------|---------------------------------------------------------------------------------------------------|---------------------------------------------------|
| Variables            | https://mi.docs.wso2.com/en/latest/reference/synapse-properties/expressions/#variables            | Ballerina variable retrieval                      |
| Functions            | https://mi.docs.wso2.com/en/latest/reference/synapse-properties/expressions/#functions            | Need specific library function calls              |
| JSONPath expressions | https://mi.docs.wso2.com/en/latest/reference/synapse-properties/expressions/#jsonpath-expressions | json navigation expressions                       |
| XPath expressions    | https://mi.docs.wso2.com/en/latest/reference/synapse-properties/expressions/#xpath-expressions    | XML navigation expressions with query expressions |

- Identified several gaps
    - Type conversion in ballerina needs to be handled ( if there is no `type` parameter is present)
    - Synapse `scope` concept is not directly mappable ( https://mi.docs.wso2.com/en/latest/reference/synapse-properties/scopes/)
    - Error handling needs to be handled separately (Fault sequence, other runtime exceptions)