Browse Source

Merge pull request #576 in DESIGN/design from ~ALEX.SUNG/design:feature/10.0 to feature/10.0

REPORT-11622 信息收集移至云中心

* commit 'ca58fc5a81c2529790c68405daf7740b2761d70b':
  数据量大的方案,发送zip文件到云中心
  content需要编码
research/10.0
Alex.Sung 6 years ago
parent
commit
6d3cfb9289
  1. 37
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

37
designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

@ -58,6 +58,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -227,11 +228,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
private void sendFunctionsInfo(){ private void sendFunctionsInfo(){
long currentTime = new Date().getTime(); long currentTime = new Date().getTime();
ArrayList<Map<String, Object>> content = null; ArrayList<Map<String, Object>> content = null;
try {
content = getFunctionsContentAsByte(currentTime); content = getFunctionsContentAsByte(currentTime);
} catch (JSONException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
boolean success = false; boolean success = false;
String url = CloudCenter.getInstance().acquireUrlByKind(TABLE_FUNCTION_RECORD); String url = CloudCenter.getInstance().acquireUrlByKind(TABLE_FUNCTION_RECORD);
if(content.size() > 0){ if(content.size() > 0){
@ -243,22 +240,31 @@ public class InformationCollector implements XMLReadable, XMLWriter {
deleteFunctionRecords(currentTime); deleteFunctionRecords(currentTime);
} }
} }
// //先将发送压缩文件这段代码注释,之后提任务
//大数据量下发送压缩zip数据不容易丢失
// try {
// ObjectMapper objectMapper = new ObjectMapper();
// String contentStr = objectMapper.writeValueAsString(content);
// InputStream inputStream = new ByteArrayInputStream(contentStr.getBytes("UTF-8"));
// String recordUrl = url+"?token=" + SiteCenterToken.generateToken() + "&content="+ IOUtils.inputStream2Bytes(IOUtils.toZipIn(inputStream));
//
// String res = HttpToolbox.get(recordUrl);
// success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
// } catch (Exception e) {
// FineLoggerFactory.getLogger().error(e.getMessage(), e);
// }
// if (success) {
// deleteFunctionRecords(currentTime);
// }
} }
private boolean sendFunctionRecord(String url, Map<String,Object> record) { private boolean sendFunctionRecord(String url, Map<String,Object> record) {
HashMap<String, String> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
para.put("content", new JSONObject(record).toString());
String res = null;
try {
res = HttpToolbox.get(url, para);
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
boolean success = false; boolean success = false;
try { try {
String recordUrl = url+"?token=" + SiteCenterToken.generateToken() + "&content="+URLEncoder.encode(new JSONObject(record).toString(), EncodeConstants.ENCODING_UTF_8);
String res = HttpToolbox.get(recordUrl);
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
} catch (JSONException e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
return success; return success;
@ -424,14 +430,13 @@ public class InformationCollector implements XMLReadable, XMLWriter {
}); });
} }
public static ArrayList getFunctionsContentAsByte(long currentTime) throws JSONException{ public static ArrayList getFunctionsContentAsByte(long currentTime){
ArrayList<Map<String,Object>> records = new ArrayList<Map<String,Object>>(); ArrayList<Map<String,Object>> records = new ArrayList<Map<String,Object>>();
QueryCondition condition = QueryFactory.create().addRestriction( QueryCondition condition = QueryFactory.create().addRestriction(
RestrictionFactory.lte(COLUMN_TIME, currentTime) RestrictionFactory.lte(COLUMN_TIME, currentTime)
); );
try { try {
DataList<FocusPoint> focusPoints = MetricRegistry.getMetric().find(FocusPoint.class,condition); DataList<FocusPoint> focusPoints = MetricRegistry.getMetric().find(FocusPoint.class,condition);
focusPoints.getList();
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
String bbsUserName = MarketConfig.getInstance().getBbsUsername(); String bbsUserName = MarketConfig.getInstance().getBbsUsername();
String uuid = envManager.getUUID(); String uuid = envManager.getUUID();

Loading…
Cancel
Save