This commit is contained in:
crusader 2018-07-02 17:15:18 +09:00
parent a6b9b609d1
commit 29629b144f
3 changed files with 27 additions and 66 deletions

View File

@ -50,7 +50,7 @@
<dependency>
<groupId>com.loafle.overflow</groupId>
<artifactId>commons-java</artifactId>
<version>1.0.117-SNAPSHOT</version>
<version>1.0.118-SNAPSHOT</version>
</dependency>
<dependency>

View File

@ -277,29 +277,8 @@ public class CentralInfraService implements InfraService {
@Override
@Transactional
public List<Infra> 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<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);
}
public List<Infra> registDiscoverd(Long probeID, List<Host> hosts,
List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
List<Infra> infras = new ArrayList<>();
@ -317,23 +296,6 @@ public class CentralInfraService implements InfraService {
return infras;
}
public List<Infra> testRegistDiscoverd(Long probeID, List<Host> hosts, List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
List<Infra> infras = new ArrayList<>();
if (null != hosts) {
for (Host host : hosts) {
infras.add(this.registByHost(probeID, host));
}
}
if (null != services) {
for (com.loafle.overflow.model.discovery.Service service : services) {
infras.add(this.registByService(probeID, service));
}
}
return infras;
}
public InfraZone registInfraZoneByInfraHostIP(Long probeID, InfraHostIP infraHostIP) throws OverflowException {
if (null == infraHostIP) {
throw new OverflowException("InfraHostIP is not valid");

View File

@ -67,34 +67,34 @@ public class CentralInfraServiceTest {
host.setMac("44:8a:5b:44:8c:e4");
host.setDiscoveredDate(new Date());
host.setZone(zone);
// for (int j = 22; j < 25; j++) {
port = new Port();
port.setDiscoveredDate(new Date());
port.setHost(host);
port.setMetaPortType(MetaPortType.Enum.TCP.to());
port.setPortNumber(22);
// for (int j = 22; j < 25; j++) {
port = new Port();
port.setDiscoveredDate(new Date());
port.setHost(host);
port.setMetaPortType(MetaPortType.Enum.TCP.to());
port.setPortNumber(22);
// for (int x = 24; x < 25; x++) {
service = new Service();
cryptoType = new MetaCryptoType();
cryptoType.setKey("TLS");
cryptoType.setId(Short.valueOf((short) 17));
cryptoType.setName("TLS");
// for (int x = 24; x < 25; x++) {
service = new Service();
cryptoType = new MetaCryptoType();
cryptoType.setKey("TLS");
cryptoType.setId(Short.valueOf((short) 17));
cryptoType.setName("TLS");
service.setMetaCryptoType(cryptoType);
service.setPort(port);
service.setDiscoveredDate(new Date());
service.setKey("SSH");
services.add(service);
// }
port.setServiceList(services);
ports.add(port);
// }
service.setMetaCryptoType(cryptoType);
service.setPort(port);
service.setDiscoveredDate(new Date());
service.setKey("SSH");
services.add(service);
// }
port.setServiceList(services);
ports.add(port);
// }
host.setPortList(ports);
hosts.add(host);
// }
List<Infra> infras = this.centralInfraService.testRegistDiscoverd(Long.valueOf((long)1), hosts, services);
List<Infra> infras = this.centralInfraService.registDiscoverd(Long.valueOf((long) 1), hosts, services);
// System.out.println("CentralInfraServiceTest Infra List Size: " +
// infras.size());
}
@ -119,9 +119,8 @@ public class CentralInfraServiceTest {
public void registByHost() {
}
// Long probeID,
// com.loafle.overflow.model.discovery.Service service
// Long probeID,
// com.loafle.overflow.model.discovery.Service service
@Test
public void registByService() throws OverflowException {
Host host = null;