From c9d5d197061da77e0fe606814f78128198d7267e Mon Sep 17 00:00:00 2001 From: insanity Date: Thu, 21 Jun 2018 21:55:13 +0900 Subject: [PATCH] targetservice --- pom.xml | 2 +- .../target/service/CentralTargetService.java | 46 +++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 408a08a..ff0c095 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ com.loafle.overflow commons-java - 1.0.92-SNAPSHOT + 1.0.93-SNAPSHOT diff --git a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java index 9072b4f..85a161b 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java +++ b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java @@ -1,5 +1,6 @@ package com.loafle.overflow.central.module.target.service; +import java.util.ArrayList; import java.util.List; import com.loafle.overflow.central.commons.utils.PageUtil; @@ -8,9 +9,17 @@ import com.loafle.overflow.central.module.target.dao.TargetDAO; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.model.PageParams; 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.meta.MetaTargetHostType; +import com.loafle.overflow.model.meta.MetaTargetServiceType; +import com.loafle.overflow.model.meta.MetaTargetType; +import com.loafle.overflow.model.meta.MetaTargetTypeCategory; 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.meta.MetaTargetHostTypeMappingService; +import com.loafle.overflow.service.central.meta.MetaTargetServiceTypeService; import com.loafle.overflow.service.central.target.TargetService; import org.springframework.beans.factory.annotation.Autowired; @@ -26,7 +35,11 @@ public class CentralTargetService implements TargetService { @Autowired private TargetDAO targetDAO; @Autowired + private InfraService infraService; + @Autowired private CentralProbeService probeService; + @Autowired + private MetaTargetServiceTypeService metaTargetServiceTypeService; @Transactional public Target regist(Target target, Long probeID) throws OverflowException { @@ -68,7 +81,30 @@ public class CentralTargetService implements TargetService { } @Transactional - public List registAll(List targets, Long probeID) throws OverflowException { + public List registAll(List infraIDs, Long probeID) throws OverflowException { + List targets = new ArrayList(); + for (Long infraID : infraIDs) { + Infra infra = this.infraService.read(infraID); + if (null == infra) { + throw new OverflowException(String.format("ID[%d] of Infra is not exist.", infraID)); + } + String metaInfraTypeKey = infra.getMetaInfraType().getKey(); + Target target = new Target(); + target.setInfra(infra); + target.setSensorCount(0); + if (metaInfraTypeKey.equals(MetaInfraType.Enum.HOST.to().getKey())) { + InfraHost infraHost = (InfraHost) infra; + target.setMetaTargetType(MetaTargetHostType.Enum.UNKNOWN.to()); + target.setName(infraHost.getInfraHostIPs().get(0).getAddress()); + } else if (metaInfraTypeKey.equals(MetaInfraType.Enum.SERVICE.to().getKey())) { + com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService) infra; + target.setMetaTargetType(infraService.getMetaTargetServiceType()); + String name = infraService.getMetaTargetServiceType().getName() + " on " + + infraService.getInfraHostPort().getInfraHostIP().getAddress(); + target.setName(name); + } + targets.add(target); + } List registered = this.targetDAO.saveAll(targets); Probe probe = this.probeService.read(probeID); if (null == probe) { @@ -81,12 +117,4 @@ public class CentralTargetService implements TargetService { return registered; } - public List readAllByZoneID() throws OverflowException { - return null; - } - - public List readAllTargetByProbeID(Long probeID) throws OverflowException { - return null; - } - }