From a645486a613c28ec091dde24bc3af8474f94c79f Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 11 Aug 2025 23:06:07 +0530 Subject: [PATCH 01/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ca328b2..184d944 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.12.3" +distribution-version = "2201.12.0" [[package]] org = "ballerina" @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.1" +version = "2.14.3" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.0" +version = "2.14.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From 7d8f3d056af5cb25da6c342f913a20f0bdafbf4a Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 13 Aug 2025 13:48:18 +0530 Subject: [PATCH 02/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 184d944..ca17e8c 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.0" +version = "1.1.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} From 5fdd43758f425c762f38558cac5bf1e23675613c Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 13 Aug 2025 14:33:48 +0530 Subject: [PATCH 03/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ca17e8c..6d284be 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.1" +version = "1.1.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.3" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.1" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From 67819edcdd1439e095615a6c776aed10aa9546fb Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 13 Aug 2025 14:40:38 +0530 Subject: [PATCH 04/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 6d284be..ca17e8c 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.0" +version = "1.1.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.0" +version = "2.14.3" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.0" +version = "2.14.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From 9b2c690b5896d77382c77c3a2a8468c807d723b3 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 13 Aug 2025 14:43:30 +0530 Subject: [PATCH 05/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ca17e8c..98ee753 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -111,6 +111,9 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} ] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] [[package]] org = "ballerina" @@ -305,6 +308,7 @@ version = "1.1.0" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, {org = "ballerina", name = "mime"}, From 791175ad291201dca0cf0104ad487ec5080a3515 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 13 Aug 2025 16:39:05 +0530 Subject: [PATCH 06/22] Add feature to update existing service in the catalog --- ballerina/service.bal | 67 +++++++++++++++++++++++++++++++++++++++++++ ballerina/utils.bal | 8 ++++++ 2 files changed, 75 insertions(+) diff --git a/ballerina/service.bal b/ballerina/service.bal index 634ba90..75944a5 100644 --- a/ballerina/service.bal +++ b/ballerina/service.bal @@ -56,6 +56,18 @@ function publishArtifacts(ServiceArtifact[] artifacts) returns error? { return apimClient; } + Service[]|error services = retrieveAllExisitingservices(apimClient, artifacts); + if services is error { + log:printError("Error occurred while retrieving existing services: ", services); + return services; + } + + error? removeResult = removeExistingServices(apimClient, services); + if removeResult is error { + log:printError("Error occurred while removing existing services: ", removeResult); + return removeResult; + } + error? e = (); foreach ServiceArtifact artifact in artifacts { Service|error res = apimClient->/services.post({ @@ -99,3 +111,58 @@ function getServerCert(string? serverCert) returns http:ClientSecureSocket? { } return {enable: false}; } + +function retrieveAllExisitingservices(Client apimClient, ServiceArtifact[] artifacts) returns Service[]|error { + Service[] services = []; + string serviceKeys = getCommaSeparatedServiceKeys(artifacts); + boolean isFirstIteration = true; + string? next = (); + int offset = 0; + int 'limit = 25; + while isFirstIteration || next != "" { + isFirstIteration = false; + ServiceList|error serviceList = apimClient->/services(key = serviceKeys, offset = offset, 'limit = 'limit); + if serviceList is error { + log:printError("Error occurred while retrieving existing services: ", serviceList); + return serviceList; + } + + Service[]? fetchedServices = serviceList.list; + Pagination? pagination = serviceList.pagination; + if fetchedServices != () { + services.push(...fetchedServices); + } + + if pagination == () { + next = ""; + continue; + } + + string? nextResult = pagination.next; + if nextResult == () { + next = ""; + continue; + } + + offset += 'limit; + next = nextResult; + } + + return services; +} + +function removeExistingServices(Client apimClient, Service[] services) returns error? { + foreach Service serviceObject in services { + string? id = serviceObject.id; + if id == () { + log:printInfo("Service ID is not available for service: " + serviceObject.serviceKey.toBalString()); + continue; + } + + http:Response|error response = apimClient->/services/[id].delete(); + if response is error { + log:printError("Error occurred while deleting existing service: ", response); + return response; + } + } +} diff --git a/ballerina/utils.bal b/ballerina/utils.bal index 7837721..c27c17a 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -250,3 +250,11 @@ isolated function createBodyParts(record {|anydata...;|} anyRecord, map Date: Wed, 13 Aug 2025 16:40:40 +0530 Subject: [PATCH 07/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 98ee753..ca17e8c 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -111,9 +111,6 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} ] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] [[package]] org = "ballerina" @@ -308,7 +305,6 @@ version = "1.1.0" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, {org = "ballerina", name = "mime"}, From d021b11228e2ca3aca1e5ea2d8a7435571421cd1 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 13 Aug 2025 16:42:38 +0530 Subject: [PATCH 08/22] Update lang version in dependencies toml --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ca17e8c..30bbced 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.12.0" +distribution-version = "2201.12.7" [[package]] org = "ballerina" From 5e29d2b3ad8e108e42ce2c04444373fe8765fb98 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 13 Aug 2025 17:00:26 +0530 Subject: [PATCH 09/22] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index ed13d09..00b32cc 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerinax" name = "wso2.apim.catalog" -version = "1.1.0" +version = "1.1.1" distribution = "2201.12.0" [platform.java21] @@ -10,8 +10,8 @@ graalvmCompatible = true [[platform.java21.dependency]] groupId = "io.ballerina" artifactId = "wso2.apim.catalog-native" -version = "1.1.0" -path = "../native/build/libs/wso2.apim.catalog-native-1.1.0.jar" +version = "1.1.1" +path = "../native/build/libs/wso2.apim.catalog-native-1.1.1-SNAPSHOT.jar" [[platform.java21.dependency]] groupId = "com.fasterxml.jackson.core" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 31bc218..f90f7e0 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,7 +3,7 @@ id = "wso2.apim.catalog-compiler-plugin" class = "io.ballerina.wso2.apim.catalog.ServiceCatalogCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/wso2.apim.catalog-compiler-plugin-1.1.0.jar" +path = "../compiler-plugin/build/libs/wso2.apim.catalog-compiler-plugin-1.1.1-SNAPSHOT.jar" [[dependency]] path = "lib/ballerina-to-openapi-2.0.3.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 30bbced..a78d18b 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.12.7" +distribution-version = "2201.12.0" [[package]] org = "ballerina" @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.1" +version = "1.1.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.3" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.1" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -301,7 +301,7 @@ modules = [ [[package]] org = "ballerinax" name = "wso2.apim.catalog" -version = "1.1.0" +version = "1.1.1" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, From 5acfc6d1aa05be382a676a5b35874d16467457dd Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 14 Aug 2025 13:40:58 +0530 Subject: [PATCH 10/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index a78d18b..793b4e8 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.0" +version = "1.1.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.0" +version = "2.14.3" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.0" +version = "2.14.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From 613b63a0a4bcddab3691dc8eb85605df66e25c91 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 14 Aug 2025 16:44:18 +0530 Subject: [PATCH 11/22] Update update service functionality --- ballerina/service.bal | 19 ++++--------------- ballerina/utils.bal | 9 ++------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/ballerina/service.bal b/ballerina/service.bal index 75944a5..c8c71a5 100644 --- a/ballerina/service.bal +++ b/ballerina/service.bal @@ -115,12 +115,9 @@ function getServerCert(string? serverCert) returns http:ClientSecureSocket? { function retrieveAllExisitingservices(Client apimClient, ServiceArtifact[] artifacts) returns Service[]|error { Service[] services = []; string serviceKeys = getCommaSeparatedServiceKeys(artifacts); - boolean isFirstIteration = true; - string? next = (); int offset = 0; int 'limit = 25; - while isFirstIteration || next != "" { - isFirstIteration = false; + while true { ServiceList|error serviceList = apimClient->/services(key = serviceKeys, offset = offset, 'limit = 'limit); if serviceList is error { log:printError("Error occurred while retrieving existing services: ", serviceList); @@ -133,19 +130,11 @@ function retrieveAllExisitingservices(Client apimClient, ServiceArtifact[] artif services.push(...fetchedServices); } - if pagination == () { - next = ""; - continue; - } - - string? nextResult = pagination.next; - if nextResult == () { - next = ""; - continue; + if pagination?.next == () { + break; } offset += 'limit; - next = nextResult; } return services; @@ -155,7 +144,7 @@ function removeExistingServices(Client apimClient, Service[] services) returns e foreach Service serviceObject in services { string? id = serviceObject.id; if id == () { - log:printInfo("Service ID is not available for service: " + serviceObject.serviceKey.toBalString()); + log:printWarn("Service ID is not available for service: " + serviceObject.serviceKey.toBalString()); continue; } diff --git a/ballerina/utils.bal b/ballerina/utils.bal index c27c17a..0c6421b 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -251,10 +251,5 @@ isolated function createBodyParts(record {|anydata...;|} anyRecord, map + string:'join(",", ...from ServiceArtifact artifact in artifacts select artifact.serviceKey); From 78c1f9fdedec4d84c57dabecbd269bf06696ad16 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 18 Aug 2025 09:39:41 +0530 Subject: [PATCH 12/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 793b4e8..a78d18b 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.1" +version = "1.1.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.3" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.1" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From e54275bee99ed766cb9572016743c28069c49a67 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 18 Aug 2025 10:16:07 +0530 Subject: [PATCH 13/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index a78d18b..793b4e8 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.0" +version = "1.1.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.0" +version = "2.14.3" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.0" +version = "2.14.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From 666242f5fb541ceb87bee2e1b084b73be2b618f2 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 18 Aug 2025 10:33:30 +0530 Subject: [PATCH 14/22] Update the pagination logic --- ballerina/service.bal | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ballerina/service.bal b/ballerina/service.bal index c8c71a5..c163872 100644 --- a/ballerina/service.bal +++ b/ballerina/service.bal @@ -130,7 +130,8 @@ function retrieveAllExisitingservices(Client apimClient, ServiceArtifact[] artif services.push(...fetchedServices); } - if pagination?.next == () { + string? next = pagination?.next; + if next == () || next == "" { break; } From 19bfe1e8b89e3bab49261539bb1789ccf692e6b0 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 18 Aug 2025 13:09:13 +0530 Subject: [PATCH 15/22] Add service removal when user stops the services --- ballerina/listener.bal | 4 +++- ballerina/service.bal | 54 +++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/ballerina/listener.bal b/ballerina/listener.bal index 8ddd7b7..2bfd59d 100644 --- a/ballerina/listener.bal +++ b/ballerina/listener.bal @@ -17,14 +17,16 @@ public class Listener { int port; public function 'start() returns error? { - ServiceArtifact[] artifacts = getArtifacts(); + artifacts = getArtifacts(); check publishArtifacts(artifacts); } public function gracefulStop() returns error? { + check findAndRemoveExistingServices(apimClient, artifacts); } public function immediateStop() returns error? { + check findAndRemoveExistingServices(apimClient, artifacts); } public function detach(service object {} s) returns error? { diff --git a/ballerina/service.bal b/ballerina/service.bal index c163872..b0e142e 100644 --- a/ballerina/service.bal +++ b/ballerina/service.bal @@ -33,41 +33,26 @@ configurable string[] scopes = ["service_catalog:service_view", "apim:api_view", listener Listener 'listener = new Listener(port); +Client apimClient = check new (serviceUrl = serviceUrl, config = { + auth: { + username, + tokenUrl, + password, + clientId, + clientSecret, + scopes, + clientConfig: getClientConfig(clientSecureSocketpath, clientSecureSocketpassword) + }, + secureSocket: getServerCert(serverCert) +}); + +ServiceArtifact[] artifacts = []; + service / on 'listener { } function publishArtifacts(ServiceArtifact[] artifacts) returns error? { - Client|error apimClient = new (serviceUrl = serviceUrl, config = { - auth: { - username, - tokenUrl, - password, - clientId, - clientSecret, - scopes, - clientConfig: getClientConfig(clientSecureSocketpath, clientSecureSocketpassword) - }, - secureSocket: getServerCert(serverCert) - }); - - if apimClient is error { - log:printError("Error occurred while creating the client: ", apimClient); - return apimClient; - } - - Service[]|error services = retrieveAllExisitingservices(apimClient, artifacts); - if services is error { - log:printError("Error occurred while retrieving existing services: ", services); - return services; - } - - error? removeResult = removeExistingServices(apimClient, services); - if removeResult is error { - log:printError("Error occurred while removing existing services: ", removeResult); - return removeResult; - } - error? e = (); foreach ServiceArtifact artifact in artifacts { Service|error res = apimClient->/services.post({ @@ -156,3 +141,12 @@ function removeExistingServices(Client apimClient, Service[] services) returns e } } } + +function findAndRemoveExistingServices(Client apimClient, ServiceArtifact[] artifacts) returns error? { + Service[]|error existingServices = retrieveAllExisitingservices(apimClient, artifacts); + if existingServices is error { + return existingServices; + } + + return removeExistingServices(apimClient, existingServices); +} From 8b8adf22ef8d7ca724cb6c406483263e7bf15606 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 18 Aug 2025 14:24:29 +0530 Subject: [PATCH 16/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 793b4e8..a78d18b 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.1" +version = "1.1.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.3" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.1" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From c3daae84a158809c3205bc74bca4e519e9131348 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 18 Aug 2025 14:29:49 +0530 Subject: [PATCH 17/22] Add functionality to store service ids --- ballerina/Dependencies.toml | 6 ++-- ballerina/listener.bal | 11 ++----- ballerina/service.bal | 66 ++++++++----------------------------- ballerina/utils.bal | 3 -- 4 files changed, 19 insertions(+), 67 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index a78d18b..793b4e8 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.0" +version = "1.1.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.0" +version = "2.14.3" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.0" +version = "2.14.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, diff --git a/ballerina/listener.bal b/ballerina/listener.bal index 2bfd59d..3f4c18f 100644 --- a/ballerina/listener.bal +++ b/ballerina/listener.bal @@ -15,18 +15,17 @@ // under the License. public class Listener { - int port; public function 'start() returns error? { - artifacts = getArtifacts(); + ServiceArtifact[] artifacts = getArtifacts(); check publishArtifacts(artifacts); } public function gracefulStop() returns error? { - check findAndRemoveExistingServices(apimClient, artifacts); + check removeExistingServices(apimClient); } public function immediateStop() returns error? { - check findAndRemoveExistingServices(apimClient, artifacts); + check removeExistingServices(apimClient); } public function detach(service object {} s) returns error? { @@ -34,8 +33,4 @@ public class Listener { public function attach(service object {} s, string[]? name = ()) returns error? { } - - public function init(int port) { - self.port = port; - } } diff --git a/ballerina/service.bal b/ballerina/service.bal index b0e142e..8c6bb92 100644 --- a/ballerina/service.bal +++ b/ballerina/service.bal @@ -31,7 +31,9 @@ configurable string clientSecureSocketpassword = ""; configurable string? serverCert = (); configurable string[] scopes = ["service_catalog:service_view", "apim:api_view", "service_catalog:service_write"]; -listener Listener 'listener = new Listener(port); +listener Listener 'listener = new Listener(); + +final string[] publishedServiceIds = []; Client apimClient = check new (serviceUrl = serviceUrl, config = { auth: { @@ -46,12 +48,6 @@ Client apimClient = check new (serviceUrl = serviceUrl, config = { secureSocket: getServerCert(serverCert) }); -ServiceArtifact[] artifacts = []; - -service / on 'listener { - -} - function publishArtifacts(ServiceArtifact[] artifacts) returns error? { error? e = (); foreach ServiceArtifact artifact in artifacts { @@ -73,7 +69,15 @@ function publishArtifacts(ServiceArtifact[] artifacts) returns error? { // If there is an error, wait until other artifacts get published if res is error { e = res; + continue; } + + string? id = res?.id; + if id == () { + continue; + } + + publishedServiceIds.push(id); } return e; } @@ -97,43 +101,8 @@ function getServerCert(string? serverCert) returns http:ClientSecureSocket? { return {enable: false}; } -function retrieveAllExisitingservices(Client apimClient, ServiceArtifact[] artifacts) returns Service[]|error { - Service[] services = []; - string serviceKeys = getCommaSeparatedServiceKeys(artifacts); - int offset = 0; - int 'limit = 25; - while true { - ServiceList|error serviceList = apimClient->/services(key = serviceKeys, offset = offset, 'limit = 'limit); - if serviceList is error { - log:printError("Error occurred while retrieving existing services: ", serviceList); - return serviceList; - } - - Service[]? fetchedServices = serviceList.list; - Pagination? pagination = serviceList.pagination; - if fetchedServices != () { - services.push(...fetchedServices); - } - - string? next = pagination?.next; - if next == () || next == "" { - break; - } - - offset += 'limit; - } - - return services; -} - -function removeExistingServices(Client apimClient, Service[] services) returns error? { - foreach Service serviceObject in services { - string? id = serviceObject.id; - if id == () { - log:printWarn("Service ID is not available for service: " + serviceObject.serviceKey.toBalString()); - continue; - } - +function removeExistingServices(Client apimClient) returns error? { + foreach string id in publishedServiceIds { http:Response|error response = apimClient->/services/[id].delete(); if response is error { log:printError("Error occurred while deleting existing service: ", response); @@ -141,12 +110,3 @@ function removeExistingServices(Client apimClient, Service[] services) returns e } } } - -function findAndRemoveExistingServices(Client apimClient, ServiceArtifact[] artifacts) returns error? { - Service[]|error existingServices = retrieveAllExisitingservices(apimClient, artifacts); - if existingServices is error { - return existingServices; - } - - return removeExistingServices(apimClient, existingServices); -} diff --git a/ballerina/utils.bal b/ballerina/utils.bal index 0c6421b..7837721 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -250,6 +250,3 @@ isolated function createBodyParts(record {|anydata...;|} anyRecord, map - string:'join(",", ...from ServiceArtifact artifact in artifacts select artifact.serviceKey); From 33d6a0858291e181f3cc9bb923aa09d844655bd6 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 18 Aug 2025 16:36:54 +0530 Subject: [PATCH 18/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 793b4e8..a78d18b 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.1" +version = "1.1.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.3" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.1" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From c2cda40e41bf8e8ca7ef31801280b32ff2df1b64 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 18 Aug 2025 16:44:17 +0530 Subject: [PATCH 19/22] Update delete implementation --- ballerina/service.bal | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ballerina/service.bal b/ballerina/service.bal index 8c6bb92..8c648c7 100644 --- a/ballerina/service.bal +++ b/ballerina/service.bal @@ -105,8 +105,14 @@ function removeExistingServices(Client apimClient) returns error? { foreach string id in publishedServiceIds { http:Response|error response = apimClient->/services/[id].delete(); if response is error { - log:printError("Error occurred while deleting existing service: ", response); + log:printError("Error occurred while deleting the service: ", response, serviceId = id); return response; } + + if response.statusCode != 204 { + string responseMessage = (check response.getJsonPayload()).toJsonString(); + log:printError("Failed to delete service: ", serviceId = id, message = responseMessage); + return error("Failed to delete the service with id: " + id, cause = responseMessage); + } } } From f31c189efa1455e7e1f2ad8f22cdf3ab2267e34e Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 19 Aug 2025 10:12:54 +0530 Subject: [PATCH 20/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index a78d18b..793b4e8 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.0" +version = "1.1.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.0" +version = "2.14.3" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.0" +version = "2.14.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From f61013279553edc3523db661506545db27175fde Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 19 Aug 2025 10:31:06 +0530 Subject: [PATCH 21/22] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 793b4e8..a78d18b 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -53,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "data.jsondata" -version = "1.1.1" +version = "1.1.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.object"} @@ -73,7 +73,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.3" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -240,7 +240,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.14.1" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, From 768d42da2becba924291a83d79659d3aa5cc9f7c Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 19 Aug 2025 10:40:16 +0530 Subject: [PATCH 22/22] Revert changes done to the port --- ballerina/listener.bal | 5 +++++ ballerina/service.bal | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ballerina/listener.bal b/ballerina/listener.bal index 3f4c18f..07b57be 100644 --- a/ballerina/listener.bal +++ b/ballerina/listener.bal @@ -15,6 +15,7 @@ // under the License. public class Listener { + int port; public function 'start() returns error? { ServiceArtifact[] artifacts = getArtifacts(); check publishArtifacts(artifacts); @@ -33,4 +34,8 @@ public class Listener { public function attach(service object {} s, string[]? name = ()) returns error? { } + + public function init(int port) { + self.port = port; + } } diff --git a/ballerina/service.bal b/ballerina/service.bal index 8c648c7..1baee86 100644 --- a/ballerina/service.bal +++ b/ballerina/service.bal @@ -31,7 +31,7 @@ configurable string clientSecureSocketpassword = ""; configurable string? serverCert = (); configurable string[] scopes = ["service_catalog:service_view", "apim:api_view", "service_catalog:service_write"]; -listener Listener 'listener = new Listener(); +listener Listener 'listener = new Listener(port); final string[] publishedServiceIds = [];