Merge remote-tracking branch 'origin/master'

This commit is contained in:
geek 2018-05-29 19:55:21 +09:00
commit 5062432f07
53 changed files with 518 additions and 531 deletions

28
.vscode/launch.test.json vendored Normal file
View File

@ -0,0 +1,28 @@
{
"run": {
"default": "",
"items": [
{
"name": "central",
"projectName": "central",
"workingDirectory": "/project/loafle/overflow/central",
"args": [],
"vmargs": [],
"preLaunchTask": ""
}
]
},
"debug": {
"default": "",
"items": [
{
"name": "central",
"projectName": "central",
"workingDirectory": "/project/loafle/overflow/central",
"args": [],
"vmargs": [],
"preLaunchTask": ""
}
]
}
}

View File

@ -3,7 +3,7 @@ package com.loafle.overflow.central.commons.service;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
public interface MessagePublisher { public interface MessagePublisher {
void publishToDomainMembers(final long domainID, final String method, final Object... params) throws OverflowException; void publishToDomainMembers(final Long domainID, final String method, final Object... params) throws OverflowException;
void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params) throws OverflowException; void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params) throws OverflowException;
void publishToMember(final String memberID, final String method, final Object... params) throws OverflowException; void publishToMember(final String memberID, final String method, final Object... params) throws OverflowException;

View File

@ -3,7 +3,6 @@ package com.loafle.overflow.central.module.apikey.dao;
import com.loafle.overflow.model.apikey.ApiKey; import com.loafle.overflow.model.apikey.ApiKey;
import com.loafle.overflow.model.domain.Domain;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -16,5 +15,5 @@ public interface ApiKeyDAO extends JpaRepository<ApiKey, Long> {
ApiKey findByApiKey(String apiKey); ApiKey findByApiKey(String apiKey);
ApiKey findByDomain(Domain domain); ApiKey findByDomainId(Long domainID);
} }

View File

@ -27,8 +27,8 @@ public class CentralApiKeyService implements ApiKeyService {
return this.apiKeyDAO.save(apiKey); return this.apiKeyDAO.save(apiKey);
} }
public ApiKey readByDomain(Domain domain) throws OverflowException { public ApiKey readByDomainID(Long domainID) throws OverflowException {
return this.apiKeyDAO.findByDomain(domain); return this.apiKeyDAO.findByDomainId(domainID);
} }
public boolean check(String apiKey) throws OverflowException { public boolean check(String apiKey) throws OverflowException {

View File

@ -40,7 +40,7 @@ public class CentralAuthCrawlerService implements AuthCrawlerService {
return this.authCrawlerDAO.save(dbAuthCrawler); return this.authCrawlerDAO.save(dbAuthCrawler);
} }
public boolean checkAuthCrawler(long infraId, MetaCrawler crawler, String authJson) throws OverflowException { public boolean checkAuthCrawler(Long infraId, MetaCrawler crawler, String authJson) throws OverflowException {
Infra infra = this.infraService.read(infraId); Infra infra = this.infraService.read(infraId);

View File

@ -21,12 +21,10 @@ public interface DomainMemberDAO extends JpaRepository<DomainMember, Long> {
@Query("SELECT dm from DomainMember dm where dm.member.email = (:email)") @Query("SELECT dm from DomainMember dm where dm.member.email = (:email)")
DomainMember findByMemberEmail(@Param("email") String email); DomainMember findByMemberEmail(@Param("email") String email);
@Query("SELECT dm.domain from DomainMember dm where dm.member = (:member)") @Query("SELECT dm.domain from DomainMember dm where dm.member.id = (:memberID)")
Domain findDomainByMember(@Param("member") Member member); Domain findDomainByMemberId(@Param("memberID") Long memberID);
@Query("SELECT dm.member from DomainMember dm where dm.domain = (:domain)")
List<Member> findAllMemberByDomain(@Param("domain") Domain domain);
@Query("SELECT dm.member from DomainMember dm where dm.domain.id = (:domainID)") @Query("SELECT dm.member from DomainMember dm where dm.domain.id = (:domainID)")
List<Member> findAllMemberByDomainID(@Param("domainID") long domainID); List<Member> findAllMemberByDomainId(@Param("domainID") Long domainID);
} }

View File

@ -22,28 +22,20 @@ public class CentralDomainMemberService implements DomainMemberService {
@Autowired @Autowired
private DomainMemberDAO domainMemberDAO; private DomainMemberDAO domainMemberDAO;
@Autowired
private MemberDAO memberDAO;
public void regist(DomainMember domainMember) { public void regist(DomainMember domainMember) {
this.domainMemberDAO.save(domainMember); this.domainMemberDAO.save(domainMember);
} }
public Domain readDomainByMemberID(long id) { public Domain readDomainByMemberID(Long memberID) {
Member member = this.memberDAO.findOne(id); return this.domainMemberDAO.findDomainByMemberId(memberID);
return this.domainMemberDAO.findDomainByMember(member);
} }
public DomainMember readByMemberEmail(String email) { public DomainMember readByMemberEmail(String email) {
return this.domainMemberDAO.findByMemberEmail(email); return this.domainMemberDAO.findByMemberEmail(email);
} }
public List<Member> readAllMemberByDomain(Domain domain) { public List<Member> readAllMemberByDomainID(final Long domainID) {
return this.domainMemberDAO.findAllMemberByDomain(domain); return this.domainMemberDAO.findAllMemberByDomainId(domainID);
}
public List<Member> readAllMemberByDomainID(final long domainID) {
return this.domainMemberDAO.findAllMemberByDomainID(domainID);
} }
} }

View File

@ -48,7 +48,7 @@ public class EmailAuthService {
// private static final String WEB_NG_MEMBER_ADDR = "http://127.0.0.1:4200/auth/"; // private static final String WEB_NG_MEMBER_ADDR = "http://127.0.0.1:4200/auth/";
public EmailAuth read(long id) { public EmailAuth read(Long id) {
return this.emailAuthDAO.findOne(id); return this.emailAuthDAO.findOne(id);
} }
@ -125,7 +125,7 @@ public class EmailAuthService {
} }
// dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk= // dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk=
public List<EmailAuth> readByMember(long memberId) { public List<EmailAuth> readByMember(Long memberId) {
return this.emailAuthDAO.findByMember(new Member(memberId)); return this.emailAuthDAO.findByMember(new Member(memberId));
} }

View File

@ -47,7 +47,7 @@ public class SensorConfigGenerator {
} }
Sensor dbSensor = sensorItems.get(0).getSensor(); Sensor dbSensor = sensorItems.get(0).getSensor();
Infra infra = this.infraService.readByTarget(dbSensor.getTarget()); Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId());
// 7 = Infra OS Service // 7 = Infra OS Service
if(infra.getInfraType().getId() == 7) { if(infra.getInfraType().getId() == 7) {

View File

@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.history.dao;
import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.history.History; import com.loafle.overflow.model.history.History;
import com.loafle.overflow.model.probe.Probe;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -17,13 +16,13 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface HistoryDAO extends JpaRepository<History, Long> { public interface HistoryDAO extends JpaRepository<History, Long> {
Page<History> findAllByProbe(Probe probe, Pageable pageable); Page<History> findAllByProbeId(Long probeID, Pageable pageable);
@Query("SELECT h FROM History h WHERE h.probe.id = :#{#probe.id} and h.type.id = :#{#type.id}") @Query("SELECT h FROM History h WHERE h.probe.id = :#{#probeID} and h.type.id = :#{#type.id}")
Page<History> findAllByProbeAndType(@Param("probe") Probe probe, @Param("type") com.loafle.overflow.model.meta.MetaHistoryType type, Pageable pageable); Page<History> findAllByProbeIdAndType(@Param("probeID") Long probeID, @Param("type") com.loafle.overflow.model.meta.MetaHistoryType type, Pageable pageable);
Page<History> findAllByDomain(@Param("domain") Domain domain, Pageable pageRequest); Page<History> findAllByDomainId(Long domainID, Pageable pageRequest);
@Query("SELECT h FROM History h WHERE h.domain.id = :#{#domain.id} and h.type.id = :#{#type.id}") @Query("SELECT h FROM History h WHERE h.domain.id = :#{#domainID} and h.type.id = :#{#type.id}")
Page<History> findAllByDomainAndType(@Param("domain") Domain domain, @Param("type") com.loafle.overflow.model.meta.MetaHistoryType type, Pageable pageRequest); Page<History> findAllByDomainIdAndType(@Param("domainID") Long domainID, @Param("type") com.loafle.overflow.model.meta.MetaHistoryType type, Pageable pageRequest);
} }

View File

@ -23,20 +23,20 @@ public class CentralHistoryService implements HistoryService {
} }
public Page<History> readAllByProbeAndType(Probe probe, MetaHistoryType type, PageParams pageParams) { public Page<History> readAllByProbeIDAndType(Long probeID, MetaHistoryType type, PageParams pageParams) {
return this.historyDAO.findAllByProbeAndType(probe, type, PageUtil.getPageRequest(pageParams)); return this.historyDAO.findAllByProbeIdAndType(probeID, type, PageUtil.getPageRequest(pageParams));
} }
public Page<History> readAllByProbe(Probe probe, com.loafle.overflow.core.model.PageParams pageParams) { public Page<History> readAllByProbeID(Long probeID, PageParams pageParams) {
return this.historyDAO.findAllByProbe(probe, PageUtil.getPageRequest(pageParams)); return this.historyDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams));
} }
public Page<History> readAllByDomain(Domain domain, PageParams pageParams) { public Page<History> readAllByDomainID(Long domainID, PageParams pageParams) {
return this.historyDAO.findAllByDomain(domain, PageUtil.getPageRequest(pageParams)); return this.historyDAO.findAllByDomainId(domainID, PageUtil.getPageRequest(pageParams));
} }
public Page<History> readAllByDomainAndType(Domain domain, MetaHistoryType type, PageParams pageParams) { public Page<History> readAllByDomainIDAndType(Long domainID, MetaHistoryType type, PageParams pageParams) {
return this.historyDAO.findAllByDomainAndType(domain, type, PageUtil.getPageRequest(pageParams)); return this.historyDAO.findAllByDomainIdAndType(domainID, type, PageUtil.getPageRequest(pageParams));
} }
} }

View File

@ -17,9 +17,9 @@ import java.util.List;
*/ */
@Repository @Repository
public interface InfraDAO extends JpaRepository<Infra, Long> { public interface InfraDAO extends JpaRepository<Infra, Long> {
List<Infra> findAllByProbe(Probe probe); List<Infra> findAllByProbeId(Long probeID);
Page<Infra> findAllByProbe(Probe probe, Pageable pageable); Page<Infra> findAllByProbeId(Long probeID, Pageable pageable);
@Query("SELECT i FROM INFRA i WHERE i.probe IN (:probeList) AND i.target != NULL") @Query("SELECT i FROM INFRA i WHERE i.probe IN (:probeList) AND i.target != NULL")
Page<Infra> findAllByProbeList(@Param("probeList") List<Probe> probeList, Pageable pageable); Page<Infra> findAllByProbeList(@Param("probeList") List<Probe> probeList, Pageable pageable);
@ -28,6 +28,6 @@ public interface InfraDAO extends JpaRepository<Infra, Long> {
@Query("SELECT DISTINCT i.target FROM INFRA i WHERE i.probe IN (:probeList)") @Query("SELECT DISTINCT i.target FROM INFRA i WHERE i.probe IN (:probeList)")
List<Target> findAllTargetByProbeList(@Param("probeList") List<Probe> probeList); List<Target> findAllTargetByProbeList(@Param("probeList") List<Probe> probeList);
Infra findByTarget(Target target); Infra findByTargetId(Long targetID);
// List<Infra> findAllByProbe(List<Probe> probeList); // List<Infra> findAllByProbe(List<Probe> probeList);
} }

View File

@ -13,5 +13,5 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface InfraOSPortDAO extends JpaRepository<InfraOSPort, Long> { public interface InfraOSPortDAO extends JpaRepository<InfraOSPort, Long> {
@Query("SELECT p from com.loafle.overflow.model.infra.InfraOSPort p WHERE p.os.id = (:osId) AND p.port = (:portNumber) AND p.portType = (:portType)") @Query("SELECT p from com.loafle.overflow.model.infra.InfraOSPort p WHERE p.os.id = (:osId) AND p.port = (:portNumber) AND p.portType = (:portType)")
InfraOSPort findByPort(@Param("osId") long osId,@Param("portNumber") Integer portNumber,@Param("portType") String portType); InfraOSPort findByPort(@Param("osId") Long osId,@Param("portNumber") Integer portNumber,@Param("portType") String portType);
} }

View File

@ -12,5 +12,5 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface InfraServiceDAO extends JpaRepository<InfraService, Long> { public interface InfraServiceDAO extends JpaRepository<InfraService, Long> {
@Query("SELECT ins from com.loafle.overflow.model.infra.InfraService ins WHERE ins.host.id = (:hostId) AND ins.port = (:portNumber) AND ins.portType = (:portType)") @Query("SELECT ins from com.loafle.overflow.model.infra.InfraService ins WHERE ins.host.id = (:hostId) AND ins.port = (:portNumber) AND ins.portType = (:portType)")
InfraService findByService(@Param("hostId") long hostId,@Param("portNumber") int portNumber,@Param("portType") String portType); InfraService findByService(@Param("hostId") Long hostId,@Param("portNumber") Integer portNumber,@Param("portType") String portType);
} }

View File

@ -20,7 +20,7 @@ public class CentralInfraHostService implements InfraHostService {
return this.infraHostDAO.save(infraHost); return this.infraHostDAO.save(infraHost);
} }
public InfraHost read(long id) throws OverflowException { public InfraHost read(Long id) throws OverflowException {
return this.infraHostDAO.findOne(id); return this.infraHostDAO.findOne(id);
} }

View File

@ -19,7 +19,7 @@ public class CentralInfraMachineService implements InfraMachineService {
return this.infraMachineDAO.save(infraMachine); return this.infraMachineDAO.save(infraMachine);
} }
public InfraMachine read(long id) { public InfraMachine read(Long id) {
return this.infraMachineDAO.findOne(id); return this.infraMachineDAO.findOne(id);
} }
} }

View File

@ -20,7 +20,7 @@ public class CentralInfraOSApplicationService implements InfraOSApplicationServi
return this.infraOSApplicationDAO.save(infraOSApplication); return this.infraOSApplicationDAO.save(infraOSApplication);
} }
public InfraOSApplication read(long id)throws OverflowException { public InfraOSApplication read(Long id)throws OverflowException {
return this.infraOSApplicationDAO.findOne(id); return this.infraOSApplicationDAO.findOne(id);
} }
} }

View File

@ -20,7 +20,7 @@ public class CentralInfraOSDaemonService implements InfraOSDaemonService {
return this.infraOSDaemonDAO.save(infraOSDaemon); return this.infraOSDaemonDAO.save(infraOSDaemon);
} }
public InfraOSDaemon read(long id) throws OverflowException { public InfraOSDaemon read(Long id) throws OverflowException {
return this.infraOSDaemonDAO.findOne(id); return this.infraOSDaemonDAO.findOne(id);
} }
} }

View File

@ -20,11 +20,11 @@ public class CentralInfraOSPortService implements InfraOSPortService {
return this.infraOSPortDAO.save(infraOSPort); return this.infraOSPortDAO.save(infraOSPort);
} }
public InfraOSPort read(long id) throws OverflowException { public InfraOSPort read(Long id) throws OverflowException {
return this.infraOSPortDAO.findOne(id); return this.infraOSPortDAO.findOne(id);
} }
public InfraOSPort readByPort(long osId, int portNumber, String portType) throws OverflowException { public InfraOSPort readByPort(Long osId, int portNumber, String portType) throws OverflowException {
return this.infraOSPortDAO.findByPort(osId, portNumber, portType); return this.infraOSPortDAO.findByPort(osId, portNumber, portType);
} }
} }

View File

@ -20,7 +20,7 @@ public class CentralInfraOSService implements InfraOSService {
return this.infraOSDAO.save(infraOS); return this.infraOSDAO.save(infraOS);
} }
public InfraOS read(long id) throws OverflowException { public InfraOS read(Long id) throws OverflowException {
return this.infraOSDAO.findOne(id); return this.infraOSDAO.findOne(id);
} }
} }

View File

@ -37,18 +37,18 @@ public class CentralInfraService implements InfraService {
return this.infraDAO.save(infra); return this.infraDAO.save(infra);
} }
public Infra read(long id) throws OverflowException { public Infra read(Long id) throws OverflowException {
Infra infra = this.infraDAO.findOne(id); Infra infra = this.infraDAO.findOne(id);
infra.getTarget().setSensors(this.sensorDAO.findAllByTarget(infra.getTarget())); infra.getTarget().setSensors(this.sensorDAO.findAllByTargetId(infra.getTarget().getId()));
return infra; return infra;
} }
public Page<Infra> readAllByProbe(Probe probe, PageParams pageParams) throws OverflowException { public Page<Infra> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.infraDAO.findAllByProbe(probe, PageUtil.getPageRequest(pageParams)); return this.infraDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams));
} }
public Page<Infra> readAllByDomain(Domain domain, PageParams pageParams) throws OverflowException { public Page<Infra> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomain(domain); List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
if(probeList == null || probeList.size() <= 0) { if(probeList == null || probeList.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable()); throw new OverflowException("ProbeNotFoundException", new Throwable());
@ -56,15 +56,15 @@ public class CentralInfraService implements InfraService {
Page<Infra> infraList = this.infraDAO.findAllByProbeList(probeList, PageUtil.getPageRequest(pageParams)); Page<Infra> infraList = this.infraDAO.findAllByProbeList(probeList, PageUtil.getPageRequest(pageParams));
for (Infra infra: infraList) { for (Infra infra: infraList) {
infra.getTarget().setSensors(this.sensorDAO.findAllByTarget(infra.getTarget())); infra.getTarget().setSensors(this.sensorDAO.findAllByTargetId(infra.getTarget().getId()));
} }
return infraList; return infraList;
} }
public List<Target> readAllTargetByDomain(Domain domain) throws OverflowException { public List<Target> readAllTargetByDomainID(Long domainID) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomain(domain); List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
if(probeList == null || probeList.size() <= 0) { if(probeList == null || probeList.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable()); throw new OverflowException("ProbeNotFoundException", new Throwable());
@ -78,8 +78,8 @@ public class CentralInfraService implements InfraService {
// return null; // return null;
} }
public Infra readByTarget(Target target) throws OverflowException { public Infra readByTargetID(Long targetID) throws OverflowException {
return this.infraDAO.findByTarget(target); return this.infraDAO.findByTargetId(targetID);
} }
} }

View File

@ -20,11 +20,11 @@ public class CentralInfraServiceService implements InfraServiceService {
return this.infraServiceDAO.save(infraService); return this.infraServiceDAO.save(infraService);
} }
public InfraService read(long id) throws OverflowException { public InfraService read(Long id) throws OverflowException {
return this.infraServiceDAO.findOne(id); return this.infraServiceDAO.findOne(id);
} }
public InfraService readByService(long hostId, int portNumber, String portType) throws OverflowException { public InfraService readByService(Long hostId, int portNumber, String portType) throws OverflowException {
return this.infraServiceDAO.findByService(hostId, portNumber, portType); return this.infraServiceDAO.findByService(hostId, portNumber, portType);
} }
} }

View File

@ -238,7 +238,7 @@ public class CentralMemberService implements MemberService {
return cMember; return cMember;
} }
public Member read(long memberId) throws OverflowException { public Member read(Long memberId) throws OverflowException {
if (memberId <= 0) { if (memberId <= 0) {
throw new OverflowException("SignInIdNotExistException()", new Throwable()); throw new OverflowException("SignInIdNotExistException()", new Throwable());
} }
@ -248,7 +248,7 @@ public class CentralMemberService implements MemberService {
} }
@WebappAPI @WebappAPI
public void withdrawal(Member member) throws OverflowException { public void withdrawal(Long memberId) throws OverflowException {
String email = SessionMetadata.getTargetID(); String email = SessionMetadata.getTargetID();
// Todo DB delete? // Todo DB delete?
@ -262,7 +262,7 @@ public class CentralMemberService implements MemberService {
return null; return null;
} }
return this.domainMemberService.readAllMemberByDomain(probe.getDomain()); return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId());
} }
public List<Member> readAllByApiKey(String apikey) throws OverflowException { public List<Member> readAllByApiKey(String apikey) throws OverflowException {
@ -273,15 +273,10 @@ public class CentralMemberService implements MemberService {
return null; return null;
} }
return this.domainMemberService.readAllMemberByDomain(apiKey.getDomain()); return this.domainMemberService.readAllMemberByDomainID(apiKey.getDomain().getId());
} }
public List<Member> readAllByDomain(Domain domain) throws OverflowException { public List<Member> readAllByDomainID(final Long domainID) throws OverflowException {
return this.domainMemberService.readAllMemberByDomain(domain);
}
public List<Member> readAllByDomainID(final long domainID) throws OverflowException {
return this.domainMemberService.readAllMemberByDomainID(domainID); return this.domainMemberService.readAllMemberByDomainID(domainID);
} }

View File

@ -50,11 +50,11 @@ public class CentralMemberTotpService implements MemberTotpService {
return this.totpDAO.save(totp); return this.totpDAO.save(totp);
} }
public void remove(long id) throws OverflowException { public void remove(Long id) throws OverflowException {
this.totpDAO.delete(id); this.totpDAO.delete(id);
} }
public MemberTotp read(long id) throws OverflowException { public MemberTotp read(Long id) throws OverflowException {
return this.totpDAO.findOne(id); return this.totpDAO.findOne(id);
} }

View File

@ -22,7 +22,7 @@ public class CentralMetaSensorDisplayItemService implements MetaSensorDisplayIte
return this.displayItemDAO.save(item); return this.displayItemDAO.save(item);
} }
public MetaSensorDisplayItem read(long id) throws OverflowException { public MetaSensorDisplayItem read(Long id) throws OverflowException {
return this.displayItemDAO.findOne(id); return this.displayItemDAO.findOne(id);
} }

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.noauthprobe.dao; package com.loafle.overflow.central.module.noauthprobe.dao;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.noauthprobe.NoAuthProbe; import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
@ -18,8 +17,8 @@ public interface NoAuthProbeDAO extends JpaRepository<NoAuthProbe, Long> {
NoAuthProbe findByTempProbeKey(String tempProbeKey); NoAuthProbe findByTempProbeKey(String tempProbeKey);
@Query("SELECT n FROM NoAuthProbe n WHERE n.domain.id = :#{#domain.id} and n.status.id = 3") // 3 = Process @Query("SELECT n FROM NoAuthProbe n WHERE n.domain.id = :domainID and n.status.id = 3") // 3 = Process
List<NoAuthProbe> findAllByDomain(@Param("domain") Domain domain); List<NoAuthProbe> findAllByDomainId(@Param("domainID") Long domainID);
// NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent); // NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent);
// List<NoAuthProbeDeprecate> findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent); // List<NoAuthProbeDeprecate> findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent);

View File

@ -5,7 +5,6 @@ import com.loafle.overflow.core.annotation.ProbeAPI;
import com.loafle.overflow.core.annotation.WebappAPI; import com.loafle.overflow.core.annotation.WebappAPI;
import com.loafle.overflow.central.commons.utils.GenerateKey; import com.loafle.overflow.central.commons.utils.GenerateKey;
import com.loafle.overflow.central.commons.utils.SessionMetadata; import com.loafle.overflow.central.commons.utils.SessionMetadata;
import com.loafle.overflow.central.commons.utils.StringConvertor;
import com.loafle.overflow.central.module.noauthprobe.dao.NoAuthProbeDAO; import com.loafle.overflow.central.module.noauthprobe.dao.NoAuthProbeDAO;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.apikey.ApiKey; import com.loafle.overflow.model.apikey.ApiKey;
@ -20,6 +19,9 @@ import com.loafle.overflow.model.meta.MetaInfraVendor;
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus; import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
import com.loafle.overflow.model.meta.MetaProbeStatus; import com.loafle.overflow.model.meta.MetaProbeStatus;
import com.loafle.overflow.model.noauthprobe.NoAuthProbe; import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescription;
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionHost;
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionNetwork;
import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.model.probe.ProbeHost; import com.loafle.overflow.model.probe.ProbeHost;
import com.loafle.overflow.service.central.apikey.ApiKeyService; import com.loafle.overflow.service.central.apikey.ApiKeyService;
@ -32,16 +34,13 @@ import com.loafle.overflow.service.central.probe.ProbeHostService;
import com.loafle.overflow.service.central.probe.ProbeService; import com.loafle.overflow.service.central.probe.ProbeService;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import javax.transaction.Transactional; import javax.transaction.Transactional;
@ -52,190 +51,189 @@ import javax.transaction.Transactional;
@Service("NoAuthProbeService") @Service("NoAuthProbeService")
public class CentralNoAuthProbeService implements NoAuthProbeService { public class CentralNoAuthProbeService implements NoAuthProbeService {
@Autowired @Autowired
private NoAuthProbeDAO noAuthProbeDAO; private NoAuthProbeDAO noAuthProbeDAO;
@Autowired @Autowired
private ApiKeyService apiKeyService; private ApiKeyService apiKeyService;
@Autowired @Autowired
private ProbeService probeService; private ProbeService probeService;
@Autowired @Autowired
private MessagePublisher messagePublisher; private MessagePublisher messagePublisher;
@Autowired @Autowired
private DomainMemberService domainMemberService; private DomainMemberService domainMemberService;
@Autowired @Autowired
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@Autowired @Autowired
private InfraMachineService infraMachineService; private InfraMachineService infraMachineService;
@Autowired @Autowired
private InfraOSService infraOSService; private InfraOSService infraOSService;
@Autowired @Autowired
private InfraHostService infraHostService; private InfraHostService infraHostService;
@Autowired @Autowired
private ProbeHostService probeHostService; private ProbeHostService probeHostService;
@ProbeAPI @ProbeAPI
public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException { public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException {
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey()); ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
noAuthProbe.setDomain(apiKey.getDomain()); noAuthProbe.setDomain(apiKey.getDomain());
noAuthProbe.setTempProbeKey(GenerateKey.getKey()); noAuthProbe.setTempProbeKey(GenerateKey.getKey());
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 3)); noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 3));
messagePublisher.publishToDomainMembers(apiKey.getDomain().getId(), "NoAuthProbeService.regist", noAuthProbe); messagePublisher.publishToDomainMembers(apiKey.getDomain().getId(), "NoAuthProbeService.regist", noAuthProbe);
return this.noAuthProbeDAO.save(noAuthProbe); return this.noAuthProbeDAO.save(noAuthProbe);
}
public List<NoAuthProbe> readAllByDomainID(Long domainID) throws OverflowException {
return this.noAuthProbeDAO.findAllByDomainId(domainID);
}
public NoAuthProbe read(Long id) {
return this.noAuthProbeDAO.findOne(id);
}
@WebappAPI
@Transactional
public List<NoAuthProbe> acceptNoAuthProbe(Long noAuthProbeID) throws OverflowException {
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
NoAuthProbeDescription noAuthProbeDescription = null;
try {
noAuthProbeDescription = this.objectMapper.readValue(noAuthProbe.getDescription(), NoAuthProbeDescription.class);
} catch (IOException e) {
throw new OverflowException("json error", e);
} }
public List<NoAuthProbe> readAllByDomain(Domain domain) throws OverflowException { Probe probe = this.newProbe(noAuthProbe, noAuthProbeDescription);
InfraMachine machine = this.newInfraMachine(noAuthProbe);
InfraOS os = this.newInfraOS(machine, noAuthProbeDescription.getHost());
InfraHost host = this.newInfraHost(os, noAuthProbeDescription.getNetwork());
this.newProbeHost(host, probe);
return this.noAuthProbeDAO.findAllByDomain(domain); noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
} this.noAuthProbeDAO.save(noAuthProbe);
public NoAuthProbe read(long id) { messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", probe.getProbeKey());
return this.noAuthProbeDAO.findOne(id);
}
@WebappAPI return this.readAllByDomainID(noAuthProbe.getDomain().getId());
@Transactional }
public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws OverflowException {
HashMap<String, Object> objMap; private Probe newProbe(NoAuthProbe noauthprobe, NoAuthProbeDescription noAuthProbeDescription) throws OverflowException {
try {
objMap = this.objectMapper.readValue(noAuthProbe.getDescription(), new TypeReference<Map<String, Object>>(){});
} catch (IOException e) {
throw new OverflowException("json error", e);
}
Map<String, String> hostMap = (Map<String, String>) objMap.get("host"); BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
Map<String, String> netMap = (Map<String, String>) objMap.get("network"); String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
Probe probe = this.newProbe(noAuthProbe, hostMap, netMap); ApiKey apiKey = apiKeyService.readByApiKey(noauthprobe.getApiKey());
InfraMachine machine = this.newInfraMachine(noAuthProbe); String memberEmail = SessionMetadata.getTargetID();
InfraOS os = this.newInfraOS(machine, hostMap); DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
InfraHost host = this.newInfraHost(os, netMap);
this.newProbeHost(host, probe);
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1)); Probe probe = new Probe();
this.noAuthProbeDAO.save(noAuthProbe); probe.setEncryptionKey(encryptKey);
probe.setProbeKey(GenerateKey.getKey());
probe.setDomain(new Domain(apiKey.getDomain().getId()));
probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
probe.setTargetCount(0);
probe.setStatus(new MetaProbeStatus((short) 1));
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", String dispName = noAuthProbeDescription.getHost().getName();
probe.getProbeKey()); dispName += " probe";
probe.setDisplayName(dispName);
return this.readAllByDomain(noAuthProbe.getDomain()); String addrStr = noAuthProbeDescription.getNetwork().getAddress();
} String[] addrArr = addrStr.split("\\|");
probe.setCidr(addrArr[0]);
private Probe newProbe(NoAuthProbe noauthprobe, Map<String, String> hostMap, Map<String, String> netMap) throws OverflowException { return this.probeService.regist(probe);
}
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); private InfraMachine newInfraMachine(NoAuthProbe noauthprobe) throws OverflowException {
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString()); MetaInfraType infraType = new MetaInfraType();
infraType.setId(1);
ApiKey apiKey = apiKeyService.readByApiKey(noauthprobe.getApiKey()); InfraMachine infraMachine = new InfraMachine();
String memberEmail = SessionMetadata.getTargetID(); infraMachine.setMeta(noauthprobe.getDescription());
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail); infraMachine.setInfraType(infraType);
Probe probe = new Probe(); return this.infraMachineService.regist(infraMachine);
probe.setEncryptionKey(encryptKey); }
probe.setProbeKey(GenerateKey.getKey());
probe.setDomain(new Domain(apiKey.getDomain().getId()));
probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
probe.setTargetCount(0);
probe.setStatus(new MetaProbeStatus((short) 1));
String dispName = hostMap.get("name"); private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost) throws OverflowException {
dispName += " probe"; MetaInfraType infraType = new MetaInfraType();
probe.setDisplayName(dispName); infraType.setId(3);
String addrStr = netMap.get("address"); InfraOS infraOS = new InfraOS();
String[] addrArr = addrStr.split("\\|"); infraOS.setMachine(infraMachine);
probe.setCidr(addrArr[0]); infraOS.setInfraType(infraType);
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS()));
return this.probeService.regist(probe); return this.infraOSService.regist(infraOS);
} }
private InfraMachine newInfraMachine(NoAuthProbe noauthprobe) throws OverflowException { private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork) throws OverflowException {
MetaInfraType infraType = new MetaInfraType(); MetaInfraType infraType = new MetaInfraType();
infraType.setId(1); infraType.setId(2);
InfraMachine infraMachine = new InfraMachine(); InfraHost infraHost = new InfraHost();
infraMachine.setMeta(noauthprobe.getDescription()); String addrStr = noAuthProbeDescriptionNetwork.getAddress();
infraMachine.setInfraType(infraType); String[] addrArr = addrStr.split("\\|");
return this.infraMachineService.regist(infraMachine); infraHost.setIpv4(addrArr[0]);
} infraHost.setMac(noAuthProbeDescriptionNetwork.getMacAddress());
infraHost.setOs(infraOS);
infraHost.setInfraType(infraType);
private InfraOS newInfraOS(InfraMachine infraMachine, Map<String, String> hostMap) throws OverflowException { return this.infraHostService.regist(infraHost);
MetaInfraType infraType = new MetaInfraType(); }
infraType.setId(3);
InfraOS infraOS = new InfraOS(); private void newProbeHost(InfraHost infraHost, Probe probe) throws OverflowException {
infraOS.setMachine(infraMachine); ProbeHost probeHost = new ProbeHost();
infraOS.setInfraType(infraType); probeHost.setHost(infraHost);
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(hostMap.get("os"))); probeHost.setProbe(probe);
return this.infraOSService.regist(infraOS); this.probeHostService.regist(probeHost);
} }
private InfraHost newInfraHost(InfraOS infraOS, Map<String, String> netMap) throws OverflowException { @WebappAPI
MetaInfraType infraType = new MetaInfraType(); public List<NoAuthProbe> denyNoauthProbe(Long noAuthProbeID) throws OverflowException {
infraType.setId(2); NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
InfraHost infraHost = new InfraHost(); noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2));
String addrStr = netMap.get("address"); this.noAuthProbeDAO.save(noAuthProbe);
String[] addrArr = addrStr.split("\\|");
infraHost.setIpv4(addrArr[0]); messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Deny");
infraHost.setMac(netMap.get("macAddress"));
infraHost.setOs(infraOS);
infraHost.setInfraType(infraType);
return this.infraHostService.regist(infraHost); return this.readAllByDomainID(noAuthProbe.getDomain().getId());
} }
private void newProbeHost(InfraHost infraHost, Probe probe) throws OverflowException { public NoAuthProbe readByTempProbeKey(String tempKey) throws OverflowException {
ProbeHost probeHost = new ProbeHost(); return this.noAuthProbeDAO.findByTempProbeKey(tempKey);
probeHost.setHost(infraHost); }
probeHost.setProbe(probe);
this.probeHostService.regist(probeHost); public void onConnect(String tempKey, String connectAddress) throws OverflowException {
} NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey);
noAuthProbe.setConnectDate(new Date());
noAuthProbe.setConnectAddress(connectAddress);
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
@WebappAPI messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect", noAuthProbe);
public List<NoAuthProbe> denyNoauthProbe(NoAuthProbe noAuthProbe) throws OverflowException { }
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2));
this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Deny"); public void onDisconnect(String tempKey) throws OverflowException {
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey);
noAuthProbe.setConnectDate(null);
noAuthProbe.setConnectAddress(null);
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
return this.readAllByDomain(noAuthProbe.getDomain()); messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect", noAuthProbe);
} }
public NoAuthProbe readByTempProbeKey(String tempKey) throws OverflowException {
return this.noAuthProbeDAO.findByTempProbeKey(tempKey);
}
public void onConnect(String tempKey, String connectAddress) throws OverflowException {
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey);
noAuthProbe.setConnectDate(new Date());
noAuthProbe.setConnectAddress(connectAddress);
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect", noAuthProbe);
}
public void onDisconnect(String tempKey) throws OverflowException {
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey);
noAuthProbe.setConnectDate(null);
noAuthProbe.setConnectAddress(null);
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect", noAuthProbe);
}
} }

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.probe.dao; package com.loafle.overflow.central.module.probe.dao;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.probe.Probe;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
@ -16,7 +15,7 @@ import java.util.List;
public interface ProbeDAO extends JpaRepository<Probe, Long> { public interface ProbeDAO extends JpaRepository<Probe, Long> {
Probe findByProbeKey(String probeKey); Probe findByProbeKey(String probeKey);
List<Probe> findAllByDomainOrderByIdDesc(Domain domain); List<Probe> findAllByDomainIdOrderByIdDesc(Long domainID);
// @Modifying(clearAutomatically = true) // @Modifying(clearAutomatically = true)
// @Query("UPDATE Probe p set p.connectDate = :connectDate, p.connectAddress = :connectAddress where p.probeKey = :probeKey") // @Query("UPDATE Probe p set p.connectDate = :connectDate, p.connectAddress = :connectAddress where p.probeKey = :probeKey")

View File

@ -2,8 +2,6 @@ package com.loafle.overflow.central.module.probe.dao;
import java.util.List; import java.util.List;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.model.probe.ProbeHost; import com.loafle.overflow.model.probe.ProbeHost;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
@ -17,8 +15,8 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface ProbeHostDAO extends JpaRepository<ProbeHost, Long> { public interface ProbeHostDAO extends JpaRepository<ProbeHost, Long> {
ProbeHost findByProbe(Probe probe); ProbeHost findByProbeId(Long probeID);
@Query("SELECT h FROM ProbeHost h WHERE h.probe.domain = (:domain)") @Query("SELECT h FROM ProbeHost h WHERE h.probe.domain.id = (:domainID)")
List<ProbeHost> findAllByDomain(@Param("domain")Domain domain); List<ProbeHost> findAllByDomainId(@Param("domainID")Long domainID);
} }

View File

@ -5,7 +5,6 @@ import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.model.probe.ProbeTask; import com.loafle.overflow.model.probe.ProbeTask;
/** /**
@ -13,5 +12,5 @@ import com.loafle.overflow.model.probe.ProbeTask;
*/ */
@Repository @Repository
public interface ProbeTaskDAO extends JpaRepository<ProbeTask, Long> { public interface ProbeTaskDAO extends JpaRepository<ProbeTask, Long> {
List<ProbeTask> findAllByProbe(Probe probe); List<ProbeTask> findAllByProbeId(Long probeID);
} }

View File

@ -21,20 +21,20 @@ public class CentralProbeHostService implements ProbeHostService {
@Autowired @Autowired
private ProbeHostDAO probeHostDAO; private ProbeHostDAO probeHostDAO;
public ProbeHost read(long id) throws OverflowException { public ProbeHost read(Long id) throws OverflowException {
return this.probeHostDAO.findOne(id); return this.probeHostDAO.findOne(id);
} }
public ProbeHost readByProbe(Probe probe) throws OverflowException { public ProbeHost readByProbeID(Long probeID) throws OverflowException {
return this.probeHostDAO.findByProbe(probe); return this.probeHostDAO.findByProbeId(probeID);
} }
public ProbeHost regist(ProbeHost probeHost) throws OverflowException { public ProbeHost regist(ProbeHost probeHost) throws OverflowException {
return this.probeHostDAO.save(probeHost); return this.probeHostDAO.save(probeHost);
} }
public List<ProbeHost> readAllByDomain(Domain domain) throws OverflowException { public List<ProbeHost> readAllByDomainID(Long domainID) throws OverflowException {
return this.probeHostDAO.findAllByDomain(domain); return this.probeHostDAO.findAllByDomainId(domainID);
} }
} }

View File

@ -32,12 +32,12 @@ public class CentralProbeService implements ProbeService {
return this.probeDAO.save(probes); return this.probeDAO.save(probes);
} }
public List<Probe> readAllByDomain(Domain domain) throws OverflowException { public List<Probe> readAllByDomainID(Long domainID) throws OverflowException {
List<Probe> probes = this.probeDAO.findAllByDomainOrderByIdDesc(domain); List<Probe> probes = this.probeDAO.findAllByDomainIdOrderByIdDesc(domainID);
return probes; return probes;
} }
public Probe read(long id) throws OverflowException { public Probe read(Long id) throws OverflowException {
return this.probeDAO.findOne(id); return this.probeDAO.findOne(id);
} }
@ -49,7 +49,7 @@ public class CentralProbeService implements ProbeService {
return this.probeDAO.save(probe); return this.probeDAO.save(probe);
} }
public boolean remove(long id) throws OverflowException { public boolean remove(Long id) throws OverflowException {
this.probeDAO.delete(id); this.probeDAO.delete(id);
return true; return true;
} }
@ -69,7 +69,7 @@ public class CentralProbeService implements ProbeService {
return this.probeDAO.save(p); return this.probeDAO.save(p);
} }
public Probe modifyDisplayName(long probeId, String displayName) { public Probe modifyDisplayName(Long probeId, String displayName) {
Probe probe = this.probeDAO.findOne(probeId); Probe probe = this.probeDAO.findOne(probeId);
probe.setDisplayName(displayName); probe.setDisplayName(displayName);
return this.probeDAO.save(probe); return this.probeDAO.save(probe);

View File

@ -24,7 +24,7 @@ public class CentralProbeTaskService implements ProbeTaskService{
return this.probeTaskDAO.save(probeTask); return this.probeTaskDAO.save(probeTask);
} }
public List<ProbeTask> readAllByProbe(Probe probe) throws OverflowException { public List<ProbeTask> readAllByProbeID(Long probeID) throws OverflowException {
return this.probeTaskDAO.findAllByProbe(probe); return this.probeTaskDAO.findAllByProbeId(probeID);
} }
} }

View File

@ -18,9 +18,8 @@ import com.loafle.overflow.model.target.Target;
*/ */
@Repository @Repository
public interface SensorDAO extends JpaRepository<Sensor, Long> { public interface SensorDAO extends JpaRepository<Sensor, Long> {
Page<Sensor> findAllByTargetId(Long targetID, Pageable pageable);
Page<Sensor> findAllByTarget(Target target, Pageable pageable); List<Sensor> findAllByTargetId(Long targetID);
List<Sensor> findAllByTarget(Target target);
@Query("SELECT s from Sensor s WHERE s.target in (:targetList)") @Query("SELECT s from Sensor s WHERE s.target in (:targetList)")
Page<Sensor> findAllByTargetList(@Param("targetList") List<Target> targetList, Pageable pageable); Page<Sensor> findAllByTargetList(@Param("targetList") List<Target> targetList, Pageable pageable);

View File

@ -55,9 +55,9 @@ public class CentralSensorService implements SensorService {
return this.sensorDAO.save(sensor); return this.sensorDAO.save(sensor);
} }
public Page<Sensor> readAllByDomain(Domain domain, PageParams pageParams) throws OverflowException { public Page<Sensor> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomain(domain); List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
if (probeList == null || probeList.size() <= 0) { if (probeList == null || probeList.size() <= 0) {
throw new OverflowException("", new Throwable()); throw new OverflowException("", new Throwable());
@ -72,37 +72,40 @@ public class CentralSensorService implements SensorService {
return this.sensorDAO.findAllByTargetList(targetList, PageUtil.getPageRequest(pageParams)); return this.sensorDAO.findAllByTargetList(targetList, PageUtil.getPageRequest(pageParams));
} }
public Page<Sensor> readAllByInfra(long infraId, PageParams pageParams) throws OverflowException { public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
Infra dbInfra = this.infraService.read(infraId); Infra dbInfra = this.infraService.read(infraID);
if (dbInfra == null || dbInfra.getTarget() == null) { if (dbInfra == null || dbInfra.getTarget() == null) {
throw new OverflowException("", new Throwable()); throw new OverflowException("", new Throwable());
} }
return this.sensorDAO.findAllByTarget(dbInfra.getTarget(), PageUtil.getPageRequest(pageParams)); return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), PageUtil.getPageRequest(pageParams));
} }
public Page<Sensor> readAllByTarget(Target target, PageParams pageParams) throws OverflowException { public Page<Sensor> readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException {
return this.sensorDAO.findAllByTarget(target, PageUtil.getPageRequest(pageParams)); return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams));
} }
public Sensor read(String id) throws OverflowException { public Sensor read(Long id) throws OverflowException {
return this.sensorDAO.findOne(Long.valueOf(id)); return this.sensorDAO.findOne(Long.valueOf(id));
} }
@Transactional @Transactional
public void remove(Sensor sensor) throws OverflowException { public void remove(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findOne(sensorID);
this.targetService.decreaseSensorCount(sensor.getTarget()); this.targetService.decreaseSensorCount(sensor.getTarget());
this.sensorDAO.delete(sensor); this.sensorDAO.delete(sensor);
} }
public Sensor start(Sensor sensor) throws OverflowException { public Sensor start(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findOne(sensorID);
MetaSensorStatus status = new MetaSensorStatus((short) 1); MetaSensorStatus status = new MetaSensorStatus((short) 1);
sensor.setStatus(status); sensor.setStatus(status);
return this.sensorDAO.save(sensor); return this.sensorDAO.save(sensor);
} }
public Sensor stop(Sensor sensor) throws OverflowException { public Sensor stop(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findOne(sensorID);
MetaSensorStatus status = new MetaSensorStatus((short) 2); MetaSensorStatus status = new MetaSensorStatus((short) 2);
sensor.setStatus(status); sensor.setStatus(status);
return this.sensorDAO.save(sensor); return this.sensorDAO.save(sensor);

View File

@ -43,7 +43,7 @@ public class RedisMessagePublisher implements MessagePublisher {
this.topics = topics; this.topics = topics;
} }
public void publishToDomainMembers(final long domainID, final String method, final Object... params) public void publishToDomainMembers(final Long domainID, final String method, final Object... params)
throws OverflowException { throws OverflowException {
PublishMessage message = new PublishMessage(); PublishMessage message = new PublishMessage();
message.setTargetType(PublishMessage.TargetType.MEMBER); message.setTargetType(PublishMessage.TargetType.MEMBER);
@ -92,7 +92,7 @@ public class RedisMessagePublisher implements MessagePublisher {
} }
@Cacheable("memberListByDomain") @Cacheable("memberListByDomain")
protected List<String> getMemberListByDomainID(final long domainID) throws OverflowException { protected List<String> getMemberListByDomainID(final Long domainID) throws OverflowException {
return this.getMemberList(memberService.readAllByDomainID(domainID)); return this.getMemberList(memberService.readAllByDomainID(domainID));
} }

View File

@ -990,7 +990,7 @@ INSERT INTO public.infra_os_application ("name",id,os_id) VALUES (
INSERT INTO public.infra_os_daemon ("name",id,os_id) VALUES ( INSERT INTO public.infra_os_daemon ("name",id,os_id) VALUES (
'Apache',6,2); 'Apache',6,2);
insert into public.PROBE_INFRAHOST (HOST_ID, PROBE_ID) values (3, 1); insert into public.probe_host (HOST_ID, PROBE_ID) values (3, 1);
INSERT INTO public.sensor (crawler_input_items,create_date,description,crawler_id,status,target_id,item_count,display_name) VALUES ( INSERT INTO public.sensor (crawler_input_items,create_date,description,crawler_id,status,target_id,item_count,display_name) VALUES (
@ -1237,10 +1237,10 @@ INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,
'52abd6fd57e511e7ac52080027658d13','2017-06-26 12:43:46.877','{"host":{"name":"geek-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"03000200-0400-0500-0006-000700080009"},"network":{"name":"enp3s0","address":"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d13',1,NULL,3); '52abd6fd57e511e7ac52080027658d13','2017-06-26 12:43:46.877','{"host":{"name":"geek-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"03000200-0400-0500-0006-000700080009"},"network":{"name":"enp3s0","address":"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d13',1,NULL,3);
INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,domain_id,probe_id,status) VALUES ( INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,domain_id,probe_id,status) VALUES (
'52abd6fd57e511e7ac52080027658d14','2017-08-11 12:43:46.877','{"host":{"name":"insanity-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"4C4C4544-0044-4A10-8039-C7C04F595031"},"network":{"name":"enp3s0","address":"192.168.1.105/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d14',1,NULL,3); '52abd6fd57e511e7ac52080027658d13','2017-08-11 12:43:46.877','{"host":{"name":"insanity-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"4C4C4544-0044-4A10-8039-C7C04F595031"},"network":{"name":"enp3s0","address":"192.168.1.105/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d14',1,NULL,3);
INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,domain_id,probe_id,status) VALUES ( INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,domain_id,probe_id,status) VALUES (
'52abd6fd57e511e7ac52080027658d15','2017-08-11 12:43:46.877','{"host":{"name":"snoop-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"DE60E4C3-347A-4D38-AEAB-1760471665EA"},"network":{"name":"enp3s0","address":"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d15',1,NULL,3); '52abd6fd57e511e7ac52080027658d13','2017-08-11 12:43:46.877','{"host":{"name":"snoop-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"DE60E4C3-347A-4D38-AEAB-1760471665EA"},"network":{"name":"enp3s0","address":"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d15',1,NULL,3);

View File

@ -35,14 +35,14 @@ public class ApiKeyServiceTest {
apiKey.setApiKey("70124b775bd511e7b059080027658d13"); apiKey.setApiKey("70124b775bd511e7b059080027658d13");
Domain domain = new Domain(); Domain domain = new Domain();
domain.setId(1); domain.setId(Long.valueOf(1));
apiKey.setDomain(domain); apiKey.setDomain(domain);
this.apiKeyService.regist(apiKey); this.apiKeyService.regist(apiKey);
Assert.assertNotEquals(apiKey.getId(), 0); Assert.assertNotEquals(apiKey.getId().longValue(), 0);
} }
@Ignore @Ignore
@ -61,11 +61,7 @@ public class ApiKeyServiceTest {
@Ignore @Ignore
@Test @Test
public void findByDomain() throws OverflowException { public void findByDomain() throws OverflowException {
ApiKey apiKey = this.apiKeyService.readByDomainID(Long.valueOf(1));
Domain domain = new Domain();
domain.setId(1);
ApiKey apiKey = this.apiKeyService.readByDomain(domain);
Assert.assertNotEquals(apiKey, null); Assert.assertNotEquals(apiKey, null);

View File

@ -28,7 +28,7 @@ public class AuthCrawlerServiceTest {
AuthCrawler authCrawler = new AuthCrawler(); AuthCrawler authCrawler = new AuthCrawler();
Target target = new Target(); Target target = new Target();
target.setId(4); target.setId(Long.valueOf(4));
authCrawler.setTarget(target); authCrawler.setTarget(target);
@ -43,7 +43,7 @@ public class AuthCrawlerServiceTest {
this.authCrawlerService.regist(authCrawler); this.authCrawlerService.regist(authCrawler);
Assert.assertNotEquals(authCrawler.getId(), 0); Assert.assertNotEquals(authCrawler.getId().longValue(), 0);
} }
@ -54,7 +54,7 @@ public class AuthCrawlerServiceTest {
metaCrawler.setId((short)23); metaCrawler.setId((short)23);
Target target = new Target(); Target target = new Target();
target.setId(5); target.setId(Long.valueOf(5));
AuthCrawler authCrawler = this.authCrawlerService.readAuth(metaCrawler, target); AuthCrawler authCrawler = this.authCrawlerService.readAuth(metaCrawler, target);

View File

@ -36,27 +36,23 @@ public class DomainMemberServiceTest {
DomainMember domainMember = new DomainMember(); DomainMember domainMember = new DomainMember();
Domain domain = new Domain(); Domain domain = new Domain();
domain.setId(1); domain.setId(Long.valueOf(1));
Member member = new Member(); Member member = new Member();
member.setId(1); member.setId(Long.valueOf(1));
domainMember.setDomain(domain); domainMember.setDomain(domain);
domainMember.setMember(member); domainMember.setMember(member);
this.domainMemberService.regist(domainMember); this.domainMemberService.regist(domainMember);
Assert.assertNotEquals(domainMember.getId(), 0); Assert.assertNotEquals(domainMember.getId().longValue(), 0);
} }
@Test @Test
public void readAllMemberByDomain() throws OverflowException { public void readAllMemberByDomain() throws OverflowException {
List<Member> members = this.domainMemberService.readAllMemberByDomainID(Long.valueOf(1));
Domain domain = new Domain();
domain.setId(1);
List<Member> members = this.domainMemberService.readAllMemberByDomain(domain);
Assert.assertNotEquals(members.size(), 0); Assert.assertNotEquals(members.size(), 0);

View File

@ -33,7 +33,7 @@ public class DomainServiceTest {
this.domainService.regist(domain); this.domainService.regist(domain);
Assert.assertNotEquals(domain.getId(), 0); Assert.assertNotEquals(domain.getId().longValue(), 0);
} }
} }

View File

@ -30,7 +30,7 @@ public class EmailAuthServiceTest {
@Ignore @Ignore
public void TestMailSend() throws Exception { public void TestMailSend() throws Exception {
Member member = new Member(); Member member = new Member();
member.setId(1); member.setId(Long.valueOf(1));
member.setEmail("overflow@loafle.com"); member.setEmail("overflow@loafle.com");
this.emailAuthService.sendEmailByMember(member); this.emailAuthService.sendEmailByMember(member);
} }
@ -39,7 +39,7 @@ public class EmailAuthServiceTest {
public void TestCompareDate() throws Exception { public void TestCompareDate() throws Exception {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
EmailAuth auth = emailAuthService.read(1); EmailAuth auth = emailAuthService.read(Long.valueOf(1));
cal.setTime(auth.getCreateDate()); cal.setTime(auth.getCreateDate());
cal.add(Calendar.HOUR, 12); cal.add(Calendar.HOUR, 12);

View File

@ -35,9 +35,9 @@ public class HistoryServiceTest {
Random rand = new Random(); Random rand = new Random();
for (int i=0;i<100;i++) { for (int i=0;i<100;i++) {
History h = new History(); History h = new History();
h.setMember(new Member(1)); h.setMember(new Member(Long.valueOf(1)));
h.setProbe(new Probe(rand.nextBoolean() ? 1 : 2)); h.setProbe(new Probe(rand.nextBoolean() ? Long.valueOf(1) : Long.valueOf(2)));
h.setDomain(new Domain(1)); h.setDomain(new Domain(Long.valueOf(1)));
h.setType(new MetaHistoryType(rand.nextInt((6 - 1) + 1) + 1)); h.setType(new MetaHistoryType(rand.nextInt((6 - 1) + 1) + 1));
h.setMessage("Test History " + i); h.setMessage("Test History " + i);
this.historyService.regist(h); this.historyService.regist(h);
@ -60,7 +60,7 @@ public class HistoryServiceTest {
p.setSortCol("type.name"); p.setSortCol("type.name");
p.setSortDirection("descending"); p.setSortDirection("descending");
Page<History> result = this.historyService.readAllByProbe(new Probe(1), p); Page<History> result = this.historyService.readAllByProbeID(Long.valueOf(1), p);
for (History h : result.getContent()) { for (History h : result.getContent()) {
System.out.println(h.getId()); System.out.println(h.getId());
} }

View File

@ -28,7 +28,7 @@ public class InfraDAOTest {
List<Probe> probes = new ArrayList<>(); List<Probe> probes = new ArrayList<>();
Probe probe = new Probe(); Probe probe = new Probe();
probe.setId(1); probe.setId(Long.valueOf(1));
probes.add(probe); probes.add(probe);

View File

@ -37,7 +37,7 @@ public class InfraHostServiceTest {
infraHost.setMac("30-9C-23-15-A3-09"); infraHost.setMac("30-9C-23-15-A3-09");
infraHost.setIpv4("192.168.1.1"); infraHost.setIpv4("192.168.1.1");
InfraOS infraOS = new InfraOS(); InfraOS infraOS = new InfraOS();
infraOS.setId(2); infraOS.setId(Long.valueOf(2));
infraHost.setOs(infraOS); infraHost.setOs(infraOS);
@ -47,14 +47,14 @@ public class InfraHostServiceTest {
this.infraHostService.regist(infraHost); this.infraHostService.regist(infraHost);
Assert.assertNotEquals(infraHost.getId(), 0 ); Assert.assertNotEquals(infraHost.getId().longValue(), 0 );
} }
@Test @Test
public void read() throws Exception { public void read() throws Exception {
InfraHost infraHost = this.infraHostService.read(1); InfraHost infraHost = this.infraHostService.read(Long.valueOf(1));
String json = objectMapper.writeValueAsString(infraHost); String json = objectMapper.writeValueAsString(infraHost);

View File

@ -42,7 +42,7 @@ public class InfraMachineServiceTest {
this.infraMachineService.regist(infraMachine); this.infraMachineService.regist(infraMachine);
Assert.assertNotEquals(infraMachine.getId(), 0); Assert.assertNotEquals(infraMachine.getId().longValue(), 0);
} }
@ -51,7 +51,7 @@ public class InfraMachineServiceTest {
// regist(); // regist();
InfraMachine infraMachine = this.infraMachineService.read(1); InfraMachine infraMachine = this.infraMachineService.read(Long.valueOf(1));
String json = objectMapper.writeValueAsString(infraMachine); String json = objectMapper.writeValueAsString(infraMachine);
System.out.println(json); System.out.println(json);

View File

@ -36,7 +36,7 @@ public class InfraOSApplicationServiceTest {
infraOSApplication.setName("Apache"); infraOSApplication.setName("Apache");
InfraOS infraOS = new InfraOS(); InfraOS infraOS = new InfraOS();
infraOS.setId(2); infraOS.setId(Long.valueOf(2));
infraOSApplication.setOs(infraOS); infraOSApplication.setOs(infraOS);
@ -46,14 +46,14 @@ public class InfraOSApplicationServiceTest {
this.infraOSApplicationService.regist(infraOSApplication); this.infraOSApplicationService.regist(infraOSApplication);
Assert.assertNotEquals(infraOSApplication.getId(), 0); Assert.assertNotEquals(infraOSApplication.getId().longValue(), 0);
} }
@Test @Test
public void read() throws Exception { public void read() throws Exception {
InfraOSApplication infraOSApplication = this.infraOSApplicationService.read(1); InfraOSApplication infraOSApplication = this.infraOSApplicationService.read(Long.valueOf(1));
Assert.assertNotNull(infraOSApplication); Assert.assertNotNull(infraOSApplication);

View File

@ -36,7 +36,7 @@ public class InfraOSDaemonServiceTest {
infraOSDaemon.setName("Apache"); infraOSDaemon.setName("Apache");
InfraOS infraOS = new InfraOS(); InfraOS infraOS = new InfraOS();
infraOS.setId(2); infraOS.setId(Long.valueOf(2));
infraOSDaemon.setOs(infraOS); infraOSDaemon.setOs(infraOS);
@ -46,14 +46,14 @@ public class InfraOSDaemonServiceTest {
this.infraOSDaemonService.regist(infraOSDaemon); this.infraOSDaemonService.regist(infraOSDaemon);
Assert.assertNotEquals(infraOSDaemon.getId(), 0); Assert.assertNotEquals(infraOSDaemon.getId().longValue(), 0);
} }
@Test @Test
public void read() throws Exception { public void read() throws Exception {
InfraOSDaemon infraOSDaemon = this.infraOSDaemonService.read(1); InfraOSDaemon infraOSDaemon = this.infraOSDaemonService.read(Long.valueOf(1));
Assert.assertNotNull(infraOSDaemon); Assert.assertNotNull(infraOSDaemon);
String json = objectMapper.writeValueAsString(infraOSDaemon); String json = objectMapper.writeValueAsString(infraOSDaemon);

View File

@ -37,7 +37,7 @@ public class InfraOSPortServiceTest {
infraOSPort.setPortType("TCP"); infraOSPort.setPortType("TCP");
InfraOS infraOS = new InfraOS(); InfraOS infraOS = new InfraOS();
infraOS.setId(1); infraOS.setId(Long.valueOf(1));
MetaInfraType metaInfraType = new MetaInfraType(); MetaInfraType metaInfraType = new MetaInfraType();
metaInfraType.setId(2); metaInfraType.setId(2);
@ -58,7 +58,7 @@ public class InfraOSPortServiceTest {
InfraOSPort infraOSPort; InfraOSPort infraOSPort;
try { try {
infraOSPort = this.infraOSPortService.readByPort(1, 22, "TCP"); infraOSPort = this.infraOSPortService.readByPort(Long.valueOf(1), 22, "TCP");
Assert.assertNotEquals(infraOSPort, null); Assert.assertNotEquals(infraOSPort, null);
} catch (OverflowException e) { } catch (OverflowException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block

View File

@ -40,7 +40,7 @@ public class InfraOSServiceTest {
infraOS.setMeta(""); infraOS.setMeta("");
InfraMachine infraMachine = new InfraMachine(); InfraMachine infraMachine = new InfraMachine();
infraMachine.setId(1); infraMachine.setId(Long.valueOf(1));
MetaInfraType metaInfraType = new MetaInfraType(); MetaInfraType metaInfraType = new MetaInfraType();
metaInfraType.setId(3); metaInfraType.setId(3);
@ -55,7 +55,7 @@ public class InfraOSServiceTest {
@Test @Test
public void read() throws Exception { public void read() throws Exception {
InfraOS infraOS = this.infraOSService.read(1); InfraOS infraOS = this.infraOSService.read(Long.valueOf(1));
String json = objectMapper.writeValueAsString(infraOS); String json = objectMapper.writeValueAsString(infraOS);
System.out.println(json); System.out.println(json);
} }

View File

@ -1,164 +1,154 @@
// package com.loafle.overflow.central.module.noauthprobe.service; package com.loafle.overflow.central.module.noauthprobe.service;
// import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.commons.service.MessagePublisher;
// 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.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 com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
// import org.junit.Assert; import org.junit.Assert;
// import org.junit.Ignore; 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;
// 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.io.IOException;
// import java.util.ArrayList; import java.util.ArrayList;
// import java.util.List; import java.util.List;
// /** /**
// * Created by snoop on 17. 6. 28. * Created by snoop on 17. 6. 28.
// */ */
// @RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
// @ContextConfiguration(classes = {AppConfigTest.class}) @ContextConfiguration(classes = { AppConfigTest.class })
// public class NoAuthProbeServiceTest { public class NoAuthProbeServiceTest {
// @Autowired @Autowired
// private NoAuthProbeService noAuthProbeService; private CentralNoAuthProbeService noAuthProbeService;
// @Autowired @Autowired
// private MessagePublisher messagePublisher; private MessagePublisher messagePublisher;
// @Ignore @Ignore
// @Test @Test
// public void regist() throws Exception { public void regist() throws Exception {
// NoAuthProbe noAuthProbe = new NoAuthProbe(); NoAuthProbe noAuthProbe = new NoAuthProbe();
// noAuthProbe.setHostName("snoop");
// noAuthProbe.setIpAddress(3232235980L);
// noAuthProbe.setMacAddress(8796753988883L);
noAuthProbe.setDescription(
"{\"host\":{\"name\":\"snoop-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"DE60E4C3-347A-4D38-AEAB-1760471665EA\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
// // noAuthProbe.setHostName("snoop"); noAuthProbe.setApiKey("52abd6fd57e511e7ac52080027658d13");
// // noAuthProbe.setIpAddress(3232235980L);
// // noAuthProbe.setMacAddress(8796753988883L);
// noAuthProbe.setDescription("{\"host\":{\"name\":\"snoop-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"DE60E4C3-347A-4D38-AEAB-1760471665EA\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
// noAuthProbe.setApiKey("52abd6fd57e511e7ac52080027658d13"); MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
metaNoAuthProbeStatus.setId((short) 3);
// MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus(); noAuthProbe.setStatus(metaNoAuthProbeStatus);
// metaNoAuthProbeStatus.setId((short)3); noAuthProbe.setTempProbeKey("ac7f252b5bc811e784ad080027658d13");
// noAuthProbe.setStatus(metaNoAuthProbeStatus); Domain d = new Domain();
// noAuthProbe.setTempProbeKey("ac7f252b5bc811e784ad080027658d13"); d.setId(Long.valueOf(1));
noAuthProbe.setDomain(d);
// Domain d = new Domain(); this.noAuthProbeService.regist(noAuthProbe);
// d.setId(1);
// noAuthProbe.setDomain(d);
// this.noAuthProbeService.regist(noAuthProbe); Assert.assertNotEquals(noAuthProbe.getId().longValue(), 0);
// Assert.assertNotEquals(noAuthProbe.getId(), 0); }
// } @Ignore
@Test
public void registForNoAuthProbes() throws Exception {
// @Ignore NoAuthProbe noAuthProbe = new NoAuthProbe();
// @Test
// public void registForNoAuthProbes() throws Exception {
// NoAuthProbe noAuthProbe = new NoAuthProbe(); // noAuthProbe.setHostName("geek");
// noAuthProbe.setIpAddress(3232235980L);
// noAuthProbe.setMacAddress(8796753988883L);
noAuthProbe.setDescription(
"{\"host\":{\"name\":\"geek-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"03000200-0400-0500-0006-000700080009\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
noAuthProbe.setApiKey("521abd6fd57e511e7ac52080027658d13");
// // noAuthProbe.setHostName("geek"); MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
// // noAuthProbe.setIpAddress(3232235980L); metaNoAuthProbeStatus.setId((short) 3);
// // noAuthProbe.setMacAddress(8796753988883L);
// noAuthProbe.setDescription("{\"host\":{\"name\":\"geek-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"03000200-0400-0500-0006-000700080009\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
// noAuthProbe.setApiKey("521abd6fd57e511e7ac52080027658d13");
// MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus(); noAuthProbe.setStatus(metaNoAuthProbeStatus);
// metaNoAuthProbeStatus.setId((short)3); noAuthProbe.setTempProbeKey("a1c7f252b5bc811e784ad080027658d13");
// noAuthProbe.setStatus(metaNoAuthProbeStatus); Domain d = new Domain();
// noAuthProbe.setTempProbeKey("a1c7f252b5bc811e784ad080027658d13"); d.setId(Long.valueOf(1));
noAuthProbe.setDomain(d);
// Domain d = new Domain(); List<NoAuthProbe> noAuthProbes = new ArrayList<NoAuthProbe>();
// d.setId(1);
// noAuthProbe.setDomain(d);
// List<NoAuthProbe> noAuthProbes = new ArrayList<NoAuthProbe>(); noAuthProbes.add(noAuthProbe);
// List<NoAuthProbe> dd =
// this.noAuthProbeService.registForNoAuthProbes(noAuthProbes);
// noAuthProbes.add(noAuthProbe); // System.out.println(dd.get(0).getId());
// // List<NoAuthProbe> dd = this.noAuthProbeService.registForNoAuthProbes(noAuthProbes);
// // System.out.println(dd.get(0).getId()); Assert.assertNotEquals(noAuthProbes.size(), 2);
// Assert.assertNotEquals(noAuthProbes.size(), 2); }
// } @Ignore
@Test
public void readAllByDomainID() throws Exception {
List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomainID(Long.valueOf(1));
// @Ignore Assert.assertNotEquals(probes.size(), 0);
// @Test
// public void readAllByDomain() throws Exception {
// Domain domain = new Domain(); }
// domain.setId(1);
// List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomain(domain); @Ignore
@Test
public void read() throws Exception {
NoAuthProbe noAuthProbe = this.noAuthProbeService.read(Long.valueOf(1));
// Assert.assertNotEquals(probes.size(), 0); Assert.assertNotEquals(noAuthProbe, null);
}
// } @Ignore
@Test
public void acceptProbe() throws Exception {
// @Ignore this.noAuthProbeService.acceptNoAuthProbe(Long.valueOf(1));
// @Test
// public void read() throws Exception {
// NoAuthProbe noAuthProbe = this.noAuthProbeService.read(1); }
// Assert.assertNotEquals(noAuthProbe, null); @Ignore
// } @Test
public void ssss() {
String ss = "192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64";
// @Ignore String[] sss = ss.split("\\|");
// @Test
// public void acceptProbe() throws IOException {
// NoAuthProbe noAuthProbe = this.noAuthProbeService.read(1); System.out.println(sss[0]);
}
// this.noAuthProbeService.acceptNoAuthProbe(noAuthProbe); @Test
public void readByTempKey() throws Exception {
// } NoAuthProbe noAuthProbe = this.noAuthProbeService.readByTempProbeKey("1cf2555c57d511e79714080027658d15");
// @Ignore Assert.assertNotEquals(noAuthProbe, null);
// @Test
// public void ssss() {
// String ss = "192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64";
// String[] sss = ss.split("\\|"); }
// System.out.println(sss[0]); @Test
// } @Ignore
public void sendWeb() throws OverflowException {
List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomainID(Long.valueOf(1));
// @Test messagePublisher.publishToDomainMembers(Long.valueOf(1), "NoAuthProbeService.regist", probes);
// public void readByTempKey() {
// NoAuthProbe noAuthProbe = this.noAuthProbeService.readByTempKey("1cf2555c57d511e79714080027658d15"); }
// Assert.assertNotEquals(noAuthProbe, null); }
// }
// @Test
// @Ignore
// public void sendWeb() throws OverflowException {
// Domain domain = new Domain();
// domain.setId(1);
// List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomain(domain);
// messagePublisher.publishToDomainMembers(domain.getId(), "NoAuthProbeService.regist", probes);
// }
// }

View File

@ -1,146 +1,145 @@
package com.loafle.overflow.central.module.target.service; package com.loafle.overflow.central.module.target.service;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.model.discovery.Host; import com.loafle.overflow.model.discovery.Host;
import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.service.central.target.TargetDiscoveryService; import com.loafle.overflow.service.central.target.TargetDiscoveryService;
import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Ignore; 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.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
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.BufferedReader; import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Date; import java.util.List;
import java.util.List;
/** /**
* Created by snoop on 17. 6. 28. * Created by snoop on 17. 6. 28.
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AppConfigTest.class}) @ContextConfiguration(classes = {AppConfigTest.class})
public class TargetDiscoveryServiceTest { public class TargetDiscoveryServiceTest {
@Autowired @Autowired
private ResourceLoader resourceLoader; private ResourceLoader resourceLoader;
@Autowired @Autowired
private TargetDiscoveryService targetDiscoveryService; private TargetDiscoveryService targetDiscoveryService;
// @Ignore // @Ignore
@Test @Test
public void saveAllTarget() throws Exception { public void saveAllTarget() throws Exception {
String json = readFileAsString(resourceLoader.getResource("classpath:2018-04-25-tds.json").getURI().getPath()); String json = readFileAsString(resourceLoader.getResource("classpath:2018-04-25-tds.json").getURI().getPath());
// Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create(); // Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
List<Host> hosts = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Host.class)); List<Host> hosts = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Host.class));
Probe probe = new Probe(); Probe probe = new Probe();
probe.setId(1); probe.setId(Long.valueOf(1));
this.targetDiscoveryService.saveAllTarget(hosts, probe); this.targetDiscoveryService.saveAllTarget(hosts, probe);
} }
private String readFileAsString(String filePath) throws IOException { private String readFileAsString(String filePath) throws IOException {
StringBuffer fileData = new StringBuffer(); StringBuffer fileData = new StringBuffer();
BufferedReader reader = new BufferedReader( BufferedReader reader = new BufferedReader(
new FileReader(filePath)); new FileReader(filePath));
char[] buf = new char[1024]; char[] buf = new char[1024];
int numRead=0; int numRead=0;
while((numRead=reader.read(buf)) != -1){ while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead); String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData); fileData.append(readData);
} }
reader.close(); reader.close();
return fileData.toString(); return fileData.toString();
} }
@Ignore @Ignore
@Test @Test
public void testParam() throws NoSuchMethodException { public void testParam() throws NoSuchMethodException {
Method m = this.targetDiscoveryService.getClass().getMethod("saveAllTarget", List.class, Probe.class); Method m = this.targetDiscoveryService.getClass().getMethod("saveAllTarget", List.class, Probe.class);
// Method m = TargetDiscoveryService.class.getMethod("saveAllTarget", List.class, Probe.class); // Method m = TargetDiscoveryService.class.getMethod("saveAllTarget", List.class, Probe.class);
Class<?> clazz = AopUtils.getTargetClass(this.targetDiscoveryService); Class<?> clazz = AopUtils.getTargetClass(this.targetDiscoveryService);
Method[] ms = clazz.getMethods(); Method[] ms = clazz.getMethods();
Method sm = null; Method sm = null;
for(Method mm : ms){ for(Method mm : ms){
if ("saveAllTarget".equals(mm.getName())) { if ("saveAllTarget".equals(mm.getName())) {
sm = mm; sm = mm;
break; break;
} }
} }
if (sm != null) { if (sm != null) {
Type[] ts = sm.getGenericParameterTypes(); Type[] ts = sm.getGenericParameterTypes();
for(Type t : ts){ for(Type t : ts){
if (t instanceof ParameterizedType) { if (t instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType)t; ParameterizedType pt = (ParameterizedType)t;
System.out.println(pt.getActualTypeArguments()[0].getTypeName()); System.out.println(pt.getActualTypeArguments()[0].getTypeName());
} }
System.out.println(t.getTypeName()); System.out.println(t.getTypeName());
} }
} }
System.out.println(m.getName()); System.out.println(m.getName());
Type[] genericParameterTypes = m.getGenericParameterTypes(); Type[] genericParameterTypes = m.getGenericParameterTypes();
for(Type genericParameterType : genericParameterTypes){ for(Type genericParameterType : genericParameterTypes){
if(genericParameterType instanceof ParameterizedType){ if(genericParameterType instanceof ParameterizedType){
ParameterizedType aType = (ParameterizedType) genericParameterType; ParameterizedType aType = (ParameterizedType) genericParameterType;
Type[] parameterArgTypes = aType.getActualTypeArguments(); Type[] parameterArgTypes = aType.getActualTypeArguments();
for(Type parameterArgType : parameterArgTypes){ for(Type parameterArgType : parameterArgTypes){
Class parameterArgClass = (Class) parameterArgType; Class parameterArgClass = (Class) parameterArgType;
System.out.println("parameterArgClass = " + parameterArgClass); System.out.println("parameterArgClass = " + parameterArgClass);
} }
} }
} }
} }
@Ignore @Ignore
@Test @Test
public void testName() throws ClassNotFoundException { public void testName() throws ClassNotFoundException {
Object o = this.targetDiscoveryService; Object o = this.targetDiscoveryService;
String nnn = o.getClass().getSimpleName(); String nnn = o.getClass().getSimpleName();
System.out.println(nnn); System.out.println(nnn);
} }
} }

View File

@ -1,4 +1,4 @@
datasource.url=jdbc:postgresql://192.168.1.50:5432/overflow datasource.url=jdbc:postgresql://192.168.1.101:5432/overflow
datasource.username=overflow datasource.username=overflow
datasource.password=qwer5795 datasource.password=qwer5795
datasource.driver-class-name=org.postgresql.Driver datasource.driver-class-name=org.postgresql.Driver