From 7214a95d9119492d39e4ea1a45aa9385782f4cf0 Mon Sep 17 00:00:00 2001 From: Suyash Gupta Date: Fri, 5 Aug 2022 04:51:56 +0530 Subject: [PATCH 1/2] accept callback_url --- .../ebi/tsc/tesk/k8s/constant/Constants.java | 7 ++++- .../k8s/convert/TesKubernetesConverter.java | 4 +++ .../uk/ac/ebi/tsc/tesk/tes/model/TesTask.java | 27 ++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java b/src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java index f6b7716..9419dd3 100644 --- a/src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java +++ b/src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java @@ -25,7 +25,7 @@ public class Constants { * Key in JSON taskmaster input, which holds list of executors */ public static final String TASKMASTER_INPUT_EXEC_KEY = "executors"; - + /** * */ @@ -69,6 +69,11 @@ public class Constants { */ public static final String ANN_JSON_INPUT_KEY = "json-input"; + /** + * Key of the annotation, that stores the callback URL + */ + public static final String ANN_CALLBACK_URL_KEY = "callback_url"; + /** * Key of the label, that stores taskmaster's name (==TES task generated ID) in executor jobs */ diff --git a/src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java b/src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java index 2c575a6..b5b3ba9 100644 --- a/src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java +++ b/src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java @@ -75,6 +75,10 @@ public V1Job fromTesTaskToK8sJob(TesTask task, User user) { V1Job taskMasterJob = this.taskmasterTemplateSupplier.get(); //put input task name as annotation taskMasterJob.getMetadata().putAnnotationsItem(ANN_TESTASK_NAME_KEY, task.getName()); + // put callback URL as annotation + if (task.getCallbackUrl() != null) { + taskMasterJob.getMetadata().putAnnotationsItem(ANN_CALLBACK_URL_KEY, task.getCallbackUrl()); + } //creating user and owning group taskMasterJob.getMetadata().putLabelsItem(LABEL_USERID_KEY, user.getUsername()); if (task.getTags() != null && task.getTags().containsKey("GROUP_NAME")) { diff --git a/src/main/java/uk/ac/ebi/tsc/tesk/tes/model/TesTask.java b/src/main/java/uk/ac/ebi/tsc/tesk/tes/model/TesTask.java index 1720b13..2b7901c 100644 --- a/src/main/java/uk/ac/ebi/tsc/tesk/tes/model/TesTask.java +++ b/src/main/java/uk/ac/ebi/tsc/tesk/tes/model/TesTask.java @@ -32,6 +32,9 @@ public class TesTask { @JsonProperty("description") private String description; + @JsonProperty("callback_url") + private String callbackUrl; + @JsonProperty("inputs") @Valid private List inputs = null; @@ -144,6 +147,26 @@ public void setDescription(String description) { this.description = description; } + public TesTask callbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + return this; + } + + /** + * Optional user-provided callback URL. + * @return callbackUrl + */ + @ApiModelProperty(value = "Optional user-provided callback URL.") + + + public String getCallbackUrl() { + return callbackUrl; + } + + public void setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + } + public TesTask inputs(List inputs) { this.inputs = inputs; return this; @@ -372,6 +395,7 @@ public boolean equals(Object o) { Objects.equals(this.state, tesTask.state) && Objects.equals(this.name, tesTask.name) && Objects.equals(this.description, tesTask.description) && + Objects.equals(this.callbackUrl, tesTask.callbackUrl) && Objects.equals(this.inputs, tesTask.inputs) && Objects.equals(this.outputs, tesTask.outputs) && Objects.equals(this.resources, tesTask.resources) && @@ -384,7 +408,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(id, state, name, description, inputs, outputs, resources, executors, volumes, tags, logs, creationTime); + return Objects.hash(id, state, name, description, callbackUrl, inputs, outputs, resources, executors, volumes, tags, logs, creationTime); } @Override @@ -396,6 +420,7 @@ public String toString() { sb.append(" state: ").append(toIndentedString(state)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); sb.append(" inputs: ").append(toIndentedString(inputs)).append("\n"); sb.append(" outputs: ").append(toIndentedString(outputs)).append("\n"); sb.append(" resources: ").append(toIndentedString(resources)).append("\n"); From d3cda2bb568b5e5cc861d962238920defb096f6e Mon Sep 17 00:00:00 2001 From: Suyash Gupta Date: Thu, 11 Aug 2022 20:53:40 +0530 Subject: [PATCH 2/2] add callback url to taskmaster env variables --- .../uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java | 10 +++++----- .../tsc/tesk/k8s/convert/TesKubernetesConverter.java | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java b/src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java index 9419dd3..ede544b 100644 --- a/src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java +++ b/src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java @@ -21,6 +21,11 @@ public class Constants { */ public static final String TASKMASTER_INPUT = "JSON_INPUT"; + /** + * ENV var that stores the callback URL + */ + public static final String TASKMASTER_CALLBACK_URL = "CALLBACK_URL"; + /** * Key in JSON taskmaster input, which holds list of executors */ @@ -69,11 +74,6 @@ public class Constants { */ public static final String ANN_JSON_INPUT_KEY = "json-input"; - /** - * Key of the annotation, that stores the callback URL - */ - public static final String ANN_CALLBACK_URL_KEY = "callback_url"; - /** * Key of the label, that stores taskmaster's name (==TES task generated ID) in executor jobs */ diff --git a/src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java b/src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java index b5b3ba9..e12e2e4 100644 --- a/src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java +++ b/src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java @@ -75,10 +75,6 @@ public V1Job fromTesTaskToK8sJob(TesTask task, User user) { V1Job taskMasterJob = this.taskmasterTemplateSupplier.get(); //put input task name as annotation taskMasterJob.getMetadata().putAnnotationsItem(ANN_TESTASK_NAME_KEY, task.getName()); - // put callback URL as annotation - if (task.getCallbackUrl() != null) { - taskMasterJob.getMetadata().putAnnotationsItem(ANN_CALLBACK_URL_KEY, task.getCallbackUrl()); - } //creating user and owning group taskMasterJob.getMetadata().putLabelsItem(LABEL_USERID_KEY, user.getUsername()); if (task.getTags() != null && task.getTags().containsKey("GROUP_NAME")) { @@ -117,6 +113,10 @@ public V1Job fromTesTaskToK8sJob(TesTask task, User user) { String taskMasterInputAsJSON = this.gson.toJson(taskMasterInput); //placing taskmaster's parameter (JSONed map of: inputs, outputs, volumes, executors (as jobs) into ENV variable in taskmaster spec taskMasterJob.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv().stream().filter(x -> x.getName().equals(TASKMASTER_INPUT)).forEach(x -> x.setValue(taskMasterInputAsJSON)); + //place callback URL as ENV variable in taskmaster spec + if (task.getCallbackUrl() != null) { + taskMasterJob.getSpec().getTemplate().getSpec().getContainers().get(0).addEnvItem(new V1EnvVar().name(TASKMASTER_CALLBACK_URL).value(task.getCallbackUrl())); + } return taskMasterJob; }