|
|
|
@ -20,15 +20,25 @@ import com.fr.general.DesUtils;
|
|
|
|
|
import com.fr.general.GeneralUtils; |
|
|
|
|
import com.fr.general.IOUtils; |
|
|
|
|
import com.fr.general.http.HttpClient; |
|
|
|
|
import com.fr.general.http.HttpToolbox; |
|
|
|
|
import com.fr.intelli.record.FocusPoint; |
|
|
|
|
import com.fr.intelli.record.MetricException; |
|
|
|
|
import com.fr.intelli.record.MetricRegistry; |
|
|
|
|
import com.fr.json.JSONArray; |
|
|
|
|
import com.fr.json.JSONException; |
|
|
|
|
import com.fr.json.JSONObject; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import com.fr.log.message.ParameterMessage; |
|
|
|
|
import com.fr.record.DBRecordXManager; |
|
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
|
import com.fr.stable.ProductConstants; |
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.stable.query.QueryFactory; |
|
|
|
|
import com.fr.stable.query.condition.QueryCondition; |
|
|
|
|
import com.fr.stable.query.data.DataList; |
|
|
|
|
import com.fr.stable.query.restriction.RestrictionFactory; |
|
|
|
|
import com.fr.stable.xml.XMLPrintWriter; |
|
|
|
|
import com.fr.stable.xml.XMLReadable; |
|
|
|
|
import com.fr.stable.xml.XMLTools; |
|
|
|
@ -84,6 +94,15 @@ public class InformationCollector implements XMLReadable, XMLWriter {
|
|
|
|
|
|
|
|
|
|
public static final String TABLE_NAME = "fr_functionrecord"; |
|
|
|
|
public static final String FUNC_COLUMNNAME = "func"; |
|
|
|
|
public static final String COLUMN_TIME = "time"; |
|
|
|
|
public static final String TABLE_FUNCTION_RECORD = "function.record"; |
|
|
|
|
private static final String ATTR_ID = "id"; |
|
|
|
|
private static final String ATTR_TEXT = "text"; |
|
|
|
|
private static final String ATTR_SOURCE = "source"; |
|
|
|
|
private static final String ATTR_TIME = "time"; |
|
|
|
|
private static final String ATTR_TITLE = "title"; |
|
|
|
|
private static final String ATTR_USER_NAME = "username"; |
|
|
|
|
private static final String ATTR_UUID = "uuid"; |
|
|
|
|
|
|
|
|
|
private static InformationCollector collector; |
|
|
|
|
|
|
|
|
@ -207,133 +226,44 @@ public class InformationCollector implements XMLReadable, XMLWriter {
|
|
|
|
|
|
|
|
|
|
private void sendFunctionsInfo(){ |
|
|
|
|
long currentTime = new Date().getTime(); |
|
|
|
|
long lastTime = getLastTimeMillis(); |
|
|
|
|
if (currentTime - lastTime <= DELTA) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// byte[] content = ArrayUtils.EMPTY_BYTE_ARRAY;
|
|
|
|
|
// Connection conn = null;
|
|
|
|
|
// Table table = new Table(TABLE_NAME);
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
// conn = DBRecordXManager.getDB().createConnection();
|
|
|
|
|
// ResultSet rs = selectAllFromLogDB(conn, table);
|
|
|
|
|
//
|
|
|
|
|
// if(rs == null){
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// content = getFunctionsContentAsByte(rs);
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// FRContext.getLogger().error(e.getMessage(), e);
|
|
|
|
|
// } finally {
|
|
|
|
|
// DBUtils.closeConnection(conn);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// HttpClient httpClient = new HttpClient(CloudCenter.getInstance().acquireUrlByKind("functions.info"));
|
|
|
|
|
// httpClient.setContent(content);
|
|
|
|
|
// httpClient.setTimeout(5000);
|
|
|
|
|
//
|
|
|
|
|
// if (!httpClient.isServerAlive()) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// String res = httpClient.getResponseText();
|
|
|
|
|
// boolean success = false;
|
|
|
|
|
// try {
|
|
|
|
|
// success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
|
|
|
|
|
// } catch (JSONException e) {
|
|
|
|
|
// FRContext.getLogger().error(e.getMessage(), e);
|
|
|
|
|
// }
|
|
|
|
|
// //服务器返回true, 说明已经获取成功, 清空当前记录的信息
|
|
|
|
|
// if (success) {
|
|
|
|
|
// deleteLogDB(conn, table);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void deleteLogDB(Connection conn, Table table) { |
|
|
|
|
try { |
|
|
|
|
conn = DBRecordXManager.getDB().createConnection(); |
|
|
|
|
Delete delete = new Delete(table); |
|
|
|
|
delete.execute(conn); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FRContext.getLogger().error(e.getMessage(), e); |
|
|
|
|
} finally { |
|
|
|
|
DBUtils.closeConnection(conn); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private byte[] getFunctionsContentAsByte(ResultSet rs) throws JSONException{ |
|
|
|
|
com.fr.json.JSONObject content = new com.fr.json.JSONObject(); |
|
|
|
|
HashMap resultMap = new HashMap(); |
|
|
|
|
|
|
|
|
|
ArrayList<Map<String, Object>> content = null; |
|
|
|
|
try { |
|
|
|
|
while (rs.next()) { |
|
|
|
|
com.fr.json.JSONObject js = new com.fr.json.JSONObject(rs.getString(FUNC_COLUMNNAME)); |
|
|
|
|
Map tempMap = js.toMap(); |
|
|
|
|
for (Object key : tempMap.keySet()) { |
|
|
|
|
if(resultMap.containsKey(key)){ |
|
|
|
|
int cacheCount = Integer.parseInt(resultMap.get(key).toString()); |
|
|
|
|
int currentCount = Integer.parseInt(tempMap.get(key).toString()); |
|
|
|
|
resultMap.put(key, cacheCount + currentCount); |
|
|
|
|
} else { |
|
|
|
|
resultMap.put(key, tempMap.get(key)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
content = getFunctionsContentAsByte(currentTime); |
|
|
|
|
} catch (JSONException e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
rs.close(); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
//这边不记,可能还没建表
|
|
|
|
|
boolean success = false; |
|
|
|
|
String url = CloudCenter.getInstance().acquireUrlByKind(TABLE_FUNCTION_RECORD); |
|
|
|
|
if(content.size() > 0){ |
|
|
|
|
for(int i=0; i<content.size(); i++){ |
|
|
|
|
success = sendFunctionRecord(url, content.get(i)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSONArray functionArray = new JSONArray(); |
|
|
|
|
for(Object key : resultMap.keySet()){ |
|
|
|
|
com.fr.json.JSONObject jsonObject = new com.fr.json.JSONObject(); |
|
|
|
|
jsonObject.put("point", key); |
|
|
|
|
jsonObject.put("times", resultMap.get(key)); |
|
|
|
|
functionArray.put(jsonObject); |
|
|
|
|
//服务器返回true, 说明已经获取成功, 清空当前记录的信息
|
|
|
|
|
if (success) { |
|
|
|
|
deleteFunctionRecords(currentTime); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); |
|
|
|
|
content.put("username", MarketConfig.getInstance().getBbsUsername()); |
|
|
|
|
content.put("uuid", envManager.getUUID()); |
|
|
|
|
content.put("functions", functionArray); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
return content.toString().getBytes(EncodeConstants.ENCODING_UTF_8); |
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
FRContext.getLogger().error(e.getMessage(), e); |
|
|
|
|
return ArrayUtils.EMPTY_BYTE_ARRAY; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ResultSet selectAllFromLogDB(Connection conn, Table table) { |
|
|
|
|
|
|
|
|
|
Select select = new Select(table, DialectFactory.generateDialect(conn)); |
|
|
|
|
PreparedStatement ps; |
|
|
|
|
ResultSet rs; |
|
|
|
|
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 { |
|
|
|
|
ps = select.createPreparedStatement(conn); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
return null; |
|
|
|
|
res = HttpToolbox.get(url, para); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
rs = ps.executeQuery(); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
boolean success = false; |
|
|
|
|
try { |
|
|
|
|
ps.close(); |
|
|
|
|
} catch (SQLException e1) { |
|
|
|
|
//这边不记,可能还没建表
|
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); |
|
|
|
|
} catch (JSONException e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
return rs; |
|
|
|
|
return success; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 收集开始使用时间,发送信息 |
|
|
|
|
*/ |
|
|
|
@ -494,6 +424,47 @@ public class InformationCollector implements XMLReadable, XMLWriter {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static ArrayList getFunctionsContentAsByte(long currentTime) throws JSONException{ |
|
|
|
|
ArrayList<Map<String,Object>> records = new ArrayList<Map<String,Object>>(); |
|
|
|
|
QueryCondition condition = QueryFactory.create().addRestriction( |
|
|
|
|
RestrictionFactory.lte(COLUMN_TIME, currentTime) |
|
|
|
|
); |
|
|
|
|
try { |
|
|
|
|
DataList<FocusPoint> focusPoints = MetricRegistry.getMetric().find(FocusPoint.class,condition); |
|
|
|
|
focusPoints.getList(); |
|
|
|
|
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); |
|
|
|
|
String bbsUserName = MarketConfig.getInstance().getBbsUsername(); |
|
|
|
|
String uuid = envManager.getUUID(); |
|
|
|
|
if(!focusPoints.isEmpty()){ |
|
|
|
|
for(FocusPoint focusPoint : focusPoints.getList()){ |
|
|
|
|
Map<String,Object> record = new HashMap<>(); |
|
|
|
|
record.put(ATTR_ID, focusPoint.getId()); |
|
|
|
|
record.put(ATTR_TEXT, focusPoint.getText()); |
|
|
|
|
record.put(ATTR_SOURCE, focusPoint.getSource()); |
|
|
|
|
record.put(ATTR_TIME, focusPoint.getTime().getTime()); |
|
|
|
|
record.put(ATTR_TITLE, focusPoint.getTitle()); |
|
|
|
|
record.put(ATTR_USER_NAME, bbsUserName); |
|
|
|
|
record.put(ATTR_UUID, uuid); |
|
|
|
|
records.add(record); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (MetricException e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
return records; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void deleteFunctionRecords(long currentTime) { |
|
|
|
|
QueryCondition condition = QueryFactory.create().addRestriction( |
|
|
|
|
RestrictionFactory.lte(COLUMN_TIME, currentTime) |
|
|
|
|
); |
|
|
|
|
try { |
|
|
|
|
MetricRegistry.getMetric().clean(condition); |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private class StartStopTime implements XMLReadable, XMLWriter { |
|
|
|
|
|
|
|
|
|
private String startDate; |
|
|
|
|