Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
wangpeng
dinky
Commits
80529cf8
Unverified
Commit
80529cf8
authored
Oct 20, 2023
by
gaoyan
Committed by
GitHub
Oct 20, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Optimize ]optimize The Process (#2409)
* optimize The Process * fix processID use DTO * formate code
parent
227b6e9f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
29 deletions
+56
-29
ProcessAspect.java
dinky-admin/src/main/java/org/dinky/aop/ProcessAspect.java
+2
-2
ConsoleContextHolder.java
...src/main/java/org/dinky/context/ConsoleContextHolder.java
+46
-17
ProcessStepType.java
...rc/main/java/org/dinky/process/enums/ProcessStepType.java
+8
-10
No files found.
dinky-admin/src/main/java/org/dinky/aop/ProcessAspect.java
View file @
80529cf8
...
...
@@ -87,7 +87,7 @@ public class ProcessAspect {
String
parentStep
=
MDC
.
get
(
PROCESS_STEP
);
ProcessStepType
processStepType
=
processStep
.
type
();
MDC
.
put
(
PROCESS_STEP
,
processStepType
.
getValue
());
contextHolder
.
registerProcessStep
(
processStepType
,
MDC
.
get
(
PROCESS_NAME
));
contextHolder
.
registerProcessStep
(
processStepType
,
MDC
.
get
(
PROCESS_NAME
)
,
parentStep
);
try
{
result
=
joinPoint
.
proceed
();
...
...
@@ -120,7 +120,7 @@ public class ProcessAspect {
Annotation
[]
paramAnn
=
annotations
[
i
];
for
(
Annotation
annotation
:
paramAnn
)
{
if
(
annotation
instanceof
ProcessId
)
{
return
param
;
return
String
.
valueOf
(
param
.
hashCode
())
;
}
}
}
...
...
dinky-admin/src/main/java/org/dinky/context/ConsoleContextHolder.java
View file @
80529cf8
...
...
@@ -19,14 +19,18 @@
package
org
.
dinky
.
context
;
import
org.dinky.aop.ProcessAspect
;
import
org.dinky.data.exception.BusException
;
import
org.dinky.process.enums.ProcessStatus
;
import
org.dinky.process.enums.ProcessStepType
;
import
org.dinky.process.enums.ProcessType
;
import
org.dinky.process.exception.DinkyException
;
import
org.dinky.process.model.ProcessEntity
;
import
org.dinky.process.model.ProcessStep
;
import
org.dinky.utils.LogUtil
;
import
org.apache.http.util.TextUtils
;
import
java.nio.charset.Charset
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
...
...
@@ -35,6 +39,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
org.slf4j.MDC
;
import
org.springframework.web.servlet.mvc.method.annotation.SseEmitter
;
import
com.alibaba.fastjson2.JSONObject
;
...
...
@@ -111,8 +116,8 @@ public class ConsoleContextHolder extends BaseSseContext<String, ProcessEntity>
throw
new
BusException
(
StrFormatter
.
format
(
"process {} does not exist"
,
processName
));
}
logPross
.
get
(
processName
).
appendLog
(
log
);
Map
<
String
,
ProcessStep
>
parentStep
=
getParentNode
(
processStep
,
getStepsMap
(
processName
));
parentStep
.
get
(
processStep
.
getValue
())
.
appendLog
(
log
);
ProcessStep
stepNode
=
getStepNode
(
processStep
.
getValue
()
,
getStepsMap
(
processName
));
stepNode
.
appendLog
(
log
);
sendAsync
(
processName
,
logPross
.
get
(
processName
));
}
...
...
@@ -145,9 +150,11 @@ public class ConsoleContextHolder extends BaseSseContext<String, ProcessEntity>
*
* @param type process step type
* @param processName process name
* @param parentStep parent step
* @throws RuntimeException Throws an exception if the process does not exist
*/
public
void
registerProcessStep
(
ProcessStepType
type
,
String
processName
)
throws
RuntimeException
{
public
void
registerProcessStep
(
ProcessStepType
type
,
String
processName
,
String
parentStep
)
throws
RuntimeException
{
if
(!
logPross
.
containsKey
(
processName
))
{
throw
new
BusException
(
StrFormatter
.
format
(
"Process {} does not exist"
,
processName
));
}
...
...
@@ -162,7 +169,14 @@ public class ConsoleContextHolder extends BaseSseContext<String, ProcessEntity>
.
errLog
(
new
StringBuilder
())
.
childStepsMap
(
new
LinkedHashMap
<>())
.
build
();
getParentNode
(
type
,
process
.
getStepsMap
()).
put
(
type
.
getValue
(),
processStep
);
if
(
TextUtils
.
isEmpty
(
parentStep
))
{
// parentStep为空表示为顶级节点
process
.
getStepsMap
().
put
(
type
.
getValue
(),
processStep
);
}
else
{
ProcessStep
stepNode
=
getStepNode
(
parentStep
,
process
.
getStepsMap
());
stepNode
.
getChildStepsMap
().
put
(
type
.
getValue
(),
processStep
);
}
}
/**
...
...
@@ -203,8 +217,7 @@ public class ConsoleContextHolder extends BaseSseContext<String, ProcessEntity>
if
(!
logPross
.
containsKey
(
processName
))
{
return
;
}
Map
<
String
,
ProcessStep
>
processStepNode
=
getParentNode
(
type
,
getStepsMap
(
processName
));
ProcessStep
processStep
=
processStepNode
.
get
(
type
.
getValue
());
ProcessStep
processStep
=
getStepNode
(
type
.
getValue
(),
getStepsMap
(
processName
));
processStep
.
setStepStatus
(
status
);
processStep
.
setEndTime
(
LocalDateTime
.
now
());
processStep
.
setTime
(
processStep
.
getEndTime
().
compareTo
(
processStep
.
getStartTime
()));
...
...
@@ -213,19 +226,35 @@ public class ConsoleContextHolder extends BaseSseContext<String, ProcessEntity>
}
}
private
ProcessStep
getStepNode
(
String
stepType
,
Map
<
String
,
ProcessStep
>
stepsMap
)
{
ProcessStep
stepNode
=
findStepNode
(
stepType
,
stepsMap
);
if
(
stepNode
!=
null
)
{
return
stepNode
;
}
String
errorStr
=
StrFormatter
.
format
(
"Get Parent Node Failed, This is most likely a Dinky bug, "
+
"please report the following information back to the community:\nProcess:{},\nstep:{},\nprocessNam:{}"
,
JSONObject
.
toJSONString
(
logPross
),
stepType
,
MDC
.
get
(
ProcessAspect
.
PROCESS_NAME
));
throw
new
DinkyException
(
errorStr
);
}
/**
* The * method first checks if a given type has a parent step (i.e. type.getParentStep()) is null).
* If there is a parent step, recursively call the getParentNode method, passing the parent step type and stepsMap
* to get the child step mapping of the parent node.
* If a given type does not have a parent step, it returns steps directly to indicate that the step of that type is a top-level step.
* Finally, the getParentNode method returns a mapping of child steps containing the parent node for use in other methods.
*/
private
Map
<
String
,
ProcessStep
>
getParentNode
(
ProcessStepType
type
,
Map
<
String
,
ProcessStep
>
stepsMap
)
{
if
(
type
.
getParentStep
()
!=
null
)
{
Map
<
String
,
ProcessStep
>
map
=
getParentNode
(
type
.
getParentStep
(),
stepsMap
);
return
map
.
get
(
type
.
getParentStep
().
getValue
()).
getChildStepsMap
();
* 递归查找节点
* */
private
ProcessStep
findStepNode
(
String
stepType
,
Map
<
String
,
ProcessStep
>
stepsMap
)
{
for
(
Map
.
Entry
<
String
,
ProcessStep
>
entry
:
stepsMap
.
entrySet
())
{
if
(
entry
.
getKey
().
equals
(
stepType
))
{
return
entry
.
getValue
();
}
else
{
ProcessStep
stepNode
=
findStepNode
(
stepType
,
entry
.
getValue
().
getChildStepsMap
());
if
(
stepNode
!=
null
)
{
return
stepNode
;
}
}
}
return
stepsMap
;
return
null
;
}
private
Map
<
String
,
ProcessStep
>
getStepsMap
(
String
processName
)
{
...
...
dinky-process/src/main/java/org/dinky/process/enums/ProcessStepType.java
View file @
80529cf8
...
...
@@ -26,22 +26,20 @@ import lombok.Getter;
@Getter
public
enum
ProcessStepType
{
SUBMIT_TASK
(
"SUBMIT_TASK"
,
null
,
Status
.
PROCESS_SUBMIT_SUBMITTASK
),
SUBMIT_PRECHECK
(
"SUBMIT_PRECHECK"
,
S
UBMIT_TASK
,
S
tatus
.
PROCESS_SUBMIT_CHECKSQL
),
SUBMIT_EXECUTE
(
"SUBMIT_EXECUTE"
,
S
UBMIT_TASK
,
S
tatus
.
PROCESS_SUBMIT_EXECUTE
),
SUBMIT_BUILD_CONFIG
(
"SUBMIT_BUILD_CONFIG"
,
S
UBMIT_EXECUTE
,
S
tatus
.
PROCESS_SUBMIT_BUILDCONFIG
),
SUBMIT_EXECUTE_COMMON_SQL
(
"SUBMIT_EXECUTE_COMMON_SQL"
,
S
UBMIT_BUILD_CONFIG
,
S
tatus
.
PROCESS_SUBMIT_EXECUTECOMMSQL
),
SUBMIT_EXECUTE_FLINK_SQL
(
"SUBMIT_EXECUTE_FLINK_SQL"
,
S
UBMIT_BUILD_CONFIG
,
S
tatus
.
PROCESS_SUBMIT_EXECUTEFLINKSQL
),
UNKNOWN
(
"UNKNOWN"
,
null
,
Status
.
UNKNOWN_ERROR
),
SUBMIT_TASK
(
"SUBMIT_TASK"
,
Status
.
PROCESS_SUBMIT_SUBMITTASK
),
SUBMIT_PRECHECK
(
"SUBMIT_PRECHECK"
,
Status
.
PROCESS_SUBMIT_CHECKSQL
),
SUBMIT_EXECUTE
(
"SUBMIT_EXECUTE"
,
Status
.
PROCESS_SUBMIT_EXECUTE
),
SUBMIT_BUILD_CONFIG
(
"SUBMIT_BUILD_CONFIG"
,
Status
.
PROCESS_SUBMIT_BUILDCONFIG
),
SUBMIT_EXECUTE_COMMON_SQL
(
"SUBMIT_EXECUTE_COMMON_SQL"
,
Status
.
PROCESS_SUBMIT_EXECUTECOMMSQL
),
SUBMIT_EXECUTE_FLINK_SQL
(
"SUBMIT_EXECUTE_FLINK_SQL"
,
Status
.
PROCESS_SUBMIT_EXECUTEFLINKSQL
),
UNKNOWN
(
"UNKNOWN"
,
Status
.
UNKNOWN_ERROR
),
;
private
final
String
value
;
private
final
ProcessStepType
parentStep
;
private
final
Status
desc
;
ProcessStepType
(
String
type
,
ProcessStepType
parentStep
,
Status
desc
)
{
ProcessStepType
(
String
type
,
Status
desc
)
{
this
.
value
=
type
;
this
.
parentStep
=
parentStep
;
this
.
desc
=
desc
;
}
...
...
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