|
@@ -0,0 +1,865 @@
|
|
|
+package com.saga.util;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.zillion.util.log.LogUtil;
|
|
|
+
|
|
|
+import com.saga.entity.PointSet;
|
|
|
+import com.saga.entity.Record;
|
|
|
+import com.sagacloud.json.JSONArray;
|
|
|
+import com.sagacloud.json.JSONObject;
|
|
|
+import com.zillion.database.agent.ZillionAgent;
|
|
|
+
|
|
|
+public class HBaseUtil {
|
|
|
+ public static void GetCollectorStatus(ZillionAgent agent, String db, String tb, String project) throws Exception {
|
|
|
+
|
|
|
+ JSONObject Criteria = new JSONObject();
|
|
|
+ Criteria.put("project", project);
|
|
|
+ Criteria.put("collector",
|
|
|
+ Constant.getLocalHostLANAddress().getHostAddress() + ":" + Constant.TypePort.get("Down"));
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "select");
|
|
|
+ wrapperObject.put("Database", db);
|
|
|
+ wrapperObject.put("Datatable", tb);
|
|
|
+ wrapperObject.put("Criteria", Criteria);
|
|
|
+ JSONObject queryResult = agent.Query(wrapperObject);
|
|
|
+ JSONArray resultContent = (JSONArray) queryResult.get("Content");
|
|
|
+ LogUtil.info("Reload Project:" + project + " CollectorStatus Begin...");
|
|
|
+ for (int i = 0; i < resultContent.size(); i++) {
|
|
|
+ JSONObject dataItem = (JSONObject) resultContent.get(i);
|
|
|
+ String node = (String) dataItem.get("gateway");
|
|
|
+ String key = project + "-" + node;
|
|
|
+ String receivetime = (String) dataItem.get("receivetime");
|
|
|
+ Constant.nodeList.put(key, Constant.parse(receivetime).getTime());
|
|
|
+ LogUtil.info("project " + project + " collector " + Constant.getLocalHostLANAddress().getHostAddress() + ":"
|
|
|
+ + Constant.TypePort.get("Down") + " gateway " + node + " " + System.currentTimeMillis() + " "
|
|
|
+ + Constant.parse(receivetime).getTime());
|
|
|
+ }
|
|
|
+ LogUtil.info("Reload Project:" + project + " CollectorStatus End...");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void GetPointStatus(ZillionAgent agent, String db, String tb, String project) throws Exception {
|
|
|
+
|
|
|
+ JSONObject Criteria = new JSONObject();
|
|
|
+ Criteria.put("project", project);
|
|
|
+ Criteria.put("collector",
|
|
|
+ Constant.getLocalHostLANAddress().getHostAddress() + ":" + Constant.TypePort.get("Down"));
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "select");
|
|
|
+ wrapperObject.put("Database", db);
|
|
|
+ wrapperObject.put("Datatable", tb);
|
|
|
+ wrapperObject.put("Criteria", Criteria);
|
|
|
+ JSONObject queryResult = agent.Query(wrapperObject);
|
|
|
+ JSONArray resultContent = (JSONArray) queryResult.get("Content");
|
|
|
+ LogUtil.info("Reload Project:" + project + " PointStatus Begin...");
|
|
|
+ // synchronized (Constant.pointListUp) {
|
|
|
+ for (int i = 0; i < resultContent.size(); i++) {
|
|
|
+ JSONObject dataItem = (JSONObject) resultContent.get(i);
|
|
|
+ String node = (String) dataItem.get("gateway");
|
|
|
+ String meter = (String) dataItem.get("meter");
|
|
|
+ String funcid = (String) dataItem.get("funcid");
|
|
|
+ String updown = (String) dataItem.get("updown");
|
|
|
+ if ("up".equalsIgnoreCase(updown)) {
|
|
|
+ String key = project + "-" + node + "-" + meter + "." + funcid;
|
|
|
+ String receivetime = (String) dataItem.get("receivetime");
|
|
|
+ Constant.pointListUp.put(key, Constant.parse(receivetime).getTime());
|
|
|
+ LogUtil.info("project " + project + " collector " + Constant.getLocalHostLANAddress().getHostAddress()
|
|
|
+ + ":" + Constant.TypePort.get("Down") + " gateway " + node + " meter " + meter + " funcid "
|
|
|
+ + funcid + " " + System.currentTimeMillis() + " " + Constant.parse(receivetime).getTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // }
|
|
|
+ LogUtil.info("Reload Project:" + project + " PointStatus End...");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Getset(ZillionAgent agent, String db, String tb, String building, String meter, long funcid,
|
|
|
+ String query_from, String query_to) throws Exception {
|
|
|
+
|
|
|
+ JSONObject Criteria = new JSONObject();
|
|
|
+ Criteria.put("building", building);
|
|
|
+ Criteria.put("meter", meter);
|
|
|
+ Criteria.put("funcid", funcid);
|
|
|
+ JSONObject range = new JSONObject();
|
|
|
+ range.put("$gt", query_from);
|
|
|
+ range.put("$lt", query_to);
|
|
|
+ Criteria.put("receivetime", range);
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "select");
|
|
|
+ wrapperObject.put("Database", db);
|
|
|
+ wrapperObject.put("Datatable", tb);
|
|
|
+ wrapperObject.put("Criteria", Criteria);
|
|
|
+ JSONObject queryResult = agent.Query(wrapperObject);
|
|
|
+ JSONArray resultContent = (JSONArray) queryResult.get("Content");
|
|
|
+ // File test = new File(System.getProperty("user.dir") + "/test.log");
|
|
|
+ // CSVUtil.insert(test, new StringBuffer("Getset" + " " + db + " " + tb
|
|
|
+ // + " " + building + " " + meter + " "
|
|
|
+ // + funcid + " " + query_from + " " + query_to + "\r\n"));
|
|
|
+ for (int i = 0; i < resultContent.size(); i++) {
|
|
|
+ JSONObject dataItem = (JSONObject) resultContent.get(i);
|
|
|
+
|
|
|
+ String receivetime = (String) dataItem.get("receivetime");
|
|
|
+ String endtime = (String) dataItem.get("endtime");
|
|
|
+ Double data = (Double) dataItem.get("data");
|
|
|
+ String status = (String) dataItem.get("status");
|
|
|
+ System.out.println(
|
|
|
+ "receivetime " + receivetime + " endtime " + endtime + " data:" + data + " status " + status);
|
|
|
+ // CSVUtil.insert(test, new StringBuffer("receivetime " +
|
|
|
+ // receivetime + " endtime " + endtime + " data:" + data
|
|
|
+ // + " status " + status + "\r\n"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Getset_present(ZillionAgent agent, String db, String tb, String building, String meter,
|
|
|
+ long funcid) throws Exception {
|
|
|
+
|
|
|
+ JSONObject Criteria = new JSONObject();
|
|
|
+ Criteria.put("building", building);
|
|
|
+ Criteria.put("meter", meter);
|
|
|
+ Criteria.put("funcid", funcid);
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "select");
|
|
|
+ wrapperObject.put("Database", db);
|
|
|
+ wrapperObject.put("Datatable", tb);
|
|
|
+ wrapperObject.put("Criteria", Criteria);
|
|
|
+ JSONObject queryResult = agent.Query(wrapperObject);
|
|
|
+ JSONArray resultContent = (JSONArray) queryResult.get("Content");
|
|
|
+ // File test = new File(System.getProperty("user.dir") + "/test.log");
|
|
|
+ // CSVUtil.insert(test, new StringBuffer(
|
|
|
+ // "Getset_present" + " " + db + " " + tb + " " + building + " " + meter
|
|
|
+ // + " " + funcid + "\r\n"));
|
|
|
+ for (int i = 0; i < resultContent.size(); i++) {
|
|
|
+ JSONObject dataItem = (JSONObject) resultContent.get(i);
|
|
|
+
|
|
|
+ String receivetime = (String) dataItem.get("receivetime");
|
|
|
+ String endtime = (String) dataItem.get("endtime");
|
|
|
+ Double data = (Double) dataItem.get("data");
|
|
|
+ String status = (String) dataItem.get("status");
|
|
|
+ // CSVUtil.insert(test, new StringBuffer("receivetime " +
|
|
|
+ // receivetime + " endtime " + endtime + " data:" + data
|
|
|
+ // + " status " + status + "\r\n"));
|
|
|
+ System.out.println(
|
|
|
+ "receivetime " + receivetime + " endtime " + endtime + " data:" + data + " status " + status);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void GetOriginal_month(ZillionAgent agent, String db, String tb, String building, String meter,
|
|
|
+ long funcid, String query_from, String query_to) throws Exception {
|
|
|
+
|
|
|
+ JSONObject Criteria = new JSONObject();
|
|
|
+ Criteria.put("building", building);
|
|
|
+ Criteria.put("meter", meter);
|
|
|
+ Criteria.put("funcid", funcid);
|
|
|
+ JSONObject range = new JSONObject();
|
|
|
+ range.put("$gt", query_from);
|
|
|
+ range.put("$lt", query_to);
|
|
|
+ Criteria.put("receivetime", range);
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "select");
|
|
|
+ wrapperObject.put("Database", db);
|
|
|
+ wrapperObject.put("Datatable", tb);
|
|
|
+ wrapperObject.put("Criteria", Criteria);
|
|
|
+ JSONObject queryResult = agent.Query(wrapperObject);
|
|
|
+ JSONArray resultContent = (JSONArray) queryResult.get("Content");
|
|
|
+ // File test = new File(System.getProperty("user.dir") + "/test.log");
|
|
|
+ // CSVUtil.insert(test, new StringBuffer("GetOriginal_month" + " " + db
|
|
|
+ // + " " + tb + " " + building + " " + meter
|
|
|
+ // + " " + funcid + " " + query_from + " " + query_to + "\r\n"));
|
|
|
+ for (int i = 0; i < resultContent.size(); i++) {
|
|
|
+ JSONObject dataItem = (JSONObject) resultContent.get(i);
|
|
|
+
|
|
|
+ String receivetime = (String) dataItem.get("receivetime");
|
|
|
+
|
|
|
+ Double data = (Double) dataItem.get("data");
|
|
|
+ // CSVUtil.insert(test, new StringBuffer("receivetime " +
|
|
|
+ // receivetime + " data:" + data + "\r\n"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void GetOriginal_present(ZillionAgent agent, String db, String tb, String building, String meter,
|
|
|
+ long funcid) throws Exception {
|
|
|
+
|
|
|
+ JSONObject Criteria = new JSONObject();
|
|
|
+ Criteria.put("building", building);
|
|
|
+ Criteria.put("meter", meter);
|
|
|
+ Criteria.put("funcid", funcid);
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "select");
|
|
|
+ wrapperObject.put("Database", db);
|
|
|
+ wrapperObject.put("Datatable", tb);
|
|
|
+ wrapperObject.put("Criteria", Criteria);
|
|
|
+ JSONObject queryResult = agent.Query(wrapperObject);
|
|
|
+ JSONArray resultContent = (JSONArray) queryResult.get("Content");
|
|
|
+ // File test = new File(System.getProperty("user.dir") + "/test.log");
|
|
|
+ // CSVUtil.insert(test, new StringBuffer(
|
|
|
+ // "GetOriginal_present" + " " + db + " " + tb + " " + building + " " +
|
|
|
+ // meter + " " + funcid + "\r\n"));
|
|
|
+ for (int i = 0; i < resultContent.size(); i++) {
|
|
|
+ JSONObject dataItem = (JSONObject) resultContent.get(i);
|
|
|
+ String receivetime = (String) dataItem.get("receivetime");
|
|
|
+ Double data = (Double) dataItem.get("data");
|
|
|
+ // CSVUtil.insert(test, new StringBuffer("receivetime " +
|
|
|
+ // receivetime + " data:" + data + "\r\n"));
|
|
|
+ System.out
|
|
|
+ .println("meter " + meter + " funcid " + funcid + " receivetime " + receivetime + " data:" + data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static JSONObject CreateJSON(String Name, String Type) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("Name", Name);
|
|
|
+ result.put("Type", Type);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateDB(ZillionAgent agent, String DB) throws Exception {
|
|
|
+ agent.NDL_AddDatabase(DB);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean tableExist(ZillionAgent agent, String DBName, String tableName) throws Exception {
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "table_list");
|
|
|
+ wrapperObject.put("Database", DBName);
|
|
|
+ JSONObject result = agent.Query(wrapperObject);
|
|
|
+ JSONArray array = (JSONArray) result.get("Content");
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ String tableNameInner = (String) array.get(i);
|
|
|
+ if (tableNameInner.equalsIgnoreCase(tableName)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateTable(ZillionAgent agent, String DB, String tableName) throws Exception {
|
|
|
+ if (!tableExist(agent, DB, tableName)) {
|
|
|
+ JSONArray Columns = new JSONArray();
|
|
|
+ Columns.add(CreateJSON("building", "String"));
|
|
|
+ Columns.add(CreateJSON("meter", "String"));
|
|
|
+ Columns.add(CreateJSON("funcid", "Long"));
|
|
|
+ Columns.add(CreateJSON("receivetime", "String"));
|
|
|
+ Columns.add(CreateJSON("data", "Double"));
|
|
|
+ JSONArray Key = new JSONArray();
|
|
|
+ Key.add("building");
|
|
|
+ Key.add("meter");
|
|
|
+ Key.add("funcid");
|
|
|
+ Key.add("receivetime");
|
|
|
+ JSONObject Definition = new JSONObject();
|
|
|
+ Definition.put("Columns", Columns);
|
|
|
+ Definition.put("Key", Key);
|
|
|
+ Definition.put("delete_UsePutV", false);
|
|
|
+ Definition.put("table_type", "split_month");
|
|
|
+ Definition.put("split_column", "receivetime");
|
|
|
+ JSONArray Indexes = new JSONArray();
|
|
|
+ agent.DDL_AddTable(DB, tableName, Definition, Indexes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateTable_present(ZillionAgent agent, String DB, String tableName) throws Exception {
|
|
|
+ if (!tableExist(agent, DB, tableName)) {
|
|
|
+
|
|
|
+ JSONArray Columns = new JSONArray();
|
|
|
+ Columns.add(CreateJSON("building", "String"));
|
|
|
+ Columns.add(CreateJSON("meter", "String"));
|
|
|
+ Columns.add(CreateJSON("funcid", "Long"));
|
|
|
+ Columns.add(CreateJSON("receivetime", "String"));
|
|
|
+ Columns.add(CreateJSON("data", "Double"));
|
|
|
+ JSONArray Key = new JSONArray();
|
|
|
+ Key.add("building");
|
|
|
+ Key.add("meter");
|
|
|
+ Key.add("funcid");
|
|
|
+ JSONObject Definition = new JSONObject();
|
|
|
+ Definition.put("Columns", Columns);
|
|
|
+ Definition.put("Key", Key);
|
|
|
+ Definition.put("delete_UsePutV", false);
|
|
|
+ JSONArray Indexes = new JSONArray();
|
|
|
+ agent.DDL_AddTable(DB, tableName, Definition, Indexes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateTable_set(ZillionAgent agent, String DB, String tableName) throws Exception {
|
|
|
+ if (!tableExist(agent, DB, tableName)) {
|
|
|
+
|
|
|
+ JSONArray Columns = new JSONArray();
|
|
|
+ Columns.add(CreateJSON("building", "String"));
|
|
|
+ Columns.add(CreateJSON("meter", "String"));
|
|
|
+ Columns.add(CreateJSON("funcid", "Long"));
|
|
|
+ Columns.add(CreateJSON("receivetime", "String"));
|
|
|
+ Columns.add(CreateJSON("data", "Double"));
|
|
|
+ Columns.add(CreateJSON("status", "String"));
|
|
|
+ Columns.add(CreateJSON("endtime", "String"));
|
|
|
+ JSONArray Key = new JSONArray();
|
|
|
+ Key.add("building");
|
|
|
+ Key.add("meter");
|
|
|
+ Key.add("funcid");
|
|
|
+ Key.add("receivetime");
|
|
|
+ JSONObject Definition = new JSONObject();
|
|
|
+ Definition.put("Columns", Columns);
|
|
|
+ Definition.put("Key", Key);
|
|
|
+ JSONArray Indexes = new JSONArray();
|
|
|
+ agent.DDL_AddTable(DB, tableName, Definition, Indexes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateTable_setpresent(ZillionAgent agent, String DB, String tableName) throws Exception {
|
|
|
+ if (!tableExist(agent, DB, tableName)) {
|
|
|
+
|
|
|
+ JSONArray Columns = new JSONArray();
|
|
|
+ Columns.add(CreateJSON("building", "String"));
|
|
|
+ Columns.add(CreateJSON("meter", "String"));
|
|
|
+ Columns.add(CreateJSON("funcid", "Long"));
|
|
|
+ Columns.add(CreateJSON("receivetime", "String"));
|
|
|
+ Columns.add(CreateJSON("data", "Double"));
|
|
|
+ Columns.add(CreateJSON("status", "String"));
|
|
|
+ Columns.add(CreateJSON("endtime", "String"));
|
|
|
+ JSONArray Key = new JSONArray();
|
|
|
+ Key.add("building");
|
|
|
+ Key.add("meter");
|
|
|
+ Key.add("funcid");
|
|
|
+ JSONObject Definition = new JSONObject();
|
|
|
+ Definition.put("Columns", Columns);
|
|
|
+ Definition.put("Key", Key);
|
|
|
+ JSONArray Indexes = new JSONArray();
|
|
|
+ agent.DDL_AddTable(DB, tableName, Definition, Indexes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateTable_CollectorStatus(ZillionAgent agent, String DB, String tableName) throws Exception {
|
|
|
+ if (!tableExist(agent, DB, tableName)) {
|
|
|
+
|
|
|
+ JSONArray Columns = new JSONArray();
|
|
|
+ Columns.add(CreateJSON("project", "String"));
|
|
|
+ Columns.add(CreateJSON("collector", "String"));
|
|
|
+ Columns.add(CreateJSON("gateway", "String"));
|
|
|
+ Columns.add(CreateJSON("status", "String"));
|
|
|
+ Columns.add(CreateJSON("receivetime", "String"));
|
|
|
+ Columns.add(CreateJSON("detail", "String"));
|
|
|
+
|
|
|
+ JSONArray Key = new JSONArray();
|
|
|
+ Key.add("project");
|
|
|
+ Key.add("collector");
|
|
|
+ Key.add("gateway");
|
|
|
+ JSONObject Definition = new JSONObject();
|
|
|
+ Definition.put("Columns", Columns);
|
|
|
+ Definition.put("Key", Key);
|
|
|
+ JSONArray Indexes = new JSONArray();
|
|
|
+ agent.DDL_AddTable(DB, tableName, Definition, Indexes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateTable_CollectorCommunicationLog(ZillionAgent agent, String DB, String tableName)
|
|
|
+ throws Exception {
|
|
|
+ if (!tableExist(agent, DB, tableName)) {
|
|
|
+
|
|
|
+ JSONArray Columns = new JSONArray();
|
|
|
+ Columns.add(CreateJSON("project", "String"));
|
|
|
+ Columns.add(CreateJSON("collector", "String"));
|
|
|
+ Columns.add(CreateJSON("gateway", "String"));
|
|
|
+ Columns.add(CreateJSON("receivetime", "String"));
|
|
|
+ Columns.add(CreateJSON("function", "String"));
|
|
|
+
|
|
|
+ JSONArray Key = new JSONArray();
|
|
|
+ Key.add("project");
|
|
|
+ Key.add("collector");
|
|
|
+ Key.add("gateway");
|
|
|
+ Key.add("receivetime");
|
|
|
+ JSONObject Definition = new JSONObject();
|
|
|
+ Definition.put("Columns", Columns);
|
|
|
+ Definition.put("Key", Key);
|
|
|
+ JSONArray Indexes = new JSONArray();
|
|
|
+ agent.DDL_AddTable(DB, tableName, Definition, Indexes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateTable_PointStatus(ZillionAgent agent, String DB, String tableName) throws Exception {
|
|
|
+ if (!tableExist(agent, DB, tableName)) {
|
|
|
+
|
|
|
+ JSONArray Columns = new JSONArray();
|
|
|
+ Columns.add(CreateJSON("project", "String"));
|
|
|
+ Columns.add(CreateJSON("collector", "String"));
|
|
|
+ Columns.add(CreateJSON("gateway", "String"));
|
|
|
+ Columns.add(CreateJSON("meter", "String"));
|
|
|
+ Columns.add(CreateJSON("funcid", "String"));
|
|
|
+ Columns.add(CreateJSON("updown", "String"));
|
|
|
+ Columns.add(CreateJSON("status", "String"));
|
|
|
+ Columns.add(CreateJSON("receivetime", "String"));
|
|
|
+ Columns.add(CreateJSON("detail", "String"));
|
|
|
+
|
|
|
+ JSONArray Key = new JSONArray();
|
|
|
+ Key.add("project");
|
|
|
+ Key.add("collector");
|
|
|
+ Key.add("gateway");
|
|
|
+ Key.add("meter");
|
|
|
+ Key.add("funcid");
|
|
|
+ Key.add("updown");
|
|
|
+ JSONObject Definition = new JSONObject();
|
|
|
+ Definition.put("Columns", Columns);
|
|
|
+ Definition.put("Key", Key);
|
|
|
+ JSONArray Indexes = new JSONArray();
|
|
|
+ agent.DDL_AddTable(DB, tableName, Definition, Indexes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateTable_PointInfo(ZillionAgent agent, String DB, String tableName) throws Exception {
|
|
|
+ if (!tableExist(agent, DB, tableName)) {
|
|
|
+
|
|
|
+ JSONArray Columns = new JSONArray();
|
|
|
+ Columns.add(CreateJSON("project", "String"));
|
|
|
+ Columns.add(CreateJSON("gateway", "String"));
|
|
|
+ Columns.add(CreateJSON("meter", "String"));
|
|
|
+ Columns.add(CreateJSON("BusNo", "String"));
|
|
|
+ Columns.add(CreateJSON("site", "String"));
|
|
|
+
|
|
|
+ JSONArray Key = new JSONArray();
|
|
|
+ Key.add("project");
|
|
|
+ Key.add("gateway");
|
|
|
+ Key.add("meter");
|
|
|
+ JSONObject Definition = new JSONObject();
|
|
|
+ Definition.put("Columns", Columns);
|
|
|
+ Definition.put("Key", Key);
|
|
|
+ JSONArray Indexes = new JSONArray();
|
|
|
+ agent.DDL_AddTable(DB, tableName, Definition, Indexes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void CreateTable_PointCommunicationLog(ZillionAgent agent, String DB, String tableName)
|
|
|
+ throws Exception {
|
|
|
+ if (!tableExist(agent, DB, tableName)) {
|
|
|
+
|
|
|
+ JSONArray Columns = new JSONArray();
|
|
|
+ Columns.add(CreateJSON("project", "String"));
|
|
|
+ Columns.add(CreateJSON("collector", "String"));
|
|
|
+ Columns.add(CreateJSON("gateway", "String"));
|
|
|
+ Columns.add(CreateJSON("meter", "String"));
|
|
|
+ Columns.add(CreateJSON("funcid", "String"));
|
|
|
+ Columns.add(CreateJSON("updown", "String"));
|
|
|
+ Columns.add(CreateJSON("function", "String"));
|
|
|
+ Columns.add(CreateJSON("seq", "String"));
|
|
|
+ Columns.add(CreateJSON("receivetime", "String"));
|
|
|
+ Columns.add(CreateJSON("feedback", "String"));
|
|
|
+
|
|
|
+ JSONArray Key = new JSONArray();
|
|
|
+ Key.add("project");
|
|
|
+ Key.add("collector");
|
|
|
+ Key.add("gateway");
|
|
|
+ Key.add("meter");
|
|
|
+ Key.add("funcid");
|
|
|
+ Key.add("updown");
|
|
|
+ Key.add("function");
|
|
|
+ Key.add("seq");
|
|
|
+ Key.add("receivetime");
|
|
|
+ JSONObject Definition = new JSONObject();
|
|
|
+ Definition.put("Columns", Columns);
|
|
|
+ Definition.put("Key", Key);
|
|
|
+ JSONArray Indexes = new JSONArray();
|
|
|
+ agent.DDL_AddTable(DB, tableName, Definition, Indexes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void InsertCollectorStatus(ZillionAgent agent, String DB, String project, String collector,
|
|
|
+ String node, String status, String receivetime) throws Exception {
|
|
|
+
|
|
|
+ JSONArray InsertObjects = new JSONArray();
|
|
|
+ try {
|
|
|
+ if (DB != null) {
|
|
|
+
|
|
|
+ JSONObject InsertObject = new JSONObject();
|
|
|
+ InsertObject.put("project", project);
|
|
|
+ InsertObject.put("collector", collector);
|
|
|
+ InsertObject.put("gateway", node);
|
|
|
+ InsertObject.put("status", status);
|
|
|
+ InsertObject.put("receivetime", receivetime);
|
|
|
+
|
|
|
+ InsertObjects.add(InsertObject);
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_put");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "pointgatewaystatus");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.error("HBaseUtil.InsertCollectorStatus.Exception: " + e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void InsertCollectorCommunicationLog(ZillionAgent agent, String DB, String project, String collector,
|
|
|
+ String node, String receivetime, String function) throws Exception {
|
|
|
+
|
|
|
+ JSONArray InsertObjects = new JSONArray();
|
|
|
+ try {
|
|
|
+ if (DB != null) {
|
|
|
+
|
|
|
+ JSONObject InsertObject = new JSONObject();
|
|
|
+ InsertObject.put("project", project);
|
|
|
+ InsertObject.put("collector", collector);
|
|
|
+ InsertObject.put("gateway", node);
|
|
|
+ InsertObject.put("receivetime", receivetime);
|
|
|
+ InsertObject.put("function", function);
|
|
|
+
|
|
|
+ InsertObjects.add(InsertObject);
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_insert");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "pointgatewaylog");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.error("HBaseUtil.BatchInsert.Exception: " + e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void InsertPointStatus(ZillionAgent agent, String DB, String project, String collector, String node,
|
|
|
+ String meter, String funcid, String updown, String status, String receivetime, String detail)
|
|
|
+ throws Exception {
|
|
|
+
|
|
|
+ JSONArray InsertObjects = new JSONArray();
|
|
|
+ try {
|
|
|
+ if (DB != null) {
|
|
|
+
|
|
|
+ JSONObject InsertObject = new JSONObject();
|
|
|
+ InsertObject.put("project", project);
|
|
|
+ InsertObject.put("collector", collector);
|
|
|
+ InsertObject.put("gateway", node);
|
|
|
+ InsertObject.put("meter", meter);
|
|
|
+ InsertObject.put("funcid", funcid);
|
|
|
+ InsertObject.put("updown", updown);
|
|
|
+ InsertObject.put("status", status);
|
|
|
+ InsertObject.put("receivetime", receivetime);
|
|
|
+ InsertObject.put("detail", detail);
|
|
|
+
|
|
|
+ InsertObjects.add(InsertObject);
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_put");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "pointstatus");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.error("HBaseUtil.InsertPointStatus.Exception: " + e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void InsertPointInfo(ZillionAgent agent, String DB, String project, String node, String point,
|
|
|
+ String BusNo, String site) throws Exception {
|
|
|
+
|
|
|
+ JSONArray InsertObjects = new JSONArray();
|
|
|
+ try {
|
|
|
+ if (DB != null) {
|
|
|
+
|
|
|
+ JSONObject InsertObject = new JSONObject();
|
|
|
+ InsertObject.put("project", project);
|
|
|
+ InsertObject.put("gateway", node);
|
|
|
+ InsertObject.put("meter", point);
|
|
|
+ InsertObject.put("BusNo", BusNo);
|
|
|
+ InsertObject.put("site", site);
|
|
|
+
|
|
|
+ InsertObjects.add(InsertObject);
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_put");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "pointinfo");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ LogUtil.error("HBaseUtil.InsertPointInfo.Exception: " + e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void InsertPointCommunicationLog(ZillionAgent agent, String DB, String project, String collector,
|
|
|
+ String node, String meter, String funcid, String updown, String function, String seq, String receivetime,
|
|
|
+ String feedback) throws Exception {
|
|
|
+
|
|
|
+ JSONArray InsertObjects = new JSONArray();
|
|
|
+ try {
|
|
|
+ if (DB != null) {
|
|
|
+
|
|
|
+ JSONObject InsertObject = new JSONObject();
|
|
|
+ InsertObject.put("project", project);
|
|
|
+ InsertObject.put("collector", collector);
|
|
|
+ InsertObject.put("gateway", node);
|
|
|
+ InsertObject.put("meter", meter);
|
|
|
+ InsertObject.put("funcid", funcid);
|
|
|
+ InsertObject.put("updown", updown);
|
|
|
+ InsertObject.put("function", function);
|
|
|
+ InsertObject.put("seq", seq);
|
|
|
+ InsertObject.put("receivetime", receivetime);
|
|
|
+ InsertObject.put("feedback", feedback);
|
|
|
+
|
|
|
+ InsertObjects.add(InsertObject);
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_insert");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "pointlog");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.error("HBaseUtil.InsertPointCommunicationLog.Exception: " + e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // public static void InsertPointCommunicationLog(List<String> list) throws
|
|
|
+ // Exception {
|
|
|
+ // // TODO Auto-generated method stub
|
|
|
+ // JSONArray InsertObjects = new JSONArray();
|
|
|
+ // String DB = null;
|
|
|
+ // try {
|
|
|
+ // for (String s : list) {
|
|
|
+ // String[] rlist = s.split(";");
|
|
|
+ //
|
|
|
+ // // 0 building,
|
|
|
+ // // 1 Constant.getLocalHostLANAddress().getHostAddress(),
|
|
|
+ // // 2 mac,
|
|
|
+ // // 3 meter + "." + record.funcID,
|
|
|
+ // // 4 function,
|
|
|
+ // // 5 id,
|
|
|
+ // // 6 rList[3],
|
|
|
+ // // 7 record.addtion
|
|
|
+ // DB = Constant.BuildingDB.get(rlist[0]) == null ? DB :
|
|
|
+ // Constant.BuildingDB.get(rlist[0]);
|
|
|
+ // if (DB != null) {
|
|
|
+ // JSONObject InsertObject = new JSONObject();
|
|
|
+ // InsertObject.put("project", rlist[0]);
|
|
|
+ // InsertObject.put("collector", rlist[1]);
|
|
|
+ // InsertObject.put("gateway", rlist[2]);
|
|
|
+ // InsertObject.put("point", rlist[3]);
|
|
|
+ // InsertObject.put("function", rlist[4]);
|
|
|
+ // InsertObject.put("seq", rlist[5]);
|
|
|
+ // InsertObject.put("receivetime", rlist[6]);
|
|
|
+ // InsertObject.put("feedback", rlist.length > 7 ? rlist[7] : "");
|
|
|
+ //
|
|
|
+ // InsertObjects.add(InsertObject);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // JSONObject wrapperObject = new JSONObject();
|
|
|
+ // if (DB != null) {
|
|
|
+ // wrapperObject = new JSONObject();
|
|
|
+ // wrapperObject.put("QueryType", "batch_insert");
|
|
|
+ // wrapperObject.put("Database", DB);
|
|
|
+ // wrapperObject.put("Datatable", "pointlog");
|
|
|
+ // wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ // Constant.agent.Query(wrapperObject);
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // LogUtil.error("HBaseUtil.InsertPointCommunicationLog.Exception: " +
|
|
|
+ // e.toString());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ public static void BatchInsert(ZillionAgent agent, String DB, List<Record> dataList) throws Exception {
|
|
|
+ JSONArray InsertObjects = new JSONArray();
|
|
|
+ try {
|
|
|
+ if (DB != null && dataList.size() > 0) {
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
+
|
|
|
+ Record data = dataList.get(i);
|
|
|
+
|
|
|
+ JSONObject InsertObject = new JSONObject();
|
|
|
+ InsertObject.put("building", data.buildingSign);
|
|
|
+ InsertObject.put("meter", data.meterSign);
|
|
|
+ InsertObject.put("funcid", (long) data.funcID);
|
|
|
+ InsertObject.put("receivetime", Constant.format(data.receivetime));
|
|
|
+ InsertObject.put("data", data.data);
|
|
|
+
|
|
|
+ InsertObjects.add(InsertObject);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (InsertObjects.size() > 0) {
|
|
|
+ Constant.writeDB += InsertObjects.size();
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_insert");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "original_month");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_put");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "original_present");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ // LogUtil.info("insert into " + DB + "." +
|
|
|
+ // "original_month&" + "original_present "
|
|
|
+ // + InsertObjects.toFormatString());
|
|
|
+ LogUtil.info(
|
|
|
+ "insert into " + DB + "." + "original_month&" + "original_present " + InsertObjects.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.error("HBaseUtil.BatchInsert.Exception: " + e.toString());
|
|
|
+ Constant.DBConn = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void BatchInsert_Set1(ZillionAgent agent, String DB, PointSet ps) throws Exception {
|
|
|
+ JSONArray InsertObjects = new JSONArray();
|
|
|
+ try {
|
|
|
+ if (DB != null) {
|
|
|
+
|
|
|
+ JSONObject InsertObject = new JSONObject();
|
|
|
+ // InsertObject.put("building", ps.buildingSign);
|
|
|
+ InsertObject.put("building", ps.buildingSignUP);
|
|
|
+ InsertObject.put("meter", ps.meterSign);
|
|
|
+ InsertObject.put("funcid", (long) ps.funcID);
|
|
|
+ InsertObject.put("receivetime", Constant.format(new Date((long) ps.sendTime)));
|
|
|
+ InsertObject.put("data", ps.dataSet);
|
|
|
+ InsertObject.put("status", "processing:sent");
|
|
|
+
|
|
|
+ // LogUtil.info(InsertObject.toFormatString());
|
|
|
+
|
|
|
+ InsertObjects.add(InsertObject);
|
|
|
+
|
|
|
+ if (InsertObjects.size() > 0) {
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_insert");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "originalset");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_put");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "originalset_present");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ // LogUtil.info("insert into " + DB + "." + "originalset&" +
|
|
|
+ // "originalset_present "
|
|
|
+ // + InsertObject.toFormatString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.error("HBaseUtil.BatchInsert_Set1.Exception: " + e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void BatchInsert_Set2(ZillionAgent agent, String DB, PointSet ps) throws Exception {
|
|
|
+ JSONArray InsertObjects = new JSONArray();
|
|
|
+ try {
|
|
|
+ if (DB != null) {
|
|
|
+
|
|
|
+ JSONObject InsertObject = new JSONObject();
|
|
|
+ // InsertObject.put("building", ps.buildingSign);
|
|
|
+ InsertObject.put("building", ps.buildingSignUP);
|
|
|
+ InsertObject.put("meter", ps.meterSign);
|
|
|
+ InsertObject.put("funcid", (long) ps.funcID);
|
|
|
+ InsertObject.put("receivetime", Constant.format(new Date((long) ps.sendTime)));
|
|
|
+ InsertObject.put("data", ps.dataSet);
|
|
|
+ InsertObject.put("status", "finish:finish:" + ps.status);
|
|
|
+ InsertObject.put("endtime", Constant.format(new Date()));
|
|
|
+
|
|
|
+ // LogUtil.info(InsertObject.toFormatString());
|
|
|
+
|
|
|
+ InsertObjects.add(InsertObject);
|
|
|
+
|
|
|
+ if (InsertObjects.size() > 0) {
|
|
|
+
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_put");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "originalset");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_put");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "originalset_present");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ // LogUtil.info("insert into " + DB + "." + "originalset&" +
|
|
|
+ // "originalset_present "
|
|
|
+ // + InsertObject.toFormatString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.error("HBaseUtil.BatchInsert_Set2.Exception: " + e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void BatchInsert_Set3(ZillionAgent agent, String DB, PointSet ps) throws Exception {
|
|
|
+ JSONArray InsertObjects = new JSONArray();
|
|
|
+ try {
|
|
|
+ if (DB != null) {
|
|
|
+
|
|
|
+ JSONObject InsertObject = new JSONObject();
|
|
|
+ // InsertObject.put("building", ps.buildingSign);
|
|
|
+ InsertObject.put("building", ps.buildingSignUP);
|
|
|
+ InsertObject.put("meter", ps.meterSign);
|
|
|
+ InsertObject.put("funcid", (long) ps.funcID);
|
|
|
+ InsertObject.put("receivetime", Constant.format(new Date((long) ps.sendTime)));
|
|
|
+ InsertObject.put("data", ps.dataSet);
|
|
|
+ InsertObject.put("status", "finish:finish:" + "fail:timeout");
|
|
|
+ InsertObject.put("endtime", Constant.format(new Date()));
|
|
|
+
|
|
|
+ // LogUtil.info(InsertObject.toFormatString());
|
|
|
+
|
|
|
+ InsertObjects.add(InsertObject);
|
|
|
+
|
|
|
+ if (InsertObjects.size() > 0) {
|
|
|
+ JSONObject wrapperObject = new JSONObject();
|
|
|
+
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_put");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "originalset");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ wrapperObject = new JSONObject();
|
|
|
+ wrapperObject.put("QueryType", "batch_put");
|
|
|
+ wrapperObject.put("Database", DB);
|
|
|
+ wrapperObject.put("Datatable", "originalset_present");
|
|
|
+ wrapperObject.put("InsertObjects", InsertObjects);
|
|
|
+ agent.Query(wrapperObject);
|
|
|
+ // LogUtil.info("insert into " + DB + "." + "originalset&" +
|
|
|
+ // "originalset_present "
|
|
|
+ // + InsertObject.toFormatString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.error("HBaseUtil.BatchInsert_Set3.Exception: " + e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|