diff --git a/pom.xml b/pom.xml index 3e5dfa5..6fb19e1 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ com.loafle.overflow commons-java - 1.0.14-SNAPSHOT + 1.0.18-SNAPSHOT diff --git a/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java b/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java index b46612c..5964e41 100644 --- a/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java +++ b/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java @@ -22,7 +22,7 @@ public class PageUtil { if (pageParams.getSortDirection().isEmpty()) pageParams.setSortDirection("descending"); - return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(), + return PageRequest.of(pageParams.getPageNo(), pageParams.getCountPerPage(), new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol())); } } diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java index 123a43b..5e2a74d 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java @@ -19,43 +19,7 @@ import com.loafle.overflow.service.central.sensor.SensorItemService; @Service("SensorConfigGenerator") public class SensorConfigGenerator { - @Autowired - private SensorItemService sensorItemService; - - @Autowired - private InfraService infraService; - - @Autowired - private InfraHostGenerator infraHostGenerator; - - @Autowired - private InfraServiceGenerator infraServiceGenerator; - public String generate(Sensor sensor) throws Exception { - PageParams pageParams = new PageParams(); - pageParams.setPageNo(0); - pageParams.setCountPerPage(Integer.MAX_VALUE); - pageParams.setSortCol("id"); - pageParams.setSortDirection("descending"); - Page dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams); - - List sensorItems = dbItemList.getContent(); - - if (sensorItems.size() <= 0) { - return ""; - } - Sensor dbSensor = sensorItems.get(0).getSensor(); - - Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId()); - - // 7 = Infra OS Service - if (infra.getMetaInfraType().getId() == 7) { - return this.infraServiceGenerator.process(dbSensor, sensorItems, infra); - } - if (infra.getMetaInfraType().getId() == 2) { - return this.infraHostGenerator.process(dbSensor, sensorItems, infra); - } - return null; } diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java index ba80aa2..7b26807 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java @@ -3,10 +3,8 @@ package com.loafle.overflow.central.module.infra.service; import com.loafle.overflow.central.commons.utils.PageUtil; import com.loafle.overflow.central.module.infra.dao.InfraDAO; import com.loafle.overflow.core.model.PageParams; -import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.central.module.sensor.dao.SensorDAO; -import com.loafle.overflow.model.target.Target; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.infra.Infra; import com.loafle.overflow.service.central.infra.InfraService; @@ -17,9 +15,6 @@ import org.springframework.stereotype.Service; import java.util.List; -/** - * Created by insanity on 17. 6. 28. - */ @Service("InfraService") public class CentralInfraService implements InfraService { @@ -38,8 +33,7 @@ public class CentralInfraService implements InfraService { } public Infra read(Long id) throws OverflowException { - Infra infra = this.infraDAO.findById(id).get(); - return infra; + return this.infraDAO.findById(id).get(); } public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { @@ -57,25 +51,4 @@ public class CentralInfraService implements InfraService { return infraList; } - public List readAllTargetByDomainID(Long domainID) throws OverflowException { - - List probes = this.probeService.readAllByDomainID(domainID); - - if (probes == null || probes.size() <= 0) { - throw new OverflowException("ProbeNotFoundException", new Throwable()); - } - - return this.infraDAO.findAllTargetByProbeIn(probes); - } - - public List readAllTargetByProbes(List probes) throws OverflowException { - return this.infraDAO.findAllTargetByProbeIn(probes); - // return null; - } - - public Infra readByTargetID(Long targetID) throws OverflowException { - // return this.infraDAO.findByTargetId(targetID); - return null; - } - } diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceService.java index 0574087..7b1d48b 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceService.java @@ -4,6 +4,7 @@ import com.loafle.overflow.central.module.infra.dao.InfraServiceDAO; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.infra.InfraService; import com.loafle.overflow.service.central.infra.InfraServiceService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,15 +17,15 @@ public class CentralInfraServiceService implements InfraServiceService { @Autowired InfraServiceDAO infraServiceDAO; - public InfraService regist(InfraService infraService) throws OverflowException { + public com.loafle.overflow.model.infra.InfraService regist(InfraService infraService) throws OverflowException { return this.infraServiceDAO.save(infraService); } - public InfraService read(Long id) throws OverflowException { + public com.loafle.overflow.model.infra.InfraService read(Long id) throws OverflowException { return this.infraServiceDAO.findById(id).get(); } - public InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType) + public com.loafle.overflow.model.infra.InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType) throws OverflowException { return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, portType); } diff --git a/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java b/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java index f58468e..0230a28 100644 --- a/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java +++ b/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java @@ -1,7 +1,6 @@ package com.loafle.overflow.central.module.member.service; import com.loafle.overflow.core.annotation.WebappAPI; -import com.loafle.overflow.central.commons.utils.SessionMetadata; import com.loafle.overflow.central.module.member.dao.MemberDAO; import com.loafle.overflow.core.exception.OverflowException; @@ -168,13 +167,24 @@ public class CentralMemberService implements MemberService { return this.modify(member); } + public List readAllByProbeKey(String probeKey) throws OverflowException { + + Probe probe = this.probeService.readByProbeKey(probeKey); + + if (probe == null) { + return null; + } + + return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId()); + } + + public void signout(Member member) { // Todo websocket session remove } @WebappAPI public Member modify(Member member, String pw) throws OverflowException { - String email = SessionMetadata.getTargetID(); Member preMember = this.memberDAO.findByEmail(member.getEmail()); if (null == preMember || 0 >= preMember.getId()) { @@ -246,21 +256,10 @@ public class CentralMemberService implements MemberService { @WebappAPI public void withdrawal(Long memberId) throws OverflowException { - String email = SessionMetadata.getTargetID(); - + // String email = SessionMetadata.getTargetID(); // Todo DB delete? } - public List readAllByProbeKey(String probeKey) throws OverflowException { - - Probe probe = this.probeService.readByProbeKey(probeKey); - - if (probe == null) { - return null; - } - - return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId()); - } public List readAllByApiKey(String apikey) throws OverflowException { diff --git a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeTaskDAO.java b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeTaskDAO.java deleted file mode 100644 index d7eb78b..0000000 --- a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeTaskDAO.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.loafle.overflow.central.module.probe.dao; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -import com.loafle.overflow.model.probe.ProbeTask; - -/** - * Created by snoop on 17. 6. 26. - */ -@Repository -public interface ProbeTaskDAO extends JpaRepository { - List findAllByProbeId(Long probeId); -} diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java index bced7ac..031e486 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java @@ -10,15 +10,16 @@ import com.loafle.overflow.service.central.probe.ProbeHostService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -/** - * Created by snoop on 17. 8. 21. - */ @Service("ProbeHostService") public class CentralProbeHostService implements ProbeHostService { @Autowired private ProbeHostDAO probeHostDAO; + public ProbeHost regist(ProbeHost probeHost) throws OverflowException { + return this.probeHostDAO.save(probeHost); + } + public ProbeHost read(Long id) throws OverflowException { return this.probeHostDAO.findById(id).get(); } @@ -27,10 +28,6 @@ public class CentralProbeHostService implements ProbeHostService { return this.probeHostDAO.findByProbeId(probeID); } - public ProbeHost regist(ProbeHost probeHost) throws OverflowException { - return this.probeHostDAO.save(probeHost); - } - public List readAllByDomainID(Long domainID) throws OverflowException { return this.probeHostDAO.findAllByProbeDomainId(domainID); } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java index 6a00c94..1db2fb1 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java @@ -12,9 +12,7 @@ import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; -/** - * Created by snoop on 17. 6. 28. - */ + @Service("ProbeService") public class CentralProbeService implements ProbeService { @@ -27,10 +25,6 @@ public class CentralProbeService implements ProbeService { return this.probeDAO.save(probe); } - public List regist(List probes) throws OverflowException { - return (List) this.probeDAO.saveAll(probes); - } - public List readAllByDomainID(Long domainID) throws OverflowException { List probes = this.probeDAO.findAllByDomainIdOrderByIdDesc(domainID); return probes; @@ -39,11 +33,7 @@ public class CentralProbeService implements ProbeService { public Probe read(Long id) throws OverflowException { return this.probeDAO.findById(id).get(); } - - public Probe readByProbeKey(String probeKey) throws OverflowException { - return this.probeDAO.findByProbeKey(probeKey); - } - + public Probe modify(Probe probe) throws OverflowException { return this.probeDAO.save(probe); } @@ -53,14 +43,18 @@ public class CentralProbeService implements ProbeService { return true; } - public Probe increaseTargetCount(Probe probe) { - Probe p = this.probeDAO.findById(probe.getId()).get(); + public Probe readByProbeKey(String probeKey) throws OverflowException { + return this.probeDAO.findByProbeKey(probeKey); + } + + public Probe increaseTargetCount(Long id) throws OverflowException { + Probe p = this.probeDAO.findById(id).get(); p.setTargetCount(p.getTargetCount() + 1); return this.probeDAO.save(p); } - public Probe decreaseTargetCount(Probe probe) { - Probe p = this.probeDAO.findById(probe.getId()).get(); + public Probe decreaseTargetCount(Long id) throws OverflowException { + Probe p = this.probeDAO.findById(id).get(); int count = p.getTargetCount(); if (count > 0) { p.setTargetCount(count - 1); @@ -68,11 +62,6 @@ public class CentralProbeService implements ProbeService { return this.probeDAO.save(p); } - public Probe modifyDisplayName(Long probeId, String displayName) { - Probe probe = this.probeDAO.findById(probeId).get(); - probe.setDisplayName(displayName); - return this.probeDAO.save(probe); - } public void onConnect(String probeKey, String connectAddress) throws OverflowException { Probe probe = this.probeDAO.findByProbeKey(probeKey); @@ -91,4 +80,5 @@ public class CentralProbeService implements ProbeService { messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onDisconnect", probe); } + } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java deleted file mode 100644 index e13f81d..0000000 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.loafle.overflow.central.module.probe.service; - -import com.loafle.overflow.central.module.probe.dao.ProbeTaskDAO; -import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.probe.ProbeTask; -import com.loafle.overflow.service.central.probe.ProbeTaskService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * Created by snoop on 17. 6. 28. - */ -@Service("ProbeTaskService") -public class CentralProbeTaskService implements ProbeTaskService { - - @Autowired - private ProbeTaskDAO probeTaskDAO; - - public ProbeTask regist(ProbeTask probeTask) throws OverflowException { - return this.probeTaskDAO.save(probeTask); - } - - public List readAllByProbeID(Long probeID) throws OverflowException { - return this.probeTaskDAO.findAllByProbeId(probeID); - } -} diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java index 312c0a8..cd718f5 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java @@ -20,4 +20,6 @@ public interface SensorDAO extends JpaRepository { List findAllByTargetId(Long targetID); Page findAllByTargetIn(List targets, Pageable pageable); + + Page findAllByTargetInfraId(Long infraID, Pageable pageable); } diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java index 30e1bdc..172e671 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java @@ -30,7 +30,7 @@ public class CentralSensorItemService implements SensorItemService { @Transactional public SensorItem regist(SensorItem sensorItem) throws OverflowException { Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get(); - s.setItemCount((short) (s.getItemCount() + 1)); + s.setItemCount(s.getItemCount() + 1); this.sensorDAO.save(s); return this.sensorItemDAO.save(sensorItem); } @@ -38,7 +38,7 @@ public class CentralSensorItemService implements SensorItemService { @Transactional public boolean registAll(List sensorItemList) throws OverflowException { Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get(); - s.setItemCount((short) sensorItemList.size()); + s.setItemCount(sensorItemList.size()); this.sensorDAO.save(s); this.sensorItemDAO.saveAll(sensorItemList); return true; @@ -55,7 +55,7 @@ public class CentralSensorItemService implements SensorItemService { @Transactional public void remove(SensorItem sensorItem) throws OverflowException { Sensor s = sensorItem.getSensor(); - s.setItemCount((short) (s.getItemCount() - 1)); + s.setItemCount(s.getItemCount() - 1); this.sensorDAO.save(s); this.sensorItemDAO.delete(sensorItem); } diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java index dc41251..20d4daa 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java @@ -5,13 +5,8 @@ import com.loafle.overflow.central.module.generator.service.SensorConfigGenerato import com.loafle.overflow.central.module.sensor.dao.SensorDAO; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.model.PageParams; -import com.loafle.overflow.model.meta.MetaSensorStatus; -import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.sensor.SensorItem; -import com.loafle.overflow.model.target.Target; -import com.loafle.overflow.service.central.infra.InfraService; -import com.loafle.overflow.service.central.probe.ProbeService; import com.loafle.overflow.service.central.sensor.SensorItemService; import com.loafle.overflow.service.central.sensor.SensorService; import com.loafle.overflow.service.central.target.TargetService; @@ -32,12 +27,6 @@ public class CentralSensorService implements SensorService { @Autowired SensorDAO sensorDAO; - @Autowired - private ProbeService probeService; - - @Autowired - private InfraService infraService; - @Autowired private SensorItemService sensorItemService; @@ -48,72 +37,61 @@ public class CentralSensorService implements SensorService { private TargetService targetService; @Transactional - public Sensor regist(Sensor sensor) throws OverflowException { - this.targetService.increaseSensorCount(sensor.getTarget()); + public Sensor regist(Sensor sensor, Long targetID) throws OverflowException { + this.targetService.increaseSensorCount(targetID); return this.sensorDAO.save(sensor); } + public Sensor read(Long id) throws OverflowException { + return this.sensorDAO.findById(id).get(); + } + + @Transactional + public void remove(Long id, Long targertID) throws OverflowException { + this.targetService.decreaseSensorCount(targertID); + this.sensorDAO.deleteById(id); + } + + public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { + // FIXME: NOT IMPLEMENTS + return null; + } + public Page readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { - - List probeList = this.probeService.readAllByDomainID(domainID); - - if (probeList == null || probeList.size() <= 0) { - throw new OverflowException("", new Throwable()); - } - - List targetList = this.infraService.readAllTargetByProbes(probeList); - - if (targetList == null || targetList.size() <= 0) { - throw new OverflowException("", new Throwable()); - } - - return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams)); + // FIXME: NOT IMPLEMENTS + return null; } public Page readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException { - // Infra dbInfra = this.infraService.read(infraID); - // if (dbInfra == null) { - // throw new OverflowException("", new Throwable()); - // } - // return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), - // PageUtil.getPageRequest(pageParams)); - return null; + return this.sensorDAO.findAllByTargetInfraId(infraID, PageUtil.getPageRequest(pageParams)); } public Page readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException { return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams)); } - public Sensor read(Long id) throws OverflowException { - return this.sensorDAO.findById(Long.valueOf(id)).get(); + @Override + public Sensor increaseSensorItemCount(Long id) throws OverflowException { + Sensor s = this.sensorDAO.findById(id).get(); + s.setItemCount(s.getItemCount() + 1); + return this.sensorDAO.save(s); } - @Transactional - public void remove(Long sensorID) throws OverflowException { - Sensor sensor = this.sensorDAO.findById(sensorID).get(); - this.targetService.decreaseSensorCount(sensor.getTarget()); - this.sensorDAO.delete(sensor); - } - - public Sensor start(Long sensorID) throws OverflowException { - Sensor sensor = this.sensorDAO.findById(sensorID).get(); - MetaSensorStatus status = new MetaSensorStatus((short) 1); - sensor.setMetaSensorStatus(status); - return this.sensorDAO.save(sensor); - } - - public Sensor stop(Long sensorID) throws OverflowException { - Sensor sensor = this.sensorDAO.findById(sensorID).get(); - MetaSensorStatus status = new MetaSensorStatus((short) 2); - sensor.setMetaSensorStatus(status); - return this.sensorDAO.save(sensor); + @Override + public Sensor decreaseSensorItemCount(Long id) throws OverflowException { + Sensor s = this.sensorDAO.findById(id).get(); + int count = s.getItemCount(); + if (count > 0) { + s.setItemCount(count - 1); + } + return this.sensorDAO.save(s); } @Transactional public Sensor registSensorConfig(Sensor sensor, List sensorItemList, String etcJson) throws OverflowException { - this.targetService.increaseSensorCount(sensor.getTarget()); + this.targetService.increaseSensorCount(sensor.getTarget().getId()); this.sensorDAO.save(sensor); for (SensorItem sensorItem : sensorItemList) { @@ -132,9 +110,4 @@ public class CentralSensorService implements SensorService { throw new OverflowException("", new Throwable()); } } - - // public List readAllByTarget(Target target, PageParams pageParams) { - // return this.sensorDAO.findAllByTarget(target, - // PageUtil.getPageRequest(pageParams)); - // } -} +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java deleted file mode 100644 index e2be40c..0000000 --- a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java +++ /dev/null @@ -1,237 +0,0 @@ -// package com.loafle.overflow.central.module.target.service; - -// import com.loafle.overflow.central.module.infra.service.*; -// import com.loafle.overflow.core.exception.OverflowException; -// import com.loafle.overflow.core.type.PortType; -// import com.loafle.overflow.model.discovery.Host; -// import com.loafle.overflow.model.discovery.Port; - -// import com.loafle.overflow.model.infra.*; -// import com.loafle.overflow.model.meta.MetaInfraType; -// import com.loafle.overflow.model.meta.MetaInfraVendor; -// import com.loafle.overflow.model.probe.Probe; -// import com.loafle.overflow.model.target.Target; -// import com.loafle.overflow.service.central.target.*; -// import org.springframework.beans.factory.annotation.Autowired; -// import org.springframework.stereotype.Service; - -// import javax.transaction.Transactional; -// import java.util.List; - -// /** -// * Created by snoop on 17. 6. 28. -// */ -// @Service("TargetDiscoveryService") -// public class CentralTargetDiscoveryService implements TargetDiscoveryService -// { - -// @Autowired -// private TargetService targetService; - -// @Autowired -// private CentralInfraMachineService infraMachineService; - -// @Autowired -// private CentralInfraOSService infraOSService; - -// @Autowired -// private CentralInfraHostService infraHostService; - -// // @Autowired -// // private CentralInfraService infraService; - -// @Autowired -// private CentralInfraOSPortService infraOSPortService; - -// @Autowired -// private CentralInfraServiceService infraServiceService; - -// @Transactional -// public boolean saveAllTarget(List hosts, Probe probe) throws -// OverflowException { - -// InfraHost infraHost = null; - -// for (Host host : hosts) { - -// infraHost = this.createAndReadHost(host, probe); - -// this.createPort(infraHost, host, probe); - -// } -// return true; -// } - -// private void createService(InfraHost infraHost, Port port, Probe probe) -// throws OverflowException { - -// MetaInfraType typeService = new MetaInfraType(7); - -// String portType = "UDP"; - -// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP -// || port.getPortType() == null) { -// portType = "TCP"; -// } - -// if (port.getServiceList() == null) { -// return; -// } - -// // for(String key : port.getServices().keySet()) { -// for (com.loafle.overflow.model.discovery.Service service : -// port.getServiceList()) { - -// // com.loafle.overflow.module.discovery.model.Service service = -// // port.getServices().get(key); - -// InfraService dbInfraService = this.infraServiceService -// .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), -// portType); - -// if (dbInfraService != null) { -// if (service.isTarget() && dbInfraService.getTarget() == null) { -// Target targetService = new Target(); -// targetService.setDisplayName(service.getServiceName()); -// this.targetService.regist(targetService, probe); -// dbInfraService.setTarget(targetService); -// this.infraServiceService.regist(dbInfraService); -// } -// continue; -// } - -// InfraService infraService = new InfraService(); -// infraService.setInfraHost(infraHost); -// infraService.setPort(port.getPortNumber()); -// infraService.setPortType(portType); -// infraService.setMetaInfraType(typeService); -// infraService.setProbe(probe); - -// if (port.getPortType() == PortType.TLS) { -// infraService.setTlsType(true); -// } -// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); - -// if (service.isTarget()) { -// Target targetService = new Target(); -// targetService.setDisplayName(service.getServiceName()); -// this.targetService.regist(targetService, probe); -// infraService.setTarget(targetService); -// } - -// this.infraServiceService.regist(infraService); - -// } - -// } - -// private void createPort(InfraHost infraHost, Host host, Probe probe) throws -// OverflowException { - -// // if(host.getPorts() == null) { -// // return; -// // } - -// String portType = "UDP"; - -// MetaInfraType typePort = new MetaInfraType(6); - -// InfraOS infraOS = infraHost.getInfraOS(); - -// // for( String key: host.getPorts().keySet()) { - -// if (host.getPortList() == null) { -// return; -// } - -// for (Port port : host.getPortList()) { -// // Port port = host.getPorts().get(key); - -// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) -// { -// portType = "TCP"; -// } - -// InfraOSPort dbInfraOSPort = -// this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), -// port.getPortNumber(), -// portType); -// if (dbInfraOSPort == null) { -// InfraOSPort infraOSPort = new InfraOSPort(); -// infraOSPort.setInfraOS(infraOS); -// infraOSPort.setPort(port.getPortNumber()); -// infraOSPort.setPortType(portType); -// infraOSPort.setProbe(probe); -// infraOSPort.setMetaInfraType(typePort); - -// if (port.getPortType() == PortType.TLS) { -// infraOSPort.setTlsType(true); -// } -// infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); -// this.infraOSPortService.regist(infraOSPort); -// } - -// this.createService(infraHost, port, probe); -// } -// } - -// private InfraHost createAndReadHost(Host host, Probe probe) throws -// OverflowException { - -// InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4()); -// if (infraHost != null) { - -// if (host.isTarget() && infraHost.getTarget() == null) { -// Target target = new Target(); -// target.setDisplayName(host.getIpv4() + "-Host"); - -// this.targetService.regist(target, probe); -// infraHost.setTarget(target); -// this.infraHostService.regist(infraHost); -// } - -// return infraHost; -// } else { -// MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine; - -// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os - -// MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host - -// InfraMachine infraMachine = new InfraMachine(); -// infraMachine.setProbe(probe); -// infraMachine.setMetaInfraType(typeMachine); -// infraMachine.setMeta(host.getIpv4() + "-MACHINE"); -// this.infraMachineService.regist(infraMachine); - -// InfraOS infraOS = new InfraOS(); -// infraOS.setInfraMachine(infraMachine); -// infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); -// infraOS.setMetaInfraType(typeOS); -// infraOS.setProbe(probe); -// infraOS.setMeta(host.getIpv4() + "-OS"); -// this.infraOSService.regist(infraOS); - -// InfraHost newInfraHost = new InfraHost(); -// newInfraHost.setIpv4(host.getIpv4()); -// newInfraHost.setMac(host.getMac()); -// newInfraHost.setInfraOS(infraOS); -// newInfraHost.setMetaInfraType(typeHost); -// newInfraHost.setProbe(probe); - -// if (host.isTarget()) { -// Target target = new Target(); -// target.setDisplayName(host.getIpv4() + "-Host"); - -// this.targetService.regist(target, probe); -// newInfraHost.setTarget(target); -// } - -// this.infraHostService.regist(newInfraHost); -// infraHost = newInfraHost; -// } - -// return infraHost; -// } - -// } diff --git a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java index 18688b7..4479349 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java +++ b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java @@ -41,43 +41,34 @@ public class CentralTargetService implements TargetService { private CentralInfraServiceService infraServiceService; @Transactional - public Target regist(Target target, Probe probe) throws OverflowException { - this.probeService.increaseTargetCount(probe); + public Target regist(Target target, Long probeID) throws OverflowException { + this.probeService.increaseTargetCount(probeID); return this.targetDAO.save(target); } @Transactional - public void remove(Target target, Probe probe) throws OverflowException { - this.probeService.decreaseTargetCount(probe); - this.targetDAO.delete(target); + public void remove(Long id, Long probeID) throws OverflowException { + this.probeService.decreaseTargetCount(probeID); + this.targetDAO.deleteById(id); } - public Target read(String id) throws OverflowException { - return this.targetDAO.findById(Long.valueOf(id)).get(); + public Target read(Long id) throws OverflowException { + return this.targetDAO.findById(id).get(); } public Target modify(Target target) throws OverflowException { return this.targetDAO.save(target); } - @Deprecated - public Target regist(Target target) throws OverflowException { - return this.targetDAO.save(target); - } - @Deprecated - public void remove(Target target) throws OverflowException { - this.targetDAO.delete(target); - } - - public Target increaseSensorCount(Target target) throws OverflowException { - Target t = this.targetDAO.findById(target.getId()).get(); + public Target increaseSensorCount(Long id) throws OverflowException { + Target t = this.targetDAO.findById(id).get(); t.setSensorCount(t.getSensorCount() + 1); return this.targetDAO.save(t); } - public Target decreaseSensorCount(Target target) throws OverflowException { - Target t = this.targetDAO.findById(target.getId()).get(); + public Target decreaseSensorCount(Long id) throws OverflowException { + Target t = this.targetDAO.findById(id).get(); int count = t.getSensorCount(); if (t.getSensorCount() > 0) { t.setSensorCount(count - 1); @@ -102,7 +93,6 @@ public class CentralTargetService implements TargetService { public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams)); - // return null; } @Transactional diff --git a/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java b/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java index cb57122..5c4f109 100644 --- a/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java +++ b/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.redis.service; -import com.google.gson.Gson; import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.model.PublishMessage; diff --git a/src/test/java/com/loafle/overflow/central/commons/utils/EmailSenderTest.java b/src/test/java/com/loafle/overflow/central/commons/utils/EmailSenderTest.java index 3d77ca7..71a27ed 100644 --- a/src/test/java/com/loafle/overflow/central/commons/utils/EmailSenderTest.java +++ b/src/test/java/com/loafle/overflow/central/commons/utils/EmailSenderTest.java @@ -12,7 +12,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.net.URLDecoder; import java.net.URLEncoder; -import static org.junit.Assert.*; /** * Created by geek on 17. 9. 5. diff --git a/src/test/java/com/loafle/overflow/central/module/apikey/service/ApiKeyServiceTest.java b/src/test/java/com/loafle/overflow/central/module/apikey/service/ApiKeyServiceTest.java index d26db65..4bf5dc3 100644 --- a/src/test/java/com/loafle/overflow/central/module/apikey/service/ApiKeyServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/apikey/service/ApiKeyServiceTest.java @@ -14,7 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.*; /** * Created by snoop on 17. 6. 28. diff --git a/src/test/java/com/loafle/overflow/central/module/domain/service/DomainMemberServiceTest.java b/src/test/java/com/loafle/overflow/central/module/domain/service/DomainMemberServiceTest.java index 459b865..2b80058 100644 --- a/src/test/java/com/loafle/overflow/central/module/domain/service/DomainMemberServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/domain/service/DomainMemberServiceTest.java @@ -17,7 +17,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.List; -import static org.junit.Assert.*; /** * Created by snoop on 17. 6. 28. diff --git a/src/test/java/com/loafle/overflow/central/module/domain/service/DomainServiceTest.java b/src/test/java/com/loafle/overflow/central/module/domain/service/DomainServiceTest.java index 1887bea..550c0d4 100644 --- a/src/test/java/com/loafle/overflow/central/module/domain/service/DomainServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/domain/service/DomainServiceTest.java @@ -11,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.*; /** * Created by snoop on 17. 6. 28. diff --git a/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraDAOTest.java b/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraDAOTest.java deleted file mode 100644 index f3a7a6b..0000000 --- a/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraDAOTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.loafle.overflow.central.module.infra.dao; - -import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.model.probe.Probe; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by snoop on 17. 9. 14. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) -public class InfraDAOTest { - - @Autowired - private InfraDAO infraDAO; - - @Test - public void findAllTargetByProbeIn() throws Exception { - - List probes = new ArrayList<>(); - - Probe probe = new Probe(); - probe.setId(Long.valueOf(1)); - - probes.add(probe); - - - this.infraDAO.findAllTargetByProbeIn(probes); - - } - -} diff --git a/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraOSPortDAOTest.java b/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraOSPortDAOTest.java deleted file mode 100644 index 8906489..0000000 --- a/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraOSPortDAOTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.loafle.overflow.central.module.infra.dao; - -import com.loafle.overflow.central.spring.AppConfigTest; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.junit.Assert.*; - -/** - * Created by snoop on 18. 4. 25. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) -public class InfraOSPortDAOTest { - - @Autowired - private InfraOSPortDAO infraOSPortDAO; - - @Test - public void findByPort() throws Exception { - - -// this.infraOSPortDAO.findByPort(1, 22, "UDP"); - - } - -} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java index 3ae22c9..9e2d465 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java @@ -1,17 +1,7 @@ package com.loafle.overflow.central.module.infra.service; import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.infra.InfraHost; -import com.loafle.overflow.model.infra.InfraOS; -import com.loafle.overflow.model.meta.MetaInfraType; -import com.loafle.overflow.service.central.infra.InfraHostService; - -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Assert; -import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -22,56 +12,4 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration(classes = { AppConfigTest.class }) public class InfraHostServiceTest { - @Autowired - private InfraHostService infraHostService; - - @Autowired - private ObjectMapper objectMapper; - - @Test - // @Ignore - public void regist() throws Exception { - - InfraHost infraHost = new InfraHost(); - - infraHost.setMac("30-9C-23-15-A3-09"); - infraHost.setIpv4("192.168.1.1"); - InfraOS infraOS = new InfraOS(); - infraOS.setId(Long.valueOf(2)); - - infraHost.setInfraOS(infraOS); - - MetaInfraType metaInfraType = new MetaInfraType(2); - - this.infraHostService.regist(infraHost); - - Assert.assertNotEquals(infraHost.getId().longValue(), 0); - - } - - @Test - public void read() throws Exception { - - InfraHost infraHost = this.infraHostService.read(Long.valueOf(1)); - - String json = objectMapper.writeValueAsString(infraHost); - - System.out.println(json); - - } - - @Test - public void readByIp() { - - InfraHost infraHost; - try { - infraHost = this.infraHostService.readByProbeIdAndIpv4(Long.valueOf(1), "192.168.1.1"); - Assert.assertNotEquals(infraHost, null); - } catch (OverflowException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - } \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraMachineServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraMachineServiceTest.java deleted file mode 100644 index 26a30e3..0000000 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraMachineServiceTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.loafle.overflow.central.module.infra.service; - -import com.google.gson.Gson; -import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.model.infra.InfraMachine; -import com.loafle.overflow.model.meta.MetaInfraType; -import com.loafle.overflow.service.central.infra.InfraMachineService; - -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - - -/** - * Created by snoop on 17. 7. 27. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) -public class InfraMachineServiceTest { - - @Autowired - private InfraMachineService infraMachineService; - - @Autowired - private ObjectMapper objectMapper; - - // @Ignore - @Test - public void regist() throws Exception { - - InfraMachine infraMachine = new InfraMachine(); - - infraMachine.setMeta("i am a infra machine"); - - MetaInfraType metaInfraType = new MetaInfraType(1); - - this.infraMachineService.regist(infraMachine); - - Assert.assertNotEquals(infraMachine.getId().longValue(), 0); - - } - - @Test - public void read() throws Exception { - -// regist(); - - InfraMachine infraMachine = this.infraMachineService.read(Long.valueOf(1)); - - String json = objectMapper.writeValueAsString(infraMachine); - System.out.println(json); - } - -} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSApplicationServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSApplicationServiceTest.java deleted file mode 100644 index 4a05240..0000000 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSApplicationServiceTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.loafle.overflow.central.module.infra.service; - -import com.google.gson.Gson; -import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.model.infra.InfraOS; -import com.loafle.overflow.model.infra.InfraOSApplication; -import com.loafle.overflow.model.meta.MetaInfraType; -import com.loafle.overflow.service.central.infra.InfraOSApplicationService; - -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Created by snoop on 17. 7. 28. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) -public class InfraOSApplicationServiceTest { - - @Autowired - private InfraOSApplicationService infraOSApplicationService; - - @Autowired - private ObjectMapper objectMapper; - -// @Ignore - @Test - public void regist() throws Exception { - InfraOSApplication infraOSApplication = new InfraOSApplication(); - - infraOSApplication.setName("Apache"); - - InfraOS infraOS = new InfraOS(); - infraOS.setId(Long.valueOf(2)); - - infraOSApplication.setInfraOS(infraOS); - - MetaInfraType metaInfraType = new MetaInfraType(4); - - this.infraOSApplicationService.regist(infraOSApplication); - - - Assert.assertNotEquals(infraOSApplication.getId().longValue(), 0); - - } - - @Test - public void read() throws Exception { - - InfraOSApplication infraOSApplication = this.infraOSApplicationService.read(Long.valueOf(1)); - - Assert.assertNotNull(infraOSApplication); - - String json = objectMapper.writeValueAsString(infraOSApplication); - System.out.println(json); - - } - -} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSDaemonServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSDaemonServiceTest.java deleted file mode 100644 index e45ba15..0000000 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSDaemonServiceTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.loafle.overflow.central.module.infra.service; - -import com.google.gson.Gson; -import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.model.infra.InfraOS; -import com.loafle.overflow.model.infra.InfraOSDaemon; -import com.loafle.overflow.model.meta.MetaInfraType; -import com.loafle.overflow.service.central.infra.InfraOSDaemonService; - -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Created by snoop on 17. 7. 28. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) -public class InfraOSDaemonServiceTest { - - @Autowired - private InfraOSDaemonService infraOSDaemonService; - - @Autowired - private ObjectMapper objectMapper; - -// @Ignore - @Test - public void regist() throws Exception { - - InfraOSDaemon infraOSDaemon = new InfraOSDaemon(); - infraOSDaemon.setName("Apache"); - - InfraOS infraOS = new InfraOS(); - infraOS.setId(Long.valueOf(2)); - - infraOSDaemon.setInfraOS(infraOS); - - MetaInfraType metaInfraType = new MetaInfraType(5); - - this.infraOSDaemonService.regist(infraOSDaemon); - - Assert.assertNotEquals(infraOSDaemon.getId().longValue(), 0); - - } - - @Test - public void read() throws Exception { - - InfraOSDaemon infraOSDaemon = this.infraOSDaemonService.read(Long.valueOf(1)); - Assert.assertNotNull(infraOSDaemon); - - String json = objectMapper.writeValueAsString(infraOSDaemon); - System.out.println(json); - - } - -} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSPortServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSPortServiceTest.java deleted file mode 100644 index 319dbac..0000000 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSPortServiceTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.loafle.overflow.central.module.infra.service; - -import com.google.gson.Gson; -import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.infra.InfraOS; -import com.loafle.overflow.model.infra.InfraOSPort; -import com.loafle.overflow.model.meta.MetaInfraType; -import com.loafle.overflow.service.central.infra.InfraOSPortService; - -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Created by snoop on 17. 7. 28. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) -public class InfraOSPortServiceTest { - - @Autowired - private InfraOSPortService infraOSPortService; - @Autowired - private ObjectMapper objectMapper; - -// @Ignore - @Test - public void regist() throws Exception { - - InfraOSPort infraOSPort = new InfraOSPort(); - infraOSPort.setTlsType(false); - infraOSPort.setPortType("TCP"); - - InfraOS infraOS = new InfraOS(); - infraOS.setId(Long.valueOf(1)); - - MetaInfraType metaInfraType = new MetaInfraType(2); - - infraOSPort.setInfraOS(infraOS); - - // FIXME::vendor??? - - } - - @Test - public void read() throws Exception { - } - - @Test - public void readByPort() { - - InfraOSPort infraOSPort; - try { - infraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(Long.valueOf(1), 22, "TCP"); - Assert.assertNotEquals(infraOSPort, null); - } catch (OverflowException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - } - -} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSServiceTest.java deleted file mode 100644 index 6119d3a..0000000 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSServiceTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.loafle.overflow.central.module.infra.service; - -import com.google.gson.Gson; -import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.model.infra.InfraMachine; -import com.loafle.overflow.model.infra.InfraOS; -import com.loafle.overflow.model.meta.MetaInfraType; -import com.loafle.overflow.model.meta.MetaInfraVendor; -import com.loafle.overflow.service.central.infra.InfraOSService; - -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Created by snoop on 17. 7. 27. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) -public class InfraOSServiceTest { - - @Autowired - private InfraOSService infraOSService; - @Autowired - private ObjectMapper objectMapper; - - @Test -// @Ignore - public void registOS() throws Exception { - - InfraOS infraOS = new InfraOS(); - - MetaInfraVendor metaInfraVendor = new MetaInfraVendor(); - metaInfraVendor.setId(26); - - infraOS.setMetaInfraVendor(metaInfraVendor); - infraOS.setMeta(""); - - InfraMachine infraMachine = new InfraMachine(); - infraMachine.setId(Long.valueOf(1)); - - MetaInfraType metaInfraType = new MetaInfraType(3); - - infraOS.setInfraMachine(infraMachine); - - - - this.infraOSService.regist(infraOS); - } - - @Test - public void read() throws Exception { - - InfraOS infraOS = this.infraOSService.read(Long.valueOf(1)); - String json = objectMapper.writeValueAsString(infraOS); - System.out.println(json); - } - -} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceServiceTest.java index b91d6a2..afa190e 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceServiceTest.java @@ -1,18 +1,8 @@ package com.loafle.overflow.central.module.infra.service; -import com.google.gson.Gson; import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.model.infra.InfraHost; -import com.loafle.overflow.model.infra.InfraService; -import com.loafle.overflow.model.meta.MetaInfraType; -import com.loafle.overflow.model.meta.MetaInfraVendor; -import com.loafle.overflow.service.central.infra.InfraServiceService; -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Assert; -import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -22,10 +12,4 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { AppConfigTest.class }) public class InfraServiceServiceTest { - - @Autowired - private InfraServiceService infraServiceService; - @Autowired - private ObjectMapper objectMapper; - } \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceTest.java index 3738241..3796bcd 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceTest.java @@ -1,119 +1,15 @@ -// package com.loafle.overflow.central.module.infra.service; +package com.loafle.overflow.central.module.infra.service; -// import com.loafle.overflow.central.spring.AppConfigTest; -// import org.codehaus.jackson.map.ObjectMapper; -// import org.junit.Test; -// import org.junit.runner.RunWith; -// import org.springframework.beans.factory.annotation.Autowired; -// import org.springframework.data.domain.Page; -// import org.springframework.test.context.ContextConfiguration; -// import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -// import java.io.IOException; - -// import static org.junit.Assert.assertNotNull; - -// /** -// * Created by snoop on 17. 7. 27. -// */ -// @RunWith(SpringJUnit4ClassRunner.class) -// @ContextConfiguration(classes = {AppConfigTest.class}) -// public class InfraServiceTest { - -// @Autowired -// private InfraService infraService; - -// @Autowired -// private ProbeService probeService; - -// @Autowired -// private InfraMachineService infraMachineService; +import com.loafle.overflow.central.spring.AppConfigTest; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -// @Test -// public void tttt() { - -// } - -// @Test -// public void readAllByProbe() throws IOException { -// Probe probe = new Probe(); -// probe.setId(1); -// PageParams pageParams = new PageParams(); -// pageParams.setCountPerPage(100); -// pageParams.setPageNo(0); -// pageParams.setSortCol("id"); -// pageParams.setSortDirection("descending"); -// Page list = this.infraService.readAllByProbe(probe, pageParams); - -// assertNotNull(list); -// } - -// @Test -// public void read() throws Exception { - -// // registInfraMachine(); - -// Infra infra = this.infraService.read(1); - -// ObjectMapper objectMapper = new ObjectMapper(); -// String json = objectMapper.writeValueAsString(infra); - -// System.out.println(json); -// } - -// // @Test -// // public void readAllProbe() throws IOException { -// // -// // Probe probe = new Probe(); -// // probe.setId(1); -// // -// // List infraList = this.infraService.readAllByProbe(probe); -// // -// // ObjectMapper objectMapper = new ObjectMapper(); -// // String json = objectMapper.writeValueAsString(infraList); -// // -// // System.out.println(json); -// // -// // } - -// @Test -// public void readAllTarget() { -// Domain domain = new Domain(); -// domain.setId(1); - -// // this.infraService.readAllTargetByProbeList() -// } - -// @Test -// public void readByTarget() throws IOException { -// Target target = new Target(); -// target.setId(1); - -// Infra infra = this.infraService.readByTarget(target); - -// ObjectMapper objectMapper = new ObjectMapper(); -// String json = objectMapper.writeValueAsString(infra); - -// System.out.println(json); -// } - -// // @Test -// // public void readAllByProbeList() throws IOException { -// // -// // Domain domain = new Domain(); -// // domain.setId(1); -// // -// // -// // List fl = this.infraService.readAllByDomain(domain); -// // -// // System.out.println(fl.size()); -// // ObjectMapper objectMapper = new ObjectMapper(); -// // String json = objectMapper.writeValueAsString(fl); -// // -// // System.out.println(json); -// // -// // } - -// } \ No newline at end of file +/** + * Created by snoop on 17. 7. 27. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfigTest.class}) +public class InfraServiceTest { +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/member/service/MemberServiceTest.java b/src/test/java/com/loafle/overflow/central/module/member/service/MemberServiceTest.java index 8a72050..183c9ad 100644 --- a/src/test/java/com/loafle/overflow/central/module/member/service/MemberServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/member/service/MemberServiceTest.java @@ -1,12 +1,9 @@ package com.loafle.overflow.central.module.member.service; import com.loafle.overflow.central.spring.AppConfigTest; - import com.loafle.overflow.model.member.Member; import com.loafle.overflow.service.central.member.MemberService; import com.loafle.overflow.service.central.member.MemberTotpService; - import org.junit.Assert; - import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -14,10 +11,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - import java.util.Date; - import java.util.List; - import java.util.regex.Matcher; - import java.util.regex.Pattern; /** * Created by insanity on 17. 6. 28. diff --git a/src/test/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeServiceTest.java b/src/test/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeServiceTest.java index dfe7f65..b7126e9 100644 --- a/src/test/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeServiceTest.java @@ -6,7 +6,6 @@ import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus; import com.loafle.overflow.model.noauthprobe.NoAuthProbe; -import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService; import org.junit.Assert; import org.junit.Ignore; @@ -16,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.io.IOException; import java.util.ArrayList; import java.util.List; diff --git a/src/test/java/com/loafle/overflow/central/module/target/service/TargetDiscoveryServiceTest.java b/src/test/java/com/loafle/overflow/central/module/target/service/TargetDiscoveryServiceTest.java deleted file mode 100644 index 5eb3939..0000000 --- a/src/test/java/com/loafle/overflow/central/module/target/service/TargetDiscoveryServiceTest.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.loafle.overflow.central.module.target.service; - - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; -import com.loafle.overflow.central.spring.AppConfigTest; - -import com.loafle.overflow.model.discovery.Host; -import com.loafle.overflow.model.probe.Probe; -import com.loafle.overflow.service.central.target.TargetDiscoveryService; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.aop.support.AopUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.ResourceLoader; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.List; - -/** - * Created by snoop on 17. 6. 28. -*/ - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) -public class TargetDiscoveryServiceTest { - - @Autowired - private ResourceLoader resourceLoader; - - @Autowired - private TargetDiscoveryService targetDiscoveryService; - -// @Ignore - @Test - public void saveAllTarget() throws Exception { - - String json = readFileAsString(resourceLoader.getResource("classpath:2018-04-25-tds.json").getURI().getPath()); - -// Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create(); - - - ObjectMapper mapper = new ObjectMapper(); - - mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - List hosts = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Host.class)); - - - Probe probe = new Probe(); - probe.setId(Long.valueOf(1)); - - this.targetDiscoveryService.saveAllTarget(hosts, probe); - } - - private String readFileAsString(String filePath) throws IOException { - StringBuffer fileData = new StringBuffer(); - BufferedReader reader = new BufferedReader( - new FileReader(filePath)); - char[] buf = new char[1024]; - int numRead=0; - while((numRead=reader.read(buf)) != -1){ - String readData = String.valueOf(buf, 0, numRead); - fileData.append(readData); - } - reader.close(); - return fileData.toString(); - } - - - @Ignore - @Test - public void testParam() throws NoSuchMethodException { - - Method m = this.targetDiscoveryService.getClass().getMethod("saveAllTarget", List.class, Probe.class); -// Method m = TargetDiscoveryService.class.getMethod("saveAllTarget", List.class, Probe.class); - - Class clazz = AopUtils.getTargetClass(this.targetDiscoveryService); - Method[] ms = clazz.getMethods(); - - Method sm = null; - for(Method mm : ms){ - if ("saveAllTarget".equals(mm.getName())) { - sm = mm; - break; - } - } - - if (sm != null) { - Type[] ts = sm.getGenericParameterTypes(); - for(Type t : ts){ - if (t instanceof ParameterizedType) { - ParameterizedType pt = (ParameterizedType)t; - System.out.println(pt.getActualTypeArguments()[0].getTypeName()); - } - System.out.println(t.getTypeName()); - - - } - } - - - System.out.println(m.getName()); - Type[] genericParameterTypes = m.getGenericParameterTypes(); - - for(Type genericParameterType : genericParameterTypes){ - if(genericParameterType instanceof ParameterizedType){ - ParameterizedType aType = (ParameterizedType) genericParameterType; - Type[] parameterArgTypes = aType.getActualTypeArguments(); - for(Type parameterArgType : parameterArgTypes){ - Class parameterArgClass = (Class) parameterArgType; - System.out.println("parameterArgClass = " + parameterArgClass); - } - } - } - } - - @Ignore - @Test - public void testName() throws ClassNotFoundException { - - Object o = this.targetDiscoveryService; - - String nnn = o.getClass().getSimpleName(); - System.out.println(nnn); - - - - - - - } - -} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/module/target/service/TargetServiceTest.java b/src/test/java/com/loafle/overflow/central/module/target/service/TargetServiceTest.java deleted file mode 100644 index 6215518..0000000 --- a/src/test/java/com/loafle/overflow/central/module/target/service/TargetServiceTest.java +++ /dev/null @@ -1,67 +0,0 @@ - package com.loafle.overflow.central.module.target.service; - - - import com.loafle.overflow.central.spring.AppConfigTest; - import com.loafle.overflow.core.model.PageParams; - import com.loafle.overflow.model.target.Target; - import com.loafle.overflow.service.central.target.TargetService; - import org.junit.Assert; - import org.junit.Ignore; - import org.junit.Test; - import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; - import org.springframework.data.domain.Page; - import org.springframework.test.context.ActiveProfiles; - import org.springframework.test.context.ContextConfiguration; - import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - - import java.util.Date; - - /** - * Created by insanity on 17. 6. 28. - */ - - @RunWith(SpringJUnit4ClassRunner.class) - @ActiveProfiles("test") - @ContextConfiguration(classes = {AppConfigTest.class}) - public class TargetServiceTest { -// @Autowired -// TargetService targetService; -// -// @Ignore -// @Test -// public void regist() throws Exception { -//// Target t = new Target(); -//// t.setCreateDate(new Date()); -//// // Infra infra = new Infra(); -//// // infra.setId(1); -//// // Probe probe = new Probe(); -//// // probe.setId(1); -//// // t.setProbe(probe); -//// // t.setInfra(infra); -//// t.setDescription("i am target"); -//// t.setDisplayName("ghost target"); -//// -//// Target res = this.targetService.regist(t); -//// Assert.assertNotNull(res); -// } -// -// @Test -// @Ignore -// public void read() throws Exception { -//// Target res = this.targetService.read("1"); -//// Assert.assertNotNull(res); -// } -// -// @Test -// public void testReadAllByProbeId() throws Exception { -// PageParams pageParams = new PageParams(); -// pageParams.setPageNo(1); -// pageParams.setCountPerPage(10); -// -// Page targets = this.targetService.readAllByProbeID((long)1, pageParams); -// -// System.out.println(targets.getSize()); -// } -// - } diff --git a/src/test/java/com/loafle/overflow/central/spring/AppConfigTest.java b/src/test/java/com/loafle/overflow/central/spring/AppConfigTest.java index b0a8eb4..22ca600 100644 --- a/src/test/java/com/loafle/overflow/central/spring/AppConfigTest.java +++ b/src/test/java/com/loafle/overflow/central/spring/AppConfigTest.java @@ -6,7 +6,6 @@ import org.springframework.context.annotation.*; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.test.context.TestPropertySource; -import static org.junit.Assert.*; /** * Created by geek on 17. 8. 8.