syntax error fix
This commit is contained in:
parent
07ef365ad3
commit
b4eed25b5f
2
pom.xml
2
pom.xml
|
@ -49,7 +49,7 @@
|
|||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>commons-java</artifactId>
|
||||
<version>1.0.6-SNAPSHOT</version>
|
||||
<version>1.0.8-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository;
|
|||
*/
|
||||
@Repository
|
||||
public interface InfraHostDAO extends JpaRepository<InfraHost, Long> {
|
||||
InfraHost findByIpv4(String ipv4);
|
||||
InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4);
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.loafle.overflow.central.module.infra.service;
|
||||
|
||||
|
||||
import com.loafle.overflow.central.module.infra.dao.InfraHostDAO;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.model.infra.InfraHost;
|
||||
|
@ -20,12 +21,12 @@ public class CentralInfraHostService implements InfraHostService {
|
|||
return this.infraHostDAO.save(infraHost);
|
||||
}
|
||||
|
||||
public InfraHost read(Long id) throws OverflowException {
|
||||
public InfraHost read(Long id) throws OverflowException {
|
||||
return this.infraHostDAO.findOne(id);
|
||||
}
|
||||
|
||||
public InfraHost readByIp(String ip) throws OverflowException {
|
||||
return this.infraHostDAO.findByIpv4(ip);
|
||||
public InfraHost readByProbeIdAndIpv4(Long probeId, String ip) throws OverflowException {
|
||||
return this.infraHostDAO.findByProbeIdAndIpv4(probeId, ip);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ public class CentralInfraService implements InfraService {
|
|||
|
||||
public Infra read(Long id) throws OverflowException {
|
||||
Infra infra = this.infraDAO.findOne(id);
|
||||
infra.getTarget().setSensors(this.sensorDAO.findAllByTargetId(infra.getTarget().getId()));
|
||||
return infra;
|
||||
}
|
||||
|
||||
|
@ -55,9 +54,6 @@ public class CentralInfraService implements InfraService {
|
|||
}
|
||||
|
||||
Page<Infra> infraList = this.infraDAO.findAllByProbeInAndTargetNotNull(probeList, PageUtil.getPageRequest(pageParams));
|
||||
for (Infra infra : infraList) {
|
||||
infra.getTarget().setSensors(this.sensorDAO.findAllByTargetId(infra.getTarget().getId()));
|
||||
}
|
||||
return infraList;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,13 +73,12 @@ public class CentralSensorService implements SensorService {
|
|||
}
|
||||
|
||||
public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
|
||||
Infra dbInfra = this.infraService.read(infraID);
|
||||
|
||||
if (dbInfra == null || dbInfra.getTarget() == null) {
|
||||
throw new OverflowException("", new Throwable());
|
||||
}
|
||||
|
||||
return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), PageUtil.getPageRequest(pageParams));
|
||||
// Infra dbInfra = this.infraService.read(infraID);
|
||||
// if (dbInfra == null) {
|
||||
// throw new OverflowException("", new Throwable());
|
||||
// }
|
||||
// return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), PageUtil.getPageRequest(pageParams));
|
||||
return null;
|
||||
}
|
||||
|
||||
public Page<Sensor> readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException {
|
||||
|
|
|
@ -9,4 +9,5 @@ import org.springframework.stereotype.Repository;
|
|||
*/
|
||||
@Repository
|
||||
public interface TargetDAO extends JpaRepository<Target, Long> {
|
||||
Target findByInfraId(Long infraId);
|
||||
}
|
||||
|
|
|
@ -1,226 +1,226 @@
|
|||
package com.loafle.overflow.central.module.target.service;
|
||||
// package com.loafle.overflow.central.module.target.service;
|
||||
|
||||
import com.loafle.overflow.central.module.infra.service.*;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.core.type.PortType;
|
||||
import com.loafle.overflow.model.discovery.Host;
|
||||
import com.loafle.overflow.model.discovery.Port;
|
||||
// import com.loafle.overflow.central.module.infra.service.*;
|
||||
// import com.loafle.overflow.core.exception.OverflowException;
|
||||
// import com.loafle.overflow.core.type.PortType;
|
||||
// import com.loafle.overflow.model.discovery.Host;
|
||||
// import com.loafle.overflow.model.discovery.Port;
|
||||
|
||||
import com.loafle.overflow.model.infra.*;
|
||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||
import com.loafle.overflow.model.meta.MetaInfraVendor;
|
||||
import com.loafle.overflow.model.probe.Probe;
|
||||
import com.loafle.overflow.model.target.Target;
|
||||
import com.loafle.overflow.service.central.target.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
// import com.loafle.overflow.model.infra.*;
|
||||
// import com.loafle.overflow.model.meta.MetaInfraType;
|
||||
// import com.loafle.overflow.model.meta.MetaInfraVendor;
|
||||
// import com.loafle.overflow.model.probe.Probe;
|
||||
// import com.loafle.overflow.model.target.Target;
|
||||
// import com.loafle.overflow.service.central.target.*;
|
||||
// import org.springframework.beans.factory.annotation.Autowired;
|
||||
// import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
// import javax.transaction.Transactional;
|
||||
// import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by snoop on 17. 6. 28.
|
||||
*/
|
||||
@Service("TargetDiscoveryService")
|
||||
public class CentralTargetDiscoveryService implements TargetDiscoveryService {
|
||||
// /**
|
||||
// * Created by snoop on 17. 6. 28.
|
||||
// */
|
||||
// @Service("TargetDiscoveryService")
|
||||
// public class CentralTargetDiscoveryService implements TargetDiscoveryService {
|
||||
|
||||
@Autowired
|
||||
private TargetService targetService;
|
||||
// @Autowired
|
||||
// private TargetService targetService;
|
||||
|
||||
@Autowired
|
||||
private CentralInfraMachineService infraMachineService;
|
||||
// @Autowired
|
||||
// private CentralInfraMachineService infraMachineService;
|
||||
|
||||
@Autowired
|
||||
private CentralInfraOSService infraOSService;
|
||||
// @Autowired
|
||||
// private CentralInfraOSService infraOSService;
|
||||
|
||||
@Autowired
|
||||
private CentralInfraHostService infraHostService;
|
||||
// @Autowired
|
||||
// private CentralInfraHostService infraHostService;
|
||||
|
||||
// @Autowired
|
||||
// private CentralInfraService infraService;
|
||||
// // @Autowired
|
||||
// // private CentralInfraService infraService;
|
||||
|
||||
@Autowired
|
||||
private CentralInfraOSPortService infraOSPortService;
|
||||
// @Autowired
|
||||
// private CentralInfraOSPortService infraOSPortService;
|
||||
|
||||
@Autowired
|
||||
private CentralInfraServiceService infraServiceService;
|
||||
// @Autowired
|
||||
// private CentralInfraServiceService infraServiceService;
|
||||
|
||||
@Transactional
|
||||
public boolean saveAllTarget(List<Host> hosts, Probe probe) throws OverflowException {
|
||||
// @Transactional
|
||||
// public boolean saveAllTarget(List<Host> hosts, Probe probe) throws OverflowException {
|
||||
|
||||
InfraHost infraHost = null;
|
||||
// InfraHost infraHost = null;
|
||||
|
||||
for (Host host : hosts) {
|
||||
// for (Host host : hosts) {
|
||||
|
||||
infraHost = this.createAndReadHost(host, probe);
|
||||
// infraHost = this.createAndReadHost(host, probe);
|
||||
|
||||
this.createPort(infraHost, host, probe);
|
||||
// this.createPort(infraHost, host, probe);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
private void createService(InfraHost infraHost, Port port, Probe probe) throws OverflowException {
|
||||
// private void createService(InfraHost infraHost, Port port, Probe probe) throws OverflowException {
|
||||
|
||||
MetaInfraType typeService = new MetaInfraType(7);
|
||||
// MetaInfraType typeService = new MetaInfraType(7);
|
||||
|
||||
String portType = "UDP";
|
||||
// String portType = "UDP";
|
||||
|
||||
if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) {
|
||||
portType = "TCP";
|
||||
}
|
||||
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) {
|
||||
// portType = "TCP";
|
||||
// }
|
||||
|
||||
if (port.getServiceList() == null) {
|
||||
return;
|
||||
}
|
||||
// if (port.getServiceList() == null) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// for(String key : port.getServices().keySet()) {
|
||||
for (com.loafle.overflow.model.discovery.Service service : port.getServiceList()) {
|
||||
// // for(String key : port.getServices().keySet()) {
|
||||
// for (com.loafle.overflow.model.discovery.Service service : port.getServiceList()) {
|
||||
|
||||
// com.loafle.overflow.module.discovery.model.Service service =
|
||||
// port.getServices().get(key);
|
||||
// // com.loafle.overflow.module.discovery.model.Service service =
|
||||
// // port.getServices().get(key);
|
||||
|
||||
InfraService dbInfraService = this.infraServiceService
|
||||
.readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), portType);
|
||||
// InfraService dbInfraService = this.infraServiceService
|
||||
// .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), portType);
|
||||
|
||||
if (dbInfraService != null) {
|
||||
if (service.isTarget() && dbInfraService.getTarget() == null) {
|
||||
Target targetService = new Target();
|
||||
targetService.setDisplayName(service.getServiceName());
|
||||
this.targetService.regist(targetService, probe);
|
||||
dbInfraService.setTarget(targetService);
|
||||
this.infraServiceService.regist(dbInfraService);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// if (dbInfraService != null) {
|
||||
// if (service.isTarget() && dbInfraService.getTarget() == null) {
|
||||
// Target targetService = new Target();
|
||||
// targetService.setDisplayName(service.getServiceName());
|
||||
// this.targetService.regist(targetService, probe);
|
||||
// dbInfraService.setTarget(targetService);
|
||||
// this.infraServiceService.regist(dbInfraService);
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
|
||||
InfraService infraService = new InfraService();
|
||||
infraService.setInfraHost(infraHost);
|
||||
infraService.setPort(port.getPortNumber());
|
||||
infraService.setPortType(portType);
|
||||
infraService.setMetaInfraType(typeService);
|
||||
infraService.setProbe(probe);
|
||||
// InfraService infraService = new InfraService();
|
||||
// infraService.setInfraHost(infraHost);
|
||||
// infraService.setPort(port.getPortNumber());
|
||||
// infraService.setPortType(portType);
|
||||
// infraService.setMetaInfraType(typeService);
|
||||
// infraService.setProbe(probe);
|
||||
|
||||
if (port.getPortType() == PortType.TLS) {
|
||||
infraService.setTlsType(true);
|
||||
}
|
||||
infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
|
||||
// if (port.getPortType() == PortType.TLS) {
|
||||
// infraService.setTlsType(true);
|
||||
// }
|
||||
// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
|
||||
|
||||
if (service.isTarget()) {
|
||||
Target targetService = new Target();
|
||||
targetService.setDisplayName(service.getServiceName());
|
||||
this.targetService.regist(targetService, probe);
|
||||
infraService.setTarget(targetService);
|
||||
}
|
||||
// if (service.isTarget()) {
|
||||
// Target targetService = new Target();
|
||||
// targetService.setDisplayName(service.getServiceName());
|
||||
// this.targetService.regist(targetService, probe);
|
||||
// infraService.setTarget(targetService);
|
||||
// }
|
||||
|
||||
this.infraServiceService.regist(infraService);
|
||||
// this.infraServiceService.regist(infraService);
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
private void createPort(InfraHost infraHost, Host host, Probe probe) throws OverflowException {
|
||||
// private void createPort(InfraHost infraHost, Host host, Probe probe) throws OverflowException {
|
||||
|
||||
// if(host.getPorts() == null) {
|
||||
// return;
|
||||
// }
|
||||
// // if(host.getPorts() == null) {
|
||||
// // return;
|
||||
// // }
|
||||
|
||||
String portType = "UDP";
|
||||
// String portType = "UDP";
|
||||
|
||||
MetaInfraType typePort = new MetaInfraType(6);
|
||||
// MetaInfraType typePort = new MetaInfraType(6);
|
||||
|
||||
InfraOS infraOS = infraHost.getInfraOS();
|
||||
// InfraOS infraOS = infraHost.getInfraOS();
|
||||
|
||||
// for( String key: host.getPorts().keySet()) {
|
||||
// // for( String key: host.getPorts().keySet()) {
|
||||
|
||||
if (host.getPortList() == null) {
|
||||
return;
|
||||
}
|
||||
// if (host.getPortList() == null) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
for (Port port : host.getPortList()) {
|
||||
// Port port = host.getPorts().get(key);
|
||||
// for (Port port : host.getPortList()) {
|
||||
// // Port port = host.getPorts().get(key);
|
||||
|
||||
if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
|
||||
portType = "TCP";
|
||||
}
|
||||
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
|
||||
// portType = "TCP";
|
||||
// }
|
||||
|
||||
InfraOSPort dbInfraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), port.getPortNumber(),
|
||||
portType);
|
||||
if (dbInfraOSPort == null) {
|
||||
InfraOSPort infraOSPort = new InfraOSPort();
|
||||
infraOSPort.setInfraOS(infraOS);
|
||||
infraOSPort.setPort(port.getPortNumber());
|
||||
infraOSPort.setPortType(portType);
|
||||
infraOSPort.setProbe(probe);
|
||||
infraOSPort.setMetaInfraType(typePort);
|
||||
// InfraOSPort dbInfraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), port.getPortNumber(),
|
||||
// portType);
|
||||
// if (dbInfraOSPort == null) {
|
||||
// InfraOSPort infraOSPort = new InfraOSPort();
|
||||
// infraOSPort.setInfraOS(infraOS);
|
||||
// infraOSPort.setPort(port.getPortNumber());
|
||||
// infraOSPort.setPortType(portType);
|
||||
// infraOSPort.setProbe(probe);
|
||||
// infraOSPort.setMetaInfraType(typePort);
|
||||
|
||||
if (port.getPortType() == PortType.TLS) {
|
||||
infraOSPort.setTlsType(true);
|
||||
}
|
||||
infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
|
||||
this.infraOSPortService.regist(infraOSPort);
|
||||
}
|
||||
// if (port.getPortType() == PortType.TLS) {
|
||||
// infraOSPort.setTlsType(true);
|
||||
// }
|
||||
// infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
|
||||
// this.infraOSPortService.regist(infraOSPort);
|
||||
// }
|
||||
|
||||
this.createService(infraHost, port, probe);
|
||||
}
|
||||
}
|
||||
// this.createService(infraHost, port, probe);
|
||||
// }
|
||||
// }
|
||||
|
||||
private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException {
|
||||
// private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException {
|
||||
|
||||
InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4());
|
||||
if (infraHost != null) {
|
||||
// InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4());
|
||||
// if (infraHost != null) {
|
||||
|
||||
if (host.isTarget() && infraHost.getTarget() == null) {
|
||||
Target target = new Target();
|
||||
target.setDisplayName(host.getIpv4() + "-Host");
|
||||
// if (host.isTarget() && infraHost.getTarget() == null) {
|
||||
// Target target = new Target();
|
||||
// target.setDisplayName(host.getIpv4() + "-Host");
|
||||
|
||||
this.targetService.regist(target, probe);
|
||||
infraHost.setTarget(target);
|
||||
this.infraHostService.regist(infraHost);
|
||||
}
|
||||
// this.targetService.regist(target, probe);
|
||||
// infraHost.setTarget(target);
|
||||
// this.infraHostService.regist(infraHost);
|
||||
// }
|
||||
|
||||
return infraHost;
|
||||
} else {
|
||||
MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine;
|
||||
// return infraHost;
|
||||
// } else {
|
||||
// MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine;
|
||||
|
||||
MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os
|
||||
// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os
|
||||
|
||||
MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host
|
||||
// MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host
|
||||
|
||||
InfraMachine infraMachine = new InfraMachine();
|
||||
infraMachine.setProbe(probe);
|
||||
infraMachine.setMetaInfraType(typeMachine);
|
||||
infraMachine.setMeta(host.getIpv4() + "-MACHINE");
|
||||
this.infraMachineService.regist(infraMachine);
|
||||
// InfraMachine infraMachine = new InfraMachine();
|
||||
// infraMachine.setProbe(probe);
|
||||
// infraMachine.setMetaInfraType(typeMachine);
|
||||
// infraMachine.setMeta(host.getIpv4() + "-MACHINE");
|
||||
// this.infraMachineService.regist(infraMachine);
|
||||
|
||||
InfraOS infraOS = new InfraOS();
|
||||
infraOS.setInfraMachine(infraMachine);
|
||||
infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
|
||||
infraOS.setMetaInfraType(typeOS);
|
||||
infraOS.setProbe(probe);
|
||||
infraOS.setMeta(host.getIpv4() + "-OS");
|
||||
this.infraOSService.regist(infraOS);
|
||||
// InfraOS infraOS = new InfraOS();
|
||||
// infraOS.setInfraMachine(infraMachine);
|
||||
// infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
|
||||
// infraOS.setMetaInfraType(typeOS);
|
||||
// infraOS.setProbe(probe);
|
||||
// infraOS.setMeta(host.getIpv4() + "-OS");
|
||||
// this.infraOSService.regist(infraOS);
|
||||
|
||||
InfraHost newInfraHost = new InfraHost();
|
||||
newInfraHost.setIpv4(host.getIpv4());
|
||||
newInfraHost.setMac(host.getMac());
|
||||
newInfraHost.setInfraOS(infraOS);
|
||||
newInfraHost.setMetaInfraType(typeHost);
|
||||
newInfraHost.setProbe(probe);
|
||||
// InfraHost newInfraHost = new InfraHost();
|
||||
// newInfraHost.setIpv4(host.getIpv4());
|
||||
// newInfraHost.setMac(host.getMac());
|
||||
// newInfraHost.setInfraOS(infraOS);
|
||||
// newInfraHost.setMetaInfraType(typeHost);
|
||||
// newInfraHost.setProbe(probe);
|
||||
|
||||
if (host.isTarget()) {
|
||||
Target target = new Target();
|
||||
target.setDisplayName(host.getIpv4() + "-Host");
|
||||
// if (host.isTarget()) {
|
||||
// Target target = new Target();
|
||||
// target.setDisplayName(host.getIpv4() + "-Host");
|
||||
|
||||
this.targetService.regist(target, probe);
|
||||
newInfraHost.setTarget(target);
|
||||
}
|
||||
// this.targetService.regist(target, probe);
|
||||
// newInfraHost.setTarget(target);
|
||||
// }
|
||||
|
||||
this.infraHostService.regist(newInfraHost);
|
||||
infraHost = newInfraHost;
|
||||
}
|
||||
// this.infraHostService.regist(newInfraHost);
|
||||
// infraHost = newInfraHost;
|
||||
// }
|
||||
|
||||
return infraHost;
|
||||
}
|
||||
// return infraHost;
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
|
|
@ -1,24 +1,31 @@
|
|||
package com.loafle.overflow.central.module.target.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.loafle.overflow.central.module.infra.service.CentralInfraHostService;
|
||||
import com.loafle.overflow.central.module.infra.service.CentralInfraServiceService;
|
||||
import com.loafle.overflow.central.module.probe.service.CentralProbeService;
|
||||
import com.loafle.overflow.central.module.target.dao.TargetDAO;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.core.type.CryptoType;
|
||||
import com.loafle.overflow.model.discovery.Host;
|
||||
import com.loafle.overflow.model.discovery.Service;
|
||||
import com.loafle.overflow.model.infra.InfraHost;
|
||||
import com.loafle.overflow.model.infra.InfraService;
|
||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||
import com.loafle.overflow.model.meta.MetaInfraVendor;
|
||||
import com.loafle.overflow.model.probe.Probe;
|
||||
import com.loafle.overflow.model.target.Target;
|
||||
import com.loafle.overflow.service.central.target.TargetService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Created by insanity on 17. 6. 28.
|
||||
*/
|
||||
@Service("TargetService")
|
||||
@org.springframework.stereotype.Service("TargetService")
|
||||
public class CentralTargetService implements TargetService {
|
||||
|
||||
@Autowired
|
||||
|
@ -27,6 +34,8 @@ public class CentralTargetService implements TargetService {
|
|||
private CentralProbeService probeService;
|
||||
@Autowired
|
||||
private CentralInfraHostService infraHostService;
|
||||
@Autowired
|
||||
private CentralInfraServiceService infraServiceService;
|
||||
|
||||
@Transactional
|
||||
public Target regist(Target target, Probe probe) throws OverflowException {
|
||||
|
@ -73,20 +82,88 @@ public class CentralTargetService implements TargetService {
|
|||
return this.targetDAO.save(t);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Target> registDiscoveredTargets(Long probeId, List<Host> hosts,
|
||||
List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
|
||||
/*
|
||||
* 해당 host의 mac에 해당하는 infraHost가 이미 존재하는지 검사 infraHost가 없다면 create infraHost가
|
||||
* 있다면 update infraHost.getTarget()이 있어도 무조건 새로운 target으로 연결
|
||||
*
|
||||
*
|
||||
* for(Host host : hosts) { Target target = new Target();
|
||||
*
|
||||
* MetaInfraType infraType = new MetaInfraType(); infraType.setId(2); InfraHost
|
||||
* infraHost = new InfraHost(); infraHost.setInfraType(infraType);
|
||||
* infraHost.setProbe(new Probe(probeId)); infraHost.setTarget(target); }
|
||||
*/
|
||||
return null;
|
||||
|
||||
public Target readExistHostTarget(Long probeId, String ip) throws OverflowException {
|
||||
InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip);
|
||||
if (null == infraHost) return null;
|
||||
return this.targetDAO.findByInfraId(infraHost.getId());
|
||||
}
|
||||
|
||||
public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException {
|
||||
InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber, portType);
|
||||
if (null == infraService) return null;
|
||||
return this.targetDAO.findByInfraId(infraService.getId());
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public List<Target> registDiscoveredTargets(Long probeId, List<Host> hosts, List<Service> services)
|
||||
throws OverflowException {
|
||||
List<Target> targets = new ArrayList<Target>();
|
||||
targets.addAll(registDiscoveredHostTargets(probeId, hosts));
|
||||
targets.addAll(this.registDiscoveredServiceTargets(probeId, services));
|
||||
return targets;
|
||||
}
|
||||
|
||||
private List<Target> registDiscoveredHostTargets(Long probeId, List<Host> hosts) throws OverflowException {
|
||||
List<Target> targets = new ArrayList<>();
|
||||
if (null == hosts)
|
||||
return targets;
|
||||
for (Host host : hosts) {
|
||||
InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
|
||||
Target target = new Target();
|
||||
target.setInfra(infraHost);
|
||||
String displayName = host.getIpv6() == null ? host.getIpv6() : host.getIpv4();
|
||||
target.setDisplayName(displayName);
|
||||
targets.add(this.targetDAO.save(target));
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
private List<Target> registDiscoveredServiceTargets(Long probeId, List<Service> services) throws OverflowException {
|
||||
List<Target> targets = new ArrayList<>();
|
||||
if (null == services)
|
||||
return targets;
|
||||
for (Service service : services) {
|
||||
Host host = service.getPort().getHost();
|
||||
InfraHost infraHost = null;
|
||||
InfraHost existInfraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4());
|
||||
InfraService infraService = null;
|
||||
if (null != existInfraHost) {
|
||||
infraHost = existInfraHost;
|
||||
} else {
|
||||
infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
|
||||
infraService = this.registInfraServiceByDiscoveredService(infraHost, service, probeId);
|
||||
}
|
||||
|
||||
Target target = new Target();
|
||||
target.setInfra(infraService);
|
||||
String displayName = service.getServiceName();
|
||||
target.setDisplayName(displayName);
|
||||
targets.add(this.targetDAO.save(target));
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId) throws OverflowException {
|
||||
InfraHost infraHost = new InfraHost();
|
||||
infraHost.setMetaInfraType(new MetaInfraType(2));
|
||||
infraHost.setProbe(new Probe(probeId));
|
||||
infraHost.setIpv4(host.getIpv4());
|
||||
infraHost.setIpv6(host.getIpv6());
|
||||
infraHost.setMac(host.getMac());
|
||||
return this.infraHostService.regist(infraHost);
|
||||
}
|
||||
|
||||
private InfraService registInfraServiceByDiscoveredService(InfraHost infraHost, Service service, Long probeId) throws OverflowException {
|
||||
InfraService infraService = new InfraService();
|
||||
infraHost.setMetaInfraType(new MetaInfraType(7));
|
||||
infraService.setInfraHost(infraHost);
|
||||
infraService.setPort(service.getPort().getPortNumber());
|
||||
infraService.setPortType(service.getPort().getPortType().toString());
|
||||
infraService.setTlsType(service.getCryptoType() == CryptoType.TLS);
|
||||
infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
|
||||
return this.infraServiceService.regist(infraService);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user