This commit is contained in:
crusader 2018-04-24 22:23:44 +09:00
parent 37cac2b0d3
commit a5330571f9
3 changed files with 38 additions and 30 deletions

View File

@ -10,6 +10,7 @@ import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.interfaces.Service; import com.loafle.overflow.core.interfaces.Service;
import com.loafle.overflow.crawler.Crawler; import com.loafle.overflow.crawler.Crawler;
import com.loafle.overflow.model.sensorconfig.SensorConfig; import com.loafle.overflow.model.sensorconfig.SensorConfig;
import com.loafle.overflow.service.container.CrawlerService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -19,59 +20,60 @@ import org.springframework.beans.factory.annotation.Autowired;
* CrawlerService * CrawlerService
*/ */
@RPCService("CrawlerService") @RPCService("CrawlerService")
public class CrawlerService implements Service { public class ContainerCrawlerService implements Service, CrawlerService {
private static final Logger logger = LoggerFactory.getLogger(CrawlerService.class); private static final Logger logger = LoggerFactory.getLogger(ContainerCrawlerService.class);
@Autowired @Autowired
private SensorConfigService sensorConfigService; private SensorConfigService sensorConfigService;
@Resource(name=Container.CRAWLERS) @Resource(name = Container.CRAWLERS)
private Map<String, Crawler> crawlers; private Map<String, Crawler> crawlers;
@Override @Override
public void initService() throws Exception { public void initService() throws Exception {
if (null == this.crawlers) { if (null == this.crawlers) {
throw new Exception("Crawlers is not set"); throw new Exception("Crawlers is not set");
} }
} }
@Override
public void startService() throws Exception {
}
@Override
public void stopService() {
}
@Override @Override
public void destroyService() { public void startService() throws Exception {
}
}
@Override
public void stopService() {
}
@Override
public void destroyService() {
}
@Override
public void Auth(String crawlerName, Map<String, Object> authInfoMap) throws OverflowException { public void Auth(String crawlerName, Map<String, Object> authInfoMap) throws OverflowException {
Crawler crawler = this.crawlers.get(crawlerName); Crawler crawler = this.crawlers.get(crawlerName);
if (null == crawler) { if (null == crawler) {
throw new OverflowException(String.format("There is no crawler[%s]", crawlerName), null); throw new OverflowException(String.format("There is no crawler[%s]", crawlerName), null);
} }
crawler.auth(authInfoMap); crawler.auth(authInfoMap);
} }
@Override
public Map<String, String> Get(String sensorConfigID) throws OverflowException { public Map<String, String> Get(String sensorConfigID) throws OverflowException {
SensorConfig sensorConfig = this.sensorConfigService.getSensorConfig(sensorConfigID); SensorConfig sensorConfig = this.sensorConfigService.getSensorConfig(sensorConfigID);
if (null == sensorConfig) { if (null == sensorConfig) {
throw new OverflowException(String.format("There is no sensor config for id[%s]", sensorConfigID), null); throw new OverflowException(String.format("There is no sensor config for id[%s]", sensorConfigID), null);
} }
String crawlerName = sensorConfig.getCrawler().getName(); String crawlerName = sensorConfig.getCrawler().getName();
Crawler crawler = this.crawlers.get(crawlerName); Crawler crawler = this.crawlers.get(crawlerName);
if (null == crawler) { if (null == crawler) {
throw new OverflowException(String.format("There is no crawler[%s] for id[%s]", crawlerName, sensorConfigID), null); throw new OverflowException(String.format("There is no crawler[%s] for id[%s]", crawlerName, sensorConfigID), null);
} }
return crawler.get(sensorConfig); return crawler.get(sensorConfig);
} }
} }

View File

@ -3,12 +3,13 @@ package com.loafle.overflow.container.service;
import com.loafle.overflow.core.annotation.RPCService; import com.loafle.overflow.core.annotation.RPCService;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.interfaces.Service; import com.loafle.overflow.core.interfaces.Service;
import com.loafle.overflow.service.container.ProbeService;
/** /**
* ProbeService * ProbeService
*/ */
@RPCService("ProbeService") @RPCService("ProbeService")
public class ProbeService implements Service { public class ContainerProbeService implements Service, ProbeService {
@Override @Override
public void initService() throws Exception { public void initService() throws Exception {

View File

@ -8,6 +8,7 @@ import com.loafle.overflow.core.annotation.RPCService;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.interfaces.Service; import com.loafle.overflow.core.interfaces.Service;
import com.loafle.overflow.model.sensorconfig.SensorConfig; import com.loafle.overflow.model.sensorconfig.SensorConfig;
import com.loafle.overflow.service.container.SensorConfigService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -16,8 +17,8 @@ import org.slf4j.LoggerFactory;
* SensorConfigService * SensorConfigService
*/ */
@RPCService("SensorConfigService") @RPCService("SensorConfigService")
public class SensorConfigService implements Service { public class ContainerSensorConfigService implements Service, SensorConfigService {
private static final Logger logger = LoggerFactory.getLogger(SensorConfigService.class); private static final Logger logger = LoggerFactory.getLogger(ContainerSensorConfigService.class);
private Map<String, SensorConfig> sensorConfigs; private Map<String, SensorConfig> sensorConfigs;
@ -45,6 +46,7 @@ public class SensorConfigService implements Service {
return this.sensorConfigs.get(configID); return this.sensorConfigs.get(configID);
} }
@Override
public void InitConfig(List<SensorConfig> sensorConfigs) throws OverflowException { public void InitConfig(List<SensorConfig> sensorConfigs) throws OverflowException {
if (null == sensorConfigs || 0 == sensorConfigs.size()) { if (null == sensorConfigs || 0 == sensorConfigs.size()) {
return; return;
@ -56,6 +58,7 @@ public class SensorConfigService implements Service {
logger.debug("Sensor configs[%d] were added", sensorConfigs.size()); logger.debug("Sensor configs[%d] were added", sensorConfigs.size());
} }
@Override
public void AddConfig(SensorConfig sensorConfig) throws OverflowException { public void AddConfig(SensorConfig sensorConfig) throws OverflowException {
if (null == sensorConfig) { if (null == sensorConfig) {
throw new OverflowException("Sensor config is not valid", null); throw new OverflowException("Sensor config is not valid", null);
@ -71,7 +74,8 @@ public class SensorConfigService implements Service {
logger.debug("Sensor config[%s] was added", configID); logger.debug("Sensor config[%s] was added", configID);
} }
public void UddConfig(SensorConfig sensorConfig) throws OverflowException { @Override
public void UpdateConfig(SensorConfig sensorConfig) throws OverflowException {
if (null == sensorConfig) { if (null == sensorConfig) {
throw new OverflowException("Sensor config is not valid", null); throw new OverflowException("Sensor config is not valid", null);
} }
@ -87,7 +91,8 @@ public class SensorConfigService implements Service {
logger.debug("Sensor config[%s] was updated", configID); logger.debug("Sensor config[%s] was updated", configID);
} }
public void RddConfig(String configID) throws OverflowException { @Override
public void RemoveConfig(String configID) throws OverflowException {
if (!this.sensorConfigs.containsKey(configID)) { if (!this.sensorConfigs.containsKey(configID)) {
throw new OverflowException(String.format("Sensor config[%s] is not exist", configID), null); throw new OverflowException(String.format("Sensor config[%s] is not exist", configID), null);
} }