Commit 34c046da authored by Stefan Dähling's avatar Stefan Dähling
Browse files

get mas info

parent 8de28a69
Pipeline #302686 passed with stages
in 56 seconds
......@@ -47,6 +47,7 @@ package frontend
import (
"errors"
"net/http"
"strconv"
"strings"
amsclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/ams/client"
......@@ -96,6 +97,13 @@ func (fe *Frontend) handleAMS(w http.ResponseWriter, r *http.Request,
resvalid = true
cmapErr, httpErr = fe.handleMAS(w, r)
}
case 5:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[3] == "mas" && cmapErr == nil {
resvalid = true
cmapErr, httpErr = fe.handlemasID(masID, w, r)
}
default:
cmapErr = errors.New("Resource not found")
}
......@@ -117,7 +125,29 @@ func (fe *Frontend) handleMAS(w http.ResponseWriter, r *http.Request) (cmapErr,
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/clonemap/mas")
cmapErr = errors.New("Error: Method not allowed on path /api/ams/mas")
}
return
}
// handlemasID is the handler for requests to path /api/ams/mas/{mas-id}
func (fe *Frontend) handlemasID(masID int, w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr error) {
if r.Method == "GET" {
// return long information about specified MAS
var masInfo schemas.MASInfo
masInfo, _, cmapErr = amsclient.GetMAS(masID)
if cmapErr == nil {
httpErr = httpreply.Resource(w, masInfo, cmapErr)
} else {
httpErr = httpreply.CMAPError(w, cmapErr.Error())
}
} else if r.Method == "DELETE" {
// delete specified MAS
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/ams/mas/{mas-id}")
}
return
}
......
......@@ -12,17 +12,21 @@ function sideoverview(){
$(".modules").hide();
$("#headertitle").text("Overview");
updateSidebar();
contentOverview();
// fetch('/api/ams/mas').then(response => response.json()).then(data => console.log(data));
}
function sideplatform(){
$(".modules").hide();
$("#headertitle").text("Platform");
contentPlatform();
}
function sidemas(){
$(".modules").show();
$("#headertitle").text(this.id);
masID = this.id.split("sidemas")
contentAMS(parseInt(masID[1]))
}
function updateSidebar(){
......@@ -32,9 +36,56 @@ function updateSidebar(){
.then(mas => {
$("#maslist").empty()
for (let i of mas) {
console.log(i);
$("#maslist").append("<li><a href=\"#\" class=\"masbutton\" id=\"sidemas"+i.id.toString()+"\">MAS"+i.id.toString()+"</a></li>")
}
$(".masbutton").click(sidemas);
})
}
function contentOverview() {
$(".contenttitle").replaceWith("<h2 class=\"contenttitle\">Overview</h2>");
clearContent();
}
function contentPlatform() {
$(".contenttitle").replaceWith("<h2 class=\"contenttitle\">Platform</h2>");
clearContent();
}
function contentAMS(masID){
fetch('/api/ams/mas/'+masID.toString())
.then(response => response.json())
.then(masInfo => {
$(".contenttitle").replaceWith("<h2 class=\"contenttitle\">MAS"+masID.toString()+"</h2>");
contentMasInfo(masInfo);
console.log(masInfo);
})
}
function clearContent() {
$(".content").empty();
}
function contentMasInfo(masInfo) {
clearContent();
$(".content").append("<table id=\"masinfotable\"></table>");
$("#masinfotable").append("<tr><th>ID:</th><th>"+masInfo.id.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th>Config</th></tr>");
$("#masinfotable").append("<tr><th></th><th>Name:</th><th>"+masInfo.config.name+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th>Agents per agency:</th><th>"+masInfo.config.agentsperagency.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th>DF:</th><th>"+masInfo.config.df.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th>Logging:</th><th>"+masInfo.config.logging.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th>MQTT:</th><th>"+masInfo.config.mqtt.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th>Containers</th></tr>");
for (let i of masInfo.groups.instances) {
$("#masinfotable").append("<tr><th></th><th>"+i.id.toString()+":</th><th>"+i.config.image+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th></th><th>Agencies:</th><th>"+i.agencies.counter.toString()+"</th></tr>");
}
$("#masinfotable").append("<tr><th>Agents</th></tr>");
for (let i of masInfo.agents.instances) {
$("#masinfotable").append("<tr><th></th><th>"+i.id.toString()+":</th></tr>");
$("#masinfotable").append("<tr><th></th><th></th><th>Name:</th><th>"+i.spec.name+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th></th><th>Type:</th><th>"+i.spec.type+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th></th><th>Address:</th><th>"+i.address.agency+"</th></tr>");
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment