提交 fbb78ae0 编写于 作者: Z zhourui

修复集群切换

上级 217a578c
package com.x.base.core.project.connection;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.x.base.core.project.bean.NameValuePair;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.http.WrapOutBoolean;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.base.core.project.tools.ListTools;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
......@@ -198,24 +194,20 @@ public class ConnectionAction {
return read(response, connection);
}
public static ActionResponse multiFormPost(String address, List<NameValuePair> heads, String fileName, byte[] bytes, Map<String, String> map) throws Exception {
public static ActionResponse multiFormPost(String address, List<NameValuePair> heads, String fileName, byte[] bytes,
Map<String, String> map) throws Exception {
ActionResponse response = new ActionResponse();
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost uploadFile = new HttpPost(address);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("fileName", fileName, ContentType.TEXT_PLAIN);
if(map!=null){
for(String key : map.keySet()){
if (map != null) {
for (String key : map.keySet()) {
builder.addTextBody(key, map.get(key), ContentType.TEXT_PLAIN);
}
}
builder.addBinaryBody(
"file",
bytes,
ContentType.APPLICATION_OCTET_STREAM,
fileName
);
builder.addBinaryBody("file", bytes, ContentType.APPLICATION_OCTET_STREAM, fileName);
HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);
if (ListTools.isNotEmpty(heads)) {
......@@ -231,14 +223,13 @@ public class ConnectionAction {
}
CloseableHttpResponse httpResponse = httpClient.execute(uploadFile);
HttpEntity responseEntity = httpResponse.getEntity();
String value= EntityUtils.toString(responseEntity, DefaultCharset.name);
String value = EntityUtils.toString(responseEntity, DefaultCharset.name);
try {
response = gson.fromJson(value, ActionResponse.class);
} catch (Exception e) {
response.setType(ActionResponse.Type.connectFatal);
response.setMessage("convert to json error, address:" + address
+ ", method: multiFormPost, because:" + e.getMessage() + ", value:"
+ value + ".");
response.setMessage("convert to json error, address:" + address + ", method: multiFormPost, because:"
+ e.getMessage() + ", value:" + value + ".");
}
} catch (Exception e) {
response.setType(ActionResponse.Type.connectFatal);
......
......@@ -3,14 +3,13 @@ package com.x.base.core.project.http;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.zip.CRC32;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.exception.PromptException;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.tools.DefaultCharset;
import org.apache.commons.lang3.StringUtils;
public class ActionResult<T> implements Serializable {
......@@ -62,6 +61,14 @@ public class ActionResult<T> implements Serializable {
}
}
/**
* 此方法不会抛出execption 与 ActionResponse 带类型的方法不同
*
* @see ActionResponse
*
* @return
*/
public T getData() {
return data;
}
......
......@@ -93,64 +93,7 @@
"pathParameters": [],
"formParameters": [],
"queryParameters": [],
"ins": [
{
"name": "name",
"type": "String",
"isCollection": false,
"description": "名称,不可重名.",
"isBaseType": true
},
{
"name": "title",
"type": "String",
"isCollection": false,
"description": "标题.",
"isBaseType": true
},
{
"name": "visible",
"type": "Boolean",
"isCollection": false,
"description": "是否是可见的应用.",
"isBaseType": true
},
{
"name": "orderNumber",
"type": "Integer",
"isCollection": false,
"description": "排序号,升序排列,为空在最后",
"isBaseType": true
},
{
"name": "path",
"type": "String",
"isCollection": false,
"description": "应用路径.",
"isBaseType": true
},
{
"name": "iconPath",
"type": "String",
"isCollection": false,
"description": "图标位置.",
"isBaseType": true
},
{
"name": "allowList",
"type": "List\u003cString\u003e",
"isCollection": true,
"description": "可访问人员.",
"isBaseType": true
},
{
"name": "denyList",
"type": "List\u003cString\u003e",
"isCollection": true,
"description": "拒绝访问人员.",
"isBaseType": true
}
],
"ins": [],
"outs": [
{
"name": "value",
......@@ -231,64 +174,7 @@
],
"formParameters": [],
"queryParameters": [],
"ins": [
{
"name": "name",
"type": "String",
"isCollection": false,
"description": "名称,不可重名.",
"isBaseType": true
},
{
"name": "title",
"type": "String",
"isCollection": false,
"description": "标题.",
"isBaseType": true
},
{
"name": "visible",
"type": "Boolean",
"isCollection": false,
"description": "是否是可见的应用.",
"isBaseType": true
},
{
"name": "orderNumber",
"type": "Integer",
"isCollection": false,
"description": "排序号,升序排列,为空在最后",
"isBaseType": true
},
{
"name": "path",
"type": "String",
"isCollection": false,
"description": "应用路径.",
"isBaseType": true
},
{
"name": "iconPath",
"type": "String",
"isCollection": false,
"description": "图标位置.",
"isBaseType": true
},
{
"name": "allowList",
"type": "List\u003cString\u003e",
"isCollection": true,
"description": "可访问人员.",
"isBaseType": true
},
{
"name": "denyList",
"type": "List\u003cString\u003e",
"isCollection": true,
"description": "拒绝访问人员.",
"isBaseType": true
}
],
"ins": [],
"outs": [
{
"name": "value",
......@@ -318,80 +204,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "id",
"type": "String",
"isCollection": false,
"description": "数据库主键,自动生成."
},
{
"name": "name",
"type": "String",
"isCollection": false,
"description": "名称,不可重名."
},
{
"name": "title",
"type": "String",
"isCollection": false,
"description": "标题."
},
{
"name": "visible",
"type": "Boolean",
"isCollection": false,
"description": "是否是可见的应用."
},
{
"name": "orderNumber",
"type": "Integer",
"isCollection": false,
"description": "排序号,升序排列,为空在最后"
},
{
"name": "path",
"type": "String",
"isCollection": false,
"description": "应用路径."
},
{
"name": "iconPath",
"type": "String",
"isCollection": false,
"description": "图标位置."
},
{
"name": "allowList",
"type": "List\u003cString\u003e",
"isCollection": true,
"description": "可访问人员."
},
{
"name": "denyList",
"type": "List\u003cString\u003e",
"isCollection": true,
"description": "拒绝访问人员."
},
{
"name": "type",
"type": "String",
"isCollection": false,
"description": "类型:system|custom"
},
{
"name": "createTime",
"type": "Date",
"isCollection": false,
"description": "创建时间,自动生成,索引创建在约束中."
},
{
"name": "updateTime",
"type": "Date",
"isCollection": false,
"description": "修改时间,自动生成,索引创建在约束中."
}
]
"outs": []
},
{
"name": "listAll",
......@@ -407,80 +220,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "id",
"type": "String",
"isCollection": false,
"description": "数据库主键,自动生成."
},
{
"name": "name",
"type": "String",
"isCollection": false,
"description": "名称,不可重名."
},
{
"name": "title",
"type": "String",
"isCollection": false,
"description": "标题."
},
{
"name": "visible",
"type": "Boolean",
"isCollection": false,
"description": "是否是可见的应用."
},
{
"name": "orderNumber",
"type": "Integer",
"isCollection": false,
"description": "排序号,升序排列,为空在最后"
},
{
"name": "path",
"type": "String",
"isCollection": false,
"description": "应用路径."
},
{
"name": "iconPath",
"type": "String",
"isCollection": false,
"description": "图标位置."
},
{
"name": "allowList",
"type": "List\u003cString\u003e",
"isCollection": true,
"description": "可访问人员."
},
{
"name": "denyList",
"type": "List\u003cString\u003e",
"isCollection": true,
"description": "拒绝访问人员."
},
{
"name": "type",
"type": "String",
"isCollection": false,
"description": "类型:system|custom"
},
{
"name": "createTime",
"type": "Date",
"isCollection": false,
"description": "创建时间,自动生成,索引创建在约束中."
},
{
"name": "updateTime",
"type": "Date",
"isCollection": false,
"description": "修改时间,自动生成,索引创建在约束中."
}
]
"outs": []
}
]
},
......
package com.x.server.console;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.logger.Logger;
......@@ -13,6 +9,11 @@ import com.x.server.console.node.UpdateApplicationsEvent;
import com.x.server.console.node.VoteCenterEvent;
import com.x.server.console.server.Servers;
import org.apache.commons.lang3.BooleanUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class RegistApplicationsAndVoteCenterTask implements Job {
private static Logger logger = LoggerFactory.getLogger(RegistApplicationsAndVoteCenterTask.class);
......@@ -20,14 +21,15 @@ public class RegistApplicationsAndVoteCenterTask implements Job {
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
try {
if (Servers.applicationServerIsRunning()) {
// 先选举center
Config.resource_node_eventQueue().put(XGsonBuilder.instance().toJsonTree(new VoteCenterEvent()));
if (BooleanUtils.isTrue(Servers.applicationServerIsRunning())) {
Config.resource_node_eventQueue()
.put(XGsonBuilder.instance().toJsonTree(new RegistApplicationsEvent()));
} else {
Config.resource_node_eventQueue()
.put(XGsonBuilder.instance().toJsonTree(new UpdateApplicationsEvent()));
}
Config.resource_node_eventQueue().put(XGsonBuilder.instance().toJsonTree(new VoteCenterEvent()));
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -39,6 +39,7 @@ public class ActionControl extends ActionBase {
private static final String CMD_UF = "uf";
private static final String CMD_DDL = "ddl";
private static final String CMD_RST = "rst";
private static final String CMD_SC = "sc";
private static final int REPEAT_MAX = 100;
private static final int REPEAT_MIN = 1;
......@@ -75,6 +76,8 @@ public class ActionControl extends ActionBase {
ddl(cmd);
} else if (cmd.hasOption(CMD_RST)) {
rst(cmd);
} else if (cmd.hasOption(CMD_SC)) {
sc(cmd);
} else {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("control command", options);
......@@ -99,6 +102,7 @@ public class ActionControl extends ActionBase {
options.addOption(ufOption());
options.addOption(ddlOption());
options.addOption(rstOption());
options.addOption(scOption());
return options;
}
......@@ -165,8 +169,12 @@ public class ActionControl extends ActionBase {
}
private static Option rstOption() {
return Option.builder("rst").longOpt("restartApp").argName("name").hasArg().desc("重启指定应用: 应用名称:name, 不带.war")
.build();
return Option.builder("rst").longOpt("restartApplication").argName("name").hasArg()
.desc("重启指定应用: 应用名称:name, 不带.war").build();
}
private static Option scOption() {
return Option.builder("sc").longOpt("showCluster").desc("显示集群信息.").build();
}
private void ec(CommandLine cmd) throws Exception {
......@@ -270,6 +278,11 @@ public class ActionControl extends ActionBase {
rst.execute(name);
}
private void sc(CommandLine cmd) throws Exception {
ShowCluster sc = new ShowCluster();
sc.execute();
}
private Integer getArgInteger(CommandLine cmd, String opt, Integer defaultValue) {
Integer repeat = defaultValue;
String r = cmd.getOptionValue(opt);
......
package com.x.server.console.action;
import java.util.Date;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
public class ShowCluster {
private static Logger logger = LoggerFactory.getLogger(ShowCluster.class);
private Date start = new Date();
public boolean execute() throws Exception {
StringBuilder sb = new StringBuilder();
sb.append("show cluster:").append(StringUtils.LF);
sb.append("center pirmary node:" + Config.resource_node_centersPirmaryNode()).append(StringUtils.LF);
sb.append("center pirmary port:" + Config.resource_node_centersPirmaryPort()).append(StringUtils.LF);
sb.append("center pirmary sslEnable:" + Config.resource_node_centersPirmarySslEnable()).append(StringUtils.LF);
sb.append("applications:").append(StringUtils.LF);
sb.append(Config.resource_node_applications());
logger.print(sb.toString());
return true;
}
}
\ No newline at end of file
......@@ -30,10 +30,8 @@ public class VoteCenterEvent implements Event {
ActionResponse response = CipherConnectionAction.get(false,
Config.url_x_program_center_jaxrs(entry, "echo"));
JsonElement jsonElement = response.getData();
if (null != jsonElement) {
JsonElement jsonElement = response.getData(JsonElement.class);
if (null != jsonElement && (!jsonElement.isJsonNull())) {
if ((!StringUtils.equals(Config.resource_node_centersPirmaryNode(), entry.getKey()))
|| (!Objects.equals(Config.resource_node_centersPirmaryPort(), entry.getValue().getPort()))
|| (!Objects.equals(Config.resource_node_centersPirmarySslEnable(),
......@@ -47,7 +45,6 @@ public class VoteCenterEvent implements Event {
}
} catch (Exception e) {
}
}
......
......@@ -376,32 +376,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "name",
"type": "String",
"isCollection": false,
"description": "名称"
},
{
"name": "value",
"type": "String",
"isCollection": false,
"description": "值"
},
{
"name": "count",
"type": "Long",
"isCollection": false,
"description": "数量"
},
{
"name": "duration",
"type": "Long",
"isCollection": false,
"description": "总时长"
}
]
"outs": []
},
{
"name": "listCountCompletedTaskByActivity",
......@@ -859,26 +834,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "name",
"type": "String",
"isCollection": false,
"description": "名称"
},
{
"name": "value",
"type": "String",
"isCollection": false,
"description": "值"
},
{
"name": "count",
"type": "Long",
"isCollection": false,
"description": "数量"
}
]
"outs": []
},
{
"name": "listCountExpiredWorkByApplication",
......@@ -1006,26 +962,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "name",
"type": "String",
"isCollection": false,
"description": "名称"
},
{
"name": "value",
"type": "String",
"isCollection": false,
"description": "值"
},
{
"name": "count",
"type": "Long",
"isCollection": false,
"description": "数量"
}
]
"outs": []
},
{
"name": "listCountStartTaskByActivity",
......@@ -1190,26 +1127,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "name",
"type": "String",
"isCollection": false,
"description": "名称"
},
{
"name": "value",
"type": "String",
"isCollection": false,
"description": "值"
},
{
"name": "count",
"type": "Long",
"isCollection": false,
"description": "数量"
}
]
"outs": []
},
{
"name": "listCountStartWorkByApplication",
......@@ -1462,26 +1380,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "application",
"type": "List\u003cWoApplication\u003e",
"isCollection": true,
"description": "应用分类"
},
{
"name": "process",
"type": "List\u003cWoProcess\u003e",
"isCollection": true,
"description": "分类流程"
},
{
"name": "activity",
"type": "List\u003cWoActivity\u003e",
"isCollection": true,
"description": "活动分类"
}
]
"outs": []
},
{
"name": "categoryTrigger",
......@@ -1497,26 +1396,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "application",
"type": "List\u003cWoApplication\u003e",
"isCollection": true,
"description": "应用分类"
},
{
"name": "process",
"type": "List\u003cWoProcess\u003e",
"isCollection": true,
"description": "分类流程"
},
{
"name": "activity",
"type": "List\u003cWoActivity\u003e",
"isCollection": true,
"description": "活动分类"
}
]
"outs": []
},
{
"name": "organization",
......@@ -1532,20 +1412,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "unit",
"type": "List\u003cWoUnit\u003e",
"isCollection": true,
"description": "按组织统计"
},
{
"name": "person",
"type": "List\u003cWoPerson\u003e",
"isCollection": true,
"description": "按个人统计"
}
]
"outs": []
},
{
"name": "running",
......@@ -1577,80 +1444,7 @@
"formParameters": [],
"queryParameters": [],
"ins": [],
"outs": [
{
"name": "applicationCount",
"type": "Long",
"isCollection": false,
"description": "应用数量"
},
{
"name": "processCount",
"type": "Long",
"isCollection": false,
"description": "流程数量"
},
{
"name": "taskCount",
"type": "Long",
"isCollection": false,
"description": "待办数量"
},
{
"name": "taskCompletedCount",
"type": "Long",
"isCollection": false,
"description": "已办数量"
},
{
"name": "readCount",
"type": "Long",
"isCollection": false,
"description": "待阅数量"
},
{
"name": "readCompletedCount",
"type": "Long",
"isCollection": false,
"description": "已阅数量"
},
{
"name": "workCount",
"type": "Long",
"isCollection": false,
"description": "工作实例数量"
},
{
"name": "workCompletedCount",
"type": "Long",
"isCollection": false,
"description": "已完成工作数量"
},
{
"name": "expiredTaskCount",
"type": "Long",
"isCollection": false,
"description": "超时待办数量"
},
{
"name": "expiredTaskCompletedCount",
"type": "Long",
"isCollection": false,
"description": "超时已办数量"
},
{
"name": "expiredWorkCount",
"type": "Long",
"isCollection": false,
"description": "超时工作数量"
},
{
"name": "expiredWorkCompletedCount",
"type": "Long",
"isCollection": false,
"description": "身份对象"
}
]
"outs": []
}
]
},
......
/********************
resources.getEntityManagerContainer(); //实体管理器
resources.getContext(); //上下文根
resources.getOrganization(); //组织访问
resources.getWebservicesClient();//webSerivces客户端
********************/
var type = 'zhengwuDingdingMessage';
var resp = resources.getContext().applications().getQuery(com.x.base.core.project.x_message_assemble_communicate.class,
'consume/list/' + type + '/count/100');
var messages = resp.getDataAsList(com.x.message.core.entity.Message.class);
for (var i in messages) {
var message = messages[i];
switch (message.getType()) {
case 'task_create':
if (com.x.base.core.project.config.Config.zhengwuDingding().getTaskToMessage()) {
var person = resources.getOrganization().person().getObject(message.getPerson());
var body = JSON.parse(message.getBody());
if (body) {
if (person) {
if (person.getZhengwuDingdingId()) {
var txt = '您有新的待办需要处理:' + body['title'] + '.';
send('184707353', person.getZhengwuDingdingId(), txt);
print('发送政务钉钉待办消息,通知对象: ' + message.getPerson() + '(' + person.getZhengwuDingdingId() + '), 消息:' + txt + '.');
} else {
print('发送政务钉钉待办消息失败,通知对象' + message.getPerson() + ' 无法获取政务钉钉id.');
}
} else {
print('发送政务钉钉待办消息失败,通知对象' + message.getPerson() + ' 不存在.');
}
} else {
print('发送政务钉钉待办消息失败,通知对象' + message.getPerson() + ' 无法获取消息对象.');
}
}
break;
case 'taskCompleted_create':
if (com.x.base.core.project.config.Config.zhengwuDingding().getTaskCompletedToMessage()) {
var person = resources.getOrganization().person().getObject(message.getPerson());
var body = JSON.parse(message.getBody());
if (body) {
if (person) {
if (person.getZhengwuDingdingId()) {
var txt = '您的待办已经处理完成:' + body['title'] + '.';
send('184707353', person.getZhengwuDingdingId(), txt);
print('发送政务钉钉已办消息,通知对象: ' + message.getPerson() + '(' + person.getZhengwuDingdingId() + '), 消息:' + txt + '.');
} else {
print('发送政务钉钉已办消息失败,通知对象' + message.getPerson() + ' 无法获取政务钉钉id.');
}
} else {
print('发送政务钉钉已办消息失败,通知对象' + message.getPerson() + ' 不存在.');
}
} else {
print('发送政务钉钉待办消息失败,通知对象' + message.getPerson() + ' 无法获取消息对象.');
}
}
break;
case 'read_create':
if (com.x.base.core.project.config.Config.zhengwuDingding().getReadToMessage()) {
var person = resources.getOrganization().person().getObject(message.getPerson());
var body = JSON.parse(message.getBody());
if (body) {
if (person) {
if (person.getZhengwuDingdingId()) {
var txt = '您有新的待阅需要处理:' + body['title'] + '.';
send('184707353', person.getZhengwuDingdingId(), txt);
print('发送政务钉钉待阅消息,通知对象: ' + message.getPerson() + '(' + person.getZhengwuDingdingId() + '), 消息:' + txt + '.');
} else {
print('发送政务钉钉待阅消息失败,通知对象' + message.getPerson() + ' 无法获取政务钉钉id.');
}
} else {
print('发送政务钉钉待阅消息失败,通知对象' + message.getPerson() + ' 不存在.');
}
} else {
print('发送政务钉钉待办消息失败,通知对象' + message.getPerson() + ' 无法获取消息对象.');
}
}
break;
case 'readCompleted_create':
if (com.x.base.core.project.config.Config.zhengwuDingding().getReadCompletedToMessage()) {
var person = resources.getOrganization().person().getObject(message.getPerson());
var body = JSON.parse(message.getBody());
if (body) {
if (person) {
if (person.getZhengwuDingdingId()) {
var txt = '您的待阅已经处理完成:' + body['title'] + '.';
send('184707353', person.getZhengwuDingdingId(), txt);
print('发送政务钉钉已阅消息,通知对象: ' + message.getPerson() + '(' + person.getZhengwuDingdingId() + '), 消息:' + txt + '.');
} else {
print('发送政务钉钉已阅消息失败,通知对象' + message.getPerson() + ' 无法获取政务钉钉id.');
}
} else {
print('发送政务钉钉已阅消息失败,通知对象' + message.getPerson() + ' 不存在.');
}
} else {
print('发送政务钉钉待办消息失败,通知对象' + message.getPerson() + ' 无法获取消息对象.');
}
}
break;
default:
system.print('未知的消息类型: ' + message.getType() + ' , title: ' + message.getTitle() + '.');
break;
}
consume(message.getId(), type);
}
function send(agentId, user, message) {
var body = '{"agentId":"184707353","touser":"' + '10001461928' + '","toparty": "","msgtype":"text","context":"' + message + '"}';
var address = com.x.base.core.project.config.Config.zhengwuDingding().getOapiAddress() + "/ent_message/send?access_token=" + com.x.base.core.project.config.Config.zhengwuDingding().appAccessToken();
com.x.base.core.project.connection.HttpConnection.postAsString(address, null, body);
}
function consume(id, type) {
resources.getContext().applications().getQuery(com.x.base.core.project.x_message_assemble_communicate.class,
'consume/' + id + '/type/' + type);
}
......@@ -24,15 +24,15 @@ public class CenterQueue extends AbstractQueue<CenterQueueBody> {
protected void execute(CenterQueueBody body) throws Exception {
switch (body.type()) {
case CenterQueueBody.TYPE_REGISTAPPLICATIONS:
CenterQueueRegistApplicationsBody centerQueueRegistApplicationsBody = (CenterQueueRegistApplicationsBody) body;
registApplications(centerQueueRegistApplicationsBody);
break;
case CenterQueueBody.TYPE_REFRESHAPPLICATION:
this.refresh((CenterQueueRefreshBody) body);
break;
default:
break;
case CenterQueueBody.TYPE_REGISTAPPLICATIONS:
CenterQueueRegistApplicationsBody centerQueueRegistApplicationsBody = (CenterQueueRegistApplicationsBody) body;
registApplications(centerQueueRegistApplicationsBody);
break;
case CenterQueueBody.TYPE_REFRESHAPPLICATION:
this.refresh((CenterQueueRefreshBody) body);
break;
default:
break;
}
}
......@@ -53,109 +53,8 @@ public class CenterQueue extends AbstractQueue<CenterQueueBody> {
Config.resource_node_applications(XGsonBuilder.instance().toJsonTree(applications));
}
}
// if (null != Config.resource_node_applications()) {
// applications = XGsonBuilder.instance().fromJson(Config.resource_node_applications(), Applications.class);
// for (Application body : centerQueueRegistApplicationsBody) {
// Application application = applications.get(body.getClassName(), body.getNode());
// if (null != application) {
// application.setReportDate(now);
// this.updateScheduleLocalRequestAndScheduleRequest(body);
// } else {
// body.setReportDate(now);
// applications.add(body.getClassName(), body);
// this.updateScheduleLocalRequestAndScheduleRequest(body);
// updated = true;
// }
// }
// } else {
// applications = new Applications();
// for (Application body : centerQueueRegistApplicationsBody) {
// body.setReportDate(now);
// applications.add(body.getClassName(), body);
// this.updateScheduleLocalRequestAndScheduleRequest(body);
// }
// updated = true;
// }
}
// private void updateScheduleLocalRequestAndScheduleRequest(Application body) throws Exception {
// if (ListTools.isNotEmpty(body.getScheduleLocalRequestList())) {
// business.entityManagerContainer().beginTransaction(ScheduleLocal.class);
// body.getScheduleLocalRequestList().stream().forEach(o -> {
// this.updateScheduleLocalRequest(business, body, o);
// });
// business.entityManagerContainer().commit();
// }
// if (ListTools.isNotEmpty(body.getScheduleRequestList())) {
// business.entityManagerContainer().beginTransaction(Schedule.class);
// body.getScheduleRequestList().stream().forEach(o -> {
// this.updateScheduleRequest(business, body, o);
// });
// business.entityManagerContainer().commit();
// }
// }
//
// private void updateScheduleLocalRequest(Business business, Application body, ScheduleLocalRequest request) {
// try {
// List<ScheduleLocal> list = business.entityManagerContainer().listEqualAndEqualAndEqual(ScheduleLocal.class,
// ScheduleLocal.node_FIELDNAME, body.getNode(), ScheduleLocal.application_FIELDNAME,
// body.getClassName(), ScheduleLocal.className_FIELDNAME, request.getClassName());
// if (!list.isEmpty()) {
// ScheduleLocal o = list.get(0);
// o.setClassName(request.getClassName());
// o.setApplication(body.getClassName());
// o.setNode(body.getNode());
// o.setCron(request.getCron());
// o.setDelay(request.getDelay());
// o.setInterval(request.getInterval());
// o.setReportTime(new Date());
// business.entityManagerContainer().check(o, CheckPersistType.all);
// } else {
// ScheduleLocal o = new ScheduleLocal();
// o.setClassName(request.getClassName());
// o.setApplication(body.getClassName());
// o.setNode(body.getNode());
// o.setCron(request.getCron());
// o.setDelay(request.getDelay());
// o.setInterval(request.getInterval());
// o.setReportTime(new Date());
// business.entityManagerContainer().persist(o);
// }
// } catch (Exception e) {
// logger.error(e);
// }
// }
//
// private void updateScheduleRequest(Business business, Application body, ScheduleRequest request) {
// try {
// List<Schedule> list = business.entityManagerContainer().listEqualAndEqualAndEqual(Schedule.class,
// Schedule.node_FIELDNAME, body.getNode(), Schedule.application_FIELDNAME, body.getClassName(),
// Schedule.className_FIELDNAME, request.getClassName());
// if (!list.isEmpty()) {
// Schedule o = list.get(0);
// o.setClassName(request.getClassName());
// o.setApplication(body.getClassName());
// o.setNode(body.getNode());
// o.setCron(request.getCron());
// o.setWeight(body.getScheduleWeight());
// o.setReportTime(new Date());
// business.entityManagerContainer().check(o, CheckPersistType.all);
// } else {
// Schedule o = new Schedule();
// o.setClassName(request.getClassName());
// o.setApplication(body.getClassName());
// o.setNode(body.getNode());
// o.setCron(request.getCron());
// o.setWeight(body.getScheduleWeight());
// o.setReportTime(new Date());
// business.entityManagerContainer().persist(o);
// }
// } catch (Exception e) {
// logger.error(e);
// }
// }
private void refresh(CenterQueueRefreshBody body) throws Exception {
Applications applications = ThisApplication.context().applications();
Date now = new Date();
......
......@@ -55,17 +55,6 @@ public class Context extends AbstractContext {
private static Logger logger = LoggerFactory.getLogger(Context.class);
public Applications applications() throws Exception {
// if (applications.isEmpty()) {
// synchronized (Context.class) {
// if (applications.isEmpty()) {
// if (null != Config.resource_node_applications()) {
// this.applications = XGsonBuilder.instance().fromJson(Config.resource_node_applications(),
// Applications.class);
// }
//
// }
// }
// }
return applications;
}
......@@ -171,8 +160,6 @@ public class Context extends AbstractContext {
context.clazz = Class.forName(servletContextEvent.getServletContext().getInitParameter(INITPARAMETER_PORJECT));
context.initDatas();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
// context.cleanupSchedule(emc);
// context.cleanupScheduleLocal(emc);
context.checkDefaultRole(emc);
}
servletContext.setAttribute(context.getClass().getName(), context);
......
//package com.x.program.center;
//
//import java.util.Date;
//import java.util.List;
//
//import javax.persistence.EntityManager;
//import javax.persistence.criteria.CriteriaBuilder;
//import javax.persistence.criteria.CriteriaQuery;
//import javax.persistence.criteria.Predicate;
//import javax.persistence.criteria.Root;
//
//import com.x.base.core.container.EntityManagerContainer;
//import com.x.base.core.container.factory.EntityManagerContainerFactory;
//import com.x.base.core.project.Application;
//import com.x.base.core.project.config.ApplicationServer;
//import com.x.base.core.project.config.Config;
//import com.x.base.core.project.logger.Logger;
//import com.x.base.core.project.logger.LoggerFactory;
//import com.x.base.core.project.queue.AbstractQueue;
//import com.x.base.core.project.schedule.ReportToCenter.Report;
//import com.x.base.core.project.schedule.ScheduleLocalRequest;
//import com.x.base.core.project.schedule.ScheduleRequest;
//import com.x.base.core.project.tools.ListTools;
//import com.x.base.core.project.tools.StringTools;
//import com.x.program.center.core.entity.Schedule;
//import com.x.program.center.core.entity.ScheduleLocal;
//import com.x.program.center.core.entity.ScheduleLocal_;
//import com.x.program.center.core.entity.Schedule_;
//
//public class ReportQueue extends AbstractQueue<Report> {
//
// private static Logger logger = LoggerFactory.getLogger(ReportQueue.class);
//
// @Override
// protected void execute(Report report) throws Exception {
// try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
// Business business = new Business(emc);
// Application application = ThisApplication.context().applications().get(report.getClassName(),
// report.getToken());
// if (null != application) {
// application.setReportDate(new Date());
// } else {
// ApplicationServer applicationServer = Config.nodes().applicationServers().get(report.getNode());
// application = new Application();
// application.setName(report.getName());
// application.setNode(report.getNode());
// application.setPort(applicationServer.getPort());
// application.setContextPath(report.getContextPath());
// application.setToken(report.getToken());
// application.setWeight((null == report.getWeight()) ? 100 : report.getWeight());
// application.setSslEnable(report.getSslEnable());
// application.setReportDate(new Date());
// application.setProxyPort(applicationServer.getProxyPort());
// application.setProxyHost(applicationServer.getProxyHost());
// ThisApplication.context().applications().add(report.getClassName(), application);
// ThisApplication.context().applications().setToken(StringTools.uniqueToken());
// }
// if (ListTools.isNotEmpty(report.getScheduleLocalRequestList())) {
// emc.beginTransaction(ScheduleLocal.class);
// report.getScheduleLocalRequestList().stream().forEach(o -> {
// this.update(business, o);
// });
// emc.commit();
// }
// if (ListTools.isNotEmpty(report.getScheduleRequestList())) {
// emc.beginTransaction(Schedule.class);
// report.getScheduleRequestList().stream().forEach(o -> {
// this.update(business, o);
// });
// emc.commit();
// }
// } catch (Exception e) {
// logger.error(e);
// }
// }
//
// private void update(Business business, ScheduleLocalRequest request) {
// try {
// EntityManager em = business.entityManagerContainer().get(ScheduleLocal.class);
// CriteriaBuilder cb = em.getCriteriaBuilder();
// CriteriaQuery<ScheduleLocal> cq = cb.createQuery(ScheduleLocal.class);
// Root<ScheduleLocal> root = cq.from(ScheduleLocal.class);
// Predicate p = cb.equal(root.get(ScheduleLocal_.node), request.getNode());
// p = cb.and(p, cb.equal(root.get(ScheduleLocal_.application), request.getApplication()));
// p = cb.and(p, cb.equal(root.get(ScheduleLocal_.className), request.getClassName()));
// cq.select(root).where(p).distinct(true);
// List<ScheduleLocal> list = em.createQuery(cq).setMaxResults(1).getResultList();
// if (!list.isEmpty()) {
// ScheduleLocal o = list.get(0);
// o.setClassName(request.getClassName());
// o.setApplication(request.getApplication());
// o.setNode(request.getNode());
// o.setCron(request.getCron());
// o.setDelay(request.getDelay());
// o.setInterval(request.getInterval());
// o.setReportTime(new Date());
// } else {
// ScheduleLocal o = new ScheduleLocal();
// o.setClassName(request.getClassName());
// o.setApplication(request.getApplication());
// o.setNode(request.getNode());
// o.setCron(request.getCron());
// o.setDelay(request.getDelay());
// o.setInterval(request.getInterval());
// o.setReportTime(new Date());
// business.entityManagerContainer().persist(o);
// }
// } catch (Exception e) {
// logger.error(e);
// }
// }
//
// private void update(Business business, ScheduleRequest request) {
// try {
// EntityManager em = business.entityManagerContainer().get(Schedule.class);
// CriteriaBuilder cb = em.getCriteriaBuilder();
// CriteriaQuery<Schedule> cq = cb.createQuery(Schedule.class);
// Root<Schedule> root = cq.from(Schedule.class);
// Predicate p = cb.equal(root.get(Schedule_.node), request.getNode());
// p = cb.and(p, cb.equal(root.get(Schedule_.application), request.getApplication()));
// p = cb.and(p, cb.equal(root.get(Schedule_.className), request.getClassName()));
// cq.select(root).where(p).distinct(true);
// List<Schedule> list = em.createQuery(cq).setMaxResults(1).getResultList();
// if (!list.isEmpty()) {
// Schedule o = list.get(0);
// o.setClassName(request.getClassName());
// o.setApplication(request.getApplication());
// o.setNode(request.getNode());
// o.setCron(request.getCron());
// o.setReportTime(new Date());
// } else {
// Schedule o = new Schedule();
// o.setClassName(request.getClassName());
// o.setApplication(request.getApplication());
// o.setNode(request.getNode());
// o.setCron(request.getCron());
// o.setReportTime(new Date());
// business.entityManagerContainer().persist(o);
// }
// } catch (Exception e) {
// logger.error(e);
// }
// }
//
//}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册