Merge branch 'development' into CORE-12019/Capture-CPI-build-errors

This commit is contained in:
egabrovski-r3 2023-03-28 17:27:11 +03:00 committed by GitHub
commit cd57d05e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 114 additions and 51 deletions

View File

@ -1,5 +0,0 @@
@Library('corda-shared-build-pipeline-steps@5.0') _
cordaNexusScanPipeline(
nexusAppId: 'com.corda.CSDE-Java.5.0'
)

View File

@ -56,8 +56,6 @@ dependencies {
extension = 'cpb' extension = 'cpb'
} }
} }
implementation "org.codehaus.groovy:groovy-json:3.0.9"
} }
// task groupings // 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 // 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' def notaryCpiName = 'CSDE Notary Server CPI'
@ -148,6 +146,19 @@ tasks.register("stopCorda") {
} }
} }
tasks.register("stopAndCleanCorda") {
group = cordaGroup
dependsOn('clean')
doLast {
try {
cordaLifeCycle.stopCorda()
} catch (Exception ignore) {
println("ignoring exception: ${ignore.toString()}")
}
delete devEnvWorkspace
}
}
tasks.register("getPostgresJDBC") { tasks.register("getPostgresJDBC") {
group = supportingGroup group = supportingGroup
doLast { doLast {

View File

@ -23,8 +23,12 @@ public class CordaLifeCycleHelper {
Unirest.config().verifySsl(false); Unirest.config().verifySsl(false);
} }
public void startCorda() throws IOException { public void startCorda() throws IOException, CsdeException {
PrintStream pidStore = new PrintStream(new FileOutputStream(pc.cordaPidCache)); File cordaPIDFile = new File(pc.cordaPidCache);
if (cordaPIDFile.exists()) {
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(); File combinedWorkerJar = pc.project.getConfigurations().getByName("combinedWorker").getSingleFile();
// Manual version of the command to start postgres (for reference): // Manual version of the command to start postgres (for reference):
@ -87,7 +91,7 @@ public class CordaLifeCycleHelper {
cordaPIDFile.delete(); cordaPIDFile.delete();
} }
else { 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?");
} }
} }
} }

View File

@ -1,44 +1,22 @@
package com.r3.csde; package com.r3.csde;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode; import kong.unirest.JsonNode;
import kong.unirest.Unirest; import kong.unirest.Unirest;
import kong.unirest.json.JSONArray; import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject; 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 // todo: This class needs refactoring, see https://r3-cev.atlassian.net/browse/CORE-11624
public class CordaStatusQueries { public class CordaStatusQueries {
ProjectContext pc; ProjectContext pc;
public CordaStatusQueries(ProjectContext _pc){ pc = _pc; }
public CordaStatusQueries(ProjectContext _pc) {
public HttpResponse<JsonNode> getVNodeInfo() { pc = _pc;
Unirest.config().verifySsl(false);
return Unirest.get(pc.baseURL + "/api/v1/virtualnode/")
.basicAuth(pc.rpcUser, pc.rpcPasswd)
.asJson();
}
public void listVNodesVerbose() {
HttpResponse<JsonNode> vnodeResponse = getVNodeInfo();
pc.out.println("VNodes:\n" + vnodeResponse.getBody().toPrettyString());
}
// X500Name, shorthash, cpiname
public void listVNodes() {
HttpResponse<JsonNode> 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 HttpResponse<JsonNode> getCpiInfo() { public HttpResponse<JsonNode> getCpiInfo() {
@ -48,17 +26,92 @@ public class CordaStatusQueries {
.asJson(); .asJson();
} }
public HttpResponse<JsonNode> getVNodeInfo() {
Unirest.config().verifySsl(false);
return Unirest.get(pc.baseURL + "/api/v1/virtualnode/")
.basicAuth(pc.rpcUser, pc.rpcPasswd)
.asJson();
}
// cpiName, cpiVersion
public void listCPIs() { public void listCPIs() {
HttpResponse<JsonNode> cpiResponse = getCpiInfo(); HttpResponse<JsonNode> cpiResponse = getCpiInfo();
JSONArray jArray = (JSONArray) cpiResponse.getBody().getObject().get("cpis");
for(Object o: jArray){ JSONArray cpisJson = (JSONArray) cpiResponse.getBody().getObject().get("cpis");
List<List<String>> lines = new LinkedList<>();
for (Object o : cpisJson) {
if (o instanceof JSONObject) { if (o instanceof JSONObject) {
JSONObject idObj = ((JSONObject) o).getJSONObject("id"); JSONObject idObj = ((JSONObject) o).getJSONObject("id");
pc.out.print("cpiName=" + idObj.get("cpiName")); String cpiName = idObj.get("cpiName").toString();
pc.out.println(", cpiVersion=" + idObj.get("cpiVersion")); String cpiVersion = idObj.get("cpiVersion").toString();
lines.add(Arrays.asList(cpiName, cpiVersion));
} }
} }
List<String> title = Arrays.asList("CPI Name", "CPI Version");
List<Integer> titleSizes = Arrays.asList(40, 20);
printTable(titleSizes, title, lines);
} }
public void listVNodesVerbose() {
HttpResponse<JsonNode> vnodeResponse = getVNodeInfo();
pc.out.println("VNodes:\n" + vnodeResponse.getBody().toPrettyString());
}
// x500Name, shortHash, cpiName
public void listVNodes() {
HttpResponse<JsonNode> vnodeResponse = getVNodeInfo();
JSONArray virtualNodesJson = (JSONArray) vnodeResponse.getBody().getObject().get("virtualNodes");
List<List<String>> 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<String> title = Arrays.asList("X500 Name", "Holding identity short hash", "CPI Name");
List<Integer> titleSizes = Arrays.asList(60, 30, 40);
printTable(titleSizes, title, lines);
}
public void printTable(List<Integer> titleSizes, List<String> title, List<List<String>> 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<String> line : lines) {
pc.out.println(formatLine(titleSizes, line));
}
pc.out.println(separator);
}
public String formatLine(List<Integer> titleSizes, List<String> 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();
}
} }