Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
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
liyuan
byit-myth-job
Commits
5a46c038
Commit
5a46c038
authored
Jan 07, 2020
by
guominglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试发布接口
parent
84a3c1bc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
0 deletions
+106
-0
JobUtils.java
...exector-plugin/src/main/java/com/byit/utils/JobUtils.java
+28
-0
Test.java
...ent/byit-demo-client/src/main/java/com/byit/job/Test.java
+78
-0
No files found.
byit-myth-executor/myth-exector-plugin/src/main/java/com/byit/utils/JobUtils.java
View file @
5a46c038
...
...
@@ -2,6 +2,7 @@ package com.byit.utils;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.job.dto.plugin.PluginPackage
;
import
com.byit.job.enums.plugin.PluginEnum
;
import
com.byit.job.exceptions.plugin.PluginException
;
import
com.byit.job.handler.interfaces.IJobHandler
;
...
...
@@ -24,6 +25,10 @@ import java.util.concurrent.ConcurrentHashMap;
public
class
JobUtils
{
private
static
final
String
REQUEST_PREFIX
=
"http://"
;
private
static
final
String
REQUEST_ADD_JOB_RESOURCES_SUFFIX
=
"/job/addJob"
;
//发布工作流
private
static
final
String
REQUEST_FLOW_PUBLISH
=
"/api/flow/publish"
;
//创建工作空间
private
static
final
String
REQUEST_WORKSPACE_ADD
=
"/api/workspace/add"
;
/**
* 当前项目运行环境 jar file
*/
...
...
@@ -56,6 +61,29 @@ public class JobUtils {
}
public
static
String
publish
(
PluginPackage
pluginPackage
){
log
.
info
(
"---------------开始发布工作流,flowName:{}---------------------"
,
pluginPackage
.
getFlow
().
getName
());
//请求的路径
String
requestUrl
=
REQUEST_PREFIX
+
"127.0.0.1"
+
":"
+
"8080"
+
REQUEST_FLOW_PUBLISH
;
//发送请求 添加任务
String
addRequestResult
=
HttpUtil
.
post
(
requestUrl
,
"pluginPackageParam="
+
JSON
.
toJSONString
(
pluginPackage
));
log
.
info
(
"--------------------添加任务完成,添加结果为:{}------------------------"
,
addRequestResult
);
return
addRequestResult
;
}
public
static
String
addWorkspace
(
String
workspaceName
){
log
.
info
(
"---------------开始创建工作空间,workspaceName:{}---------------------"
,
workspaceName
);
//请求的路径
String
requestUrl
=
REQUEST_PREFIX
+
"127.0.0.1"
+
":"
+
"8080"
+
REQUEST_WORKSPACE_ADD
;
//发送请求 添加任务
String
addRequestResult
=
HttpUtil
.
post
(
requestUrl
,
"workspaceName="
+
workspaceName
);
log
.
info
(
"--------------------添加任务完成,添加结果为:{}------------------------"
,
addRequestResult
);
return
addRequestResult
;
}
/**
* 判断当前的运行环境是什么 jar : table of Contents(目录)
* @return jar -->true 目录 -->false
...
...
demo-client/byit-demo-client/src/main/java/com/byit/job/Test.java
0 → 100644
View file @
5a46c038
package
com
.
byit
.
job
;
import
com.byit.job.dto.plugin.*
;
import
com.byit.utils.JobUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* @description: 测试
* @author: gml
* @create: 2020-01-07 10:11
*/
public
class
Test
{
public
static
void
main
(
String
[]
args
)
{
JobUtils
.
addWorkspace
(
"test"
);
PluginPackage
pluginPackage
=
new
PluginPackage
();
pluginPackage
.
setWorkspaceName
(
"test"
);
pluginPackage
.
setFlow
(
getFlow
(
"test"
));
JobUtils
.
publish
(
pluginPackage
);
}
public
static
PluginFlow
getFlow
(
String
name
){
PluginFlow
flow
=
new
PluginFlow
();
flow
.
setName
(
name
);
flow
.
setRePublish
(
false
);
flow
.
setPrincipal
(
"admin"
);
PluginFlowConfig
flowConfig
=
new
PluginFlowConfig
();
flowConfig
.
setAlarmlAction
(
"1"
);
flowConfig
.
setExecType
(
"1"
);
flowConfig
.
setFlowCron
(
"0 0 2 * * ? *"
);
flowConfig
.
setPriority
(
"1"
);
flowConfig
.
setScheduleFollow
(
"1"
);
flowConfig
.
setAlarmEmail
(
"qwe@qq.com"
);
PluginNode
start
=
getNode
(
"start"
,
"echo start"
,
"echo start"
,
null
);
PluginNode
center
=
getNode
(
"center"
,
"echo center"
,
"echo center"
,
"start"
);
PluginNode
end
=
getNode
(
"end"
,
"echo end"
,
"echo end"
,
"center"
);
List
<
PluginBaseNode
>
nodeList
=
new
ArrayList
<>();
nodeList
.
add
(
start
);
nodeList
.
add
(
center
);
nodeList
.
add
(
end
);
flow
.
setConfig
(
flowConfig
);
flow
.
setNodeList
(
nodeList
);
return
flow
;
}
public
static
PluginNode
getNode
(
String
name
,
String
cmd
,
String
source
,
String
dependNames
)
{
PluginNode
node
=
new
PluginNode
();
node
.
setType
(
"node"
);
node
.
setName
(
name
);
node
.
setJobType
(
"SHELL"
);
node
.
setRunCommand
(
cmd
);
node
.
setRunSource
(
source
);
PluginNodeConfig
nodeConfig
=
new
PluginNodeConfig
();
nodeConfig
.
setFailedRetryCount
(
1
);
nodeConfig
.
setFailedRetryInterval
(
300000L
);
nodeConfig
.
setPriority
(
"1"
);
node
.
setConfig
(
nodeConfig
);
if
(
StringUtils
.
isNotEmpty
(
dependNames
))
{
node
.
setDependNodeNameList
(
Arrays
.
asList
(
dependNames
));
}
return
node
;
}
}
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