inprogress

This commit is contained in:
insanity 2018-06-11 15:13:34 +09:00
parent fdc9e80fbd
commit 9b697a9fc7

View File

@ -12,6 +12,7 @@ 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.Infra;
import com.loafle.overflow.model.infra.InfraHost;
import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.model.target.Target;
@ -59,7 +60,6 @@ public class CentralTargetService implements TargetService {
return this.targetDAO.save(target);
}
public Target increaseSensorCount(Long id) throws OverflowException {
Target t = this.targetDAO.findById(id).get();
t.setSensorCount(t.getSensorCount() + 1);
@ -76,7 +76,8 @@ public class CentralTargetService implements TargetService {
}
public Target readExistHostTarget(Long probeId, String ip) throws OverflowException {
// InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip);
// InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId,
// ip);
// if (null == infraHost)
// return null;
// return this.targetDAO.findByInfraId(infraHost.getId());
@ -84,7 +85,9 @@ public class CentralTargetService implements TargetService {
}
public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException {
// InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber,
// InfraService infraService =
// this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId,
// portNumber,
// portType);
// if (null == infraService)
// return null;
@ -99,18 +102,31 @@ public class CentralTargetService implements TargetService {
@Transactional
public List<Target> registDiscoveredTargets(Long probeID, List<Host> hosts, List<Service> services)
throws OverflowException {
List<Infra> infras = this.infraService.regist(probeID, hosts, null);
for (Infra infra : infras) {
List<Target> targets = new ArrayList<Target>();
for (Host host : hosts) {
InfraHost infraHost = this.infraService.regist(probeID, host);
String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? host.getIpv6()
: host.getIpv4();
Target target = new Target();
if (infra.getMetaInfraType().getKey().equals("")) {
target.setInfra(infraHost);
target.setSensorCount(0);
target.setName(displayName);
targets.add(target);
}
for (Service service : services) {
com.loafle.overflow.model.infra.InfraService infraService = this.infraService.regist(probeID, service);
Target target = new Target();
target.setInfra(infraService);
target.setSensorCount(0);
target.setName(infraService.getMetaInfraType().getName());
targets.add(target);
}
return null;
return this.targetDAO.saveAll(targets);
}
// private List<Target> registDiscoveredHostTargets(Long probeId, List<Host> hosts) throws OverflowException {
// private List<Target> registDiscoveredHostTargets(Long probeId, List<Host>
// hosts) throws OverflowException {
// List<Target> targets = new ArrayList<>();
// if (null == hosts)
// return targets;
@ -118,7 +134,8 @@ public class CentralTargetService implements TargetService {
// InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
// Target target = new Target();
// target.setInfra(infraHost);
// String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? host.getIpv6()
// String displayName = (host.getIpv6() == null ||
// host.getIpv6().trim().isEmpty()) ? host.getIpv6()
// : host.getIpv4();
// target.setDisplayName(displayName);
// targets.add(this.targetDAO.save(target));
@ -127,20 +144,23 @@ public class CentralTargetService implements TargetService {
// return null;
// }
// private List<Target> registDiscoveredServiceTargets(Long probeId, List<Service> services) throws OverflowException {
// 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());
// 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);
// infraService = this.registInfraServiceByDiscoveredService(infraHost, service,
// probeId);
// }
// Target target = new Target();
@ -152,7 +172,8 @@ public class CentralTargetService implements TargetService {
// return targets;
// }
// private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId) throws OverflowException {
// private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId)
// throws OverflowException {
// InfraHost infraHost = new InfraHost();
// infraHost.setMetaInfraType(new MetaInfraType(2));
// infraHost.setProbe(new Probe(probeId));
@ -162,7 +183,8 @@ public class CentralTargetService implements TargetService {
// return this.infraHostService.regist(infraHost);
// }
// private InfraService registInfraServiceByDiscoveredService(InfraHost infraHost, Service service, Long probeId)
// private InfraService registInfraServiceByDiscoveredService(InfraHost
// infraHost, Service service, Long probeId)
// throws OverflowException {
// InfraService infraService = new InfraService();
// infraHost.setMetaInfraType(new MetaInfraType(7));
@ -170,7 +192,8 @@ public class CentralTargetService implements TargetService {
// // infraService.setPort(service.getPort().getPortNumber());
// // infraService.setPortType(service.getPort().getPortType().toString());
// // infraService.setTlsType(service.getCryptoType() == CryptoType.TLS);
// // infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
// //
// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
// return this.infraServiceService.regist(infraService);
// }