增加配置全量同步配置数据组织逻辑以及下发接口

This commit is contained in:
zhangwei
2018-11-26 14:34:24 +08:00
parent 74889a1836
commit ce8e1469f9
10 changed files with 2621 additions and 0 deletions

View File

@@ -624,6 +624,142 @@ public class ConfigServiceUtil {
}
return result;
}
/**
* 配置全量更新指令下发
* @param params
* @return
* @throws MaatConvertException
*/
public static ToMaatResult configSyncCmd(String params) throws MaatConvertException{
Response response=null;
ToMaatResult bean = null;
try {
String result = null;
String url = DictUtils.getDictLabel("config_sync_url", "sync_cmd");
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
logger.info("sync_cmd url:"+url);
//获取响应结果
Builder header = wt.request(MediaType.APPLICATION_JSON)
.header("Content-Type", MediaType.APPLICATION_JSON);
try {
response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON));
if(response != null) {
result=response.readEntity(String.class);
}
} catch (Exception e) {
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
}
if(response != null && response.getStatus() == 200){
logger.info("get result success");
JsonConfig config=new JsonConfig();
JSONObject resObject = JSONObject.fromObject(result,config);
bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
}else{
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+result);
}
} catch (Exception e) {
throw e;
}finally {
if (response != null) {
response.close();
}
}
return bean;
}
/**
* 配置全量更新获取当前状态
* @param params
* @return
* @throws MaatConvertException
*/
public static ToMaatResult configSyncStatus() throws MaatConvertException{
Response response=null;
ToMaatResult bean = null;
try {
String result = null;
String url = DictUtils.getDictLabel("config_sync_url", "get_sync_status");
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
logger.info("get_sync_status url:"+url);
//获取响应结果
Builder header = wt.request(MediaType.APPLICATION_JSON)
.header("Content-Type", MediaType.APPLICATION_JSON);
try {
response= header.get();
if(response != null) {
result=response.readEntity(String.class);
}
} catch (Exception e) {
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
}
if(response != null && response.getStatus() == 200){
logger.info("get result success");
JsonConfig config=new JsonConfig();
JSONObject resObject = JSONObject.fromObject(result,config);
bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
}else{
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+result);
}
} catch (Exception e) {
throw e;
}finally {
if (response != null) {
response.close();
}
}
return bean;
}
/**
* 配置全量更新
* @param params
* @return
* @throws MaatConvertException
*/
public static ToMaatResult configSync(String params,Integer cfgType,Integer serviceId,String tableName,String completeTag) throws MaatConvertException{
Response response=null;
ToMaatResult bean = null;
try {
String result = null;
String url = DictUtils.getDictLabel("config_sync_url", "sync_send");
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
logger.info("sync_send url:"+url);
//获取响应结果
Builder header = wt.request(MediaType.APPLICATION_JSON)
.header("Content-Type", MediaType.APPLICATION_JSON)
.header("Config-Type", cfgType)
.header("Service-Id", serviceId)
.header("Config-Table", tableName)
.header("Last-Completed-Tag", completeTag);
try {
response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON));
if(response != null) {
result=response.readEntity(String.class);
}
} catch (Exception e) {
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
}
if(response != null && response.getStatus() == 200){
logger.info("get result success");
JsonConfig config=new JsonConfig();
config.setExcludes(new String[]{"configCompileList"});
JSONObject resObject = JSONObject.fromObject(result,config);
bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
}else{
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+result);
}
} catch (Exception e) {
throw e;
}finally {
if (response != null) {
response.close();
}
}
return bean;
}
public static void main(String[] args) {
try {
// getId(1,1);