This commit is contained in:
crusader 2018-04-24 21:57:05 +09:00
parent 8625e10e00
commit 591f5f5e9a
21 changed files with 330 additions and 369 deletions

14
pom.xml
View File

@ -25,10 +25,10 @@
<spring.data.jpa.version>1.11.4.RELEASE</spring.data.jpa.version> <spring.data.jpa.version>1.11.4.RELEASE</spring.data.jpa.version>
<spring.data.redis.version>1.8.7.RELEASE</spring.data.redis.version> <spring.data.redis.version>1.8.7.RELEASE</spring.data.redis.version>
<spring.crypto.version>4.2.3.RELEASE</spring.crypto.version> <spring.crypto.version>4.2.3.RELEASE</spring.crypto.version>
<gson.version>2.8.2</gson.version>
<hibernate.version>5.2.10.Final</hibernate.version> <hibernate.version>5.2.10.Final</hibernate.version>
<javax.mail.version>1.4.7</javax.mail.version> <javax.mail.version>1.4.7</javax.mail.version>
<javax.mail-api.version>1.6.0</javax.mail-api.version> <javax.mail-api.version>1.6.0</javax.mail-api.version>
<jackson.mapper.version>1.9.13</jackson.mapper.version>
<apache.velocity.version>1.7</apache.velocity.version> <apache.velocity.version>1.7</apache.velocity.version>
<docker.registry.name>docker.loafle.net/overflow</docker.registry.name> <docker.registry.name>docker.loafle.net/overflow</docker.registry.name>
<googleauth.version>1.1.2</googleauth.version> <googleauth.version>1.1.2</googleauth.version>
@ -97,12 +97,6 @@
<version>9.4-1200-jdbc41</version> <version>9.4-1200-jdbc41</version>
</dependency> </dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.mapper.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager --> <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency> <dependency>
@ -124,6 +118,12 @@
<version>${spring.crypto.version}</version> <version>${spring.crypto.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<!-- Mail --> <!-- Mail -->
<!-- https://mvnrepository.com/artifact/javax.mail/mail --> <!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency> <dependency>

View File

@ -1,7 +1,5 @@
package com.loafle.overflow.central.module.discovery.service; package com.loafle.overflow.central.module.discovery.service;
import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.commons.service.MessagePublisher;
import com.loafle.overflow.central.commons.utils.SessionMetadata; import com.loafle.overflow.central.commons.utils.SessionMetadata;
import com.loafle.overflow.core.annotation.ProbeAPI; import com.loafle.overflow.core.annotation.ProbeAPI;
@ -10,11 +8,9 @@ import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.discovery.*; import com.loafle.overflow.model.discovery.*;
import com.loafle.overflow.service.central.discovery.DiscoveryService; import com.loafle.overflow.service.central.discovery.DiscoveryService;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.Date; import java.util.Date;
/** /**
@ -23,76 +19,68 @@ import java.util.Date;
@Service("DiscoveryService") @Service("DiscoveryService")
public class CentralDiscoveryService implements DiscoveryService { public class CentralDiscoveryService implements DiscoveryService {
@Autowired @Autowired
private MessagePublisher messagePublisher; private MessagePublisher messagePublisher;
public void startDiscovery(DiscoveryStartInfo startInfo) throws OverflowException,IOException { @WebappAPI
public void discoverZone(String probeID, DiscoverZone discoveryZone) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID();
ObjectMapper objectMapper = new ObjectMapper(); messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverZone", requesterSessionID, discoveryZone);
}
String json = objectMapper.writeValueAsString(startInfo); @WebappAPI
public void discoverHost(String probeID, Zone zone, DiscoverHost discoveryHost) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID();
System.out.println("Start Discovery"); messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverHost", requesterSessionID, zone, discoveryHost);
System.out.println(json); }
// this.messagePublisher.publishToProbe("/auth", noAuthProbe.getTempProbeKey(), "NoAuthProbeService.acceptNoAuthProbe", probe.getProbeKey());
}
@WebappAPI @WebappAPI
public void discoverZone(String probeID, DiscoverZone discoveryZone) throws OverflowException { public void discoverPort(String probeID, Host host, DiscoverPort discoveryPort) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID(); String requesterSessionID = SessionMetadata.getSessionID();
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverZone", requesterSessionID, discoveryZone); messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverPort", requesterSessionID, host, discoveryPort);
} }
@WebappAPI @WebappAPI
public void discoverHost(String probeID, Zone zone, DiscoverHost discoveryHost) throws OverflowException { public void discoverService(String probeID, Port port,
String requesterSessionID = SessionMetadata.getSessionID(); com.loafle.overflow.model.discovery.DiscoverService discoveryService) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID();
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverHost", requesterSessionID, zone, discoveryHost); messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverService", requesterSessionID, port,
} discoveryService);
}
@WebappAPI @ProbeAPI
public void discoverPort(String probeID, Host host, DiscoverPort discoveryPort) throws OverflowException { public void discoverStart(String requesterSessionID, Date startDate) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID(); messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStart", startDate);
}
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverPort", requesterSessionID, host, discoveryPort); @ProbeAPI
} public void discoverStop(String requesterSessionID, Date stopDate) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStop", stopDate);
}
@WebappAPI @ProbeAPI
public void discoverService(String probeID, Port port, com.loafle.overflow.model.discovery.DiscoverService discoveryService) throws OverflowException { public void discoveredZone(String requesterSessionID, Zone zone) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID(); messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredZone", zone);
}
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverService", requesterSessionID, port, discoveryService); @ProbeAPI
} public void discoveredHost(String requesterSessionID, Host host) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredHost", host);
}
@ProbeAPI @ProbeAPI
public void discoverStart(String requesterSessionID, Date startDate) throws OverflowException { public void discoveredPort(String requesterSessionID, Port port) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStart", startDate); messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredPort", port);
} }
@ProbeAPI @ProbeAPI
public void discoverStop(String requesterSessionID, Date stopDate) throws OverflowException { public void discoveredService(String requesterSessionID, com.loafle.overflow.model.discovery.Service service)
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStop", stopDate); throws OverflowException {
} messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredService", service);
}
@ProbeAPI
public void discoveredZone(String requesterSessionID, Zone zone) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredZone", zone);
}
@ProbeAPI
public void discoveredHost(String requesterSessionID, Host host) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredHost", host);
}
@ProbeAPI
public void discoveredPort(String requesterSessionID, Port port) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredPort", port);
}
@ProbeAPI
public void discoveredService(String requesterSessionID, com.loafle.overflow.model.discovery.Service service) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredService", service);
}
} }

View File

@ -1,5 +1,7 @@
package com.loafle.overflow.central.module.generator.service; package com.loafle.overflow.central.module.generator.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.central.commons.utils.StringConvertor; import com.loafle.overflow.central.commons.utils.StringConvertor;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.type.PortType; import com.loafle.overflow.core.type.PortType;
@ -17,8 +19,6 @@ import com.loafle.overflow.model.sensorconfig.SensorConfig;
import com.loafle.overflow.model.sensorconfig.Target; import com.loafle.overflow.model.sensorconfig.Target;
import com.loafle.overflow.service.central.auth.AuthCrawlerService; import com.loafle.overflow.service.central.auth.AuthCrawlerService;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -32,81 +32,79 @@ import java.util.Map;
@Service("InfraHostGenerator") @Service("InfraHostGenerator")
public class InfraHostGenerator { public class InfraHostGenerator {
@Autowired @Autowired
private GenerateUtil generateUtil; private GenerateUtil generateUtil;
@Autowired @Autowired
private InfraHostWMIGenerator infraHostWMIGenerator; private InfraHostWMIGenerator infraHostWMIGenerator;
@Autowired @Autowired
private AuthCrawlerService authCrawlerService; private AuthCrawlerService authCrawlerService;
public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception { @Autowired
private Gson gson;
InfraHost infraHost = (InfraHost) infra; public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception {
SensorConfig sensorConfig = new SensorConfig(); InfraHost infraHost = (InfraHost) infra;
sensorConfig.setConfigID(String.valueOf(dbSensor.getId()));
Target target = this.createTarget(infraHost, dbSensor); SensorConfig sensorConfig = new SensorConfig();
sensorConfig.setConfigID(String.valueOf(dbSensor.getId()));
if (target == null) { Target target = this.createTarget(infraHost, dbSensor);
return null;
}
sensorConfig.setTarget(target); if (target == null) {
return null;
// FIXME: Interval
Schedule schedule = new Schedule();
schedule.setInterval("5");
sensorConfig.setSchedule(schedule);
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler());
sensorConfig.setCrawler(crawler);
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler());
if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
}
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(sensorConfig);
} }
private Target createTarget(InfraHost infraHost, Sensor dbSensor) sensorConfig.setTarget(target);
throws Exception {
AuthCrawler authCrawler = this.authCrawlerService.readAuth(dbSensor.getCrawler(), dbSensor.getTarget()); // FIXME: Interval
Schedule schedule = new Schedule();
schedule.setInterval("5");
sensorConfig.setSchedule(schedule);
if (authCrawler == null) { Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler());
return null; sensorConfig.setCrawler(crawler);
}
Target target = new Target(); Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler());
Connection connection = new Connection();
connection.setIp(StringConvertor.intToIp(infraHost.getIp()));
HashMap<String, String> optionMap; if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
optionMap = new ObjectMapper().readValue(authCrawler.getAuthJson(), this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
new TypeReference<HashMap<String, String>>() {
});
if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
connection.setPort(135);
connection.setPortType(PortType.TCP);
connection.setSsl(false);
target.setConnection(connection);
Map<String, Object> auth = new HashMap<>();
auth.put("id", optionMap.get("ID"));
auth.put("pw", optionMap.get("PassWord"));
target.setAuth(auth);
}
return target;
} }
return gson.toJson(sensorConfig);
}
private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception {
AuthCrawler authCrawler = this.authCrawlerService.readAuth(dbSensor.getCrawler(), dbSensor.getTarget());
if (authCrawler == null) {
return null;
}
Target target = new Target();
Connection connection = new Connection();
connection.setIp(StringConvertor.intToIp(infraHost.getIp()));
HashMap<String, String> optionMap = this.gson.fromJson(authCrawler.getAuthJson(), TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
connection.setPort(135);
connection.setPortType(PortType.TCP);
connection.setSsl(false);
target.setConnection(connection);
Map<String, Object> auth = new HashMap<>();
auth.put("id", optionMap.get("ID"));
auth.put("pw", optionMap.get("PassWord"));
target.setAuth(auth);
}
return target;
}
} }

View File

@ -1,5 +1,7 @@
package com.loafle.overflow.central.module.generator.service; package com.loafle.overflow.central.module.generator.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.model.meta.MetaSensorItemKey;
import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.sensor.Sensor;
import com.loafle.overflow.model.sensor.SensorItem; import com.loafle.overflow.model.sensor.SensorItem;
@ -9,8 +11,6 @@ import com.loafle.overflow.model.sensorconfig.MappingInfo;
import com.loafle.overflow.model.sensorconfig.QueryInfo; import com.loafle.overflow.model.sensorconfig.QueryInfo;
import com.loafle.overflow.model.sensorconfig.SensorConfig; import com.loafle.overflow.model.sensorconfig.SensorConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,6 +29,9 @@ public class InfraHostWMIGenerator {
@Autowired @Autowired
private GenerateUtil generateUtil; private GenerateUtil generateUtil;
@Autowired
private Gson gson;
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
SensorConfig sensorConfig) throws Exception { SensorConfig sensorConfig) throws Exception {
@ -84,9 +87,7 @@ public class InfraHostWMIGenerator {
String json = tempItemKey.getOption(); String json = tempItemKey.getOption();
if (json != null && json.length() > 0) { if (json != null && json.length() > 0) {
HashMap<String, Object> optionMap; HashMap<String, String> optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String, Object>>() {
});
Object obj = null; Object obj = null;
obj = optionMap.get("appends"); obj = optionMap.get("appends");

View File

@ -1,5 +1,7 @@
package com.loafle.overflow.central.module.generator.service; package com.loafle.overflow.central.module.generator.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.central.commons.utils.StringConvertor; import com.loafle.overflow.central.commons.utils.StringConvertor;
import com.loafle.overflow.core.type.PortType; import com.loafle.overflow.core.type.PortType;
import com.loafle.overflow.model.auth.AuthCrawler; import com.loafle.overflow.model.auth.AuthCrawler;
@ -16,8 +18,6 @@ import com.loafle.overflow.model.sensorconfig.SensorConfig;
import com.loafle.overflow.model.sensorconfig.Target; import com.loafle.overflow.model.sensorconfig.Target;
import com.loafle.overflow.service.central.auth.AuthCrawlerService; import com.loafle.overflow.service.central.auth.AuthCrawlerService;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -44,6 +44,9 @@ public class InfraServiceGenerator {
@Autowired @Autowired
private AuthCrawlerService authCrawlerService; private AuthCrawlerService authCrawlerService;
@Autowired
private Gson gson;
public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception { public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception {
com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService)infra; com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService)infra;
@ -75,8 +78,7 @@ public class InfraServiceGenerator {
this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
} }
ObjectMapper objectMapper = new ObjectMapper(); return gson.toJson(sensorConfig);
return objectMapper.writeValueAsString(sensorConfig);
} }
private Target createTarget(InfraService infraService, Sensor sensor) throws Exception { private Target createTarget(InfraService infraService, Sensor sensor) throws Exception {
@ -96,8 +98,7 @@ public class InfraServiceGenerator {
target.setConnection(connection); target.setConnection(connection);
HashMap<String,String> optionMap; HashMap<String, String> optionMap = this.gson.fromJson(authCrawler.getAuthJson(), TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
optionMap = new ObjectMapper().readValue(authCrawler.getAuthJson(), new TypeReference<HashMap<String,String>>() {});
Map<String, Object> auth = new HashMap<>(); Map<String, Object> auth = new HashMap<>();

View File

@ -1,5 +1,7 @@
package com.loafle.overflow.central.module.generator.service; package com.loafle.overflow.central.module.generator.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.model.meta.MetaSensorItemKey;
import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.sensor.Sensor;
import com.loafle.overflow.model.sensor.SensorItem; import com.loafle.overflow.model.sensor.SensorItem;
@ -9,8 +11,6 @@ import com.loafle.overflow.model.sensorconfig.MappingInfo;
import com.loafle.overflow.model.sensorconfig.QueryInfo; import com.loafle.overflow.model.sensorconfig.QueryInfo;
import com.loafle.overflow.model.sensorconfig.SensorConfig; import com.loafle.overflow.model.sensorconfig.SensorConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -28,6 +28,9 @@ public class InfraServiceJMXGenerator {
@Autowired @Autowired
private GenerateUtil generateUtil; private GenerateUtil generateUtil;
@Autowired
private Gson gson;
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
SensorConfig sensorConfig) throws Exception { SensorConfig sensorConfig) throws Exception {
Map<String, List<MetaSensorItemKey>> metricMap = null; Map<String, List<MetaSensorItemKey>> metricMap = null;
@ -70,9 +73,7 @@ public class InfraServiceJMXGenerator {
List<String> arrayCol = null; List<String> arrayCol = null;
if (json != null && json.length() > 0) { if (json != null && json.length() > 0) {
HashMap<String, Object> optionMap; HashMap<String, String> optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String, Object>>() {
});
Object obj = null; Object obj = null;
obj = optionMap.get("aliases"); obj = optionMap.get("aliases");

View File

@ -1,5 +1,7 @@
package com.loafle.overflow.central.module.generator.service; package com.loafle.overflow.central.module.generator.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.model.meta.MetaSensorItemKey;
import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.sensor.Sensor;
@ -10,10 +12,6 @@ import com.loafle.overflow.model.sensorconfig.MappingInfo;
import com.loafle.overflow.model.sensorconfig.QueryInfo; import com.loafle.overflow.model.sensorconfig.QueryInfo;
import com.loafle.overflow.model.sensorconfig.SensorConfig; import com.loafle.overflow.model.sensorconfig.SensorConfig;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -31,6 +29,8 @@ public class InfraServiceMysqlGenerator {
@Autowired @Autowired
private GenerateUtil generateUtil; private GenerateUtil generateUtil;
@Autowired
private Gson gson;
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
SensorConfig sensorConfig) throws Exception { SensorConfig sensorConfig) throws Exception {
@ -83,9 +83,7 @@ public class InfraServiceMysqlGenerator {
String json = tempItemKey.getOption(); String json = tempItemKey.getOption();
if (json != null && json.length() > 0) { if (json != null && json.length() > 0) {
HashMap<String, Object> optionMap; HashMap<String, String> optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String, Object>>() {
});
Object obj = null; Object obj = null;
obj = optionMap.get("valueColumn"); obj = optionMap.get("valueColumn");

View File

@ -4,10 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.List; import java.util.List;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.model.PageParams; import com.loafle.overflow.core.model.PageParams;
import com.loafle.overflow.model.infra.Infra; import com.loafle.overflow.model.infra.Infra;
import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.sensor.Sensor;

View File

@ -1,5 +1,7 @@
package com.loafle.overflow.central.module.noauthprobe.service; package com.loafle.overflow.central.module.noauthprobe.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.commons.service.MessagePublisher;
import com.loafle.overflow.central.commons.stereotype.ProbeAPI; import com.loafle.overflow.central.commons.stereotype.ProbeAPI;
import com.loafle.overflow.central.commons.stereotype.WebappAPI; import com.loafle.overflow.central.commons.stereotype.WebappAPI;
@ -20,8 +22,6 @@ import com.loafle.overflow.service.central.domain.DomainMemberService;
import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService; import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
import com.loafle.overflow.service.central.probe.ProbeService; import com.loafle.overflow.service.central.probe.ProbeService;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -46,15 +46,15 @@ public class CentralNoAuthProbeService implements NoAuthProbeService{
@Autowired @Autowired
private ProbeService probeService; private ProbeService probeService;
@Autowired
private ObjectMapper objectMapper;
@Autowired @Autowired
private MessagePublisher messagePublisher; private MessagePublisher messagePublisher;
@Autowired @Autowired
private DomainMemberService domainMemberService; private DomainMemberService domainMemberService;
@Autowired
private Gson gson;
@ProbeAPI @ProbeAPI
public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException{ public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException{
@ -99,12 +99,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService{
probe.setAuthorizeMember(new Member(domainMember.getMember().getId())); probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
probe.setStatus(new MetaProbeStatus((short)1)); probe.setStatus(new MetaProbeStatus((short)1));
Map<String, Object> objMap = null; HashMap<String, Object> objMap = this.gson.fromJson(noAuthProbe.getDescription(), TypeToken.getParameterized(HashMap.class, String.class, Object.class).getType());
try {
objMap = this.objectMapper.readValue(noAuthProbe.getDescription(), new TypeReference<HashMap<String,Object>>() {});
} catch (Exception e) {
e.printStackTrace();
}
Map<String, String> hostMap = (Map<String, String>) objMap.get("host"); Map<String, String> hostMap = (Map<String, String>) objMap.get("host");
Map<String, String> netMap = (Map<String, String>) objMap.get("network"); Map<String, String> netMap = (Map<String, String>) objMap.get("network");

View File

@ -1,18 +1,15 @@
package com.loafle.overflow.central.proxy; package com.loafle.overflow.central.proxy;
import com.google.gson.internal.Primitives; import com.google.gson.Gson;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.JavaType;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -26,15 +23,13 @@ public class ServiceInvoker {
// @Autowired // @Autowired
private ApplicationContext context; private ApplicationContext context;
private ObjectMapper objectMapper;
private Map<String, Cache> serviceCacheMap; private Map<String, Cache> serviceCacheMap;
@Autowired
private Gson gson;
public ServiceInvoker(ApplicationContext context) { public ServiceInvoker(ApplicationContext context) {
this.context = context; this.context = context;
objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
serviceCacheMap = new HashMap<>(); serviceCacheMap = new HashMap<>();
} }
@ -122,15 +117,7 @@ public class ServiceInvoker {
} }
private Object getValue(Type parameterType, String json) throws IllegalArgumentException { private Object getValue(Type parameterType, String json) throws IllegalArgumentException {
JavaType targetType = objectMapper.getTypeFactory().constructType(parameterType); return this.gson.fromJson(json, parameterType);
if (!Primitives.isPrimitive(parameterType) && !parameterType.getTypeName().equals(String.class.getName())) {
try {
return objectMapper.readValue(json, targetType);
} catch (IOException e) {
throw new IllegalArgumentException("");
}
}
return objectMapper.convertValue(json, targetType);
} }
private Object[] getParameters(Type[] parameterTypes, List<ByteString> params) throws IllegalArgumentException { private Object[] getParameters(Type[] parameterTypes, List<ByteString> params) throws IllegalArgumentException {
@ -187,11 +174,7 @@ public class ServiceInvoker {
throw new OverflowException("internal error", e); throw new OverflowException("internal error", e);
} }
try { jsonInString = this.gson.toJson(result);
jsonInString = objectMapper.writeValueAsString(result);
} catch (IOException e) {
throw new OverflowException("internal error", e);
}
return jsonInString; return jsonInString;
} }

View File

@ -1,12 +1,12 @@
package com.loafle.overflow.central.redis.service; package com.loafle.overflow.central.redis.service;
import com.google.gson.Gson;
import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.commons.service.MessagePublisher;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.model.PublishMessage; import com.loafle.overflow.core.model.PublishMessage;
import com.loafle.overflow.model.member.Member; import com.loafle.overflow.model.member.Member;
import com.loafle.overflow.service.central.member.MemberService; import com.loafle.overflow.service.central.member.MemberService;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -20,114 +20,113 @@ import java.util.Map;
@Service @Service
public class RedisMessagePublisher implements MessagePublisher { public class RedisMessagePublisher implements MessagePublisher {
private static final String CHANNEL_WEBAPP = "/webapp"; private static final String CHANNEL_WEBAPP = "/webapp";
private static final String CHANNEL_NOAUTH_PROBE = "/auth"; private static final String CHANNEL_NOAUTH_PROBE = "/auth";
private static final String CHANNEL_PROBE = "/probe"; private static final String CHANNEL_PROBE = "/probe";
@Autowired @Autowired
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@Autowired @Autowired
private ObjectMapper objectMapper; private Gson gson;
@Autowired @Autowired
private MemberService memberService; private MemberService memberService;
private Map<String, ChannelTopic> topics; private Map<String, ChannelTopic> topics;
public RedisMessagePublisher() { public RedisMessagePublisher() {
}
public RedisMessagePublisher(final RedisTemplate<String, Object> redisTemplate,
final Map<String, ChannelTopic> topics) {
this.redisTemplate = redisTemplate;
this.topics = topics;
}
public void publishToDomainMembers(final long domainID, final String method, final Object... params)
throws OverflowException {
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.MEMBER);
message.setTargets(getMemberListByDomainID(domainID));
this.publish(CHANNEL_WEBAPP, message, method, params);
}
public void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params)
throws OverflowException {
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.MEMBER);
message.setTargets(getMemberListByProbeKey(probeKey));
this.publish(CHANNEL_WEBAPP, message, method, params);
}
public void publishToMember(final String memberID, final String method, final Object... params)
throws OverflowException {
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.MEMBER);
message.addTarget(memberID);
this.publish(CHANNEL_WEBAPP, message, method, params);
}
public void publishToMemberSession(final String memberSessionID, final String method, final Object... params)
throws OverflowException {
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.MEMBER_SESSION);
message.addTarget(memberSessionID);
this.publish(CHANNEL_WEBAPP, message, method, params);
}
public void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params)
throws OverflowException {
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.PROBE);
message.addTarget(tempProbeKey);
this.publish(CHANNEL_NOAUTH_PROBE, message, method, params);
}
public void publishToProbe(final String probeKey, final String method, final Object... params)
throws OverflowException {
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.PROBE);
message.addTarget(probeKey);
this.publish(CHANNEL_PROBE, message, method, params);
}
@Cacheable("memberListByDomain")
protected List<String> getMemberListByDomainID(final long domainID) throws OverflowException {
return this.getMemberList(memberService.readAllByDomainID(domainID));
}
@Cacheable("memberListByProbeKey")
protected List<String> getMemberListByProbeKey(final String probeKey) throws OverflowException {
return this.getMemberList(memberService.readAllByProbeKey(probeKey));
}
protected List<String> getMemberList(final List<Member> members) {
List<String> results = new ArrayList<>(members.size());
for (Member member : members) {
results.add(member.getEmail());
} }
public RedisMessagePublisher(final RedisTemplate<String, Object> redisTemplate, final Map<String, ChannelTopic> topics) { return results;
this.redisTemplate = redisTemplate; }
this.topics = topics;
} protected void publish(final String channel, PublishMessage message, final String method, Object... params) {
ChannelTopic topic = this.topics.get(channel);
public void publishToDomainMembers(final long domainID, final String method, final Object... params) throws OverflowException { message.setMessage(new PublishMessage.PublishMessageBody(method, this.getMessageBody(params)));
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.MEMBER); String json = this.gson.toJson(message);
message.setTargets(getMemberListByDomainID(domainID)); redisTemplate.convertAndSend(topic.getTopic(), json);
this.publish(CHANNEL_WEBAPP, message, method, params); }
}
public void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params) throws OverflowException { protected List<String> getMessageBody(final Object... params) {
PublishMessage message = new PublishMessage(); List<String> results = new ArrayList<>(params.length);
message.setTargetType(PublishMessage.TargetType.MEMBER); for (Object param : params) {
message.setTargets(getMemberListByProbeKey(probeKey)); if (param.getClass().equals(String.class)) {
this.publish(CHANNEL_WEBAPP, message, method, params); results.add((String) param);
} } else {
results.add(this.gson.toJson(param));
public void publishToMember(final String memberID, final String method, final Object... params) throws OverflowException { }
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.MEMBER);
message.addTarget(memberID);
this.publish(CHANNEL_WEBAPP, message, method, params);
}
public void publishToMemberSession(final String memberSessionID, final String method, final Object... params) throws OverflowException {
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.MEMBER_SESSION);
message.addTarget(memberSessionID);
this.publish(CHANNEL_WEBAPP, message, method, params);
}
public void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params) throws OverflowException {
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.PROBE);
message.addTarget(tempProbeKey);
this.publish(CHANNEL_NOAUTH_PROBE, message, method, params);
}
public void publishToProbe(final String probeKey, final String method, final Object... params) throws OverflowException {
PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.PROBE);
message.addTarget(probeKey);
this.publish(CHANNEL_PROBE, message, method, params);
}
@Cacheable("memberListByDomain")
protected List<String> getMemberListByDomainID(final long domainID) throws OverflowException {
return this.getMemberList(memberService.readAllByDomainID(domainID));
}
@Cacheable("memberListByProbeKey")
protected List<String> getMemberListByProbeKey(final String probeKey) throws OverflowException {
return this.getMemberList(memberService.readAllByProbeKey(probeKey));
}
protected List<String> getMemberList(final List<Member> members) {
List<String> results = new ArrayList<>(members.size());
for (Member member: members) {
results.add(member.getEmail());
}
return results;
}
protected void publish(final String channel, PublishMessage message, final String method, Object... params) {
ChannelTopic topic = this.topics.get(channel);
message.setMessage(new PublishMessage.PublishMessageBody(method, this.getMessageBody(params)));
try {
String json = this.objectMapper.writeValueAsString(message);
redisTemplate.convertAndSend(topic.getTopic(), json);
} catch (IOException e) {
e.printStackTrace();
}
}
protected List<String> getMessageBody(final Object... params) {
List<String> results = new ArrayList<>(params.length);
try {
for (Object param : params) {
if (param.getClass().equals(String.class)) {
results.add((String)param);
} else {
results.add(objectMapper.writeValueAsString(param));
}
}
} catch (IOException e) {
e.printStackTrace();
}
return results;
} }
return results;
}
} }

View File

@ -1,7 +1,7 @@
package com.loafle.overflow.central.spring; package com.loafle.overflow.central.spring;
import org.codehaus.jackson.map.DeserializationConfig; import com.google.gson.Gson;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.context.annotation.*; import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@ -9,45 +9,34 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
* Created by insanity on 17. 6. 13. * Created by insanity on 17. 6. 13.
*/ */
@Configuration @Configuration
@ComponentScan(basePackages = {"com.loafle.overflow"}, excludeFilters = @ComponentScan.Filter({Configuration.class})) @ComponentScan(basePackages = {
@Import({ "com.loafle.overflow" }, excludeFilters = @ComponentScan.Filter({ Configuration.class }))
JdbcConfiguration.class, @Import({ JdbcConfiguration.class, MailConfiguration.class, RedisConfiguration.class, CacheConfiguration.class })
MailConfiguration.class, @PropertySource({ "classpath:database.properties", "classpath:mail.properties", "classpath:redis.properties",
RedisConfiguration.class, "classpath:cache.properties" })
CacheConfiguration.class
})
@PropertySource({
"classpath:database.properties",
"classpath:mail.properties",
"classpath:redis.properties",
"classpath:cache.properties"
})
public class AppConfig { public class AppConfig {
// @Bean // @Bean
// public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { // public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
// PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); // PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
//// ppc.setLocation(new ClassPathResource("database.properties")); //// ppc.setLocation(new ClassPathResource("database.properties"));
// ppc.setLocations(new Resource[] { // ppc.setLocations(new Resource[] {
// new ClassPathResource("database.properties"), // new ClassPathResource("database.properties"),
// new ClassPathResource("mail.properties"), // new ClassPathResource("mail.properties"),
// new ClassPathResource("redis.properties") // new ClassPathResource("redis.properties")
// }); // });
// ppc.setIgnoreUnresolvablePlaceholders(true); // ppc.setIgnoreUnresolvablePlaceholders(true);
// //
// return ppc; // return ppc;
// } // }
@Bean @Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer(); return new PropertySourcesPlaceholderConfigurer();
} }
@Bean @Bean
public ObjectMapper getObjectMapper() { public Gson gson() {
Gson gson = new Gson();
ObjectMapper objectMapper = new ObjectMapper(); return gson;
}
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper;
}
} }

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.spring; package com.loafle.overflow.central.spring;
import org.codehaus.jackson.map.ObjectMapper;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;

View File

@ -1,5 +1,6 @@
package com.loafle.overflow.central.module.infra.service; package com.loafle.overflow.central.module.infra.service;
import com.google.gson.Gson;
import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.infra.InfraHost; import com.loafle.overflow.model.infra.InfraHost;
@ -7,7 +8,6 @@ import com.loafle.overflow.model.infra.InfraOS;
import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.service.central.infra.InfraHostService; import com.loafle.overflow.service.central.infra.InfraHostService;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -26,6 +26,9 @@ public class InfraHostServiceTest {
@Autowired @Autowired
private InfraHostService infraHostService; private InfraHostService infraHostService;
@Autowired
private Gson gson;
@Test @Test
// @Ignore // @Ignore
public void regist() throws Exception { public void regist() throws Exception {
@ -55,8 +58,7 @@ public class InfraHostServiceTest {
InfraHost infraHost = this.infraHostService.read(1); InfraHost infraHost = this.infraHostService.read(1);
ObjectMapper objectMapper = new ObjectMapper(); String json = gson.toJson(infraHost);
String json = objectMapper.writeValueAsString(infraHost);
System.out.println(json); System.out.println(json);

View File

@ -1,11 +1,11 @@
package com.loafle.overflow.central.module.infra.service; package com.loafle.overflow.central.module.infra.service;
import com.google.gson.Gson;
import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.model.infra.InfraMachine; import com.loafle.overflow.model.infra.InfraMachine;
import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.service.central.infra.InfraMachineService; import com.loafle.overflow.service.central.infra.InfraMachineService;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -24,7 +24,10 @@ public class InfraMachineServiceTest {
@Autowired @Autowired
private InfraMachineService infraMachineService; private InfraMachineService infraMachineService;
// @Ignore @Autowired
private Gson gson;
// @Ignore
@Test @Test
public void regist() throws Exception { public void regist() throws Exception {
@ -49,8 +52,7 @@ public class InfraMachineServiceTest {
InfraMachine infraMachine = this.infraMachineService.read(1); InfraMachine infraMachine = this.infraMachineService.read(1);
ObjectMapper objectMapper = new ObjectMapper(); String json = gson.toJson(infraMachine);
String json = objectMapper.writeValueAsString(infraMachine);
System.out.println(json); System.out.println(json);
} }

View File

@ -1,12 +1,12 @@
package com.loafle.overflow.central.module.infra.service; package com.loafle.overflow.central.module.infra.service;
import com.google.gson.Gson;
import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.model.infra.InfraOS; import com.loafle.overflow.model.infra.InfraOS;
import com.loafle.overflow.model.infra.InfraOSApplication; import com.loafle.overflow.model.infra.InfraOSApplication;
import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.service.central.infra.InfraOSApplicationService; import com.loafle.overflow.service.central.infra.InfraOSApplicationService;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -24,6 +24,9 @@ public class InfraOSApplicationServiceTest {
@Autowired @Autowired
private InfraOSApplicationService infraOSApplicationService; private InfraOSApplicationService infraOSApplicationService;
@Autowired
private Gson gson;
// @Ignore // @Ignore
@Test @Test
public void regist() throws Exception { public void regist() throws Exception {
@ -53,9 +56,7 @@ public class InfraOSApplicationServiceTest {
Assert.assertNotNull(infraOSApplication); Assert.assertNotNull(infraOSApplication);
ObjectMapper objectMapper = new ObjectMapper(); String json = gson.toJson(infraOSApplication);
String json = objectMapper.writeValueAsString(infraOSApplication);
System.out.println(json); System.out.println(json);
} }

View File

@ -1,12 +1,12 @@
package com.loafle.overflow.central.module.infra.service; package com.loafle.overflow.central.module.infra.service;
import com.google.gson.Gson;
import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.model.infra.InfraOS; import com.loafle.overflow.model.infra.InfraOS;
import com.loafle.overflow.model.infra.InfraOSDaemon; import com.loafle.overflow.model.infra.InfraOSDaemon;
import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.service.central.infra.InfraOSDaemonService; import com.loafle.overflow.service.central.infra.InfraOSDaemonService;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -24,6 +24,9 @@ public class InfraOSDaemonServiceTest {
@Autowired @Autowired
private InfraOSDaemonService infraOSDaemonService; private InfraOSDaemonService infraOSDaemonService;
@Autowired
private Gson gson;
// @Ignore // @Ignore
@Test @Test
public void regist() throws Exception { public void regist() throws Exception {
@ -52,8 +55,7 @@ public class InfraOSDaemonServiceTest {
InfraOSDaemon infraOSDaemon = this.infraOSDaemonService.read(1); InfraOSDaemon infraOSDaemon = this.infraOSDaemonService.read(1);
Assert.assertNotNull(infraOSDaemon); Assert.assertNotNull(infraOSDaemon);
ObjectMapper objectMapper = new ObjectMapper(); String json = gson.toJson(infraOSDaemon);
String json = objectMapper.writeValueAsString(infraOSDaemon);
System.out.println(json); System.out.println(json);
} }

View File

@ -1,5 +1,6 @@
package com.loafle.overflow.central.module.infra.service; package com.loafle.overflow.central.module.infra.service;
import com.google.gson.Gson;
import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.infra.InfraOS; import com.loafle.overflow.model.infra.InfraOS;
@ -23,6 +24,8 @@ public class InfraOSPortServiceTest {
@Autowired @Autowired
private InfraOSPortService infraOSPortService; private InfraOSPortService infraOSPortService;
@Autowired
private Gson gson;
// @Ignore // @Ignore
@Test @Test

View File

@ -1,5 +1,6 @@
package com.loafle.overflow.central.module.infra.service; package com.loafle.overflow.central.module.infra.service;
import com.google.gson.Gson;
import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.model.infra.InfraMachine; import com.loafle.overflow.model.infra.InfraMachine;
import com.loafle.overflow.model.infra.InfraOS; import com.loafle.overflow.model.infra.InfraOS;
@ -7,7 +8,6 @@ import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.model.meta.MetaInfraVendor; import com.loafle.overflow.model.meta.MetaInfraVendor;
import com.loafle.overflow.service.central.infra.InfraOSService; import com.loafle.overflow.service.central.infra.InfraOSService;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -23,6 +23,8 @@ public class InfraOSServiceTest {
@Autowired @Autowired
private InfraOSService infraOSService; private InfraOSService infraOSService;
@Autowired
private Gson gson;
@Test @Test
// @Ignore // @Ignore
@ -53,8 +55,7 @@ public class InfraOSServiceTest {
public void read() throws Exception { public void read() throws Exception {
InfraOS infraOS = this.infraOSService.read(1); InfraOS infraOS = this.infraOSService.read(1);
ObjectMapper objectMapper = new ObjectMapper(); String json = gson.toJson(infraOS);
String json = objectMapper.writeValueAsString(infraOS);
System.out.println(json); System.out.println(json);
} }

View File

@ -1,5 +1,6 @@
package com.loafle.overflow.central.module.infra.service; package com.loafle.overflow.central.module.infra.service;
import com.google.gson.Gson;
import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.model.infra.InfraHost; import com.loafle.overflow.model.infra.InfraHost;
import com.loafle.overflow.model.infra.InfraService; import com.loafle.overflow.model.infra.InfraService;
@ -23,5 +24,7 @@ public class InfraServiceServiceTest {
@Autowired @Autowired
private InfraServiceService infraServiceService; private InfraServiceService infraServiceService;
@Autowired
private Gson gson;
} }

View File

@ -1,7 +1,5 @@
package com.loafle.overflow.central.spring; package com.loafle.overflow.central.spring;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.*; import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@ -12,6 +10,8 @@ import org.springframework.test.context.TestPropertySource;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import com.google.gson.Gson;
/** /**
* Created by geek on 17. 8. 8. * Created by geek on 17. 8. 8.
*/ */
@ -51,12 +51,9 @@ public class AppConfigTest {
} }
@Bean @Bean
public ObjectMapper getObjectMapper() { public Gson gson() {
Gson gson = new Gson();
ObjectMapper objectMapper = new ObjectMapper(); return gson;
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper;
} }
} }