ing
This commit is contained in:
parent
18cba274cf
commit
8d0e5a0839
2
pom.xml
2
pom.xml
|
@ -50,7 +50,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.loafle.overflow</groupId>
|
<groupId>com.loafle.overflow</groupId>
|
||||||
<artifactId>commons-java</artifactId>
|
<artifactId>commons-java</artifactId>
|
||||||
<version>1.0.89-SNAPSHOT</version>
|
<version>1.0.90-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package com.loafle.overflow.central.module.infra.service;
|
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.commons.utils.PageUtil;
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraDAO;
|
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.InfraHostDAO;
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraServiceDAO;
|
import com.loafle.overflow.central.module.infra.dao.InfraServiceDAO;
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraZoneDAO;
|
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.CentralMetaCryptoTypeService;
|
||||||
|
import com.loafle.overflow.central.module.meta.service.CentralMetaTargetServiceTypeService;
|
||||||
import com.loafle.overflow.core.model.PageParams;
|
import com.loafle.overflow.core.model.PageParams;
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
import com.loafle.overflow.model.probe.Probe;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
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.MetaCryptoType;
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||||
import com.loafle.overflow.model.meta.MetaTargetHostType;
|
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.model.meta.MetaTargetZoneType;
|
||||||
import com.loafle.overflow.service.central.infra.InfraService;
|
import com.loafle.overflow.service.central.infra.InfraService;
|
||||||
import com.loafle.overflow.service.central.probe.ProbeService;
|
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.IPAddress;
|
||||||
import inet.ipaddr.IPAddressString;
|
import inet.ipaddr.IPAddressString;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
@Service("InfraService")
|
@Service("InfraService")
|
||||||
public class CentralInfraService implements InfraService {
|
public class CentralInfraService implements InfraService {
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ProbeService probeService;
|
ProbeService probeService;
|
||||||
|
|
||||||
|
@ -74,6 +86,9 @@ public class CentralInfraService implements InfraService {
|
||||||
@Autowired
|
@Autowired
|
||||||
CentralMetaCryptoTypeService metaCryptoTypeService;
|
CentralMetaCryptoTypeService metaCryptoTypeService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CentralMetaTargetServiceTypeService metaTargetServiceTypeService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Infra regist(Infra infra) throws OverflowException {
|
public Infra regist(Infra infra) throws OverflowException {
|
||||||
return this.infraDAO.save(infra);
|
return this.infraDAO.save(infra);
|
||||||
|
@ -189,6 +204,15 @@ public class CentralInfraService implements InfraService {
|
||||||
String.format("MetaCryptoTypeKey[%s] is not valid", service.getMetaCryptoType().getKey()));
|
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);
|
Probe probe = this.probeService.read(probeID);
|
||||||
if (null == probe) {
|
if (null == probe) {
|
||||||
throw new OverflowException(String.format("ID[%d] of Probe is not valid", probeID));
|
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();
|
com.loafle.overflow.model.infra.InfraService infraService = new com.loafle.overflow.model.infra.InfraService();
|
||||||
infraService.setMetaInfraType(MetaInfraType.Enum.SERVICE.to());
|
infraService.setMetaInfraType(MetaInfraType.Enum.SERVICE.to());
|
||||||
infraService.setProbe(probe);
|
infraService.setProbe(probe);
|
||||||
|
infraService.setMetaTargetServiceType(metaTargetServiceType);
|
||||||
infraService.setInfraHostPort(infraHostPort);
|
infraService.setInfraHostPort(infraHostPort);
|
||||||
infraService.setMetaCryptoType(metaCryptoType);
|
infraService.setMetaCryptoType(metaCryptoType);
|
||||||
|
|
||||||
|
@ -255,8 +280,29 @@ public class CentralInfraService implements InfraService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<Infra> registDiscoverd(Long probeID, List<Host> hosts,
|
public List<Infra> registDiscoverd(Long probeID, String compressedHostsAndServices) throws OverflowException {
|
||||||
List<com.loafle.overflow.model.discovery.Service> services) 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<Host> hosts = null;
|
||||||
|
List<com.loafle.overflow.model.discovery.Service> services = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
JsonNode node = this.objectMapper.readTree(gis);
|
||||||
|
hosts = this.objectMapper.readValue(node.get("hosts").traverse(), new TypeReference<List<Host>>() {
|
||||||
|
});
|
||||||
|
services = this.objectMapper.readValue(node.get("services").traverse(),
|
||||||
|
new TypeReference<List<com.loafle.overflow.model.discovery.Service>>() {
|
||||||
|
});
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new OverflowException("Cannot convert to json", e);
|
||||||
|
}
|
||||||
|
|
||||||
List<Infra> infras = new ArrayList<>();
|
List<Infra> infras = new ArrayList<>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user