Add environment block to defineCluster

Change-Id: I59e500b95e8d4307f0740eab1b50e279d97f8dc3
This commit is contained in:
Rudi Schlatte 2024-03-28 16:18:27 +01:00
parent cf552733b6
commit 7df7f8bcf1
2 changed files with 41 additions and 27 deletions

View File

@ -392,45 +392,52 @@ public class ExnConnector {
/** /**
* Define a cluster with the given name and node list. * Define a cluster with the given name and node list.
* *
* <p>The nodes are passed in a JSON array containing objects of the * <p>The cluster is passed in a JSON of the following shape:
* following shape: *
*
* <pre>{@code * <pre>{@code
* { * {
* "nodeName": "some-component", * "name":"485d7-1",
* "nodeCandidateId": "some-candidate-id", * "master-node":"N485d7-1-masternode",
* "cloudId": "some-cloud-id" * "nodes":[
* {
* "nodeName":"N485d7-1-masternode",
* "nodeCandidateId":"8a7481018e8572f9018e857ed0c50c53",
* "cloudId":"demo-cloud"
* },
* {
* "nodeName":"N485d7-1-dummy-app-worker-1-1",
* "nodeCandidateId":"8a7481018e8572f9018e857ecfb30c21",
* "cloudId":"demo-cloud"
* }
* ],
* "env-var": {
* "APPLICATION_ID", "the-application-id"
* }
* } * }
* }</pre> * }</pre>
* *
* <p>Each value for {@code nodeName} has to be globally unique, and * <p>Each value for {@code nodeName} has to be globally unique, must
* should be either the name of the master node or the name of a node that * start with a letter and contain numbers, letters and hyphens only.
* will subsequently be referenced in the affinity trait of the modified *
* kubevela file (see {@link NebulousAppDeployer#addNodeAffinities()}).
*
* <p>The values for {@code nodeCandidateId} and {@code cloudId} come from * <p>The values for {@code nodeCandidateId} and {@code cloudId} come from
* the return value of a call to {@link #findNodeCandidates()}. * the return value of a call to {@link #findNodeCandidates()}.
* *
* @param appID The application's id, used only for logging. * @param appID The application's id, used only for logging.
* @param clusterName The cluster name. * @param clusterName The cluster name, used only for logging.
* @param masterNodeName The name of the master node. * @param cluster A JSON object, as detailed above.
* @param nodes A JSON array containing the node definitions, including the master node.
* @return true if the cluster was successfully defined, false otherwise. * @return true if the cluster was successfully defined, false otherwise.
*/ */
public boolean defineCluster(String appID, String clusterName, String masterNodeName, ArrayNode nodes) { public boolean defineCluster(String appID, String clusterName, ObjectNode cluster) {
// https://openproject.nebulouscloud.eu/projects/nebulous-collaboration-hub/wiki/deployment-manager-sal-1#specification-of-endpoints-being-developed // https://openproject.nebulouscloud.eu/projects/nebulous-collaboration-hub/wiki/deployment-manager-sal-1#specification-of-endpoints-being-developed
ObjectNode body = mapper.createObjectNode() Main.logFile("define-cluster-" + appID + ".json", cluster);
.put("name", clusterName)
.put("master-node", masterNodeName);
body.putArray("nodes").addAll(nodes);
Map<String, Object> msg; Map<String, Object> msg;
try { try {
msg = Map.of("metaData", Map.of("user", "admin"), msg = Map.of("metaData", Map.of("user", "admin"),
"body", mapper.writeValueAsString(body)); "body", mapper.writeValueAsString(cluster));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
log.error("Could not convert JSON to string (this should never happen)", log.error("Could not convert JSON to string (this should never happen)",
keyValue("appId", appID), e); keyValue("appId", appID), keyValue("clusterName", clusterName), e);
return false; return false;
} }
Map<String, Object> response = defineCluster.sendSync(msg, appID, null, false); Map<String, Object> response = defineCluster.sendSync(msg, appID, null, false);
@ -506,10 +513,12 @@ public class ExnConnector {
.put("appName", appName) .put("appName", appName)
.put("action", "apply") .put("action", "apply")
.put("flags", ""); .put("flags", "");
Main.logFile("deploy-application-" + appID + ".json", body);
Map<String, Object> msg; Map<String, Object> msg;
try { try {
String bodyStr = mapper.writeValueAsString(body);
msg = Map.of("metaData", Map.of("user", "admin", "clusterName", clusterName), msg = Map.of("metaData", Map.of("user", "admin", "clusterName", clusterName),
"body", mapper.writeValueAsString(body)); "body", bodyStr);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
log.error("Could not convert JSON to string (this should never happen)", log.error("Could not convert JSON to string (this should never happen)",
keyValue("appId", appID), keyValue("clusterName", clusterName), e); keyValue("appId", appID), keyValue("clusterName", clusterName), e);

View File

@ -274,7 +274,7 @@ public class NebulousAppDeployer {
ObjectNode cluster = mapper.createObjectNode(); ObjectNode cluster = mapper.createObjectNode();
cluster.put("name", clusterName) cluster.put("name", clusterName)
.put("master-node", masterNodeName); .put("master-node", masterNodeName);
ArrayNode nodes = cluster.withArray("nodes"); ArrayNode nodes = cluster.withArray("/nodes");
if (masterNodeCandidate != null) { if (masterNodeCandidate != null) {
nodes.addObject() nodes.addObject()
.put("nodeName", masterNodeName) .put("nodeName", masterNodeName)
@ -287,8 +287,10 @@ public class NebulousAppDeployer {
.put("nodeCandidateId", candidate.getId()) .put("nodeCandidateId", candidate.getId())
.put("cloudId", candidate.getCloud().getId()); .put("cloudId", candidate.getCloud().getId());
}); });
ObjectNode environment = cluster.withObject("/env-var");
environment.put("APPLICATION_ID", appUUID);
log.info("Calling defineCluster", keyValue("appId", appUUID), keyValue("clusterName", clusterName)); log.info("Calling defineCluster", keyValue("appId", appUUID), keyValue("clusterName", clusterName));
boolean defineClusterSuccess = conn.defineCluster(appUUID, clusterName, masterNodeName, nodes); boolean defineClusterSuccess = conn.defineCluster(appUUID, clusterName, cluster);
if (!defineClusterSuccess) { if (!defineClusterSuccess) {
log.error("Call to defineCluster failed, blindly continuing...", log.error("Call to defineCluster failed, blindly continuing...",
keyValue("appId", appUUID), keyValue("clusterName", clusterName)); keyValue("appId", appUUID), keyValue("clusterName", clusterName));
@ -324,6 +326,9 @@ public class NebulousAppDeployer {
// case we want to continue. // case we want to continue.
clusterState = conn.getCluster(clusterName); clusterState = conn.getCluster(clusterName);
} }
log.info("Cluster deployment finished, continuing with app deployment",
keyValue("appId", appUUID), keyValue("clusterName", clusterName),
keyValue("clusterState", clusterState));
log.info("Calling labelCluster", keyValue("appId", appUUID), keyValue("clusterName", clusterName)); log.info("Calling labelCluster", keyValue("appId", appUUID), keyValue("clusterName", clusterName));
boolean labelClusterSuccess = conn.labelNodes(appUUID, clusterName, nodeLabels); boolean labelClusterSuccess = conn.labelNodes(appUUID, clusterName, nodeLabels);