diff --git a/ccp/js/executionformcontroller.js b/ccp/js/executionformcontroller.js
index bf7c109..5dc17fe 100644
--- a/ccp/js/executionformcontroller.js
+++ b/ccp/js/executionformcontroller.js
@@ -4,22 +4,21 @@ class CCPExecutionForm extends HTMLElement{
#rootdoc;
#data;
#method;
- #infrastructurecontroller;
+ #executionmonitor;
#serviceurl = "https://nubis1.int.d4science.net:8080"
- //#cdnurl = "https://nubis1.int.d4science.net:8080/ccp/executionformfragment.html"
- #cdnurl = "http://d4science-cdn-public:8984/resources/ccp/executionformfragment.html"
+ #cdnurl = "https://nubis1.int.d4science.net:8080/ccp/executionformfragment.html"
+ //#cdnurl = "http://d4science-cdn-public:8984/resources/ccp/executionformfragment.html"
constructor(){
super()
this.#boot = document.querySelector("d4s-boot-2")
this.#rootdoc = this.attachShadow({ "mode" : "open"})
- this.#infrastructurecontroller = document.querySelector("d4s-ccp-infrastructurelist")
this.fetchMarkup()
}
static get observedAttributes() {
- return ["method"];
+ return ["method"];
}
attributeChangedCallback(name, oldValue, newValue) {
@@ -52,6 +51,16 @@ class CCPExecutionForm extends HTMLElement{
}
).then(data=>{
this.#data = data
+ const rts =
+ this.#data.links
+ .filter(l => l.rel === "compatibleWith")
+ .map(l=>l.href.replace("runtimes/",""))
+ .join(" ")
+ return this.#boot.secureFetch(this.#serviceurl + "/infrastructures/runtimes?runtimes=" + rts)
+
+ }).then(resp=>{
+ this.#data.executable = resp.status === 200
+ }).then(()=>{
this.showMethod()
}).catch(err=>alert(err))
}
@@ -70,14 +79,49 @@ class CCPExecutionForm extends HTMLElement{
sendExecutionRequest(){
const url = this.#serviceurl + "/processes/" + this.#method + "/execution"
+ const req = this.buildRequest()
this.#boot.secureFetch(
- url, { method : "POST", body : JSON.stringify({}), headers : { "Content-Type" : "application/json"}}
+ url, { method : "POST", body : JSON.stringify(req), headers : { "Content-Type" : "application/json"}}
).then(reply=>{
if(reply.status !== 200 && reply.status !== 201){
throw "Error while requesting resource"
}
- console.log("Execution reuqest sent")
- }).catch(err => alert("Unable to call execute"))
+ return reply.json()
+ }).then(data=>{
+ if(data.status !== "accepted"){
+ throw "Execution has not been accepted by server"
+ }
+ this.#executionmonitor = document.querySelector("d4s-ccp-executionmonitor")
+ if(this.#executionmonitor){
+ this.#executionmonitor.addExecution( { self : data.links[0].href, events : [data], jobID : data.jobID, method : this.#data.title})
+ }
+ }).catch(err => alert("Unable to call execute: " + err))
+ }
+
+ buildRequest(){
+ let request = { inputs : {}, outputs : {}, response : "raw"}
+
+ //fill inputs
+ const inputs = this.getInputs()
+ inputs.forEach(i=>{
+ request.inputs[i.name] = i.value
+ })
+
+ //fill outputs
+ const outputs = this.getOutputs()
+ outputs.forEach(o=>{
+ if(o.enabled) request.outputs[o.name] = { transmissionMode : "value" };
+ })
+
+ return request
+ }
+
+ getInputs(){
+ return Array.prototype.slice.call(this.#rootdoc.querySelectorAll("d4s-ccp-input"))
+ }
+
+ getOutputs(){
+ return Array.prototype.slice.call(this.#rootdoc.querySelectorAll("d4s-ccp-output"))
}
#empty_executionform_bss = {
@@ -153,29 +197,13 @@ class CCPExecutionForm extends HTMLElement{
BSS.apply(this.#executionform_bss)
}
},
- {
- target: "div.ccp-runtimes select",
- in : (e,d)=>d,
- recurse : [
- {
- "in" : (e,d)=>{
- const rts = d.links.filter(l=> l.rel === "compatibleWith").map(l=>l.href.replace("runtimes/",""))
- return this.#infrastructurecontroller.getCompatibleRuntimes(rts)
- },
- target : "option",
- apply : (e,d)=>{
- e.value = d.runtime["descriptor-id"]
- e.textContent = `${d.runtime.name} [${d.infrastructure.name}]`
- }
- }
- ]
- },
{
target: "#execute_method_button",
on_click : ev=>{
ev.preventDefault()
ev.stopPropagation()
- this.sendExecutionRequest()
+ if(this.#data.executable) this.sendExecutionRequest();
+ else alert("This method has no compatible runtimes available")
return false;
}
},
@@ -185,3 +213,35 @@ class CCPExecutionForm extends HTMLElement{
}
window.customElements.define('d4s-ccp-executionform', CCPExecutionForm);
+
+class CCPExecutionEnvironmentOption extends HTMLOptionElement{
+
+ #infrastructure;
+ #runtime;
+
+ constructor(runtime, infrastructure){
+ super(`${runtime.name} [${infrastructure.name}]`, runtime["descriptor-id"])
+ this.#runtime = runtime
+ this.#infrastructure = infrastructure
+ this.textContent = `${runtime.name} [${infrastructure.name}]`
+ this.value = this.runtimeId
+ }
+
+ get infrastructureName(){
+ return this.#infrastructure.name
+ }
+
+ get infrastructureId(){
+ return this.#infrastructure.id
+ }
+
+ get runtimeName(){
+ return this.#runtime.name
+ }
+
+ get runtimeId(){
+ return this.#runtime["descriptor-id"]
+ }
+}
+
+window.customElements.define('d4s-ccp-environment-option', CCPExecutionEnvironmentOption, {extends:'option'});
diff --git a/ccp/js/executionmonitorcontroller.js b/ccp/js/executionmonitorcontroller.js
new file mode 100644
index 0000000..2f34711
--- /dev/null
+++ b/ccp/js/executionmonitorcontroller.js
@@ -0,0 +1,132 @@
+class CCPExecutionMonitor extends HTMLElement {
+
+ #boot = null;
+ #rootdoc = null;
+ #broadcasturl = "ws://nubis1.int.d4science.net:8989/ws/notification";
+ #executions = [];
+ #socket = null;
+
+ constructor(){
+ super()
+ this.#boot = document.querySelector("d4s-boot-2")
+ this.#rootdoc = this.attachShadow({ "mode" : "open"})
+ this.connectBroadcast()
+ }
+
+ connectedCallback(){
+ this.#rootdoc.innerHTML = this.render()
+ }
+
+ render(){
+ return `
+
+
+
+
+
+
+
+
+
+
+
+
+