arranging
This commit is contained in:
parent
07e9f73e48
commit
08a8dbc18b
2
pom.xml
2
pom.xml
|
@ -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.14-SNAPSHOT</version>
|
<version>1.0.18-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class PageUtil {
|
||||||
if (pageParams.getSortDirection().isEmpty())
|
if (pageParams.getSortDirection().isEmpty())
|
||||||
pageParams.setSortDirection("descending");
|
pageParams.setSortDirection("descending");
|
||||||
|
|
||||||
return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(),
|
return PageRequest.of(pageParams.getPageNo(), pageParams.getCountPerPage(),
|
||||||
new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol()));
|
new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,43 +19,7 @@ import com.loafle.overflow.service.central.sensor.SensorItemService;
|
||||||
@Service("SensorConfigGenerator")
|
@Service("SensorConfigGenerator")
|
||||||
public class SensorConfigGenerator {
|
public class SensorConfigGenerator {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SensorItemService sensorItemService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraService infraService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraHostGenerator infraHostGenerator;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraServiceGenerator infraServiceGenerator;
|
|
||||||
|
|
||||||
public String generate(Sensor sensor) throws Exception {
|
public String generate(Sensor sensor) throws Exception {
|
||||||
PageParams pageParams = new PageParams();
|
|
||||||
pageParams.setPageNo(0);
|
|
||||||
pageParams.setCountPerPage(Integer.MAX_VALUE);
|
|
||||||
pageParams.setSortCol("id");
|
|
||||||
pageParams.setSortDirection("descending");
|
|
||||||
Page<SensorItem> dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams);
|
|
||||||
|
|
||||||
List<SensorItem> sensorItems = dbItemList.getContent();
|
|
||||||
|
|
||||||
if (sensorItems.size() <= 0) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
Sensor dbSensor = sensorItems.get(0).getSensor();
|
|
||||||
|
|
||||||
Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId());
|
|
||||||
|
|
||||||
// 7 = Infra OS Service
|
|
||||||
if (infra.getMetaInfraType().getId() == 7) {
|
|
||||||
return this.infraServiceGenerator.process(dbSensor, sensorItems, infra);
|
|
||||||
}
|
|
||||||
if (infra.getMetaInfraType().getId() == 2) {
|
|
||||||
return this.infraHostGenerator.process(dbSensor, sensorItems, infra);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,8 @@ package com.loafle.overflow.central.module.infra.service;
|
||||||
import com.loafle.overflow.central.commons.utils.PageUtil;
|
import com.loafle.overflow.central.commons.utils.PageUtil;
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraDAO;
|
import com.loafle.overflow.central.module.infra.dao.InfraDAO;
|
||||||
import com.loafle.overflow.core.model.PageParams;
|
import com.loafle.overflow.core.model.PageParams;
|
||||||
import com.loafle.overflow.model.domain.Domain;
|
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
import com.loafle.overflow.model.probe.Probe;
|
||||||
import com.loafle.overflow.central.module.sensor.dao.SensorDAO;
|
import com.loafle.overflow.central.module.sensor.dao.SensorDAO;
|
||||||
import com.loafle.overflow.model.target.Target;
|
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.model.infra.Infra;
|
import com.loafle.overflow.model.infra.Infra;
|
||||||
import com.loafle.overflow.service.central.infra.InfraService;
|
import com.loafle.overflow.service.central.infra.InfraService;
|
||||||
|
@ -17,9 +15,6 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by insanity on 17. 6. 28.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Service("InfraService")
|
@Service("InfraService")
|
||||||
public class CentralInfraService implements InfraService {
|
public class CentralInfraService implements InfraService {
|
||||||
|
@ -38,8 +33,7 @@ public class CentralInfraService implements InfraService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Infra read(Long id) throws OverflowException {
|
public Infra read(Long id) throws OverflowException {
|
||||||
Infra infra = this.infraDAO.findById(id).get();
|
return this.infraDAO.findById(id).get();
|
||||||
return infra;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Infra> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
|
public Page<Infra> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
|
||||||
|
@ -57,25 +51,4 @@ public class CentralInfraService implements InfraService {
|
||||||
return infraList;
|
return infraList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Target> readAllTargetByDomainID(Long domainID) throws OverflowException {
|
|
||||||
|
|
||||||
List<Probe> probes = this.probeService.readAllByDomainID(domainID);
|
|
||||||
|
|
||||||
if (probes == null || probes.size() <= 0) {
|
|
||||||
throw new OverflowException("ProbeNotFoundException", new Throwable());
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.infraDAO.findAllTargetByProbeIn(probes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Target> readAllTargetByProbes(List<Probe> probes) throws OverflowException {
|
|
||||||
return this.infraDAO.findAllTargetByProbeIn(probes);
|
|
||||||
// return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Infra readByTargetID(Long targetID) throws OverflowException {
|
|
||||||
// return this.infraDAO.findByTargetId(targetID);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.loafle.overflow.central.module.infra.dao.InfraServiceDAO;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.model.infra.InfraService;
|
import com.loafle.overflow.model.infra.InfraService;
|
||||||
import com.loafle.overflow.service.central.infra.InfraServiceService;
|
import com.loafle.overflow.service.central.infra.InfraServiceService;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -16,15 +17,15 @@ public class CentralInfraServiceService implements InfraServiceService {
|
||||||
@Autowired
|
@Autowired
|
||||||
InfraServiceDAO infraServiceDAO;
|
InfraServiceDAO infraServiceDAO;
|
||||||
|
|
||||||
public InfraService regist(InfraService infraService) throws OverflowException {
|
public com.loafle.overflow.model.infra.InfraService regist(InfraService infraService) throws OverflowException {
|
||||||
return this.infraServiceDAO.save(infraService);
|
return this.infraServiceDAO.save(infraService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InfraService read(Long id) throws OverflowException {
|
public com.loafle.overflow.model.infra.InfraService read(Long id) throws OverflowException {
|
||||||
return this.infraServiceDAO.findById(id).get();
|
return this.infraServiceDAO.findById(id).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType)
|
public com.loafle.overflow.model.infra.InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType)
|
||||||
throws OverflowException {
|
throws OverflowException {
|
||||||
return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, portType);
|
return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, portType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.loafle.overflow.central.module.member.service;
|
package com.loafle.overflow.central.module.member.service;
|
||||||
|
|
||||||
import com.loafle.overflow.core.annotation.WebappAPI;
|
import com.loafle.overflow.core.annotation.WebappAPI;
|
||||||
import com.loafle.overflow.central.commons.utils.SessionMetadata;
|
|
||||||
import com.loafle.overflow.central.module.member.dao.MemberDAO;
|
import com.loafle.overflow.central.module.member.dao.MemberDAO;
|
||||||
|
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
|
@ -168,13 +167,24 @@ public class CentralMemberService implements MemberService {
|
||||||
return this.modify(member);
|
return this.modify(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Member> readAllByProbeKey(String probeKey) throws OverflowException {
|
||||||
|
|
||||||
|
Probe probe = this.probeService.readByProbeKey(probeKey);
|
||||||
|
|
||||||
|
if (probe == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void signout(Member member) {
|
public void signout(Member member) {
|
||||||
// Todo websocket session remove
|
// Todo websocket session remove
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebappAPI
|
@WebappAPI
|
||||||
public Member modify(Member member, String pw) throws OverflowException {
|
public Member modify(Member member, String pw) throws OverflowException {
|
||||||
String email = SessionMetadata.getTargetID();
|
|
||||||
Member preMember = this.memberDAO.findByEmail(member.getEmail());
|
Member preMember = this.memberDAO.findByEmail(member.getEmail());
|
||||||
|
|
||||||
if (null == preMember || 0 >= preMember.getId()) {
|
if (null == preMember || 0 >= preMember.getId()) {
|
||||||
|
@ -246,21 +256,10 @@ public class CentralMemberService implements MemberService {
|
||||||
|
|
||||||
@WebappAPI
|
@WebappAPI
|
||||||
public void withdrawal(Long memberId) throws OverflowException {
|
public void withdrawal(Long memberId) throws OverflowException {
|
||||||
String email = SessionMetadata.getTargetID();
|
// String email = SessionMetadata.getTargetID();
|
||||||
|
|
||||||
// Todo DB delete?
|
// Todo DB delete?
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Member> readAllByProbeKey(String probeKey) throws OverflowException {
|
|
||||||
|
|
||||||
Probe probe = this.probeService.readByProbeKey(probeKey);
|
|
||||||
|
|
||||||
if (probe == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Member> readAllByApiKey(String apikey) throws OverflowException {
|
public List<Member> readAllByApiKey(String apikey) throws OverflowException {
|
||||||
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.probe.dao;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.loafle.overflow.model.probe.ProbeTask;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 6. 26.
|
|
||||||
*/
|
|
||||||
@Repository
|
|
||||||
public interface ProbeTaskDAO extends JpaRepository<ProbeTask, Long> {
|
|
||||||
List<ProbeTask> findAllByProbeId(Long probeId);
|
|
||||||
}
|
|
|
@ -10,15 +10,16 @@ import com.loafle.overflow.service.central.probe.ProbeHostService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 8. 21.
|
|
||||||
*/
|
|
||||||
@Service("ProbeHostService")
|
@Service("ProbeHostService")
|
||||||
public class CentralProbeHostService implements ProbeHostService {
|
public class CentralProbeHostService implements ProbeHostService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProbeHostDAO probeHostDAO;
|
private ProbeHostDAO probeHostDAO;
|
||||||
|
|
||||||
|
public ProbeHost regist(ProbeHost probeHost) throws OverflowException {
|
||||||
|
return this.probeHostDAO.save(probeHost);
|
||||||
|
}
|
||||||
|
|
||||||
public ProbeHost read(Long id) throws OverflowException {
|
public ProbeHost read(Long id) throws OverflowException {
|
||||||
return this.probeHostDAO.findById(id).get();
|
return this.probeHostDAO.findById(id).get();
|
||||||
}
|
}
|
||||||
|
@ -27,10 +28,6 @@ public class CentralProbeHostService implements ProbeHostService {
|
||||||
return this.probeHostDAO.findByProbeId(probeID);
|
return this.probeHostDAO.findByProbeId(probeID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProbeHost regist(ProbeHost probeHost) throws OverflowException {
|
|
||||||
return this.probeHostDAO.save(probeHost);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ProbeHost> readAllByDomainID(Long domainID) throws OverflowException {
|
public List<ProbeHost> readAllByDomainID(Long domainID) throws OverflowException {
|
||||||
return this.probeHostDAO.findAllByProbeDomainId(domainID);
|
return this.probeHostDAO.findAllByProbeDomainId(domainID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,7 @@ import org.springframework.stereotype.Service;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 6. 28.
|
|
||||||
*/
|
|
||||||
@Service("ProbeService")
|
@Service("ProbeService")
|
||||||
public class CentralProbeService implements ProbeService {
|
public class CentralProbeService implements ProbeService {
|
||||||
|
|
||||||
|
@ -27,10 +25,6 @@ public class CentralProbeService implements ProbeService {
|
||||||
return this.probeDAO.save(probe);
|
return this.probeDAO.save(probe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Probe> regist(List<Probe> probes) throws OverflowException {
|
|
||||||
return (List<Probe>) this.probeDAO.saveAll(probes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Probe> readAllByDomainID(Long domainID) throws OverflowException {
|
public List<Probe> readAllByDomainID(Long domainID) throws OverflowException {
|
||||||
List<Probe> probes = this.probeDAO.findAllByDomainIdOrderByIdDesc(domainID);
|
List<Probe> probes = this.probeDAO.findAllByDomainIdOrderByIdDesc(domainID);
|
||||||
return probes;
|
return probes;
|
||||||
|
@ -39,11 +33,7 @@ public class CentralProbeService implements ProbeService {
|
||||||
public Probe read(Long id) throws OverflowException {
|
public Probe read(Long id) throws OverflowException {
|
||||||
return this.probeDAO.findById(id).get();
|
return this.probeDAO.findById(id).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Probe readByProbeKey(String probeKey) throws OverflowException {
|
|
||||||
return this.probeDAO.findByProbeKey(probeKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Probe modify(Probe probe) throws OverflowException {
|
public Probe modify(Probe probe) throws OverflowException {
|
||||||
return this.probeDAO.save(probe);
|
return this.probeDAO.save(probe);
|
||||||
}
|
}
|
||||||
|
@ -53,14 +43,18 @@ public class CentralProbeService implements ProbeService {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Probe increaseTargetCount(Probe probe) {
|
public Probe readByProbeKey(String probeKey) throws OverflowException {
|
||||||
Probe p = this.probeDAO.findById(probe.getId()).get();
|
return this.probeDAO.findByProbeKey(probeKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Probe increaseTargetCount(Long id) throws OverflowException {
|
||||||
|
Probe p = this.probeDAO.findById(id).get();
|
||||||
p.setTargetCount(p.getTargetCount() + 1);
|
p.setTargetCount(p.getTargetCount() + 1);
|
||||||
return this.probeDAO.save(p);
|
return this.probeDAO.save(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Probe decreaseTargetCount(Probe probe) {
|
public Probe decreaseTargetCount(Long id) throws OverflowException {
|
||||||
Probe p = this.probeDAO.findById(probe.getId()).get();
|
Probe p = this.probeDAO.findById(id).get();
|
||||||
int count = p.getTargetCount();
|
int count = p.getTargetCount();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
p.setTargetCount(count - 1);
|
p.setTargetCount(count - 1);
|
||||||
|
@ -68,11 +62,6 @@ public class CentralProbeService implements ProbeService {
|
||||||
return this.probeDAO.save(p);
|
return this.probeDAO.save(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Probe modifyDisplayName(Long probeId, String displayName) {
|
|
||||||
Probe probe = this.probeDAO.findById(probeId).get();
|
|
||||||
probe.setDisplayName(displayName);
|
|
||||||
return this.probeDAO.save(probe);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onConnect(String probeKey, String connectAddress) throws OverflowException {
|
public void onConnect(String probeKey, String connectAddress) throws OverflowException {
|
||||||
Probe probe = this.probeDAO.findByProbeKey(probeKey);
|
Probe probe = this.probeDAO.findByProbeKey(probeKey);
|
||||||
|
@ -91,4 +80,5 @@ public class CentralProbeService implements ProbeService {
|
||||||
|
|
||||||
messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onDisconnect", probe);
|
messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onDisconnect", probe);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.probe.service;
|
|
||||||
|
|
||||||
import com.loafle.overflow.central.module.probe.dao.ProbeTaskDAO;
|
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
|
||||||
import com.loafle.overflow.model.probe.ProbeTask;
|
|
||||||
import com.loafle.overflow.service.central.probe.ProbeTaskService;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 6. 28.
|
|
||||||
*/
|
|
||||||
@Service("ProbeTaskService")
|
|
||||||
public class CentralProbeTaskService implements ProbeTaskService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ProbeTaskDAO probeTaskDAO;
|
|
||||||
|
|
||||||
public ProbeTask regist(ProbeTask probeTask) throws OverflowException {
|
|
||||||
return this.probeTaskDAO.save(probeTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ProbeTask> readAllByProbeID(Long probeID) throws OverflowException {
|
|
||||||
return this.probeTaskDAO.findAllByProbeId(probeID);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,4 +20,6 @@ public interface SensorDAO extends JpaRepository<Sensor, Long> {
|
||||||
List<Sensor> findAllByTargetId(Long targetID);
|
List<Sensor> findAllByTargetId(Long targetID);
|
||||||
|
|
||||||
Page<Sensor> findAllByTargetIn(List<Target> targets, Pageable pageable);
|
Page<Sensor> findAllByTargetIn(List<Target> targets, Pageable pageable);
|
||||||
|
|
||||||
|
Page<Sensor> findAllByTargetInfraId(Long infraID, Pageable pageable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class CentralSensorItemService implements SensorItemService {
|
||||||
@Transactional
|
@Transactional
|
||||||
public SensorItem regist(SensorItem sensorItem) throws OverflowException {
|
public SensorItem regist(SensorItem sensorItem) throws OverflowException {
|
||||||
Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get();
|
Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get();
|
||||||
s.setItemCount((short) (s.getItemCount() + 1));
|
s.setItemCount(s.getItemCount() + 1);
|
||||||
this.sensorDAO.save(s);
|
this.sensorDAO.save(s);
|
||||||
return this.sensorItemDAO.save(sensorItem);
|
return this.sensorItemDAO.save(sensorItem);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class CentralSensorItemService implements SensorItemService {
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean registAll(List<SensorItem> sensorItemList) throws OverflowException {
|
public boolean registAll(List<SensorItem> sensorItemList) throws OverflowException {
|
||||||
Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get();
|
Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get();
|
||||||
s.setItemCount((short) sensorItemList.size());
|
s.setItemCount(sensorItemList.size());
|
||||||
this.sensorDAO.save(s);
|
this.sensorDAO.save(s);
|
||||||
this.sensorItemDAO.saveAll(sensorItemList);
|
this.sensorItemDAO.saveAll(sensorItemList);
|
||||||
return true;
|
return true;
|
||||||
|
@ -55,7 +55,7 @@ public class CentralSensorItemService implements SensorItemService {
|
||||||
@Transactional
|
@Transactional
|
||||||
public void remove(SensorItem sensorItem) throws OverflowException {
|
public void remove(SensorItem sensorItem) throws OverflowException {
|
||||||
Sensor s = sensorItem.getSensor();
|
Sensor s = sensorItem.getSensor();
|
||||||
s.setItemCount((short) (s.getItemCount() - 1));
|
s.setItemCount(s.getItemCount() - 1);
|
||||||
this.sensorDAO.save(s);
|
this.sensorDAO.save(s);
|
||||||
this.sensorItemDAO.delete(sensorItem);
|
this.sensorItemDAO.delete(sensorItem);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,8 @@ import com.loafle.overflow.central.module.generator.service.SensorConfigGenerato
|
||||||
import com.loafle.overflow.central.module.sensor.dao.SensorDAO;
|
import com.loafle.overflow.central.module.sensor.dao.SensorDAO;
|
||||||
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.meta.MetaSensorStatus;
|
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
|
||||||
import com.loafle.overflow.model.sensor.Sensor;
|
import com.loafle.overflow.model.sensor.Sensor;
|
||||||
import com.loafle.overflow.model.sensor.SensorItem;
|
import com.loafle.overflow.model.sensor.SensorItem;
|
||||||
import com.loafle.overflow.model.target.Target;
|
|
||||||
import com.loafle.overflow.service.central.infra.InfraService;
|
|
||||||
import com.loafle.overflow.service.central.probe.ProbeService;
|
|
||||||
import com.loafle.overflow.service.central.sensor.SensorItemService;
|
import com.loafle.overflow.service.central.sensor.SensorItemService;
|
||||||
import com.loafle.overflow.service.central.sensor.SensorService;
|
import com.loafle.overflow.service.central.sensor.SensorService;
|
||||||
import com.loafle.overflow.service.central.target.TargetService;
|
import com.loafle.overflow.service.central.target.TargetService;
|
||||||
|
@ -32,12 +27,6 @@ public class CentralSensorService implements SensorService {
|
||||||
@Autowired
|
@Autowired
|
||||||
SensorDAO sensorDAO;
|
SensorDAO sensorDAO;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ProbeService probeService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraService infraService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SensorItemService sensorItemService;
|
private SensorItemService sensorItemService;
|
||||||
|
|
||||||
|
@ -48,72 +37,61 @@ public class CentralSensorService implements SensorService {
|
||||||
private TargetService targetService;
|
private TargetService targetService;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Sensor regist(Sensor sensor) throws OverflowException {
|
public Sensor regist(Sensor sensor, Long targetID) throws OverflowException {
|
||||||
this.targetService.increaseSensorCount(sensor.getTarget());
|
this.targetService.increaseSensorCount(targetID);
|
||||||
return this.sensorDAO.save(sensor);
|
return this.sensorDAO.save(sensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Sensor read(Long id) throws OverflowException {
|
||||||
|
return this.sensorDAO.findById(id).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void remove(Long id, Long targertID) throws OverflowException {
|
||||||
|
this.targetService.decreaseSensorCount(targertID);
|
||||||
|
this.sensorDAO.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<Sensor> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
|
||||||
|
// FIXME: NOT IMPLEMENTS
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Page<Sensor> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
|
public Page<Sensor> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
|
||||||
|
// FIXME: NOT IMPLEMENTS
|
||||||
List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
|
return null;
|
||||||
|
|
||||||
if (probeList == null || probeList.size() <= 0) {
|
|
||||||
throw new OverflowException("", new Throwable());
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Target> targetList = this.infraService.readAllTargetByProbes(probeList);
|
|
||||||
|
|
||||||
if (targetList == null || targetList.size() <= 0) {
|
|
||||||
throw new OverflowException("", new Throwable());
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
|
public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
|
||||||
// Infra dbInfra = this.infraService.read(infraID);
|
return this.sensorDAO.findAllByTargetInfraId(infraID, PageUtil.getPageRequest(pageParams));
|
||||||
// if (dbInfra == null) {
|
|
||||||
// throw new OverflowException("", new Throwable());
|
|
||||||
// }
|
|
||||||
// return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(),
|
|
||||||
// PageUtil.getPageRequest(pageParams));
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Sensor> readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException {
|
public Page<Sensor> readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException {
|
||||||
return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams));
|
return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sensor read(Long id) throws OverflowException {
|
@Override
|
||||||
return this.sensorDAO.findById(Long.valueOf(id)).get();
|
public Sensor increaseSensorItemCount(Long id) throws OverflowException {
|
||||||
|
Sensor s = this.sensorDAO.findById(id).get();
|
||||||
|
s.setItemCount(s.getItemCount() + 1);
|
||||||
|
return this.sensorDAO.save(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Override
|
||||||
public void remove(Long sensorID) throws OverflowException {
|
public Sensor decreaseSensorItemCount(Long id) throws OverflowException {
|
||||||
Sensor sensor = this.sensorDAO.findById(sensorID).get();
|
Sensor s = this.sensorDAO.findById(id).get();
|
||||||
this.targetService.decreaseSensorCount(sensor.getTarget());
|
int count = s.getItemCount();
|
||||||
this.sensorDAO.delete(sensor);
|
if (count > 0) {
|
||||||
}
|
s.setItemCount(count - 1);
|
||||||
|
}
|
||||||
public Sensor start(Long sensorID) throws OverflowException {
|
return this.sensorDAO.save(s);
|
||||||
Sensor sensor = this.sensorDAO.findById(sensorID).get();
|
|
||||||
MetaSensorStatus status = new MetaSensorStatus((short) 1);
|
|
||||||
sensor.setMetaSensorStatus(status);
|
|
||||||
return this.sensorDAO.save(sensor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sensor stop(Long sensorID) throws OverflowException {
|
|
||||||
Sensor sensor = this.sensorDAO.findById(sensorID).get();
|
|
||||||
MetaSensorStatus status = new MetaSensorStatus((short) 2);
|
|
||||||
sensor.setMetaSensorStatus(status);
|
|
||||||
return this.sensorDAO.save(sensor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Sensor registSensorConfig(Sensor sensor, List<SensorItem> sensorItemList, String etcJson)
|
public Sensor registSensorConfig(Sensor sensor, List<SensorItem> sensorItemList, String etcJson)
|
||||||
throws OverflowException {
|
throws OverflowException {
|
||||||
|
|
||||||
this.targetService.increaseSensorCount(sensor.getTarget());
|
this.targetService.increaseSensorCount(sensor.getTarget().getId());
|
||||||
this.sensorDAO.save(sensor);
|
this.sensorDAO.save(sensor);
|
||||||
|
|
||||||
for (SensorItem sensorItem : sensorItemList) {
|
for (SensorItem sensorItem : sensorItemList) {
|
||||||
|
@ -132,9 +110,4 @@ public class CentralSensorService implements SensorService {
|
||||||
throw new OverflowException("", new Throwable());
|
throw new OverflowException("", new Throwable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// public List<Sensor> readAllByTarget(Target target, PageParams pageParams) {
|
|
||||||
// return this.sensorDAO.findAllByTarget(target,
|
|
||||||
// PageUtil.getPageRequest(pageParams));
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -1,237 +0,0 @@
|
||||||
// package com.loafle.overflow.central.module.target.service;
|
|
||||||
|
|
||||||
// import com.loafle.overflow.central.module.infra.service.*;
|
|
||||||
// import com.loafle.overflow.core.exception.OverflowException;
|
|
||||||
// import com.loafle.overflow.core.type.PortType;
|
|
||||||
// import com.loafle.overflow.model.discovery.Host;
|
|
||||||
// import com.loafle.overflow.model.discovery.Port;
|
|
||||||
|
|
||||||
// import com.loafle.overflow.model.infra.*;
|
|
||||||
// import com.loafle.overflow.model.meta.MetaInfraType;
|
|
||||||
// import com.loafle.overflow.model.meta.MetaInfraVendor;
|
|
||||||
// import com.loafle.overflow.model.probe.Probe;
|
|
||||||
// import com.loafle.overflow.model.target.Target;
|
|
||||||
// import com.loafle.overflow.service.central.target.*;
|
|
||||||
// import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
// import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
// import javax.transaction.Transactional;
|
|
||||||
// import java.util.List;
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Created by snoop on 17. 6. 28.
|
|
||||||
// */
|
|
||||||
// @Service("TargetDiscoveryService")
|
|
||||||
// public class CentralTargetDiscoveryService implements TargetDiscoveryService
|
|
||||||
// {
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private TargetService targetService;
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private CentralInfraMachineService infraMachineService;
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private CentralInfraOSService infraOSService;
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private CentralInfraHostService infraHostService;
|
|
||||||
|
|
||||||
// // @Autowired
|
|
||||||
// // private CentralInfraService infraService;
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private CentralInfraOSPortService infraOSPortService;
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private CentralInfraServiceService infraServiceService;
|
|
||||||
|
|
||||||
// @Transactional
|
|
||||||
// public boolean saveAllTarget(List<Host> hosts, Probe probe) throws
|
|
||||||
// OverflowException {
|
|
||||||
|
|
||||||
// InfraHost infraHost = null;
|
|
||||||
|
|
||||||
// for (Host host : hosts) {
|
|
||||||
|
|
||||||
// infraHost = this.createAndReadHost(host, probe);
|
|
||||||
|
|
||||||
// this.createPort(infraHost, host, probe);
|
|
||||||
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private void createService(InfraHost infraHost, Port port, Probe probe)
|
|
||||||
// throws OverflowException {
|
|
||||||
|
|
||||||
// MetaInfraType typeService = new MetaInfraType(7);
|
|
||||||
|
|
||||||
// String portType = "UDP";
|
|
||||||
|
|
||||||
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP
|
|
||||||
// || port.getPortType() == null) {
|
|
||||||
// portType = "TCP";
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (port.getServiceList() == null) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // for(String key : port.getServices().keySet()) {
|
|
||||||
// for (com.loafle.overflow.model.discovery.Service service :
|
|
||||||
// port.getServiceList()) {
|
|
||||||
|
|
||||||
// // com.loafle.overflow.module.discovery.model.Service service =
|
|
||||||
// // port.getServices().get(key);
|
|
||||||
|
|
||||||
// InfraService dbInfraService = this.infraServiceService
|
|
||||||
// .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(),
|
|
||||||
// portType);
|
|
||||||
|
|
||||||
// if (dbInfraService != null) {
|
|
||||||
// if (service.isTarget() && dbInfraService.getTarget() == null) {
|
|
||||||
// Target targetService = new Target();
|
|
||||||
// targetService.setDisplayName(service.getServiceName());
|
|
||||||
// this.targetService.regist(targetService, probe);
|
|
||||||
// dbInfraService.setTarget(targetService);
|
|
||||||
// this.infraServiceService.regist(dbInfraService);
|
|
||||||
// }
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// InfraService infraService = new InfraService();
|
|
||||||
// infraService.setInfraHost(infraHost);
|
|
||||||
// infraService.setPort(port.getPortNumber());
|
|
||||||
// infraService.setPortType(portType);
|
|
||||||
// infraService.setMetaInfraType(typeService);
|
|
||||||
// infraService.setProbe(probe);
|
|
||||||
|
|
||||||
// if (port.getPortType() == PortType.TLS) {
|
|
||||||
// infraService.setTlsType(true);
|
|
||||||
// }
|
|
||||||
// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
|
|
||||||
|
|
||||||
// if (service.isTarget()) {
|
|
||||||
// Target targetService = new Target();
|
|
||||||
// targetService.setDisplayName(service.getServiceName());
|
|
||||||
// this.targetService.regist(targetService, probe);
|
|
||||||
// infraService.setTarget(targetService);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.infraServiceService.regist(infraService);
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private void createPort(InfraHost infraHost, Host host, Probe probe) throws
|
|
||||||
// OverflowException {
|
|
||||||
|
|
||||||
// // if(host.getPorts() == null) {
|
|
||||||
// // return;
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// String portType = "UDP";
|
|
||||||
|
|
||||||
// MetaInfraType typePort = new MetaInfraType(6);
|
|
||||||
|
|
||||||
// InfraOS infraOS = infraHost.getInfraOS();
|
|
||||||
|
|
||||||
// // for( String key: host.getPorts().keySet()) {
|
|
||||||
|
|
||||||
// if (host.getPortList() == null) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// for (Port port : host.getPortList()) {
|
|
||||||
// // Port port = host.getPorts().get(key);
|
|
||||||
|
|
||||||
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP)
|
|
||||||
// {
|
|
||||||
// portType = "TCP";
|
|
||||||
// }
|
|
||||||
|
|
||||||
// InfraOSPort dbInfraOSPort =
|
|
||||||
// this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(),
|
|
||||||
// port.getPortNumber(),
|
|
||||||
// portType);
|
|
||||||
// if (dbInfraOSPort == null) {
|
|
||||||
// InfraOSPort infraOSPort = new InfraOSPort();
|
|
||||||
// infraOSPort.setInfraOS(infraOS);
|
|
||||||
// infraOSPort.setPort(port.getPortNumber());
|
|
||||||
// infraOSPort.setPortType(portType);
|
|
||||||
// infraOSPort.setProbe(probe);
|
|
||||||
// infraOSPort.setMetaInfraType(typePort);
|
|
||||||
|
|
||||||
// if (port.getPortType() == PortType.TLS) {
|
|
||||||
// infraOSPort.setTlsType(true);
|
|
||||||
// }
|
|
||||||
// infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
|
|
||||||
// this.infraOSPortService.regist(infraOSPort);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.createService(infraHost, port, probe);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private InfraHost createAndReadHost(Host host, Probe probe) throws
|
|
||||||
// OverflowException {
|
|
||||||
|
|
||||||
// InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4());
|
|
||||||
// if (infraHost != null) {
|
|
||||||
|
|
||||||
// if (host.isTarget() && infraHost.getTarget() == null) {
|
|
||||||
// Target target = new Target();
|
|
||||||
// target.setDisplayName(host.getIpv4() + "-Host");
|
|
||||||
|
|
||||||
// this.targetService.regist(target, probe);
|
|
||||||
// infraHost.setTarget(target);
|
|
||||||
// this.infraHostService.regist(infraHost);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return infraHost;
|
|
||||||
// } else {
|
|
||||||
// MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine;
|
|
||||||
|
|
||||||
// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os
|
|
||||||
|
|
||||||
// MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host
|
|
||||||
|
|
||||||
// InfraMachine infraMachine = new InfraMachine();
|
|
||||||
// infraMachine.setProbe(probe);
|
|
||||||
// infraMachine.setMetaInfraType(typeMachine);
|
|
||||||
// infraMachine.setMeta(host.getIpv4() + "-MACHINE");
|
|
||||||
// this.infraMachineService.regist(infraMachine);
|
|
||||||
|
|
||||||
// InfraOS infraOS = new InfraOS();
|
|
||||||
// infraOS.setInfraMachine(infraMachine);
|
|
||||||
// infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
|
|
||||||
// infraOS.setMetaInfraType(typeOS);
|
|
||||||
// infraOS.setProbe(probe);
|
|
||||||
// infraOS.setMeta(host.getIpv4() + "-OS");
|
|
||||||
// this.infraOSService.regist(infraOS);
|
|
||||||
|
|
||||||
// InfraHost newInfraHost = new InfraHost();
|
|
||||||
// newInfraHost.setIpv4(host.getIpv4());
|
|
||||||
// newInfraHost.setMac(host.getMac());
|
|
||||||
// newInfraHost.setInfraOS(infraOS);
|
|
||||||
// newInfraHost.setMetaInfraType(typeHost);
|
|
||||||
// newInfraHost.setProbe(probe);
|
|
||||||
|
|
||||||
// if (host.isTarget()) {
|
|
||||||
// Target target = new Target();
|
|
||||||
// target.setDisplayName(host.getIpv4() + "-Host");
|
|
||||||
|
|
||||||
// this.targetService.regist(target, probe);
|
|
||||||
// newInfraHost.setTarget(target);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.infraHostService.regist(newInfraHost);
|
|
||||||
// infraHost = newInfraHost;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return infraHost;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
|
@ -41,43 +41,34 @@ public class CentralTargetService implements TargetService {
|
||||||
private CentralInfraServiceService infraServiceService;
|
private CentralInfraServiceService infraServiceService;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Target regist(Target target, Probe probe) throws OverflowException {
|
public Target regist(Target target, Long probeID) throws OverflowException {
|
||||||
this.probeService.increaseTargetCount(probe);
|
this.probeService.increaseTargetCount(probeID);
|
||||||
return this.targetDAO.save(target);
|
return this.targetDAO.save(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void remove(Target target, Probe probe) throws OverflowException {
|
public void remove(Long id, Long probeID) throws OverflowException {
|
||||||
this.probeService.decreaseTargetCount(probe);
|
this.probeService.decreaseTargetCount(probeID);
|
||||||
this.targetDAO.delete(target);
|
this.targetDAO.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Target read(String id) throws OverflowException {
|
public Target read(Long id) throws OverflowException {
|
||||||
return this.targetDAO.findById(Long.valueOf(id)).get();
|
return this.targetDAO.findById(id).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Target modify(Target target) throws OverflowException {
|
public Target modify(Target target) throws OverflowException {
|
||||||
return this.targetDAO.save(target);
|
return this.targetDAO.save(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Target regist(Target target) throws OverflowException {
|
|
||||||
return this.targetDAO.save(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
public Target increaseSensorCount(Long id) throws OverflowException {
|
||||||
public void remove(Target target) throws OverflowException {
|
Target t = this.targetDAO.findById(id).get();
|
||||||
this.targetDAO.delete(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Target increaseSensorCount(Target target) throws OverflowException {
|
|
||||||
Target t = this.targetDAO.findById(target.getId()).get();
|
|
||||||
t.setSensorCount(t.getSensorCount() + 1);
|
t.setSensorCount(t.getSensorCount() + 1);
|
||||||
return this.targetDAO.save(t);
|
return this.targetDAO.save(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Target decreaseSensorCount(Target target) throws OverflowException {
|
public Target decreaseSensorCount(Long id) throws OverflowException {
|
||||||
Target t = this.targetDAO.findById(target.getId()).get();
|
Target t = this.targetDAO.findById(id).get();
|
||||||
int count = t.getSensorCount();
|
int count = t.getSensorCount();
|
||||||
if (t.getSensorCount() > 0) {
|
if (t.getSensorCount() > 0) {
|
||||||
t.setSensorCount(count - 1);
|
t.setSensorCount(count - 1);
|
||||||
|
@ -102,7 +93,6 @@ public class CentralTargetService implements TargetService {
|
||||||
|
|
||||||
public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
|
public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
|
||||||
return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams));
|
return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams));
|
||||||
// return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.loafle.overflow.central.redis.service;
|
package com.loafle.overflow.central.redis.service;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.central.commons.service.MessagePublisher;
|
import com.loafle.overflow.central.commons.service.MessagePublisher;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.core.model.PublishMessage;
|
import com.loafle.overflow.core.model.PublishMessage;
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by geek on 17. 9. 5.
|
* Created by geek on 17. 9. 5.
|
||||||
|
|
|
@ -14,7 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by snoop on 17. 6. 28.
|
* Created by snoop on 17. 6. 28.
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by snoop on 17. 6. 28.
|
* Created by snoop on 17. 6. 28.
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by snoop on 17. 6. 28.
|
* Created by snoop on 17. 6. 28.
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.infra.dao;
|
|
||||||
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
|
||||||
|
|
||||||
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 findAllTargetByProbeIn() throws Exception {
|
|
||||||
|
|
||||||
List<Probe> probes = new ArrayList<>();
|
|
||||||
|
|
||||||
Probe probe = new Probe();
|
|
||||||
probe.setId(Long.valueOf(1));
|
|
||||||
|
|
||||||
probes.add(probe);
|
|
||||||
|
|
||||||
|
|
||||||
this.infraDAO.findAllTargetByProbeIn(probes);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.infra.dao;
|
|
||||||
|
|
||||||
import com.loafle.overflow.central.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 static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 18. 4. 25.
|
|
||||||
*/
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
|
||||||
public class InfraOSPortDAOTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraOSPortDAO infraOSPortDAO;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findByPort() throws Exception {
|
|
||||||
|
|
||||||
|
|
||||||
// this.infraOSPortDAO.findByPort(1, 22, "UDP");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,17 +1,7 @@
|
||||||
package com.loafle.overflow.central.module.infra.service;
|
package com.loafle.overflow.central.module.infra.service;
|
||||||
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
import com.loafle.overflow.central.spring.AppConfigTest;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
|
||||||
import com.loafle.overflow.model.infra.InfraHost;
|
|
||||||
import com.loafle.overflow.model.infra.InfraOS;
|
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
|
||||||
import com.loafle.overflow.service.central.infra.InfraHostService;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
@ -22,56 +12,4 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
@ContextConfiguration(classes = { AppConfigTest.class })
|
@ContextConfiguration(classes = { AppConfigTest.class })
|
||||||
public class InfraHostServiceTest {
|
public class InfraHostServiceTest {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraHostService infraHostService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
// @Ignore
|
|
||||||
public void regist() throws Exception {
|
|
||||||
|
|
||||||
InfraHost infraHost = new InfraHost();
|
|
||||||
|
|
||||||
infraHost.setMac("30-9C-23-15-A3-09");
|
|
||||||
infraHost.setIpv4("192.168.1.1");
|
|
||||||
InfraOS infraOS = new InfraOS();
|
|
||||||
infraOS.setId(Long.valueOf(2));
|
|
||||||
|
|
||||||
infraHost.setInfraOS(infraOS);
|
|
||||||
|
|
||||||
MetaInfraType metaInfraType = new MetaInfraType(2);
|
|
||||||
|
|
||||||
this.infraHostService.regist(infraHost);
|
|
||||||
|
|
||||||
Assert.assertNotEquals(infraHost.getId().longValue(), 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void read() throws Exception {
|
|
||||||
|
|
||||||
InfraHost infraHost = this.infraHostService.read(Long.valueOf(1));
|
|
||||||
|
|
||||||
String json = objectMapper.writeValueAsString(infraHost);
|
|
||||||
|
|
||||||
System.out.println(json);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void readByIp() {
|
|
||||||
|
|
||||||
InfraHost infraHost;
|
|
||||||
try {
|
|
||||||
infraHost = this.infraHostService.readByProbeIdAndIpv4(Long.valueOf(1), "192.168.1.1");
|
|
||||||
Assert.assertNotEquals(infraHost, null);
|
|
||||||
} catch (OverflowException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,58 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.infra.service;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
|
||||||
import com.loafle.overflow.model.infra.InfraMachine;
|
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
|
||||||
import com.loafle.overflow.service.central.infra.InfraMachineService;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.junit.Assert;
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 7. 27.
|
|
||||||
*/
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
|
||||||
public class InfraMachineServiceTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraMachineService infraMachineService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
// @Ignore
|
|
||||||
@Test
|
|
||||||
public void regist() throws Exception {
|
|
||||||
|
|
||||||
InfraMachine infraMachine = new InfraMachine();
|
|
||||||
|
|
||||||
infraMachine.setMeta("i am a infra machine");
|
|
||||||
|
|
||||||
MetaInfraType metaInfraType = new MetaInfraType(1);
|
|
||||||
|
|
||||||
this.infraMachineService.regist(infraMachine);
|
|
||||||
|
|
||||||
Assert.assertNotEquals(infraMachine.getId().longValue(), 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void read() throws Exception {
|
|
||||||
|
|
||||||
// regist();
|
|
||||||
|
|
||||||
InfraMachine infraMachine = this.infraMachineService.read(Long.valueOf(1));
|
|
||||||
|
|
||||||
String json = objectMapper.writeValueAsString(infraMachine);
|
|
||||||
System.out.println(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.infra.service;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
|
||||||
import com.loafle.overflow.model.infra.InfraOS;
|
|
||||||
import com.loafle.overflow.model.infra.InfraOSApplication;
|
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
|
||||||
import com.loafle.overflow.service.central.infra.InfraOSApplicationService;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.junit.Assert;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 7. 28.
|
|
||||||
*/
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
|
||||||
public class InfraOSApplicationServiceTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraOSApplicationService infraOSApplicationService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
// @Ignore
|
|
||||||
@Test
|
|
||||||
public void regist() throws Exception {
|
|
||||||
InfraOSApplication infraOSApplication = new InfraOSApplication();
|
|
||||||
|
|
||||||
infraOSApplication.setName("Apache");
|
|
||||||
|
|
||||||
InfraOS infraOS = new InfraOS();
|
|
||||||
infraOS.setId(Long.valueOf(2));
|
|
||||||
|
|
||||||
infraOSApplication.setInfraOS(infraOS);
|
|
||||||
|
|
||||||
MetaInfraType metaInfraType = new MetaInfraType(4);
|
|
||||||
|
|
||||||
this.infraOSApplicationService.regist(infraOSApplication);
|
|
||||||
|
|
||||||
|
|
||||||
Assert.assertNotEquals(infraOSApplication.getId().longValue(), 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void read() throws Exception {
|
|
||||||
|
|
||||||
InfraOSApplication infraOSApplication = this.infraOSApplicationService.read(Long.valueOf(1));
|
|
||||||
|
|
||||||
Assert.assertNotNull(infraOSApplication);
|
|
||||||
|
|
||||||
String json = objectMapper.writeValueAsString(infraOSApplication);
|
|
||||||
System.out.println(json);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.infra.service;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
|
||||||
import com.loafle.overflow.model.infra.InfraOS;
|
|
||||||
import com.loafle.overflow.model.infra.InfraOSDaemon;
|
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
|
||||||
import com.loafle.overflow.service.central.infra.InfraOSDaemonService;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.junit.Assert;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 7. 28.
|
|
||||||
*/
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
|
||||||
public class InfraOSDaemonServiceTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraOSDaemonService infraOSDaemonService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
// @Ignore
|
|
||||||
@Test
|
|
||||||
public void regist() throws Exception {
|
|
||||||
|
|
||||||
InfraOSDaemon infraOSDaemon = new InfraOSDaemon();
|
|
||||||
infraOSDaemon.setName("Apache");
|
|
||||||
|
|
||||||
InfraOS infraOS = new InfraOS();
|
|
||||||
infraOS.setId(Long.valueOf(2));
|
|
||||||
|
|
||||||
infraOSDaemon.setInfraOS(infraOS);
|
|
||||||
|
|
||||||
MetaInfraType metaInfraType = new MetaInfraType(5);
|
|
||||||
|
|
||||||
this.infraOSDaemonService.regist(infraOSDaemon);
|
|
||||||
|
|
||||||
Assert.assertNotEquals(infraOSDaemon.getId().longValue(), 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void read() throws Exception {
|
|
||||||
|
|
||||||
InfraOSDaemon infraOSDaemon = this.infraOSDaemonService.read(Long.valueOf(1));
|
|
||||||
Assert.assertNotNull(infraOSDaemon);
|
|
||||||
|
|
||||||
String json = objectMapper.writeValueAsString(infraOSDaemon);
|
|
||||||
System.out.println(json);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.infra.service;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
|
||||||
import com.loafle.overflow.model.infra.InfraOS;
|
|
||||||
import com.loafle.overflow.model.infra.InfraOSPort;
|
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
|
||||||
import com.loafle.overflow.service.central.infra.InfraOSPortService;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.junit.Assert;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 7. 28.
|
|
||||||
*/
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
|
||||||
public class InfraOSPortServiceTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraOSPortService infraOSPortService;
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
// @Ignore
|
|
||||||
@Test
|
|
||||||
public void regist() throws Exception {
|
|
||||||
|
|
||||||
InfraOSPort infraOSPort = new InfraOSPort();
|
|
||||||
infraOSPort.setTlsType(false);
|
|
||||||
infraOSPort.setPortType("TCP");
|
|
||||||
|
|
||||||
InfraOS infraOS = new InfraOS();
|
|
||||||
infraOS.setId(Long.valueOf(1));
|
|
||||||
|
|
||||||
MetaInfraType metaInfraType = new MetaInfraType(2);
|
|
||||||
|
|
||||||
infraOSPort.setInfraOS(infraOS);
|
|
||||||
|
|
||||||
// FIXME::vendor???
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void read() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void readByPort() {
|
|
||||||
|
|
||||||
InfraOSPort infraOSPort;
|
|
||||||
try {
|
|
||||||
infraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(Long.valueOf(1), 22, "TCP");
|
|
||||||
Assert.assertNotEquals(infraOSPort, null);
|
|
||||||
} catch (OverflowException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.infra.service;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
|
||||||
import com.loafle.overflow.model.infra.InfraMachine;
|
|
||||||
import com.loafle.overflow.model.infra.InfraOS;
|
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
|
||||||
import com.loafle.overflow.model.meta.MetaInfraVendor;
|
|
||||||
import com.loafle.overflow.service.central.infra.InfraOSService;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 7. 27.
|
|
||||||
*/
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
|
||||||
public class InfraOSServiceTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraOSService infraOSService;
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
// @Ignore
|
|
||||||
public void registOS() throws Exception {
|
|
||||||
|
|
||||||
InfraOS infraOS = new InfraOS();
|
|
||||||
|
|
||||||
MetaInfraVendor metaInfraVendor = new MetaInfraVendor();
|
|
||||||
metaInfraVendor.setId(26);
|
|
||||||
|
|
||||||
infraOS.setMetaInfraVendor(metaInfraVendor);
|
|
||||||
infraOS.setMeta("");
|
|
||||||
|
|
||||||
InfraMachine infraMachine = new InfraMachine();
|
|
||||||
infraMachine.setId(Long.valueOf(1));
|
|
||||||
|
|
||||||
MetaInfraType metaInfraType = new MetaInfraType(3);
|
|
||||||
|
|
||||||
infraOS.setInfraMachine(infraMachine);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.infraOSService.regist(infraOS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void read() throws Exception {
|
|
||||||
|
|
||||||
InfraOS infraOS = this.infraOSService.read(Long.valueOf(1));
|
|
||||||
String json = objectMapper.writeValueAsString(infraOS);
|
|
||||||
System.out.println(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +1,8 @@
|
||||||
package com.loafle.overflow.central.module.infra.service;
|
package com.loafle.overflow.central.module.infra.service;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
import com.loafle.overflow.central.spring.AppConfigTest;
|
||||||
import com.loafle.overflow.model.infra.InfraHost;
|
|
||||||
import com.loafle.overflow.model.infra.InfraService;
|
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
|
||||||
import com.loafle.overflow.model.meta.MetaInfraVendor;
|
|
||||||
import com.loafle.overflow.service.central.infra.InfraServiceService;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
@ -22,10 +12,4 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = { AppConfigTest.class })
|
@ContextConfiguration(classes = { AppConfigTest.class })
|
||||||
public class InfraServiceServiceTest {
|
public class InfraServiceServiceTest {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InfraServiceService infraServiceService;
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,119 +1,15 @@
|
||||||
// package com.loafle.overflow.central.module.infra.service;
|
package com.loafle.overflow.central.module.infra.service;
|
||||||
|
|
||||||
// import com.loafle.overflow.central.spring.AppConfigTest;
|
import com.loafle.overflow.central.spring.AppConfigTest;
|
||||||
// import org.codehaus.jackson.map.ObjectMapper;
|
import org.junit.runner.RunWith;
|
||||||
// import org.junit.Test;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
// import org.junit.runner.RunWith;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
// import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
// import org.springframework.data.domain.Page;
|
|
||||||
// import org.springframework.test.context.ContextConfiguration;
|
|
||||||
// import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
// import java.io.IOException;
|
|
||||||
|
|
||||||
// import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Created by snoop on 17. 7. 27.
|
|
||||||
// */
|
|
||||||
// @RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
// @ContextConfiguration(classes = {AppConfigTest.class})
|
|
||||||
// public class InfraServiceTest {
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private InfraService infraService;
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private ProbeService probeService;
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private InfraMachineService infraMachineService;
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
// @Test
|
* Created by snoop on 17. 7. 27.
|
||||||
// public void tttt() {
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
// }
|
@ContextConfiguration(classes = {AppConfigTest.class})
|
||||||
|
public class InfraServiceTest {
|
||||||
// @Test
|
}
|
||||||
// public void readAllByProbe() throws IOException {
|
|
||||||
// Probe probe = new Probe();
|
|
||||||
// probe.setId(1);
|
|
||||||
// PageParams pageParams = new PageParams();
|
|
||||||
// pageParams.setCountPerPage(100);
|
|
||||||
// pageParams.setPageNo(0);
|
|
||||||
// pageParams.setSortCol("id");
|
|
||||||
// pageParams.setSortDirection("descending");
|
|
||||||
// Page<Infra> list = this.infraService.readAllByProbe(probe, pageParams);
|
|
||||||
|
|
||||||
// assertNotNull(list);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void read() throws Exception {
|
|
||||||
|
|
||||||
// // registInfraMachine();
|
|
||||||
|
|
||||||
// Infra infra = this.infraService.read(1);
|
|
||||||
|
|
||||||
// ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
// String json = objectMapper.writeValueAsString(infra);
|
|
||||||
|
|
||||||
// System.out.println(json);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // @Test
|
|
||||||
// // public void readAllProbe() throws IOException {
|
|
||||||
// //
|
|
||||||
// // Probe probe = new Probe();
|
|
||||||
// // probe.setId(1);
|
|
||||||
// //
|
|
||||||
// // List<Infra> infraList = this.infraService.readAllByProbe(probe);
|
|
||||||
// //
|
|
||||||
// // ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
// // String json = objectMapper.writeValueAsString(infraList);
|
|
||||||
// //
|
|
||||||
// // System.out.println(json);
|
|
||||||
// //
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void readAllTarget() {
|
|
||||||
// Domain domain = new Domain();
|
|
||||||
// domain.setId(1);
|
|
||||||
|
|
||||||
// // this.infraService.readAllTargetByProbeList()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void readByTarget() throws IOException {
|
|
||||||
// Target target = new Target();
|
|
||||||
// target.setId(1);
|
|
||||||
|
|
||||||
// Infra infra = this.infraService.readByTarget(target);
|
|
||||||
|
|
||||||
// ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
// String json = objectMapper.writeValueAsString(infra);
|
|
||||||
|
|
||||||
// System.out.println(json);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // @Test
|
|
||||||
// // public void readAllByProbeList() throws IOException {
|
|
||||||
// //
|
|
||||||
// // Domain domain = new Domain();
|
|
||||||
// // domain.setId(1);
|
|
||||||
// //
|
|
||||||
// //
|
|
||||||
// // List<Infra> fl = this.infraService.readAllByDomain(domain);
|
|
||||||
// //
|
|
||||||
// // System.out.println(fl.size());
|
|
||||||
// // ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
// // String json = objectMapper.writeValueAsString(fl);
|
|
||||||
// //
|
|
||||||
// // System.out.println(json);
|
|
||||||
// //
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// }
|
|
|
@ -1,12 +1,9 @@
|
||||||
package com.loafle.overflow.central.module.member.service;
|
package com.loafle.overflow.central.module.member.service;
|
||||||
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
import com.loafle.overflow.central.spring.AppConfigTest;
|
||||||
import com.loafle.overflow.model.member.Member;
|
|
||||||
import com.loafle.overflow.service.central.member.MemberService;
|
import com.loafle.overflow.service.central.member.MemberService;
|
||||||
import com.loafle.overflow.service.central.member.MemberTotpService;
|
import com.loafle.overflow.service.central.member.MemberTotpService;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -14,10 +11,6 @@
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by insanity on 17. 6. 28.
|
* Created by insanity on 17. 6. 28.
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.model.domain.Domain;
|
import com.loafle.overflow.model.domain.Domain;
|
||||||
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
|
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
|
||||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
|
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
|
||||||
import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
@ -16,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
|
@ -1,145 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.target.service;
|
|
||||||
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
|
||||||
|
|
||||||
import com.loafle.overflow.model.discovery.Host;
|
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
|
||||||
import com.loafle.overflow.service.central.target.TargetDiscoveryService;
|
|
||||||
import org.codehaus.jackson.map.DeserializationConfig;
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.aop.support.AopUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by snoop on 17. 6. 28.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
|
||||||
public class TargetDiscoveryServiceTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ResourceLoader resourceLoader;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TargetDiscoveryService targetDiscoveryService;
|
|
||||||
|
|
||||||
// @Ignore
|
|
||||||
@Test
|
|
||||||
public void saveAllTarget() throws Exception {
|
|
||||||
|
|
||||||
String json = readFileAsString(resourceLoader.getResource("classpath:2018-04-25-tds.json").getURI().getPath());
|
|
||||||
|
|
||||||
// Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create();
|
|
||||||
|
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
|
|
||||||
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
|
|
||||||
List<Host> hosts = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Host.class));
|
|
||||||
|
|
||||||
|
|
||||||
Probe probe = new Probe();
|
|
||||||
probe.setId(Long.valueOf(1));
|
|
||||||
|
|
||||||
this.targetDiscoveryService.saveAllTarget(hosts, probe);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String readFileAsString(String filePath) throws IOException {
|
|
||||||
StringBuffer fileData = new StringBuffer();
|
|
||||||
BufferedReader reader = new BufferedReader(
|
|
||||||
new FileReader(filePath));
|
|
||||||
char[] buf = new char[1024];
|
|
||||||
int numRead=0;
|
|
||||||
while((numRead=reader.read(buf)) != -1){
|
|
||||||
String readData = String.valueOf(buf, 0, numRead);
|
|
||||||
fileData.append(readData);
|
|
||||||
}
|
|
||||||
reader.close();
|
|
||||||
return fileData.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testParam() throws NoSuchMethodException {
|
|
||||||
|
|
||||||
Method m = this.targetDiscoveryService.getClass().getMethod("saveAllTarget", List.class, Probe.class);
|
|
||||||
// Method m = TargetDiscoveryService.class.getMethod("saveAllTarget", List.class, Probe.class);
|
|
||||||
|
|
||||||
Class<?> clazz = AopUtils.getTargetClass(this.targetDiscoveryService);
|
|
||||||
Method[] ms = clazz.getMethods();
|
|
||||||
|
|
||||||
Method sm = null;
|
|
||||||
for(Method mm : ms){
|
|
||||||
if ("saveAllTarget".equals(mm.getName())) {
|
|
||||||
sm = mm;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sm != null) {
|
|
||||||
Type[] ts = sm.getGenericParameterTypes();
|
|
||||||
for(Type t : ts){
|
|
||||||
if (t instanceof ParameterizedType) {
|
|
||||||
ParameterizedType pt = (ParameterizedType)t;
|
|
||||||
System.out.println(pt.getActualTypeArguments()[0].getTypeName());
|
|
||||||
}
|
|
||||||
System.out.println(t.getTypeName());
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(m.getName());
|
|
||||||
Type[] genericParameterTypes = m.getGenericParameterTypes();
|
|
||||||
|
|
||||||
for(Type genericParameterType : genericParameterTypes){
|
|
||||||
if(genericParameterType instanceof ParameterizedType){
|
|
||||||
ParameterizedType aType = (ParameterizedType) genericParameterType;
|
|
||||||
Type[] parameterArgTypes = aType.getActualTypeArguments();
|
|
||||||
for(Type parameterArgType : parameterArgTypes){
|
|
||||||
Class parameterArgClass = (Class) parameterArgType;
|
|
||||||
System.out.println("parameterArgClass = " + parameterArgClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testName() throws ClassNotFoundException {
|
|
||||||
|
|
||||||
Object o = this.targetDiscoveryService;
|
|
||||||
|
|
||||||
String nnn = o.getClass().getSimpleName();
|
|
||||||
System.out.println(nnn);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package com.loafle.overflow.central.module.target.service;
|
|
||||||
|
|
||||||
|
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
|
||||||
import com.loafle.overflow.core.model.PageParams;
|
|
||||||
import com.loafle.overflow.model.target.Target;
|
|
||||||
import com.loafle.overflow.service.central.target.TargetService;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by insanity on 17. 6. 28.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("test")
|
|
||||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
|
||||||
public class TargetServiceTest {
|
|
||||||
// @Autowired
|
|
||||||
// TargetService targetService;
|
|
||||||
//
|
|
||||||
// @Ignore
|
|
||||||
// @Test
|
|
||||||
// public void regist() throws Exception {
|
|
||||||
//// Target t = new Target();
|
|
||||||
//// t.setCreateDate(new Date());
|
|
||||||
//// // Infra infra = new Infra();
|
|
||||||
//// // infra.setId(1);
|
|
||||||
//// // Probe probe = new Probe();
|
|
||||||
//// // probe.setId(1);
|
|
||||||
//// // t.setProbe(probe);
|
|
||||||
//// // t.setInfra(infra);
|
|
||||||
//// t.setDescription("i am target");
|
|
||||||
//// t.setDisplayName("ghost target");
|
|
||||||
////
|
|
||||||
//// Target res = this.targetService.regist(t);
|
|
||||||
//// Assert.assertNotNull(res);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// @Ignore
|
|
||||||
// public void read() throws Exception {
|
|
||||||
//// Target res = this.targetService.read("1");
|
|
||||||
//// Assert.assertNotNull(res);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// public void testReadAllByProbeId() throws Exception {
|
|
||||||
// PageParams pageParams = new PageParams();
|
|
||||||
// pageParams.setPageNo(1);
|
|
||||||
// pageParams.setCountPerPage(10);
|
|
||||||
//
|
|
||||||
// Page<Target> targets = this.targetService.readAllByProbeID((long)1, pageParams);
|
|
||||||
//
|
|
||||||
// System.out.println(targets.getSize());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
}
|
|
|
@ -6,7 +6,6 @@ import org.springframework.context.annotation.*;
|
||||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||||
import org.springframework.test.context.TestPropertySource;
|
import org.springframework.test.context.TestPropertySource;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by geek on 17. 8. 8.
|
* Created by geek on 17. 8. 8.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user