This commit is contained in:
insanity 2018-04-27 14:44:08 +09:00
parent 1f6933f8df
commit 8799462ec2
4 changed files with 64 additions and 3 deletions

View File

@ -144,6 +144,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
probe.setProbeKey(GenerateKey.getKey()); probe.setProbeKey(GenerateKey.getKey());
probe.setDomain(new Domain(apiKey.getDomain().getId())); probe.setDomain(new Domain(apiKey.getDomain().getId()));
probe.setAuthorizeMember(new Member(domainMember.getMember().getId())); probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
probe.setTargetCount(0);
probe.setStatus(new MetaProbeStatus((short) 1)); probe.setStatus(new MetaProbeStatus((short) 1));
String dispName = hostMap.get("name"); String dispName = hostMap.get("name");

View File

@ -44,4 +44,19 @@ public class CentralProbeService implements ProbeService {
public Probe modify(Probe probe) throws OverflowException { public Probe modify(Probe probe) throws OverflowException {
return this.probeDAO.save(probe); return this.probeDAO.save(probe);
} }
public Probe increaseTargetCount(Probe probe) {
Probe p = this.probeDAO.findOne(probe.getId());
p.setTargetCount(p.getTargetCount() + 1);
return this.probeDAO.save(p);
}
public Probe decreaseTargetCount(Probe probe) {
Probe p = this.probeDAO.findOne(probe.getId());
int count = p.getTargetCount();
if (count > 0) {
p.setTargetCount(count - 1);
}
return this.probeDAO.save(p);
}
} }

View File

@ -3,6 +3,7 @@ package com.loafle.overflow.central.module.sensor.service;
import com.loafle.overflow.central.commons.utils.PageUtil; import com.loafle.overflow.central.commons.utils.PageUtil;
import com.loafle.overflow.central.module.generator.service.SensorConfigGenerator; import com.loafle.overflow.central.module.generator.service.SensorConfigGenerator;
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.core.model.PageParams; import com.loafle.overflow.core.model.PageParams;
import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.domain.Domain;
@ -45,7 +46,12 @@ public class CentralSensorService implements SensorService {
@Autowired @Autowired
private SensorConfigGenerator sensorConfigGenerator; private SensorConfigGenerator sensorConfigGenerator;
public Sensor regist(Sensor sensor) { @Autowired
private CentralTargetService targetService;
@Transactional
public Sensor regist(Sensor sensor) throws OverflowException {
this.targetService.increaseSensorCount(sensor.getTarget());
return this.sensorDAO.save(sensor); return this.sensorDAO.save(sensor);
} }
@ -84,7 +90,9 @@ public class CentralSensorService implements SensorService {
return this.sensorDAO.findOne(Long.valueOf(id)); return this.sensorDAO.findOne(Long.valueOf(id));
} }
@Transactional
public void remove(Sensor sensor) throws OverflowException { public void remove(Sensor sensor) throws OverflowException {
this.targetService.decreaseSensorCount(sensor.getTarget());
this.sensorDAO.delete(sensor); this.sensorDAO.delete(sensor);
} }
@ -103,6 +111,7 @@ public class CentralSensorService implements SensorService {
@Transactional @Transactional
public Sensor registSensorConfig(Sensor sensor, List<SensorItem> sensorItemList, String etcJson) throws OverflowException { public Sensor registSensorConfig(Sensor sensor, List<SensorItem> sensorItemList, String etcJson) throws OverflowException {
this.targetService.increaseSensorCount(sensor.getTarget());
this.sensorDAO.save(sensor); this.sensorDAO.save(sensor);
for (SensorItem sensorItem : sensorItemList) { for (SensorItem sensorItem : sensorItemList) {

View File

@ -1,7 +1,11 @@
package com.loafle.overflow.central.module.target.service; package com.loafle.overflow.central.module.target.service;
import javax.transaction.Transactional;
import com.loafle.overflow.central.module.probe.service.CentralProbeService;
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.probe.Probe;
import com.loafle.overflow.model.target.Target; import com.loafle.overflow.model.target.Target;
import com.loafle.overflow.service.central.target.TargetService; import com.loafle.overflow.service.central.target.TargetService;
@ -16,16 +20,48 @@ public class CentralTargetService implements TargetService {
@Autowired @Autowired
private TargetDAO targetDAO; private TargetDAO targetDAO;
@Autowired
private CentralProbeService probeService;
public Target regist(Target target) throws OverflowException {
@Transactional
public Target regist(Target target, Probe probe) throws OverflowException {
this.probeService.increaseTargetCount(probe);
return this.targetDAO.save(target); return this.targetDAO.save(target);
} }
@Transactional
public void remove(Target target, Probe probe) throws OverflowException {
this.probeService.decreaseTargetCount(probe);
this.targetDAO.delete(target);
}
public Target read(String id) throws OverflowException { public Target read(String id) throws OverflowException {
return this.targetDAO.findOne(Long.valueOf(id)); return this.targetDAO.findOne(Long.valueOf(id));
} }
@Deprecated
public Target regist(Target target) throws OverflowException {
return this.targetDAO.save(target);
}
@Deprecated
public void remove(Target target) throws OverflowException { public void remove(Target target) throws OverflowException {
this.targetDAO.delete(target); this.targetDAO.delete(target);
} }
public Target increaseSensorCount(Target target) throws OverflowException {
Target t = this.targetDAO.findOne(target.getId());
t.setSensorCount(t.getSensorCount() + 1);
return this.targetDAO.save(t);
}
public Target decreaseSensorCount(Target target) throws OverflowException {
Target t = this.targetDAO.findOne(target.getId());
int count = t.getSensorCount();
if (t.getSensorCount() > 0) {
t.setSensorCount(count - 1);
}
return this.targetDAO.save(t);
}
} }