From bedc850dea1d7d10f98f3c64a5c822f9ec46c060 Mon Sep 17 00:00:00 2001 From: Emil Gabrovski Date: Mon, 27 Mar 2023 10:36:36 +0300 Subject: [PATCH 01/10] CORE-12019 Add a Fast Check for already running CSDE before trying to start it --- .../src/main/java/com/r3/csde/CordaLifeCycleHelper.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/com/r3/csde/CordaLifeCycleHelper.java b/buildSrc/src/main/java/com/r3/csde/CordaLifeCycleHelper.java index daa78a6..a61a56d 100644 --- a/buildSrc/src/main/java/com/r3/csde/CordaLifeCycleHelper.java +++ b/buildSrc/src/main/java/com/r3/csde/CordaLifeCycleHelper.java @@ -24,7 +24,11 @@ public class CordaLifeCycleHelper { } public void startCorda() throws IOException { - PrintStream pidStore = new PrintStream(new FileOutputStream(pc.cordaPidCache)); + File cordaPIDFile = new File(pc.cordaPidCache); + if (cordaPIDFile.exists()) { + throw new IOException("Cannot start the Combined worker\nCached process ID file " + cordaPIDFile + " existing.\nWas the combined worker already started?"); + } + PrintStream pidStore = new PrintStream(new FileOutputStream(cordaPIDFile)); File combinedWorkerJar = pc.project.getConfigurations().getByName("combinedWorker").getSingleFile(); // Manual version of the command to start postgres (for reference): From 48a19a73e125806dd0bcb0c4c982d7e5141934e0 Mon Sep 17 00:00:00 2001 From: Emil Gabrovski Date: Mon, 27 Mar 2023 10:49:23 +0300 Subject: [PATCH 02/10] CORE-12019 Add a "stopAndCleanCorda" gradle task that will Stop Corda5 if running and do some cleanup --- buildSrc/src/main/groovy/csde.gradle | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/buildSrc/src/main/groovy/csde.gradle b/buildSrc/src/main/groovy/csde.gradle index a94ffa9..574617e 100644 --- a/buildSrc/src/main/groovy/csde.gradle +++ b/buildSrc/src/main/groovy/csde.gradle @@ -148,6 +148,18 @@ tasks.register("stopCorda") { } } +tasks.register("stopAndCleanCorda") { + group = cordaGroup + dependsOn('clean') + doLast { + try { + cordaLifeCycle.stopCorda() + } catch (Exception ignored) { + } + delete devEnvWorkspace + } +} + tasks.register("getPostgresJDBC") { group = supportingGroup doLast { From 2ea1a213bc7caf26b51b6e9034be6de12427e71b Mon Sep 17 00:00:00 2001 From: Emil Gabrovski Date: Mon, 27 Mar 2023 17:07:30 +0300 Subject: [PATCH 03/10] CORE-12019 Fix PR comments --- buildSrc/src/main/groovy/csde.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/csde.gradle b/buildSrc/src/main/groovy/csde.gradle index 574617e..2b5369d 100644 --- a/buildSrc/src/main/groovy/csde.gradle +++ b/buildSrc/src/main/groovy/csde.gradle @@ -154,7 +154,8 @@ tasks.register("stopAndCleanCorda") { doLast { try { cordaLifeCycle.stopCorda() - } catch (Exception ignored) { + } catch (Exception ignore) { + println(ignore.toString()) } delete devEnvWorkspace } From 69552679195ca71b16c1e504f9db8853b90d862e Mon Sep 17 00:00:00 2001 From: Emil Gabrovski Date: Mon, 27 Mar 2023 10:57:16 +0300 Subject: [PATCH 04/10] CORE-12019 Better CordaStatusQueries impl - better formatting and extracting common logic in utility functions --- .../java/com/r3/csde/CordaStatusQueries.java | 133 ++++++++++++------ 1 file changed, 93 insertions(+), 40 deletions(-) diff --git a/buildSrc/src/main/java/com/r3/csde/CordaStatusQueries.java b/buildSrc/src/main/java/com/r3/csde/CordaStatusQueries.java index 95072ba..38bf834 100644 --- a/buildSrc/src/main/java/com/r3/csde/CordaStatusQueries.java +++ b/buildSrc/src/main/java/com/r3/csde/CordaStatusQueries.java @@ -1,44 +1,22 @@ package com.r3.csde; +import kong.unirest.HttpResponse; import kong.unirest.JsonNode; import kong.unirest.Unirest; import kong.unirest.json.JSONArray; import kong.unirest.json.JSONObject; -import kong.unirest.HttpResponse; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; // todo: This class needs refactoring, see https://r3-cev.atlassian.net/browse/CORE-11624 public class CordaStatusQueries { ProjectContext pc; - public CordaStatusQueries(ProjectContext _pc){ pc = _pc; } - - public HttpResponse getVNodeInfo() { - Unirest.config().verifySsl(false); - return Unirest.get(pc.baseURL + "/api/v1/virtualnode/") - .basicAuth(pc.rpcUser, pc.rpcPasswd) - .asJson(); - } - public void listVNodesVerbose() { - HttpResponse vnodeResponse = getVNodeInfo(); - pc.out.println("VNodes:\n" + vnodeResponse.getBody().toPrettyString()); - } - - // X500Name, shorthash, cpiname - public void listVNodes() { - HttpResponse vnodeResponse = getVNodeInfo(); - - JSONArray virtualNodesJson = (JSONArray) vnodeResponse.getBody().getObject().get("virtualNodes"); - pc.out.println("X500 Name\tHolding identity short hash\tCPI Name"); - for(Object o: virtualNodesJson){ - if(o instanceof JSONObject) { - JSONObject idObj = ((JSONObject) o).getJSONObject("holdingIdentity"); - JSONObject cpiObj = ((JSONObject) o).getJSONObject("cpiIdentifier"); - pc.out.print("\"" + idObj.get("x500Name") + "\""); - pc.out.print("\t\"" + idObj.get("shortHash") + "\""); - pc.out.println("\t\"" + cpiObj.get("cpiName") + "\""); - } - } + public CordaStatusQueries(ProjectContext _pc) { + pc = _pc; } public HttpResponse getCpiInfo() { @@ -48,17 +26,92 @@ public class CordaStatusQueries { .asJson(); } - public void listCPIs() { - HttpResponse cpiResponse = getCpiInfo(); - JSONArray jArray = (JSONArray) cpiResponse.getBody().getObject().get("cpis"); - - for(Object o: jArray){ - if(o instanceof JSONObject) { - JSONObject idObj = ((JSONObject) o).getJSONObject("id"); - pc.out.print("cpiName=" + idObj.get("cpiName")); - pc.out.println(", cpiVersion=" + idObj.get("cpiVersion")); - } - } + public HttpResponse getVNodeInfo() { + Unirest.config().verifySsl(false); + return Unirest.get(pc.baseURL + "/api/v1/virtualnode/") + .basicAuth(pc.rpcUser, pc.rpcPasswd) + .asJson(); } + // cpiName, cpiVersion + public void listCPIs() { + HttpResponse cpiResponse = getCpiInfo(); + + JSONArray cpisJson = (JSONArray) cpiResponse.getBody().getObject().get("cpis"); + + List> lines = new LinkedList<>(); + for (Object o : cpisJson) { + if (o instanceof JSONObject) { + JSONObject idObj = ((JSONObject) o).getJSONObject("id"); + String cpiName = idObj.get("cpiName").toString(); + String cpiVersion = idObj.get("cpiVersion").toString(); + + lines.add(Arrays.asList(cpiName, cpiVersion)); + } + } + List title = Arrays.asList("CPI Name", "CPI Version"); + List titleSizes = Arrays.asList(40, 20); + printTable(titleSizes, title, lines); + } + + public void listVNodesVerbose() { + HttpResponse vnodeResponse = getVNodeInfo(); + pc.out.println("VNodes:\n" + vnodeResponse.getBody().toPrettyString()); + } + + // x500Name, shortHash, cpiName + public void listVNodes() { + HttpResponse vnodeResponse = getVNodeInfo(); + + JSONArray virtualNodesJson = (JSONArray) vnodeResponse.getBody().getObject().get("virtualNodes"); + + List> lines = new LinkedList<>(); + for (Object o : virtualNodesJson) { + if (o instanceof JSONObject) { + JSONObject idObj = ((JSONObject) o).getJSONObject("holdingIdentity"); + String x500Name = idObj.get("x500Name").toString(); + String shortHash = idObj.get("shortHash").toString(); + + JSONObject cpiObj = ((JSONObject) o).getJSONObject("cpiIdentifier"); + String cpiName = cpiObj.get("cpiName").toString(); + + lines.add(Arrays.asList(x500Name, shortHash, cpiName)); + } + } + List title = Arrays.asList("X500 Name", "Holding identity short hash", "CPI Name"); + List titleSizes = Arrays.asList(60, 30, 40); + printTable(titleSizes, title, lines); + } + + public void printTable(List titleSizes, List title, List> lines) { + int width = titleSizes.stream().reduce(0, Integer::sum); + String separator = "-".repeat(width + 1); + pc.out.println(separator); + pc.out.println(formatLine(titleSizes, title)); + pc.out.println(separator); + for (List line : lines) { + pc.out.println(formatLine(titleSizes, line)); + } + pc.out.println(separator); + } + + public String formatLine(List titleSizes, List line) { + StringBuilder sb = new StringBuilder(); + int delta = 0; + for (int i = 0; i < titleSizes.size(); i++) { + String s = line.get(i); + sb.append("| ").append(s); + delta += titleSizes.get(i) - (2 + s.length()); + + if (delta > 0) { + sb.append(" ".repeat(delta)); + delta = 0; + } else { + sb.append(" "); + delta -= 1; + } + } + sb.append("|"); + return sb.toString(); + } } From c026a13ad1f4e7ec812154c8c212477a7813882d Mon Sep 17 00:00:00 2001 From: Emil Gabrovski Date: Mon, 27 Mar 2023 11:03:56 +0300 Subject: [PATCH 05/10] CORE-12019 Add one more vNode, Evelyn - with the next letter and with a unique length --- config/static-network-config.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/static-network-config.json b/config/static-network-config.json index 9adde9b..42bfbe2 100644 --- a/config/static-network-config.json +++ b/config/static-network-config.json @@ -15,6 +15,10 @@ "x500Name" : "CN=Dave, OU=Test Dept, O=R3, L=London, C=GB", "cpi" : "cpi name" }, + { + "x500Name" : "CN=Evelyn, OU=Test Dept, O=R3, L=London, C=GB", + "cpi" : "cpi name" + }, { "x500Name" : "CN=NotaryRep1, OU=Test Dept, O=R3, L=London, C=GB", "cpi" : "CSDE Notary Server CPI", From 25baaeb663c953a2af0f474234ce1d09bdf57a5f Mon Sep 17 00:00:00 2001 From: Emil Gabrovski Date: Mon, 27 Mar 2023 11:05:04 +0300 Subject: [PATCH 06/10] CORE-12019 Remove unused dependency --- buildSrc/src/main/groovy/csde.gradle | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/buildSrc/src/main/groovy/csde.gradle b/buildSrc/src/main/groovy/csde.gradle index a94ffa9..b07d114 100644 --- a/buildSrc/src/main/groovy/csde.gradle +++ b/buildSrc/src/main/groovy/csde.gradle @@ -56,8 +56,6 @@ dependencies { extension = 'cpb' } } - - implementation "org.codehaus.groovy:groovy-json:3.0.9" } // task groupings @@ -85,7 +83,7 @@ def workflowBuildDir = rootDir.toString() + "/workflows/build" // todo: Need to read things from cordapp plugin - the cordapp names will be changed by the user -def appCpiName = 'cpi name' +def appCpiName = 'cpi name' // !!! this must match with the cpi name in /config/static-network-config.json def notaryCpiName = 'CSDE Notary Server CPI' From 53b164ef20a2df10fdb099a504eb2a4a3e4ad91f Mon Sep 17 00:00:00 2001 From: Emil Gabrovski Date: Tue, 28 Mar 2023 12:25:40 +0300 Subject: [PATCH 07/10] CORE-12019 Fix PR comments --- buildSrc/src/main/groovy/csde.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/csde.gradle b/buildSrc/src/main/groovy/csde.gradle index 2b5369d..7d9fbc6 100644 --- a/buildSrc/src/main/groovy/csde.gradle +++ b/buildSrc/src/main/groovy/csde.gradle @@ -155,7 +155,7 @@ tasks.register("stopAndCleanCorda") { try { cordaLifeCycle.stopCorda() } catch (Exception ignore) { - println(ignore.toString()) + println("ignoring exception: ${ignore.toString()}") } delete devEnvWorkspace } From 67c888df2bf3b70c4566c75e54ed93f3f892cccf Mon Sep 17 00:00:00 2001 From: Emil Gabrovski Date: Tue, 28 Mar 2023 12:36:08 +0300 Subject: [PATCH 08/10] CORE-12019 Fix PR comments --- .../src/main/java/com/r3/csde/CordaLifeCycleHelper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/com/r3/csde/CordaLifeCycleHelper.java b/buildSrc/src/main/java/com/r3/csde/CordaLifeCycleHelper.java index a61a56d..c76382f 100644 --- a/buildSrc/src/main/java/com/r3/csde/CordaLifeCycleHelper.java +++ b/buildSrc/src/main/java/com/r3/csde/CordaLifeCycleHelper.java @@ -23,10 +23,10 @@ public class CordaLifeCycleHelper { Unirest.config().verifySsl(false); } - public void startCorda() throws IOException { + public void startCorda() throws IOException, CsdeException { File cordaPIDFile = new File(pc.cordaPidCache); if (cordaPIDFile.exists()) { - throw new IOException("Cannot start the Combined worker\nCached process ID file " + cordaPIDFile + " existing.\nWas the combined worker already started?"); + throw new CsdeException("Cannot start the Combined worker. Cached process ID file " + cordaPIDFile + " existing. Was the combined worker already started?"); } PrintStream pidStore = new PrintStream(new FileOutputStream(cordaPIDFile)); File combinedWorkerJar = pc.project.getConfigurations().getByName("combinedWorker").getSingleFile(); @@ -91,7 +91,7 @@ public class CordaLifeCycleHelper { cordaPIDFile.delete(); } else { - throw new CsdeException("Cannot stop the Combined worker\nCached process ID file " + pc.cordaPidCache + " missing.\nWas the combined worker not started?"); + throw new CsdeException("Cannot stop the Combined worker. Cached process ID file " + pc.cordaPidCache + " missing. Was the combined worker not started?"); } } } From 80b62c71b7eace180e722a22414ad9940501494d Mon Sep 17 00:00:00 2001 From: Emil Gabrovski Date: Tue, 28 Mar 2023 12:40:15 +0300 Subject: [PATCH 09/10] CORE-12019 Fix PR comments --- config/static-network-config.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/static-network-config.json b/config/static-network-config.json index 42bfbe2..9adde9b 100644 --- a/config/static-network-config.json +++ b/config/static-network-config.json @@ -15,10 +15,6 @@ "x500Name" : "CN=Dave, OU=Test Dept, O=R3, L=London, C=GB", "cpi" : "cpi name" }, - { - "x500Name" : "CN=Evelyn, OU=Test Dept, O=R3, L=London, C=GB", - "cpi" : "cpi name" - }, { "x500Name" : "CN=NotaryRep1, OU=Test Dept, O=R3, L=London, C=GB", "cpi" : "CSDE Notary Server CPI", From 318a8184d8fc01dedec2235f086c070b93176dd4 Mon Sep 17 00:00:00 2001 From: Sean Brereton <46895769+seanbrereton@users.noreply.github.com> Date: Tue, 28 Mar 2023 11:42:23 +0100 Subject: [PATCH 10/10] INFRA-2041: Remove nexusScan pipeline due to nexus licence expiring (#23) Co-authored-by: Matt Bradbury <68864218+mattbradburyr3@users.noreply.github.com> --- .ci/nightly/JenkinsfileNexusScan | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .ci/nightly/JenkinsfileNexusScan diff --git a/.ci/nightly/JenkinsfileNexusScan b/.ci/nightly/JenkinsfileNexusScan deleted file mode 100644 index e2d589a..0000000 --- a/.ci/nightly/JenkinsfileNexusScan +++ /dev/null @@ -1,5 +0,0 @@ -@Library('corda-shared-build-pipeline-steps@5.0') _ - -cordaNexusScanPipeline( - nexusAppId: 'com.corda.CSDE-Java.5.0' -)