From 816bb769f8e9ff9941913bd1484deb3f9d7c1f3e Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 15 Jun 2018 15:02:58 +0900 Subject: [PATCH] ing --- pom.xml | 2 +- .../module/infra/dao/InfraHostDAO.java | 3 +++ .../module/infra/dao/InfraHostPortDAO.java | 13 +++++++--- .../module/infra/dao/InfraServiceDAO.java | 6 ++--- .../infra/service/CentralInfraService.java | 3 +++ .../resources/profiles/local/init.sample.sql | 15 ++++++------ .../domain/service/DomainServiceTest.java | 24 +++++++++---------- .../infra/service/InfraServiceTest.java | 22 +++++++++++++++-- 8 files changed, 58 insertions(+), 30 deletions(-) diff --git a/pom.xml b/pom.xml index 1b43465..09a6d59 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ com.loafle.overflow commons-java - 1.0.74-SNAPSHOT + 1.0.77-SNAPSHOT diff --git a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java index 6966330..5d5f736 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java @@ -1,5 +1,7 @@ package com.loafle.overflow.central.module.infra.dao; +import java.util.List; + import com.loafle.overflow.model.infra.InfraHost; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -9,4 +11,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraHostDAO extends JpaRepository { + List findAllByInfraZoneId(Long infraZoneId); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostPortDAO.java b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostPortDAO.java index 76ef1b2..5e2ddb6 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostPortDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostPortDAO.java @@ -5,6 +5,8 @@ import java.util.List; import com.loafle.overflow.model.infra.InfraHostPort; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; /** @@ -12,9 +14,14 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraHostPortDAO extends JpaRepository { - List findAllByInfraHostIPId(Long infraHostIPId); + @Query("SELECT ihp from InfraHostPort ihp where ihp.infraHostIP.id = :infraHostIPId") + List findAllByInfraHostIPId(@Param("infraHostIPId") Long infraHostIPId); - List findAllByInfraHostIPIdAndMetaPortTypeId(Long infraHostIPId, Short metaPortTypeId); + @Query("SELECT ihp from InfraHostPort ihp where ihp.infraHostIP.id = :infraHostIPId AND metaPortType.key = :metaPortTypeKey") + List findAllByInfraHostIPIdAndMetaPortTypeKey(@Param("infraHostIPId") Long infraHostIPId, + @Param("metaPortTypeKey") Short metaPortTypeKey); - InfraHostPort findByInfraHostIPIdAndMetaPortTypeKeyAndPort(Long infraHostIPId, String metaPortTypeKey, Integer port); + @Query("SELECT ihp from InfraHostPort ihp where ihp.infraHostIP.id = :infraHostIPId AND metaPortType.key = :metaPortTypeKey AND port = :port") + InfraHostPort findByInfraHostIPIdAndMetaPortTypeKeyAndPort(@Param("infraHostIPId") Long infraHostIPId, + @Param("metaPortTypeKey") String metaPortTypeKey, @Param("port") Integer port); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraServiceDAO.java b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraServiceDAO.java index 71132ce..4385faa 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraServiceDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraServiceDAO.java @@ -11,8 +11,8 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraServiceDAO extends JpaRepository { - @Query("SELECT i from InfraService i where i.infraHostPort.infraHost.id = :infraHostId AND i.infraHostPort.metaPortType.key = :metaPortTypeKey AND i.infraHostPort.port = :port") - InfraService findByInfraHostPortInfraHostIdAndInfraHostPortMetaPortTypeKeyAndInfraHostPortPort( - @Param("infraHostId") Long infraHostId, @Param("metaPortTypeKey") String metaPortTypeKey, + @Query("SELECT i from InfraService i where i.infraHostPort.infraHostIP.id = :infraHostIPId AND i.infraHostPort.metaPortType.key = :metaPortTypeKey AND i.infraHostPort.port = :port") + InfraService findByInfraHostPortInfraHostIPIdAndInfraHostPortMetaPortTypeKeyAndInfraHostPortPort( + @Param("infraHostIPId") Long infraHostIPId, @Param("metaPortTypeKey") String metaPortTypeKey, @Param("port") Integer port); } 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 8b75491..a47f8c8 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 @@ -358,4 +358,7 @@ public class CentralInfraService implements InfraService { return null; } + public List readAllInfraHostByInfraZoneID(Long infraZoneID) throws OverflowException { + return this.infraHostDAO.findAllByInfraZoneId(infraZoneID); + } } diff --git a/src/main/resources/profiles/local/init.sample.sql b/src/main/resources/profiles/local/init.sample.sql index a3de25c..3b08732 100644 --- a/src/main/resources/profiles/local/init.sample.sql +++ b/src/main/resources/profiles/local/init.sample.sql @@ -69,15 +69,14 @@ INSERT INTO public.infra (infra_type, meta_infra_type_id, probe_id) VALUES (3, 3 INSERT INTO public.infra_zone (id, meta_target_zone_type_id, network, iface, meta_ip_type_id, "address", mac) VALUES (1, 1, '192.168.1.0/24', 'enp3s0', 1, '192.168.1.101', '44:8a:5b:f1:f1:f3'); -INSERT INTO public.infra_host (id, infra_zone_id, meta_target_host_type_id) VALUES (2, 1, 127); +INSERT INTO public.infra_host_machine (meta) VALUES ('{"vendor": "Micro-Star International Co., Ltd.", "product": "GP60 2QF (To be filled by O.E.M.)", "version": "REV:1.0", "serial": "9S716GH21875ZF1000339"}'); + +INSERT INTO public.infra_host_os ("name", os, platform, platform_family, platform_version, kernel_version, host_id) VALUES ('geek-ubuntu', 'linux', 'ubuntu', 'debian', '', '4.4.0-93-generic', '03000200-0400-0500-0006-000700080009'); + +INSERT INTO public.infra_host (id, infra_zone_id, meta_target_host_type_id, infra_host_machine_id, infra_host_os_id) VALUES (2, 1, 127, 1, 1); INSERT INTO public.infra_host_ip (infra_host_id, meta_ip_type_id, "address", mac) VALUES (2, 1, '192.168.1.101', '44:8a:5b:f1:f1:f3'); -INSERT INTO public.infra_host_port (infra_host_id, meta_port_type_id, port) VALUES (2, 1, 5432); - - -INSERT INTO public.infra_host_machine (infra_host_id, meta) VALUES (2, '{"vendor": "Micro-Star International Co., Ltd.", "product": "GP60 2QF (To be filled by O.E.M.)", "version": "REV:1.0", "serial": "9S716GH21875ZF1000339"}'); - -INSERT INTO public.infra_host_os (infra_host_id, "name", os, platform, platform_family, platform_version, kernel_version, host_id) VALUES (2, 'geek-ubuntu', 'linux', 'ubuntu', 'debian', '', '4.4.0-93-generic', '03000200-0400-0500-0006-000700080009'); +INSERT INTO public.infra_host_port (infra_host_ip_id, meta_port_type_id, port) VALUES (1, 1, 5432); INSERT INTO public.infra_host_application (infra_host_id, "name") VALUES (2, 'Apache Httpd'); @@ -91,7 +90,7 @@ INSERT INTO public.infra_host_daemon (infra_host_id, "name") VALUES (2, 'Postgre INSERT INTO public.infra_host_daemon (infra_host_id, "name") VALUES (2, 'MySQL'); -INSERT INTO public.infra_service (id, meta_target_service_type_id, infra_host_ip_id, infra_host_port_id) VALUES (3, 1035, 1, 1); +INSERT INTO public.infra_service (id, meta_target_service_type_id, infra_host_port_id, meta_crypto_type_id) VALUES (3, 1035, 1, 1); INSERT INTO public.target (infra_id, "name", description, sensor_count, meta_target_type_id) VALUES (1, 'Zone', 'Zone Target', 1, 2); 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 550c0d4..2ca92c2 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 @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.domain.service; - import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.model.domain.Domain; import org.junit.Assert; @@ -11,28 +10,27 @@ 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. 6. 28. */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) +@ContextConfiguration(classes = { AppConfigTest.class }) public class DomainServiceTest { - @Autowired - private CentralDomainService domainService; + @Autowired + private CentralDomainService domainService; - @Ignore - @Test - public void regist() throws Exception { + @Ignore + @Test + public void regist() throws Exception { - Domain domain = new Domain(); + Domain domain = new Domain(); - domain.setName("overFlow's domain22"); + domain.setName("overFlow's domain22"); - this.domainService.regist(domain); + this.domainService.regist(domain); - Assert.assertNotEquals(domain.getId().longValue(), 0); - } + Assert.assertNotEquals(domain.getId().longValue(), 0); + } } \ 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 3796bcd..9426640 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,15 +1,33 @@ package com.loafle.overflow.central.module.infra.service; +import static org.junit.Assert.assertNotNull; + +import java.util.List; + import com.loafle.overflow.central.spring.AppConfigTest; +import com.loafle.overflow.model.infra.InfraHost; + +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}) +@ContextConfiguration(classes = { AppConfigTest.class }) public class InfraServiceTest { + + @Autowired + private CentralInfraService infraService; + + @Test + public void readAllInfraHostByInfraZoneID() throws Exception { + List infraHosts = this.infraService.readAllInfraHostByInfraZoneID((long) 1); + + assertNotNull(infraHosts); + } + } \ No newline at end of file