This commit is contained in:
insanity 2018-06-11 19:52:27 +09:00
parent 950d075fe4
commit 847300b3b0
4 changed files with 14 additions and 133 deletions

View File

@ -50,7 +50,7 @@
<dependency> <dependency>
<groupId>com.loafle.overflow</groupId> <groupId>com.loafle.overflow</groupId>
<artifactId>commons-java</artifactId> <artifactId>commons-java</artifactId>
<version>1.0.30-SNAPSHOT</version> <version>1.0.33-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -103,7 +103,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
} }
Probe probe = this.newProbe(noAuthProbe, noAuthProbeDescription); Probe probe = this.newProbe(noAuthProbe, noAuthProbeDescription);
InfraHost host = this.infraService.regist(probe.getId(), noAuthProbeDescription); InfraHost host = this.infraService.registByNoAuthProbe(probe.getId(), noAuthProbeDescription);
this.newProbeHost(host, probe); this.newProbeHost(host, probe);
noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 1)); noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 1));

View File

@ -12,10 +12,5 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface TargetDAO extends JpaRepository<Target, Long> { public interface TargetDAO extends JpaRepository<Target, Long> {
Target findByInfraId(Long infraId); Target findByInfraId(Long infraId);
// @Query("select t.infra from target t where t.infra.probe.id = :probeId")
// Page<Target> findForProbeId(@Param("probeId") Long probeId, Pageable
// pageRequest);
Page<Target> findAllByInfraProbeId(Long probeId, Pageable pageRequest); Page<Target> findAllByInfraProbeId(Long probeId, Pageable pageRequest);
} }

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.target.service; package com.loafle.overflow.central.module.target.service;
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;
@ -8,15 +7,8 @@ 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;
import com.loafle.overflow.core.model.PageParams; 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.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.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;
@ -33,12 +25,6 @@ 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
private InfraService infraService;
@Transactional @Transactional
public Target regist(Target target, Long probeID) throws OverflowException { public Target regist(Target target, Long probeID) throws OverflowException {
@ -75,126 +61,26 @@ public class CentralTargetService implements TargetService {
return this.targetDAO.save(t); return this.targetDAO.save(t);
} }
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());
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());
return null;
}
public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams)); return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams));
} }
@Transactional @Transactional
public List<Target> registDiscoveredTargets(Long probeID, List<Host> hosts, List<Service> services) public List<Target> registAll(List<Target> targets, Long probeID) throws OverflowException {
throws OverflowException { List<Target> registered = this.targetDAO.saveAll(targets);
List<Target> targets = new ArrayList<Target>(); Probe probe = this.probeService.read(probeID);
for (Host host : hosts) { if (null == probe) {
InfraHost infraHost = this.infraService.regist(probeID, host); throw new OverflowException(String.format("ID[%d] of Probe is not valid", probeID));
String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? host.getIpv6()
: host.getIpv4();
Target target = new Target();
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);
} }
Integer targetCount = probe.getTargetCount() + registered.size();
probe.setTargetCount(targetCount);
this.probeService.modify(probe);
return this.targetDAO.saveAll(targets); return registered;
} }
// private List<Target> registDiscoveredHostTargets(Long probeId, List<Host> public List<Target> readAllByZoneID() throws OverflowException {
// hosts) throws OverflowException { return null;
// 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 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);
// }
} }