This commit is contained in:
crusader 2018-06-05 21:56:40 +09:00
parent e8cd4eda7c
commit 07ef365ad3
62 changed files with 476 additions and 554 deletions

27
pom.xml
View File

@ -40,6 +40,18 @@
</properties>
<dependencies>
<dependency>
<groupId>com.loafle.overflow</groupId>
<artifactId>central-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.loafle.overflow</groupId>
<artifactId>commons-java</artifactId>
<version>1.0.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.loafle.commons</groupId>
<artifactId>rpc-java</artifactId>
@ -185,21 +197,6 @@
<version>${caffeine.version}</version>
</dependency>
<dependency>
<groupId>com.loafle.overflow</groupId>
<artifactId>central-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.loafle.overflow</groupId>
<artifactId>commons-java</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.warrenstrange</groupId>
<artifactId>googleauth</artifactId>

View File

@ -3,12 +3,19 @@ package com.loafle.overflow.central.commons.service;
import com.loafle.overflow.core.exception.OverflowException;
public interface MessagePublisher {
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 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 publishToMember(final String memberID, final String method, final Object... params) throws OverflowException;
void publishToMemberSession(final String memberSessionID, final String method, final Object... params) throws OverflowException;
void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params) throws OverflowException;
void publishToMemberSession(final String memberSessionID, final String method, final Object... params)
throws OverflowException;
void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params)
throws OverflowException;
void publishToProbe(final String probeKey, final String method, final Object... params) throws OverflowException;
}

View File

@ -6,7 +6,6 @@ import com.loafle.overflow.central.module.apikey.dao.ApiKeyDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.apikey.ApiKey;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.service.central.apikey.ApiKeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -1,11 +1,6 @@
package com.loafle.overflow.central.module.auth.dao;
import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.model.target.Target;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -14,5 +9,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface AuthCrawlerDAO extends JpaRepository<AuthCrawler, Long> {
AuthCrawler findByCrawlerAndTarget(MetaCrawler metaCrawler, Target target);
AuthCrawler findByMetaCrawlerIdAndTargetId(Short metaCrawlerId, Long targetId);
}

View File

@ -7,7 +7,6 @@ import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.infra.Infra;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.model.target.Target;
import com.loafle.overflow.service.central.auth.AuthCrawlerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -18,40 +17,39 @@ import org.springframework.stereotype.Service;
@Service("AuthCrawlerService")
public class CentralAuthCrawlerService implements AuthCrawlerService {
@Autowired
private AuthCrawlerDAO authCrawlerDAO;
@Autowired
private AuthCrawlerDAO authCrawlerDAO;
@Autowired
private CentralInfraService infraService;
@Autowired
private CentralInfraService infraService;
public AuthCrawler regist(AuthCrawler authCrawler) {
public AuthCrawler regist(AuthCrawler authCrawler) {
// if (authCrawler == null) {
// return this.authCrawlerDAO.save(authCrawler);
// }
AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByCrawlerAndTarget(authCrawler.getCrawler(),
authCrawler.getTarget());
AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(authCrawler.getMetaCrawler().getId(),
authCrawler.getTarget().getId());
if (authCrawler == null) {
return this.authCrawlerDAO.save(authCrawler);
}
dbAuthCrawler.setAuthJson(authCrawler.getAuthJson());
dbAuthCrawler.setMetaCrawler(authCrawler.getMetaCrawler());
dbAuthCrawler.setTarget(authCrawler.getTarget());
dbAuthCrawler.setAuthJson(authCrawler.getAuthJson());
dbAuthCrawler.setCrawler(authCrawler.getCrawler());
dbAuthCrawler.setTarget(authCrawler.getTarget());
return this.authCrawlerDAO.save(dbAuthCrawler);
}
return this.authCrawlerDAO.save(dbAuthCrawler);
}
public boolean checkAuthCrawler(Long infraId, MetaCrawler metaCrawler, 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);
// FIXME: Check Crawler on Probe
// FIXME: Check Crawler on Probe
return false;
}
return false;
}
public AuthCrawler readByMetaCrawlerIDAndTargetID(Short metaCrawlerID, Long targetID) throws OverflowException {
public AuthCrawler readAuth(MetaCrawler metaCrawler, Target target) throws OverflowException {
return this.authCrawlerDAO.findByCrawlerAndTarget(metaCrawler, target);
}
return this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(metaCrawlerID, targetID);
}
}

View File

@ -52,6 +52,13 @@ public class CentralDiscoveryService implements DiscoveryService {
discoveryService);
}
@WebappAPI
public void stopDiscovery(String probeID) throws OverflowException {
String requesterSessionID = SessionMetadata.getSessionID();
messagePublisher.publishToProbe(probeID, "DiscoveryService.StopDiscovery", requesterSessionID);
}
@ProbeAPI
public void discoveryStart(String requesterSessionID, Date startDate) throws OverflowException {
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStart", startDate);

View File

@ -1,13 +1,9 @@
package com.loafle.overflow.central.module.domain.dao;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.domain.DomainMember;
import com.loafle.overflow.model.member.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -18,13 +14,9 @@ import java.util.List;
@Repository
public interface DomainMemberDAO extends JpaRepository<DomainMember, Long> {
@Query("SELECT dm from DomainMember dm where dm.member.email = (:email)")
DomainMember findByMemberEmail(@Param("email") String email);
@Query("SELECT dm.domain from DomainMember dm where dm.member.id = (:memberID)")
Domain findDomainByMemberId(@Param("memberID") Long memberID);
DomainMember findByMemberEmail(String memberEmail);
Domain findDomainByMemberId(Long memberId);
@Query("SELECT dm.member from DomainMember dm where dm.domain.id = (:domainID)")
List<Member> findAllMemberByDomainId(@Param("domainID") Long domainID);
List<Member> findAllMemberByDomainId(Long domainID);
}

View File

@ -2,8 +2,6 @@ package com.loafle.overflow.central.module.domain.service;
import com.loafle.overflow.central.module.domain.dao.DomainMemberDAO;
import com.loafle.overflow.central.module.member.dao.MemberDAO;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.domain.DomainMember;
import com.loafle.overflow.model.member.Member;
@ -19,23 +17,23 @@ import java.util.List;
@Service("DomainMemberService")
public class CentralDomainMemberService implements DomainMemberService {
@Autowired
private DomainMemberDAO domainMemberDAO;
@Autowired
private DomainMemberDAO domainMemberDAO;
public void regist(DomainMember domainMember) {
this.domainMemberDAO.save(domainMember);
}
public void regist(DomainMember domainMember) {
this.domainMemberDAO.save(domainMember);
}
public Domain readDomainByMemberID(Long memberID) {
return this.domainMemberDAO.findDomainByMemberId(memberID);
}
public Domain readDomainByMemberID(Long memberID) {
return this.domainMemberDAO.findDomainByMemberId(memberID);
}
public DomainMember readByMemberEmail(String email) {
return this.domainMemberDAO.findByMemberEmail(email);
}
public DomainMember readByMemberEmail(String email) {
return this.domainMemberDAO.findByMemberEmail(email);
}
public List<Member> readAllMemberByDomainID(final Long domainID) {
return this.domainMemberDAO.findAllMemberByDomainId(domainID);
}
public List<Member> readAllMemberByDomainID(final Long domainID) {
return this.domainMemberDAO.findAllMemberByDomainId(domainID);
}
}

View File

@ -14,10 +14,10 @@ import org.springframework.stereotype.Service;
@Service("DomainService")
public class CentralDomainService implements DomainService {
@Autowired
private DomainDAO domainDAO;
@Autowired
private DomainDAO domainDAO;
public void regist(Domain domain) throws OverflowException {
this.domainDAO.save(domain);
}
public void regist(Domain domain) throws OverflowException {
this.domainDAO.save(domain);
}
}

View File

@ -1,8 +1,6 @@
package com.loafle.overflow.central.module.email.dao;
import com.loafle.overflow.model.email.EmailAuth;
import com.loafle.overflow.model.member.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -15,7 +13,6 @@ import java.util.List;
public interface EmailAuthDAO extends JpaRepository<EmailAuth, Long> {
EmailAuth findByEmailAuthKey(String emailAuthKey);
List<EmailAuth> findByMember(Member member);
List<EmailAuth> findByMemberId(Long memberId);
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.email.service;
import com.loafle.overflow.central.commons.utils.EmailSender;
import com.loafle.overflow.central.commons.utils.GenerateKey;
import com.loafle.overflow.central.module.domain.dao.DomainDAO;
@ -28,221 +27,219 @@ import java.util.*;
*/
@Service("EmailAuthService")
public class EmailAuthService {
private static final String WEB_GO_MEMBER_ADDR = "http://127.0.0.1:4200/#/auth/";
private static final String WEB_GO_MEMBER_ADDR = "http://127.0.0.1:4200/#/auth/";
@Autowired
private EmailAuthDAO emailAuthDAO;
@Autowired
private EmailAuthDAO emailAuthDAO;
@Autowired
private MemberDAO memberDAO;
@Autowired
private MemberDAO memberDAO;
@Autowired
private DomainDAO domainDAO;
@Autowired
private DomainDAO domainDAO;
@Autowired
private DomainMemberDAO domainMemberDAO;
@Autowired
private DomainMemberDAO domainMemberDAO;
@Autowired
private EmailSender emailSender;
@Autowired
private EmailSender emailSender;
// 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) {
return this.emailAuthDAO.findOne(id);
}
public EmailAuth read(Long id) {
return this.emailAuthDAO.findOne(id);
public EmailAuth readBySignupAuthKey(String token) throws OverflowException {
// System.out.println("authKey = [" + token + "]");
// String deStr = URLDecoder.decode(token, "UTF-8");
// System.out.println("deStr = [" + deStr + "]");
//
// EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(deStr);
EmailAuth auth = this.readByToken(token);
if (auth != null) {
boolean res = this.isValidateTime(auth);
if (!res) {
throw new OverflowException("The authentication expiration time has expired, or the token has been verified.",
new Throwable());
}
auth.setAuthConfirmDate(new Date());
this.emailAuthDAO.save(auth);
auth.getMember().setMetaMemberStatus(new MetaMemberStatus((short) 2));
this.memberDAO.save(auth.getMember());
Domain domain = new Domain();
domain.setName(auth.getMember().getCompanyName());
Domain domain1 = this.domainDAO.save(domain);
DomainMember domainMember = new DomainMember();
domainMember.setDomain(domain1);
domainMember.setMember(auth.getMember());
this.domainMemberDAO.save(domainMember);
}
public EmailAuth readBySignupAuthKey(String token) throws OverflowException {
// System.out.println("authKey = [" + token + "]");
// String deStr = URLDecoder.decode(token, "UTF-8");
// System.out.println("deStr = [" + deStr + "]");
//
// EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(deStr);
return auth;
}
EmailAuth auth = this.readByToken(token);
public EmailAuth readByPwAuthKey(String token) throws OverflowException {
if (auth != null) {
EmailAuth auth = this.readByToken(token);
boolean res = this.isValidateTime(auth);
if (auth != null && (auth.getMember() != null && auth.getMember().getId() > 0)) {
boolean res = this.isValidateTime(auth);
if (!res) {
throw new OverflowException(
"The authentication expiration time has expired, or the token has been verified.",
new Throwable());
}
if (!res) {
throw new OverflowException("The authentication expiration time has expired, or the token has been verified.",
new Throwable());
}
auth.setAuthConfirmDate(new Date());
this.emailAuthDAO.save(auth);
auth.getMember().setStatus(new MetaMemberStatus((short)2));
this.memberDAO.save(auth.getMember());
Domain domain = new Domain();
domain.setName(auth.getMember().getCompanyName());
Domain domain1 = this.domainDAO.save(domain);
DomainMember domainMember = new DomainMember();
domainMember.setDomain(domain1);
domainMember.setMember(auth.getMember());
this.domainMemberDAO.save(domainMember);
}
return auth;
auth.setAuthConfirmDate(new Date());
this.emailAuthDAO.save(auth);
}
public EmailAuth readByPwAuthKey(String token) throws OverflowException {
return auth;
EmailAuth auth = this.readByToken(token);
}
if (auth != null && (auth.getMember() != null && auth.getMember().getId() > 0)) {
boolean res = this.isValidateTime(auth);
if (!res) {
throw new OverflowException(
"The authentication expiration time has expired, or the token has been verified.",
new Throwable());
}
auth.setAuthConfirmDate(new Date());
this.emailAuthDAO.save(auth);
}
return auth;
public EmailAuth readByToken(String token) {
String encode = "";
try {
encode = URLEncoder.encode(token, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
public EmailAuth readByToken(String token) {
String encode = "";
EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(encode);
try {
encode = URLEncoder.encode(token, "UTF-8");
}catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return auth;
}
// dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk=
EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(encode);
public List<EmailAuth> readByMember(Long memberId) {
return this.emailAuthDAO.findByMemberId(memberId);
}
return auth;
}
// dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk=
public EmailAuth modify(EmailAuth emailAuth) {
return this.emailAuthDAO.save(emailAuth);
}
public List<EmailAuth> readByMember(Long memberId) {
return this.emailAuthDAO.findByMember(new Member(memberId));
public EmailAuth sendEmailByMember(Member member) throws OverflowException {
return this.sendEMail(member, 1);
}
// Todo Send Email Refactoring
public EmailAuth sendEmailResetPassword(Member member) throws OverflowException {
return this.sendEMail(member, 2);
}
private boolean isValidateTime(EmailAuth auth) {
Calendar cal = Calendar.getInstance();
cal.setTime(auth.getCreateDate());
cal.add(Calendar.HOUR, 12);
Date futureDate = cal.getTime();
Date nowDate = new Date();
if (!nowDate.before(futureDate)) {
return false;
}
public EmailAuth modify(EmailAuth emailAuth) {
return this.emailAuthDAO.save(emailAuth);
if (null != auth.getAuthConfirmDate()) {
return false;
}
public EmailAuth sendEmailByMember(Member member) throws OverflowException {
return this.sendEMail(member, 1);
return true;
}
private EmailAuth sendEMail(Member member, int status) throws OverflowException {
String key = GenerateKey.getKey();
// String enMail = emailSender.encrypt(key);
String mailSubject = null;
String entry = null;
String templateName = null;
EmailAuth auth = new EmailAuth();
auth.setMember(member);
auth.setEmailAuthKey(key);
auth.setMetaEmailStatus(new MetaEmailStatus(status));
// System.out.println("encode = [" + encode + "]");
String encode = "";
try {
encode = URLEncoder.encode(key, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// Todo Send Email Refactoring
public EmailAuth sendEmailResetPassword(Member member) throws OverflowException {
return this.sendEMail(member, 2);
if (status == 1) {
mailSubject = "Signup Confirm Mail";
entry = "confirm-signup";
templateName = "/vmtemplates/signup.vm";
} else if (status == 2) {
mailSubject = "Reset Password Confirm Mail";
entry = "confirm-reset-password";
templateName = "/vmtemplates/password_reset.vm";
}
private boolean isValidateTime(EmailAuth auth) {
Mail mail = new Mail();
mail.setMailTo(member.getEmail());
mail.setMailSubject(mailSubject);
mail.setTemplateLoacation(templateName);
Calendar cal = Calendar.getInstance();
String uri = WEB_GO_MEMBER_ADDR + entry + "?token=" + encode;
cal.setTime(auth.getCreateDate());
cal.add(Calendar.HOUR, 12);
Date futureDate = cal.getTime();
Map<String, Object> model = new HashMap<>();
model.put("firstName", auth.getMember().getName());
model.put("lastName", auth.getMember().getCompanyName());
model.put("location", "Seoul");
model.put("signature", "www.loafle.com");
model.put("content", uri);
mail.setModel(model);
emailSender.sendSimpleEmail(mail);
Date nowDate = new Date();
this.emailAuthDAO.save(auth);
if (!nowDate.before(futureDate)) {
return false;
}
if (null != auth.getAuthConfirmDate()) {
return false;
}
return true;
}
private EmailAuth sendEMail(Member member, int status) throws OverflowException {
String key = GenerateKey.getKey();
// String enMail = emailSender.encrypt(key);
String mailSubject = null;
String entry = null;
String templateName = null;
EmailAuth auth = new EmailAuth();
auth.setMember(member);
auth.setEmailAuthKey(key);
auth.setEmailStatus(new MetaEmailStatus(status));
// System.out.println("encode = [" + encode + "]");
String encode = "";
try {
encode = URLEncoder.encode(key, "UTF-8");
}catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (status == 1) {
mailSubject = "Signup Confirm Mail";
entry = "confirm-signup";
templateName = "/vmtemplates/signup.vm";
} else if (status == 2) {
mailSubject = "Reset Password Confirm Mail";
entry = "confirm-reset-password";
templateName = "/vmtemplates/password_reset.vm";
}
Mail mail = new Mail();
mail.setMailTo(member.getEmail());
mail.setMailSubject(mailSubject);
mail.setTemplateLoacation(templateName);
String uri = WEB_GO_MEMBER_ADDR + entry + "?token=" + encode;
Map<String, Object> model = new HashMap<>();
model.put("firstName", auth.getMember().getName());
model.put("lastName", auth.getMember().getCompanyName());
model.put("location", "Seoul");
model.put("signature", "www.loafle.com");
model.put("content", uri);
mail.setModel(model);
emailSender.sendSimpleEmail(mail);
this.emailAuthDAO.save(auth);
return auth;
}
return auth;
}
}
// EmailAuth auth = new EmailAuth();
// auth.setMember(member);
// String en = emailSender.encrypt(member.getEmail());
// auth.setEmailAuthKey(en);
// auth.setEmailStatus(new MetaEmailStatus(1));
// String encode = URLEncoder.encode(en, "UTF-8");
// EmailAuth auth = new EmailAuth();
// auth.setMember(member);
// String en = emailSender.encrypt(member.getEmail());
// auth.setEmailAuthKey(en);
// auth.setEmailStatus(new MetaEmailStatus(1));
// String encode = URLEncoder.encode(en, "UTF-8");
//
//// System.out.println("encode = [" + encode + "]");
// Mail mail = new Mail();
// mail.setMailTo(member.getEmail());
// mail.setMailSubject("Confirm Email");
//// mail.setMailContent("http://127.0.0.1:19080/account/confirm_signup?key="+ encode +"\r\nConfirm Email");
//// System.out.println("encode = [" + encode + "]");
// Mail mail = new Mail();
// mail.setMailTo(member.getEmail());
// mail.setMailSubject("Confirm Email");
//// mail.setMailContent("http://127.0.0.1:19080/account/confirm_signup?key="+
// encode +"\r\nConfirm Email");
//
// String uri = WEB_GO_MEMBER_ADDR + "confirm_signup?key=" + encode + "\r\nConfirm Email";
// Map<String, Object> model = new HashMap<>();
// model.put("firstName", auth.getMember().getName());
// model.put("lastName", auth.getMember().getCompanyName());
// model.put("location", "Seoul");
// model.put("signature", "www.loafle.com");
// model.put("content", uri);
// String uri = WEB_GO_MEMBER_ADDR + "confirm_signup?key=" + encode +
// "\r\nConfirm Email";
// Map<String, Object> model = new HashMap<>();
// model.put("firstName", auth.getMember().getName());
// model.put("lastName", auth.getMember().getCompanyName());
// model.put("location", "Seoul");
// model.put("signature", "www.loafle.com");
// model.put("content", uri);
//
// mail.setModel(model);
// emailSender.sendSimpleEmail(mail);
// mail.setModel(model);
// emailSender.sendSimpleEmail(mail);
//
// this.emailAuthDAO.save(auth);
// this.emailAuthDAO.save(auth);
//
// return auth;
// return auth;

View File

@ -42,7 +42,7 @@ public class GenerateUtil {
return resultMap;
}
resultMap = this.metaSensorItemKeyService.readAllMapByCrawler(metaCrawler);
resultMap = this.metaSensorItemKeyService.readAllMapByMetaCrawlerID(metaCrawler.getId());
this.mappingMap.put(metaCrawler.getId(), resultMap);
return resultMap;
@ -85,7 +85,7 @@ public class GenerateUtil {
MetaSensorItemKey itemKey = null;
for(SensorItem sItem : sensorItems) {
itemKey = keyMap.get(sItem.getItem().getId());
itemKey = keyMap.get(sItem.getMetaSensorDisplayItem().getId());
if(metricMap.containsKey(itemKey.getFroms()) == false) {
metricMap.put(itemKey.getFroms(), new ArrayList<>());
}
@ -98,7 +98,7 @@ public class GenerateUtil {
public Keys createKeys(MetaSensorItemKey itemKey) throws OverflowException {
Keys keys = new Keys();
keys.setKey(itemKey.getKey());
keys.setMetric(itemKey.getItem().getKey());
keys.setMetric(itemKey.getMetaSensorItem().getKey());
return keys;
}
}

View File

@ -63,12 +63,12 @@ public class InfraHostGenerator {
schedule.setInterval("5");
sensorConfig.setSchedule(schedule);
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler());
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getMetaCrawler());
sensorConfig.setCrawler(crawler);
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler());
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getMetaCrawler());
if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
}
@ -77,7 +77,7 @@ public class InfraHostGenerator {
private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception {
AuthCrawler authCrawler = this.authCrawlerService.readAuth(dbSensor.getCrawler(), dbSensor.getTarget());
AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(), dbSensor.getTarget().getId());
if (authCrawler == null) {
return null;
@ -89,7 +89,7 @@ public class InfraHostGenerator {
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference<Map<String, String>>(){});
if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
connection.setPort(135);
connection.setPortType(PortType.TCP);
connection.setSsl(false);

View File

@ -66,14 +66,14 @@ public class InfraServiceGenerator {
schedule.setInterval("5");
sensorConfig.setSchedule(schedule);
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler());
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getMetaCrawler());
sensorConfig.setCrawler(crawler);
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler());
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getMetaCrawler());
if(dbSensor.getCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
if(dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
} else if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
} else if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
}
@ -82,7 +82,7 @@ public class InfraServiceGenerator {
private Target createTarget(InfraService infraService, Sensor sensor) throws Exception {
AuthCrawler authCrawler = this.authCrawlerService.readAuth(sensor.getCrawler(), sensor.getTarget());
AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(), sensor.getTarget().getId());
if(authCrawler == null) {
return null;
@ -90,7 +90,7 @@ public class InfraServiceGenerator {
Target target = new Target();
Connection connection = new Connection();
connection.setIp(infraService.getHost().getIpv4());
connection.setIp(infraService.getInfraHost().getIpv4());
connection.setPort(infraService.getPort());
connection.setPortType(PortType.valueOf(infraService.getPortType()));
connection.setSsl(infraService.isTlsType());
@ -101,11 +101,11 @@ public class InfraServiceGenerator {
Map<String, Object> auth = new HashMap<>();
if(sensor.getCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
auth.put("url", "jdbc:mysql://"+ infraService.getHost().getIpv4() +":" + infraService.getPort());
if(sensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
auth.put("url", "jdbc:mysql://"+ infraService.getInfraHost().getIpv4() +":" + infraService.getPort());
auth.put("id", optionMap.get("ID")); // FIXME: Auth Info
auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info
} else if (sensor.getCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
} else if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
auth.put("id", optionMap.get("ID")); // FIXME: Auth Info
auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info
connection.setPort(9840);

View File

@ -63,7 +63,7 @@ public class InfraServiceJMXGenerator {
keys = new Keys();
keys.setKey(tempItemKey.getKey());
keys.setMetric(tempItemKey.getItem().getKey());
keys.setMetric(tempItemKey.getMetaSensorItem().getKey());
keysList.add(this.generateUtil.createKeys(tempItemKey));
}

View File

@ -38,7 +38,7 @@ public class SensorConfigGenerator {
pageParams.setCountPerPage(Integer.MAX_VALUE);
pageParams.setSortCol("id");
pageParams.setSortDirection("descending");
Page<SensorItem> dbItemList = this.sensorItemService.readAllBySensor(sensor, pageParams);
Page<SensorItem> dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams);
List<SensorItem> sensorItems = dbItemList.getContent();
@ -50,10 +50,10 @@ public class SensorConfigGenerator {
Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId());
// 7 = Infra OS Service
if(infra.getInfraType().getId() == 7) {
if(infra.getMetaInfraType().getId() == 7) {
return this.infraServiceGenerator.process(dbSensor, sensorItems, infra);
}
if(infra.getInfraType().getId() == 2) {
if(infra.getMetaInfraType().getId() == 2) {
return this.infraHostGenerator.process(dbSensor, sensorItems, infra);
}

View File

@ -1,16 +1,12 @@
package com.loafle.overflow.central.module.history.dao;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.history.History;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* Created by insanity on 17. 8. 23.
*/
@ -18,11 +14,9 @@ import org.springframework.stereotype.Repository;
public interface HistoryDAO extends JpaRepository<History, Long> {
Page<History> findAllByProbeId(Long probeID, Pageable pageable);
@Query("SELECT h FROM History h WHERE h.probe.id = :#{#probeID} and h.type.id = :#{#type.id}")
Page<History> findAllByProbeIdAndType(@Param("probeID") Long probeID, @Param("type") com.loafle.overflow.model.meta.MetaHistoryType type, Pageable pageable);
Page<History> findAllByProbeIdAndMetaHistoryTypeId(Long probeID, Integer metaHistoryTypeId, Pageable pageable);
Page<History> findAllByDomainId(Long domainID, Pageable pageRequest);
@Query("SELECT h FROM History h WHERE h.domain.id = :#{#domainID} and h.type.id = :#{#type.id}")
Page<History> findAllByDomainIdAndType(@Param("domainID") Long domainID, @Param("type") com.loafle.overflow.model.meta.MetaHistoryType type, Pageable pageRequest);
Page<History> findAllByDomainIdAndMetaHistoryTypeId(Long domainID, Integer metaHistoryTypeId, Pageable pageRequest);
}

View File

@ -2,6 +2,7 @@ package com.loafle.overflow.central.module.history.service;
import com.loafle.overflow.central.commons.utils.PageUtil;
import com.loafle.overflow.central.module.history.dao.HistoryDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.model.PageParams;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.history.History;
@ -18,25 +19,25 @@ public class CentralHistoryService implements HistoryService {
@Autowired
private HistoryDAO historyDAO;
public History regist(History history) {
public History regist(History history) throws OverflowException {
return this.historyDAO.save(history);
}
public Page<History> readAllByProbeIDAndType(Long probeID, MetaHistoryType type, PageParams pageParams) {
return this.historyDAO.findAllByProbeIdAndType(probeID, type, PageUtil.getPageRequest(pageParams));
public Page<History> readAllByProbeIDAndMetaHistoryTypeID(Long probeID, Integer metaHistoryTypeID, PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByProbeIdAndMetaHistoryTypeId(probeID, metaHistoryTypeID, PageUtil.getPageRequest(pageParams));
}
public Page<History> readAllByProbeID(Long probeID, PageParams pageParams) {
public Page<History> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams));
}
public Page<History> readAllByDomainID(Long domainID, PageParams pageParams) {
public Page<History> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByDomainId(domainID, PageUtil.getPageRequest(pageParams));
}
public Page<History> readAllByDomainIDAndType(Long domainID, MetaHistoryType type, PageParams pageParams) {
return this.historyDAO.findAllByDomainIdAndType(domainID, type, PageUtil.getPageRequest(pageParams));
public Page<History> readAllByDomainIDAndMetaHistoryTypeID(Long domainID, Integer metaHistoryTypeID, PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByDomainIdAndMetaHistoryTypeId(domainID, metaHistoryTypeID, PageUtil.getPageRequest(pageParams));
}
}

View File

@ -6,8 +6,6 @@ import com.loafle.overflow.model.target.Target;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -21,13 +19,10 @@ public interface InfraDAO extends JpaRepository<Infra, Long> {
Page<Infra> findAllByProbeId(Long probeID, Pageable pageable);
@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> findAllByProbeInAndTargetNotNull(List<Probe> probes, Pageable pageable);
@Query("SELECT DISTINCT i.target FROM INFRA i WHERE i.probe IN (:probeList)")
List<Target> findAllTargetByProbeList(@Param("probeList") List<Probe> probeList);
List<Target> findAllTargetByProbeIn(List<Probe> probes);
Infra findByTargetId(Long targetID);
// List<Infra> findAllByProbe(List<Probe> probeList);
}

View File

@ -2,9 +2,6 @@ package com.loafle.overflow.central.module.infra.dao;
import com.loafle.overflow.model.infra.InfraOSPort;
import org.springframework.data.jpa.repository.JpaRepository;
// import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
@ -12,6 +9,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
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)")
InfraOSPort findByPort(@Param("osId") Long osId,@Param("portNumber") Integer portNumber,@Param("portType") String portType);
InfraOSPort findByInfraOSIdAndPortAndPortType(Long infraOSId, Integer port, String portType);
}

View File

@ -2,8 +2,6 @@ package com.loafle.overflow.central.module.infra.dao;
import com.loafle.overflow.model.infra.InfraService;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
@ -11,6 +9,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
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)")
InfraService findByService(@Param("hostId") Long hostId,@Param("portNumber") Integer portNumber,@Param("portType") String portType);
InfraService findByInfraHostIdAndPortAndPortType(Long infraHostId, Integer port, String portType);
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.infra.service;
import com.loafle.overflow.central.module.infra.dao.InfraHostDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.infra.InfraHost;
@ -21,11 +20,11 @@ public class CentralInfraHostService implements InfraHostService {
return this.infraHostDAO.save(infraHost);
}
public InfraHost read(Long id) throws OverflowException {
public InfraHost read(Long id) throws OverflowException {
return this.infraHostDAO.findOne(id);
}
public InfraHost readByIp(String ip) throws OverflowException {
public InfraHost readByIp(String ip) throws OverflowException {
return this.infraHostDAO.findByIpv4(ip);
}

View File

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

View File

@ -24,7 +24,8 @@ public class CentralInfraOSPortService implements InfraOSPortService {
return this.infraOSPortDAO.findOne(id);
}
public InfraOSPort readByPort(Long osId, int portNumber, String portType) throws OverflowException {
return this.infraOSPortDAO.findByPort(osId, portNumber, portType);
public InfraOSPort readByInfraOSIDAndPortAndPortType(Long infraOSID, Integer port, String portType)
throws OverflowException {
return this.infraOSPortDAO.findByInfraOSIdAndPortAndPortType(infraOSID, port, portType);
}
}

View File

@ -50,32 +50,31 @@ public class CentralInfraService implements InfraService {
public Page<Infra> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
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());
}
Page<Infra> infraList = this.infraDAO.findAllByProbeList(probeList, PageUtil.getPageRequest(pageParams));
for (Infra infra: infraList) {
Page<Infra> infraList = this.infraDAO.findAllByProbeInAndTargetNotNull(probeList, PageUtil.getPageRequest(pageParams));
for (Infra infra : infraList) {
infra.getTarget().setSensors(this.sensorDAO.findAllByTargetId(infra.getTarget().getId()));
}
return infraList;
}
public List<Target> readAllTargetByDomainID(Long domainID) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
List<Probe> probes = this.probeService.readAllByDomainID(domainID);
if(probeList == null || probeList.size() <= 0) {
if (probes == null || probes.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable());
}
return this.infraDAO.findAllTargetByProbeList(probeList);
return this.infraDAO.findAllTargetByProbeIn(probes);
}
public List<Target> readAllTargetByProbeList(List<Probe> probeList) throws OverflowException {
return this.infraDAO.findAllTargetByProbeList(probeList);
// return null;
public List<Target> readAllTargetByProbes(List<Probe> probes) throws OverflowException {
return this.infraDAO.findAllTargetByProbeIn(probes);
// return null;
}
public Infra readByTargetID(Long targetID) throws OverflowException {

View File

@ -24,7 +24,8 @@ public class CentralInfraServiceService implements InfraServiceService {
return this.infraServiceDAO.findOne(id);
}
public InfraService readByService(Long hostId, int portNumber, String portType) throws OverflowException {
return this.infraServiceDAO.findByService(hostId, portNumber, portType);
public InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType)
throws OverflowException {
return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, portType);
}
}

View File

@ -2,8 +2,6 @@ package com.loafle.overflow.central.module.member.dao;
import com.loafle.overflow.model.member.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
@ -12,6 +10,5 @@ import org.springframework.stereotype.Repository;
@Repository
public interface MemberDAO extends JpaRepository<Member, Long> {
@Query("select m from Member m WHERE m.email = :signinId")
Member findByEmail(@Param("signinId") String signinId);
Member findByEmail(String email);
}

View File

@ -1,10 +1,7 @@
package com.loafle.overflow.central.module.member.dao;
import com.loafle.overflow.model.member.Member;
import com.loafle.overflow.model.member.MemberTotp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
@ -12,8 +9,7 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface MemberTotpDAO extends JpaRepository<MemberTotp, Long> {
@Query("select m from MemberTotp m WHERE m.secretCode = :secretCode")
MemberTotp findBySecretCode(@Param("secretCode") String secretCode);
MemberTotp findBySecretCode(String secretCode);
MemberTotp findByMember(Member member);
MemberTotp findByMemberEmail(String memberEmail);
}

View File

@ -61,7 +61,7 @@ public class CentralMemberService implements MemberService {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
}
if ( m.getStatus().getId() == 1 ) {
if ( m.getMetaMemberStatus().getId() == 1 ) {
throw new OverflowException("EmailNotConfirmedException()", new Throwable());
}
@ -103,8 +103,8 @@ public class CentralMemberService implements MemberService {
}
member.setPw(passwordEncoder.encode(pw));
if (member.getStatus() == null) {
member.setStatus(new MetaMemberStatus((short) 1));
if (member.getMetaMemberStatus() == null) {
member.setMetaMemberStatus(new MetaMemberStatus((short) 1));
}
member.setTotpType(false);
@ -204,9 +204,9 @@ public class CentralMemberService implements MemberService {
member.setPw(preMember.getPw());
}
if (member.getStatus() == null || member.getStatus().getId() <= 0) {
member.setStatus(new MetaMemberStatus());
member.getStatus().setId(preMember.getStatus().getId());
if (member.getMetaMemberStatus() == null || member.getMetaMemberStatus().getId() <= 0) {
member.setMetaMemberStatus(new MetaMemberStatus());
member.getMetaMemberStatus().setId(preMember.getMetaMemberStatus().getId());
}
return this.modify(member);
}

View File

@ -58,8 +58,8 @@ public class CentralMemberTotpService implements MemberTotpService {
return this.totpDAO.findOne(id);
}
public boolean checkCodeForMember(Member member, String code) throws OverflowException {
MemberTotp totp = this.totpDAO.findByMember(member);
public boolean checkCodeForMember(String memberEmail, String code) throws OverflowException {
MemberTotp totp = this.totpDAO.findByMemberEmail(memberEmail);
if (null == totp && (totp.getSecretCode() == null || totp.getSecretCode().equals(""))) {
throw new OverflowException("SignInIdNotExistException", new Throwable());
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.meta.dao;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.model.meta.MetaCrawlerInputItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -12,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaCrawlerInputItemDAO extends JpaRepository<MetaCrawlerInputItem, Integer> {
List<MetaCrawlerInputItem> findAllByCrawler(MetaCrawler crawler);
List<MetaCrawlerInputItem> findAllByMetaCrawlerId(Short metaCrawlerId);
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.meta.dao;
import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.model.meta.MetaInfraVendor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -12,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaInfraVendorDAO extends JpaRepository<MetaInfraVendor, Integer> {
List<MetaInfraVendor> findAllByInfraType(MetaInfraType infraType);
List<MetaInfraVendor> findAllByMetaInfraTypeId(Integer MetaInfraTypeId);
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.meta.dao;
import com.loafle.overflow.model.meta.MetaProbeOs;
import com.loafle.overflow.model.meta.MetaProbePackage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -12,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaProbePackageDAO extends JpaRepository<MetaProbePackage, Long> {
List<MetaProbePackage> findAllByOs(MetaProbeOs metaProbeOs);
List<MetaProbePackage> findAllByMetaProbeOsId(Short metaProbeOsId);
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.meta.dao;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.model.meta.MetaSensorDisplayItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -12,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaSensorDisplayItemDAO extends JpaRepository<MetaSensorDisplayItem, Long> {
public List<MetaSensorDisplayItem> findAllByCrawler(MetaCrawler crawler);
public List<MetaSensorDisplayItem> findAllByMetaCrawlerId(Short metaCrawlerId);
}

View File

@ -1,11 +1,8 @@
package com.loafle.overflow.central.module.meta.dao;
import com.loafle.overflow.model.meta.MetaSensorDisplayItem;
import com.loafle.overflow.model.meta.MetaSensorDisplayMapping;
import com.loafle.overflow.model.meta.MetaSensorItemKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -15,6 +12,5 @@ import java.util.List;
*/
@Repository
public interface MetaSensorDisplayMappingDAO extends JpaRepository<MetaSensorDisplayMapping, Short> {
@Query("SELECT m.itemKey from MetaSensorDisplayMapping m where m.displayItem = (:displayItem)")
public List<MetaSensorItemKey> findAllMetaSensorItemKeyByDisplayItem(@Param("displayItem") MetaSensorDisplayItem displayItem);
public List<MetaSensorItemKey> findAllMetaSensorItemKeyByMetaSensorDisplayItemId(Long metaSensorDisplayItemId);
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.meta.dao;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.model.meta.MetaSensorItemKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -12,6 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaSensorItemKeyDAO extends JpaRepository<MetaSensorItemKey, Long> {
// @Query("SELECT msik.item.id, msik.key from MetaSensorItemKey msik WHERE msik.crawler.id = (:metaCrawler.id)")
List<MetaSensorItemKey> findAllByCrawler(MetaCrawler metaCrawler);
List<MetaSensorItemKey> findAllByMetaCrawlerId(Short metaCrawlerId);
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.meta.dao;
import com.loafle.overflow.model.meta.MetaInfraVendor;
import com.loafle.overflow.model.meta.MetaVendorCrawler;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -11,6 +10,6 @@ import java.util.List;
* Created by insanity on 17. 6. 23.
*/
@Repository
public interface MetaVendorCrawlerDAO extends JpaRepository<MetaVendorCrawler, Integer>{
List<MetaVendorCrawler> findAllByInfraVendor(MetaInfraVendor infraVendor);
public interface MetaVendorCrawlerDAO extends JpaRepository<MetaVendorCrawler, Integer> {
List<MetaVendorCrawler> findAllByMetaInfraVendorId(Integer metaInfraVendorId);
}

View File

@ -19,7 +19,7 @@ public class CentralMetaCrawlerInputItemService implements MetaCrawlerInputItemS
@Autowired
private MetaCrawlerInputItemDAO crawlerInputItemDAO;
public List<MetaCrawlerInputItem> readAllByMetaCrawler(MetaCrawler metaCrawler) throws OverflowException {
return this.crawlerInputItemDAO.findAllByCrawler(metaCrawler);
public List<MetaCrawlerInputItem> readAllByMetaCrawlerID(Short metaCrawlerID) throws OverflowException {
return this.crawlerInputItemDAO.findAllByMetaCrawlerId(metaCrawlerID);
}
}

View File

@ -27,7 +27,7 @@ public class CentralMetaHistoryTypeService implements MetaHistoryTypeService {
return this.hisotyTypeDAO.save(type);
}
public List<MetaHistoryType> registAll(List<MetaHistoryType> types) throws OverflowException {
return this.hisotyTypeDAO.save(types);
public List<MetaHistoryType> registAll(List<MetaHistoryType> metaHistoryTypes) throws OverflowException {
return this.hisotyTypeDAO.save(metaHistoryTypes);
}
}

View File

@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service;
import com.loafle.overflow.central.module.meta.dao.MetaInfraVendorDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.model.meta.MetaInfraVendor;
import com.loafle.overflow.service.central.meta.MetaInfraVendorService;
import org.springframework.beans.factory.annotation.Autowired;
@ -20,8 +19,8 @@ public class CentralMetaInfraVendorService implements MetaInfraVendorService {
@Autowired
private MetaInfraVendorDAO infraVendorDAO;
public List<MetaInfraVendor> readAllByMetaInfraType(MetaInfraType infraType) throws OverflowException {
return this.infraVendorDAO.findAllByInfraType(infraType);
public List<MetaInfraVendor> readAllByMetaInfraTypeID(Integer metaInfraTypeID) throws OverflowException {
return this.infraVendorDAO.findAllByMetaInfraTypeId(metaInfraTypeID);
}
}

View File

@ -19,7 +19,7 @@ public class CentralMetaProbePackageService implements MetaProbePackageService {
@Autowired
private MetaProbePackageDAO probePackageDAO;
public List<MetaProbePackage> readAllByOs(MetaProbeOs metaProbeOs) throws OverflowException {
return this.probePackageDAO.findAllByOs(metaProbeOs);
public List<MetaProbePackage> readAllByMetaProbeOsID(Short metaProbeOsID) throws OverflowException {
return this.probePackageDAO.findAllByMetaProbeOsId(metaProbeOsID);
}
}

View File

@ -26,7 +26,7 @@ public class CentralMetaSensorDisplayItemService implements MetaSensorDisplayIte
return this.displayItemDAO.findOne(id);
}
public List<MetaSensorDisplayItem> readAllByCrawler(MetaCrawler crawler) throws OverflowException {
return this.displayItemDAO.findAllByCrawler(crawler);
public List<MetaSensorDisplayItem> readAllByCrawlerID(Short metaCrawlerID) throws OverflowException {
return this.displayItemDAO.findAllByMetaCrawlerId(metaCrawlerID);
}
}

View File

@ -23,7 +23,7 @@ public class CentralMetaSensorDisplayMappingService implements MetaSensorDisplay
return this.mappingDAO.save(m);
}
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByDisplayItem(MetaSensorDisplayItem displayItem) throws OverflowException {
return this.mappingDAO.findAllMetaSensorItemKeyByDisplayItem(displayItem);
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByDisplayItemID(Long metaSensorDisplayItemID) throws OverflowException {
return this.mappingDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID);
}
}

View File

@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service;
import com.loafle.overflow.central.module.meta.dao.MetaSensorItemKeyDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.model.meta.MetaSensorItemKey;
import com.loafle.overflow.service.central.meta.MetaSensorItemKeyService;
import org.springframework.beans.factory.annotation.Autowired;
@ -22,19 +21,18 @@ public class CentralMetaSensorItemKeyService implements MetaSensorItemKeyService
@Autowired
private MetaSensorItemKeyDAO metaSensorItemKeyDAO;
public List<MetaSensorItemKey> readAllByCrawler(MetaCrawler metaCrawler) throws OverflowException {
return this.metaSensorItemKeyDAO.findAllByCrawler(metaCrawler);
public List<MetaSensorItemKey> readAllByMetaCrawlerID(Short metaCrawlerID) throws OverflowException {
return this.metaSensorItemKeyDAO.findAllByMetaCrawlerId(metaCrawlerID);
}
public Map<Integer, MetaSensorItemKey> readAllMapByCrawler(MetaCrawler metaCrawler) throws OverflowException {
public Map<Integer, MetaSensorItemKey> readAllMapByMetaCrawlerID(Short metaCrawlerID) throws OverflowException {
Map<Integer, MetaSensorItemKey> resultMap = new HashMap<>();
List<MetaSensorItemKey> resultList = this.metaSensorItemKeyDAO.findAllByCrawler(metaCrawler);
List<MetaSensorItemKey> resultList = this.metaSensorItemKeyDAO.findAllByMetaCrawlerId(metaCrawlerID);
for(MetaSensorItemKey oa : resultList) {
resultMap.put(oa.getItem().getId(), oa);
for (MetaSensorItemKey oa : resultList) {
resultMap.put(oa.getMetaSensorItem().getId(), oa);
}
return resultMap;

View File

@ -20,9 +20,9 @@ public class CentralMetaVendorCrawlerService implements MetaVendorCrawlerService
@Autowired
private MetaVendorCrawlerDAO crawlerDAO;
public List<MetaVendorCrawler> readAllByInfraVendor(MetaInfraVendor infraVendor) throws OverflowException {
public List<MetaVendorCrawler> readAllByMetaInfraVendorID(Integer metaInfraVendorID) throws OverflowException {
return this.crawlerDAO.findAllByInfraVendor(infraVendor);
return this.crawlerDAO.findAllByMetaInfraVendorId(metaInfraVendorID);
}
public MetaVendorCrawler regist(MetaVendorCrawler metaVendorCrawler) throws OverflowException {

View File

@ -3,8 +3,6 @@ package com.loafle.overflow.central.module.noauthprobe.dao;
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -17,8 +15,7 @@ public interface NoAuthProbeDAO extends JpaRepository<NoAuthProbe, Long> {
NoAuthProbe findByTempProbeKey(String tempProbeKey);
@Query("SELECT n FROM NoAuthProbe n WHERE n.domain.id = :domainID and n.status.id = 3") // 3 = Process
List<NoAuthProbe> findAllByDomainId(@Param("domainID") Long domainID);
List<NoAuthProbe> findAllByDomainIdAndMetaNoAuthProbeStatusId(Long domainID, Short metaNoAuthProbeStatusId);
// NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent);
// List<NoAuthProbeDeprecate> findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent);

View File

@ -85,7 +85,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
noAuthProbe.setDomain(apiKey.getDomain());
noAuthProbe.setTempProbeKey(GenerateKey.getKey());
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 3));
noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 3));
messagePublisher.publishToDomainMembers(apiKey.getDomain().getId(), "NoAuthProbeService.regist", noAuthProbe);
@ -94,7 +94,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
public List<NoAuthProbe> readAllByDomainID(Long domainID) throws OverflowException {
return this.noAuthProbeDAO.findAllByDomainId(domainID);
return this.noAuthProbeDAO.findAllByDomainIdAndMetaNoAuthProbeStatusId(domainID, (short) 3);
}
public NoAuthProbe read(Long id) {
@ -119,15 +119,17 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
InfraHost host = this.newInfraHost(os, noAuthProbeDescription.getNetwork());
this.newProbeHost(host, probe);
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 1));
this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", probe.getProbeKey());
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept",
probe.getProbeKey());
return this.readAllByDomainID(noAuthProbe.getDomain().getId());
}
private Probe newProbe(NoAuthProbe noauthprobe, NoAuthProbeDescription noAuthProbeDescription) throws OverflowException {
private Probe newProbe(NoAuthProbe noauthprobe, NoAuthProbeDescription noAuthProbeDescription)
throws OverflowException {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
@ -142,7 +144,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
probe.setDomain(new Domain(apiKey.getDomain().getId()));
probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
probe.setTargetCount(0);
probe.setStatus(new MetaProbeStatus((short) 1));
probe.setMetaProbeStatus(new MetaProbeStatus((short) 1));
String dispName = noAuthProbeDescription.getHost().getName();
dispName += " probe";
@ -156,31 +158,30 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
}
private InfraMachine newInfraMachine(NoAuthProbe noauthprobe) throws OverflowException {
MetaInfraType infraType = new MetaInfraType();
infraType.setId(1);
MetaInfraType metaInfraType = new MetaInfraType(1);
InfraMachine infraMachine = new InfraMachine();
infraMachine.setMeta(noauthprobe.getDescription());
infraMachine.setInfraType(infraType);
infraMachine.setMetaInfraType(metaInfraType);
return this.infraMachineService.regist(infraMachine);
}
private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost) throws OverflowException {
MetaInfraType infraType = new MetaInfraType();
infraType.setId(3);
private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost)
throws OverflowException {
MetaInfraType metaInfraType = new MetaInfraType(3);
InfraOS infraOS = new InfraOS();
infraOS.setMachine(infraMachine);
infraOS.setInfraType(infraType);
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS()));
infraOS.setInfraMachine(infraMachine);
infraOS.setMetaInfraType(metaInfraType);
infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS()));
return this.infraOSService.regist(infraOS);
}
private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork) throws OverflowException {
MetaInfraType infraType = new MetaInfraType();
infraType.setId(2);
private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork)
throws OverflowException {
MetaInfraType metaInfraType = new MetaInfraType(2);
InfraHost infraHost = new InfraHost();
String addrStr = noAuthProbeDescriptionNetwork.getAddress();
@ -188,8 +189,8 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
infraHost.setIpv4(addrArr[0]);
infraHost.setMac(noAuthProbeDescriptionNetwork.getMacAddress());
infraHost.setOs(infraOS);
infraHost.setInfraType(infraType);
infraHost.setInfraOS(infraOS);
infraHost.setMetaInfraType(metaInfraType);
return this.infraHostService.regist(infraHost);
}
@ -206,7 +207,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
public List<NoAuthProbe> denyNoauthProbe(Long noAuthProbeID) throws OverflowException {
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2));
noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 2));
this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Deny");
@ -224,7 +225,8 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
noAuthProbe.setConnectAddress(connectAddress);
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect", noAuthProbe);
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect",
noAuthProbe);
}
public void onDisconnect(String tempKey) throws OverflowException {
@ -233,7 +235,8 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
noAuthProbe.setConnectAddress(null);
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect", noAuthProbe);
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect",
noAuthProbe);
}
}

View File

@ -1,13 +1,10 @@
package com.loafle.overflow.central.module.notification.dao;
import com.loafle.overflow.model.member.Member;
import com.loafle.overflow.model.notification.Notification;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -16,15 +13,13 @@ import java.util.List;
* Created by insanity on 17. 8. 25.
*/
@Repository
public interface NotificationDAO extends JpaRepository<Notification, Long> {
public interface NotificationDAO extends JpaRepository<Notification, Long> {
List<Notification> findAllByMember(Member member);
List<Notification> findAllByMemberEmail(String memberEmail);
Page<Notification> findAllByMember(Member member, Pageable pageRequest);
Page<Notification> findAllByMemberEmail(String memberEmail, Pageable pageRequest);
@Query("SELECT n FROM Notification n WHERE n.member.id = :#{#member.id} and n.confirmDate IS NULL")
Page<Notification> findAllUnconfirmedByMember(@Param("member") Member member, Pageable pageRequest);
Page<Notification> findAllByMemberEmailAndConfirmDateNull(String memberEmail, Pageable pageRequest);
@Query("SELECT COUNT(n) FROM Notification n WHERE n.member.id = :#{#member.id} and n.confirmDate IS NULL")
int findAllUnconfirmedCountByMember(@Param("member") Member member);
Long countByMemberEmailAndConfirmDateNull(String memberEmail);
}

View File

@ -28,37 +28,42 @@ public class CentralNotificationService implements NotificationService {
return this.notificationDAO.save(notification);
}
public Page<Notification> readAllByMember(Member member, PageParams pageParams) throws OverflowException {
return this.notificationDAO.findAllByMember(member, PageUtil.getPageRequest(pageParams));
public Page<Notification> readAllByMemberEmail(String memberEmail, PageParams pageParams) throws OverflowException {
return this.notificationDAO.findAllByMemberEmail(memberEmail, PageUtil.getPageRequest(pageParams));
}
public Page<Notification> readAllUnconfirmedByMember(Member member, PageParams pageParams) throws OverflowException {
return this.notificationDAO.findAllUnconfirmedByMember(member, PageUtil.getPageRequest(pageParams));
public Page<Notification> readAllUnconfirmedByMemberEmail(String memberEmail, PageParams pageParams)
throws OverflowException {
return this.notificationDAO.findAllByMemberEmailAndConfirmDateNull(memberEmail,
PageUtil.getPageRequest(pageParams));
}
public int readUnconfirmedCount(Member member) throws OverflowException {
return this.notificationDAO.findAllUnconfirmedCountByMember(member);
public Long readUnconfirmedCountByMemberEmail(String memberEmail) throws OverflowException {
return this.notificationDAO.countByMemberEmailAndConfirmDateNull(memberEmail);
}
public Page<Notification> markAllAsRead(Member member, PageParams pageParams) throws OverflowException {
List<Notification> list = this.notificationDAO.findAllByMember(member);
public Page<Notification> markAllAsReadByMemberEmail(String memberEmail, PageParams pageParams)
throws OverflowException {
List<Notification> list = this.notificationDAO.findAllByMemberEmail(memberEmail);
for (Notification n : list) {
n.setConfirmDate(new Date());
}
this.notificationDAO.save(list);
return this.readAllByMember(member, pageParams);
return this.readAllByMemberEmail(memberEmail, pageParams);
}
public Page<Notification> markAllAsUnread(Member member, PageParams pageParams) throws OverflowException {
List<Notification> list = this.notificationDAO.findAllByMember(member);
public Page<Notification> markAllAsUnreadMemberEmail(String memberEmail, PageParams pageParams)
throws OverflowException {
List<Notification> list = this.notificationDAO.findAllByMemberEmail(memberEmail);
for (Notification n : list) {
n.setConfirmDate(null);
}
this.notificationDAO.save(list);
return this.readAllByMember(member, pageParams);
return this.readAllByMemberEmail(memberEmail, pageParams);
}
public Notification markAsRead(Notification notification) throws OverflowException {
public Notification markAsRead(Long notificationID) throws OverflowException {
Notification notification = this.notificationDAO.findOne(notificationID);
notification.setConfirmDate(new Date());
return this.notificationDAO.save(notification);
}

View File

@ -5,11 +5,8 @@ import java.util.List;
import com.loafle.overflow.model.probe.ProbeHost;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* Created by snoop on 17. 8. 21.
*/
@ -17,6 +14,5 @@ import org.springframework.stereotype.Repository;
public interface ProbeHostDAO extends JpaRepository<ProbeHost, Long> {
ProbeHost findByProbeId(Long probeID);
@Query("SELECT h FROM ProbeHost h WHERE h.probe.domain.id = (:domainID)")
List<ProbeHost> findAllByDomainId(@Param("domainID")Long domainID);
List<ProbeHost> findAllByProbeDomainId(Long domainID);
}

View File

@ -12,5 +12,5 @@ import com.loafle.overflow.model.probe.ProbeTask;
*/
@Repository
public interface ProbeTaskDAO extends JpaRepository<ProbeTask, Long> {
List<ProbeTask> findAllByProbeId(Long probeID);
List<ProbeTask> findAllByProbeId(Long probeId);
}

View File

@ -4,8 +4,6 @@ import java.util.List;
import com.loafle.overflow.central.module.probe.dao.ProbeHostDAO;
import com.loafle.overflow.core.exception.OverflowException;
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.service.central.probe.ProbeHostService;
@ -32,9 +30,8 @@ public class CentralProbeHostService implements ProbeHostService {
public ProbeHost regist(ProbeHost probeHost) throws OverflowException {
return this.probeHostDAO.save(probeHost);
}
public List<ProbeHost> readAllByDomainID(Long domainID) throws OverflowException {
return this.probeHostDAO.findAllByDomainId(domainID);
return this.probeHostDAO.findAllByProbeDomainId(domainID);
}
}

View File

@ -3,7 +3,6 @@ package com.loafle.overflow.central.module.probe.service;
import com.loafle.overflow.central.commons.service.MessagePublisher;
import com.loafle.overflow.central.module.probe.dao.ProbeDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.service.central.probe.ProbeService;

View File

@ -2,7 +2,6 @@ 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.Probe;
import com.loafle.overflow.model.probe.ProbeTask;
import com.loafle.overflow.service.central.probe.ProbeTaskService;

View File

@ -1,11 +1,8 @@
package com.loafle.overflow.central.module.sensor.dao;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -19,8 +16,8 @@ import com.loafle.overflow.model.target.Target;
@Repository
public interface SensorDAO extends JpaRepository<Sensor, Long> {
Page<Sensor> findAllByTargetId(Long targetID, Pageable pageable);
List<Sensor> findAllByTargetId(Long targetID);
@Query("SELECT s from Sensor s WHERE s.target in (:targetList)")
Page<Sensor> findAllByTargetList(@Param("targetList") List<Target> targetList, Pageable pageable);
Page<Sensor> findAllByTargetIn(List<Target> targets, Pageable pageable);
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.sensor.dao;
import com.loafle.overflow.model.sensor.Sensor;
import com.loafle.overflow.model.sensor.SensorItem;
import org.springframework.data.domain.Page;
@ -13,5 +12,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface SensorItemDAO extends JpaRepository<SensorItem, Long> {
Page<SensorItem> findAllBySensor(Sensor sensor, Pageable pageable);
Page<SensorItem> findAllBySensorId(Long sensorId, Pageable pageable);
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.sensor.dao;
import com.loafle.overflow.model.meta.MetaSensorDisplayItem;
import com.loafle.overflow.model.meta.MetaSensorItemKey;
import com.loafle.overflow.model.sensor.SensorItemDependency;
@ -15,5 +14,5 @@ import java.util.List;
@Repository
public interface SensorItemDependencyDAO extends JpaRepository<SensorItemDependency, Long> {
List<MetaSensorItemKey> findAllByDisplayItem(MetaSensorDisplayItem displayItem);
List<MetaSensorItemKey> findAllByMetaSensorDisplayItemId(Long metaSensorDisplayItemId);
}

View File

@ -28,17 +28,19 @@ public class CentralSensorItemDependencyService implements SensorItemDependencyS
return this.sensorItemDependencyDAO.save(dependency);
}
public List<MetaSensorItemKey> readAllByDisplayItem(MetaSensorDisplayItem displayItem) throws OverflowException {
return this.sensorItemDependencyDAO.findAllByDisplayItem(displayItem);
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByMetaSensorDisplayItemID(Long metaSensorDisplayItemID)
throws OverflowException {
return this.sensorItemDependencyDAO.findAllByMetaSensorDisplayItemId(metaSensorDisplayItemID);
}
public Map<String, List<MetaSensorItemKey>> readAllByDisplayItems(
List<MetaSensorDisplayItem> displayItems) throws OverflowException {
public Map<String, List<MetaSensorItemKey>> readAllMapByMetaSensorDisplayItems(
List<MetaSensorDisplayItem> metaSensorDisplayItems) throws OverflowException {
Map<String, List<MetaSensorItemKey>> map = new HashMap<String, List<MetaSensorItemKey>>();
for (MetaSensorDisplayItem displayItem : displayItems) {
List<MetaSensorItemKey> itemKeys = this.sensorItemDependencyDAO.findAllByDisplayItem(displayItem);
for (MetaSensorDisplayItem displayItem : metaSensorDisplayItems) {
List<MetaSensorItemKey> itemKeys = this.sensorItemDependencyDAO
.findAllByMetaSensorDisplayItemId(displayItem.getId());
map.put(displayItem.getKey(), itemKeys);
}

View File

@ -30,7 +30,7 @@ public class CentralSensorItemService implements SensorItemService {
@Transactional
public SensorItem regist(SensorItem sensorItem) throws OverflowException {
Sensor s = sensorDAO.findOne(sensorItem.getSensor().getId());
s.setItemCount((short)(s.getItemCount() + 1));
s.setItemCount((short) (s.getItemCount() + 1));
this.sensorDAO.save(s);
return this.sensorItemDAO.save(sensorItem);
}
@ -38,7 +38,7 @@ public class CentralSensorItemService implements SensorItemService {
@Transactional
public boolean registAll(List<SensorItem> sensorItemList) throws OverflowException {
Sensor s = sensorDAO.findOne(sensorItemList.get(0).getSensor().getId());
s.setItemCount((short)sensorItemList.size());
s.setItemCount((short) sensorItemList.size());
this.sensorDAO.save(s);
this.sensorItemDAO.save(sensorItemList);
return true;
@ -48,14 +48,14 @@ public class CentralSensorItemService implements SensorItemService {
return this.sensorItemDAO.findOne(Long.valueOf(id));
}
public Page<SensorItem> readAllBySensor(Sensor sensor, PageParams pageParams) throws OverflowException {
return this.sensorItemDAO.findAllBySensor(sensor, PageUtil.getPageRequest(pageParams));
public Page<SensorItem> readAllBySensorID(Long sensorID, PageParams pageParams) throws OverflowException {
return this.sensorItemDAO.findAllBySensorId(sensorID, PageUtil.getPageRequest(pageParams));
}
@Transactional
public void remove(SensorItem sensorItem) throws OverflowException {
Sensor s = sensorItem.getSensor();
s.setItemCount((short)(s.getItemCount() - 1));
s.setItemCount((short) (s.getItemCount() - 1));
this.sensorDAO.save(s);
this.sensorItemDAO.delete(sensorItem);
}

View File

@ -63,13 +63,13 @@ public class CentralSensorService implements SensorService {
throw new OverflowException("", new Throwable());
}
List<Target> targetList = this.infraService.readAllTargetByProbeList(probeList);
List<Target> targetList = this.infraService.readAllTargetByProbes(probeList);
if (targetList == null || targetList.size() <= 0) {
throw new OverflowException("", new Throwable());
}
return this.sensorDAO.findAllByTargetList(targetList, PageUtil.getPageRequest(pageParams));
return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams));
}
public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
@ -100,14 +100,14 @@ public class CentralSensorService implements SensorService {
public Sensor start(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findOne(sensorID);
MetaSensorStatus status = new MetaSensorStatus((short) 1);
sensor.setStatus(status);
sensor.setMetaSensorStatus(status);
return this.sensorDAO.save(sensor);
}
public Sensor stop(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findOne(sensorID);
MetaSensorStatus status = new MetaSensorStatus((short) 2);
sensor.setStatus(status);
sensor.setMetaSensorStatus(status);
return this.sensorDAO.save(sensor);
}

View File

@ -22,7 +22,7 @@ import java.util.List;
* Created by snoop on 17. 6. 28.
*/
@Service("TargetDiscoveryService")
public class CentralTargetDiscoveryService implements TargetDiscoveryService{
public class CentralTargetDiscoveryService implements TargetDiscoveryService {
@Autowired
private TargetService targetService;
@ -50,7 +50,7 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{
InfraHost infraHost = null;
for(Host host : hosts) {
for (Host host : hosts) {
infraHost = this.createAndReadHost(host, probe);
@ -62,29 +62,29 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{
private void createService(InfraHost infraHost, Port port, Probe probe) throws OverflowException {
MetaInfraType typeService = new MetaInfraType();
typeService.setId(7);
MetaInfraType typeService = new MetaInfraType(7);
String portType = "UDP";
if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) {
if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) {
portType = "TCP";
}
if(port.getServiceList() == null) {
if (port.getServiceList() == null) {
return;
}
// for(String key : port.getServices().keySet()) {
for(com.loafle.overflow.model.discovery.Service service : port.getServiceList()) {
// 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);
// com.loafle.overflow.module.discovery.model.Service service =
// port.getServices().get(key);
InfraService dbInfraService = this.infraServiceService.readByService(infraHost.getId(), port.getPortNumber(), portType);
InfraService dbInfraService = this.infraServiceService
.readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), portType);
if(dbInfraService != null) {
if(service.isTarget() && dbInfraService.getTarget() == null) {
if (dbInfraService != null) {
if (service.isTarget() && dbInfraService.getTarget() == null) {
Target targetService = new Target();
targetService.setDisplayName(service.getServiceName());
this.targetService.regist(targetService, probe);
@ -95,18 +95,18 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{
}
InfraService infraService = new InfraService();
infraService.setHost(infraHost);
infraService.setInfraHost(infraHost);
infraService.setPort(port.getPortNumber());
infraService.setPortType(portType);
infraService.setInfraType(typeService);
infraService.setMetaInfraType(typeService);
infraService.setProbe(probe);
if (port.getPortType() == PortType.TLS) {
infraService.setTlsType(true);
}
infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
if(service.isTarget()) {
if (service.isTarget()) {
Target targetService = new Target();
targetService.setDisplayName(service.getServiceName());
this.targetService.regist(targetService, probe);
@ -121,43 +121,43 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{
private void createPort(InfraHost infraHost, Host host, Probe probe) throws OverflowException {
// if(host.getPorts() == null) {
// return;
// }
// if(host.getPorts() == null) {
// return;
// }
String portType = "UDP";
MetaInfraType typePort = new MetaInfraType();
typePort.setId(6);
MetaInfraType typePort = new MetaInfraType(6);
InfraOS infraOS = infraHost.getOs();
InfraOS infraOS = infraHost.getInfraOS();
// for( String key: host.getPorts().keySet()) {
// for( String key: host.getPorts().keySet()) {
if(host.getPortList() == null) {
if (host.getPortList() == null) {
return;
}
for( Port port: host.getPortList()) {
// Port port = host.getPorts().get(key);
for (Port port : host.getPortList()) {
// Port port = host.getPorts().get(key);
if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
portType = "TCP";
}
InfraOSPort dbInfraOSPort = this.infraOSPortService.readByPort(infraOS.getId(), port.getPortNumber(), portType);
if(dbInfraOSPort == null) {
InfraOSPort dbInfraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), port.getPortNumber(),
portType);
if (dbInfraOSPort == null) {
InfraOSPort infraOSPort = new InfraOSPort();
infraOSPort.setOs(infraOS);
infraOSPort.setInfraOS(infraOS);
infraOSPort.setPort(port.getPortNumber());
infraOSPort.setPortType(portType);
infraOSPort.setProbe(probe);
infraOSPort.setInfraType(typePort);
infraOSPort.setMetaInfraType(typePort);
if (port.getPortType() == PortType.TLS) {
infraOSPort.setTlsType(true);
}
infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
this.infraOSPortService.regist(infraOSPort);
}
@ -167,11 +167,10 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{
private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException {
InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4());
if(infraHost != null) {
if (infraHost != null) {
if(host.isTarget() && infraHost.getTarget() == null) {
if (host.isTarget() && infraHost.getTarget() == null) {
Target target = new Target();
target.setDisplayName(host.getIpv4() + "-Host");
@ -182,38 +181,34 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{
return infraHost;
} else {
MetaInfraType typeMachine = new MetaInfraType();
typeMachine.setId(1); // 1 = Machine;
MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine;
MetaInfraType typeOS = new MetaInfraType();
typeOS.setId(3); // 3 = Os
MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os
MetaInfraType typeHost = new MetaInfraType();
typeHost.setId(2); // 2 = Host
MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host
InfraMachine infraMachine = new InfraMachine();
infraMachine.setProbe(probe);
infraMachine.setInfraType(typeMachine);
infraMachine.setMeta(host.getIpv4()+"-MACHINE");
infraMachine.setMetaInfraType(typeMachine);
infraMachine.setMeta(host.getIpv4() + "-MACHINE");
this.infraMachineService.regist(infraMachine);
InfraOS infraOS = new InfraOS();
infraOS.setMachine(infraMachine);
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
infraOS.setInfraType(typeOS);
infraOS.setInfraMachine(infraMachine);
infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
infraOS.setMetaInfraType(typeOS);
infraOS.setProbe(probe);
infraOS.setMeta(host.getIpv4()+"-OS");
infraOS.setMeta(host.getIpv4() + "-OS");
this.infraOSService.regist(infraOS);
InfraHost newInfraHost = new InfraHost();
newInfraHost.setIpv4(host.getIpv4());
newInfraHost.setMac(host.getMac());
newInfraHost.setOs(infraOS);
newInfraHost.setInfraType(typeHost);
newInfraHost.setInfraOS(infraOS);
newInfraHost.setMetaInfraType(typeHost);
newInfraHost.setProbe(probe);
if(host.isTarget()) {
if (host.isTarget()) {
Target target = new Target();
target.setDisplayName(host.getIpv4() + "-Host");
@ -225,10 +220,7 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{
infraHost = newInfraHost;
}
return infraHost;
}
}

View File

@ -7,8 +7,6 @@ import com.loafle.overflow.central.module.probe.service.CentralProbeService;
import com.loafle.overflow.central.module.target.dao.TargetDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.discovery.Host;
import com.loafle.overflow.model.infra.InfraHost;
import com.loafle.overflow.model.meta.MetaInfraType;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.model.target.Target;
import com.loafle.overflow.service.central.target.TargetService;
@ -76,24 +74,19 @@ public class CentralTargetService implements TargetService {
}
@Transactional
public void registDiscoveredTargets(Long probeId, List<Host> hosts, List<Service> services) {
public List<Target> registDiscoveredTargets(Long probeId, List<Host> hosts,
List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
/*
해당 host의 mac에 해당하는 infraHost가 이미 존재하는지 검사
infraHost가 없다면 create
infraHost가 있다면 update
infraHost.getTarget() 있어도 무조건 새로운 target으로 연결
for(Host host : hosts) {
Target target = new Target();
MetaInfraType infraType = new MetaInfraType();
infraType.setId(2);
InfraHost infraHost = new InfraHost();
infraHost.setInfraType(infraType);
infraHost.setProbe(new Probe(probeId));
infraHost.setTarget(target);
}
*/
* 해당 host의 mac에 해당하는 infraHost가 이미 존재하는지 검사 infraHost가 없다면 create infraHost가
* 있다면 update infraHost.getTarget() 있어도 무조건 새로운 target으로 연결
*
*
* for(Host host : hosts) { Target target = new Target();
*
* MetaInfraType infraType = new MetaInfraType(); infraType.setId(2); InfraHost
* infraHost = new InfraHost(); infraHost.setInfraType(infraType);
* infraHost.setProbe(new Probe(probeId)); infraHost.setTarget(target); }
*/
return null;
}
}