From ad07199a2f129ea7894dcd9c152f9b16e2044fe3 Mon Sep 17 00:00:00 2001 From: crusader Date: Mon, 11 Jun 2018 21:24:55 +0900 Subject: [PATCH] ing --- .../service/CentralAuthCrawlerService.java | 55 --------------- .../generator/service/InfraHostGenerator.java | 29 ++++---- .../service/InfraServiceGenerator.java | 67 +++++++++---------- .../module/infra/dao/InfraHostDAO.java | 2 - .../module/infra/dao/InfraServiceDAO.java | 9 ++- src/main/resources/local/init.sql | 2 +- .../auth/service/AuthCrawlerServiceTest.java | 58 ---------------- 7 files changed, 52 insertions(+), 170 deletions(-) delete mode 100644 src/main/java/com/loafle/overflow/central/module/auth/service/CentralAuthCrawlerService.java delete mode 100644 src/test/java/com/loafle/overflow/central/module/auth/service/AuthCrawlerServiceTest.java diff --git a/src/main/java/com/loafle/overflow/central/module/auth/service/CentralAuthCrawlerService.java b/src/main/java/com/loafle/overflow/central/module/auth/service/CentralAuthCrawlerService.java deleted file mode 100644 index d8f876b..0000000 --- a/src/main/java/com/loafle/overflow/central/module/auth/service/CentralAuthCrawlerService.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.loafle.overflow.central.module.auth.service; - -import com.loafle.overflow.central.module.auth.dao.AuthCrawlerDAO; - -import com.loafle.overflow.central.module.infra.service.CentralInfraService; -import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.auth.AuthCrawler; -import com.loafle.overflow.model.infra.Infra; -import com.loafle.overflow.model.meta.MetaCrawler; -import com.loafle.overflow.service.central.auth.AuthCrawlerService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * Created by snoop on 17. 8. 30. - */ -@Service("AuthCrawlerService") -public class CentralAuthCrawlerService implements AuthCrawlerService { - - @Autowired - private AuthCrawlerDAO authCrawlerDAO; - - @Autowired - private CentralInfraService infraService; - - public AuthCrawler regist(AuthCrawler authCrawler) { - // if (authCrawler == null) { - // return this.authCrawlerDAO.save(authCrawler); - // } - - AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(authCrawler.getMetaCrawler().getId(), - authCrawler.getTarget().getId()); - - dbAuthCrawler.setAuthJson(authCrawler.getAuthJson()); - dbAuthCrawler.setMetaCrawler(authCrawler.getMetaCrawler()); - dbAuthCrawler.setTarget(authCrawler.getTarget()); - - return this.authCrawlerDAO.save(dbAuthCrawler); - } - - public boolean checkAuthCrawler(Long infraId, MetaCrawler metaCrawler, String authJson) throws OverflowException { - - Infra infra = this.infraService.read(infraId); - - // FIXME: Check Crawler on Probe - - return false; - } - - public AuthCrawler readByMetaCrawlerIDAndTargetID(Short metaCrawlerID, Long targetID) throws OverflowException { - - return this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(metaCrawlerID, targetID); - } - -} diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java index 2821ecc..3112d9f 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.generator.service; -import com.loafle.overflow.core.type.PortType; import com.loafle.overflow.model.auth.AuthCrawler; import com.loafle.overflow.model.infra.Infra; import com.loafle.overflow.model.infra.InfraHost; @@ -12,7 +11,6 @@ import com.loafle.overflow.model.sensorconfig.Crawler; import com.loafle.overflow.model.sensorconfig.Schedule; import com.loafle.overflow.model.sensorconfig.SensorConfig; import com.loafle.overflow.model.sensorconfig.Target; -import com.loafle.overflow.service.central.auth.AuthCrawlerService; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.type.TypeReference; @@ -35,9 +33,6 @@ public class InfraHostGenerator { @Autowired private InfraHostWMIGenerator infraHostWMIGenerator; - @Autowired - private AuthCrawlerService authCrawlerService; - @Autowired private ObjectMapper objectMapper; @@ -75,20 +70,20 @@ public class InfraHostGenerator { private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception { - AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(), - dbSensor.getTarget().getId()); + // AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(), + // dbSensor.getTarget().getId()); - if (authCrawler == null) { - return null; - } + // if (authCrawler == null) { + // return null; + // } - Target target = new Target(); - Connection connection = new Connection(); - // connection.setIp(infraHost.getIpv4()); + // Target target = new Target(); + // Connection connection = new Connection(); + // // connection.setIp(infraHost.getIpv4()); - HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), - new TypeReference>() { - }); + // HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), + // new TypeReference>() { + // }); // if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { // connection.setPort(135); @@ -105,6 +100,6 @@ public class InfraHostGenerator { // } - return target; + return null; } } diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java index 4294b84..31f5f3a 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.generator.service; -import com.loafle.overflow.core.type.PortType; import com.loafle.overflow.model.auth.AuthCrawler; import com.loafle.overflow.model.infra.Infra; import com.loafle.overflow.model.infra.InfraService; @@ -38,9 +37,6 @@ public class InfraServiceGenerator { @Autowired private InfraServiceJMXGenerator infraServiceJMXGenerator; - @Autowired - private AuthCrawlerService authCrawlerService; - @Autowired private ObjectMapper objectMapper; @@ -79,41 +75,42 @@ public class InfraServiceGenerator { private Target createTarget(InfraService infraService, Sensor sensor) throws Exception { - AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(), - sensor.getTarget().getId()); + // AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(), + // sensor.getTarget().getId()); - if (authCrawler == null) { - return null; - } - - Target target = new Target(); - Connection connection = new Connection(); - // connection.setIp(infraService.getInfraHost().getIpv4()); - // connection.setPort(infraService.getPort()); - // connection.setPortType(PortType.valueOf(infraService.getPortType())); - // connection.setSsl(infraService.isTlsType()); - - target.setConnection(connection); - - HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), - new TypeReference>() { - }); - - Map auth = new HashMap<>(); - - // if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { - // auth.put("url", "jdbc:mysql://" + infraService.getInfraHost().getIpv4() + ":" + infraService.getPort()); - // auth.put("id", optionMap.get("ID")); // FIXME: Auth Info - // auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info - // } else if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { - // auth.put("id", optionMap.get("ID")); // FIXME: Auth Info - // auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info - // connection.setPort(9840); + // if (authCrawler == null) { + // return null; // } - target.setAuth(auth); + // Target target = new Target(); + // Connection connection = new Connection(); + // // connection.setIp(infraService.getInfraHost().getIpv4()); + // // connection.setPort(infraService.getPort()); + // // connection.setPortType(PortType.valueOf(infraService.getPortType())); + // // connection.setSsl(infraService.isTlsType()); - return target; + // target.setConnection(connection); + + // HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), + // new TypeReference>() { + // }); + + // Map auth = new HashMap<>(); + + // // if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { + // // auth.put("url", "jdbc:mysql://" + infraService.getInfraHost().getIpv4() + ":" + infraService.getPort()); + // // auth.put("id", optionMap.get("ID")); // FIXME: Auth Info + // // auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info + // // } else if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { + // // auth.put("id", optionMap.get("ID")); // FIXME: Auth Info + // // auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info + // // connection.setPort(9840); + // // } + + // target.setAuth(auth); + + // return target; + return null; } } 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 d030841..6966330 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 @@ -9,6 +9,4 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraHostDAO extends JpaRepository { - InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4); - } \ 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 5b16135..71132ce 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 @@ -2,6 +2,8 @@ package com.loafle.overflow.central.module.infra.dao; import com.loafle.overflow.model.infra.InfraService; 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; /** @@ -9,5 +11,8 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraServiceDAO extends JpaRepository { - InfraService findByInfraHostIdAndPortAndPortType(Long infraHostId, Integer port, String portType); -} \ No newline at end of file + @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, + @Param("port") Integer port); +} diff --git a/src/main/resources/local/init.sql b/src/main/resources/local/init.sql index 59d35a3..48c7735 100644 --- a/src/main/resources/local/init.sql +++ b/src/main/resources/local/init.sql @@ -838,7 +838,7 @@ INSERT INTO public.infra (id, meta_infra_type_id, probe_id) VALUES (3, 3, 1); 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, meta_target_host_type_id) VALUES (2, 127); +INSERT INTO public.infra_host (id, infra_zone_id, meta_target_host_type_id) VALUES (2, 1, 127); INSERT INTO public.infra_host_ip (id, infra_host_id, meta_ip_type_id "address", mac) VALUES (1, 2, 1, '192.168.1.101', '44:8a:5b:f1:f1:f3'); INSERT INTO public.infra_host_port (id, infra_host_id, meta_port_type_id "address", mac) VALUES (1, 2, 1, 5432); diff --git a/src/test/java/com/loafle/overflow/central/module/auth/service/AuthCrawlerServiceTest.java b/src/test/java/com/loafle/overflow/central/module/auth/service/AuthCrawlerServiceTest.java deleted file mode 100644 index 0485d5b..0000000 --- a/src/test/java/com/loafle/overflow/central/module/auth/service/AuthCrawlerServiceTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.loafle.overflow.central.module.auth.service; - -import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.auth.AuthCrawler; -import com.loafle.overflow.model.meta.MetaCrawler; -import com.loafle.overflow.model.target.Target; -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. 8. 30. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) -public class AuthCrawlerServiceTest { - - @Autowired - private CentralAuthCrawlerService authCrawlerService; - - @Test - public void regist() throws Exception { - - AuthCrawler authCrawler = new AuthCrawler(); - - Target target = new Target(); - target.setId(Long.valueOf(4)); - - authCrawler.setTarget(target); - - - MetaCrawler metaCrawler = new MetaCrawler(); - metaCrawler.setId((short)11); - - authCrawler.setMetaCrawler(metaCrawler); - - authCrawler.setAuthJson("{\"DB Name\":\"test\",\"ID\":\"docker\",\"PassWord\":\"qwer5795QWER\"}"); - - - this.authCrawlerService.regist(authCrawler); - - Assert.assertNotEquals(authCrawler.getId().longValue(), 0); - - } - - @Test - public void findAuth() throws OverflowException { - AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID((short)23, Long.valueOf(5)); - - Assert.assertNotEquals(authCrawler, null); - - } - -} \ No newline at end of file