in progress

This commit is contained in:
insanity 2018-06-10 22:05:31 +09:00
parent 31cd0efd8a
commit 006d6cff51
3 changed files with 119 additions and 130 deletions

View File

@ -10,14 +10,21 @@ import com.loafle.overflow.model.discovery.Host;
import com.loafle.overflow.model.discovery.Zone; import com.loafle.overflow.model.discovery.Zone;
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.infra.InfraHost;
import com.loafle.overflow.model.infra.InfraHostIP;
import com.loafle.overflow.model.infra.InfraZone; 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.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.infra.InfraService;
import com.loafle.overflow.service.central.probe.ProbeService; import com.loafle.overflow.service.central.probe.ProbeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service("InfraService") @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 { 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; return null;
} }
@ -73,7 +84,22 @@ public class CentralInfraService implements InfraService {
} }
public InfraHost regist(Long probeID, NoAuthProbeDescription noAuthProbeDescription) throws OverflowException { 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);
} }
} }

View File

@ -5,6 +5,7 @@ import com.loafle.overflow.core.annotation.ProbeAPI;
import com.loafle.overflow.core.annotation.WebappAPI; import com.loafle.overflow.core.annotation.WebappAPI;
import com.loafle.overflow.central.commons.utils.GenerateKey; import com.loafle.overflow.central.commons.utils.GenerateKey;
import com.loafle.overflow.central.commons.utils.SessionMetadata; 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.central.module.noauthprobe.dao.NoAuthProbeDAO;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.apikey.ApiKey; 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.domain.DomainMember;
import com.loafle.overflow.model.infra.InfraHost; import com.loafle.overflow.model.infra.InfraHost;
import com.loafle.overflow.model.member.Member; 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.MetaNoAuthProbeStatus;
import com.loafle.overflow.model.meta.MetaProbeStatus; import com.loafle.overflow.model.meta.MetaProbeStatus;
import com.loafle.overflow.model.noauthprobe.NoAuthProbe; import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescription; 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.Probe;
import com.loafle.overflow.model.probe.ProbeHost; import com.loafle.overflow.model.probe.ProbeHost;
import com.loafle.overflow.service.central.apikey.ApiKeyService; import com.loafle.overflow.service.central.apikey.ApiKeyService;
import com.loafle.overflow.service.central.domain.DomainMemberService; 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.noauthprobe.NoAuthProbeService;
import com.loafle.overflow.service.central.probe.ProbeHostService; import com.loafle.overflow.service.central.probe.ProbeHostService;
import com.loafle.overflow.service.central.probe.ProbeService; import com.loafle.overflow.service.central.probe.ProbeService;
@ -65,11 +62,8 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@Autowired @Autowired
private InfraMachineService infraMachineService; private CentralInfraService infraService;
@Autowired
private InfraOSService infraOSService;
@Autowired
private InfraHostService infraHostService;
@Autowired @Autowired
private ProbeHostService probeHostService; private ProbeHostService probeHostService;
@ -109,9 +103,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
} }
Probe probe = this.newProbe(noAuthProbe, noAuthProbeDescription); Probe probe = this.newProbe(noAuthProbe, noAuthProbeDescription);
InfraMachine machine = this.newInfraMachine(noAuthProbe); InfraHost host = this.infraService.regist(probe.getId(), noAuthProbeDescription);
InfraOS os = this.newInfraOS(machine, noAuthProbeDescription.getHost());
InfraHost host = this.newInfraHost(os, noAuthProbeDescription.getNetwork());
this.newProbeHost(host, probe); this.newProbeHost(host, probe);
noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 1)); noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 1));
@ -152,43 +144,6 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
return this.probeService.regist(probe); 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 { private void newProbeHost(InfraHost infraHost, Probe probe) throws OverflowException {
ProbeHost probeHost = new ProbeHost(); ProbeHost probeHost = new ProbeHost();

View File

@ -4,8 +4,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.loafle.overflow.central.commons.utils.PageUtil; 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.probe.service.CentralProbeService;
import com.loafle.overflow.central.module.target.dao.TargetDAO; import com.loafle.overflow.central.module.target.dao.TargetDAO;
import com.loafle.overflow.core.exception.OverflowException; 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.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.InfraHost; import com.loafle.overflow.model.infra.Infra;
import com.loafle.overflow.model.infra.InfraService;
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;
import com.loafle.overflow.service.central.infra.InfraService;
import com.loafle.overflow.service.central.target.TargetService; import com.loafle.overflow.service.central.target.TargetService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -34,10 +32,12 @@ public class CentralTargetService implements TargetService {
private TargetDAO targetDAO; private TargetDAO targetDAO;
@Autowired @Autowired
private CentralProbeService probeService; private CentralProbeService probeService;
// @Autowired
// private CentralInfraHostService infraHostService;
// @Autowired
// private CentralInfraServiceService infraServiceService;
@Autowired @Autowired
private CentralInfraHostService infraHostService; private InfraService infraService;
@Autowired
private CentralInfraServiceService infraServiceService;
@Transactional @Transactional
public Target regist(Target target, Long probeID) throws OverflowException { 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 { 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;
} }
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 = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber,
portType); // 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;
} }
public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
@ -95,75 +97,81 @@ 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<Target> targets = new ArrayList<Target>(); List<Infra> infras = this.infraService.regist(probeID, hosts, null);
targets.addAll(registDiscoveredHostTargets(probeId, hosts)); for (Infra infra : infras) {
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 target = new Target();
target.setInfra(infraHost); if (infra.getMetaInfraType().getKey().equals("")) {
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);
} }
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 { // private List<Target> registDiscoveredHostTargets(Long probeId, List<Host> hosts) throws OverflowException {
InfraHost infraHost = new InfraHost(); // List<Target> targets = new ArrayList<>();
infraHost.setMetaInfraType(new MetaInfraType(2)); // if (null == hosts)
infraHost.setProbe(new Probe(probeId)); // return targets;
// infraHost.setIpv4(host.getIpv4()); // for (Host host : hosts) {
// infraHost.setIpv6(host.getIpv6()); // InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
// infraHost.setMac(host.getMac()); // Target target = new Target();
return this.infraHostService.regist(infraHost); // 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) // private List<Target> registDiscoveredServiceTargets(Long probeId, List<Service> services) throws OverflowException {
throws OverflowException { // List<Target> targets = new ArrayList<>();
InfraService infraService = new InfraService(); // if (null == services)
infraHost.setMetaInfraType(new MetaInfraType(7)); // return targets;
// infraService.setInfraHost(infraHost); // for (Service service : services) {
// infraService.setPort(service.getPort().getPortNumber()); // Host host = service.getPort().getHost();
// infraService.setPortType(service.getPort().getPortType().toString()); // InfraHost infraHost = null;
// infraService.setTlsType(service.getCryptoType() == CryptoType.TLS); // InfraHost existInfraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4());
// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); // InfraService infraService = null;
return this.infraServiceService.regist(infraService); // 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);
// }
} }