ing
This commit is contained in:
parent
48564e1269
commit
950d075fe4
2
pom.xml
2
pom.xml
|
@ -50,7 +50,7 @@
|
|||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>commons-java</artifactId>
|
||||
<version>1.0.27-SNAPSHOT</version>
|
||||
<version>1.0.30-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -16,5 +16,5 @@ public interface InfraHostIPDAO extends JpaRepository<InfraHostIP, Long> {
|
|||
List<InfraHostIP> findAllByInfraHostIdAndMetaIPTypeKey(Long infraHostId, String metaIPTypeKey);
|
||||
List<InfraHostIP> findAllByInfraHostIdAndMac(Long infraHostId, String mac);
|
||||
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.InfraHostPortDAO;
|
||||
import com.loafle.overflow.central.module.meta.service.CentralMetaIPTypeService;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.model.infra.InfraHostIP;
|
||||
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.InfraHostPortService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -21,26 +23,66 @@ public class CentralInfraHostIPService implements InfraHostIPService {
|
|||
@Autowired
|
||||
InfraHostIPDAO infraHostIPDAO;
|
||||
|
||||
@Autowired
|
||||
CentralMetaIPTypeService metaIPTypeService;
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfraHostIP read(Long id) throws OverflowException {
|
||||
return this.infraHostIPDAO.findById(id).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfraHostIP> readByInfraHostID(Long infraHostID) throws OverflowException {
|
||||
return this.infraHostIPDAO.findAllByInfraHostId(infraHostID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfraHostIP> readByInfraHostIDAndMetaIPTypeKey(Long infraHostID, String metaIPTypeKey)
|
||||
throws OverflowException {
|
||||
return this.infraHostIPDAO.findAllByInfraHostIdAndMetaIPTypeKey(infraHostID, metaIPTypeKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfraHostIP readByInfraHostIDAndMetaIPTypeKeyAndAddress(Long infraHostID, String metaIPTypeKey, String address)
|
||||
throws OverflowException {
|
||||
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.module.infra.dao.InfraDAO;
|
||||
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.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.model.probe.Probe;
|
||||
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.MetaInfraType;
|
||||
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.NoAuthProbeDescriptionHost;
|
||||
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.meta.MetaIPTypeService;
|
||||
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 org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service("InfraService")
|
||||
public class CentralInfraService implements InfraService {
|
||||
@Autowired
|
||||
ProbeService probeService;
|
||||
|
||||
@Autowired
|
||||
InfraDAO infraDAO;
|
||||
|
@ -43,6 +55,12 @@ public class CentralInfraService implements InfraService {
|
|||
@Autowired
|
||||
InfraServiceDAO infraServiceDAO;
|
||||
|
||||
@Autowired
|
||||
CentralInfraHostIPService infraHostIPService;
|
||||
|
||||
@Autowired
|
||||
CentralMetaIPTypeService metaIPTypeService;
|
||||
|
||||
@Override
|
||||
public Infra regist(Infra infra) throws OverflowException {
|
||||
return this.infraDAO.save(infra);
|
||||
|
@ -50,6 +68,40 @@ public class CentralInfraService implements InfraService {
|
|||
|
||||
@Override
|
||||
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());
|
||||
if (null != infraZone) {
|
||||
return infraZone;
|
||||
|
@ -57,13 +109,70 @@ public class CentralInfraService implements InfraService {
|
|||
|
||||
infraZone = new InfraZone();
|
||||
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
|
||||
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
|
||||
|
@ -73,6 +182,7 @@ public class CentralInfraService implements InfraService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<Infra> registDiscoverd(Long probeID, List<Host> hosts,
|
||||
List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue
Block a user