From 65784514d002db61d6b720b06a8572a8d789a4e9 Mon Sep 17 00:00:00 2001 From: insanity Date: Mon, 26 Jun 2017 20:11:47 +0900 Subject: [PATCH] sensor item --- .../overflow/module/sensor/dao/SensorDAO.java | 5 +- .../module/sensor/dao/SensorItemDAO.java | 6 +- .../com/loafle/overflow/proxy/db/DBProxy.java | 6 -- src/main/resources/init.sql | 57 +++++++++------- .../meta/dao/MetaSensorItemDAOTest.java | 66 +++++++++++++++++++ .../meta/dao/MetaSensorItemTypeDAOTest.java | 48 ++++++++++++++ .../module/sensor/dao/SensorDAOTest.java | 14 +++- .../module/target/dao/TargetDAOTest.java | 2 + 8 files changed, 170 insertions(+), 34 deletions(-) create mode 100644 src/test/java/com/loafle/overflow/meta/dao/MetaSensorItemDAOTest.java create mode 100644 src/test/java/com/loafle/overflow/meta/dao/MetaSensorItemTypeDAOTest.java diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java index 4afb306..ef7b776 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java +++ b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java @@ -2,13 +2,16 @@ package com.loafle.overflow.module.sensor.dao; import com.loafle.overflow.module.sensor.model.Sensor; +import com.loafle.overflow.module.target.model.Target; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + /** * Created by root on 17. 6. 9. */ @Repository public interface SensorDAO extends JpaRepository { - + List findAllByTarget(Target target); } diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDAO.java b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDAO.java index 6e72d89..196f62f 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDAO.java +++ b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDAO.java @@ -1,14 +1,16 @@ package com.loafle.overflow.module.sensor.dao; +import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.sensor.model.SensorItem; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + /** * Created by root on 17. 6. 9. */ @Repository public interface SensorItemDAO extends JpaRepository { - -// List findAllByCrawlerId(Crawler crawler); + List findAllBySensor(Sensor sensor); } diff --git a/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java index 04e1f3b..e6921dc 100644 --- a/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java +++ b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java @@ -60,12 +60,6 @@ public class DBProxy { daoMap.put("infraOSDaemon", ctx.getBean(InfraOSDaemonDAO.class)); daoMap.put("infraOSPort", ctx.getBean(InfraOSPortDAO.class)); daoMap.put("infraService", ctx.getBean(InfraServiceDAO.class)); - -// daoMap.put("crawler", crawlerDAO); -// daoMap.put("crawlerInputItem", crawlerInputItemDAO); -// daoMap.put("crawlerInputItemMapping", crawlerInputItemMappingDAO); -// daoMap.put("sensorItemCategory", sensorItemCategoryDao); -// daoMap.put("sensorItemMapping", sensorItemMappingDao); } public void start(int port) throws IOException { diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 7c0aeb0..154caab 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -189,6 +189,41 @@ INSERT INTO public.meta_probe_package (id,create_date,architecture_id,os_id,vers INSERT INTO public.meta_probe_package (id,create_date,architecture_id,os_id,version_id) VALUES ( 16,'2017-06-25 16:59:59.522',2,4,2); +INSERT INTO public.meta_probe_status (id,"name") VALUES ( +1,'INITIAL'); +INSERT INTO public.meta_probe_status (id,"name") VALUES ( +2,'NORMAL'); + +INSERT INTO public.meta_noauth_probe_status (id,"name") VALUES ( +1,'ACCEPT'); +INSERT INTO public.meta_noauth_probe_status (id,"name") VALUES ( +2,'DENY'); +INSERT INTO public.meta_noauth_probe_status (id,"name") VALUES ( +3,'PROCESS'); + +INSERT INTO public.meta_probe_task_type (id,create_date,description,"name") VALUES ( +1,'2017-06-26 15:58:02.397','DISCOVERY START','DISCOVERY'); + +INSERT INTO public.meta_sensor_status (id,"name") VALUES ( +1,'RUNNING'); +INSERT INTO public.meta_sensor_status (id,"name") VALUES ( +2,'STOPPED'); + +INSERT INTO public.meta_sensor_item_type (id,create_date,description,"name") VALUES ( +1,'2017-06-26 19:49:39.690','CPU blah blah blah','CPU'); +INSERT INTO public.meta_sensor_item_type (id,create_date,description,"name") VALUES ( +2,'2017-06-26 19:49:39.811','MEMORY blah blah blah','MEMORY'); +INSERT INTO public.meta_sensor_item_type (id,create_date,description,"name") VALUES ( +3,'2017-06-26 19:49:39.824','DISK blah blah blah','DISK'); + +INSERT INTO public.meta_sensor_item (id,create_date,"key","name",type_id) VALUES ( +1,'2017-06-26 20:10:08.269','cpu.usage','CPU USAGE',1); +INSERT INTO public.meta_sensor_item (id,create_date,"key","name",type_id) VALUES ( +2,'2017-06-26 20:10:08.361','cpu.free','CPU FREE',1); +INSERT INTO public.meta_sensor_item (id,create_date,"key","name",type_id) VALUES ( +3,'2017-06-26 20:10:08.376','mem.usage','MEMORY USAGE',2); +INSERT INTO public.meta_sensor_item (id,create_date,"key","name",type_id) VALUES ( +4,'2017-06-26 20:10:08.394','mem.free','MEMORY FREE',2); -- -- @@ -210,30 +245,15 @@ INSERT INTO public."domain" (id,create_date,"name") VALUES ( INSERT INTO public.domain_member (id,create_date,domain_id,member_id) VALUES ( 1,'2017-06-26 11:27:43.023',1,1); - -INSERT INTO public.meta_probe_status (id,"name") VALUES ( -1,'INITIAL'); -INSERT INTO public.meta_probe_status (id,"name") VALUES ( -2,'NORMAL'); - -INSERT INTO public.meta_noauth_probe_status (id,"name") VALUES ( -1,'ACCEPT'); -INSERT INTO public.meta_noauth_probe_status (id,"name") VALUES ( -2,'DENY'); -INSERT INTO public.meta_noauth_probe_status (id,"name") VALUES ( -3,'PROCESS'); - INSERT INTO public.api_key (id,api_key,create_date,domain_id) VALUES ( 1,'52abd6fd57e511e7ac52080027658d13','2017-06-26 13:02:28.347',1); - INSERT INTO public.noauth_probe (id,api_key,create_date,host_name,ip_address,mac_address,temp_probe_key,domain_id,probe_id,status) VALUES ( 1,'52abd6fd57e511e7ac52080027658d13','2017-06-26 12:43:46.877','snoop',3232235980,8796753988883,'1cf2555c57d511e79714080027658d13',1,NULL,3); INSERT INTO public.probe (id,create_date,description,encryption_key,last_polling_date,next_polling_date,probe_key,domain_id,status) VALUES ( 1,'2017-06-26 12:44:59.813','snoop probe','9c8d41ab57de11e7a2c9080027658d13',NULL,NULL,'a1e1710557de11e78799080027658d13',1,1); - INSERT INTO public.infra_machine (id,create_date,meta,probe_id) VALUES ( 0,'2017-06-26 12:12:11.698',NULL,1); @@ -243,10 +263,3 @@ INSERT INTO public.infra (id,child_id,create_date,type_id) VALUES ( INSERT INTO public.target (id,create_date,infra_id,probe_id) VALUES ( 1,'2017-06-26 12:37:22.854',1,1); -INSERT INTO public.meta_probe_task_type (id,create_date,description,"name") VALUES ( -1,'2017-06-26 15:58:02.397','DISCOVERY START','DISCOVERY'); - -INSERT INTO public.meta_sensor_status (id,"name") VALUES ( -1,'RUNNING'); -INSERT INTO public.meta_sensor_status (id,"name") VALUES ( -2,'STOPPED'); \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/meta/dao/MetaSensorItemDAOTest.java b/src/test/java/com/loafle/overflow/meta/dao/MetaSensorItemDAOTest.java new file mode 100644 index 0000000..4948b8d --- /dev/null +++ b/src/test/java/com/loafle/overflow/meta/dao/MetaSensorItemDAOTest.java @@ -0,0 +1,66 @@ +package com.loafle.overflow.meta.dao; + +import com.loafle.overflow.AppConfig; +import com.loafle.overflow.JdbcConfiguration; +import com.loafle.overflow.meta.model.MetaSensorItem; +import com.loafle.overflow.meta.model.MetaSensorItemType; +import org.junit.Ignore; +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.Date; + +/** + * Created by snoop on 17. 6. 26. + */ +@Ignore +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) +public class MetaSensorItemDAOTest { + + @Autowired + private MetaSensorItemDAO dao; + + @Test + public void Create() { + MetaSensorItemType cpuType = new MetaSensorItemType(); + cpuType.setId((short)1); + + MetaSensorItemType memType = new MetaSensorItemType(); + memType.setId((short)2); + + MetaSensorItem item1 = new MetaSensorItem(); + item1.setMetaSensorItemType(cpuType); + item1.setKey("cpu.usage"); + item1.setName("CPU USAGE"); + item1.setCreateDate(new Date()); + dao.save(item1); + + MetaSensorItem item2 = new MetaSensorItem(); + item2.setMetaSensorItemType(cpuType); + item2.setKey("cpu.free"); + item2.setName("CPU FREE"); + item2.setCreateDate(new Date()); + dao.save(item2); + + MetaSensorItem item3 = new MetaSensorItem(); + item3.setMetaSensorItemType(memType); + item3.setKey("mem.usage"); + item3.setName("MEMORY USAGE"); + item3.setCreateDate(new Date()); + dao.save(item3); + + MetaSensorItem item4 = new MetaSensorItem(); + item4.setMetaSensorItemType(memType); + item4.setKey("mem.free"); + item4.setName("MEMORY FREE"); + item4.setCreateDate(new Date()); + dao.save(item4); + + + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/meta/dao/MetaSensorItemTypeDAOTest.java b/src/test/java/com/loafle/overflow/meta/dao/MetaSensorItemTypeDAOTest.java new file mode 100644 index 0000000..67c3c21 --- /dev/null +++ b/src/test/java/com/loafle/overflow/meta/dao/MetaSensorItemTypeDAOTest.java @@ -0,0 +1,48 @@ +package com.loafle.overflow.meta.dao; + +import com.loafle.overflow.AppConfig; +import com.loafle.overflow.JdbcConfiguration; +import com.loafle.overflow.meta.model.MetaSensorItemType; +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.Date; + +/** + * Created by snoop on 17. 6. 26. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) +public class MetaSensorItemTypeDAOTest { + + @Autowired + private MetaSensorItemTypeDAO dao; + + @Test + public void Create() { + MetaSensorItemType category1 = new MetaSensorItemType(); + category1.setId((short)1); + category1.setCreateDate(new Date()); + category1.setName("CPU"); + category1.setDescription("CPU blah blah blah"); + dao.save(category1); + + MetaSensorItemType category2 = new MetaSensorItemType(); + category2.setId((short)2); + category2.setCreateDate(new Date()); + category2.setName("MEMORY"); + category2.setDescription("MEMORY blah blah blah"); + dao.save(category2); + + MetaSensorItemType category3 = new MetaSensorItemType(); + category3.setId((short)3); + category3.setCreateDate(new Date()); + category3.setName("DISK"); + category3.setDescription("DISK blah blah blah"); + dao.save(category3); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/module/sensor/dao/SensorDAOTest.java b/src/test/java/com/loafle/overflow/module/sensor/dao/SensorDAOTest.java index 4ab33bb..17d3bd6 100644 --- a/src/test/java/com/loafle/overflow/module/sensor/dao/SensorDAOTest.java +++ b/src/test/java/com/loafle/overflow/module/sensor/dao/SensorDAOTest.java @@ -7,16 +7,16 @@ import com.loafle.overflow.meta.model.MetaCrawlerInputItem; import com.loafle.overflow.meta.model.MetaSensorStatus; import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.target.model.Target; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; 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.Date; +import java.util.List; +@Ignore @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) public class SensorDAOTest { @@ -27,6 +27,7 @@ public class SensorDAOTest { @Before public void setUp() throws Exception { + create(); } @After @@ -58,5 +59,12 @@ public class SensorDAOTest { sensorDAO.save(sensor); } + @Test + public void list() { + Target t = new Target(); + t.setId(1); + List sensors = this.sensorDAO.findAllByTarget(t); + Assert.assertEquals(2, sensors.size()); + } } \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java b/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java index 1a3ec1c..769b124 100644 --- a/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java +++ b/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java @@ -6,6 +6,7 @@ import com.loafle.overflow.module.infra.model.Infra; import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.target.model.Target; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +16,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Date; import java.util.List; +@Ignore @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) public class TargetDAOTest {