targetservice

This commit is contained in:
insanity 2018-06-21 21:55:13 +09:00
parent 4df4a962b6
commit c9d5d19706
2 changed files with 38 additions and 10 deletions

View File

@ -50,7 +50,7 @@
<dependency>
<groupId>com.loafle.overflow</groupId>
<artifactId>commons-java</artifactId>
<version>1.0.92-SNAPSHOT</version>
<version>1.0.93-SNAPSHOT</version>
</dependency>
<dependency>

View File

@ -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<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);
Probe probe = this.probeService.read(probeID);
if (null == probe) {
@ -81,12 +117,4 @@ public class CentralTargetService implements TargetService {
return registered;
}
public List<Target> readAllByZoneID() throws OverflowException {
return null;
}
public List<Target> readAllTargetByProbeID(Long probeID) throws OverflowException {
return null;
}
}