diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 3eb19e76..1f4000f8 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "cloud" -version = "2.11.0" +version = "2.11.1" repository = "https://github.com/ballerina-platform/module-ballerina-c2c" license = ["Apache-2.0"] keywords = ["cloud", "kubernetes", "docker", "k8s", "c2c"] diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 1b3ac508..11f03512 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "code2cloud" class = "io.ballerina.c2c.C2CCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/cloud-compiler-plugin-2.11.0.jar" +path = "../compiler-plugin/build/libs/cloud-compiler-plugin-2.11.1-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 9a754b9b..ce5d576f 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -10,7 +10,7 @@ distribution-version = "2201.8.0" [[package]] org = "ballerina" name = "cloud" -version = "2.11.0" +version = "2.11.1" modules = [ {org = "ballerina", packageName = "cloud", moduleName = "cloud"} ] diff --git a/compiler-plugin-tests/src/test/java/io/ballerina/c2c/test/CustomDiagnosticsTest.java b/compiler-plugin-tests/src/test/java/io/ballerina/c2c/test/CustomDiagnosticsTest.java index 9c513e51..d26fbd5d 100644 --- a/compiler-plugin-tests/src/test/java/io/ballerina/c2c/test/CustomDiagnosticsTest.java +++ b/compiler-plugin-tests/src/test/java/io/ballerina/c2c/test/CustomDiagnosticsTest.java @@ -83,8 +83,9 @@ public void testMissingPort() { BuildProject project = BuildProject.load(projectPath); Collection diagnostics = getC2CDiagnostics(project.currentPackage().getCompilation().diagnosticResult().diagnostics()); - Assert.assertEquals(diagnostics.size(), 2); + Assert.assertEquals(diagnostics.size(), 3); Iterator iterator = diagnostics.iterator(); + Assert.assertEquals(iterator.next().message(), "Missing Readiness Probe Port"); Assert.assertEquals(iterator.next().message(), "Invalid Liveness Probe Port"); Assert.assertEquals(iterator.next().message(), "Invalid Liveness Probe Path"); } diff --git a/compiler-plugin-tests/src/test/resources/diagnostics/missing-port/Cloud.toml b/compiler-plugin-tests/src/test/resources/diagnostics/missing-port/Cloud.toml index b3321f5b..a623da5c 100644 --- a/compiler-plugin-tests/src/test/resources/diagnostics/missing-port/Cloud.toml +++ b/compiler-plugin-tests/src/test/resources/diagnostics/missing-port/Cloud.toml @@ -12,3 +12,6 @@ max_cpu="0.75m" [cloud.deployment.probes.liveness] port = 9091 path = "/helloWorld/readyz" + +[cloud.deployment.probes.readiness] +path = "/helloWorld/readyz" diff --git a/compiler-plugin-tests/src/test/resources/testng.xml b/compiler-plugin-tests/src/test/resources/testng.xml index 4d212b03..b67ff6dd 100644 --- a/compiler-plugin-tests/src/test/resources/testng.xml +++ b/compiler-plugin-tests/src/test/resources/testng.xml @@ -43,7 +43,7 @@ - + diff --git a/compiler-plugin/src/main/java/io/ballerina/c2c/diagnostics/TomlDiagnosticChecker.java b/compiler-plugin/src/main/java/io/ballerina/c2c/diagnostics/TomlDiagnosticChecker.java index 3b94f687..7481dae1 100644 --- a/compiler-plugin/src/main/java/io/ballerina/c2c/diagnostics/TomlDiagnosticChecker.java +++ b/compiler-plugin/src/main/java/io/ballerina/c2c/diagnostics/TomlDiagnosticChecker.java @@ -46,10 +46,12 @@ public class TomlDiagnosticChecker { private final Project project; public TomlDiagnosticChecker(Project project) { + this.project = project; } public List validateTomlWithSource(Toml toml) { + List diagnosticInfoList = new ArrayList<>(); if (toml == null) { return Collections.emptyList(); @@ -65,9 +67,17 @@ public List validateTomlWithSource(Toml toml) { } private List validateProbe(ProjectServiceInfo projectServiceInfo, Toml probe, ProbeType type) { + List diagnosticInfos = new ArrayList<>(); - if (probe.get("port").isEmpty() || probe.get("path").isEmpty()) { - return Collections.emptyList(); + TomlNodeLocation tableLocation = probe.rootNode().location(); + if (probe.get("port").isEmpty()) { + Diagnostic portDiag = getTomlDiagnostic(tableLocation, "C2C005", "missing.probe.port", + DiagnosticSeverity.ERROR, "Missing " + type.getValue() + " Port"); + return Collections.singletonList(portDiag); + } else if (probe.get("path").isEmpty()) { + Diagnostic portDiag = getTomlDiagnostic(tableLocation, "C2C006", "missing.probe.path", + DiagnosticSeverity.ERROR, "Missing " + type.getValue() + " Path"); + return Collections.singletonList(portDiag); } TomlValueNode portNode = probe.get("port").get(); TomlValueNode pathNode = probe.get("path").get(); @@ -85,7 +95,6 @@ private List validateProbe(ProjectServiceInfo projectServiceInfo, To return diagnosticInfos; } - for (ServiceInfo serviceInfo : serviceList) { List listeners = serviceInfo.getListeners(); for (ListenerInfo listener : listeners) { @@ -119,13 +128,14 @@ private List validateProbe(ProjectServiceInfo projectServiceInfo, To "Invalid " + type.getValue() + " Resource Path"); diagnosticInfos.add(diag); } - } + } } } return diagnosticInfos; } private static boolean isValidServicePath(String servicePath, String tomlPath) { + if (servicePath.equals("/")) { return true; } @@ -139,6 +149,7 @@ private static boolean isValidServicePath(String servicePath, String tomlPath) { } private boolean isListenerPortValid(long port, List serviceInfo) { + boolean isValid = false; for (ServiceInfo service : serviceInfo) { List listeners = service.getListeners(); @@ -154,6 +165,7 @@ private boolean isListenerPortValid(long port, List serviceInfo) { } private String trimResourcePath(String resourcePath) { + resourcePath = resourcePath.trim(); if (resourcePath.startsWith("/")) { resourcePath = resourcePath.substring(1); @@ -166,6 +178,7 @@ private String trimResourcePath(String resourcePath) { private TomlDiagnostic getTomlDiagnostic(TomlNodeLocation location, String code, String template, DiagnosticSeverity severity, String message) { + io.ballerina.tools.diagnostics.DiagnosticInfo diagnosticInfo = new io.ballerina.tools.diagnostics.DiagnosticInfo(code, template, severity); return new TomlDiagnostic(location, diagnosticInfo, message); @@ -178,10 +191,12 @@ enum ProbeType { private String value; ProbeType(String value) { + this.value = value; } public String getValue() { + return value; } }