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;
- }
-
}
diff --git a/src/test/java/com/loafle/overflow/central/module/target/service/CentralTargetServiceTest.java b/src/test/java/com/loafle/overflow/central/module/target/service/CentralTargetServiceTest.java
index 740bf2d..000897a 100644
--- a/src/test/java/com/loafle/overflow/central/module/target/service/CentralTargetServiceTest.java
+++ b/src/test/java/com/loafle/overflow/central/module/target/service/CentralTargetServiceTest.java
@@ -21,10 +21,9 @@ import java.util.List;
import static org.junit.Assert.*;
-
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("test")
-@ContextConfiguration(classes = {AppConfigTest.class})
+@ContextConfiguration(classes = { AppConfigTest.class })
public class CentralTargetServiceTest {
@Autowired
@@ -43,20 +42,20 @@ public class CentralTargetServiceTest {
public void regist() {
}
-// List targets, Long probeID
+ // List targets, Long probeID
@Test
public void registAll() throws OverflowException {
List targets = new ArrayList<>();
List sensors = new ArrayList<>();
-
List metaCrawlers = this.metaCrawlerService.readAll();
List metaSensorStatusList = this.metaSensorStatusService.readAll();
-// MetaSensorDisplayItem metaSensorDisplayItem = this.metaSensorDisplayItemService.read(Long.valueOf(1));
+ // MetaSensorDisplayItem metaSensorDisplayItem =
+ // this.metaSensorDisplayItemService.read(Long.valueOf(1));
Target target = new Target();
target.setMetaTargetType(MetaTargetServiceType.Enum.UNKNOWN.to());
- target.setInfra(new com.loafle.overflow.model.infra.InfraService(Long.valueOf((long)3)));
+ target.setInfra(new com.loafle.overflow.model.infra.InfraService(Long.valueOf((long) 3)));
Sensor sensor = new Sensor();
sensor.setItemCount(0);
@@ -71,8 +70,9 @@ public class CentralTargetServiceTest {
target.setSensors(sensors);
targets.add(target);
- List targetList = this.targetService.registAll(targets, Long.valueOf(1));
+ // List targetList = this.targetService.registAll(targets,
+ // Long.valueOf(1));
- System.out.println("Target List Size: " + targetList.size());
+ // System.out.println("Target List Size: " + targetList.size());
}
}