fixed exception

This commit is contained in:
snoop 2017-09-14 17:17:40 +09:00
parent a194d9ae91
commit 83c412885d
8 changed files with 128 additions and 8 deletions

View File

@ -22,7 +22,18 @@ public class AuthCrawlerService {
private InfraService infraService; private InfraService infraService;
public AuthCrawler regist(AuthCrawler authCrawler) { public AuthCrawler regist(AuthCrawler authCrawler) {
return this.authCrawlerDAO.save(authCrawler);
AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByCrawlerAndTarget(authCrawler.getCrawler(), authCrawler.getTarget());
if(authCrawler == null) {
return this.authCrawlerDAO.save(authCrawler);
}
dbAuthCrawler.setAuthJson(authCrawler.getAuthJson());
dbAuthCrawler.setCrawler(authCrawler.getCrawler());
dbAuthCrawler.setTarget(authCrawler.getTarget());
return this.authCrawlerDAO.save(dbAuthCrawler);
} }
public boolean checkAuthCrawler(long infraId, MetaCrawler crawler, String authJson) { public boolean checkAuthCrawler(long infraId, MetaCrawler crawler, String authJson) {

View File

@ -0,0 +1,16 @@
package com.loafle.overflow.module.infra.exception;
import com.loafle.overflow.commons.exception.OverflowRuntimeException;
/**
* Created by snoop on 17. 9. 14.
*/
public class InfraNotFoundException extends OverflowRuntimeException {
public InfraNotFoundException() {
super();
}
public InfraNotFoundException(String message) {
super(message);
}
}

View File

@ -5,6 +5,7 @@ import com.loafle.overflow.commons.utils.PageUtil;
import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.domain.model.Domain;
import com.loafle.overflow.module.infra.dao.InfraDAO; import com.loafle.overflow.module.infra.dao.InfraDAO;
import com.loafle.overflow.module.infra.model.Infra; import com.loafle.overflow.module.infra.model.Infra;
import com.loafle.overflow.module.probe.exception.ProbeNotFoundException;
import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.probe.model.Probe;
import com.loafle.overflow.module.probe.service.ProbeService; import com.loafle.overflow.module.probe.service.ProbeService;
import com.loafle.overflow.module.target.model.Target; import com.loafle.overflow.module.target.model.Target;
@ -41,6 +42,11 @@ public class InfraService {
public Page<Infra> readAllByDomain(Domain domain, PageParams pageParams) { public Page<Infra> readAllByDomain(Domain domain, PageParams pageParams) {
List<Probe> probeList = this.probeService.readAllByDomain(domain); List<Probe> probeList = this.probeService.readAllByDomain(domain);
if(probeList == null || probeList.size() <= 0) {
throw new ProbeNotFoundException();
}
return this.infraDAO.findAllByProbeList(probeList, PageUtil.getPageRequest(pageParams)); return this.infraDAO.findAllByProbeList(probeList, PageUtil.getPageRequest(pageParams));
} }
@ -52,6 +58,10 @@ public class InfraService {
List<Probe> probeList = this.probeService.readAllByDomain(domain); List<Probe> probeList = this.probeService.readAllByDomain(domain);
if(probeList == null || probeList.size() <= 0) {
throw new ProbeNotFoundException();
}
return this.infraDAO.findAllTargetByProbeList(probeList); return this.infraDAO.findAllTargetByProbeList(probeList);
} }

View File

@ -55,6 +55,11 @@ public class NoAuthProbeService {
// Todo domain injection & member injection // Todo domain injection & member injection
List<Probe> probes = new ArrayList<>(); List<Probe> probes = new ArrayList<>();
Probe probe = null; Probe probe = null;
Map<String, Object> objMap = null;
Map<String, String> hostMap = null;
Map<String, String> netMap = null;
for (NoAuthProbe noAuth : noAuthProbes) { for (NoAuthProbe noAuth : noAuthProbes) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString()); String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
@ -68,13 +73,7 @@ public class NoAuthProbeService {
probe.setTargetCount(0); probe.setTargetCount(0);
probe.setSensorCount(0); probe.setSensorCount(0);
Map<String, Object> objMap = null;
objMap = this.objectMapper.readValue(noAuth.getDescription(), new TypeReference<HashMap<String,Object>>() {}); objMap = this.objectMapper.readValue(noAuth.getDescription(), new TypeReference<HashMap<String,Object>>() {});
Map<String, String> hostMap = null;
Map<String, String> netMap = null;
hostMap = (Map<String, String>)objMap.get("host"); hostMap = (Map<String, String>)objMap.get("host");
netMap = (Map<String, String>)objMap.get("network"); netMap = (Map<String, String>)objMap.get("network");

View File

@ -0,0 +1,16 @@
package com.loafle.overflow.module.probe.exception;
import com.loafle.overflow.commons.exception.OverflowRuntimeException;
/**
* Created by snoop on 17. 9. 14.
*/
public class ProbeNotFoundException extends OverflowRuntimeException {
public ProbeNotFoundException() {
super();
}
public ProbeNotFoundException(String message) {
super(message);
}
}

View File

@ -4,15 +4,18 @@ import com.loafle.overflow.commons.model.PageParams;
import com.loafle.overflow.commons.utils.PageUtil; import com.loafle.overflow.commons.utils.PageUtil;
import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.domain.model.Domain;
import com.loafle.overflow.module.generator.service.SensorConfigGenerator; import com.loafle.overflow.module.generator.service.SensorConfigGenerator;
import com.loafle.overflow.module.infra.exception.InfraNotFoundException;
import com.loafle.overflow.module.infra.model.Infra; import com.loafle.overflow.module.infra.model.Infra;
import com.loafle.overflow.module.infra.service.InfraService; import com.loafle.overflow.module.infra.service.InfraService;
import com.loafle.overflow.module.meta.model.MetaSensorStatus; import com.loafle.overflow.module.meta.model.MetaSensorStatus;
import com.loafle.overflow.module.meta.service.MetaSensorItemKeyService; import com.loafle.overflow.module.meta.service.MetaSensorItemKeyService;
import com.loafle.overflow.module.probe.exception.ProbeNotFoundException;
import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.probe.model.Probe;
import com.loafle.overflow.module.probe.service.ProbeService; import com.loafle.overflow.module.probe.service.ProbeService;
import com.loafle.overflow.module.sensor.dao.SensorDAO; import com.loafle.overflow.module.sensor.dao.SensorDAO;
import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.sensor.model.Sensor;
import com.loafle.overflow.module.sensor.model.SensorItem; import com.loafle.overflow.module.sensor.model.SensorItem;
import com.loafle.overflow.module.target.exception.TargetNotFoundException;
import com.loafle.overflow.module.target.model.Target; import com.loafle.overflow.module.target.model.Target;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -58,15 +61,25 @@ public class SensorService {
List<Probe> probeList = this.probeService.readAllByDomain(domain); List<Probe> probeList = this.probeService.readAllByDomain(domain);
if(probeList == null || probeList.size() <= 0) {
throw new ProbeNotFoundException();
}
List<Target> targetList = this.infraService.readAllTargetByProbeList(probeList); List<Target> targetList = this.infraService.readAllTargetByProbeList(probeList);
if(targetList == null || targetList.size() <= 0) {
throw new TargetNotFoundException();
}
return this.sensorDAO.findAllByTargetList(targetList, PageUtil.getPageRequest(pageParams)); return this.sensorDAO.findAllByTargetList(targetList, PageUtil.getPageRequest(pageParams));
} }
public Page<Sensor> readAllByInfra(long infraId, PageParams pageParams) { public Page<Sensor> readAllByInfra(long infraId, PageParams pageParams) {
Infra dbInfra = this.infraService.read(infraId); Infra dbInfra = this.infraService.read(infraId);
if(dbInfra == null || dbInfra.getTarget() == null) return null; if(dbInfra == null || dbInfra.getTarget() == null) {
throw new InfraNotFoundException();
}
return this.sensorDAO.findAllByTarget(dbInfra.getTarget(), PageUtil.getPageRequest(pageParams)); return this.sensorDAO.findAllByTarget(dbInfra.getTarget(), PageUtil.getPageRequest(pageParams));

View File

@ -0,0 +1,16 @@
package com.loafle.overflow.module.target.exception;
import com.loafle.overflow.commons.exception.OverflowRuntimeException;
/**
* Created by snoop on 17. 9. 14.
*/
public class TargetNotFoundException extends OverflowRuntimeException {
public TargetNotFoundException() {
super();
}
public TargetNotFoundException(String message) {
super(message);
}
}

View File

@ -0,0 +1,39 @@
package com.loafle.overflow.module.infra.dao;
import com.loafle.overflow.module.probe.model.Probe;
import com.loafle.overflow.spring.AppConfigTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.List;
/**
* Created by snoop on 17. 9. 14.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AppConfigTest.class})
public class InfraDAOTest {
@Autowired
private InfraDAO infraDAO;
@Test
public void findAllByProbeList() throws Exception {
List<Probe> probes = new ArrayList<>();
Probe probe = new Probe();
probe.setId(1);
probes.add(probe);
this.infraDAO.findAllTargetByProbeList(probes);
}
}