ing
This commit is contained in:
parent
48564e1269
commit
950d075fe4
2
pom.xml
2
pom.xml
|
@ -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.27-SNAPSHOT</version>
|
<version>1.0.30-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -16,5 +16,5 @@ public interface InfraHostIPDAO extends JpaRepository<InfraHostIP, Long> {
|
||||||
List<InfraHostIP> findAllByInfraHostIdAndMetaIPTypeKey(Long infraHostId, String metaIPTypeKey);
|
List<InfraHostIP> findAllByInfraHostIdAndMetaIPTypeKey(Long infraHostId, String metaIPTypeKey);
|
||||||
List<InfraHostIP> findAllByInfraHostIdAndMac(Long infraHostId, String mac);
|
List<InfraHostIP> findAllByInfraHostIdAndMac(Long infraHostId, String mac);
|
||||||
InfraHostIP findByInfraHostIdAndMetaIPTypeKeyAndAddress(Long infraHostId, String metaIPTypeKey, String address);
|
InfraHostIP findByInfraHostIdAndMetaIPTypeKeyAndAddress(Long infraHostId, String metaIPTypeKey, String address);
|
||||||
|
InfraHostIP findByInfraHostInfraZoneIdAndMetaIPTypeKeyAndAddress(Long infraHostInfraZoneId, String metaIPTypeKey, String address);
|
||||||
}
|
}
|
|
@ -4,9 +4,11 @@ import java.util.List;
|
||||||
|
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraHostIPDAO;
|
import com.loafle.overflow.central.module.infra.dao.InfraHostIPDAO;
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraHostPortDAO;
|
import com.loafle.overflow.central.module.infra.dao.InfraHostPortDAO;
|
||||||
|
import com.loafle.overflow.central.module.meta.service.CentralMetaIPTypeService;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.model.infra.InfraHostIP;
|
import com.loafle.overflow.model.infra.InfraHostIP;
|
||||||
import com.loafle.overflow.model.infra.InfraHostPort;
|
import com.loafle.overflow.model.infra.InfraHostPort;
|
||||||
|
import com.loafle.overflow.model.meta.MetaIPType;
|
||||||
import com.loafle.overflow.service.central.infra.InfraHostIPService;
|
import com.loafle.overflow.service.central.infra.InfraHostIPService;
|
||||||
import com.loafle.overflow.service.central.infra.InfraHostPortService;
|
import com.loafle.overflow.service.central.infra.InfraHostPortService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -21,26 +23,66 @@ public class CentralInfraHostIPService implements InfraHostIPService {
|
||||||
@Autowired
|
@Autowired
|
||||||
InfraHostIPDAO infraHostIPDAO;
|
InfraHostIPDAO infraHostIPDAO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CentralMetaIPTypeService metaIPTypeService;
|
||||||
|
|
||||||
|
@Override
|
||||||
public InfraHostIP regist(InfraHostIP infraHostIP) throws OverflowException {
|
public InfraHostIP regist(InfraHostIP infraHostIP) throws OverflowException {
|
||||||
|
if (null == infraHostIP) {
|
||||||
|
throw new OverflowException("InfraHostIP is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == infraHostIP.getInfraHost()) {
|
||||||
|
throw new OverflowException("InfraHost is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == infraHostIP.getMetaIPType()) {
|
||||||
|
throw new OverflowException("MetaIPType is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
MetaIPType metaIPType = this.metaIPTypeService.readByKey(infraHostIP.getMetaIPType().getKey());
|
||||||
|
if (null == metaIPType) {
|
||||||
|
throw new OverflowException(String.format("MetaIPTypeKey[%s] is not valid", infraHostIP.getMetaIPType().getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == infraHostIP.getAddress()) {
|
||||||
|
throw new OverflowException("IP is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == infraHostIP.getMac()) {
|
||||||
|
throw new OverflowException("Mac is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
return this.infraHostIPDAO.save(infraHostIP);
|
return this.infraHostIPDAO.save(infraHostIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public InfraHostIP read(Long id) throws OverflowException {
|
public InfraHostIP read(Long id) throws OverflowException {
|
||||||
return this.infraHostIPDAO.findById(id).get();
|
return this.infraHostIPDAO.findById(id).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<InfraHostIP> readByInfraHostID(Long infraHostID) throws OverflowException {
|
public List<InfraHostIP> readByInfraHostID(Long infraHostID) throws OverflowException {
|
||||||
return this.infraHostIPDAO.findAllByInfraHostId(infraHostID);
|
return this.infraHostIPDAO.findAllByInfraHostId(infraHostID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<InfraHostIP> readByInfraHostIDAndMetaIPTypeKey(Long infraHostID, String metaIPTypeKey)
|
public List<InfraHostIP> readByInfraHostIDAndMetaIPTypeKey(Long infraHostID, String metaIPTypeKey)
|
||||||
throws OverflowException {
|
throws OverflowException {
|
||||||
return this.infraHostIPDAO.findAllByInfraHostIdAndMetaIPTypeKey(infraHostID, metaIPTypeKey);
|
return this.infraHostIPDAO.findAllByInfraHostIdAndMetaIPTypeKey(infraHostID, metaIPTypeKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public InfraHostIP readByInfraHostIDAndMetaIPTypeKeyAndAddress(Long infraHostID, String metaIPTypeKey, String address)
|
public InfraHostIP readByInfraHostIDAndMetaIPTypeKeyAndAddress(Long infraHostID, String metaIPTypeKey, String address)
|
||||||
throws OverflowException {
|
throws OverflowException {
|
||||||
return this.infraHostIPDAO.findByInfraHostIdAndMetaIPTypeKeyAndAddress(infraHostID, metaIPTypeKey, address);
|
return this.infraHostIPDAO.findByInfraHostIdAndMetaIPTypeKeyAndAddress(infraHostID, metaIPTypeKey, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InfraHostIP readByInfraHostInfraZoneIDAndMetaIPTypeKeyAndAddress(Long infraHostInfraZoneID,
|
||||||
|
String metaIPTypeKey, String address) throws OverflowException {
|
||||||
|
return this.infraHostIPDAO.findByInfraHostInfraZoneIdAndMetaIPTypeKeyAndAddress(infraHostInfraZoneID, metaIPTypeKey,
|
||||||
|
address);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,11 @@ package com.loafle.overflow.central.module.infra.service;
|
||||||
import com.loafle.overflow.central.commons.utils.PageUtil;
|
import com.loafle.overflow.central.commons.utils.PageUtil;
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraDAO;
|
import com.loafle.overflow.central.module.infra.dao.InfraDAO;
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraHostDAO;
|
import com.loafle.overflow.central.module.infra.dao.InfraHostDAO;
|
||||||
|
import com.loafle.overflow.central.module.infra.dao.InfraHostIPDAO;
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraServiceDAO;
|
import com.loafle.overflow.central.module.infra.dao.InfraServiceDAO;
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraZoneDAO;
|
import com.loafle.overflow.central.module.infra.dao.InfraZoneDAO;
|
||||||
|
import com.loafle.overflow.central.module.meta.dao.MetaIPTypeDAO;
|
||||||
|
import com.loafle.overflow.central.module.meta.service.CentralMetaIPTypeService;
|
||||||
import com.loafle.overflow.core.model.PageParams;
|
import com.loafle.overflow.core.model.PageParams;
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
import com.loafle.overflow.model.probe.Probe;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
|
@ -17,19 +20,28 @@ import com.loafle.overflow.model.infra.InfraZone;
|
||||||
import com.loafle.overflow.model.meta.MetaIPType;
|
import com.loafle.overflow.model.meta.MetaIPType;
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||||
import com.loafle.overflow.model.meta.MetaTargetHostType;
|
import com.loafle.overflow.model.meta.MetaTargetHostType;
|
||||||
|
import com.loafle.overflow.model.meta.MetaTargetZoneType;
|
||||||
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.NoAuthProbeDescriptionHost;
|
||||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionNetwork;
|
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionNetwork;
|
||||||
|
import com.loafle.overflow.service.central.infra.InfraHostIPService;
|
||||||
import com.loafle.overflow.service.central.infra.InfraService;
|
import com.loafle.overflow.service.central.infra.InfraService;
|
||||||
|
import com.loafle.overflow.service.central.meta.MetaIPTypeService;
|
||||||
|
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 org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service("InfraService")
|
@Service("InfraService")
|
||||||
public class CentralInfraService implements InfraService {
|
public class CentralInfraService implements InfraService {
|
||||||
|
@Autowired
|
||||||
|
ProbeService probeService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
InfraDAO infraDAO;
|
InfraDAO infraDAO;
|
||||||
|
@ -43,6 +55,12 @@ public class CentralInfraService implements InfraService {
|
||||||
@Autowired
|
@Autowired
|
||||||
InfraServiceDAO infraServiceDAO;
|
InfraServiceDAO infraServiceDAO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CentralInfraHostIPService infraHostIPService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CentralMetaIPTypeService metaIPTypeService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Infra regist(Infra infra) throws OverflowException {
|
public Infra regist(Infra infra) throws OverflowException {
|
||||||
return this.infraDAO.save(infra);
|
return this.infraDAO.save(infra);
|
||||||
|
@ -50,6 +68,40 @@ public class CentralInfraService implements InfraService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfraZone registZone(Long probeID, Zone zone) throws OverflowException {
|
public InfraZone registZone(Long probeID, Zone zone) throws OverflowException {
|
||||||
|
if (null == zone) {
|
||||||
|
throw new OverflowException("Zone is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
Probe probe = this.probeService.read(probeID);
|
||||||
|
if (null == probe) {
|
||||||
|
throw new OverflowException(String.format("ID[%d] of Probe is not valid", probeID));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == zone.getNetwork()) {
|
||||||
|
throw new OverflowException("Network is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == zone.getAddress()) {
|
||||||
|
throw new OverflowException("IP is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == zone.getMac()) {
|
||||||
|
throw new OverflowException("Mac is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == zone.getIface()) {
|
||||||
|
throw new OverflowException("Iface is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == zone.getMetaIPTypeKey()) {
|
||||||
|
throw new OverflowException("MetaIPTypeKey is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
MetaIPType metaIPType = this.metaIPTypeService.readByKey(zone.getMetaIPTypeKey());
|
||||||
|
if (null == metaIPType) {
|
||||||
|
throw new OverflowException(String.format("MetaIPTypeKey[%s] is not valid", zone.getMetaIPTypeKey()));
|
||||||
|
}
|
||||||
|
|
||||||
InfraZone infraZone = this.infraZoneDAO.findByProbeIdAndNetwork(probeID, zone.getNetwork());
|
InfraZone infraZone = this.infraZoneDAO.findByProbeIdAndNetwork(probeID, zone.getNetwork());
|
||||||
if (null != infraZone) {
|
if (null != infraZone) {
|
||||||
return infraZone;
|
return infraZone;
|
||||||
|
@ -57,13 +109,70 @@ public class CentralInfraService implements InfraService {
|
||||||
|
|
||||||
infraZone = new InfraZone();
|
infraZone = new InfraZone();
|
||||||
infraZone.setMetaInfraType(MetaInfraType.Enum.ZONE.to());
|
infraZone.setMetaInfraType(MetaInfraType.Enum.ZONE.to());
|
||||||
|
infraZone.setProbe(probe);
|
||||||
|
infraZone.setMetaTargetZoneType(MetaTargetZoneType.Enum.ZONE.to());
|
||||||
|
infraZone.setNetwork(zone.getNetwork());
|
||||||
|
infraZone.setIface(zone.getIface());
|
||||||
|
infraZone.setMetaIPType(metaIPType);
|
||||||
|
infraZone.setAddress(zone.getAddress());
|
||||||
|
infraZone.setMac(zone.getMac());
|
||||||
|
|
||||||
return null;
|
return this.infraZoneDAO.save(infraZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfraHost registHost(Long probeID, Host host) throws OverflowException {
|
public InfraHost registHost(Long probeID, Host host) throws OverflowException {
|
||||||
return null;
|
if (null == host) {
|
||||||
|
throw new OverflowException("Host is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
Probe probe = this.probeService.read(probeID);
|
||||||
|
if (null == probe) {
|
||||||
|
throw new OverflowException(String.format("ID[%d] of Probe is not valid", probeID));
|
||||||
|
}
|
||||||
|
|
||||||
|
Zone zone = host.getZone();
|
||||||
|
if (null == zone) {
|
||||||
|
throw new OverflowException("Zone is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
InfraZone infraZone = this.registZone(probeID, zone);
|
||||||
|
|
||||||
|
if (null == host.getMetaIPTypeKey()) {
|
||||||
|
throw new OverflowException("MetaIPTypeKey is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
MetaIPType metaIPType = this.metaIPTypeService.readByKey(host.getMetaIPTypeKey());
|
||||||
|
if (null == metaIPType) {
|
||||||
|
throw new OverflowException(String.format("MetaIPTypeKey[%s] is not valid", host.getMetaIPTypeKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == host.getAddress()) {
|
||||||
|
throw new OverflowException("IP is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == host.getMac()) {
|
||||||
|
throw new OverflowException("Mac is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
InfraHostIP infraHostIP = this.infraHostIPService.readByInfraHostInfraZoneIDAndMetaIPTypeKeyAndAddress(infraZone.getId(), metaIPType.getKey(), host.getAddress());
|
||||||
|
if (null != infraHostIP) {
|
||||||
|
throw new OverflowException(String.format("IP[%s(%s)] of Zone[%s] is exist already", host.getAddress(), metaIPType.getName(), infraZone.getNetwork()));
|
||||||
|
}
|
||||||
|
|
||||||
|
infraHostIP = new InfraHostIP();
|
||||||
|
infraHostIP.setMetaIPType(metaIPType);
|
||||||
|
infraHostIP.setAddress(host.getAddress());
|
||||||
|
infraHostIP.setMac(host.getMac());
|
||||||
|
|
||||||
|
InfraHost infraHost = new InfraHost();
|
||||||
|
infraZone.setMetaInfraType(MetaInfraType.Enum.HOST.to());
|
||||||
|
infraZone.setProbe(probe);
|
||||||
|
infraHost.setInfraZone(infraZone);
|
||||||
|
infraHost.setMetaTargetHostType(MetaTargetHostType.Enum.UNKNOWN.to());
|
||||||
|
infraHost.setInfraHostIPs(Arrays.asList(infraHostIP));
|
||||||
|
|
||||||
|
return this.infraHostDAO.save(infraHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,6 +182,7 @@ public class CentralInfraService implements InfraService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public List<Infra> registDiscoverd(Long probeID, List<Host> hosts,
|
public List<Infra> registDiscoverd(Long probeID, List<Host> hosts,
|
||||||
List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
|
List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user