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> <dependency>
<groupId>com.loafle.overflow</groupId> <groupId>com.loafle.overflow</groupId>
<artifactId>commons-java</artifactId> <artifactId>commons-java</artifactId>
<version>1.0.117-SNAPSHOT</version> <version>1.0.118-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -277,29 +277,8 @@ public class CentralInfraService implements InfraService {
@Override @Override
@Transactional @Transactional
public List<Infra> registDiscoverd(Long probeID, String compressedHostsAndServices) throws OverflowException { public List<Infra> registDiscoverd(Long probeID, List<Host> hosts,
GZIPInputStream gis = null; List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
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<>();
@ -317,23 +296,6 @@ public class CentralInfraService implements InfraService {
return infras; 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 { public InfraZone registInfraZoneByInfraHostIP(Long probeID, InfraHostIP infraHostIP) throws OverflowException {
if (null == infraHostIP) { if (null == infraHostIP) {
throw new OverflowException("InfraHostIP is not valid"); throw new OverflowException("InfraHostIP is not valid");

View File

@ -67,14 +67,14 @@ public class CentralInfraServiceTest {
host.setMac("44:8a:5b:44:8c:e4"); host.setMac("44:8a:5b:44:8c:e4");
host.setDiscoveredDate(new Date()); host.setDiscoveredDate(new Date());
host.setZone(zone); host.setZone(zone);
// for (int j = 22; j < 25; j++) { // for (int j = 22; j < 25; j++) {
port = new Port(); port = new Port();
port.setDiscoveredDate(new Date()); port.setDiscoveredDate(new Date());
port.setHost(host); port.setHost(host);
port.setMetaPortType(MetaPortType.Enum.TCP.to()); port.setMetaPortType(MetaPortType.Enum.TCP.to());
port.setPortNumber(22); port.setPortNumber(22);
// for (int x = 24; x < 25; x++) { // for (int x = 24; x < 25; x++) {
service = new Service(); service = new Service();
cryptoType = new MetaCryptoType(); cryptoType = new MetaCryptoType();
cryptoType.setKey("TLS"); cryptoType.setKey("TLS");
@ -86,15 +86,15 @@ public class CentralInfraServiceTest {
service.setDiscoveredDate(new Date()); service.setDiscoveredDate(new Date());
service.setKey("SSH"); service.setKey("SSH");
services.add(service); services.add(service);
// } // }
port.setServiceList(services); port.setServiceList(services);
ports.add(port); ports.add(port);
// } // }
host.setPortList(ports); host.setPortList(ports);
hosts.add(host); 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: " + // System.out.println("CentralInfraServiceTest Infra List Size: " +
// infras.size()); // infras.size());
} }
@ -119,9 +119,8 @@ public class CentralInfraServiceTest {
public void registByHost() { public void registByHost() {
} }
// Long probeID,
// Long probeID, // com.loafle.overflow.model.discovery.Service service
// com.loafle.overflow.model.discovery.Service service
@Test @Test
public void registByService() throws OverflowException { public void registByService() throws OverflowException {
Host host = null; Host host = null;