SensorConfigService
This commit is contained in:
parent
d8c8101dba
commit
fb239e2249
2
pom.xml
2
pom.xml
|
@ -50,7 +50,7 @@
|
|||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>commons-java</artifactId>
|
||||
<version>1.0.113-SNAPSHOT</version>
|
||||
<version>1.0.114-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -1,13 +1,127 @@
|
|||
package com.loafle.overflow.central.module.sensor.service;
|
||||
|
||||
import com.loafle.overflow.model.sensor.Sensor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.model.infra.Infra;
|
||||
import com.loafle.overflow.model.infra.InfraHost;
|
||||
import com.loafle.overflow.model.infra.InfraHostIP;
|
||||
import com.loafle.overflow.model.infra.InfraHostPort;
|
||||
import com.loafle.overflow.model.infra.InfraService;
|
||||
import com.loafle.overflow.model.meta.MetaCollectionItem;
|
||||
import com.loafle.overflow.model.meta.MetaCollectionItemMapping;
|
||||
import com.loafle.overflow.model.meta.MetaCryptoType;
|
||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||
import com.loafle.overflow.model.sensor.Sensor;
|
||||
import com.loafle.overflow.model.sensor.SensorItem;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfigConnection;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfigCrawler;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfigItems;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfigSchedule;
|
||||
import com.loafle.overflow.service.central.meta.MetaCollectionItemMappingService;
|
||||
|
||||
import org.hibernate.mapping.Array;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service("SensorConfigService")
|
||||
public class CentralSensorConfigService {
|
||||
|
||||
public void regist(Sensor sensor) {
|
||||
@Autowired
|
||||
MetaCollectionItemMappingService metaCollectionItemMappingService;
|
||||
@Autowired
|
||||
CentralSensorItemService sensorItemService;
|
||||
|
||||
public SensorConfig regist(Sensor sensor) throws OverflowException {
|
||||
if (null == sensor.getId()) {
|
||||
throw new OverflowException(String.format("ID[%s] of Sensor is not valid", sensor.getId()));
|
||||
}
|
||||
SensorConfig sensorConfig = new SensorConfig();
|
||||
sensorConfig.setSensorID(sensor.getId());
|
||||
sensorConfig.setCrawler(this.configCrawler(sensorConfig, sensor));
|
||||
sensorConfig.setConnection(this.configConnection(sensorConfig, sensor));
|
||||
sensorConfig.setSchedule(this.configSchedule(sensorConfig, sensor));
|
||||
sensorConfig.setItems(this.configItems(sensorConfig, sensor));
|
||||
|
||||
return sensorConfig;
|
||||
}
|
||||
}
|
||||
|
||||
private SensorConfigCrawler configCrawler(SensorConfig config, Sensor sensor) throws OverflowException {
|
||||
if (null == sensor.getMetaCrawlerMapping() || null == sensor.getMetaCrawlerMapping().getMetaCrawler()
|
||||
|| null == sensor.getMetaCrawlerMapping().getMetaCrawlerContainer()) {
|
||||
throw new OverflowException(String.format("ID[%s] of Sensor is not valid", sensor.getId()));
|
||||
}
|
||||
SensorConfigCrawler sensorConfigCrawler = new SensorConfigCrawler();
|
||||
sensorConfigCrawler.setMetaCrawlerContainerKey(sensor.getMetaCrawlerMapping().getMetaCrawlerContainer().getKey());
|
||||
sensorConfigCrawler.setMetaCrawlerKey(sensor.getMetaCrawlerMapping().getMetaCrawler().getKey());
|
||||
|
||||
return sensorConfigCrawler;
|
||||
}
|
||||
|
||||
private SensorConfigConnection configConnection(SensorConfig config, Sensor sensor) throws OverflowException {
|
||||
if (null == sensor.getTarget() || null == sensor.getTarget().getInfra()
|
||||
|| null == sensor.getTarget().getInfra().getMetaInfraType()) {
|
||||
throw new OverflowException(String.format("ID[%s] of Sensor is not valid", sensor.getId()));
|
||||
}
|
||||
Infra infra = sensor.getTarget().getInfra();
|
||||
MetaInfraType metaInfraType = infra.getMetaInfraType();
|
||||
InfraHostIP infraHostIP = null;
|
||||
;
|
||||
InfraHostPort infraHostPort = null;
|
||||
MetaCryptoType metaCryptoType = null;
|
||||
;
|
||||
|
||||
if (metaInfraType.getKey() == "HOST") {
|
||||
infraHostIP = ((InfraHost) infra).getInfraHostIPs().get(0);
|
||||
} else if (metaInfraType.getKey() == "SERVICE") {
|
||||
infraHostIP = ((InfraService) infra).getInfraHostPort().getInfraHostIP();
|
||||
infraHostPort = ((InfraService) infra).getInfraHostPort();
|
||||
metaCryptoType = ((InfraService) infra).getMetaCryptoType();
|
||||
} else {
|
||||
throw new OverflowException(String.format("ID[%s] of Sensor is not valid", sensor.getId()));
|
||||
}
|
||||
|
||||
SensorConfigConnection sensorConfigConnection = new SensorConfigConnection();
|
||||
sensorConfigConnection.setMetaIPTypeKey(infraHostIP.getMetaIPType().getKey());
|
||||
sensorConfigConnection.setIp(infraHostIP.getAddress());
|
||||
if (null != infraHostPort) {
|
||||
sensorConfigConnection.setMetaPortTypeKey(infraHostPort.getMetaPortType().getKey());
|
||||
sensorConfigConnection.setPort(infraHostPort.getPort());
|
||||
}
|
||||
if (null != metaCryptoType) {
|
||||
sensorConfigConnection.setMetaCryptoTypeKey(metaCryptoType.getKey());
|
||||
}
|
||||
|
||||
return sensorConfigConnection;
|
||||
}
|
||||
|
||||
private SensorConfigSchedule configSchedule(SensorConfig config, Sensor sensor) throws OverflowException {
|
||||
Integer interval = null != sensor.getInterval() ? sensor.getInterval()
|
||||
: sensor.getMetaCrawlerMapping().getDefaultInterval();
|
||||
SensorConfigSchedule sensorConfigSchedule = new SensorConfigSchedule();
|
||||
sensorConfigSchedule.setInterval(interval);
|
||||
return sensorConfigSchedule;
|
||||
}
|
||||
|
||||
private SensorConfigItems configItems(SensorConfig config, Sensor sensor) throws OverflowException {
|
||||
List<SensorItem> sensorItems = this.sensorItemService.readAllBySensorID(sensor.getId());
|
||||
if (null == sensorItems || sensorItems.size() == 0) {
|
||||
throw new OverflowException(String.format("ID[%s] of Sensor has no SensorItem", sensor.getId()));
|
||||
}
|
||||
List<MetaCollectionItem> metaCollectionItems = new ArrayList<>();
|
||||
for (SensorItem sensorItem : sensorItems) {
|
||||
List<MetaCollectionItemMapping> metaCollectionItemMappings = this.metaCollectionItemMappingService
|
||||
.readAllByMetaDisplayItemMappingID(sensorItem.getMetaDisplayItemMapping().getId());
|
||||
for (MetaCollectionItemMapping metaCollectionItemMapping : metaCollectionItemMappings) {
|
||||
metaCollectionItems.add(metaCollectionItemMapping.getMetaCollectionItem());
|
||||
}
|
||||
}
|
||||
|
||||
SensorConfigItems sensorConfigItems = new SensorConfigItems();
|
||||
sensorConfigItems.setMetaCollectionItems(metaCollectionItems);
|
||||
|
||||
return sensorConfigItems;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user