Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ jobs:
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main
secrets: inherit
with:
additional-build-flags: -x :cdc-examples:build
81 changes: 81 additions & 0 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,89 @@ license = ["Apache-2.0"]
[build-options]
observabilityIncluded = true

[platform.java21]
graalvmCompatible=true

[[platform.java21.dependency]]
groupId = "io.ballerina.lib.cdc"
artifactId = "cdc-native-0.1.0-SNAPSHOT"
version = "0.1.0-SNAPSHOT"
path = "../native/build/libs/cdc-native-0.1.0-SNAPSHOT.jar"

[[platform.java21.dependency]]
groupId = "io.debezium"
artifactId = "debezium-api"
version = "3.0.8.Final"
path = "./lib/debezium-api-3.0.8.Final.jar"

[[platform.java21.dependency]]
groupId = "io.debezium"
artifactId = "debezium-core"
version = "3.0.8.Final"
path = "./lib/debezium-core-3.0.8.Final.jar"

[[platform.java21.dependency]]
groupId = "io.debezium"
artifactId = "debezium-embedded"
version = "3.0.8.Final"
path = "./lib/debezium-embedded-3.0.8.Final.jar"

[[platform.java21.dependency]]
groupId = "io.debezium"
artifactId = "debezium-storage-file"
version = "3.0.8.Final"
path = "./lib/debezium-storage-file-3.0.8.Final.jar"

[[platform.java21.dependency]]
groupId = "io.debezium"
artifactId = "debezium-storage-kafka"
version = "3.0.8.Final"
path = "./lib/debezium-storage-kafka-3.0.8.Final.jar"

[[platform.java21.dependency]]
groupId = "org.apache.kafka"
artifactId = "kafka-clients"
version = "3.9.0"
path = "./lib/kafka-clients-3.9.0.jar"

[[platform.java21.dependency]]
groupId = "org.apache.kafka"
artifactId = "connect-api"
version = "3.9.0"
path = "./lib/connect-api-3.9.0.jar"

[[platform.java21.dependency]]
groupId = "org.apache.kafka"
artifactId = "connect-json"
version = "3.9.0"
path = "./lib/connect-json-3.9.0.jar"

[[platform.java21.dependency]]
groupId = "org.apache.kafka"
artifactId = "connect-runtime"
version = "3.9.0"
path = "./lib/connect-runtime-3.9.0.jar"

[[platform.java21.dependency]]
groupId = "com.fasterxml.jackson.core"
artifactId = "jackson-core"
version = "2.16.2"
path = "./lib/jackson-core-2.16.2.jar"

[[platform.java21.dependency]]
groupId = "com.fasterxml.jackson.core"
artifactId = "jackson-module-afterburner"
version = "2.16.2"
path = "./lib/jackson-module-afterburner-2.16.2.jar"

[[platform.java21.dependency]]
groupId = "com.fasterxml.jackson.core"
artifactId = "jackson-annotations"
version = "2.16.2"
path = "./lib/jackson-annotations-2.16.2.jar"

[[platform.java21.dependency]]
groupId = "com.fasterxml.jackson.core"
artifactId = "jackson-databind"
version = "2.16.2"
path = "./lib/jackson-databind-2.16.2.jar"
121 changes: 119 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,31 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.12.0"
distribution-version = "2201.12.3"

[[package]]
org = "ballerina"
name = "crypto"
version = "2.9.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]
modules = [
{org = "ballerina", packageName = "crypto", moduleName = "crypto"}
]

[[package]]
org = "ballerina"
name = "data.jsondata"
version = "1.1.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]
modules = [
{org = "ballerina", packageName = "data.jsondata", moduleName = "data.jsondata"}
]

[[package]]
org = "ballerina"
Expand All @@ -15,12 +39,105 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"

[[package]]
org = "ballerina"
name = "observe"
version = "1.5.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "random"
version = "1.7.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]
modules = [
{org = "ballerina", packageName = "random", moduleName = "random"}
]

[[package]]
org = "ballerina"
name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
]

[[package]]
org = "ballerina"
name = "time"
version = "2.7.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerinai"
name = "observe"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "observe"}
]
modules = [
{org = "ballerinai", packageName = "observe", moduleName = "observe"}
]

[[package]]
org = "ballerinax"
name = "cdc"
version = "0.1.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "data.jsondata"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "random"},
{org = "ballerina", name = "test"},
{org = "ballerinai", name = "observe"}
]
modules = [
{org = "ballerinax", packageName = "cdc", moduleName = "cdc"}
Expand Down
25 changes: 25 additions & 0 deletions ballerina/annotations.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

# Provides a set of configurations for the CDC service.
#
# + tables - The name of the table or an array of table names to capture events from
public type CdcServiceConfig record {|
string|string[] tables;
|};

# The annotation to configure a CDC service.
public annotation CdcServiceConfig ServiceConfig on service;
23 changes: 22 additions & 1 deletion ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,33 @@ ballerina {
packageOrganization = packageOrg
module = packageName
langVersion = ballerinaLangVersion
testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.lib.cdc.*:ballerinax.cdc.*"
}

dependencies {
externalJars(group: 'io.debezium', name: 'debezium-api', version: debeziumVersion)
externalJars(group: 'io.debezium', name: 'debezium-core', version: debeziumVersion)
externalJars(group: 'io.debezium', name: 'debezium-embedded', version: debeziumVersion)
externalJars(group: 'io.debezium', name: 'debezium-storage-file', version: debeziumVersion)
externalJars(group: 'io.debezium', name: 'debezium-storage-kafka', version: debeziumVersion)

externalJars(group: 'org.apache.kafka', name: 'kafka-clients', version: kafkaVersion)
externalJars(group: 'org.apache.kafka', name: 'connect-api', version: kafkaVersion)
externalJars(group: 'org.apache.kafka', name: 'connect-json', version: kafkaVersion)
externalJars(group: 'org.apache.kafka', name: 'connect-runtime', version: kafkaVersion)

externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: fasterxmlVersion)
externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: fasterxmlVersion)
externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: fasterxmlVersion)
}

tasks.register('updateTomlFiles') {
doLast {
def newBallerinaToml = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version)
newBallerinaToml = newBallerinaToml.replace("@toml.version@", tomlVersion)
newBallerinaToml = newBallerinaToml.replace("@debezium.version@", debeziumVersion)
newBallerinaToml = newBallerinaToml.replace("@kafka.version@", kafkaVersion)
newBallerinaToml = newBallerinaToml.replace("@fasterxml.version@", fasterxmlVersion)
ballerinaTomlFile.text = newBallerinaToml

def newCompilerPluginToml = compilerPluginTomlFilePlaceHolder.text.replace("@project.version@", project.version)
Expand All @@ -82,6 +103,6 @@ build.dependsOn ":${packageName}-compiler-plugin:build"
build.finalizedBy ":${packageName}-compiler-plugin-tests:build"
test.dependsOn ":${packageName}-native:build"
test.dependsOn ":${packageName}-compiler-plugin:build"
test.finalizedBy ":${packageName}-compiler-plugin-tests:build"
test.finalizedBy ":${packageName}-compiler-plugin-tests:test"
publishToMavenLocal.dependsOn build
publish.dependsOn build
34 changes: 34 additions & 0 deletions ballerina/errors.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

# Represents the details of an error that occurred during event processing.
#
# + payload - The JSON payload associated with the error
public type EventProcessingErrorDetail record {
json payload;
};

# Defines the common error type for the CDC module.
public type Error distinct error;

# Represents an error that occurred during event processing.
public type EventProcessingError distinct (Error & error<EventProcessingErrorDetail>);

# Represents an error that occurred due to payload binding issues.
public type PayloadBindingError distinct EventProcessingError;

# Represents an error that occurred due to an operation not being permitted.
public type OperationNotPermittedError distinct Error;
32 changes: 32 additions & 0 deletions ballerina/extern_functions.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/jballerina.java;

isolated function externDetach(MySqlListener|MsSqlListener|PostgreSqlListener|OracleListener self, Service o) returns boolean|Error = @java:Method {
name: "detach",
'class: "io.ballerina.lib.cdc.Listener"
} external;

Check warning on line 22 in ballerina/extern_functions.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/extern_functions.bal#L22

Added line #L22 was not covered by tests

isolated function externAttach(MySqlListener|MsSqlListener|PostgreSqlListener|OracleListener self, Service o) returns Error? = @java:Method {
name: "attach",
'class: "io.ballerina.lib.cdc.Listener"
} external;

isolated function externStart(MySqlListener|MsSqlListener|PostgreSqlListener|OracleListener self, map<string> config) returns Error? = @java:Method {
name: "start",
'class: "io.ballerina.lib.cdc.Listener"
} external;

Check warning on line 32 in ballerina/extern_functions.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/extern_functions.bal#L32

Added line #L32 was not covered by tests
11 changes: 10 additions & 1 deletion ballerina/init.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@
// specific language governing permissions and limitations
// under the License.

// Importing jsondata module for cdc native jar,
// which facilitates creating Ballerina records from JSON events.
import ballerina/data.jsondata as _;
import ballerina/jballerina.java as java;

# Initializes the CDC module.
isolated function init() {
setModule();
initializeLoggingConfigurations();
}

# Sets the module information for the CDC module.
isolated function setModule() = @java:Method {
'class: "io.ballerina.lib.cdc.ModuleUtils"
'class: "io.ballerina.lib.cdc.utils.ModuleUtils"
} external;

# Sets io.debezium log levels to SEVERE
isolated function initializeLoggingConfigurations() = @java:Method {
'class: "io.ballerina.lib.cdc.utils.ModuleUtils"
} external;
Loading
Loading