This commit is contained in:
crusader 2017-12-13 23:11:33 +09:00
parent 0106a7cd30
commit 7bd7a22a1b
3 changed files with 39 additions and 6 deletions

View File

@ -33,11 +33,18 @@ public abstract class Crawler {
return true;
}
public List<ResultSet> get(String id) throws Exception {
public Map<String, String> get(String id) throws Exception {
List<ResultSet> rsList = (List<ResultSet>)getInternal(getConfig(id));
Map<String, String> rm = new HashMap<>();
Map<String, String> m = null;
return rsList;
for (ResultSet rs : rsList) {
m = rs.getData();
rm.putAll(m);
}
return rm;
}
public boolean init(Config config) throws Exception {

View File

@ -47,7 +47,7 @@ public class WMICrawler extends Crawler {
private List<Config> loadMetaConfig() throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
URL url = classLoader.getResource("config/meta");
URL url = classLoader.getResource("config/wmi/meta");
if(url == null) {
return null;
}

View File

@ -3,6 +3,8 @@ package com.loafle.overflow.probe.container.service;
import com.loafle.overflow.probe.container.crawler.Crawler;
import com.loafle.overflow.probe.container.crawler.config.Config;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ConfigService extends Service {
@ -10,9 +12,33 @@ public class ConfigService extends Service {
super(crawlers);
}
public boolean init(String crawlerName, Config config) throws Exception {
Crawler crawler = getCrawler(crawlerName);
return crawler.init(config);
public boolean init(List<Map<String, Config>> configs) throws Exception {
Crawler crawler;
Config config;
boolean ok = true;
List<Map.Entry<String, Config>> sensorIDs = new ArrayList<>();
Loop:
for (Map<String, Config> item : configs) {
for (Map.Entry<String, Config> entry : item.entrySet()) {
crawler = getCrawler(entry.getKey());
ok = crawler.init(entry.getValue());
if (!ok) {
break Loop;
}
sensorIDs.add(entry);
}
}
if (!ok) {
for (Map.Entry<String, Config> entry : sensorIDs) {
remove(entry.getKey(), entry.getValue().getId());
}
return false;
}
return true;
}
public boolean add(String crawlerName, Config config) throws Exception {