cdn-experiments/ccp/js/infrastructurelistcontrolle...

75 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-03-29 16:06:46 +02:00
class CCPInfrastructureList extends HTMLElement{
#boot;
2022-04-12 19:51:38 +02:00
#socket;
#data = {};
2022-03-29 16:06:46 +02:00
#serviceurl = "https://nubis1.int.d4science.net:8080"
2022-04-12 19:51:38 +02:00
#broadcasturl = "ws://nubis1.int.d4science.net:8989/ws/notification"
2022-03-29 16:06:46 +02:00
constructor(){
super()
this.#boot = document.querySelector("d4s-boot-2")
2022-04-12 19:51:38 +02:00
}
connectedCallback(){
2022-03-29 16:06:46 +02:00
this.fetchInfrastructures()
}
2022-04-12 19:51:38 +02:00
get data(){
return this.#data
}
fetchInfrastructures(){
console.log("Calling fetch infrastructures")
2022-05-05 12:19:06 +02:00
this.#boot.secureFetch(this.#serviceurl + "/infrastructures/cache").
2022-04-12 19:51:38 +02:00
then(resp=>{
return resp.json()
}).then(data=>{
2022-05-05 12:19:06 +02:00
this.#data = data
/*this.updateList()*/
2022-04-12 19:51:38 +02:00
}).catch(err=>{
alert("Error while downloading methods: ", err)
})
2022-03-29 16:06:46 +02:00
}
2022-05-05 12:19:06 +02:00
/* updateList(resp){
2022-04-12 19:51:38 +02:00
this.connectBroadcast()
this.#infrastructures.forEach(i=>{
2022-05-05 12:19:06 +02:00
this.#data[i.id] = { id : i.id, status : "unknown", type : i.type, name : i.name, runtimes : [] }
2022-04-12 19:51:38 +02:00
this.#boot.secureFetch(this.#serviceurl + `/infrastructures/${i.id}/status`).then(
()=>console.log("Requested async status update for infrastructure ", i.id)
)
})
}
2022-05-05 12:19:06 +02:00
*/
2022-04-12 19:51:38 +02:00
2022-05-05 12:19:06 +02:00
/* connectBroadcast(){
2022-04-12 19:51:38 +02:00
this.#socket = new WebSocket(this.#broadcasturl + "/infrastructures");
this.#socket.onmessage = event=>{
const data = JSON.parse(event.data)
this.#data[data.infrastructure].status = data.status.toLowerCase()
if(data.type.toLowerCase() === "update" && data.status.toLowerCase() === "ok"){
this.#data[data.infrastructure].runtimes = data.data.runtimes
}else{
this.#data[data.infrastructure].runtimes = []
}
console.log("New Infrastructure status", this.#data)
}
window.setInterval( ()=>this.#socket.send("ping"), 30000)
}
2022-05-05 12:19:06 +02:00
*/
2022-04-12 19:51:38 +02:00
getCompatibleRuntimes(rts){
const available = Object.keys(this.#data).reduce((acc, i) => {
const compatiblerts = this.#data[i].runtimes.
filter(r=>rts.indexOf(r["descriptor-id"]) >= 0).
map(cr=>{ return { runtime : cr, infrastructure : this.#data[i] } })
return acc.concat(compatiblerts)
}, [])
return available
2022-03-29 16:06:46 +02:00
}
}
window.customElements.define('d4s-ccp-infrastructurelist', CCPInfrastructureList);