Merge remote-tracking branch 'origin/master'

This commit is contained in:
geek 2018-06-22 11:03:11 +09:00
commit f72126c964
3 changed files with 46 additions and 18 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.92-SNAPSHOT</version> <version>1.0.93-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,5 +1,6 @@
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,9 +9,17 @@ 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.model.infra.Infra; 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.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.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.meta.MetaTargetHostTypeMappingService;
import com.loafle.overflow.service.central.meta.MetaTargetServiceTypeService;
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;
@ -26,7 +35,11 @@ public class CentralTargetService implements TargetService {
@Autowired @Autowired
private TargetDAO targetDAO; private TargetDAO targetDAO;
@Autowired @Autowired
private InfraService infraService;
@Autowired
private CentralProbeService probeService; private CentralProbeService probeService;
@Autowired
private MetaTargetServiceTypeService metaTargetServiceTypeService;
@Transactional @Transactional
public Target regist(Target target, Long probeID) throws OverflowException { public Target regist(Target target, Long probeID) throws OverflowException {
@ -68,7 +81,30 @@ public class CentralTargetService implements TargetService {
} }
@Transactional @Transactional
public List<Target> registAll(List<Target> targets, Long probeID) throws OverflowException { public List<Target> registAll(List<Long> infraIDs, Long probeID) throws OverflowException {
List<Target> targets = new ArrayList<Target>();
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<Target> registered = this.targetDAO.saveAll(targets); List<Target> registered = this.targetDAO.saveAll(targets);
Probe probe = this.probeService.read(probeID); Probe probe = this.probeService.read(probeID);
if (null == probe) { if (null == probe) {
@ -81,12 +117,4 @@ public class CentralTargetService implements TargetService {
return registered; return registered;
} }
public List<Target> readAllByZoneID() throws OverflowException {
return null;
}
public List<Target> readAllTargetByProbeID(Long probeID) throws OverflowException {
return null;
}
} }

View File

@ -21,7 +21,6 @@ import java.util.List;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("test") @ActiveProfiles("test")
@ContextConfiguration(classes = { AppConfigTest.class }) @ContextConfiguration(classes = { AppConfigTest.class })
@ -49,10 +48,10 @@ public class CentralTargetServiceTest {
List<Target> targets = new ArrayList<>(); List<Target> targets = new ArrayList<>();
List<Sensor> sensors = new ArrayList<>(); List<Sensor> sensors = new ArrayList<>();
List<MetaCrawler> metaCrawlers = this.metaCrawlerService.readAll(); List<MetaCrawler> metaCrawlers = this.metaCrawlerService.readAll();
List<MetaSensorStatus> metaSensorStatusList = this.metaSensorStatusService.readAll(); List<MetaSensorStatus> 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 target = new Target();
target.setMetaTargetType(MetaTargetServiceType.Enum.UNKNOWN.to()); target.setMetaTargetType(MetaTargetServiceType.Enum.UNKNOWN.to());
@ -71,8 +70,9 @@ public class CentralTargetServiceTest {
target.setSensors(sensors); target.setSensors(sensors);
targets.add(target); targets.add(target);
List<Target> targetList = this.targetService.registAll(targets, Long.valueOf(1)); // List<Target> targetList = this.targetService.registAll(targets,
// Long.valueOf(1));
System.out.println("Target List Size: " + targetList.size()); // System.out.println("Target List Size: " + targetList.size());
} }
} }