Parcourir la source

添加黑名单与白名单功能。其中:黑名单对building生效,白名单对funcid生效,白名单为空时白名单功能失效。

Jay Lee il y a 6 ans
Parent
commit
4abdfe7fa1

+ 50 - 63
collect/config.json

@@ -1,65 +1,52 @@
 {
-    "DB": [
-        {
-            "building": "1101080001", 
-            "database": "db_public_10", 
-            "buildingadds": [
-                {
-                    "building": "1101020001"
-                }, 
-                {
-                    "building": "1101020002"
-                }
-            ]
-        }, 
-        {
-            "building": "1101080002", 
-            "database": "db_public_10"
-        }, 
-        {
-            "building": "1101080003", 
-            "database": "db_public_10"
-        }, 
-        {
-            "building": "1101080004", 
-            "database": "db_public_10"
-        }, 
-        {
-            "building": "1101080005", 
-            "database": "db_public_10"
-        },
-        {
-            "building": "1101050001", 
-            "database": "db_public_10"
-        }, 
-        {
-            "building": "6666666666", 
-            "database": "db_public_10"
-        }, 
-        {
-            "building": "7777777777", 
-            "database": "db_public_10"
-        }, 
-        {
-            "building": "3101140002", 
-            "database": "db_public_10"
-        }, 
-        {
-            "insertthread": "1"
-        }
-    ], 
-    "Port": [
-        {
-            "type": "Up", 
-            "port": "9999",
-            "Compress":"false",
-            "History":"false"
-        }, 
-        {
-            "type": "Down", 
-            "port": "80" ,
-            "Compress":"false",
-            "History":"false"
-        }
-    ]
+	"DB": [{
+			"building": "1101080001",
+			"database": "db_public_10",
+			"buildingadds": [{
+					"building": "1101020001"
+				},
+				{
+					"building": "1101020002"
+				}
+			]
+		},
+		{
+			"building": "1101080002",
+			"database": "db_public_10"
+		},
+		{
+			"building": "1101080003",
+			"database": "db_public_10"
+		},
+		{
+			"insertthread": "1"
+		}
+	],
+	"Port": [{
+			"type": "Up",
+			"port": "9999",
+			"Compress": "false",
+			"History": "false"
+		},
+		{
+			"type": "Down",
+			"port": "80",
+			"Compress": "false",
+			"History": "false"
+		}
+	],
+	"BlackList": [{
+		"buildings": [{
+				"building": "1234567890"
+			},
+			{
+				"building": "8989898989"
+			}
+		]
+	}],
+	"WhiteList": [{
+		"funcids": [{
+			"funcid": 0
+		}]
+	}]
 }

+ 19 - 21
collect/src/main/java/com/saga/main/Main.java

@@ -605,32 +605,30 @@ public class Main {
 	private static void agentsStart() {
 		// TODO Auto-generated method stub
 		try {
-			// String resource = "/hbase-site.xml";
-			// Configuration configuration = new Configuration();
-			// configuration.addResource(new
-			// FileInputStream(System.getProperty("user.dir") + resource));
+			String resource = "/hbase-site.xml";
+			Configuration configuration = new Configuration();
+			configuration.addResource(new FileInputStream(System.getProperty("user.dir") + resource));
 			// int zookeeper_sessionTimeout = 300000;
 
-			List<String> qrlist = new ArrayList<String>();
+			// List<String> qrlist = new ArrayList<String>();
 			// qrlist.add("zookeeper1:2181,zookeeper2:2181,zookeeper3:2181");
-			qrlist.add("zookeeper1,zookeeper2,zookeeper3");
-			qrlist.add("zookeeper1.saga");
-			// qrlist.add("zookeeper1");
+			// qrlist.add("zookeeper1,zookeeper2,zookeeper3");
+			// qrlist.add("zookeeper1.saga");
+			// qrlist.add("zookeeper");
 
-			for (String qr : qrlist) {
-				try {
-					Configuration configuration = new Configuration();
-					configuration.set("hbase.cluster.distributed", "true");
-					configuration.set("hbase.zookeeper.quorum", qr);
-					ZillionAgent agent = new ZillionAgent(configuration);
-					agent.setFull_name(qr);
-					agent.Start();
-					Constant.agents.add(agent);
-				} catch (Exception e) {
-					e.printStackTrace();
-					LogUtil.error("Main.init.agentsStart: " + e.toString());
-				}
+			// for (String qr : qrlist) {
+			try {
+				// Configuration configuration = new Configuration();
+				// configuration.set("hbase.cluster.distributed", "true");
+				// configuration.set("hbase.zookeeper.quorum", qr);
+				ZillionAgent agent = new ZillionAgent(configuration);
+				agent.Start();
+				Constant.agents.add(agent);
+			} catch (Exception e) {
+				e.printStackTrace();
+				LogUtil.error("Main.init.agentsStart: " + e.toString());
 			}
+			// }
 			// Constant.agents.add(new ZillionAgent(configuration,
 			// "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181",
 			// zookeeper_sessionTimeout));

+ 31 - 2
collect/src/main/java/com/saga/thread/common/SaveThread.java

@@ -130,7 +130,7 @@ public class SaveThread extends Thread {
 										if (!building.equalsIgnoreCase(b)) {
 											continue;
 										}
-										//String mac = rList[1];
+										// String mac = rList[1];
 										String function = rList[2];
 										Date time = Constant.parse(rList[3]);
 										String meter = rList[5];
@@ -167,7 +167,9 @@ public class SaveThread extends Thread {
 											record.meterSign = meter;
 											record.receivetime = time;
 
-											this.strecordList.add(record);
+											if (toDB(record.buildingSign, record.funcID)) {
+												this.strecordList.add(record);
+											}
 
 										}
 										it.remove();
@@ -217,6 +219,33 @@ public class SaveThread extends Thread {
 		}
 	}
 
+	private boolean toDB(String buildingSign, int funcID) {
+		// TODO Auto-generated method stub
+		if (toDB_building(buildingSign) && toDB_funcid(funcID)) {
+			return true;
+		}
+		return false;
+	}
+
+	private boolean toDB_funcid(int funcID) {
+		// TODO Auto-generated method stub
+		if (Constant.whilte_Funcs == null || Constant.whilte_Funcs.size() == 0) {
+			return true;
+		}
+		if (Constant.whilte_Funcs.containsKey(funcID)) {
+			return true;
+		}
+		return false;
+	}
+
+	private boolean toDB_building(String buildingSign) {
+		// TODO Auto-generated method stub
+		if (!Constant.black_Buildings.containsKey(buildingSign)) {
+			return true;
+		}
+		return false;
+	}
+
 	// private void addPointCommunicationList(String building, String ip, String
 	// mac, String point, String id,
 	// String receivetime, String addtion) {

+ 30 - 0
collect/src/main/java/com/saga/util/Constant.java

@@ -85,6 +85,8 @@ public class Constant {
 	public static int collectReportCount = 0;
 	public static int report2DBCount = 0;
 	public static Map<String, String> pointMAC = new HashMap<String, String>();
+	public static Map<String, String> black_Buildings = new HashMap<String, String>();
+	public static Map<Integer, Integer> whilte_Funcs = new HashMap<Integer, Integer>();
 
 	static {
 		String resource = "\\config.json";
@@ -140,6 +142,34 @@ public class Constant {
 				// }
 			}
 
+			JsonArray blackList = object.get("BlackList").getAsJsonArray();
+			for (int i = 0; i < blackList.size(); i++) {
+				JsonObject subObject = blackList.get(i).getAsJsonObject();
+				if (subObject.get("buildings") != null) {
+					if (subObject.get("buildings") != null) {
+						JsonArray buildings = subObject.get("buildings").getAsJsonArray();
+						for (int j = 0; j < buildings.size(); j++) {
+							JsonObject addObject = buildings.get(j).getAsJsonObject();
+							Constant.black_Buildings.put(addObject.get("building").getAsString(), null);
+						}
+					}
+				}
+			}
+
+			JsonArray whiteList = object.get("WhiteList").getAsJsonArray();
+			for (int i = 0; i < whiteList.size(); i++) {
+				JsonObject subObject = whiteList.get(i).getAsJsonObject();
+				if (subObject.get("funcids") != null) {
+					if (subObject.get("funcids") != null) {
+						JsonArray funcids = subObject.get("funcids").getAsJsonArray();
+						for (int j = 0; j < funcids.size(); j++) {
+							JsonObject addObject = funcids.get(j).getAsJsonObject();
+							Constant.whilte_Funcs.put(addObject.get("funcid").getAsInt(), null);
+						}
+					}
+				}
+			}
+
 		} catch (Exception e) {
 			// TODO Auto-generated catch block
 			// System.out.println(e.getMessage());