diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostDaemonService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostDaemonService.java index a104813..f0ba96a 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostDaemonService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostDaemonService.java @@ -16,8 +16,8 @@ public class CentralInfraHostDaemonService implements InfraHostDaemonService { @Autowired InfraHostDaemonDAO infraHostDaemonDAO; - public InfraHostDaemon regist(InfraHostDaemon infraOSDaemon) throws OverflowException { - return this.infraHostDaemonDAO.save(infraOSDaemon); + public InfraHostDaemon regist(InfraHostDaemon infraHostDaemon) throws OverflowException { + return this.infraHostDaemonDAO.save(infraHostDaemon); } public InfraHostDaemon read(Long id) throws OverflowException { 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 35dbfdf..17c6378 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 @@ -14,7 +14,10 @@ import com.loafle.overflow.model.discovery.Port; import com.loafle.overflow.model.discovery.Zone; import com.loafle.overflow.model.infra.Infra; import com.loafle.overflow.model.infra.InfraHost; +import com.loafle.overflow.model.infra.InfraHostApplication; +import com.loafle.overflow.model.infra.InfraHostDaemon; import com.loafle.overflow.model.infra.InfraHostIP; +import com.loafle.overflow.model.infra.InfraHostMachine; import com.loafle.overflow.model.infra.InfraHostOS; import com.loafle.overflow.model.infra.InfraHostPort; import com.loafle.overflow.model.infra.InfraZone; @@ -56,12 +59,24 @@ public class CentralInfraService implements InfraService { @Autowired InfraServiceDAO infraServiceDAO; + @Autowired + CentralInfraHostMachineService infraHostMachineService; + + @Autowired + CentralInfraHostOSService infraHostOSService; + @Autowired CentralInfraHostIPService infraHostIPService; @Autowired CentralInfraHostPortService infraHostPortService; + @Autowired + CentralInfraHostApplicationService infraHostApplicationService; + + @Autowired + CentralInfraHostDaemonService infraHostDaemonService; + @Autowired CentralMetaCryptoTypeService metaCryptoTypeService; @@ -153,9 +168,13 @@ public class CentralInfraService implements InfraService { infraZone.setProbe(probe); infraHost.setInfraZone(infraZone); infraHost.setMetaTargetHostType(MetaTargetHostType.Enum.UNKNOWN.to()); - infraHost.setInfraHostIPs(Arrays.asList(infraHostIP)); - return this.infraHostDAO.save(infraHost); + infraHost = this.infraHostDAO.save(infraHost); + + infraHostIP.setInfraHost(infraHost); + this.infraHostIPService.regist(infraHostIP); + + return infraHost; } @Override @@ -229,6 +248,7 @@ public class CentralInfraService implements InfraService { infraHostIP.getMetaIPType().getName())); } + infraHostPort.setInfraHost(infraHost); infraHostPort = this.infraHostPortService.regist(infraHostPort); com.loafle.overflow.model.infra.InfraService infraService = new com.loafle.overflow.model.infra.InfraService(); @@ -288,22 +308,65 @@ public class CentralInfraService implements InfraService { infraHost.setInfraZone(new InfraZone(infraZoneID)); infraHost.setMetaInfraType(MetaInfraType.Enum.HOST.to()); + infraHost = this.infraHostDAO.save(infraHost); + + InfraHostMachine infraHostMachine = oriInfraHost.getInfraHostMachine(); + if (null != infraHostMachine) { + infraHostMachine.setInfraHost(infraHost); + this.infraHostMachineService.regist(infraHostMachine); + } + InfraHostOS infraHostOS = oriInfraHost.getInfraHostOS(); if (null != infraHostOS) { // MetaTargetHostType metaTargetHostType = // this.metaTargetHostTypeService.readByInfraHostOS(infraHostOS); infraHost.setMetaTargetHostType(MetaTargetHostType.Enum.UNKNOWN.to()); - infraHost.setInfraHostOS(infraHostOS); + infraHost = this.infraHostDAO.save(infraHost); + + infraHostOS.setInfraHost(infraHost); + this.infraHostOSService.regist(infraHostOS); } else { infraHost.setMetaTargetHostType(MetaTargetHostType.Enum.UNKNOWN.to()); + infraHost = this.infraHostDAO.save(infraHost); } - infraHost.setInfraHostIPs(oriInfraHost.getInfraHostIPs()); - infraHost.setInfraHostPorts(oriInfraHost.getInfraHostPorts()); - infraHost.setInfraHostApplications(oriInfraHost.getInfraHostApplications()); - infraHost.setInfraHostDaemons(oriInfraHost.getInfraHostDaemons()); + if (null != oriInfraHost.getInfraHostIPs()) { + for (InfraHostIP infraHostIP : oriInfraHost.getInfraHostIPs()) { + infraHostIP = this.infraHostIPService.validate(infraHostIP); + infraHostIP.setInfraHost(infraHost); - return this.infraHostDAO.save(infraHost); + this.infraHostIPService.regist(infraHostIP); + } + } else { + throw new OverflowException("InfraHostIPs is not valid"); + } + + if (null != oriInfraHost.getInfraHostPorts()) { + for (InfraHostPort infraHostPort : oriInfraHost.getInfraHostPorts()) { + infraHostPort = this.infraHostPortService.validate(infraHostPort); + infraHostPort.setInfraHost(infraHost); + + this.infraHostPortService.regist(infraHostPort); + } + } + + if (null != oriInfraHost.getInfraHostApplications()) { + for (InfraHostApplication infraHostApplication : oriInfraHost.getInfraHostApplications()) { + infraHostApplication.setInfraHost(infraHost); + + this.infraHostApplicationService.regist(infraHostApplication); + } + } + + if (null != oriInfraHost.getInfraHostDaemons()) { + for (InfraHostDaemon infraHostDaemon : oriInfraHost.getInfraHostDaemons()) { + infraHostDaemon.setInfraHost(infraHost); + + this.infraHostDaemonService.regist(infraHostDaemon); + } + } + + return infraHost; } @Override 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 1d157e4..8b0ddd8 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 @@ -52,16 +52,16 @@ public class NoAuthProbeServiceTest { @Test public void acceptNoAuthProbe() throws Exception { - List noAuthProbes = this.noAuthProbeService.acceptNoAuthProbe((long) 1, "192.168.1.0/24"); + NoAuthProbe noAuthProbe = this.noAuthProbeService.acceptNoAuthProbe((long) 1, "192.168.1.0/24"); - Assert.assertNotEquals(noAuthProbes.size(), 0); + Assert.assertNotNull(noAuthProbe); } @Test public void denyNoauthProbe() throws Exception { - List noAuthProbes = this.noAuthProbeService.denyNoauthProbe((long) 1); + NoAuthProbe noAuthProbe = this.noAuthProbeService.denyNoauthProbe((long) 1); - Assert.assertNotEquals(noAuthProbes.size(), 0); + Assert.assertNotNull(noAuthProbe); } @Test