Call deployApplication endpoint

Change-Id: I3ede8df12c59d0de7a0bdf19f7fcb34c9a001e3a
This commit is contained in:
Rudi Schlatte 2024-03-19 18:01:07 +01:00
parent 27edd92a4e
commit f4456c5fda
3 changed files with 52 additions and 58 deletions

View File

@ -403,27 +403,24 @@ public class ExnConnector {
* } * }
* }</pre> * }</pre>
* *
* <p>Each value for {@code nodeName} has to be unique, and should be * <p>Each value for {@code nodeName} has to be globally unique, and
* either the name of the master node or the name of a node that will * should be either the name of the master node or the name of a node that
* subsequently be referenced in the affinity trait of the modified * will subsequently be referenced in the affinity trait of the modified
* kubevela file (see {@link NebulousAppDeployer#addNodeAffinities()}). * 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()}.
* *
* <p>Note that this method could be rewritten to accept the nodes as a * @param appID The application's id, used only for logging.
* {@code List<org.ow2.proactive.sal.model.IaasNode>} instead, if that is * @param clusterName The cluster name.
* more convenient.
*
* @param appID The application's id, used to name the cluster.
* @param masterNodeName The name of the master node. * @param masterNodeName The name of the master node.
* @param nodes A JSON array containing the node definitions. * @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 masterNodeName, ArrayNode nodes) { public boolean defineCluster(String appID, String clusterName, String masterNodeName, ArrayNode nodes) {
// 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() ObjectNode body = mapper.createObjectNode()
.put("name", appID) .put("name", clusterName)
.put("master-node", masterNodeName); .put("master-node", masterNodeName);
body.putArray("nodes").addAll(nodes); body.putArray("nodes").addAll(nodes);
Map<String, Object> msg; Map<String, Object> msg;
@ -438,11 +435,6 @@ public class ExnConnector {
Map<String, Object> response = defineCluster.sendSync(msg, appID, null, false); Map<String, Object> response = defineCluster.sendSync(msg, appID, null, false);
JsonNode payload = extractPayloadFromExnResponse(response, appID); JsonNode payload = extractPayloadFromExnResponse(response, appID);
return payload.asBoolean(); return payload.asBoolean();
// TODO: check if we still need to unwrap this; see
// `AbstractProcessor.groovy#normalizeResponse` and bug 2055053
// https://opendev.org/nebulous/exn-middleware/src/commit/ffc2ca7bdf657b3831d2b803ff2b84d5e8e1bdcd/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/AbstractProcessor.groovy#L111
// https://bugs.launchpad.net/nebulous/+bug/2055053
// return payload.at("/success").asBoolean();
} }
/** /**
@ -483,62 +475,48 @@ public class ExnConnector {
/** /**
* Deploy a cluster created by {@link #defineCluster}. * Deploy a cluster created by {@link #defineCluster}.
* *
* @param appID The application's id, used to name the cluster. * @param appID The application's id, used for logging only.
* @param clusterName The name of the cluster.
* @return true if the cluster was successfully deployed, false otherwise. * @return true if the cluster was successfully deployed, false otherwise.
*/ */
public boolean deployCluster(String appID) { public boolean deployCluster(String appID, String clusterName) {
// 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() Map<String, Object> msg = Map.of("metaData",
.put("applicationId", appID); Map.of("user", "admin", "clusterName", clusterName));
Map<String, Object> msg;
try {
msg = Map.of("metaData", Map.of("user", "admin"),
"body", mapper.writeValueAsString(body));
} catch (JsonProcessingException e) {
log.error("Could not convert JSON to string (this should never happen)",
keyValue("appId", appID), e);
return false;
}
Map<String, Object> response = deployCluster.sendSync(msg, appID, null, false); Map<String, Object> response = deployCluster.sendSync(msg, appID, null, false);
JsonNode payload = extractPayloadFromExnResponse(response, appID); JsonNode payload = extractPayloadFromExnResponse(response, appID);
return payload.asBoolean(); return payload.asBoolean();
// TODO: check if we still need to unwrap this; see
// `AbstractProcessor.groovy#normalizeResponse` and bug 2055053
// https://opendev.org/nebulous/exn-middleware/src/commit/ffc2ca7bdf657b3831d2b803ff2b84d5e8e1bdcd/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/AbstractProcessor.groovy#L111
// https://bugs.launchpad.net/nebulous/+bug/2055053
// return payload.at("/success").asBoolean();
} }
/** /**
* Submit a KubeVela file to a deployed cluster. * Submit a KubeVela file to a deployed cluster.
* *
* @param appID The application's id. * @param appID The application's id.
* @param clusterName The name of the cluster.
* @param appName The name of the application.
* @param kubevela The KubeVela file, with node affinity traits * @param kubevela The KubeVela file, with node affinity traits
* corresponding to the cluster definintion. * corresponding to the cluster definintion, serialized into a string.
* @return true if the application was successfully deployed, false otherwise. * @return the ProActive job ID, or -1 in case of failure.
*/ */
public boolean deployApplication(String appID, String kubevela) { public long deployApplication(String appID, String clusterName, String appName, String kubevela) {
// https://openproject.nebulouscloud.eu/projects/nebulous-collaboration-hub/wiki/deployment-manager-sal-1#specification-of-endpoints-being-developed
ObjectNode body = mapper.createObjectNode() ObjectNode body = mapper.createObjectNode()
.put("applicationId", appID) .put("appFile", kubevela)
.put("KubevelaYaml", kubevela); .put("packageManager", "kubevela")
.put("appName", appName)
.put("action", "apply")
.put("flags", "");
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", "clusterName", clusterName),
"body", mapper.writeValueAsString(body)); "body", mapper.writeValueAsString(body));
} 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), e);
return false; return -1;
} }
Map<String, Object> response = deployApplication.sendSync(msg, appID, null, false); Map<String, Object> response = deployApplication.sendSync(msg, appID, null, false);
JsonNode payload = extractPayloadFromExnResponse(response, appID); JsonNode payload = extractPayloadFromExnResponse(response, appID);
return payload.asBoolean(); return payload.asLong();
// TODO: check if we still need to unwrap this; see
// `AbstractProcessor.groovy#normalizeResponse` and bug 2055053
// https://opendev.org/nebulous/exn-middleware/src/commit/ffc2ca7bdf657b3831d2b803ff2b84d5e8e1bdcd/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/AbstractProcessor.groovy#L111
// https://bugs.launchpad.net/nebulous/+bug/2055053
// return payload.at("/success").asBoolean();
} }
/** /**

View File

@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import picocli.CommandLine.Command; import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters; import picocli.CommandLine.Parameters;
import picocli.CommandLine.ParentCommand; import picocli.CommandLine.ParentCommand;
@ -30,6 +31,18 @@ public class LocalExecution implements Callable<Integer> {
@Parameters(description = "The file containing a JSON app creation message") @Parameters(description = "The file containing a JSON app creation message")
private Path app_creation_msg; private Path app_creation_msg;
@Option(names = { "--deploy" },
description = "Deploy application (default true).",
defaultValue = "true", fallbackValue = "true",
negatable = true)
private boolean deploy;
@Option(names = { "--ampl" },
description = "Send AMPL file to solver (default true).",
defaultValue = "true", fallbackValue = "true",
negatable = true)
private boolean sendAMPL;
@Override public Integer call() { @Override public Integer call() {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
CountDownLatch exn_synchronizer = new CountDownLatch(1); CountDownLatch exn_synchronizer = new CountDownLatch(1);
@ -46,13 +59,16 @@ public class LocalExecution implements Callable<Integer> {
} }
NebulousApp app = NebulousApp.newFromAppMessage(msg, connector); NebulousApp app = NebulousApp.newFromAppMessage(msg, connector);
if (connector != null) { if (connector != null) {
if (sendAMPL) {
log.debug("Sending AMPL to channel {}", connector.getAmplMessagePublisher()); log.debug("Sending AMPL to channel {}", connector.getAmplMessagePublisher());
app.sendAMPL(); app.sendAMPL();
// skip for now until the endpoints are ready and the exn middleware is running
// app.deployUnmodifiedApplication();
}
System.out.println(AMPLGenerator.generateAMPL(app)); System.out.println(AMPLGenerator.generateAMPL(app));
// TODO: wait for solver reply here? }
if (deploy) {
log.debug("Deploying application", connector.getAmplMessagePublisher());
app.deployUnmodifiedApplication();
}
}
if (connector != null) { if (connector != null) {
connector.stop(); connector.stop();
} }

View File

@ -255,7 +255,7 @@ public class NebulousAppDeployer {
// 4. Create cluster // 4. Create cluster
ObjectNode cluster = mapper.createObjectNode(); ObjectNode cluster = mapper.createObjectNode();
cluster.put("name", appUUID) 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) {
@ -270,13 +270,13 @@ public class NebulousAppDeployer {
.put("nodeCandidateId", candidate.getId()) .put("nodeCandidateId", candidate.getId())
.put("cloudId", candidate.getCloud().getId()); .put("cloudId", candidate.getCloud().getId());
}); });
boolean defineClusterSuccess = conn.defineCluster(clusterName, masterNodeName, nodes); boolean defineClusterSuccess = conn.defineCluster(appUUID, clusterName, masterNodeName, nodes);
boolean labelClusterSuccess = conn.labelNodes(appUUID, clusterName, nodeLabels); boolean labelClusterSuccess = conn.labelNodes(appUUID, clusterName, nodeLabels);
// ------------------------------------------------------------ // ------------------------------------------------------------
// 5. Deploy cluster // 5. Deploy cluster
boolean deployClusterSuccess = conn.deployCluster(clusterName); boolean deployClusterSuccess = conn.deployCluster(appUUID, clusterName);
// ------------------------------------------------------------ // ------------------------------------------------------------
// 6. Rewrite KubeVela // 6. Rewrite KubeVela
@ -292,7 +292,7 @@ public class NebulousAppDeployer {
// ------------------------------------------------------------ // ------------------------------------------------------------
// 7. Deploy application // 7. Deploy application
// TODO: call deployApplication endpoint long proActiveJobID = conn.deployApplication(appUUID, clusterName, app.getName(), rewritten_kubevela);
// ------------------------------------------------------------ // ------------------------------------------------------------
// 8. Update NebulousApp state // 8. Update NebulousApp state