in progress
This commit is contained in:
parent
31cd0efd8a
commit
006d6cff51
|
@ -10,14 +10,21 @@ import com.loafle.overflow.model.discovery.Host;
|
|||
import com.loafle.overflow.model.discovery.Zone;
|
||||
import com.loafle.overflow.model.infra.Infra;
|
||||
import com.loafle.overflow.model.infra.InfraHost;
|
||||
import com.loafle.overflow.model.infra.InfraHostIP;
|
||||
import com.loafle.overflow.model.infra.InfraZone;
|
||||
import com.loafle.overflow.model.meta.MetaIPType;
|
||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||
import com.loafle.overflow.model.meta.MetaTargetHostType;
|
||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescription;
|
||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionHost;
|
||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionNetwork;
|
||||
import com.loafle.overflow.service.central.infra.InfraService;
|
||||
import com.loafle.overflow.service.central.probe.ProbeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service("InfraService")
|
||||
|
@ -56,6 +63,10 @@ public class CentralInfraService implements InfraService {
|
|||
}
|
||||
|
||||
public InfraZone regist(Long probeID, List<Host> hosts, List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
|
||||
// List<Target> targets = new ArrayList<Target>();
|
||||
// targets.addAll(registDiscoveredHostTargets(probeId, hosts));
|
||||
// targets.addAll(this.registDiscoveredServiceTargets(probeId, services));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -73,7 +84,22 @@ public class CentralInfraService implements InfraService {
|
|||
}
|
||||
|
||||
public InfraHost regist(Long probeID, NoAuthProbeDescription noAuthProbeDescription) throws OverflowException {
|
||||
return null;
|
||||
NoAuthProbeDescriptionNetwork networkInfo = noAuthProbeDescription.getNetwork();
|
||||
InfraHostIP infraHostIP = new InfraHostIP();
|
||||
// FIXME getting IPType from networkInfo
|
||||
infraHostIP.setMetaIPType(new MetaIPType((short)1));
|
||||
infraHostIP.setAddress(networkInfo.getAddress());
|
||||
infraHostIP.setMac(networkInfo.getMacAddress());
|
||||
List<InfraHostIP> infraHostIPs = new ArrayList<>();
|
||||
infraHostIPs.add(infraHostIP);
|
||||
|
||||
InfraHost infraHost = new InfraHost();
|
||||
infraHost.setProbe(new Probe(probeID));
|
||||
infraHost.setMetaInfraType(new MetaInfraType(1));
|
||||
infraHost.setMetaTargetHostType(new MetaTargetHostType(1));
|
||||
infraHost.setInfraHostIPs(infraHostIPs);
|
||||
|
||||
return this.infraDAO.save(infraHost);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.loafle.overflow.core.annotation.ProbeAPI;
|
|||
import com.loafle.overflow.core.annotation.WebappAPI;
|
||||
import com.loafle.overflow.central.commons.utils.GenerateKey;
|
||||
import com.loafle.overflow.central.commons.utils.SessionMetadata;
|
||||
import com.loafle.overflow.central.module.infra.service.CentralInfraService;
|
||||
import com.loafle.overflow.central.module.noauthprobe.dao.NoAuthProbeDAO;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.model.apikey.ApiKey;
|
||||
|
@ -12,18 +13,14 @@ import com.loafle.overflow.model.domain.Domain;
|
|||
import com.loafle.overflow.model.domain.DomainMember;
|
||||
import com.loafle.overflow.model.infra.InfraHost;
|
||||
import com.loafle.overflow.model.member.Member;
|
||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
|
||||
import com.loafle.overflow.model.meta.MetaProbeStatus;
|
||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
|
||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescription;
|
||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionHost;
|
||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionNetwork;
|
||||
import com.loafle.overflow.model.probe.Probe;
|
||||
import com.loafle.overflow.model.probe.ProbeHost;
|
||||
import com.loafle.overflow.service.central.apikey.ApiKeyService;
|
||||
import com.loafle.overflow.service.central.domain.DomainMemberService;
|
||||
import com.loafle.overflow.service.central.infra.InfraHostService;
|
||||
import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
|
||||
import com.loafle.overflow.service.central.probe.ProbeHostService;
|
||||
import com.loafle.overflow.service.central.probe.ProbeService;
|
||||
|
@ -63,13 +60,10 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
|
|||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
private CentralInfraService infraService;
|
||||
|
||||
@Autowired
|
||||
private InfraMachineService infraMachineService;
|
||||
@Autowired
|
||||
private InfraOSService infraOSService;
|
||||
@Autowired
|
||||
private InfraHostService infraHostService;
|
||||
@Autowired
|
||||
private ProbeHostService probeHostService;
|
||||
|
||||
|
@ -109,9 +103,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
|
|||
}
|
||||
|
||||
Probe probe = this.newProbe(noAuthProbe, noAuthProbeDescription);
|
||||
InfraMachine machine = this.newInfraMachine(noAuthProbe);
|
||||
InfraOS os = this.newInfraOS(machine, noAuthProbeDescription.getHost());
|
||||
InfraHost host = this.newInfraHost(os, noAuthProbeDescription.getNetwork());
|
||||
InfraHost host = this.infraService.regist(probe.getId(), noAuthProbeDescription);
|
||||
this.newProbeHost(host, probe);
|
||||
|
||||
noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 1));
|
||||
|
@ -152,43 +144,6 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
|
|||
return this.probeService.regist(probe);
|
||||
}
|
||||
|
||||
private InfraMachine newInfraMachine(NoAuthProbe noauthprobe) throws OverflowException {
|
||||
MetaInfraType metaInfraType = new MetaInfraType(1);
|
||||
|
||||
InfraMachine infraMachine = new InfraMachine();
|
||||
infraMachine.setMeta(noauthprobe.getDescription());
|
||||
infraMachine.setMetaInfraType(metaInfraType);
|
||||
|
||||
return this.infraMachineService.regist(infraMachine);
|
||||
}
|
||||
|
||||
private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost)
|
||||
throws OverflowException {
|
||||
MetaInfraType metaInfraType = new MetaInfraType(3);
|
||||
|
||||
InfraOS infraOS = new InfraOS();
|
||||
infraOS.setInfraMachine(infraMachine);
|
||||
infraOS.setMetaInfraType(metaInfraType);
|
||||
infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS()));
|
||||
|
||||
return this.infraOSService.regist(infraOS);
|
||||
}
|
||||
|
||||
private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork)
|
||||
throws OverflowException {
|
||||
MetaInfraType metaInfraType = new MetaInfraType(2);
|
||||
|
||||
InfraHost infraHost = new InfraHost();
|
||||
String addrStr = noAuthProbeDescriptionNetwork.getAddress();
|
||||
String[] addrArr = addrStr.split("\\|");
|
||||
|
||||
infraHost.setIpv4(addrArr[0]);
|
||||
infraHost.setMac(noAuthProbeDescriptionNetwork.getMacAddress());
|
||||
infraHost.setInfraOS(infraOS);
|
||||
infraHost.setMetaInfraType(metaInfraType);
|
||||
|
||||
return this.infraHostService.regist(infraHost);
|
||||
}
|
||||
|
||||
private void newProbeHost(InfraHost infraHost, Probe probe) throws OverflowException {
|
||||
ProbeHost probeHost = new ProbeHost();
|
||||
|
|
|
@ -4,8 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import com.loafle.overflow.central.commons.utils.PageUtil;
|
||||
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;
|
||||
|
@ -13,11 +11,11 @@ import com.loafle.overflow.core.model.PageParams;
|
|||
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.infra.Infra;
|
||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||
import com.loafle.overflow.model.probe.Probe;
|
||||
import com.loafle.overflow.model.target.Target;
|
||||
import com.loafle.overflow.service.central.infra.InfraService;
|
||||
import com.loafle.overflow.service.central.target.TargetService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -34,10 +32,12 @@ public class CentralTargetService implements TargetService {
|
|||
private TargetDAO targetDAO;
|
||||
@Autowired
|
||||
private CentralProbeService probeService;
|
||||
// @Autowired
|
||||
// private CentralInfraHostService infraHostService;
|
||||
// @Autowired
|
||||
// private CentralInfraServiceService infraServiceService;
|
||||
@Autowired
|
||||
private CentralInfraHostService infraHostService;
|
||||
@Autowired
|
||||
private CentralInfraServiceService infraServiceService;
|
||||
private InfraService infraService;
|
||||
|
||||
@Transactional
|
||||
public Target regist(Target target, Long probeID) throws OverflowException {
|
||||
|
@ -76,18 +76,20 @@ public class CentralTargetService implements TargetService {
|
|||
}
|
||||
|
||||
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());
|
||||
// InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip);
|
||||
// if (null == infraHost)
|
||||
// return null;
|
||||
// return this.targetDAO.findByInfraId(infraHost.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
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());
|
||||
// InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber,
|
||||
// portType);
|
||||
// if (null == infraService)
|
||||
// return null;
|
||||
// return this.targetDAO.findByInfraId(infraService.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
|
||||
|
@ -95,75 +97,81 @@ public class CentralTargetService implements TargetService {
|
|||
}
|
||||
|
||||
@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 {
|
||||
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);
|
||||
List<Infra> infras = this.infraService.regist(probeID, hosts, null);
|
||||
for (Infra infra : infras) {
|
||||
Target target = new Target();
|
||||
target.setInfra(infraHost);
|
||||
String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? 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);
|
||||
if (infra.getMetaInfraType().getKey().equals("")) {
|
||||
|
||||
}
|
||||
|
||||
Target target = new Target();
|
||||
target.setInfra(infraService);
|
||||
String displayName = service.getServiceName();
|
||||
target.setDisplayName(displayName);
|
||||
targets.add(this.targetDAO.save(target));
|
||||
}
|
||||
return targets;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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 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().trim().isEmpty()) ? host.getIpv6()
|
||||
// : host.getIpv4();
|
||||
// target.setDisplayName(displayName);
|
||||
// targets.add(this.targetDAO.save(target));
|
||||
// }
|
||||
// return targets;
|
||||
// return null;
|
||||
// }
|
||||
|
||||
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);
|
||||
}
|
||||
// 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