Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_42566577
o2oa
提交
84c60683
o2oa
项目概览
weixin_42566577
/
o2oa
与 Fork 源项目一致
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
84c60683
编写于
5月 21, 2020
作者:
hlwwx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
'add'
上级
e0fa54ba
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
508 addition
and
0 deletion
+508
-0
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/CommandJaxrsFilter.java
...n/java/com/x/program/center/jaxrs/CommandJaxrsFilter.java
+13
-0
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/ActionCommand.java
...ava/com/x/program/center/jaxrs/command/ActionCommand.java
+127
-0
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/ActionGet.java
...in/java/com/x/program/center/jaxrs/command/ActionGet.java
+72
-0
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/ActionUploadFile.java
.../com/x/program/center/jaxrs/command/ActionUploadFile.java
+155
-0
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/BaseAction.java
...n/java/com/x/program/center/jaxrs/command/BaseAction.java
+44
-0
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/CommandAction.java
...ava/com/x/program/center/jaxrs/command/CommandAction.java
+97
-0
未找到文件。
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/CommandJaxrsFilter.java
0 → 100644
浏览文件 @
84c60683
package
com.x.program.center.jaxrs
;
import
javax.servlet.annotation.WebFilter
;
import
com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter
;
@WebFilter
(
urlPatterns
=
"/jaxrs/command/*"
,
asyncSupported
=
true
)
public
class
CommandJaxrsFilter
extends
CipherManagerJaxrsFilter
{
}
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/ActionCommand.java
0 → 100644
浏览文件 @
84c60683
package
com.x.program.center.jaxrs.command
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.net.Socket
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
com.google.gson.JsonElement
;
import
com.x.base.core.project.annotation.FieldDescribe
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.gson.GsonPropertyObject
;
import
com.x.base.core.project.gson.XGsonBuilder
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.tools.Crypto
;
/*执行服务器命令*/
public
class
ActionCommand
extends
BaseAction
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ActionCommand
.
class
);
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
JsonElement
jsonElement
)
throws
Exception
{
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
Wi
wi
=
this
.
convertToWrapIn
(
jsonElement
,
Wi
.
class
);
String
ctl
=
wi
.
getCtl
();
String
nodeName
=
wi
.
getNodeName
()
;
int
nodePort
=
Integer
.
parseInt
(
wi
.
getNodePort
());
Wo
wo
=
executeCommand
(
ctl
,
nodeName
,
nodePort
);
result
.
setData
(
wo
);
return
result
;
}
synchronized
private
Wo
executeCommand
(
String
ctl
,
String
nodeName
,
int
nodePort
)
throws
Exception
{
Wo
wo
=
new
Wo
();
wo
.
setNode
(
nodeName
);
wo
.
setStatus
(
"success"
);
try
(
Socket
socket
=
new
Socket
(
nodeName
,
nodePort
))
{
socket
.
setKeepAlive
(
true
);
socket
.
setSoTimeout
(
5000
);
try
(
DataOutputStream
dos
=
new
DataOutputStream
(
socket
.
getOutputStream
());
DataInputStream
dis
=
new
DataInputStream
(
socket
.
getInputStream
())){
Map
<
String
,
Object
>
commandObject
=
new
HashMap
<>();
commandObject
.
put
(
"command"
,
"command:"
+
ctl
);
commandObject
.
put
(
"credential"
,
Crypto
.
rsaEncrypt
(
"o2@"
,
Config
.
publicKey
()));
dos
.
writeUTF
(
XGsonBuilder
.
toJson
(
commandObject
));
dos
.
flush
();
}
}
catch
(
Exception
ex
)
{
wo
.
setStatus
(
"fail"
);
logger
.
warn
(
"socket dispatch executeCommand to {}:{} error={}"
,
nodeName
,
nodePort
,
ex
.
getMessage
());
}
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
wo
.
setTime
(
df
.
format
(
new
Date
()));
return
wo
;
}
public
static
class
Wi
extends
GsonPropertyObject
{
@FieldDescribe
(
"命令名称"
)
private
String
ctl
;
@FieldDescribe
(
"服务器地址"
)
private
String
nodeName
;
@FieldDescribe
(
"服务端口"
)
private
String
nodePort
;
public
String
getCtl
()
{
return
ctl
;
}
public
void
setCtl
(
String
ctl
)
{
this
.
ctl
=
ctl
;
}
public
String
getNodeName
()
{
return
nodeName
;
}
public
void
setNodeName
(
String
nodeName
)
{
this
.
nodeName
=
nodeName
;
}
public
String
getNodePort
()
{
return
nodePort
;
}
public
void
setNodePort
(
String
nodePort
)
{
this
.
nodePort
=
nodePort
;
}
}
public
static
class
Wo
extends
GsonPropertyObject
{
@FieldDescribe
(
"执行时间"
)
private
String
time
;
@FieldDescribe
(
"执行结束"
)
private
String
status
;
@FieldDescribe
(
"执行服务器"
)
private
String
node
;
public
String
getTime
()
{
return
time
;
}
public
void
setTime
(
String
time
)
{
this
.
time
=
time
;
}
public
String
getNode
()
{
return
node
;
}
public
void
setNode
(
String
node
)
{
this
.
node
=
node
;
}
public
String
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
status
)
{
this
.
status
=
status
;
}
}
}
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/ActionGet.java
0 → 100644
浏览文件 @
84c60683
package
com.x.program.center.jaxrs.command
;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.config.Nodes
;
import
com.x.base.core.project.exception.ExceptionEntityNotExist
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.config.Node
;
/*获取服器信息列表*/
class
ActionGet
extends
BaseAction
{
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
String
id
)
throws
Exception
{
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
Nodes
nodes
=
Config
.
nodes
();
if
(
null
==
nodes
)
{
throw
new
ExceptionEntityNotExist
(
id
,
"Nodes"
);
}
List
<
NodeInfo
>
nodeInfoList
=
new
ArrayList
<>();
for
(
String
key:
nodes
.
keySet
()){
NodeInfo
nodeInfo
=
new
NodeInfo
();
nodeInfo
.
setNodeAddress
(
key
);
nodeInfo
.
setNode
(
nodes
.
get
(
key
));
nodeInfoList
.
add
(
nodeInfo
);
}
Wo
wo
=
new
Wo
();
wo
.
setNodeList
(
nodeInfoList
);
result
.
setData
(
wo
);
return
result
;
}
public
class
NodeInfo
{
private
String
nodeAddress
;
private
Node
node
;
public
String
getNodeAddress
()
{
return
nodeAddress
;
}
public
void
setNodeAddress
(
String
nodeAddress
)
{
this
.
nodeAddress
=
nodeAddress
;
}
public
Node
getNode
()
{
return
node
;
}
public
void
setNode
(
Node
node
)
{
this
.
node
=
node
;
}
}
public
static
class
Wo
{
private
List
<
NodeInfo
>
nodeList
;
public
List
<
NodeInfo
>
getNodeList
()
{
return
nodeList
;
}
public
void
setNodeList
(
List
<
NodeInfo
>
nodeList
)
{
this
.
nodeList
=
nodeList
;
}
}
}
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/ActionUploadFile.java
0 → 100644
浏览文件 @
84c60683
package
com.x.program.center.jaxrs.command
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.InputStream
;
import
java.net.Socket
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.glassfish.jersey.media.multipart.FormDataContentDisposition
;
import
com.x.base.core.project.annotation.FieldDescribe
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.config.Nodes
;
import
com.x.base.core.project.gson.GsonPropertyObject
;
import
com.x.base.core.project.gson.XGsonBuilder
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.tools.Crypto
;
public
class
ActionUploadFile
extends
BaseAction
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
CommandAction
.
class
);
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
String
ctl
,
String
nodeName
,
String
nodePort
,
InputStream
fileInputStream
,
FormDataContentDisposition
disposition
)
throws
Exception
{
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
Wo
wo
=
null
;
if
(
nodeName
.
equalsIgnoreCase
(
"*"
))
{
Nodes
nodes
=
Config
.
nodes
();
for
(
String
node
:
nodes
.
keySet
()){
if
(
nodes
.
get
(
node
).
getApplication
().
getEnable
()
||
nodes
.
get
(
node
).
getCenter
().
getEnable
()){
wo
=
executeCommand
(
ctl
,
node
,
nodes
.
get
(
node
).
nodeAgentPort
(),
fileInputStream
,
disposition
);
}
}
}
else
{
wo
=
executeCommand
(
ctl
,
nodeName
,
Integer
.
parseInt
(
nodePort
),
fileInputStream
,
disposition
);
}
result
.
setData
(
wo
);
return
result
;
}
synchronized
private
Wo
executeCommand
(
String
ctl
,
String
nodeName
,
int
nodePort
,
InputStream
fileInputStream
,
FormDataContentDisposition
disposition
)
throws
Exception
{
Wo
wo
=
new
Wo
();
wo
.
setNode
(
nodeName
);
wo
.
setStatus
(
"success"
);
try
(
Socket
socket
=
new
Socket
(
nodeName
,
nodePort
))
{
socket
.
setKeepAlive
(
true
);
socket
.
setSoTimeout
(
5000
);
DataOutputStream
dos
=
null
;
DataInputStream
dis
=
null
;
try
{
dos
=
new
DataOutputStream
(
socket
.
getOutputStream
());
dis
=
new
DataInputStream
(
socket
.
getInputStream
());
Map
<
String
,
Object
>
commandObject
=
new
HashMap
<>();
commandObject
.
put
(
"command"
,
"redeploy:"
+
ctl
);
commandObject
.
put
(
"credential"
,
Crypto
.
rsaEncrypt
(
"o2@"
,
Config
.
publicKey
()));
dos
.
writeUTF
(
XGsonBuilder
.
toJson
(
commandObject
));
dos
.
flush
();
dos
.
writeUTF
(
disposition
.
getFileName
());
dos
.
flush
();
logger
.
info
(
"发送文件starting......."
);
byte
[]
bytes
=
new
byte
[
1024
];
int
length
=
0
;
while
((
length
=
fileInputStream
.
read
(
bytes
,
0
,
bytes
.
length
))
!=
-
1
)
{
dos
.
write
(
bytes
,
0
,
length
);
dos
.
flush
();
}
logger
.
info
(
"发送文件end......."
);
}
finally
{
dos
.
close
();
dis
.
close
();
fileInputStream
.
close
();
}
}
catch
(
Exception
ex
)
{
wo
.
setStatus
(
"fail"
);
//logger.warn("socket dispatch executeCommand to {}:{} error={}", nodeName, nodePort, ex.getMessage());
}
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
wo
.
setTime
(
df
.
format
(
new
Date
()));
return
wo
;
}
public
static
class
Wi
extends
GsonPropertyObject
{
private
String
ctl
;
private
String
nodeName
;
private
String
nodePort
;
public
String
getCtl
()
{
return
ctl
;
}
public
void
setCtl
(
String
ctl
)
{
this
.
ctl
=
ctl
;
}
public
String
getNodeName
()
{
return
nodeName
;
}
public
void
setNodeName
(
String
nodeName
)
{
this
.
nodeName
=
nodeName
;
}
public
String
getNodePort
()
{
return
nodePort
;
}
public
void
setNodePort
(
String
nodePort
)
{
this
.
nodePort
=
nodePort
;
}
}
public
static
class
Wo
extends
GsonPropertyObject
{
@FieldDescribe
(
"执行时间"
)
private
String
time
;
@FieldDescribe
(
"执行结束"
)
private
String
status
;
@FieldDescribe
(
"执行服务器"
)
private
String
node
;
public
String
getTime
()
{
return
time
;
}
public
void
setTime
(
String
time
)
{
this
.
time
=
time
;
}
public
String
getNode
()
{
return
node
;
}
public
void
setNode
(
String
node
)
{
this
.
node
=
node
;
}
public
String
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
status
)
{
this
.
status
=
status
;
}
}
}
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/BaseAction.java
0 → 100644
浏览文件 @
84c60683
package
com.x.program.center.jaxrs.command
;
import
com.x.base.core.project.cache.ApplicationCache
;
import
com.x.base.core.project.gson.GsonPropertyObject
;
import
com.x.base.core.project.jaxrs.StandardJaxrsAction
;
import
net.sf.ehcache.Ehcache
;
abstract
class
BaseAction
extends
StandardJaxrsAction
{
public
static
Ehcache
cacheLog
=
ApplicationCache
.
instance
().
getCache
(
CacheLogObject
.
class
);
public
static
class
CacheLogObject
extends
GsonPropertyObject
{
private
String
userToken
;
private
String
node
;
private
long
lastPoint
;
public
long
getLastPoint
()
{
return
lastPoint
;
}
public
void
setLastPoint
(
long
lastPoint
)
{
this
.
lastPoint
=
lastPoint
;
}
public
String
getNode
()
{
return
node
;
}
public
void
setNode
(
String
node
)
{
this
.
node
=
node
;
}
public
String
getUserToken
()
{
return
userToken
;
}
public
void
setUserToken
(
String
userToken
)
{
this
.
userToken
=
userToken
;
}
}
}
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/command/CommandAction.java
0 → 100644
浏览文件 @
84c60683
package
com.x.program.center.jaxrs.command
;
import
java.io.InputStream
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.container.AsyncResponse
;
import
javax.ws.rs.container.Suspended
;
import
javax.ws.rs.core.Context
;
import
javax.ws.rs.core.MediaType
;
import
org.glassfish.jersey.media.multipart.FormDataContentDisposition
;
import
org.glassfish.jersey.media.multipart.FormDataParam
;
import
com.google.gson.JsonElement
;
import
com.x.base.core.project.annotation.FieldDescribe
;
import
com.x.base.core.project.annotation.JaxrsDescribe
;
import
com.x.base.core.project.annotation.JaxrsMethodDescribe
;
import
com.x.base.core.project.annotation.JaxrsParameterDescribe
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.http.HttpMediaType
;
import
com.x.base.core.project.jaxrs.ResponseFactory
;
import
com.x.base.core.project.jaxrs.StandardJaxrsAction
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
@JaxrsDescribe
(
"命令"
)
@Path
(
"command"
)
public
class
CommandAction
<
Wo
>
extends
StandardJaxrsAction
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
CommandAction
.
class
);
@JaxrsMethodDescribe
(
value
=
"执行服务器命令"
,
action
=
ActionCommand
.
class
)
@POST
@Path
(
"execute"
)
@Produces
(
HttpMediaType
.
APPLICATION_JSON_UTF_8
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
void
executeCommand
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
JsonElement
jsonElement
)
{
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
ActionResult
<
ActionCommand
.
Wo
>
result
=
new
ActionResult
<>();
try
{
result
=
new
ActionCommand
().
execute
(
effectivePerson
,
jsonElement
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
result
.
error
(
e
);
}
asyncResponse
.
resume
(
ResponseFactory
.
getEntityTagActionResultResponse
(
request
,
result
));
}
@JaxrsMethodDescribe
(
value
=
"获取所有服务器信息"
,
action
=
ActionGet
.
class
)
@GET
@Path
(
"nodeInfoList"
)
@Produces
(
HttpMediaType
.
APPLICATION_JSON_UTF_8
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
void
getNodeInfoList
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
)
{
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
ActionResult
<
ActionGet
.
Wo
>
result
=
new
ActionResult
<>();
try
{
result
=
(
ActionResult
<
ActionGet
.
Wo
>)
new
ActionGet
().
execute
(
effectivePerson
,
""
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
result
.
error
(
e
);
}
asyncResponse
.
resume
(
ResponseFactory
.
getEntityTagActionResultResponse
(
request
,
result
));
}
@JaxrsMethodDescribe
(
value
=
"上传customJar,customWar,storeJar,storeWar包并自动部署"
,
action
=
ActionUploadFile
.
class
)
@POST
@Path
(
"upload"
)
@Consumes
(
MediaType
.
MULTIPART_FORM_DATA
)
@Produces
(
HttpMediaType
.
APPLICATION_JSON_UTF_8
)
public
void
upload
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
@JaxrsParameterDescribe
(
"命令名称(customJar|customWar|storeJar|storeWar)"
)
@FormDataParam
(
"ctl"
)
String
ctl
,
@JaxrsParameterDescribe
(
"服务器地址(*代表多台应用服务器)"
)
@FormDataParam
(
"nodeName"
)
String
nodeName
,
@JaxrsParameterDescribe
(
"服务端口"
)
@FormDataParam
(
"nodePort"
)
String
nodePort
,
@JaxrsParameterDescribe
(
"附件名称"
)
@FormDataParam
(
FILENAME_FIELD
)
String
fileName
,
@JaxrsParameterDescribe
(
"文件内容"
)
@FormDataParam
(
FILE_FIELD
)
InputStream
fileInputStream
,
@JaxrsParameterDescribe
(
"上传文件"
)
@FormDataParam
(
FILE_FIELD
)
final
FormDataContentDisposition
disposition
)
{
ActionResult
<
ActionUploadFile
.
Wo
>
result
=
new
ActionResult
<>();
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
try
{
result
=
new
ActionUploadFile
().
execute
(
effectivePerson
,
ctl
,
nodeName
,
nodePort
,
fileInputStream
,
disposition
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
effectivePerson
,
request
,
null
);
result
.
error
(
e
);
}
asyncResponse
.
resume
(
ResponseFactory
.
getEntityTagActionResultResponse
(
request
,
result
));
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录