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.Host;
import com.loafle.overflow.model.discovery.Service; import com.loafle.overflow.model.discovery.Service;
import com.loafle.overflow.model.infra.Infra; 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.meta.MetaInfraType;
import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.model.target.Target; import com.loafle.overflow.model.target.Target;
@ -59,7 +60,6 @@ public class CentralTargetService implements TargetService {
return this.targetDAO.save(target); return this.targetDAO.save(target);
} }
public Target increaseSensorCount(Long id) throws OverflowException { public Target increaseSensorCount(Long id) throws OverflowException {
Target t = this.targetDAO.findById(id).get(); Target t = this.targetDAO.findById(id).get();
t.setSensorCount(t.getSensorCount() + 1); t.setSensorCount(t.getSensorCount() + 1);
@ -76,18 +76,21 @@ public class CentralTargetService implements TargetService {
} }
public Target readExistHostTarget(Long probeId, String ip) throws OverflowException { 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) // if (null == infraHost)
// return null; // return null;
// return this.targetDAO.findByInfraId(infraHost.getId()); // return this.targetDAO.findByInfraId(infraHost.getId());
return null; return null;
} }
public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException { public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException {
// InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber, // InfraService infraService =
// portType); // this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId,
// portNumber,
// portType);
// if (null == infraService) // if (null == infraService)
// return null; // return null;
// return this.targetDAO.findByInfraId(infraService.getId()); // return this.targetDAO.findByInfraId(infraService.getId());
return null; return null;
} }
@ -99,79 +102,99 @@ public class CentralTargetService implements TargetService {
@Transactional @Transactional
public List<Target> registDiscoveredTargets(Long probeID, List<Host> hosts, List<Service> services) public List<Target> registDiscoveredTargets(Long probeID, List<Host> hosts, List<Service> services)
throws OverflowException { throws OverflowException {
List<Infra> infras = this.infraService.regist(probeID, hosts, null); List<Target> targets = new ArrayList<Target>();
for (Infra infra : infras) { 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(); 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>
// List<Target> targets = new ArrayList<>(); // hosts) throws OverflowException {
// if (null == hosts) // List<Target> targets = new ArrayList<>();
// return targets; // if (null == hosts)
// for (Host host : hosts) { // return targets;
// InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId); // for (Host host : hosts) {
// Target target = new Target(); // InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
// target.setInfra(infraHost); // Target target = new Target();
// String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? host.getIpv6() // target.setInfra(infraHost);
// : host.getIpv4(); // String displayName = (host.getIpv6() == null ||
// target.setDisplayName(displayName); // host.getIpv6().trim().isEmpty()) ? host.getIpv6()
// targets.add(this.targetDAO.save(target)); // : host.getIpv4();
// } // target.setDisplayName(displayName);
// return targets; // targets.add(this.targetDAO.save(target));
// return null; // }
// return targets;
// return null;
// } // }
// private List<Target> registDiscoveredServiceTargets(Long probeId, List<Service> services) throws OverflowException { // private List<Target> registDiscoveredServiceTargets(Long probeId,
// List<Target> targets = new ArrayList<>(); // List<Service> services) throws OverflowException {
// if (null == services) // List<Target> targets = new ArrayList<>();
// return targets; // if (null == services)
// for (Service service : services) { // return targets;
// Host host = service.getPort().getHost(); // for (Service service : services) {
// InfraHost infraHost = null; // Host host = service.getPort().getHost();
// InfraHost existInfraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4()); // InfraHost infraHost = null;
// InfraService infraService = null; // InfraHost existInfraHost =
// if (null != existInfraHost) { // this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4());
// infraHost = existInfraHost; // InfraService infraService = null;
// } else { // if (null != existInfraHost) {
// infraHost = this.registInfraHostByDiscoveredHost(host, probeId); // infraHost = existInfraHost;
// infraService = this.registInfraServiceByDiscoveredService(infraHost, service, probeId); // } else {
// } // infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
// infraService = this.registInfraServiceByDiscoveredService(infraHost, service,
// Target target = new Target(); // probeId);
// 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 { // Target target = new Target();
// InfraHost infraHost = new InfraHost(); // target.setInfra(infraService);
// infraHost.setMetaInfraType(new MetaInfraType(2)); // String displayName = service.getServiceName();
// infraHost.setProbe(new Probe(probeId)); // target.setDisplayName(displayName);
// // infraHost.setIpv4(host.getIpv4()); // targets.add(this.targetDAO.save(target));
// // infraHost.setIpv6(host.getIpv6()); // }
// // infraHost.setMac(host.getMac()); // return targets;
// return this.infraHostService.regist(infraHost);
// } // }
// private InfraService registInfraServiceByDiscoveredService(InfraHost infraHost, Service service, Long probeId) // private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId)
// throws OverflowException { // throws OverflowException {
// InfraService infraService = new InfraService(); // InfraHost infraHost = new InfraHost();
// infraHost.setMetaInfraType(new MetaInfraType(7)); // infraHost.setMetaInfraType(new MetaInfraType(2));
// // infraService.setInfraHost(infraHost); // infraHost.setProbe(new Probe(probeId));
// // infraService.setPort(service.getPort().getPortNumber()); // // infraHost.setIpv4(host.getIpv4());
// // infraService.setPortType(service.getPort().getPortType().toString()); // // infraHost.setIpv6(host.getIpv6());
// // infraService.setTlsType(service.getCryptoType() == CryptoType.TLS); // // infraHost.setMac(host.getMac());
// // infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); // return this.infraHostService.regist(infraHost);
// return this.infraServiceService.regist(infraService); // }
// 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);
// } // }
} }