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.redis.version>1.8.7.RELEASE</spring.data.redis.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>
<javax.mail.version>1.4.7</javax.mail.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>
<docker.registry.name>docker.loafle.net/overflow</docker.registry.name>
<googleauth.version>1.1.2</googleauth.version>
@ -97,12 +97,6 @@
<version>9.4-1200-jdbc41</version>
</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 -->
<dependency>
@ -124,6 +118,12 @@
<version>${spring.crypto.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<!-- Mail -->
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>

View File

@ -1,7 +1,5 @@
package com.loafle.overflow.central.module.discovery.service;
import com.loafle.overflow.central.commons.service.MessagePublisher;
import com.loafle.overflow.central.commons.utils.SessionMetadata;
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.service.central.discovery.DiscoveryService;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.Date;
/**
@ -23,76 +19,68 @@ import java.util.Date;
@Service("DiscoveryService")
public class CentralDiscoveryService implements DiscoveryService {
@Autowired
private MessagePublisher messagePublisher;
@Autowired
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");
System.out.println(json);
// this.messagePublisher.publishToProbe("/auth", noAuthProbe.getTempProbeKey(), "NoAuthProbeService.acceptNoAuthProbe", probe.getProbeKey());
}
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverHost", requesterSessionID, zone, discoveryHost);
}
@WebappAPI
public void discoverZone(String probeID, DiscoverZone discoveryZone) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID();
@WebappAPI
public void discoverPort(String probeID, Host host, DiscoverPort discoveryPort) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID();
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverZone", requesterSessionID, discoveryZone);
}
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverPort", requesterSessionID, host, discoveryPort);
}
@WebappAPI
public void discoverHost(String probeID, Zone zone, DiscoverHost discoveryHost) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID();
@WebappAPI
public void discoverService(String probeID, Port port,
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
public void discoverPort(String probeID, Host host, DiscoverPort discoveryPort) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID();
@ProbeAPI
public void discoverStart(String requesterSessionID, Date startDate) throws OverflowException {
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
public void discoverService(String probeID, Port port, com.loafle.overflow.model.discovery.DiscoverService discoveryService) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID();
@ProbeAPI
public void discoveredZone(String requesterSessionID, Zone zone) throws OverflowException {
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
public void discoverStart(String requesterSessionID, Date startDate) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStart", startDate);
}
@ProbeAPI
public void discoveredPort(String requesterSessionID, Port port) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredPort", port);
}
@ProbeAPI
public void discoverStop(String requesterSessionID, Date stopDate) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStop", stopDate);
}
@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);
}
@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;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.central.commons.utils.StringConvertor;
import com.loafle.overflow.core.exception.OverflowException;
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.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.stereotype.Service;
@ -32,81 +32,79 @@ import java.util.Map;
@Service("InfraHostGenerator")
public class InfraHostGenerator {
@Autowired
private GenerateUtil generateUtil;
@Autowired
private GenerateUtil generateUtil;
@Autowired
private InfraHostWMIGenerator infraHostWMIGenerator;
@Autowired
private InfraHostWMIGenerator infraHostWMIGenerator;
@Autowired
private AuthCrawlerService authCrawlerService;
@Autowired
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();
sensorConfig.setConfigID(String.valueOf(dbSensor.getId()));
InfraHost infraHost = (InfraHost) infra;
Target target = this.createTarget(infraHost, dbSensor);
SensorConfig sensorConfig = new SensorConfig();
sensorConfig.setConfigID(String.valueOf(dbSensor.getId()));
if (target == null) {
return null;
}
Target target = this.createTarget(infraHost, dbSensor);
sensorConfig.setTarget(target);
// 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);
if (target == null) {
return null;
}
private Target createTarget(InfraHost infraHost, Sensor dbSensor)
throws Exception {
sensorConfig.setTarget(target);
AuthCrawler authCrawler = this.authCrawlerService.readAuth(dbSensor.getCrawler(), dbSensor.getTarget());
// FIXME: Interval
Schedule schedule = new Schedule();
schedule.setInterval("5");
sensorConfig.setSchedule(schedule);
if (authCrawler == null) {
return null;
}
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler());
sensorConfig.setCrawler(crawler);
Target target = new Target();
Connection connection = new Connection();
connection.setIp(StringConvertor.intToIp(infraHost.getIp()));
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler());
HashMap<String, String> optionMap;
optionMap = new ObjectMapper().readValue(authCrawler.getAuthJson(),
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;
if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
}
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;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.model.meta.MetaSensorItemKey;
import com.loafle.overflow.model.sensor.Sensor;
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.SensorConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -29,6 +29,9 @@ public class InfraHostWMIGenerator {
@Autowired
private GenerateUtil generateUtil;
@Autowired
private Gson gson;
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
SensorConfig sensorConfig) throws Exception {
@ -84,9 +87,7 @@ public class InfraHostWMIGenerator {
String json = tempItemKey.getOption();
if (json != null && json.length() > 0) {
HashMap<String, Object> optionMap;
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String, Object>>() {
});
HashMap<String, String> optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
Object obj = null;
obj = optionMap.get("appends");

View File

@ -1,5 +1,7 @@
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.core.type.PortType;
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.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.stereotype.Service;
@ -44,6 +44,9 @@ public class InfraServiceGenerator {
@Autowired
private AuthCrawlerService authCrawlerService;
@Autowired
private Gson gson;
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;
@ -75,8 +78,7 @@ public class InfraServiceGenerator {
this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
}
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(sensorConfig);
return gson.toJson(sensorConfig);
}
private Target createTarget(InfraService infraService, Sensor sensor) throws Exception {
@ -96,8 +98,7 @@ public class InfraServiceGenerator {
target.setConnection(connection);
HashMap<String,String> optionMap;
optionMap = new ObjectMapper().readValue(authCrawler.getAuthJson(), new TypeReference<HashMap<String,String>>() {});
HashMap<String, String> optionMap = this.gson.fromJson(authCrawler.getAuthJson(), TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
Map<String, Object> auth = new HashMap<>();

View File

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

View File

@ -1,5 +1,7 @@
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.model.meta.MetaSensorItemKey;
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.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.stereotype.Service;
@ -31,6 +29,8 @@ public class InfraServiceMysqlGenerator {
@Autowired
private GenerateUtil generateUtil;
@Autowired
private Gson gson;
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
SensorConfig sensorConfig) throws Exception {
@ -83,9 +83,7 @@ public class InfraServiceMysqlGenerator {
String json = tempItemKey.getOption();
if (json != null && json.length() > 0) {
HashMap<String, Object> optionMap;
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String, Object>>() {
});
HashMap<String, String> optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
Object obj = null;
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.stereotype.Service;
import java.io.IOException;
import java.util.List;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.model.PageParams;
import com.loafle.overflow.model.infra.Infra;
import com.loafle.overflow.model.sensor.Sensor;

View File

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

View File

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

View File

@ -1,12 +1,12 @@
package com.loafle.overflow.central.redis.service;
import com.google.gson.Gson;
import com.loafle.overflow.central.commons.service.MessagePublisher;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.model.PublishMessage;
import com.loafle.overflow.model.member.Member;
import com.loafle.overflow.service.central.member.MemberService;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
@ -20,114 +20,113 @@ import java.util.Map;
@Service
public class RedisMessagePublisher implements MessagePublisher {
private static final String CHANNEL_WEBAPP = "/webapp";
private static final String CHANNEL_NOAUTH_PROBE = "/auth";
private static final String CHANNEL_PROBE = "/probe";
private static final String CHANNEL_WEBAPP = "/webapp";
private static final String CHANNEL_NOAUTH_PROBE = "/auth";
private static final String CHANNEL_PROBE = "/probe";
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private MemberService memberService;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Autowired
private Gson gson;
@Autowired
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) {
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());
}
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;
}
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)));
String json = this.gson.toJson(message);
redisTemplate.convertAndSend(topic.getTopic(), json);
}
protected List<String> getMessageBody(final Object... params) {
List<String> results = new ArrayList<>(params.length);
for (Object param : params) {
if (param.getClass().equals(String.class)) {
results.add((String) param);
} else {
results.add(this.gson.toJson(param));
}
}
return results;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
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.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@ -12,6 +10,8 @@ import org.springframework.test.context.TestPropertySource;
import static org.junit.Assert.*;
import com.google.gson.Gson;
/**
* Created by geek on 17. 8. 8.
*/
@ -51,12 +51,9 @@ public class AppConfigTest {
}
@Bean
public ObjectMapper getObjectMapper() {
public Gson gson() {
Gson gson = new Gson();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper;
return gson;
}
}