Commit 86274e11 authored by Stefan Dähling's avatar Stefan Dähling
Browse files

logger handler with gorila mux

parent 327ec269
Pipeline #413923 passed with stages
in 5 minutes and 15 seconds
......@@ -117,7 +117,7 @@ func (ams *AMS) handlePostMAS(w http.ResponseWriter, r *http.Request) {
return
}
// handleGetMASID is the handler for get requests to path /api/clonemap/mas/{mas-id}
// handleGetMASID is the handler for get requests to path /api/clonemap/mas/{masid}
func (ams *AMS) handleGetMASID(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
......@@ -125,7 +125,7 @@ func (ams *AMS) handleGetMASID(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
masID, cmapErr := strconv.Atoi(vars["masid"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
// return long information about specified MAS
......@@ -135,7 +135,7 @@ func (ams *AMS) handleGetMASID(w http.ResponseWriter, r *http.Request) {
return
}
// handleDeleteMASID is the handler for delete requests to path /api/clonemap/mas/{mas-id}
// handleDeleteMASID is the handler for delete requests to path /api/clonemap/mas/{masid}
func (ams *AMS) handleDeleteMASID(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
......@@ -143,7 +143,7 @@ func (ams *AMS) handleDeleteMASID(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
masID, cmapErr := strconv.Atoi(vars["masid"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
// delete specified MAS
......@@ -166,7 +166,7 @@ func (ams *AMS) handleGetMASName(w http.ResponseWriter, r *http.Request) {
return
}
// handleGetAgents is the handler for get requests to path /api/clonemap/mas/{mas-id}/agents
// handleGetAgents is the handler for get requests to path /api/clonemap/mas/{masid}/agents
func (ams *AMS) handleGetAgents(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
......@@ -174,7 +174,7 @@ func (ams *AMS) handleGetAgents(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
masID, cmapErr := strconv.Atoi(vars["masid"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
// return short information of all agents in specified MAS
......@@ -184,7 +184,7 @@ func (ams *AMS) handleGetAgents(w http.ResponseWriter, r *http.Request) {
return
}
// handlePostAgent is the handler for post requests to path /api/clonemap/mas/{mas-id}/agents
// handlePostAgent is the handler for post requests to path /api/clonemap/mas/{masid}/agents
func (ams *AMS) handlePostAgent(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
......@@ -192,7 +192,7 @@ func (ams *AMS) handlePostAgent(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
masID, cmapErr := strconv.Atoi(vars["masid"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
// create new agent in MAS
......@@ -213,15 +213,15 @@ func (ams *AMS) handlePostAgent(w http.ResponseWriter, r *http.Request) {
return
}
// handleGetAgentID is the handler for get requests to path /api/clonemap/mas/{mas-id}/agents/
// {agent-id}
// handleGetAgentID is the handler for get requests to path
// /api/clonemap/mas/{masid}/agents/{agentid}
func (ams *AMS) handleGetAgentID(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer ams.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
var agentInfo schemas.AgentInfo
......@@ -230,15 +230,15 @@ func (ams *AMS) handleGetAgentID(w http.ResponseWriter, r *http.Request) {
return
}
// handleDeleteAgentID is the handler for delete requests to path /api/clonemap/mas/{mas-id}/agents/
// {agent-id}
// handleDeleteAgentID is the handler for delete requests to path
// /api/clonemap/mas/{masid}/agents/{agentid}
func (ams *AMS) handleDeleteAgentID(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer ams.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
// delete specified agent
......@@ -248,14 +248,14 @@ func (ams *AMS) handleDeleteAgentID(w http.ResponseWriter, r *http.Request) {
}
// handleGetAgentAddress is the handler for get requests to path
// /api/clonemap/mas/{mas-id}/agents/{agent-id}/address
// /api/clonemap/mas/{masid}/agents/{agentid}/address
func (ams *AMS) handleGetAgentAddress(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer ams.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
// return address of specified agent
......@@ -266,14 +266,14 @@ func (ams *AMS) handleGetAgentAddress(w http.ResponseWriter, r *http.Request) {
}
// handlePutAgentAddress is the handler for put requests to path
// /api/clonemap/mas/{mas-id}/agents/{agent-id}/address
// /api/clonemap/mas/{masid}/agents/{agentid}/address
func (ams *AMS) handlePutAgentAddress(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer ams.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
// update address of specified agent
......@@ -295,14 +295,14 @@ func (ams *AMS) handlePutAgentAddress(w http.ResponseWriter, r *http.Request) {
}
// handlePutAgentCustom is the put handler for requests to path
// /api/clonemap/mas/{mas-id}/agents/{agent-id}/custom
// /api/clonemap/mas/{masid}/agents/{agentid}/custom
func (ams *AMS) handlePutAgentCustom(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer ams.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
// update custom of specified agent
......@@ -327,7 +327,7 @@ func (ams *AMS) handleGetAgentName(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
masID, cmapErr := strconv.Atoi(vars["masid"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
name := vars["name"]
......@@ -338,7 +338,7 @@ func (ams *AMS) handleGetAgentName(w http.ResponseWriter, r *http.Request) {
return
}
// handleGetAgencies is the handler for get requests to path /api/cloumap/mas/{mas-id}/agencies
// handleGetAgencies is the handler for get requests to path /api/cloumap/mas/{masid}/agencies
func (ams *AMS) handleGetAgencies(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
......@@ -346,7 +346,7 @@ func (ams *AMS) handleGetAgencies(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
masID, cmapErr := strconv.Atoi(vars["masid"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
// return information of specified agency
......@@ -357,7 +357,7 @@ func (ams *AMS) handleGetAgencies(w http.ResponseWriter, r *http.Request) {
}
// handleGetAgencyID is the handler for get requests to path
// /api/clonemap/mas/{mas-id}/imgroup/{imID}/agencies/{agency-id}
// /api/clonemap/mas/{masid}/imgroup/{imid}/agencies/{agencyid}
func (ams *AMS) handleGetAgencyID(w http.ResponseWriter, r *http.Request) {
ams.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
......@@ -365,17 +365,17 @@ func (ams *AMS) handleGetAgencyID(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
masID, cmapErr := strconv.Atoi(vars["masid"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
imID, cmapErr := strconv.Atoi(vars["imid"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
agencyID, cmapErr := strconv.Atoi(vars["agencyid"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
httpErr = httpreply.NotFoundError(w)
return
}
var agencySpec schemas.AgencyInfoFull
......
......@@ -52,7 +52,6 @@ import (
"io/ioutil"
"net/http"
"strconv"
"strings"
"time"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/common/httpreply"
......@@ -60,290 +59,229 @@ import (
"github.com/gorilla/mux"
)
// handleAPI is the global handler for requests to path /api
func (logger *Logger) handleAPI(w http.ResponseWriter, r *http.Request) {
var cmapErr, httpErr error
// handleAlive is the handler for requests to path /api/alive
func (logger *Logger) handleAlive(w http.ResponseWriter, r *http.Request) {
logger.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
// determine which ressource is requested and call corresponding handler
respath := strings.Split(r.URL.EscapedPath(), "/")
resvalid := false
switch len(respath) {
case 5:
if respath[2] == "logging" {
var masID int
masID, cmapErr = strconv.Atoi(respath[3])
if cmapErr == nil {
if respath[4] == "list" {
cmapErr, httpErr = logger.handleLoggerList(masID, w, r)
resvalid = true
}
}
} else if respath[2] == "state" {
var masID, agentID int
masID, cmapErr = strconv.Atoi(respath[3])
if cmapErr == nil {
if respath[4] == "list" {
cmapErr, httpErr = logger.handleStateList(masID, w, r)
resvalid = true
} else {
agentID, cmapErr = strconv.Atoi(respath[4])
if cmapErr == nil {
cmapErr, httpErr = logger.handleState(masID, agentID, w, r)
resvalid = true
}
}
}
}
case 6:
if respath[2] == "logging" {
var masID, agentID int
masID, cmapErr = strconv.Atoi(respath[3])
if cmapErr == nil {
agentID, cmapErr = strconv.Atoi(respath[4])
if cmapErr == nil {
if respath[5] == "list" {
cmapErr, httpErr = logger.handleLoggerList(masID, w, r)
} else if respath[5] == "comm" {
cmapErr, httpErr = logger.handleCommunication(masID, agentID, w, r)
} else {
logType := respath[5]
cmapErr, httpErr = logger.handleLoggerNew(masID, agentID, logType, w, r)
}
resvalid = true
}
}
}
case 8:
if respath[2] == "logging" && respath[6] == "latest" {
var masID, agentID, num int
masID, cmapErr = strconv.Atoi(respath[3])
if cmapErr == nil {
agentID, cmapErr = strconv.Atoi(respath[4])
if cmapErr == nil {
num, cmapErr = strconv.Atoi(respath[7])
logType := respath[5]
if cmapErr == nil {
cmapErr, httpErr = logger.handleLogsLatest(masID, agentID, logType, num,
w, r)
resvalid = true
}
}
}
}
case 9:
if respath[2] == "logging" && respath[6] == "time" {
var masID, agentID int
var start, end time.Time
masID, cmapErr = strconv.Atoi(respath[3])
if cmapErr == nil {
agentID, cmapErr = strconv.Atoi(respath[4])
if cmapErr == nil {
start, cmapErr = time.Parse(time.RFC3339, respath[7])
if cmapErr == nil {
end, cmapErr = time.Parse(time.RFC3339, respath[8])
logType := respath[5]
if cmapErr == nil {
cmapErr, httpErr = logger.handleLogsTime(masID, agentID, logType, start,
end, w, r)
resvalid = true
}
}
}
}
}
default:
cmapErr = errors.New("Resource not found")
}
var httpErr error
httpErr = httpreply.Alive(w, nil)
logger.logErrors(r.URL.Path, nil, httpErr)
return
}
if !resvalid {
httpErr = httpreply.NotFoundError(w)
cmapErr = errors.New("Resource not found")
}
// handlePostLogMsg is the handler for post requests to path
// /api/logging/{masid}/{agentid}/{topic}
func (logger *Logger) handlePostLogMsg(w http.ResponseWriter, r *http.Request) {
logger.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer logger.logErrors(r.URL.Path, cmapErr, httpErr)
// create new log message entry
var body []byte
body, cmapErr = ioutil.ReadAll(r.Body)
if cmapErr != nil {
logger.logError.Println(respath, cmapErr)
httpErr = httpreply.InvalidBodyError(w)
return
}
if httpErr != nil {
logger.logError.Println(respath, httpErr)
var logmsg schemas.LogMessage
cmapErr = json.Unmarshal(body, &logmsg)
if cmapErr != nil {
httpErr = httpreply.JSONUnmarshalError(w)
return
}
go logger.addAgentLogMessage(logmsg)
httpErr = httpreply.Created(w, nil, "text/plain", []byte("Ressource Created"))
return
}
// handleAlive is the handler for requests to path /api/alive
func (logger *Logger) handleAlive(w http.ResponseWriter, r *http.Request) {
// handleGetCommunication is the handler for get requests to path
// /api/logging/{masid}/{agentid}/comm
func (logger *Logger) handleGetCommunication(w http.ResponseWriter, r *http.Request) {
logger.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var httpErr error
httpErr = httpreply.Alive(w, nil)
logger.logErrors(r.URL.Path, nil, httpErr)
var cmapErr, httpErr error
defer logger.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.NotFoundError(w)
return
}
var comm []schemas.Communication
comm, cmapErr = logger.getCommunication(masID, agentID)
httpErr = httpreply.Resource(w, comm, cmapErr)
return
}
// handleLoggerNew is the handler for requests to path /api/logger/{mas-id}/{agent-id}/{logtype}
func (logger *Logger) handleLoggerNew(masID int, agentid int, logType string, w http.ResponseWriter,
r *http.Request) (cmapErr, httpErr error) {
if r.Method == "POST" {
// create new log message entry
var body []byte
body, cmapErr = ioutil.ReadAll(r.Body)
if cmapErr == nil {
var logmsg schemas.LogMessage
cmapErr = json.Unmarshal(body, &logmsg)
if cmapErr == nil {
go logger.addAgentLogMessage(logmsg)
httpErr = httpreply.Created(w, nil, "text/plain", []byte("Ressource Created"))
} else {
httpErr = httpreply.JSONUnmarshalError(w)
}
} else {
httpErr = httpreply.InvalidBodyError(w)
}
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/logger/{mas-id}/{agent-id}/" +
"{logtype}")
// handlePutCommunication is the handler for put requests to path
// /api/logging/{masid}/{agentid}/comm
func (logger *Logger) handlePutCommunication(w http.ResponseWriter, r *http.Request) {
logger.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer logger.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.NotFoundError(w)
return
}
// update communication data
var body []byte
body, cmapErr = ioutil.ReadAll(r.Body)
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
return
}
var comm []schemas.Communication
cmapErr = json.Unmarshal(body, &comm)
if cmapErr != nil {
httpErr = httpreply.JSONUnmarshalError(w)
return
}
go logger.updateCommunication(masID, agentID, comm)
httpErr = httpreply.Updated(w, nil)
return
}
// handleCommunication is the handler for requests to path /api/logger/{mas-id}/{agent-id}/comm
func (logger *Logger) handleCommunication(masID int, agentID int, w http.ResponseWriter,
r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
var comm []schemas.Communication
comm, cmapErr = logger.getCommunication(masID, agentID)
httpErr = httpreply.Resource(w, comm, cmapErr)
} else if r.Method == "PUT" {
// update communication data
var body []byte
body, cmapErr = ioutil.ReadAll(r.Body)
if cmapErr == nil {
var comm []schemas.Communication
cmapErr = json.Unmarshal(body, &comm)
if cmapErr == nil {
go logger.updateCommunication(masID, agentID, comm)
httpErr = httpreply.Updated(w, nil)
} else {
httpErr = httpreply.JSONUnmarshalError(w)
}
} else {
httpErr = httpreply.InvalidBodyError(w)
}
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/logger/{mas-id}/{agent-id}/" +
"{logtype}")
// handlePostLogMsgList is the handler for post requests to path /api/logging/{masid}/list
func (logger *Logger) handlePostLogMsgList(w http.ResponseWriter, r *http.Request) {
logger.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer logger.logErrors(r.URL.Path, cmapErr, httpErr)
// create new log message entry
var body []byte
body, cmapErr = ioutil.ReadAll(r.Body)
if cmapErr != nil {
httpErr = httpreply.NotFoundError(w)
return
}
var logmsg []schemas.LogMessage
cmapErr = json.Unmarshal(body, &logmsg)
if cmapErr != nil {
httpErr = httpreply.JSONUnmarshalError(w)
return
}
go logger.addAgentLogMessageList(logmsg)
httpErr = httpreply.Created(w, nil, "text/plain", []byte("Ressource Created"))
return
}
// handleLoggerList is the handler for requests to path /api/logger/{mas-id}/list
func (logger *Logger) handleLoggerList(masID int, w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr error) {
if r.Method == "POST" {
// create new log message entry
var body []byte
body, cmapErr = ioutil.ReadAll(r.Body)
if cmapErr == nil {
var logmsg []schemas.LogMessage
cmapErr = json.Unmarshal(body, &logmsg)
if cmapErr == nil {
go logger.addAgentLogMessageList(logmsg)
httpErr = httpreply.Created(w, nil, "text/plain", []byte("Ressource Created"))
} else {
httpErr = httpreply.JSONUnmarshalError(w)
}
} else {
httpErr = httpreply.InvalidBodyError(w)
}
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/logger/{mas-id}/list}")
// handleGetLogsLatest is the handler for requests to path
// /api/logging/{masid}/{agentid}/{topic}/latest/{num}
func (logger *Logger) handleGetLogsLatest(w http.ResponseWriter, r *http.Request) {
logger.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer logger.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.NotFoundError(w)
return
}
vars := mux.Vars(r)
topic := vars["topic"]
num, cmapErr := strconv.Atoi(vars["num"])
if cmapErr != nil {
httpErr = httpreply.InvalidBodyError(w)
return
}
var logMsg []schemas.LogMessage
logMsg, cmapErr = logger.getLatestAgentLogMessages(masID, agentID, topic, num)
httpErr = httpreply.Resource(w, logMsg, cmapErr)
return
}
// handleLogsLatest is the handler for requests to path /api/logger/{mas-id}/{agent-id}/{logtype}/
// latest/{num}
func (logger *Logger) handleLogsLatest(masID int, agentid int, logType string, num int,
w http.ResponseWriter, r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
var logMsg []schemas.LogMessage
logMsg, cmapErr = logger.getLatestAgentLogMessages(masID, agentid, logType, num)
httpErr = httpreply.Resource(w, logMsg, cmapErr)
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/logger/{mas-id}/{agent-id}/" +
"{logtype}/latest/{num}")
// handleGetLogsTime is the handler for get requests to path
// /api/logging/{masid}/{agentid}/{topic}/time/{start}/{end}
func (logger *Logger) handleGetLogsTime(w http.ResponseWriter, r *http.Request) {
logger.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer logger.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.NotFoundError(w)
return
}
vars := mux.Vars(r)
topic := vars["topic"]
start, cmapErr := time.Parse(time.RFC3339, vars["start"])
if cmapErr != nil {
httpErr = httpreply.NotFoundError(w)
return
}
end, cmapErr := time.Parse(time.RFC3339, vars["end"])
if cmapErr != nil {
httpErr = httpreply.NotFoundError(w)
return
}
var logMsg []schemas.LogMessage
logMsg, cmapErr = logger.getAgentLogMessagesInRange(masID, agentID, topic, start, end)
httpErr = httpreply.Resource(w, logMsg, cmapErr)
return
}
// handleLogsTime is the handler for requests to path /api/logger/{mas-id}/{agent-id}/{logtype}/
// time/{start}/{end}
func (logger *Logger) handleLogsTime(masID int, agentid int, logType string, start time.Time,
end time.Time, w http.ResponseWriter, r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
var logMsg []schemas.LogMessage
logMsg, cmapErr = logger.getAgentLogMessagesInRange(masID, agentid, logType, start, end)
httpErr = httpreply.Resource(w, logMsg, cmapErr)
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/logger/{mas-id}/{agent-id}/" +
"{logtype}/time/{start}/{end}")
// handleGetState is the handler for get requests to path /api/state/{masid}/{agentid}
func (logger *Logger) handleGetState(w http.ResponseWriter, r *http.Request) {
logger.logInfo.Println("Received Request: ", r.Method, " ", r.URL.EscapedPath())
var cmapErr, httpErr error
defer logger.logErrors(r.URL.Path, cmapErr, httpErr)
masID, agentID, cmapErr := getAgentID(r)
if cmapErr != nil {
httpErr = httpreply.NotFoundError(w)
return
}
var state schemas.State
state, cmapErr = logger.getAgentState(masID, agentID)
httpErr = httpreply.Resource(w, state, cmapErr)
return