diff --git a/pom.xml b/pom.xml
index 7465dea..4ecc6c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,7 @@
com.loafle.overflow
commons-java
- 1.0.89-SNAPSHOT
+ 1.0.90-SNAPSHOT
diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java
index 900a45f..a647f72 100644
--- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java
+++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java
@@ -1,11 +1,15 @@
package com.loafle.overflow.central.module.infra.service;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.loafle.overflow.central.commons.utils.PageUtil;
import com.loafle.overflow.central.module.infra.dao.InfraDAO;
import com.loafle.overflow.central.module.infra.dao.InfraHostDAO;
import com.loafle.overflow.central.module.infra.dao.InfraServiceDAO;
import com.loafle.overflow.central.module.infra.dao.InfraZoneDAO;
import com.loafle.overflow.central.module.meta.service.CentralMetaCryptoTypeService;
+import com.loafle.overflow.central.module.meta.service.CentralMetaTargetServiceTypeService;
import com.loafle.overflow.core.model.PageParams;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.core.exception.OverflowException;
@@ -21,6 +25,7 @@ import com.loafle.overflow.model.infra.InfraZone;
import com.loafle.overflow.model.meta.MetaCryptoType;
import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.model.meta.MetaTargetHostType;
+import com.loafle.overflow.model.meta.MetaTargetServiceType;
import com.loafle.overflow.model.meta.MetaTargetZoneType;
import com.loafle.overflow.service.central.infra.InfraService;
import com.loafle.overflow.service.central.probe.ProbeService;
@@ -33,11 +38,18 @@ import org.springframework.transaction.annotation.Transactional;
import inet.ipaddr.IPAddress;
import inet.ipaddr.IPAddressString;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Base64;
import java.util.List;
+import java.util.zip.GZIPInputStream;
@Service("InfraService")
public class CentralInfraService implements InfraService {
+ @Autowired
+ private ObjectMapper objectMapper;
+
@Autowired
ProbeService probeService;
@@ -74,6 +86,9 @@ public class CentralInfraService implements InfraService {
@Autowired
CentralMetaCryptoTypeService metaCryptoTypeService;
+ @Autowired
+ CentralMetaTargetServiceTypeService metaTargetServiceTypeService;
+
@Override
public Infra regist(Infra infra) throws OverflowException {
return this.infraDAO.save(infra);
@@ -189,6 +204,15 @@ public class CentralInfraService implements InfraService {
String.format("MetaCryptoTypeKey[%s] is not valid", service.getMetaCryptoType().getKey()));
}
+ if (null == service.getName()) {
+ throw new OverflowException("Name of service is not valid");
+ }
+
+ MetaTargetServiceType metaTargetServiceType = this.metaTargetServiceTypeService.readByKey(service.getName());
+ if (null == metaTargetServiceType) {
+ throw new OverflowException(String.format("MetaTargetServiceType[%s] is not valid", service.getName()));
+ }
+
Probe probe = this.probeService.read(probeID);
if (null == probe) {
throw new OverflowException(String.format("ID[%d] of Probe is not valid", probeID));
@@ -247,6 +271,7 @@ public class CentralInfraService implements InfraService {
com.loafle.overflow.model.infra.InfraService infraService = new com.loafle.overflow.model.infra.InfraService();
infraService.setMetaInfraType(MetaInfraType.Enum.SERVICE.to());
infraService.setProbe(probe);
+ infraService.setMetaTargetServiceType(metaTargetServiceType);
infraService.setInfraHostPort(infraHostPort);
infraService.setMetaCryptoType(metaCryptoType);
@@ -255,8 +280,29 @@ public class CentralInfraService implements InfraService {
@Override
@Transactional
- public List registDiscoverd(Long probeID, List hosts,
- List services) throws OverflowException {
+ public List registDiscoverd(Long probeID, String compressedHostsAndServices) throws OverflowException {
+ GZIPInputStream gis = null;
+ try {
+ byte[] compressed = Base64.getMimeDecoder().decode(compressedHostsAndServices);
+ ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
+ gis = new GZIPInputStream(bis);
+ } catch (Exception e) {
+ throw new OverflowException("Cannot deflate", e);
+ }
+
+ List hosts = null;
+ List services = null;
+
+ try {
+ JsonNode node = this.objectMapper.readTree(gis);
+ hosts = this.objectMapper.readValue(node.get("hosts").traverse(), new TypeReference>() {
+ });
+ services = this.objectMapper.readValue(node.get("services").traverse(),
+ new TypeReference>() {
+ });
+ } catch (IOException e) {
+ throw new OverflowException("Cannot convert to json", e);
+ }
List infras = new ArrayList<>();