default sensor
This commit is contained in:
parent
8d61062e62
commit
5481c323f4
2
pom.xml
2
pom.xml
|
@ -50,7 +50,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.loafle.overflow</groupId>
|
<groupId>com.loafle.overflow</groupId>
|
||||||
<artifactId>commons-java</artifactId>
|
<artifactId>commons-java</artifactId>
|
||||||
<version>1.0.112-SNAPSHOT</version>
|
<version>1.0.113-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -16,4 +16,6 @@ public interface MetaDisplayItemMappingDAO extends JpaRepository<MetaDisplayItem
|
||||||
List<MetaDisplayItemMapping> findAllByMetaCrawlerMappingId(Long metaCrawlerMappingID);
|
List<MetaDisplayItemMapping> findAllByMetaCrawlerMappingId(Long metaCrawlerMappingID);
|
||||||
|
|
||||||
List<MetaDisplayItemMapping> findAllByMetaDisplayItemId(Long metaDisplayItemID);
|
List<MetaDisplayItemMapping> findAllByMetaDisplayItemId(Long metaDisplayItemID);
|
||||||
|
|
||||||
|
List<MetaDisplayItemMapping> findAllByMetaCrawlerMappingIdAndIsDefaultTrueAndIsRequiredTrue(Long metaDisplayItemID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,8 @@ public class CentralMetaDisplayItemMappingService implements MetaDisplayItemMapp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MetaDisplayItemMapping> readAllByMetaCrawlerMappingID(Long metaCrawlerMappingID) throws OverflowException {
|
public List<MetaDisplayItemMapping> readAllByMetaCrawlerMappingID(Long metaCrawlerMappingID)
|
||||||
|
throws OverflowException {
|
||||||
return this.metaDisplayItemMappingDAO.findAllByMetaCrawlerMappingId(metaCrawlerMappingID);
|
return this.metaDisplayItemMappingDAO.findAllByMetaCrawlerMappingId(metaCrawlerMappingID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,4 +38,9 @@ public class CentralMetaDisplayItemMappingService implements MetaDisplayItemMapp
|
||||||
public List<MetaDisplayItemMapping> readAll() throws OverflowException {
|
public List<MetaDisplayItemMapping> readAll() throws OverflowException {
|
||||||
return this.metaDisplayItemMappingDAO.findAll();
|
return this.metaDisplayItemMappingDAO.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<MetaDisplayItemMapping> readAllDefault(Long metaCrawlerMappingID) throws OverflowException {
|
||||||
|
return this.metaDisplayItemMappingDAO
|
||||||
|
.findAllByMetaCrawlerMappingIdAndIsDefaultTrueAndIsRequiredTrue(metaCrawlerMappingID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.loafle.overflow.central.module.sensor.service;
|
||||||
|
|
||||||
|
import com.loafle.overflow.model.sensor.Sensor;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service("SensorConfigService")
|
||||||
|
public class CentralSensorConfigService {
|
||||||
|
|
||||||
|
public void regist(Sensor sensor) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,16 @@
|
||||||
package com.loafle.overflow.central.module.sensor.service;
|
package com.loafle.overflow.central.module.sensor.service;
|
||||||
|
|
||||||
|
import com.loafle.overflow.central.module.meta.service.CentralMetaCrawlerMappingService;
|
||||||
|
import com.loafle.overflow.central.module.meta.service.CentralMetaDisplayItemMappingService;
|
||||||
import com.loafle.overflow.central.module.sensor.dao.SensorDAO;
|
import com.loafle.overflow.central.module.sensor.dao.SensorDAO;
|
||||||
|
import com.loafle.overflow.central.module.target.service.CentralTargetService;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
|
import com.loafle.overflow.model.meta.MetaCrawlerMapping;
|
||||||
import com.loafle.overflow.model.meta.MetaDisplayItemMapping;
|
import com.loafle.overflow.model.meta.MetaDisplayItemMapping;
|
||||||
import com.loafle.overflow.model.meta.MetaSensorStatus;
|
import com.loafle.overflow.model.meta.MetaSensorStatus;
|
||||||
import com.loafle.overflow.model.sensor.Sensor;
|
import com.loafle.overflow.model.sensor.Sensor;
|
||||||
import com.loafle.overflow.model.target.Target;
|
import com.loafle.overflow.model.target.Target;
|
||||||
import com.loafle.overflow.service.central.sensor.SensorService;
|
import com.loafle.overflow.service.central.sensor.SensorService;
|
||||||
import com.loafle.overflow.service.central.target.TargetService;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -23,12 +26,37 @@ public class CentralSensorService implements SensorService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SensorDAO sensorDAO;
|
private SensorDAO sensorDAO;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CentralSensorItemService sensorItemService;
|
private CentralSensorItemService sensorItemService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TargetService targetService;
|
private CentralTargetService targetService;
|
||||||
|
@Autowired
|
||||||
|
private CentralMetaCrawlerMappingService metaCrawlerMappingService;
|
||||||
|
@Autowired
|
||||||
|
private CentralMetaDisplayItemMappingService metaDisplayItemMappingService;
|
||||||
|
@Autowired
|
||||||
|
private CentralSensorConfigService sensorConfigService;
|
||||||
|
|
||||||
|
public void registDefaults(List<Target> targets) throws OverflowException {
|
||||||
|
for (Target target : targets) {
|
||||||
|
this.registDefault(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registDefault(Target target) throws OverflowException {
|
||||||
|
List<MetaCrawlerMapping> metaCrawlerMappings = this.metaCrawlerMappingService
|
||||||
|
.readAllByMetaTargetTypeKey(target.getMetaTargetType().getKey());
|
||||||
|
for (MetaCrawlerMapping metaCrawlerMapping : metaCrawlerMappings) {
|
||||||
|
if (metaCrawlerMapping.getDefault()) {
|
||||||
|
Sensor sensor = new Sensor();
|
||||||
|
sensor.setMetaCrawlerMapping(metaCrawlerMapping);
|
||||||
|
sensor.setInterval(metaCrawlerMapping.getDefaultInterval());
|
||||||
|
sensor.setTarget(target);
|
||||||
|
|
||||||
|
this.regist(sensor, this.metaDisplayItemMappingService.readAllDefault(metaCrawlerMapping.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,14 +72,17 @@ public class CentralSensorService implements SensorService {
|
||||||
sensor.setName(targetTypeName + " Sensor via " + crawlerName);
|
sensor.setName(targetTypeName + " Sensor via " + crawlerName);
|
||||||
}
|
}
|
||||||
sensor.setMetaSensorStatus(MetaSensorStatus.Enum.RUNNING.to());
|
sensor.setMetaSensorStatus(MetaSensorStatus.Enum.RUNNING.to());
|
||||||
Sensor s = this.sensorDAO.save(sensor);
|
Sensor retSensor = this.sensorDAO.save(sensor);
|
||||||
s.setItemCount(0);
|
retSensor.setItemCount(0);
|
||||||
this.targetService.increaseSensorCount(targetID);
|
this.targetService.increaseSensorCount(targetID);
|
||||||
|
|
||||||
for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) {
|
for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) {
|
||||||
this.sensorItemService.regist(s, metaDisplayItemMapping);
|
this.sensorItemService.regist(retSensor, metaDisplayItemMapping);
|
||||||
}
|
}
|
||||||
return s;
|
|
||||||
|
this.sensorConfigService.regist(retSensor);
|
||||||
|
|
||||||
|
return retSensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -61,7 +92,7 @@ public class CentralSensorService implements SensorService {
|
||||||
if (null == sensor) {
|
if (null == sensor) {
|
||||||
throw new OverflowException(String.format("ID[%d] of Sensor is not valid", sensorID));
|
throw new OverflowException(String.format("ID[%d] of Sensor is not valid", sensorID));
|
||||||
}
|
}
|
||||||
this.sensorItemService.readAllBySensorID(sensorID);
|
this.sensorItemService.removeAllBySensorID(sensorID);
|
||||||
for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) {
|
for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) {
|
||||||
this.sensorItemService.regist(sensor, metaDisplayItemMapping);
|
this.sensorItemService.regist(sensor, metaDisplayItemMapping);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.loafle.overflow.central.module.probe.service.CentralProbeService;
|
import com.loafle.overflow.central.module.probe.service.CentralProbeService;
|
||||||
|
import com.loafle.overflow.central.module.sensor.service.CentralSensorService;
|
||||||
import com.loafle.overflow.central.module.target.dao.TargetDAO;
|
import com.loafle.overflow.central.module.target.dao.TargetDAO;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.model.infra.Infra;
|
import com.loafle.overflow.model.infra.Infra;
|
||||||
|
@ -30,6 +31,8 @@ public class CentralTargetService implements TargetService {
|
||||||
private InfraService infraService;
|
private InfraService infraService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CentralProbeService probeService;
|
private CentralProbeService probeService;
|
||||||
|
@Autowired
|
||||||
|
private CentralSensorService sensorService;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Target regist(Target target, Long probeID) throws OverflowException {
|
public Target regist(Target target, Long probeID) throws OverflowException {
|
||||||
|
@ -105,6 +108,9 @@ public class CentralTargetService implements TargetService {
|
||||||
probe.setTargetCount(targetCount);
|
probe.setTargetCount(targetCount);
|
||||||
this.probeService.modify(probe);
|
this.probeService.modify(probe);
|
||||||
|
|
||||||
|
// FIXME : process asynchronously
|
||||||
|
this.sensorService.registDefaults(registered);
|
||||||
|
|
||||||
return registered;
|
return registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1212,11 +1212,7 @@ VALUES
|
||||||
( 1 , 'service.health.response_time' , 'Service Response Time' );
|
( 1 , 'service.health.response_time' , 'Service Response Time' );
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO public.meta_display_item_mapping
|
INSERT INTO public.meta_display_item_mapping ( id , meta_crawler_mapping_id , meta_display_item_id , is_default , priority , is_required , meta_display_item_category_id ) VALUES ( 1 , 252 , 1 , 'true' , 1 , 'true' , 1 );
|
||||||
( id , meta_crawler_mapping_id , meta_display_item_id , is_default , priority )
|
|
||||||
VALUES
|
|
||||||
( 1 , 252 , 1 , 'true' , 1 );
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO public.meta_collection_item
|
INSERT INTO public.meta_collection_item
|
||||||
( id , key , item , item_class )
|
( id , key , item , item_class )
|
||||||
|
|
Loading…
Reference in New Issue
Block a user