Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
holmes
Commits
fa1b2f33
Commit
fa1b2f33
authored
Sep 13, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
ed3dc9a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
8 deletions
+19
-8
RecordOperationAspect.java
src/main/java/cn/qg/holmes/aspect/RecordOperationAspect.java
+9
-3
K8sController.java
src/main/java/cn/qg/holmes/controller/k8s/K8sController.java
+8
-5
UserBehaviorRecord.java
...java/cn/qg/holmes/entity/behavior/UserBehaviorRecord.java
+2
-0
No files found.
src/main/java/cn/qg/holmes/aspect/RecordOperationAspect.java
View file @
fa1b2f33
...
...
@@ -17,6 +17,7 @@ import org.aspectj.lang.reflect.MethodSignature;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.DefaultParameterNameDiscoverer
;
import
org.springframework.core.ParameterNameDiscoverer
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
...
...
@@ -32,6 +33,7 @@ import java.lang.reflect.Parameter;
@Slf4j
@Aspect
@Component
@Order
(
5
)
public
class
RecordOperationAspect
{
@Autowired
...
...
@@ -40,7 +42,7 @@ public class RecordOperationAspect {
@Autowired
UserBehaviorRecordService
userBehaviorRecordService
;
@
Before
(
"@annotation(cn.qg.holmes.config.annotation.RecordOperation)"
)
@
After
(
"@annotation(cn.qg.holmes.config.annotation.RecordOperation)"
)
public
void
after
(
JoinPoint
joinPoint
)
{
// 获取token,并根据token获取到用户名
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
...
...
@@ -50,7 +52,7 @@ public class RecordOperationAspect {
throw
new
UnauthorizedException
();
}
String
username
=
tokenService
.
getUserInfoFromCache
(
token
).
get
Usern
ame
();
String
username
=
tokenService
.
getUserInfoFromCache
(
token
).
get
ChineseN
ame
();
Signature
signature
=
joinPoint
.
getSignature
();
MethodSignature
methodSignature
=
(
MethodSignature
)
signature
;
RecordOperation
recordOperation
=
methodSignature
.
getMethod
().
getAnnotation
(
RecordOperation
.
class
);
...
...
@@ -58,6 +60,7 @@ public class RecordOperationAspect {
String
action
=
recordOperation
.
value
();
String
namespace
=
""
;
String
serviceName
=
""
;
String
image
=
""
;
// 获取方法里的参数
Object
[]
args
=
joinPoint
.
getArgs
();
ParameterNameDiscoverer
pnd
=
new
DefaultParameterNameDiscoverer
();
...
...
@@ -71,10 +74,11 @@ public class RecordOperationAspect {
if
(
parameterNames
[
i
].
equals
(
"namespace"
))
{
namespace
=
args
[
i
].
toString
();
}
if
(
parameterNames
[
i
].
equals
(
"
S
erviceCreateVo"
))
{
if
(
parameterNames
[
i
].
equals
(
"
s
erviceCreateVo"
))
{
ServiceCreateVo
serviceCreateVo
=
(
ServiceCreateVo
)
args
[
i
];
serviceName
=
serviceCreateVo
.
getServiceName
();
namespace
=
serviceCreateVo
.
getNamespace
();
image
=
serviceCreateVo
.
getImage
().
split
(
":"
)[
1
];
}
}
}
...
...
@@ -85,6 +89,8 @@ public class RecordOperationAspect {
userBehaviorRecord
.
setAction
(
action
);
userBehaviorRecord
.
setNamespace
(
namespace
);
userBehaviorRecord
.
setServiceName
(
serviceName
);
userBehaviorRecord
.
setImage
(
image
);
log
.
info
(
"用户{}在{}环境{}了服务{}。"
,
username
,
namespace
,
action
,
serviceName
);
userBehaviorRecordService
.
save
(
userBehaviorRecord
);
}
}
src/main/java/cn/qg/holmes/controller/k8s/K8sController.java
View file @
fa1b2f33
...
...
@@ -87,7 +87,7 @@ public class K8sController {
* @param serviceCreateVo 创建实体类
* @return
*/
@RecordOperation
(
"
create
"
)
@RecordOperation
(
"
新增服务
"
)
@PostMapping
(
"/service/create"
)
public
JsonResult
createPod
(
@RequestBody
ServiceCreateVo
serviceCreateVo
)
{
try
{
...
...
@@ -212,12 +212,13 @@ public class K8sController {
/**
* 重置pod
* @param namespace 环境
* @param
pod
Name podName
* @param
service
Name podName
* @return
*/
@RecordOperation
(
"重置服务"
)
@PostMapping
(
"/service/redeploy"
)
public
JsonResult
resetPodByName
(
String
namespace
,
String
pod
Name
)
{
return
JsonResult
.
buildSuccessResult
(
k8sService
.
resetPod
(
namespace
,
pod
Name
));
public
JsonResult
resetPodByName
(
String
namespace
,
String
service
Name
)
{
return
JsonResult
.
buildSuccessResult
(
k8sService
.
resetPod
(
namespace
,
service
Name
));
}
/**
...
...
@@ -225,6 +226,7 @@ public class K8sController {
* @param serviceCreateVo
* @return
*/
@RecordOperation
(
"jenkins打包"
)
@PostMapping
(
"/service/modify"
)
public
JsonResult
modifyPod
(
@RequestBody
ServiceCreateVo
serviceCreateVo
)
{
log
.
info
(
"接口/k8s/service/modify收到请求,请求参数为:{}"
,
JSON
.
toJSONString
(
serviceCreateVo
));
...
...
@@ -291,6 +293,7 @@ public class K8sController {
* @param serviceCreateVo
* @return
*/
@RecordOperation
(
"更新服务"
)
@PostMapping
(
"/service/update"
)
public
JsonResult
updatePod
(
@RequestBody
ServiceCreateVo
serviceCreateVo
)
{
String
namespace
=
serviceCreateVo
.
getNamespace
();
...
...
@@ -342,7 +345,7 @@ public class K8sController {
* @param serviceName 服务名称
* @return
*/
@RecordOperation
(
"
delete
"
)
@RecordOperation
(
"
删除服务
"
)
@PostMapping
(
"/service/delete"
)
public
JsonResult
deletePodByName
(
String
namespace
,
String
serviceName
)
{
return
JsonResult
.
buildSuccessResult
(
k8sService
.
deleteDeployment
(
namespace
,
serviceName
));
...
...
src/main/java/cn/qg/holmes/entity/behavior/UserBehaviorRecord.java
View file @
fa1b2f33
...
...
@@ -23,6 +23,8 @@ public class UserBehaviorRecord {
private
String
serviceName
;
private
String
image
;
private
String
namespace
;
private
String
username
;
...
...
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