Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
Cloud
MAS
clonemap
Commits
b961d1ed
Commit
b961d1ed
authored
Apr 09, 2021
by
Qianwen
Browse files
restore backend and operate in frontend
parent
29b7ad77
Changes
9
Hide whitespace changes
Inline
Side-by-side
pkg/frontend/handler.go
View file @
b961d1ed
...
...
@@ -238,7 +238,6 @@ func (fe *Frontend) server(port int) (serv *http.Server) {
s
.
Path
(
"/df/{masid}/svc/desc/{desc}/node/{nodeid}/dist/{dist}"
)
.
Methods
(
"Get"
)
.
HandlerFunc
(
fe
.
handleSvcWithDist
)
// api for logger
// s.Path("/logging/{masid}/latest/{num}").Methods("GET").HandlerFunc(fe.handleGetAllLatestLogs)
s
.
Path
(
"/logging/{masid}/{agentid}/{topic}/latest/{num}"
)
.
Methods
(
"GET"
)
.
HandlerFunc
(
fe
.
handleGetNLatestLogs
)
s
.
Path
(
"/logging/{masid}/list"
)
.
Methods
(
"Post"
)
.
HandlerFunc
(
fe
.
handlePostLogs
)
/* s.Path("/logging/{masid}/{agentid}/{topic}/time/{begin}/{end}").Methods("Get").HandlerFunc(fe.handleGetLogsWithRange) */
...
...
pkg/logger/cassandra.go
View file @
b961d1ed
...
...
@@ -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
)
{
...
...
pkg/logger/handler.go
View file @
b961d1ed
...
...
@@ -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
)
...
...
pkg/logger/logger.go
View file @
b961d1ed
...
...
@@ -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
)
{
...
...
pkg/logger/storage.go
View file @
b961d1ed
...
...
@@ -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
)
{
...
...
web/src/app/pages/logger/logger.component.css
View file @
b961d1ed
...
...
@@ -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
);
}
...
...
web/src/app/pages/logger/logger.component.html
View file @
b961d1ed
...
...
@@ -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)=
"on
Select
ID(id)"
>
<div
class=
"agent-not-selected"
[ngValue]=
"id"
(click)=
"on
Toggle
ID(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)=
"on
Delet
eID(id)"
[ngValue]=
"id"
>
<div
*ngFor=
"let id of selectedID"
class=
"agent-selected col-lg-1 active"
(click)=
"on
Toggl
eID(id)"
[ngValue]=
"id"
>
<p>
agent {{id}}
</p>
<div
class=
"delete"
><i
class=
"fas fa-trash"
></i></div>
</div>
...
...
web/src/app/pages/logger/logger.component.ts
View file @
b961d1ed
...
...
@@ -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);
...
...
web/src/app/services/logger.service.ts
View file @
b961d1ed
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
}
`
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment