Commit 843e66a5 authored by Qianwen's avatar Qianwen Committed by Nydia745
Browse files

restore backend and operate in frontend

parent 29b7ad77
This diff is collapsed.
......@@ -105,24 +105,6 @@ func (stor *cassStorage) addAgentLogMessage(log schemas.LogMessage) (err error)
return
}
// getAllLatestLogMessages return latest num log messages from all agents and with all topics
func (stor *cassStorage) getAllLatestLogMessages(masID int, num int) (logs []schemas.LogMessage, err error) {
var iter *gocql.Iter
iter = stor.session.Query("SELECT log WHERE masid = ? AND"+
"LIMIT ?", masID, num).Iter()
var js []byte
for iter.Scan(&js) {
var logmsg schemas.LogMessage
err = json.Unmarshal(js, &logmsg)
if err != nil {
return
}
logs = append(logs, logmsg)
}
return
}
// getLatestAgentLogMessages return the latest num log messages
func (stor *cassStorage) getLatestAgentLogMessages(masID int, agentID int, topic string,
num int) (logs []schemas.LogMessage, err error) {
......
......@@ -163,29 +163,6 @@ func (logger *Logger) handlePostLogMsgList(w http.ResponseWriter, r *http.Reques
logger.logErrors(r.URL.Path, cmapErr, httpErr)
}
// handleGetAllLatestLogMessages is the handler for request to path
// /api/logging/{masid}/latest/{num}
func (logger *Logger) handleGetAllLatestLogMessages(w http.ResponseWriter, r *http.Request) {
var cmapErr, httpErr error
masID, num, cmapErr := getMasAndNum(r)
if cmapErr != nil {
httpErr = httpreply.NotFoundError(w)
logger.logErrors(r.URL.Path, cmapErr, httpErr)
return
}
var logMsgs []schemas.LogMessage
logMsgs, cmapErr = logger.getAllLatestLogMessages(masID, num)
if cmapErr != nil {
httpErr = httpreply.CMAPError(w, cmapErr.Error())
logger.logErrors(r.URL.Path, cmapErr, httpErr)
return
}
httpErr = httpreply.Resource(w, logMsgs, cmapErr)
logger.logErrors(r.URL.Path, cmapErr, httpErr)
return
}
// 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) {
......@@ -366,20 +343,6 @@ func getAgentID(r *http.Request) (masID int, agentID int, err error) {
return
}
// getMasAnd returns the masID and num of logs from the path
func getMasAndNum(r *http.Request) (masID int, num int, err error) {
vars := mux.Vars(r)
masID, err = strconv.Atoi(vars["masid"])
if err != nil {
return
}
num, err = strconv.Atoi(vars["num"])
if err != nil {
return
}
return
}
// loggingMiddleware logs request before calling final handler
func (logger *Logger) loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
......@@ -394,8 +357,6 @@ func (logger *Logger) server(port int) (serv *http.Server) {
// r.HandleFunc("/api/", logger.handleAPI)
s := r.PathPrefix("/api").Subrouter()
s.Path("/alive").Methods("GET").HandlerFunc(logger.handleAlive)
s.Path("/logging/{masid}/latest/{num}").Methods("GET").
HandlerFunc(logger.handleGetAllLatestLogMessages)
s.Path("/logging/{masid}/{agentid}/{topic}").Methods("POST").HandlerFunc(logger.handlePostLogMsg)
s.Path("/logging/{masid}/{agentid}/{topic}").Methods("PUT", "GET", "DELETE").
HandlerFunc(logger.methodNotAllowed)
......
......@@ -129,12 +129,6 @@ func (logger *Logger) addAgentLogMessageList(logmsg []schemas.LogMessage) (err e
return
}
// getAllLatestLogMessages return the lastest num log messages with all agents and topics
func (logger *Logger) getAllLatestLogMessages(masID int, num int) (logs []schemas.LogMessage, err error) {
logs, err = logger.stor.getAllLatestLogMessages(masID, num)
return
}
// getLatestAgentLogMessages return the latest num log messages
func (logger *Logger) getLatestAgentLogMessages(masID int, agentID int, topic string,
num int) (logs []schemas.LogMessage, err error) {
......
......@@ -58,9 +58,6 @@ type storage interface {
// addAgentLogMessage adds an entry to specified logging entry
addAgentLogMessage(log schemas.LogMessage) (err error)
// getAllLatestLogMessages return the latest num log messages with all agents and topics
getAllLatestLogMessages(masID int, num int) (logs []schemas.LogMessage, err error)
// getLatestAgentLogMessages return the latest num log messages
getLatestAgentLogMessages(masID int, agentID int, topic string,
num int) (logs []schemas.LogMessage, err error)
......@@ -153,65 +150,6 @@ func (stor *localStorage) addAgentLogMessage(log schemas.LogMessage) (err error)
return
}
// getAllLatestLogMessages return the latest log messages of all agents
func (stor *localStorage) getAllLatestLogMessages(masID int, num int) (logs []schemas.LogMessage, err error) {
stor.mutex.Lock()
topics := [5]string{"error", "debug", "msg", "status", "app"}
var logs1, logs2, logs3, logs4, logs5 []schemas.LogMessage
if masID < len(stor.mas) {
for agentID := 0; agentID < len(stor.mas[masID].agents); agentID++ {
for _, topic := range topics {
switch topic {
case "error":
length := len(stor.mas[masID].agents[agentID].errLogs)
if length < num {
num = length
}
logs1 = make([]schemas.LogMessage, num, num)
copy(logs1, stor.mas[masID].agents[agentID].errLogs[length-num:length])
logs = append(logs, logs1...)
case "debug":
length := len(stor.mas[masID].agents[agentID].dbgLogs)
if length < num {
num = length
}
logs2 = make([]schemas.LogMessage, num, num)
copy(logs2, stor.mas[masID].agents[agentID].dbgLogs[length-num:length])
logs = append(logs, logs2...)
case "msg":
length := len(stor.mas[masID].agents[agentID].msgLogs)
if length < num {
num = length
}
logs3 = make([]schemas.LogMessage, num, num)
copy(logs3, stor.mas[masID].agents[agentID].msgLogs[length-num:length])
logs = append(logs, logs3...)
case "status":
length := len(stor.mas[masID].agents[agentID].statLogs)
if length < num {
num = length
}
logs4 = make([]schemas.LogMessage, num, num)
copy(logs4, stor.mas[masID].agents[agentID].statLogs[length-num:length])
logs = append(logs, logs4...)
case "app":
length := len(stor.mas[masID].agents[agentID].appLogs)
if length < num {
num = length
}
logs5 = make([]schemas.LogMessage, num, num)
copy(logs5, stor.mas[masID].agents[agentID].appLogs[length-num:length])
logs = append(logs, logs5...)
}
}
}
} else {
err = errors.New("masID not exist")
}
stor.mutex.Unlock()
return
}
// getLatestAgentLogMessages return the latest num log messages
func (stor *localStorage) getLatestAgentLogMessages(masID int, agentID int, topic string,
num int) (logs []schemas.LogMessage, err error) {
......
......@@ -269,13 +269,11 @@ stroke-width: 2;
}
.agentBox {
fill:white;
stroke:var(--primary-color);
stroke-width:5;
fill: var(--primary-color);
}
text {
fill: var(--primary-color);
fill: white;
color: var(--primary-color);
}
......
......@@ -21,7 +21,7 @@
<div class="modal-body">
<div class="row">
<div *ngFor="let id of notSelectedID">
<div class="agent-not-selected" [ngValue]="id" (click)="onSelectID(id)">
<div class="agent-not-selected" [ngValue]="id" (click)="onToggleID(id)">
agent {{id}}
</div>
</div>
......@@ -52,7 +52,7 @@
<div class="agent-title">Selected agents</div>
<div class="agents">
<div class="row">
<div *ngFor="let id of selectedID" class="agent-selected col-lg-1 active" (click)="onDeleteID(id)" [ngValue]="id" >
<div *ngFor="let id of selectedID" class="agent-selected col-lg-1 active" (click)="onToggleID(id)" [ngValue]="id" >
<p>agent {{id}} </p>
<div class="delete"><i class="fas fa-trash"></i></div>
</div>
......
......@@ -6,6 +6,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Agents} from 'src/app/models/agents.model';
import { LogMessage } from 'src/app/models/logMessage.model';
import { forkJoin, Observable } from 'rxjs';
......@@ -37,7 +38,7 @@ export class LoggerComponent implements OnInit {
selectedID: number[] = [];
selectedIDMap;
notSelectedID: number[] = [];
isAgentSelected: boolean[];
isAgentSelected: boolean[] = [];
isTopicSelected: boolean[] = [true, true, true, true, true];
topics: string[] = ["error", "debug", "msg", "status", "app"];
......@@ -58,8 +59,6 @@ export class LoggerComponent implements OnInit {
texts = [];
popoverContent: string = "This is the content of the popover";
popoverTopic: string;
allMsgs: LogMessage[] = [];
msgs: LogMessage[] = [];
constructor(
......@@ -88,7 +87,7 @@ export class LoggerComponent implements OnInit {
// get the selectedMASid from the current route
this.route.params.subscribe((params: Params) => {
this.selectedMASID = params.masid;
/* this.masService.getAgents(params.masid).subscribe((res: Agents) => {
this.masService.getAgents(params.masid).subscribe((res: Agents) => {
if (res.counter !== 0) {
this.agentID = res.instances.map(item => item.id);
for (let i = 0; i < res.counter; i++) {
......@@ -96,16 +95,8 @@ export class LoggerComponent implements OnInit {
}
this.updateSelectedID();
}
}); */
});
this.http.get("logs.json").subscribe( (res: LogMessage[] ) => {
this.allMsgs = res;
});
this.agentID = [0, 1, 2, 3, 4];
this.isAgentSelected = [false, false, false, false, false];
this.updateSelectedID();
});
});
}
......@@ -128,26 +119,44 @@ export class LoggerComponent implements OnInit {
this.notSelectedID.push(i);
}
}
this.msgs = [];
for (let msg of this.allMsgs) {
if (this.selectedID.includes(msg.agentid)) {
this.msgs.push(msg);
this.multiLogs().subscribe( logss => {
this.msgs = [];
for (let logs of logss) {
for (let log of logs) {
this.msgs.push(log);
}
}
}
}
this.msgs.sort((a, b) => {
let date1 = new Date(a.timestamp);
let date2 = new Date(b.timestamp);
return date2.getTime() - date1.getTime();
} )
console.log(this.msgs);
this.drawAllElements();
})
onDeleteID(i : number) {
this.isAgentSelected[i] = !this.isAgentSelected[i];
this.updateSelectedID();
this.drawAllElements();
}
onSelectID(i : number) {
multiLogs(): Observable<any[]> {
let res = [];
console.log(this.selectedID);
for (let id of this.selectedID) {
for (let topic of this.topics) {
res.push(this.loggerService.getNLatestLogs(this.selectedMASID.toString(),
id.toString(), topic, this.numLogs.toString()));
}
}
return forkJoin(res);
}
onToggleID(i : number) {
this.isAgentSelected[i] = !this.isAgentSelected[i];
this.updateSelectedID();
this.drawAllElements();
}
drawAgentBox() {
......@@ -217,7 +226,7 @@ export class LoggerComponent implements OnInit {
scaledDates.push(curr);
}
this.height = 800 + 2 * this.logBoxHeight * scaledDates[scaledDates.length-1];
this.height = 800 + this.logBoxHeight * scaledDates[scaledDates.length-1];
return scaledDates;
}
......@@ -229,7 +238,7 @@ export class LoggerComponent implements OnInit {
let idx = this.selectedID.indexOf(currMsg.agentid) + 1;
this.logBoxes.push({
x: this.interval *idx - this.logBoxWidth / 2,
y: 400 + 2 * this.logBoxHeight * scaledDates[i],
y: 400 + this.logBoxHeight * scaledDates[i],
topic: currMsg.topic,
timestamp: currMsg.timestamp,
msg: currMsg.msg,
......@@ -297,20 +306,6 @@ export class LoggerComponent implements OnInit {
onCreateLogs() {
const result = JSON.parse(this.display);
this.loggerService.createLogger(this.selectedMASID.toString(),result).subscribe(
(res) => {
console.log("success");
console.log(res);
this.modalService.dismissAll();
},
error => {
console.log(error);
}
);
}
onSearchLogs(num: string) {
/* this.numLogs = parseInt(num);
......
import { Injectable } from '@angular/core';
import { WebRequestService} from './web-request.service';
import { HttpParams } from '@angular/common/http';
import { LogMessage} from 'src/app/models/logMessage.model';
@Injectable({
providedIn: 'root'
......@@ -20,10 +22,6 @@ export class LoggerService {
createLogger(masid:string, payload: object) {
return this.webReqService.post(`api/logging/${masid}/list`, payload);
}
/* getAllLatestLogs(masid: string, num: string, params: HttpParams) {
return this.webReqService.getWithParam(`api/logger/${masid}/latest/${num}`, params);
} */
getNLatestLogs(masid: string, agentid: string, topic:string, num: string) {
return this.webReqService.get(`api/logging/${masid}/${agentid}/${topic}/latest/${num}`);
......
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