This commit is contained in:
crusader 2018-06-07 15:02:38 +09:00
parent c3ca0ea93b
commit 07e9f73e48
100 changed files with 1889 additions and 1881 deletions

13
.editorconfig Normal file
View File

@ -0,0 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false

View File

@ -1,3 +1,6 @@
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"java.configuration.updateBuildConfiguration": "automatic"
}

View File

@ -5,17 +5,17 @@ import com.loafle.overflow.central.proxy.ServiceProxy;
import java.io.IOException;
public class Central {
public static void main(String[] args) throws IOException, InterruptedException {
if(args.length <= 0) {
System.out.println("Port args");
System.out.println("first parameter is Port Number");
return;
}
int port = Integer.valueOf(args[0]);
final ServiceProxy server = new ServiceProxy();
server.start(port);
server.blockUntilShutdown();
public static void main(String[] args) throws IOException, InterruptedException {
if (args.length <= 0) {
System.out.println("Port args");
System.out.println("first parameter is Port Number");
return;
}
int port = Integer.valueOf(args[0]);
final ServiceProxy server = new ServiceProxy();
server.start(port);
server.blockUntilShutdown();
}
}

View File

@ -3,19 +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 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;
void publishToMemberSession(final String memberSessionID, 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 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;
void publishToProbe(final String probeKey, final String method, final Object... params) throws OverflowException;
}

View File

@ -29,106 +29,106 @@ import java.util.Map;
@Service("EmailSender")
public class EmailSender {
@Autowired
private JavaMailSender mailSender;
@Autowired
private JavaMailSender mailSender;
@Autowired
private VelocityEngine velocityEngine;
@Autowired
private VelocityEngine velocityEngine;
private String key = "loafle@RandomKey";
private String initVector = "loafleInitVector";
private String key = "loafle@RandomKey";
private String initVector = "loafleInitVector";
public void sendSimpleEmail(final Mail mail) throws MailException {
public void sendSimpleEmail(final Mail mail) throws MailException {
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
helper.setTo(mail.getMailTo());
helper.setFrom("geek@loafle.com");
helper.setSubject(mail.getMailSubject());
helper.setText(getContentFromTemplate(mail.getModel(), mail), true);
helper.addInline("company-logo", new ClassPathResource("/vmtemplates/overFlow_logo.png"));
};
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
helper.setTo(mail.getMailTo());
helper.setFrom("geek@loafle.com");
helper.setSubject(mail.getMailSubject());
helper.setText(getContentFromTemplate(mail.getModel(), mail), true);
helper.addInline("company-logo", new ClassPathResource("/vmtemplates/overFlow_logo.png"));
};
this.mailSender.send(preparator);
this.mailSender.send(preparator);
}
public void sendMailWithAttachment(Mail mail) throws MessagingException {
MimeMessage message = mailSender.createMimeMessage();
// pass 'true' to the constructor to create a multipart message
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setTo(mail.getMailTo());
helper.setSubject(mail.getMailSubject());
helper.setText(mail.getMailContent());
helper.setFrom("geek@loafle.com");
// FileSystemResource file = new FileSystemResource(new
// File(mail.getAttachments()));
// helper.addAttachment("Invoice", file);
mailSender.send(message);
}
public String encrypt(String value) {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
byte[] encrypted = cipher.doFinal(value.getBytes());
System.out.println("encrypted string: " + Base64.encodeBase64String(encrypted));
return Base64.encodeBase64String(encrypted);
} catch (Exception ex) {
ex.printStackTrace();
}
public void sendMailWithAttachment(Mail mail) throws MessagingException {
MimeMessage message = mailSender.createMimeMessage();
// pass 'true' to the constructor to create a multipart message
MimeMessageHelper helper = new MimeMessageHelper(message, true);
return null;
}
helper.setTo(mail.getMailTo());
helper.setSubject(mail.getMailSubject());
helper.setText(mail.getMailContent());
helper.setFrom("geek@loafle.com");
// FileSystemResource file = new FileSystemResource(new
// File(mail.getAttachments()));
// helper.addAttachment("Invoice", file);
public String decrypt(String encrypted) {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
mailSender.send(message);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
return new String(original);
} catch (Exception ex) {
ex.printStackTrace();
}
public String encrypt(String value) {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
return null;
}
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
private String getContentFromTemplate(Map<String, Object> model, Mail mail) {
StringWriter writer = new StringWriter();
VelocityContext context = new VelocityContext();
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
Template template = this.velocityEngine.getTemplate(mail.getTemplateLoacation(), "UTF-8");
byte[] encrypted = cipher.doFinal(value.getBytes());
System.out.println("encrypted string: " + Base64.encodeBase64String(encrypted));
model.forEach((key, value) -> {
context.put(key, value);
});
return Base64.encodeBase64String(encrypted);
} catch (Exception ex) {
ex.printStackTrace();
}
template.merge(context, writer);
return null;
}
// try {
public String decrypt(String encrypted) {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
return new String(original);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
private String getContentFromTemplate(Map<String, Object> model, Mail mail) {
StringWriter writer = new StringWriter();
VelocityContext context = new VelocityContext();
Template template = this.velocityEngine.getTemplate(mail.getTemplateLoacation(), "UTF-8");
model.forEach((key, value) -> {
context.put(key, value);
});
template.merge(context, writer);
// try {
// template.merge(this.velocityEngine, content);
// // content.append(VelocityEngineUtils.mergeTemplateIntoString
// // (velocityEngine,
// // mail.getTemplateLoacation(), "UTF-8", model));
// } catch (Exception e) {
// e.printStackTrace();
// }
return writer.toString();
}
// template.merge(this.velocityEngine, content);
// // content.append(VelocityEngineUtils.mergeTemplateIntoString
// // (velocityEngine,
// // mail.getTemplateLoacation(), "UTF-8", model));
// } catch (Exception e) {
// e.printStackTrace();
// }
return writer.toString();
}
}

View File

@ -8,18 +8,18 @@ import com.fasterxml.uuid.impl.TimeBasedGenerator;
* Created by geek on 18. 3. 27.
*/
public class GenerateKey {
private static TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
private static TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
public static synchronized String getKey() {
public static synchronized String getKey() {
String[] uuids = generator.generate().toString().split("-");
StringBuffer sb = new StringBuffer();
String[] uuids = generator.generate().toString().split("-");
StringBuffer sb = new StringBuffer();
for ( int idx = 0; idx < uuids.length; idx++ ) {
sb.append(uuids[idx]);
}
return sb.toString();
for (int idx = 0; idx < uuids.length; idx++) {
sb.append(uuids[idx]);
}
return sb.toString();
}
}

View File

@ -9,18 +9,20 @@ import org.springframework.data.domain.Sort;
* Created by insanity on 17. 8. 25.
*/
public class PageUtil {
private static Sort.Direction getSortDirection(String sortDirection) {
if(sortDirection.equalsIgnoreCase("ascending")) {
return Sort.Direction.ASC;
}
return Sort.Direction.DESC;
private static Sort.Direction getSortDirection(String sortDirection) {
if (sortDirection.equalsIgnoreCase("ascending")) {
return Sort.Direction.ASC;
}
return Sort.Direction.DESC;
}
public static PageRequest getPageRequest(PageParams pageParams) {
if(pageParams.getSortCol().isEmpty()) pageParams.setSortCol("id");
if(pageParams.getSortDirection().isEmpty()) pageParams.setSortDirection("descending");
public static PageRequest getPageRequest(PageParams pageParams) {
if (pageParams.getSortCol().isEmpty())
pageParams.setSortCol("id");
if (pageParams.getSortDirection().isEmpty())
pageParams.setSortDirection("descending");
return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(),
new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol()));
}
return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(),
new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol()));
}
}

View File

@ -6,46 +6,49 @@ import io.grpc.Metadata;
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
public class SessionMetadata {
/*
digits: 0-9
uppercase letters: A-Z (normalized to lower)
lowercase letters: a-z
special characters: -_.
*/
/*
* digits: 0-9 uppercase letters: A-Z (normalized to lower) lowercase letters:
* a-z special characters: -_.
*/
public static final String CLIENT_TYPE_KEY = "OVERFLOW_GRPC_CLIENT_TYPE";
public static final String SESSION_ID_KEY = "OVERFLOW_GRPC_SESSION_ID";
public static final String TARGET_ID_KEY = "OVERFLOW_GRPC_TARGET_ID";
public static final String CLIENT_TYPE_KEY = "OVERFLOW_GRPC_CLIENT_TYPE";
public static final String SESSION_ID_KEY = "OVERFLOW_GRPC_SESSION_ID";
public static final String TARGET_ID_KEY = "OVERFLOW_GRPC_TARGET_ID";
public static final Context.Key<String> CTX_CLIENT_TYPE_KEY = Context.key(CLIENT_TYPE_KEY);
public static final Context.Key<String> CTX_SESSION_ID_KEY = Context.key(SESSION_ID_KEY);
public static final Context.Key<String> CTX_TARGET_ID_KEY = Context.key(TARGET_ID_KEY);
public static final Context.Key<String> CTX_CLIENT_TYPE_KEY = Context.key(CLIENT_TYPE_KEY);
public static final Context.Key<String> CTX_SESSION_ID_KEY = Context.key(SESSION_ID_KEY);
public static final Context.Key<String> CTX_TARGET_ID_KEY = Context.key(TARGET_ID_KEY);
public static final Metadata.Key<String> METADATA_CLIENT_TYPE_KEY = Metadata.Key.of(CLIENT_TYPE_KEY, ASCII_STRING_MARSHALLER);
public static final Metadata.Key<String> METADATA_SESSION_ID_KEY = Metadata.Key.of(SESSION_ID_KEY, ASCII_STRING_MARSHALLER);
public static final Metadata.Key<String> METADATA_TARGET_ID_KEY = Metadata.Key.of(TARGET_ID_KEY, ASCII_STRING_MARSHALLER);
public static final Metadata.Key<String> METADATA_CLIENT_TYPE_KEY = Metadata.Key.of(CLIENT_TYPE_KEY,
ASCII_STRING_MARSHALLER);
public static final Metadata.Key<String> METADATA_SESSION_ID_KEY = Metadata.Key.of(SESSION_ID_KEY,
ASCII_STRING_MARSHALLER);
public static final Metadata.Key<String> METADATA_TARGET_ID_KEY = Metadata.Key.of(TARGET_ID_KEY,
ASCII_STRING_MARSHALLER);
public static ClientType getClientType() {
return ClientType.valueOf(CTX_CLIENT_TYPE_KEY.get());
}
public static String getSessionID() {
return CTX_SESSION_ID_KEY.get();
}
public static String getTargetID() {
return CTX_TARGET_ID_KEY.get();
public static ClientType getClientType() {
return ClientType.valueOf(CTX_CLIENT_TYPE_KEY.get());
}
public static String getSessionID() {
return CTX_SESSION_ID_KEY.get();
}
public static String getTargetID() {
return CTX_TARGET_ID_KEY.get();
}
public static enum ClientType {
MEMBER("MEMBER"), PROBE("PROBE");
final private String name;
private ClientType(String name) {
this.name = name;
}
public static enum ClientType {
MEMBER("MEMBER"),
PROBE("PROBE");
final private String name;
private ClientType(String name) {
this.name = name;
}
public String toString() {
return name;
}
public String toString() {
return name;
}
}
}

View File

@ -5,57 +5,51 @@ package com.loafle.overflow.central.commons.utils;
*/
public class StringConvertor {
public static String intToIp(long i) {
return ((i >> 24 ) & 0xFF) + "." +
((i >> 16 ) & 0xFF) + "." +
((i >> 8 ) & 0xFF) + "." +
( i & 0xFF);
public static String intToIp(long i) {
return ((i >> 24) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + (i & 0xFF);
}
public static long ipToLong(String ipAddress) {
String[] ipAddressInArray = ipAddress.split("\\.");
long result = 0;
for (int i = 0; i < ipAddressInArray.length; i++) {
int power = 3 - i;
int ip = Integer.parseInt(ipAddressInArray[i]);
result += ip * Math.pow(256, power);
}
return result;
}
public static long ipToLong(String ipAddress) {
// https://github.com/Sovietaced/floodlight/blob/master/src/main/java/net/floodlightcontroller/util/MACAddress.java
String[] ipAddressInArray = ipAddress.split("\\.");
public static final int MAC_ADDRESS_LENGTH = 6;
long result = 0;
for (int i = 0; i < ipAddressInArray.length; i++) {
int power = 3 - i;
int ip = Integer.parseInt(ipAddressInArray[i]);
result += ip * Math.pow(256, power);
}
return result;
public static long macStrToLong(String address) {
String[] elements = address.split(":");
if (elements.length != MAC_ADDRESS_LENGTH) {
throw new IllegalArgumentException(
"Specified MAC Address must contain 12 hex digits" + " separated pairwise by :'s.");
}
// https://github.com/Sovietaced/floodlight/blob/master/src/main/java/net/floodlightcontroller/util/MACAddress.java
public static final int MAC_ADDRESS_LENGTH = 6;
public static long macStrToLong(String address) {
String[] elements = address.split(":");
if (elements.length != MAC_ADDRESS_LENGTH) {
throw new IllegalArgumentException(
"Specified MAC Address must contain 12 hex digits" +
" separated pairwise by :'s.");
}
byte[] addressInBytes = new byte[MAC_ADDRESS_LENGTH];
for (int i = 0; i < MAC_ADDRESS_LENGTH; i++) {
String element = elements[i];
addressInBytes[i] = (byte)Integer.parseInt(element, 16);
}
long mac = 0;
for (int i = 0; i < 6; i++) {
long t = (addressInBytes[i] & 0xffL) << ((5 - i) * 8);
mac |= t;
}
return mac;
// return new MACAddress(addressInBytes);
byte[] addressInBytes = new byte[MAC_ADDRESS_LENGTH];
for (int i = 0; i < MAC_ADDRESS_LENGTH; i++) {
String element = elements[i];
addressInBytes[i] = (byte) Integer.parseInt(element, 16);
}
long mac = 0;
for (int i = 0; i < 6; i++) {
long t = (addressInBytes[i] & 0xffL) << ((5 - i) * 8);
mac |= t;
}
return mac;
// return new MACAddress(addressInBytes);
}
}

View File

@ -1,19 +1,16 @@
package com.loafle.overflow.central.module.apikey.dao;
import com.loafle.overflow.model.apikey.ApiKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Created by root on 17. 6. 1.
*/
@Repository
public interface ApiKeyDAO extends JpaRepository<ApiKey, Long> {
ApiKey findByApiKey(String apiKey);
ApiKey findByApiKey(String apiKey);
ApiKey findByDomainId(Long domainID);
ApiKey findByDomainId(Long domainID);
}

View File

@ -1,9 +1,7 @@
package com.loafle.overflow.central.module.apikey.service;
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.service.central.apikey.ApiKeyService;
@ -16,33 +14,31 @@ import org.springframework.stereotype.Service;
@Service("ApiKeyService")
public class CentralApiKeyService implements ApiKeyService {
@Autowired
private ApiKeyDAO apiKeyDAO;
@Autowired
private ApiKeyDAO apiKeyDAO;
public ApiKey regist(ApiKey apiKey) throws OverflowException {
return this.apiKeyDAO.save(apiKey);
}
public ApiKey regist(ApiKey apiKey) throws OverflowException {
public ApiKey readByDomainID(Long domainID) throws OverflowException {
return this.apiKeyDAO.findByDomainId(domainID);
}
return this.apiKeyDAO.save(apiKey);
public boolean check(String apiKey) throws OverflowException {
ApiKey retApiKey = this.apiKeyDAO.findByApiKey(apiKey);
if (retApiKey == null) {
return false;
}
public ApiKey readByDomainID(Long domainID) throws OverflowException {
return this.apiKeyDAO.findByDomainId(domainID);
}
return true;
}
public boolean check(String apiKey) throws OverflowException {
ApiKey retApiKey = this.apiKeyDAO.findByApiKey(apiKey);
if(retApiKey == null) {
return false;
}
return true;
}
public ApiKey readByApiKey(String apiKey) throws OverflowException{
return this.apiKeyDAO.findByApiKey(apiKey);
}
public ApiKey readByApiKey(String apiKey) throws OverflowException {
return this.apiKeyDAO.findByApiKey(apiKey);
}
}

View File

@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface AuthCrawlerDAO extends JpaRepository<AuthCrawler, Long> {
AuthCrawler findByMetaCrawlerIdAndTargetId(Short metaCrawlerId, Long targetId);
AuthCrawler findByMetaCrawlerIdAndTargetId(Short metaCrawlerId, Long targetId);
}

View File

@ -25,7 +25,7 @@ public class CentralAuthCrawlerService implements AuthCrawlerService {
public AuthCrawler regist(AuthCrawler authCrawler) {
// if (authCrawler == null) {
// return this.authCrawlerDAO.save(authCrawler);
// return this.authCrawlerDAO.save(authCrawler);
// }
AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(authCrawler.getMetaCrawler().getId(),

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.domain.dao;
import com.loafle.overflow.model.domain.Domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -9,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by root on 17. 6. 23.
*/
@Repository
public interface DomainDAO extends JpaRepository<Domain, Long> {
public interface DomainDAO extends JpaRepository<Domain, Long> {
}

View File

@ -11,8 +11,8 @@ import java.util.List;
*/
@Repository
public interface EmailAuthDAO extends JpaRepository<EmailAuth, Long> {
EmailAuth findByEmailAuthKey(String emailAuthKey);
EmailAuth findByEmailAuthKey(String emailAuthKey);
List<EmailAuth> findByMemberId(Long memberId);
List<EmailAuth> findByMemberId(Long memberId);
}

View File

@ -23,82 +23,75 @@ import java.util.Map;
@Service("GenerateUtil")
public class GenerateUtil {
@Autowired
private MetaSensorItemKeyService metaSensorItemKeyService;
@Autowired
private MetaSensorItemKeyService metaSensorItemKeyService;
private Map<Short, Map<Integer, MetaSensorItemKey>> mappingMap = null;
public Map<Integer, MetaSensorItemKey> initMappingMap(MetaCrawler metaCrawler) throws OverflowException {
private Map<Short, Map<Integer, MetaSensorItemKey>> mappingMap = null;
public Map<Integer, MetaSensorItemKey> initMappingMap(MetaCrawler metaCrawler) throws OverflowException {
if(this.mappingMap == null) {
this.mappingMap = new HashMap<>();
}
Map<Integer, MetaSensorItemKey> resultMap = this.mappingMap.get(metaCrawler.getId());
if(resultMap != null) {
return resultMap;
}
resultMap = this.metaSensorItemKeyService.readAllMapByMetaCrawlerID(metaCrawler.getId());
this.mappingMap.put(metaCrawler.getId(), resultMap);
return resultMap;
if (this.mappingMap == null) {
this.mappingMap = new HashMap<>();
}
Map<Integer, MetaSensorItemKey> resultMap = this.mappingMap.get(metaCrawler.getId());
public Crawler getCrawler(MetaCrawler metaCrawler) throws OverflowException {
Crawler crawler = new Crawler();
crawler.setName(metaCrawler.getName());
String container = "";
if(metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.MONGODB_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.MSSQL_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.ORACLE_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.POSTGRESQL_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
container = "java_proxy";
}
else {
container = "network_proxy";
}
crawler.setContainer(container);
return crawler;
if (resultMap != null) {
return resultMap;
}
resultMap = this.metaSensorItemKeyService.readAllMapByMetaCrawlerID(metaCrawler.getId());
this.mappingMap.put(metaCrawler.getId(), resultMap);
return resultMap;
}
public Crawler getCrawler(MetaCrawler metaCrawler) throws OverflowException {
public Map<String, List<MetaSensorItemKey>> sortItems(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap) throws OverflowException {
Crawler crawler = new Crawler();
crawler.setName(metaCrawler.getName());
Map<String, List<MetaSensorItemKey>> metricMap = new HashMap<>();
String container = "";
MetaSensorItemKey itemKey = null;
for(SensorItem sItem : sensorItems) {
itemKey = keyMap.get(sItem.getMetaSensorDisplayItem().getId());
if(metricMap.containsKey(itemKey.getFroms()) == false) {
metricMap.put(itemKey.getFroms(), new ArrayList<>());
}
metricMap.get(itemKey.getFroms()).add(itemKey);
}
return metricMap;
if (metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.MONGODB_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.MSSQL_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.ORACLE_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.POSTGRESQL_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
container = "java_proxy";
} else {
container = "network_proxy";
}
public Keys createKeys(MetaSensorItemKey itemKey) throws OverflowException {
Keys keys = new Keys();
keys.setKey(itemKey.getKey());
keys.setMetric(itemKey.getMetaSensorItem().getKey());
return keys;
crawler.setContainer(container);
return crawler;
}
public Map<String, List<MetaSensorItemKey>> sortItems(List<SensorItem> sensorItems,
Map<Integer, MetaSensorItemKey> keyMap) throws OverflowException {
Map<String, List<MetaSensorItemKey>> metricMap = new HashMap<>();
MetaSensorItemKey itemKey = null;
for (SensorItem sItem : sensorItems) {
itemKey = keyMap.get(sItem.getMetaSensorDisplayItem().getId());
if (metricMap.containsKey(itemKey.getFroms()) == false) {
metricMap.put(itemKey.getFroms(), new ArrayList<>());
}
metricMap.get(itemKey.getFroms()).add(itemKey);
}
return metricMap;
}
public Keys createKeys(MetaSensorItemKey itemKey) throws OverflowException {
Keys keys = new Keys();
keys.setKey(itemKey.getKey());
keys.setMetric(itemKey.getMetaSensorItem().getKey());
return keys;
}
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.generator.service;
import com.loafle.overflow.central.commons.utils.StringConvertor;
import com.loafle.overflow.core.type.PortType;
import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.infra.Infra;
@ -77,7 +76,8 @@ public class InfraHostGenerator {
private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception {
AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(), dbSensor.getTarget().getId());
AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(),
dbSensor.getTarget().getId());
if (authCrawler == null) {
return null;
@ -87,7 +87,9 @@ public class InfraHostGenerator {
Connection connection = new Connection();
connection.setIp(infraHost.getIpv4());
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference<Map<String, String>>(){});
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(),
new TypeReference<Map<String, String>>() {
});
if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
connection.setPort(135);

View File

@ -37,15 +37,15 @@ public class InfraHostWMIGenerator {
Map<String, List<MetaSensorItemKey>> metricMap = null;
metricMap = this.generateUtil.sortItems(sensorItems, keyMap);
// MetaSensorItemKey itemKey = null;
// MetaSensorItemKey itemKey = null;
//
// for(SensorItem sItem : sensorItems) {
// itemKey = keyMap.get(sItem.getItem().getId());
// if(metricMap.containsKey(itemKey.getFroms()) == false) {
// metricMap.put(itemKey.getFroms(), new ArrayList<>());
// }
// metricMap.get(itemKey.getFroms()).add(itemKey);
// }
// for(SensorItem sItem : sensorItems) {
// itemKey = keyMap.get(sItem.getItem().getId());
// if(metricMap.containsKey(itemKey.getFroms()) == false) {
// metricMap.put(itemKey.getFroms(), new ArrayList<>());
// }
// metricMap.get(itemKey.getFroms()).add(itemKey);
// }
List<Item> itemList = new ArrayList<>();
Item item = null;
@ -76,9 +76,9 @@ public class InfraHostWMIGenerator {
stringBuffer.append(", ");
}
// keys = new Keys();
// keys.setKey(tempItemKey.getKey());
// keys.setMetric(tempItemKey.getItem().getKey());
// keys = new Keys();
// keys.setKey(tempItemKey.getKey());
// keys.setMetric(tempItemKey.getItem().getKey());
keysList.add(this.generateUtil.createKeys(tempItemKey));
}
@ -86,7 +86,8 @@ public class InfraHostWMIGenerator {
String json = tempItemKey.getOption();
if (json != null && json.length() > 0) {
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>(){});
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>() {
});
Object obj = null;
obj = optionMap.get("appends");

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.generator.service;
import com.loafle.overflow.central.commons.utils.StringConvertor;
import com.loafle.overflow.core.type.PortType;
import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.infra.Infra;
@ -31,89 +30,91 @@ import java.util.Map;
@Service("InfraServiceGenerator")
public class InfraServiceGenerator {
@Autowired
private GenerateUtil generateUtil;
@Autowired
private GenerateUtil generateUtil;
@Autowired
private InfraServiceMysqlGenerator infraServiceMysqlGenerator;
@Autowired
private InfraServiceMysqlGenerator infraServiceMysqlGenerator;
@Autowired
private InfraServiceJMXGenerator infraServiceJMXGenerator;
@Autowired
private InfraServiceJMXGenerator infraServiceJMXGenerator;
@Autowired
private AuthCrawlerService authCrawlerService;
@Autowired
private AuthCrawlerService authCrawlerService;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private ObjectMapper objectMapper;
public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception {
com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService)infra;
public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception {
com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService) infra;
SensorConfig sensorConfig = new SensorConfig();
sensorConfig.setConfigID(String.valueOf(dbSensor.getId()));
SensorConfig sensorConfig = new SensorConfig();
sensorConfig.setConfigID(String.valueOf(dbSensor.getId()));
Target target = this.createTarget(infraService, dbSensor);
Target target = this.createTarget(infraService, dbSensor);
if(target == null) {
return null;
}
sensorConfig.setTarget(target);
// FIXME: Interval
Schedule schedule = new Schedule();
schedule.setInterval("5");
sensorConfig.setSchedule(schedule);
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getMetaCrawler());
sensorConfig.setCrawler(crawler);
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getMetaCrawler());
if(dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
} else if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
}
return objectMapper.writeValueAsString(sensorConfig);
if (target == null) {
return null;
}
private Target createTarget(InfraService infraService, Sensor sensor) throws Exception {
sensorConfig.setTarget(target);
AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(), sensor.getTarget().getId());
// FIXME: Interval
Schedule schedule = new Schedule();
schedule.setInterval("5");
sensorConfig.setSchedule(schedule);
if(authCrawler == null) {
return null;
}
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getMetaCrawler());
sensorConfig.setCrawler(crawler);
Target target = new Target();
Connection connection = new Connection();
connection.setIp(infraService.getInfraHost().getIpv4());
connection.setPort(infraService.getPort());
connection.setPortType(PortType.valueOf(infraService.getPortType()));
connection.setSsl(infraService.isTlsType());
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getMetaCrawler());
target.setConnection(connection);
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference<Map<String, String>>(){});
Map<String, Object> auth = new HashMap<>();
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.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);
}
target.setAuth(auth);
return target;
if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
} else if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
}
return objectMapper.writeValueAsString(sensorConfig);
}
private Target createTarget(InfraService infraService, Sensor sensor) throws Exception {
AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(),
sensor.getTarget().getId());
if (authCrawler == null) {
return null;
}
Target target = new Target();
Connection connection = new Connection();
connection.setIp(infraService.getInfraHost().getIpv4());
connection.setPort(infraService.getPort());
connection.setPortType(PortType.valueOf(infraService.getPortType()));
connection.setSsl(infraService.isTlsType());
target.setConnection(connection);
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(),
new TypeReference<Map<String, String>>() {
});
Map<String, Object> auth = new HashMap<>();
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.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);
}
target.setAuth(auth);
return target;
}
}

View File

@ -73,7 +73,8 @@ public class InfraServiceJMXGenerator {
List<String> arrayCol = null;
if (json != null && json.length() > 0) {
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>(){});
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>() {
});
Object obj = null;
obj = optionMap.get("aliases");

View File

@ -33,14 +33,14 @@ public class InfraServiceMysqlGenerator {
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
SensorConfig sensorConfig) throws Exception {
// List<Keys> keysList = new ArrayList<>();
// for(SensorItem sItem : sensorItems) {
// keys = new Keys();
// keys.setMetric(sItem.getItem().getKey());
// keys.setKey(KeyMap.get(sItem.getItem().getId()).getKey());
// keysList.add(keys);
// }
// item.setKeys(keysList);
// List<Keys> keysList = new ArrayList<>();
// for(SensorItem sItem : sensorItems) {
// keys = new Keys();
// keys.setMetric(sItem.getItem().getKey());
// keys.setKey(KeyMap.get(sItem.getItem().getId()).getKey());
// keysList.add(keys);
// }
// item.setKeys(keysList);
Map<String, List<MetaSensorItemKey>> metricMap = null;
metricMap = this.generateUtil.sortItems(sensorItems, keyMap);
@ -81,7 +81,8 @@ public class InfraServiceMysqlGenerator {
String json = tempItemKey.getOption();
if (json != null && json.length() > 0) {
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>(){});
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>() {
});
Object obj = null;
obj = optionMap.get("valueColumn");
@ -113,42 +114,43 @@ public class InfraServiceMysqlGenerator {
sensorConfig.setItems(itemList);
// ObjectMapper objectMapper = new ObjectMapper();
// ObjectMapper objectMapper = new ObjectMapper();
//
// return objectMapper.writeValueAsString(config);
// return objectMapper.writeValueAsString(config);
}
// public void setQueryAndMapping(MetaCrawler metaCrawler, List<Keys> keysList, QueryInfo queryInfo, MappingInfo mappingInfo) {
// public void setQueryAndMapping(MetaCrawler metaCrawler, List<Keys> keysList,
// QueryInfo queryInfo, MappingInfo mappingInfo) {
//
// switch (metaCrawler.getId()) {
// case 11: // mysql
// {
// String query = "show status where ";
//// queryInfo.setQuery("show status where ");
// switch (metaCrawler.getId()) {
// case 11: // mysql
// {
// String query = "show status where ";
//// queryInfo.setQuery("show status where ");
//
// Keys keys = null;
// for(int indexI = 0 ; indexI < keysList.size(); ++indexI) {
// keys = keysList.get(indexI);
// query += "variable_name = '";
// query += keys.getKey();
// query += "'";
// if(indexI + 1 < keysList.size()) {
// query += " or ";
// }
// }
// Keys keys = null;
// for(int indexI = 0 ; indexI < keysList.size(); ++indexI) {
// keys = keysList.get(indexI);
// query += "variable_name = '";
// query += keys.getKey();
// query += "'";
// if(indexI + 1 < keysList.size()) {
// query += " or ";
// }
// }
//
// queryInfo.setQuery(query);
// queryInfo.setQuery(query);
//
// mappingInfo.setParseDirection("row");
// mappingInfo.setValueColumn("Value");
// mappingInfo.setParseDirection("row");
// mappingInfo.setValueColumn("Value");
//
// List<String> keyColumns = new ArrayList<>();
// keyColumns.add("Variable_name");
// List<String> keyColumns = new ArrayList<>();
// keyColumns.add("Variable_name");
//
// mappingInfo.setKeyColumns(keyColumns);
// }
// break;
// }
// mappingInfo.setKeyColumns(keyColumns);
// }
// break;
// }
//
// }
// }
}

View File

@ -19,47 +19,44 @@ import com.loafle.overflow.service.central.sensor.SensorItemService;
@Service("SensorConfigGenerator")
public class SensorConfigGenerator {
@Autowired
private SensorItemService sensorItemService;
@Autowired
private SensorItemService sensorItemService;
@Autowired
private InfraService infraService;
@Autowired
private InfraService infraService;
@Autowired
private InfraHostGenerator infraHostGenerator;
@Autowired
private InfraHostGenerator infraHostGenerator;
@Autowired
private InfraServiceGenerator infraServiceGenerator;
@Autowired
private InfraServiceGenerator infraServiceGenerator;
public String generate(Sensor sensor) throws Exception {
PageParams pageParams = new PageParams();
pageParams.setPageNo(0);
pageParams.setCountPerPage(Integer.MAX_VALUE);
pageParams.setSortCol("id");
pageParams.setSortDirection("descending");
Page<SensorItem> dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams);
public String generate(Sensor sensor) throws Exception {
PageParams pageParams = new PageParams();
pageParams.setPageNo(0);
pageParams.setCountPerPage(Integer.MAX_VALUE);
pageParams.setSortCol("id");
pageParams.setSortDirection("descending");
Page<SensorItem> dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams);
List<SensorItem> sensorItems = dbItemList.getContent();
List<SensorItem> sensorItems = dbItemList.getContent();
if (sensorItems.size() <= 0) {
return "";
}
Sensor dbSensor = sensorItems.get(0).getSensor();
if(sensorItems.size() <= 0) {
return "";
}
Sensor dbSensor = sensorItems.get(0).getSensor();
Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId());
Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId());
// 7 = Infra OS Service
if(infra.getMetaInfraType().getId() == 7) {
return this.infraServiceGenerator.process(dbSensor, sensorItems, infra);
}
if(infra.getMetaInfraType().getId() == 2) {
return this.infraHostGenerator.process(dbSensor, sensorItems, infra);
}
return null;
// 7 = Infra OS Service
if (infra.getMetaInfraType().getId() == 7) {
return this.infraServiceGenerator.process(dbSensor, sensorItems, infra);
}
if (infra.getMetaInfraType().getId() == 2) {
return this.infraHostGenerator.process(dbSensor, sensorItems, infra);
}
return null;
}
}

View File

@ -12,11 +12,11 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface HistoryDAO extends JpaRepository<History, Long> {
Page<History> findAllByProbeId(Long probeID, Pageable pageable);
Page<History> findAllByProbeId(Long probeID, Pageable pageable);
Page<History> findAllByProbeIdAndMetaHistoryTypeId(Long probeID, Integer metaHistoryTypeId, Pageable pageable);
Page<History> findAllByProbeIdAndMetaHistoryTypeId(Long probeID, Integer metaHistoryTypeId, Pageable pageable);
Page<History> findAllByDomainId(Long domainID, Pageable pageRequest);
Page<History> findAllByDomainId(Long domainID, Pageable pageRequest);
Page<History> findAllByDomainIdAndMetaHistoryTypeId(Long domainID, Integer metaHistoryTypeId, Pageable pageRequest);
Page<History> findAllByDomainIdAndMetaHistoryTypeId(Long domainID, Integer metaHistoryTypeId, Pageable pageRequest);
}

View File

@ -4,10 +4,7 @@ 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;
import com.loafle.overflow.model.meta.MetaHistoryType;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.service.central.history.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
@ -16,28 +13,31 @@ import org.springframework.stereotype.Service;
@Service("HistoryService")
public class CentralHistoryService implements HistoryService {
@Autowired
private HistoryDAO historyDAO;
@Autowired
private HistoryDAO historyDAO;
public History regist(History history) throws OverflowException {
return this.historyDAO.save(history);
}
public History regist(History history) throws OverflowException {
return this.historyDAO.save(history);
}
public Page<History> readAllByProbeIDAndMetaHistoryTypeID(Long probeID, Integer metaHistoryTypeID,
PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByProbeIdAndMetaHistoryTypeId(probeID, metaHistoryTypeID,
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) throws OverflowException {
return this.historyDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(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) throws OverflowException {
return this.historyDAO.findAllByDomainId(domainID, PageUtil.getPageRequest(pageParams));
}
public Page<History> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByDomainId(domainID, PageUtil.getPageRequest(pageParams));
}
public Page<History> readAllByDomainIDAndMetaHistoryTypeID(Long domainID, Integer metaHistoryTypeID, PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByDomainIdAndMetaHistoryTypeId(domainID, metaHistoryTypeID, 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

@ -15,14 +15,14 @@ import java.util.List;
*/
@Repository
public interface InfraDAO extends JpaRepository<Infra, Long> {
List<Infra> findAllByProbeId(Long probeID);
List<Infra> findAllByProbeId(Long probeID);
Page<Infra> findAllByProbeId(Long probeID, Pageable pageable);
Page<Infra> findAllByProbeId(Long probeID, Pageable pageable);
Page<Infra> findAllByProbeIn(List<Probe> probes, Pageable pageable);
Page<Infra> findAllByProbeIn(List<Probe> probes, Pageable pageable);
List<Target> findAllTargetByProbeIn(List<Probe> probes);
List<Target> findAllTargetByProbeIn(List<Probe> probes);
// Infra findByTargetId(Long targetID);
// Infra findByTargetId(Long targetID);
}

View File

@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface InfraHostDAO extends JpaRepository<InfraHost, Long> {
InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4);
InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4);
}

View File

@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface InfraOSPortDAO extends JpaRepository<InfraOSPort, Long> {
InfraOSPort findByInfraOSAndPortAndPortType(Long infraOSId, Integer port, String portType);
InfraOSPort findByInfraOSAndPortAndPortType(Long infraOSId, Integer port, String portType);
}

View File

@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface InfraServiceDAO extends JpaRepository<InfraService, Long> {
InfraService findByInfraHostIdAndPortAndPortType(Long infraHostId, Integer port, 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;
@ -14,19 +13,19 @@ import org.springframework.stereotype.Service;
@Service("InfraHostService")
public class CentralInfraHostService implements InfraHostService {
@Autowired
InfraHostDAO infraHostDAO;
@Autowired
InfraHostDAO infraHostDAO;
public InfraHost regist(InfraHost infraHost) throws OverflowException {
return this.infraHostDAO.save(infraHost);
}
public InfraHost regist(InfraHost infraHost) throws OverflowException {
return this.infraHostDAO.save(infraHost);
}
public InfraHost read(Long id) throws OverflowException {
return this.infraHostDAO.findById(id).get();
}
public InfraHost read(Long id) throws OverflowException {
return this.infraHostDAO.findById(id).get();
}
public InfraHost readByProbeIdAndIpv4(Long probeId, String ip) throws OverflowException {
return this.infraHostDAO.findByProbeIdAndIpv4(probeId, ip);
}
public InfraHost readByProbeIdAndIpv4(Long probeId, String ip) throws OverflowException {
return this.infraHostDAO.findByProbeIdAndIpv4(probeId, ip);
}
}

View File

@ -12,14 +12,14 @@ import org.springframework.stereotype.Service;
*/
@Service("InfraMachineService")
public class CentralInfraMachineService implements InfraMachineService {
@Autowired
InfraMachineDAO infraMachineDAO;
@Autowired
InfraMachineDAO infraMachineDAO;
public InfraMachine regist(InfraMachine infraMachine) throws OverflowException {
return this.infraMachineDAO.save(infraMachine);
}
public InfraMachine regist(InfraMachine infraMachine) throws OverflowException {
return this.infraMachineDAO.save(infraMachine);
}
public InfraMachine read(Long id) {
return this.infraMachineDAO.findById(id).get();
}
public InfraMachine read(Long id) {
return this.infraMachineDAO.findById(id).get();
}
}

View File

@ -13,14 +13,14 @@ import org.springframework.stereotype.Service;
@Service("InfraOSApplicationService")
public class CentralInfraOSApplicationService implements InfraOSApplicationService {
@Autowired
InfraOSApplicationDAO infraOSApplicationDAO;
@Autowired
InfraOSApplicationDAO infraOSApplicationDAO;
public InfraOSApplication regist(InfraOSApplication infraOSApplication) throws OverflowException {
return this.infraOSApplicationDAO.save(infraOSApplication);
}
public InfraOSApplication regist(InfraOSApplication infraOSApplication) throws OverflowException {
return this.infraOSApplicationDAO.save(infraOSApplication);
}
public InfraOSApplication read(Long id) throws OverflowException {
return this.infraOSApplicationDAO.findById(id).get();
}
public InfraOSApplication read(Long id) throws OverflowException {
return this.infraOSApplicationDAO.findById(id).get();
}
}

View File

@ -13,14 +13,14 @@ import org.springframework.stereotype.Service;
@Service("InfraOSDaemonService")
public class CentralInfraOSDaemonService implements InfraOSDaemonService {
@Autowired
InfraOSDaemonDAO infraOSDaemonDAO;
@Autowired
InfraOSDaemonDAO infraOSDaemonDAO;
public InfraOSDaemon regist(InfraOSDaemon infraOSDaemon) throws OverflowException {
return this.infraOSDaemonDAO.save(infraOSDaemon);
}
public InfraOSDaemon regist(InfraOSDaemon infraOSDaemon) throws OverflowException {
return this.infraOSDaemonDAO.save(infraOSDaemon);
}
public InfraOSDaemon read(Long id) throws OverflowException {
return this.infraOSDaemonDAO.findById(id).get();
}
public InfraOSDaemon read(Long id) throws OverflowException {
return this.infraOSDaemonDAO.findById(id).get();
}
}

View File

@ -13,19 +13,19 @@ import org.springframework.stereotype.Service;
@Service("InfraOSPortService")
public class CentralInfraOSPortService implements InfraOSPortService {
@Autowired
InfraOSPortDAO infraOSPortDAO;
@Autowired
InfraOSPortDAO infraOSPortDAO;
public InfraOSPort regist(InfraOSPort infraOSPort) throws OverflowException {
return this.infraOSPortDAO.save(infraOSPort);
}
public InfraOSPort regist(InfraOSPort infraOSPort) throws OverflowException {
return this.infraOSPortDAO.save(infraOSPort);
}
public InfraOSPort read(Long id) throws OverflowException {
return this.infraOSPortDAO.findById(id).get();
}
public InfraOSPort read(Long id) throws OverflowException {
return this.infraOSPortDAO.findById(id).get();
}
public InfraOSPort readByInfraOSIDAndPortAndPortType(Long infraOSID, Integer port, String portType)
throws OverflowException {
return this.infraOSPortDAO.findByInfraOSAndPortAndPortType(infraOSID, port, portType);
}
public InfraOSPort readByInfraOSIDAndPortAndPortType(Long infraOSID, Integer port, String portType)
throws OverflowException {
return this.infraOSPortDAO.findByInfraOSAndPortAndPortType(infraOSID, port, portType);
}
}

View File

@ -13,14 +13,14 @@ import org.springframework.stereotype.Service;
@Service("InfraOSService")
public class CentralInfraOSService implements InfraOSService {
@Autowired
InfraOSDAO infraOSDAO;
@Autowired
InfraOSDAO infraOSDAO;
public InfraOS regist(InfraOS infraOS) throws OverflowException {
return this.infraOSDAO.save(infraOS);
}
public InfraOS regist(InfraOS infraOS) throws OverflowException {
return this.infraOSDAO.save(infraOS);
}
public InfraOS read(Long id) throws OverflowException {
return this.infraOSDAO.findById(id).get();
}
public InfraOS read(Long id) throws OverflowException {
return this.infraOSDAO.findById(id).get();
}
}

View File

@ -24,58 +24,58 @@ import java.util.List;
@Service("InfraService")
public class CentralInfraService implements InfraService {
@Autowired
InfraDAO infraDAO;
@Autowired
InfraDAO infraDAO;
@Autowired
SensorDAO sensorDAO;
@Autowired
SensorDAO sensorDAO;
@Autowired
private ProbeService probeService;
@Autowired
private ProbeService probeService;
public Infra regist(Infra infra) throws OverflowException {
return this.infraDAO.save(infra);
public Infra regist(Infra infra) throws OverflowException {
return this.infraDAO.save(infra);
}
public Infra read(Long id) throws OverflowException {
Infra infra = this.infraDAO.findById(id).get();
return infra;
}
public Page<Infra> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.infraDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams));
}
public Page<Infra> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
if (probeList == null || probeList.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable());
}
public Infra read(Long id) throws OverflowException {
Infra infra = this.infraDAO.findById(id).get();
return infra;
Page<Infra> infraList = this.infraDAO.findAllByProbeIn(probeList, PageUtil.getPageRequest(pageParams));
return infraList;
}
public List<Target> readAllTargetByDomainID(Long domainID) throws OverflowException {
List<Probe> probes = this.probeService.readAllByDomainID(domainID);
if (probes == null || probes.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable());
}
public Page<Infra> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.infraDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams));
}
return this.infraDAO.findAllTargetByProbeIn(probes);
}
public Page<Infra> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
public List<Target> readAllTargetByProbes(List<Probe> probes) throws OverflowException {
return this.infraDAO.findAllTargetByProbeIn(probes);
// return null;
}
if (probeList == null || probeList.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable());
}
Page<Infra> infraList = this.infraDAO.findAllByProbeIn(probeList, PageUtil.getPageRequest(pageParams));
return infraList;
}
public List<Target> readAllTargetByDomainID(Long domainID) throws OverflowException {
List<Probe> probes = this.probeService.readAllByDomainID(domainID);
if (probes == null || probes.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable());
}
return this.infraDAO.findAllTargetByProbeIn(probes);
}
public List<Target> readAllTargetByProbes(List<Probe> probes) throws OverflowException {
return this.infraDAO.findAllTargetByProbeIn(probes);
// return null;
}
public Infra readByTargetID(Long targetID) throws OverflowException {
// return this.infraDAO.findByTargetId(targetID);
return null;
}
public Infra readByTargetID(Long targetID) throws OverflowException {
// return this.infraDAO.findByTargetId(targetID);
return null;
}
}

View File

@ -13,19 +13,19 @@ import org.springframework.stereotype.Service;
@Service("InfraServiceService")
public class CentralInfraServiceService implements InfraServiceService {
@Autowired
InfraServiceDAO infraServiceDAO;
@Autowired
InfraServiceDAO infraServiceDAO;
public InfraService regist(InfraService infraService) throws OverflowException {
return this.infraServiceDAO.save(infraService);
}
public InfraService regist(InfraService infraService) throws OverflowException {
return this.infraServiceDAO.save(infraService);
}
public InfraService read(Long id) throws OverflowException {
return this.infraServiceDAO.findById(id).get();
}
public InfraService read(Long id) throws OverflowException {
return this.infraServiceDAO.findById(id).get();
}
public InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType)
throws OverflowException {
return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, portType);
}
public InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType)
throws OverflowException {
return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, portType);
}
}

View File

@ -10,5 +10,5 @@ import org.springframework.stereotype.Repository;
@Repository
public interface MemberDAO extends JpaRepository<Member, Long> {
Member findByEmail(String email);
Member findByEmail(String email);
}

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface MemberTotpDAO extends JpaRepository<MemberTotp, Long> {
MemberTotp findBySecretCode(String secretCode);
MemberTotp findBySecretCode(String secretCode);
MemberTotp findByMemberEmail(String memberEmail);
MemberTotp findByMemberEmail(String memberEmail);
}

View File

@ -32,264 +32,258 @@ import java.util.regex.Pattern;
@Service("MemberService")
public class CentralMemberService implements MemberService {
@Autowired
private MemberDAO memberDAO;
@Autowired
private MemberDAO memberDAO;
@Autowired
private EmailAuthService emailAuthService;
@Autowired
private EmailAuthService emailAuthService;
@Autowired
private ApiKeyService apiKeyService;
@Autowired
private ApiKeyService apiKeyService;
@Autowired
private DomainMemberService domainMemberService;
@Autowired
private DomainMemberService domainMemberService;
@Autowired
private ProbeService probeService;
@Autowired
private ProbeService probeService;
private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
public DomainMember signin(String signinId, String signinPw) throws OverflowException {
Member m = this.memberDAO.findByEmail(signinId);
public DomainMember signin(String signinId, String signinPw) throws OverflowException {
Member m = this.memberDAO.findByEmail(signinId);
if ( null == m ) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
}
if ( m.getMetaMemberStatus().getId() == 1 ) {
throw new OverflowException("EmailNotConfirmedException()", new Throwable());
}
Boolean match = passwordEncoder.matches(signinPw, m.getPw());
if(!match) {
if (m.getSigninFailCount() > 10) {
throw new OverflowException("SigninOverFailedException()", new Throwable());
}
m.setSigninFailCount(m.getSigninFailCount()+1);
this.modify(m);
throw new OverflowException("SignInPwNotMatchException()", new Throwable());
}
m.setSigninFailCount(0);
this.modify(m);
DomainMember dm = domainMemberService.readByMemberEmail(m.getEmail());
// Todo Signin History
return dm;
if (null == m) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
}
public Member signup(Member member, String pw) throws OverflowException {
if (m.getMetaMemberStatus().getId() == 1) {
throw new OverflowException("EmailNotConfirmedException()", new Throwable());
}
Member isMember = this.memberDAO.findByEmail(member.getEmail());
Boolean match = passwordEncoder.matches(signinPw, m.getPw());
if (!match) {
if (m.getSigninFailCount() > 10) {
throw new OverflowException("SigninOverFailedException()", new Throwable());
}
m.setSigninFailCount(m.getSigninFailCount() + 1);
this.modify(m);
throw new OverflowException("SignInPwNotMatchException()", new Throwable());
}
if (null != isMember && isMember.getId() > 0) {
throw new OverflowException("JoinedEmailException()", new Throwable());
}
m.setSigninFailCount(0);
this.modify(m);
boolean checkPass = this.isPasswordStrong(pw);
DomainMember dm = domainMemberService.readByMemberEmail(m.getEmail());
if (!checkPass) {
throw new OverflowException("PasswordNotStrongException()", new Throwable());
// (
// "Passwords must contain at least one uppercase letter, " +
// "special character, lowercase letter, and number, " +
// "and must be at least 6 characters long.");
}
// Todo Signin History
return dm;
}
public Member signup(Member member, String pw) throws OverflowException {
Member isMember = this.memberDAO.findByEmail(member.getEmail());
if (null != isMember && isMember.getId() > 0) {
throw new OverflowException("JoinedEmailException()", new Throwable());
}
boolean checkPass = this.isPasswordStrong(pw);
if (!checkPass) {
throw new OverflowException("PasswordNotStrongException()", new Throwable());
// (
// "Passwords must contain at least one uppercase letter, " +
// "special character, lowercase letter, and number, " +
// "and must be at least 6 characters long.");
}
member.setPw(passwordEncoder.encode(pw));
if (member.getMetaMemberStatus() == null) {
member.setMetaMemberStatus(new MetaMemberStatus((short) 1));
}
member.setTotpType(false);
Member resMember = this.memberDAO.save(member);
try {
this.emailAuthService.sendEmailByMember(resMember);
} catch (Exception e) {
// Todo ReSend Mail
e.printStackTrace();
}
return resMember;
}
public Member sendEmailForPassword(String email) throws OverflowException {
Member member = this.memberDAO.findByEmail(email);
if (null == member) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
}
try {
this.emailAuthService.sendEmailResetPassword(member);
} catch (Exception e) {
// Todo ReSend Mail
e.printStackTrace();
}
return member;
}
public Member resetPassword(String token, String pw) throws OverflowException {
String deStr = null;
try {
deStr = URLDecoder.decode(token, "UTF-8");
} catch (Exception e) {
}
// String deEmail = this.emailSender.decrypt(deStr);
EmailAuth auth = this.emailAuthService.readByToken(deStr);
if (auth == null) {
throw new OverflowException("Not Exist Token", null);
}
Member member = this.memberDAO.findByEmail(auth.getMember().getEmail());
if (null == member) {
throw new OverflowException("", null);
}
boolean checkPass = this.isPasswordStrong(pw);
if (!checkPass) {
throw new OverflowException("PasswordNotStrongException()", new Throwable());
// "Passwords must contain at least one uppercase letter, " +
// "special character, lowercase letter, and number, " +
// "and must be at least 6 characters long.");
}
member.setPw(passwordEncoder.encode(pw));
return this.modify(member);
}
public void signout(Member member) {
// Todo websocket session remove
}
@WebappAPI
public Member modify(Member member, String pw) throws OverflowException {
String email = SessionMetadata.getTargetID();
Member preMember = this.memberDAO.findByEmail(member.getEmail());
if (null == preMember || 0 >= preMember.getId()) {
throw new OverflowException("SigninId Not Exist()", new Throwable());
}
member.setId(preMember.getId());
if (null != pw && !pw.equals("")) {
boolean checkPass = this.isPasswordStrong(pw);
if (!checkPass) {
throw new OverflowException("PasswordNotStrongException()", new Throwable());
// "Passwords must contain at least one uppercase letter, " +
// "special character, lowercase letter, and number, " +
// "and must be at least 6 characters long.");
}
Boolean match = passwordEncoder.matches(member.getPw(), preMember.getPw());
if (!match) {
member.setPw(passwordEncoder.encode(pw));
if (member.getMetaMemberStatus() == null) {
member.setMetaMemberStatus(new MetaMemberStatus((short) 1));
}
member.setTotpType(false);
Member resMember = this.memberDAO.save(member);
try {
this.emailAuthService.sendEmailByMember(resMember);
} catch (Exception e) {
// Todo ReSend Mail
e.printStackTrace();
}
return resMember;
}
} else {
member.setPw(preMember.getPw());
}
public Member sendEmailForPassword(String email) throws OverflowException {
Member member = this.memberDAO.findByEmail(email);
if (member.getMetaMemberStatus() == null || member.getMetaMemberStatus().getId() <= 0) {
member.setMetaMemberStatus(new MetaMemberStatus());
member.getMetaMemberStatus().setId(preMember.getMetaMemberStatus().getId());
}
return this.modify(member);
}
if (null == member) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
}
private Member modify(Member member) throws OverflowException {
return this.memberDAO.save(member);
}
try {
this.emailAuthService.sendEmailResetPassword(member);
} catch (Exception e) {
// Todo ReSend Mail
e.printStackTrace();
}
public Member confirmPw(String signinId, String signinPw) throws OverflowException {
Member preMember = this.memberDAO.findByEmail(signinId);
return member;
String encodePw = passwordEncoder.encode(signinPw);
Boolean match = passwordEncoder.matches(encodePw, preMember.getPw());
if (!match) {
throw new OverflowException("SignInPwNotMatchException", new Throwable());
}
public Member resetPassword(String token, String pw) throws OverflowException {
String deStr = null;
return preMember;
}
try {
deStr = URLDecoder.decode(token, "UTF-8");
}catch (Exception e) {
public Member forgotPassword(String signinId, String newPw) throws OverflowException {
Member preMember = this.memberDAO.findByEmail(signinId);
}
// String deEmail = this.emailSender.decrypt(deStr);
EmailAuth auth = this.emailAuthService.readByToken(deStr);
if (auth == null) {
throw new OverflowException("Not Exist Token", null);
}
Member member = this.memberDAO.findByEmail(auth.getMember().getEmail());
if (null == member) {
throw new OverflowException("", null);
}
boolean checkPass = this.isPasswordStrong(pw);
if (!checkPass) {
throw new OverflowException("PasswordNotStrongException()", new Throwable());
// "Passwords must contain at least one uppercase letter, " +
// "special character, lowercase letter, and number, " +
// "and must be at least 6 characters long.");
}
member.setPw(passwordEncoder.encode(pw));
return this.modify(member);
if (null == preMember) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
}
public void signout(Member member) {
// Todo websocket session remove
Member cMember = this.modify(preMember, newPw);
return cMember;
}
public Member read(Long memberId) throws OverflowException {
if (memberId <= 0) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
}
@WebappAPI
public Member modify(Member member, String pw) throws OverflowException {
String email = SessionMetadata.getTargetID();
Member preMember = this.memberDAO.findByEmail(member.getEmail());
Member resMember = this.memberDAO.findById(memberId).get();
return resMember;
}
if (null == preMember || 0 >= preMember.getId()) {
throw new OverflowException("SigninId Not Exist()", new Throwable());
}
member.setId(preMember.getId());
if (null != pw && !pw.equals("")) {
boolean checkPass = this.isPasswordStrong(pw);
@WebappAPI
public void withdrawal(Long memberId) throws OverflowException {
String email = SessionMetadata.getTargetID();
if (!checkPass) {
throw new OverflowException("PasswordNotStrongException()", new Throwable());
// "Passwords must contain at least one uppercase letter, " +
// "special character, lowercase letter, and number, " +
// "and must be at least 6 characters long.");
}
// Todo DB delete?
}
Boolean match = passwordEncoder.matches(member.getPw(), preMember.getPw());
if(!match) {
member.setPw(passwordEncoder.encode(pw));
}
} else {
member.setPw(preMember.getPw());
}
public List<Member> readAllByProbeKey(String probeKey) throws OverflowException {
if (member.getMetaMemberStatus() == null || member.getMetaMemberStatus().getId() <= 0) {
member.setMetaMemberStatus(new MetaMemberStatus());
member.getMetaMemberStatus().setId(preMember.getMetaMemberStatus().getId());
}
return this.modify(member);
Probe probe = this.probeService.readByProbeKey(probeKey);
if (probe == null) {
return null;
}
private Member modify(Member member) throws OverflowException {
return this.memberDAO.save(member);
return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId());
}
public List<Member> readAllByApiKey(String apikey) throws OverflowException {
ApiKey apiKey = this.apiKeyService.readByApiKey(apikey);
if (apiKey == null) {
return null;
}
public Member confirmPw(String signinId, String signinPw) throws OverflowException {
Member preMember = this.memberDAO.findByEmail(signinId);
return this.domainMemberService.readAllMemberByDomainID(apiKey.getDomain().getId());
}
String encodePw = passwordEncoder.encode(signinPw);
Boolean match = passwordEncoder.matches(encodePw, preMember.getPw());
public List<Member> readAllByDomainID(final Long domainID) throws OverflowException {
if (!match) {
throw new OverflowException("SignInPwNotMatchException", new Throwable());
}
return this.domainMemberService.readAllMemberByDomainID(domainID);
}
return preMember;
}
private static final String PASSWORD_REGEXP = "(" + "(?=.*[a-z])" + "(?=.*\\d)" + "(?=.*[A-Z])"
+ "(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?])" + "." + "{6,40}" + ")";
private Pattern pattern = Pattern.compile(PASSWORD_REGEXP);
public Member forgotPassword(String signinId, String newPw) throws OverflowException {
Member preMember = this.memberDAO.findByEmail(signinId);
if (null == preMember) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
}
Member cMember = this.modify(preMember, newPw);
return cMember;
}
public Member read(Long memberId) throws OverflowException {
if (memberId <= 0) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
}
Member resMember = this.memberDAO.findById(memberId).get();
return resMember;
}
@WebappAPI
public void withdrawal(Long memberId) throws OverflowException {
String email = SessionMetadata.getTargetID();
// Todo DB delete?
}
public List<Member> readAllByProbeKey(String probeKey) throws OverflowException {
Probe probe = this.probeService.readByProbeKey(probeKey);
if(probe == null) {
return null;
}
return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId());
}
public List<Member> readAllByApiKey(String apikey) throws OverflowException {
ApiKey apiKey = this.apiKeyService.readByApiKey(apikey);
if(apiKey == null) {
return null;
}
return this.domainMemberService.readAllMemberByDomainID(apiKey.getDomain().getId());
}
public List<Member> readAllByDomainID(final Long domainID) throws OverflowException {
return this.domainMemberService.readAllMemberByDomainID(domainID);
}
private static final String PASSWORD_REGEXP = "(" +
"(?=.*[a-z])" +
"(?=.*\\d)" +
"(?=.*[A-Z])" +
"(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?])" +
"." +
"{6,40}" +
")";
private Pattern pattern = Pattern.compile(PASSWORD_REGEXP);
protected boolean isPasswordStrong(String pass) {
Matcher m = pattern.matcher(pass);
return m.matches();
}
protected boolean isPasswordStrong(String pass) {
Matcher m = pattern.matcher(pass);
return m.matches();
}
}

View File

@ -19,99 +19,100 @@ import java.util.Map;
*/
@Service("MemberTotpService")
public class CentralMemberTotpService implements MemberTotpService {
@Autowired
private MemberTotpDAO totpDAO;
@Autowired
private MemberTotpDAO totpDAO;
public void regist(Member member, String secretCode, String code) throws OverflowException {
public void regist(Member member, String secretCode, String code) throws OverflowException {
if (null == member || 0 >= member.getId()) {
throw new OverflowException("SignInIdNotExistException", new Throwable());
if (null == member || 0 >= member.getId()) {
throw new OverflowException("SignInIdNotExistException", new Throwable());
}
if (!this.checkCode(secretCode, code)) {
throw new OverflowException("TotpCodeNotMatchException", new Throwable());
}
MemberTotp totp = new MemberTotp();
totp.setMember(member);
totp.setSecretCode(secretCode);
this.totpDAO.save(totp);
}
public MemberTotp modify(MemberTotp totp) throws OverflowException {
if (null == totp.getSecretCode() || totp.getSecretCode().equals("")) {
throw new OverflowException("SecretCodeNotExistException", new Throwable());
}
if (null == totp.getMember() || 0 < totp.getMember().getId()) {
throw new OverflowException("SignInIdNotExistException", new Throwable());
}
return this.totpDAO.save(totp);
}
public void remove(Long id) throws OverflowException {
this.totpDAO.deleteById(id);
}
public MemberTotp read(Long id) throws OverflowException {
return this.totpDAO.findById(id).get();
}
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());
}
return this.checkCode(totp.getSecretCode(), code);
}
public boolean checkCode(String secretCode, String code) throws OverflowException {
GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
int codeInt = Integer.parseInt(code);
boolean isCheck = googleAuthenticator.authorize(secretCode, codeInt);
if (!isCheck) {
throw new OverflowException("TotpCodeNotMatchException", new Throwable());
}
return isCheck;
}
public Map<String, String> createTotp(Member member) throws OverflowException {
Map<String, String> returnMap = new HashMap<>();
GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
final GoogleAuthenticatorKey key = googleAuthenticator.createCredentials();
String secret = key.getKey();
// List<Integer> scratchCodes = key.getScratchCodes();
// String otpAuthURL = GoogleAuthenticatorQRGenerator.getOtpAuthURL("overFlow",
// member.getEmail(), key);
URIBuilder uri = (new URIBuilder()).setScheme("otpauth").setHost("totp")
.setPath("/" + formatLabel("overFlow", member.getEmail())).setParameter("secret", key.getKey());
returnMap.put("key", secret);
returnMap.put("uri", uri.toString());
return returnMap;
}
private String formatLabel(String issuer, String accountName) throws OverflowException {
if (accountName != null && accountName.trim().length() != 0) {
StringBuilder sb = new StringBuilder();
if (issuer != null) {
if (issuer.contains(":")) {
throw new IllegalArgumentException("Issuer cannot contain the ':' character.");
}
if (!this.checkCode(secretCode, code)) {
throw new OverflowException("TotpCodeNotMatchException", new Throwable());
}
sb.append(issuer);
sb.append(":");
}
MemberTotp totp = new MemberTotp();
totp.setMember(member);
totp.setSecretCode(secretCode);
this.totpDAO.save(totp);
}
public MemberTotp modify(MemberTotp totp) throws OverflowException {
if (null == totp.getSecretCode() || totp.getSecretCode().equals("")) {
throw new OverflowException("SecretCodeNotExistException", new Throwable());
}
if (null == totp.getMember() || 0 < totp.getMember().getId()) {
throw new OverflowException("SignInIdNotExistException", new Throwable());
}
return this.totpDAO.save(totp);
}
public void remove(Long id) throws OverflowException {
this.totpDAO.deleteById(id);
}
public MemberTotp read(Long id) throws OverflowException {
return this.totpDAO.findById(id).get();
}
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());
}
return this.checkCode(totp.getSecretCode(), code);
}
public boolean checkCode(String secretCode, String code) throws OverflowException {
GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
int codeInt = Integer.parseInt(code);
boolean isCheck = googleAuthenticator.authorize(secretCode, codeInt);
if (!isCheck) {
throw new OverflowException("TotpCodeNotMatchException", new Throwable());
}
return isCheck;
}
public Map<String, String> createTotp(Member member) throws OverflowException {
Map<String, String> returnMap = new HashMap<>();
GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
final GoogleAuthenticatorKey key = googleAuthenticator.createCredentials();
String secret = key.getKey();
// List<Integer> scratchCodes = key.getScratchCodes();
// String otpAuthURL = GoogleAuthenticatorQRGenerator.getOtpAuthURL("overFlow", member.getEmail(), key);
URIBuilder uri = (new URIBuilder()).setScheme("otpauth").setHost("totp")
.setPath("/" + formatLabel("overFlow", member.getEmail())).setParameter("secret", key.getKey());
returnMap.put("key", secret);
returnMap.put("uri", uri.toString());
return returnMap;
}
private String formatLabel(String issuer, String accountName) throws OverflowException {
if (accountName != null && accountName.trim().length() != 0) {
StringBuilder sb = new StringBuilder();
if (issuer != null) {
if (issuer.contains(":")) {
throw new IllegalArgumentException("Issuer cannot contain the ':' character.");
}
sb.append(issuer);
sb.append(":");
}
sb.append(accountName);
return sb.toString();
} else {
throw new IllegalArgumentException("Account name must not be empty.");
}
sb.append(accountName);
return sb.toString();
} else {
throw new IllegalArgumentException("Account name must not be empty.");
}
}
}

View File

@ -11,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaCrawlerInputItemDAO extends JpaRepository<MetaCrawlerInputItem, Integer> {
List<MetaCrawlerInputItem> findAllByMetaCrawlerId(Short metaCrawlerId);
List<MetaCrawlerInputItem> findAllByMetaCrawlerId(Short metaCrawlerId);
}

View File

@ -11,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaInfraVendorDAO extends JpaRepository<MetaInfraVendor, Integer> {
List<MetaInfraVendor> findAllByMetaInfraTypeId(Integer MetaInfraTypeId);
List<MetaInfraVendor> findAllByMetaInfraTypeId(Integer MetaInfraTypeId);
}

View File

@ -11,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaProbePackageDAO extends JpaRepository<MetaProbePackage, Long> {
List<MetaProbePackage> findAllByMetaProbeOsId(Short metaProbeOsId);
List<MetaProbePackage> findAllByMetaProbeOsId(Short metaProbeOsId);
}

View File

@ -8,6 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by snoop on 17. 6. 26.
*/
@Repository
public interface MetaProbeStatusDAO extends JpaRepository<MetaProbeStatus, Short> {
public interface MetaProbeStatusDAO extends JpaRepository<MetaProbeStatus, Short> {
}

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23.
*/
@Repository
public interface MetaProbeTaskTypeDAO extends JpaRepository<MetaProbeTaskType, Short>{
public interface MetaProbeTaskTypeDAO extends JpaRepository<MetaProbeTaskType, Short> {
}

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23.
*/
@Repository
public interface MetaProbeVersionDAO extends JpaRepository<MetaProbeVersion, Short>{
public interface MetaProbeVersionDAO extends JpaRepository<MetaProbeVersion, Short> {
}

View File

@ -11,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaSensorDisplayItemDAO extends JpaRepository<MetaSensorDisplayItem, Long> {
public List<MetaSensorDisplayItem> findAllByMetaCrawlerId(Short metaCrawlerId);
public List<MetaSensorDisplayItem> findAllByMetaCrawlerId(Short metaCrawlerId);
}

View File

@ -15,6 +15,7 @@ import java.util.List;
@Repository
public interface MetaSensorDisplayMappingDAO extends JpaRepository<MetaSensorDisplayMapping, Short> {
@Query("SELECT m.metaSensorItemKey from MetaSensorDisplayMapping m where m.metaSensorDisplayItem.id = :metaSensorDisplayItemId")
public List<MetaSensorItemKey> findAllMetaSensorItemKeyByMetaSensorDisplayItemId(@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId);
@Query("SELECT m.metaSensorItemKey from MetaSensorDisplayMapping m where m.metaSensorDisplayItem.id = :metaSensorDisplayItemId")
public List<MetaSensorItemKey> findAllMetaSensorItemKeyByMetaSensorDisplayItemId(
@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId);
}

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23.
*/
@Repository
public interface MetaSensorItemDAO extends JpaRepository<MetaSensorItem, Integer>{
public interface MetaSensorItemDAO extends JpaRepository<MetaSensorItem, Integer> {
}

View File

@ -11,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaSensorItemKeyDAO extends JpaRepository<MetaSensorItemKey, Long> {
List<MetaSensorItemKey> findAllByMetaCrawlerId(Short metaCrawlerId);
List<MetaSensorItemKey> findAllByMetaCrawlerId(Short metaCrawlerId);
}

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23.
*/
@Repository
public interface MetaSensorItemTypeDAO extends JpaRepository<MetaSensorItemType, Short>{
public interface MetaSensorItemTypeDAO extends JpaRepository<MetaSensorItemType, Short> {
}

View File

@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface MetaSensorStatusDAO extends JpaRepository<MetaSensorStatus, Short> {
public interface MetaSensorStatusDAO extends JpaRepository<MetaSensorStatus, Short> {
}

View File

@ -11,5 +11,5 @@ import java.util.List;
*/
@Repository
public interface MetaVendorCrawlerDAO extends JpaRepository<MetaVendorCrawler, Integer> {
List<MetaVendorCrawler> findAllByMetaInfraVendorId(Integer metaInfraVendorId);
List<MetaVendorCrawler> findAllByMetaInfraVendorId(Integer metaInfraVendorId);
}

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23.
*/
@Repository
public interface MetaVendorCrawlerSensorItemDAO extends JpaRepository<MetaVendorCrawlerSensorItem, Long>{
public interface MetaVendorCrawlerSensorItemDAO extends JpaRepository<MetaVendorCrawlerSensorItem, Long> {
}

View File

@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service;
import com.loafle.overflow.central.module.meta.dao.MetaCrawlerInputItemDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.model.meta.MetaCrawlerInputItem;
import com.loafle.overflow.service.central.meta.MetaCrawlerInputItemService;
import org.springframework.beans.factory.annotation.Autowired;
@ -16,10 +15,10 @@ import java.util.List;
@Service("MetaCrawlerInputItemService")
public class CentralMetaCrawlerInputItemService implements MetaCrawlerInputItemService {
@Autowired
private MetaCrawlerInputItemDAO crawlerInputItemDAO;
@Autowired
private MetaCrawlerInputItemDAO crawlerInputItemDAO;
public List<MetaCrawlerInputItem> readAllByMetaCrawlerID(Short metaCrawlerID) throws OverflowException {
return this.crawlerInputItemDAO.findAllByMetaCrawlerId(metaCrawlerID);
}
public List<MetaCrawlerInputItem> readAllByMetaCrawlerID(Short metaCrawlerID) throws OverflowException {
return this.crawlerInputItemDAO.findAllByMetaCrawlerId(metaCrawlerID);
}
}

View File

@ -14,10 +14,10 @@ import java.util.List;
@Service("MetaCrawlerService")
public class CentralMetaCrawlerService {
@Autowired
private MetaCrawlerDAO crawlerDAO;
@Autowired
private MetaCrawlerDAO crawlerDAO;
public List<MetaCrawler> readAll() throws OverflowException {
return this.crawlerDAO.findAll();
}
public List<MetaCrawler> readAll() throws OverflowException {
return this.crawlerDAO.findAll();
}
}

View File

@ -16,18 +16,18 @@ import java.util.List;
@Service("MetaHistoryTypeService")
public class CentralMetaHistoryTypeService implements MetaHistoryTypeService {
@Autowired
private MetaHistoryTypeDAO hisotyTypeDAO;
@Autowired
private MetaHistoryTypeDAO hisotyTypeDAO;
public List<MetaHistoryType> readAll() throws OverflowException {
return this.hisotyTypeDAO.findAll();
}
public List<MetaHistoryType> readAll() throws OverflowException {
return this.hisotyTypeDAO.findAll();
}
public MetaHistoryType regist(MetaHistoryType type) throws OverflowException {
return this.hisotyTypeDAO.save(type);
}
public MetaHistoryType regist(MetaHistoryType type) throws OverflowException {
return this.hisotyTypeDAO.save(type);
}
public List<MetaHistoryType> registAll(List<MetaHistoryType> metaHistoryTypes) throws OverflowException {
return (List<MetaHistoryType>)this.hisotyTypeDAO.saveAll(metaHistoryTypes);
}
public List<MetaHistoryType> registAll(List<MetaHistoryType> metaHistoryTypes) throws OverflowException {
return (List<MetaHistoryType>) this.hisotyTypeDAO.saveAll(metaHistoryTypes);
}
}

View File

@ -16,10 +16,10 @@ import java.util.List;
@Service("MetaInfraTypeService")
public class CentralMetaInfraTypeService implements MetaInfraTypeService {
@Autowired
private MetaInfraTypeDAO infraTypeDAO;
@Autowired
private MetaInfraTypeDAO infraTypeDAO;
public List<MetaInfraType> readAll() throws OverflowException {
return this.infraTypeDAO.findAll();
}
public List<MetaInfraType> readAll() throws OverflowException {
return this.infraTypeDAO.findAll();
}
}

View File

@ -16,11 +16,11 @@ import java.util.List;
@Service("MetaInfraVendorService")
public class CentralMetaInfraVendorService implements MetaInfraVendorService {
@Autowired
private MetaInfraVendorDAO infraVendorDAO;
@Autowired
private MetaInfraVendorDAO infraVendorDAO;
public List<MetaInfraVendor> readAllByMetaInfraTypeID(Integer metaInfraTypeID) throws OverflowException {
return this.infraVendorDAO.findAllByMetaInfraTypeId(metaInfraTypeID);
}
public List<MetaInfraVendor> readAllByMetaInfraTypeID(Integer metaInfraTypeID) throws OverflowException {
return this.infraVendorDAO.findAllByMetaInfraTypeId(metaInfraTypeID);
}
}

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaInputTypeService")
public class CentralMetaInputTypeService implements MetaInputTypeService {
@Autowired
private MetaInputTypeDAO inputTypeDAO;
@Autowired
private MetaInputTypeDAO inputTypeDAO;
public List<MetaInputType> readAll() throws OverflowException {
return this.inputTypeDAO.findAll();
}
public List<MetaInputType> readAll() throws OverflowException {
return this.inputTypeDAO.findAll();
}
}

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaMemberStatusService")
public class CentralMetaMemberStatusService implements MetaMemberStatusService {
@Autowired
private MetaMemberStatusDAO memberStatusDAO;
@Autowired
private MetaMemberStatusDAO memberStatusDAO;
public List<MetaMemberStatus> readAll() throws OverflowException {
return this.memberStatusDAO.findAll();
}
public List<MetaMemberStatus> readAll() throws OverflowException {
return this.memberStatusDAO.findAll();
}
}

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaNoAuthProbeStatusService")
public class CentralMetaNoAuthProbeStatusService implements MetaNoAuthProbeStatusService {
@Autowired
private MetaNoAuthProbeStatusDAO noAuthProbeStatusDAO;
@Autowired
private MetaNoAuthProbeStatusDAO noAuthProbeStatusDAO;
public List<MetaNoAuthProbeStatus> readAll() throws OverflowException {
return this.noAuthProbeStatusDAO.findAll();
}
public List<MetaNoAuthProbeStatus> readAll() throws OverflowException {
return this.noAuthProbeStatusDAO.findAll();
}
}

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaProbeArchitectureService")
public class CentralMetaProbeArchitectureService implements MetaProbeArchitectureService {
@Autowired
private MetaProbeArchitectureDAO probeArchitectureDAO;
@Autowired
private MetaProbeArchitectureDAO probeArchitectureDAO;
public List<MetaProbeArchitecture> readAll() throws OverflowException {
return this.probeArchitectureDAO.findAll();
}
public List<MetaProbeArchitecture> readAll() throws OverflowException {
return this.probeArchitectureDAO.findAll();
}
}

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaProbeOsService")
public class CentralMetaProbeOsService implements MetaProbeOsService {
@Autowired
private MetaProbeOsDAO probeOsDAO;
@Autowired
private MetaProbeOsDAO probeOsDAO;
public List<MetaProbeOs> readAll() throws OverflowException {
return this.probeOsDAO.findAll();
}
public List<MetaProbeOs> readAll() throws OverflowException {
return this.probeOsDAO.findAll();
}
}

View File

@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service;
import com.loafle.overflow.central.module.meta.dao.MetaProbePackageDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.meta.MetaProbeOs;
import com.loafle.overflow.model.meta.MetaProbePackage;
import com.loafle.overflow.service.central.meta.MetaProbePackageService;
import org.springframework.beans.factory.annotation.Autowired;
@ -16,10 +15,10 @@ import java.util.List;
@Service("MetaProbePackageService")
public class CentralMetaProbePackageService implements MetaProbePackageService {
@Autowired
private MetaProbePackageDAO probePackageDAO;
@Autowired
private MetaProbePackageDAO probePackageDAO;
public List<MetaProbePackage> readAllByMetaProbeOsID(Short metaProbeOsID) throws OverflowException {
return this.probePackageDAO.findAllByMetaProbeOsId(metaProbeOsID);
}
public List<MetaProbePackage> readAllByMetaProbeOsID(Short metaProbeOsID) throws OverflowException {
return this.probePackageDAO.findAllByMetaProbeOsId(metaProbeOsID);
}
}

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaProbeStatusService")
public class CentralMetaProbeStatusService implements MetaProbeStatusService {
@Autowired
private MetaProbeStatusDAO probeStatusDAO;
@Autowired
private MetaProbeStatusDAO probeStatusDAO;
public List<MetaProbeStatus> readAll() throws OverflowException {
return this.probeStatusDAO.findAll();
}
public List<MetaProbeStatus> readAll() throws OverflowException {
return this.probeStatusDAO.findAll();
}
}

View File

@ -16,10 +16,10 @@ import java.util.List;
@Service("MetaProbeTaskTypeService")
public class CentralMetaProbeTaskTypeService implements MetaProbeTaskTypeService {
@Autowired
private MetaProbeTaskTypeDAO probeTaskTypeDAO;
@Autowired
private MetaProbeTaskTypeDAO probeTaskTypeDAO;
public List<MetaProbeTaskType> readAll() throws OverflowException {
return this.probeTaskTypeDAO.findAll();
}
public List<MetaProbeTaskType> readAll() throws OverflowException {
return this.probeTaskTypeDAO.findAll();
}
}

View File

@ -16,10 +16,10 @@ import java.util.List;
@Service("MetaProbeVersionService")
public class CentralMetaProbeVersionService implements MetaProbeVersionService {
@Autowired
private MetaProbeVersionDAO probeVersionDAO;
@Autowired
private MetaProbeVersionDAO probeVersionDAO;
public List<MetaProbeVersion> readAll() throws OverflowException {
return this.probeVersionDAO.findAll();
}
public List<MetaProbeVersion> readAll() throws OverflowException {
return this.probeVersionDAO.findAll();
}
}

View File

@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service;
import com.loafle.overflow.central.module.meta.dao.MetaSensorDisplayItemDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.model.meta.MetaSensorDisplayItem;
import com.loafle.overflow.service.central.meta.MetaSensorDisplayItemService;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,18 +14,18 @@ import java.util.List;
*/
@Service("MetaSensorDisplayItemService")
public class CentralMetaSensorDisplayItemService implements MetaSensorDisplayItemService {
@Autowired
private MetaSensorDisplayItemDAO displayItemDAO;
@Autowired
private MetaSensorDisplayItemDAO displayItemDAO;
public MetaSensorDisplayItem regist(MetaSensorDisplayItem item) throws OverflowException {
return this.displayItemDAO.save(item);
}
public MetaSensorDisplayItem regist(MetaSensorDisplayItem item) throws OverflowException {
return this.displayItemDAO.save(item);
}
public MetaSensorDisplayItem read(Long id) throws OverflowException {
return this.displayItemDAO.findById(id).get();
}
public MetaSensorDisplayItem read(Long id) throws OverflowException {
return this.displayItemDAO.findById(id).get();
}
public List<MetaSensorDisplayItem> readAllByCrawlerID(Short metaCrawlerID) throws OverflowException {
return this.displayItemDAO.findAllByMetaCrawlerId(metaCrawlerID);
}
public List<MetaSensorDisplayItem> readAllByCrawlerID(Short metaCrawlerID) throws OverflowException {
return this.displayItemDAO.findAllByMetaCrawlerId(metaCrawlerID);
}
}

View File

@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service;
import com.loafle.overflow.central.module.meta.dao.MetaSensorDisplayMappingDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.meta.MetaSensorDisplayItem;
import com.loafle.overflow.model.meta.MetaSensorDisplayMapping;
import com.loafle.overflow.model.meta.MetaSensorItemKey;
import com.loafle.overflow.service.central.meta.MetaSensorDisplayMappingService;
@ -16,14 +15,15 @@ import java.util.List;
*/
@Service("MetaSensorDisplayMappingService")
public class CentralMetaSensorDisplayMappingService implements MetaSensorDisplayMappingService {
@Autowired
private MetaSensorDisplayMappingDAO mappingDAO;
@Autowired
private MetaSensorDisplayMappingDAO mappingDAO;
public MetaSensorDisplayMapping regist(MetaSensorDisplayMapping m) throws OverflowException {
return this.mappingDAO.save(m);
}
public MetaSensorDisplayMapping regist(MetaSensorDisplayMapping m) throws OverflowException {
return this.mappingDAO.save(m);
}
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByDisplayItemID(Long metaSensorDisplayItemID) throws OverflowException {
return this.mappingDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID);
}
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByDisplayItemID(Long metaSensorDisplayItemID)
throws OverflowException {
return this.mappingDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID);
}
}

View File

@ -16,18 +16,18 @@ import java.util.List;
@Service("MetaSensorItemTypeService")
public class CentralMetaSensorItemTypeService implements MetaSensorItemTypeService {
@Autowired
private MetaSensorItemTypeDAO sensorItemTypeDAO;
@Autowired
private MetaSensorItemTypeDAO sensorItemTypeDAO;
public List<MetaSensorItemType> readAll() throws OverflowException {
return this.sensorItemTypeDAO.findAll();
}
public List<MetaSensorItemType> readAll() throws OverflowException {
return this.sensorItemTypeDAO.findAll();
}
public MetaSensorItemType regist(MetaSensorItemType type) throws OverflowException {
return this.sensorItemTypeDAO.save(type);
}
public MetaSensorItemType regist(MetaSensorItemType type) throws OverflowException {
return this.sensorItemTypeDAO.save(type);
}
public List<MetaSensorItemType> registAll(List<MetaSensorItemType> list) throws OverflowException {
return (List<MetaSensorItemType>)this.sensorItemTypeDAO.saveAll(list);
}
public List<MetaSensorItemType> registAll(List<MetaSensorItemType> list) throws OverflowException {
return (List<MetaSensorItemType>) this.sensorItemTypeDAO.saveAll(list);
}
}

View File

@ -13,10 +13,10 @@ import org.springframework.stereotype.Service;
@Service("MetaSensorItemUnitService")
public class CentralMetaSensorItemUnitService implements MetaSensorItemUnitService {
@Autowired
private MetaSensorItemUnitDAO sensorItemUnitDAO;
@Autowired
private MetaSensorItemUnitDAO sensorItemUnitDAO;
public MetaSensorItemUnit regist(MetaSensorItemUnit sensorItemUnit) throws OverflowException {
return this.sensorItemUnitDAO.save(sensorItemUnit);
}
public MetaSensorItemUnit regist(MetaSensorItemUnit sensorItemUnit) throws OverflowException {
return this.sensorItemUnitDAO.save(sensorItemUnit);
}
}

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaSensorStatusService")
public class CentralMetaSensorStatusService implements MetaSensorStatusService {
@Autowired
private MetaSensorStatusDAO sensorStatusDAO;
@Autowired
private MetaSensorStatusDAO sensorStatusDAO;
public List<MetaSensorStatus> readAll() throws OverflowException {
return this.sensorStatusDAO.findAll();
}
public List<MetaSensorStatus> readAll() throws OverflowException {
return this.sensorStatusDAO.findAll();
}
}

View File

@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service;
import com.loafle.overflow.central.module.meta.dao.MetaVendorCrawlerDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.meta.MetaInfraVendor;
import com.loafle.overflow.model.meta.MetaVendorCrawler;
import com.loafle.overflow.service.central.meta.MetaVendorCrawlerService;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,15 +16,15 @@ import java.util.List;
@Service("MetaVendorCrawlerService")
public class CentralMetaVendorCrawlerService implements MetaVendorCrawlerService {
@Autowired
private MetaVendorCrawlerDAO crawlerDAO;
@Autowired
private MetaVendorCrawlerDAO crawlerDAO;
public List<MetaVendorCrawler> readAllByMetaInfraVendorID(Integer metaInfraVendorID) throws OverflowException {
public List<MetaVendorCrawler> readAllByMetaInfraVendorID(Integer metaInfraVendorID) throws OverflowException {
return this.crawlerDAO.findAllByMetaInfraVendorId(metaInfraVendorID);
}
return this.crawlerDAO.findAllByMetaInfraVendorId(metaInfraVendorID);
}
public MetaVendorCrawler regist(MetaVendorCrawler metaVendorCrawler) throws OverflowException {
return this.crawlerDAO.save(metaVendorCrawler);
}
public MetaVendorCrawler regist(MetaVendorCrawler metaVendorCrawler) throws OverflowException {
return this.crawlerDAO.save(metaVendorCrawler);
}
}

View File

@ -13,16 +13,19 @@ import java.util.List;
@Repository
public interface NoAuthProbeDAO extends JpaRepository<NoAuthProbe, Long> {
NoAuthProbe findByTempProbeKey(String tempProbeKey);
NoAuthProbe findByTempProbeKey(String tempProbeKey);
List<NoAuthProbe> findAllByDomainIdAndMetaNoAuthProbeStatusId(Long domainID, Short metaNoAuthProbeStatusId);
List<NoAuthProbe> findAllByDomainIdAndMetaNoAuthProbeStatusId(Long domainID, Short metaNoAuthProbeStatusId);
// NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent);
// List<NoAuthProbeDeprecate> findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent);
// @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey")
// @Query("select m from Member m WHERE m.email = :#{#m2.email}")
// NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent);
// List<NoAuthProbeDeprecate> findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent);
// @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey")
// @Query("select m from Member m WHERE m.email = :#{#m2.email}")
// @Modifying(clearAutomatically = true)
// @Query("UPDATE NoAuthProbe n set n.connectDate = :connectDate, n.connectAddress = :connectAddress where n.tempProbeKey = :tempProbeKey")
// int saveConnect(@Param("tempProbeKey") String tempProbeKey, @Param("connectDate") Date connectDate, @Param("connectAddress") String connectAddress);
// @Modifying(clearAutomatically = true)
// @Query("UPDATE NoAuthProbe n set n.connectDate = :connectDate,
// n.connectAddress = :connectAddress where n.tempProbeKey = :tempProbeKey")
// int saveConnect(@Param("tempProbeKey") String tempProbeKey,
// @Param("connectDate") Date connectDate, @Param("connectAddress") String
// connectAddress);
}

View File

@ -15,11 +15,11 @@ import java.util.List;
@Repository
public interface NotificationDAO extends JpaRepository<Notification, Long> {
List<Notification> findAllByMemberEmail(String memberEmail);
List<Notification> findAllByMemberEmail(String memberEmail);
Page<Notification> findAllByMemberEmail(String memberEmail, Pageable pageRequest);
Page<Notification> findAllByMemberEmail(String memberEmail, Pageable pageRequest);
Page<Notification> findAllByMemberEmailAndConfirmDateNull(String memberEmail, Pageable pageRequest);
Page<Notification> findAllByMemberEmailAndConfirmDateNull(String memberEmail, Pageable pageRequest);
Long countByMemberEmailAndConfirmDateNull(String memberEmail);
Long countByMemberEmailAndConfirmDateNull(String memberEmail);
}

View File

@ -4,7 +4,6 @@ import com.loafle.overflow.central.commons.utils.PageUtil;
import com.loafle.overflow.central.module.notification.dao.NotificationDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.model.PageParams;
import com.loafle.overflow.model.member.Member;
import com.loafle.overflow.model.notification.Notification;
import com.loafle.overflow.service.central.notification.NotificationService;
@ -21,51 +20,51 @@ import java.util.List;
@Service("NotificationService")
public class CentralNotificationService implements NotificationService {
@Autowired
private NotificationDAO notificationDAO;
@Autowired
private NotificationDAO notificationDAO;
public Notification regist(Notification notification) throws OverflowException {
return this.notificationDAO.save(notification);
}
public Notification regist(Notification notification) throws OverflowException {
return this.notificationDAO.save(notification);
}
public Page<Notification> readAllByMemberEmail(String memberEmail, PageParams pageParams) throws OverflowException {
return this.notificationDAO.findAllByMemberEmail(memberEmail, PageUtil.getPageRequest(pageParams));
}
public Page<Notification> readAllByMemberEmail(String memberEmail, PageParams pageParams) throws OverflowException {
return this.notificationDAO.findAllByMemberEmail(memberEmail, PageUtil.getPageRequest(pageParams));
}
public Page<Notification> readAllUnconfirmedByMemberEmail(String memberEmail, PageParams pageParams)
throws OverflowException {
return this.notificationDAO.findAllByMemberEmailAndConfirmDateNull(memberEmail,
PageUtil.getPageRequest(pageParams));
}
public Page<Notification> readAllUnconfirmedByMemberEmail(String memberEmail, PageParams pageParams)
throws OverflowException {
return this.notificationDAO.findAllByMemberEmailAndConfirmDateNull(memberEmail,
PageUtil.getPageRequest(pageParams));
}
public Long readUnconfirmedCountByMemberEmail(String memberEmail) throws OverflowException {
return this.notificationDAO.countByMemberEmailAndConfirmDateNull(memberEmail);
}
public Long readUnconfirmedCountByMemberEmail(String memberEmail) throws OverflowException {
return this.notificationDAO.countByMemberEmailAndConfirmDateNull(memberEmail);
}
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.saveAll(list);
return this.readAllByMemberEmail(memberEmail, pageParams);
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.saveAll(list);
return this.readAllByMemberEmail(memberEmail, pageParams);
}
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.saveAll(list);
return this.readAllByMemberEmail(memberEmail, pageParams);
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.saveAll(list);
return this.readAllByMemberEmail(memberEmail, pageParams);
}
public Notification markAsRead(Long notificationID) throws OverflowException {
Notification notification = this.notificationDAO.findById(notificationID).get();
notification.setConfirmDate(new Date());
return this.notificationDAO.save(notification);
}
public Notification markAsRead(Long notificationID) throws OverflowException {
Notification notification = this.notificationDAO.findById(notificationID).get();
notification.setConfirmDate(new Date());
return this.notificationDAO.save(notification);
}
}

View File

@ -7,17 +7,19 @@ import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Created by insanity on 17. 5. 29.
*/
@Repository
public interface ProbeDAO extends JpaRepository<Probe, Long> {
Probe findByProbeKey(String probeKey);
List<Probe> findAllByDomainIdOrderByIdDesc(Long domainID);
Probe findByProbeKey(String probeKey);
// @Modifying(clearAutomatically = true)
// @Query("UPDATE Probe p set p.connectDate = :connectDate, p.connectAddress = :connectAddress where p.probeKey = :probeKey")
// int saveConnect(@Param("probeKey") String probeKey, @Param("connectDate") Date connectDate, @Param("connectAddress") String connectAddress);
List<Probe> findAllByDomainIdOrderByIdDesc(Long domainID);
// @Modifying(clearAutomatically = true)
// @Query("UPDATE Probe p set p.connectDate = :connectDate, p.connectAddress =
// :connectAddress where p.probeKey = :probeKey")
// int saveConnect(@Param("probeKey") String probeKey, @Param("connectDate")
// Date connectDate, @Param("connectAddress") String connectAddress);
}

View File

@ -12,7 +12,7 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface ProbeHostDAO extends JpaRepository<ProbeHost, Long> {
ProbeHost findByProbeId(Long probeID);
ProbeHost findByProbeId(Long probeID);
List<ProbeHost> findAllByProbeDomainId(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

@ -16,22 +16,22 @@ import org.springframework.stereotype.Service;
@Service("ProbeHostService")
public class CentralProbeHostService implements ProbeHostService {
@Autowired
private ProbeHostDAO probeHostDAO;
@Autowired
private ProbeHostDAO probeHostDAO;
public ProbeHost read(Long id) throws OverflowException {
return this.probeHostDAO.findById(id).get();
}
public ProbeHost read(Long id) throws OverflowException {
return this.probeHostDAO.findById(id).get();
}
public ProbeHost readByProbeID(Long probeID) throws OverflowException {
return this.probeHostDAO.findByProbeId(probeID);
}
public ProbeHost readByProbeID(Long probeID) throws OverflowException {
return this.probeHostDAO.findByProbeId(probeID);
}
public ProbeHost regist(ProbeHost probeHost) throws OverflowException {
return this.probeHostDAO.save(probeHost);
}
public ProbeHost regist(ProbeHost probeHost) throws OverflowException {
return this.probeHostDAO.save(probeHost);
}
public List<ProbeHost> readAllByDomainID(Long domainID) throws OverflowException {
return this.probeHostDAO.findAllByProbeDomainId(domainID);
}
public List<ProbeHost> readAllByDomainID(Long domainID) throws OverflowException {
return this.probeHostDAO.findAllByProbeDomainId(domainID);
}
}

View File

@ -18,77 +18,77 @@ import java.util.List;
@Service("ProbeService")
public class CentralProbeService implements ProbeService {
@Autowired
private ProbeDAO probeDAO;
@Autowired
private MessagePublisher messagePublisher;
@Autowired
private ProbeDAO probeDAO;
@Autowired
private MessagePublisher messagePublisher;
public Probe regist(Probe probe) throws OverflowException {
return this.probeDAO.save(probe);
public Probe regist(Probe probe) throws OverflowException {
return this.probeDAO.save(probe);
}
public List<Probe> regist(List<Probe> probes) throws OverflowException {
return (List<Probe>) this.probeDAO.saveAll(probes);
}
public List<Probe> readAllByDomainID(Long domainID) throws OverflowException {
List<Probe> probes = this.probeDAO.findAllByDomainIdOrderByIdDesc(domainID);
return probes;
}
public Probe read(Long id) throws OverflowException {
return this.probeDAO.findById(id).get();
}
public Probe readByProbeKey(String probeKey) throws OverflowException {
return this.probeDAO.findByProbeKey(probeKey);
}
public Probe modify(Probe probe) throws OverflowException {
return this.probeDAO.save(probe);
}
public boolean remove(Long id) throws OverflowException {
this.probeDAO.deleteById(id);
return true;
}
public Probe increaseTargetCount(Probe probe) {
Probe p = this.probeDAO.findById(probe.getId()).get();
p.setTargetCount(p.getTargetCount() + 1);
return this.probeDAO.save(p);
}
public Probe decreaseTargetCount(Probe probe) {
Probe p = this.probeDAO.findById(probe.getId()).get();
int count = p.getTargetCount();
if (count > 0) {
p.setTargetCount(count - 1);
}
return this.probeDAO.save(p);
}
public List<Probe> regist(List<Probe> probes) throws OverflowException {
return (List<Probe>)this.probeDAO.saveAll(probes);
}
public Probe modifyDisplayName(Long probeId, String displayName) {
Probe probe = this.probeDAO.findById(probeId).get();
probe.setDisplayName(displayName);
return this.probeDAO.save(probe);
}
public List<Probe> readAllByDomainID(Long domainID) throws OverflowException {
List<Probe> probes = this.probeDAO.findAllByDomainIdOrderByIdDesc(domainID);
return probes;
}
public void onConnect(String probeKey, String connectAddress) throws OverflowException {
Probe probe = this.probeDAO.findByProbeKey(probeKey);
probe.setConnectDate(new Date());
probe.setConnectAddress(connectAddress);
probe = this.probeDAO.save(probe);
public Probe read(Long id) throws OverflowException {
return this.probeDAO.findById(id).get();
}
messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onConnect", probe);
}
public Probe readByProbeKey(String probeKey) throws OverflowException {
return this.probeDAO.findByProbeKey(probeKey);
}
public void onDisconnect(String probeKey) throws OverflowException {
Probe probe = this.probeDAO.findByProbeKey(probeKey);
probe.setConnectDate(null);
probe.setConnectAddress(null);
probe = this.probeDAO.save(probe);
public Probe modify(Probe probe) throws OverflowException {
return this.probeDAO.save(probe);
}
public boolean remove(Long id) throws OverflowException {
this.probeDAO.deleteById(id);
return true;
}
public Probe increaseTargetCount(Probe probe) {
Probe p = this.probeDAO.findById(probe.getId()).get();
p.setTargetCount(p.getTargetCount() + 1);
return this.probeDAO.save(p);
}
public Probe decreaseTargetCount(Probe probe) {
Probe p = this.probeDAO.findById(probe.getId()).get();
int count = p.getTargetCount();
if (count > 0) {
p.setTargetCount(count - 1);
}
return this.probeDAO.save(p);
}
public Probe modifyDisplayName(Long probeId, String displayName) {
Probe probe = this.probeDAO.findById(probeId).get();
probe.setDisplayName(displayName);
return this.probeDAO.save(probe);
}
public void onConnect(String probeKey, String connectAddress) throws OverflowException {
Probe probe = this.probeDAO.findByProbeKey(probeKey);
probe.setConnectDate(new Date());
probe.setConnectAddress(connectAddress);
probe = this.probeDAO.save(probe);
messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onConnect", probe);
}
public void onDisconnect(String probeKey) throws OverflowException {
Probe probe = this.probeDAO.findByProbeKey(probeKey);
probe.setConnectDate(null);
probe.setConnectAddress(null);
probe = this.probeDAO.save(probe);
messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onDisconnect", probe);
}
messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onDisconnect", probe);
}
}

View File

@ -14,16 +14,16 @@ import java.util.List;
* Created by snoop on 17. 6. 28.
*/
@Service("ProbeTaskService")
public class CentralProbeTaskService implements ProbeTaskService{
public class CentralProbeTaskService implements ProbeTaskService {
@Autowired
private ProbeTaskDAO probeTaskDAO;
@Autowired
private ProbeTaskDAO probeTaskDAO;
public ProbeTask regist(ProbeTask probeTask) throws OverflowException {
return this.probeTaskDAO.save(probeTask);
}
public ProbeTask regist(ProbeTask probeTask) throws OverflowException {
return this.probeTaskDAO.save(probeTask);
}
public List<ProbeTask> readAllByProbeID(Long probeID) throws OverflowException {
return this.probeTaskDAO.findAllByProbeId(probeID);
}
public List<ProbeTask> readAllByProbeID(Long probeID) throws OverflowException {
return this.probeTaskDAO.findAllByProbeId(probeID);
}
}

View File

@ -15,9 +15,9 @@ import com.loafle.overflow.model.target.Target;
*/
@Repository
public interface SensorDAO extends JpaRepository<Sensor, Long> {
Page<Sensor> findAllByTargetId(Long targetID, Pageable pageable);
Page<Sensor> findAllByTargetId(Long targetID, Pageable pageable);
List<Sensor> findAllByTargetId(Long targetID);
List<Sensor> findAllByTargetId(Long targetID);
Page<Sensor> findAllByTargetIn(List<Target> targets, Pageable pageable);
Page<Sensor> findAllByTargetIn(List<Target> targets, Pageable pageable);
}

View File

@ -12,5 +12,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface SensorItemDAO extends JpaRepository<SensorItem, Long> {
Page<SensorItem> findAllBySensorId(Long sensorId, Pageable pageable);
Page<SensorItem> findAllBySensorId(Long sensorId, Pageable pageable);
}

View File

@ -16,6 +16,7 @@ import java.util.List;
@Repository
public interface SensorItemDependencyDAO extends JpaRepository<SensorItemDependency, Long> {
@Query("SELECT s.metaSensorItemKey from SensorItemDependency s where s.metaSensorDisplayItem.id = :metaSensorDisplayItemId")
List<MetaSensorItemKey> findAllMetaSensorItemKeyByMetaSensorDisplayItemId(@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId);
@Query("SELECT s.metaSensorItemKey from SensorItemDependency s where s.metaSensorDisplayItem.id = :metaSensorDisplayItemId")
List<MetaSensorItemKey> findAllMetaSensorItemKeyByMetaSensorDisplayItemId(
@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId);
}

View File

@ -21,29 +21,29 @@ import java.util.Map;
@Service("SensorItemDependencyService")
public class CentralSensorItemDependencyService implements SensorItemDependencyService {
@Autowired
private SensorItemDependencyDAO sensorItemDependencyDAO;
@Autowired
private SensorItemDependencyDAO sensorItemDependencyDAO;
public SensorItemDependency regist(SensorItemDependency dependency) throws OverflowException {
return this.sensorItemDependencyDAO.save(dependency);
public SensorItemDependency regist(SensorItemDependency dependency) throws OverflowException {
return this.sensorItemDependencyDAO.save(dependency);
}
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByMetaSensorDisplayItemID(Long metaSensorDisplayItemID)
throws OverflowException {
return this.sensorItemDependencyDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID);
}
public Map<String, List<MetaSensorItemKey>> readAllMapByMetaSensorDisplayItems(
List<MetaSensorDisplayItem> metaSensorDisplayItems) throws OverflowException {
Map<String, List<MetaSensorItemKey>> map = new HashMap<String, List<MetaSensorItemKey>>();
for (MetaSensorDisplayItem displayItem : metaSensorDisplayItems) {
List<MetaSensorItemKey> itemKeys = this.sensorItemDependencyDAO
.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(displayItem.getId());
map.put(displayItem.getKey(), itemKeys);
}
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByMetaSensorDisplayItemID(Long metaSensorDisplayItemID)
throws OverflowException {
return this.sensorItemDependencyDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID);
}
public Map<String, List<MetaSensorItemKey>> readAllMapByMetaSensorDisplayItems(
List<MetaSensorDisplayItem> metaSensorDisplayItems) throws OverflowException {
Map<String, List<MetaSensorItemKey>> map = new HashMap<String, List<MetaSensorItemKey>>();
for (MetaSensorDisplayItem displayItem : metaSensorDisplayItems) {
List<MetaSensorItemKey> itemKeys = this.sensorItemDependencyDAO
.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(displayItem.getId());
map.put(displayItem.getKey(), itemKeys);
}
return map;
}
return map;
}
}

View File

@ -22,41 +22,41 @@ import java.util.List;
@Service("SensorItemService")
public class CentralSensorItemService implements SensorItemService {
@Autowired
private SensorItemDAO sensorItemDAO;
@Autowired
private SensorDAO sensorDAO;
@Autowired
private SensorItemDAO sensorItemDAO;
@Autowired
private SensorDAO sensorDAO;
@Transactional
public SensorItem regist(SensorItem sensorItem) throws OverflowException {
Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get();
s.setItemCount((short) (s.getItemCount() + 1));
this.sensorDAO.save(s);
return this.sensorItemDAO.save(sensorItem);
}
@Transactional
public SensorItem regist(SensorItem sensorItem) throws OverflowException {
Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get();
s.setItemCount((short) (s.getItemCount() + 1));
this.sensorDAO.save(s);
return this.sensorItemDAO.save(sensorItem);
}
@Transactional
public boolean registAll(List<SensorItem> sensorItemList) throws OverflowException {
Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get();
s.setItemCount((short) sensorItemList.size());
this.sensorDAO.save(s);
this.sensorItemDAO.saveAll(sensorItemList);
return true;
}
@Transactional
public boolean registAll(List<SensorItem> sensorItemList) throws OverflowException {
Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get();
s.setItemCount((short) sensorItemList.size());
this.sensorDAO.save(s);
this.sensorItemDAO.saveAll(sensorItemList);
return true;
}
public SensorItem read(String id) throws OverflowException {
return this.sensorItemDAO.findById(Long.valueOf(id)).get();
}
public SensorItem read(String id) throws OverflowException {
return this.sensorItemDAO.findById(Long.valueOf(id)).get();
}
public Page<SensorItem> readAllBySensorID(Long sensorID, PageParams pageParams) throws OverflowException {
return this.sensorItemDAO.findAllBySensorId(sensorID, 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));
this.sensorDAO.save(s);
this.sensorItemDAO.delete(sensorItem);
}
@Transactional
public void remove(SensorItem sensorItem) throws OverflowException {
Sensor s = sensorItem.getSensor();
s.setItemCount((short) (s.getItemCount() - 1));
this.sensorDAO.save(s);
this.sensorItemDAO.delete(sensorItem);
}
}

View File

@ -5,8 +5,6 @@ import com.loafle.overflow.central.module.generator.service.SensorConfigGenerato
import com.loafle.overflow.central.module.sensor.dao.SensorDAO;
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.infra.Infra;
import com.loafle.overflow.model.meta.MetaSensorStatus;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.model.sensor.Sensor;
@ -31,109 +29,112 @@ import java.util.List;
@Service("SensorService")
public class CentralSensorService implements SensorService {
@Autowired
SensorDAO sensorDAO;
@Autowired
SensorDAO sensorDAO;
@Autowired
private ProbeService probeService;
@Autowired
private ProbeService probeService;
@Autowired
private InfraService infraService;
@Autowired
private InfraService infraService;
@Autowired
private SensorItemService sensorItemService;
@Autowired
private SensorItemService sensorItemService;
@Autowired
private SensorConfigGenerator sensorConfigGenerator;
@Autowired
private SensorConfigGenerator sensorConfigGenerator;
@Autowired
private TargetService targetService;
@Autowired
private TargetService targetService;
@Transactional
public Sensor regist(Sensor sensor) throws OverflowException {
this.targetService.increaseSensorCount(sensor.getTarget());
return this.sensorDAO.save(sensor);
@Transactional
public Sensor regist(Sensor sensor) throws OverflowException {
this.targetService.increaseSensorCount(sensor.getTarget());
return this.sensorDAO.save(sensor);
}
public Page<Sensor> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
if (probeList == null || probeList.size() <= 0) {
throw new OverflowException("", new Throwable());
}
public Page<Sensor> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
List<Target> targetList = this.infraService.readAllTargetByProbes(probeList);
List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
if (probeList == null || probeList.size() <= 0) {
throw new OverflowException("", new Throwable());
}
List<Target> targetList = this.infraService.readAllTargetByProbes(probeList);
if (targetList == null || targetList.size() <= 0) {
throw new OverflowException("", new Throwable());
}
return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams));
if (targetList == null || targetList.size() <= 0) {
throw new OverflowException("", new Throwable());
}
public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
// Infra dbInfra = this.infraService.read(infraID);
// if (dbInfra == null) {
// throw new OverflowException("", new Throwable());
// }
// return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), PageUtil.getPageRequest(pageParams));
return null;
return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams));
}
public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
// Infra dbInfra = this.infraService.read(infraID);
// if (dbInfra == null) {
// throw new OverflowException("", new Throwable());
// }
// return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(),
// PageUtil.getPageRequest(pageParams));
return null;
}
public Page<Sensor> readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException {
return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams));
}
public Sensor read(Long id) throws OverflowException {
return this.sensorDAO.findById(Long.valueOf(id)).get();
}
@Transactional
public void remove(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findById(sensorID).get();
this.targetService.decreaseSensorCount(sensor.getTarget());
this.sensorDAO.delete(sensor);
}
public Sensor start(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findById(sensorID).get();
MetaSensorStatus status = new MetaSensorStatus((short) 1);
sensor.setMetaSensorStatus(status);
return this.sensorDAO.save(sensor);
}
public Sensor stop(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findById(sensorID).get();
MetaSensorStatus status = new MetaSensorStatus((short) 2);
sensor.setMetaSensorStatus(status);
return this.sensorDAO.save(sensor);
}
@Transactional
public Sensor registSensorConfig(Sensor sensor, List<SensorItem> sensorItemList, String etcJson)
throws OverflowException {
this.targetService.increaseSensorCount(sensor.getTarget());
this.sensorDAO.save(sensor);
for (SensorItem sensorItem : sensorItemList) {
sensorItem.setSensor(sensor);
}
public Page<Sensor> readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException {
return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams));
this.sensorItemService.registAll(sensorItemList);
return sensor;
}
public String generateSensorConfig(Sensor sensor) throws OverflowException {
try {
return this.sensorConfigGenerator.generate(sensor);
} catch (Exception e) {
throw new OverflowException("", new Throwable());
}
}
public Sensor read(Long id) throws OverflowException {
return this.sensorDAO.findById(Long.valueOf(id)).get();
}
@Transactional
public void remove(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findById(sensorID).get();
this.targetService.decreaseSensorCount(sensor.getTarget());
this.sensorDAO.delete(sensor);
}
public Sensor start(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findById(sensorID).get();
MetaSensorStatus status = new MetaSensorStatus((short) 1);
sensor.setMetaSensorStatus(status);
return this.sensorDAO.save(sensor);
}
public Sensor stop(Long sensorID) throws OverflowException {
Sensor sensor = this.sensorDAO.findById(sensorID).get();
MetaSensorStatus status = new MetaSensorStatus((short) 2);
sensor.setMetaSensorStatus(status);
return this.sensorDAO.save(sensor);
}
@Transactional
public Sensor registSensorConfig(Sensor sensor, List<SensorItem> sensorItemList, String etcJson) throws OverflowException {
this.targetService.increaseSensorCount(sensor.getTarget());
this.sensorDAO.save(sensor);
for (SensorItem sensorItem : sensorItemList) {
sensorItem.setSensor(sensor);
}
this.sensorItemService.registAll(sensorItemList);
return sensor;
}
public String generateSensorConfig(Sensor sensor) throws OverflowException {
try {
return this.sensorConfigGenerator.generate(sensor);
} catch (Exception e) {
throw new OverflowException("", new Throwable());
}
}
// public List<Sensor> readAllByTarget(Target target, PageParams pageParams) {
// return this.sensorDAO.findAllByTarget(target, PageUtil.getPageRequest(pageParams));
// }
// public List<Sensor> readAllByTarget(Target target, PageParams pageParams) {
// return this.sensorDAO.findAllByTarget(target,
// PageUtil.getPageRequest(pageParams));
// }
}

View File

@ -13,8 +13,9 @@ import org.springframework.stereotype.Repository;
public interface TargetDAO extends JpaRepository<Target, Long> {
Target findByInfraId(Long infraId);
// @Query("select t.infra from target t where t.infra.probe.id = :probeId")
// Page<Target> findForProbeId(@Param("probeId") Long probeId, Pageable pageRequest);
// @Query("select t.infra from target t where t.infra.probe.id = :probeId")
// Page<Target> findForProbeId(@Param("probeId") Long probeId, Pageable
// pageRequest);
Page<Target> findAllByInfraProbeId(Long probeId, Pageable pageRequest);
}

View File

@ -19,208 +19,219 @@
// import java.util.List;
// /**
// * Created by snoop on 17. 6. 28.
// */
// * Created by snoop on 17. 6. 28.
// */
// @Service("TargetDiscoveryService")
// public class CentralTargetDiscoveryService implements TargetDiscoveryService {
// public class CentralTargetDiscoveryService implements TargetDiscoveryService
// {
// @Autowired
// private TargetService targetService;
// @Autowired
// private TargetService targetService;
// @Autowired
// private CentralInfraMachineService infraMachineService;
// @Autowired
// private CentralInfraMachineService infraMachineService;
// @Autowired
// private CentralInfraOSService infraOSService;
// @Autowired
// private CentralInfraOSService infraOSService;
// @Autowired
// private CentralInfraHostService infraHostService;
// @Autowired
// private CentralInfraHostService infraHostService;
// // @Autowired
// // private CentralInfraService infraService;
// // @Autowired
// // private CentralInfraService infraService;
// @Autowired
// private CentralInfraOSPortService infraOSPortService;
// @Autowired
// private CentralInfraOSPortService infraOSPortService;
// @Autowired
// private CentralInfraServiceService infraServiceService;
// @Autowired
// private CentralInfraServiceService infraServiceService;
// @Transactional
// public boolean saveAllTarget(List<Host> hosts, Probe probe) throws OverflowException {
// @Transactional
// public boolean saveAllTarget(List<Host> hosts, Probe probe) throws
// OverflowException {
// InfraHost infraHost = null;
// InfraHost infraHost = null;
// for (Host host : hosts) {
// for (Host host : hosts) {
// infraHost = this.createAndReadHost(host, probe);
// infraHost = this.createAndReadHost(host, probe);
// this.createPort(infraHost, host, probe);
// }
// return true;
// }
// private void createService(InfraHost infraHost, Port port, Probe probe) throws OverflowException {
// MetaInfraType typeService = new MetaInfraType(7);
// String portType = "UDP";
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) {
// portType = "TCP";
// }
// if (port.getServiceList() == null) {
// return;
// }
// // for(String key : port.getServices().keySet()) {
// for (com.loafle.overflow.model.discovery.Service service : port.getServiceList()) {
// // com.loafle.overflow.module.discovery.model.Service service =
// // port.getServices().get(key);
// InfraService dbInfraService = this.infraServiceService
// .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), portType);
// if (dbInfraService != null) {
// if (service.isTarget() && dbInfraService.getTarget() == null) {
// Target targetService = new Target();
// targetService.setDisplayName(service.getServiceName());
// this.targetService.regist(targetService, probe);
// dbInfraService.setTarget(targetService);
// this.infraServiceService.regist(dbInfraService);
// }
// continue;
// }
// InfraService infraService = new InfraService();
// infraService.setInfraHost(infraHost);
// infraService.setPort(port.getPortNumber());
// infraService.setPortType(portType);
// infraService.setMetaInfraType(typeService);
// infraService.setProbe(probe);
// if (port.getPortType() == PortType.TLS) {
// infraService.setTlsType(true);
// }
// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
// if (service.isTarget()) {
// Target targetService = new Target();
// targetService.setDisplayName(service.getServiceName());
// this.targetService.regist(targetService, probe);
// infraService.setTarget(targetService);
// }
// this.infraServiceService.regist(infraService);
// }
// }
// private void createPort(InfraHost infraHost, Host host, Probe probe) throws OverflowException {
// // if(host.getPorts() == null) {
// // return;
// // }
// String portType = "UDP";
// MetaInfraType typePort = new MetaInfraType(6);
// InfraOS infraOS = infraHost.getInfraOS();
// // for( String key: host.getPorts().keySet()) {
// if (host.getPortList() == null) {
// return;
// }
// for (Port port : host.getPortList()) {
// // Port port = host.getPorts().get(key);
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
// portType = "TCP";
// }
// InfraOSPort dbInfraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), port.getPortNumber(),
// portType);
// if (dbInfraOSPort == null) {
// InfraOSPort infraOSPort = new InfraOSPort();
// infraOSPort.setInfraOS(infraOS);
// infraOSPort.setPort(port.getPortNumber());
// infraOSPort.setPortType(portType);
// infraOSPort.setProbe(probe);
// infraOSPort.setMetaInfraType(typePort);
// if (port.getPortType() == PortType.TLS) {
// infraOSPort.setTlsType(true);
// }
// infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
// this.infraOSPortService.regist(infraOSPort);
// }
// this.createService(infraHost, port, probe);
// }
// }
// private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException {
// InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4());
// if (infraHost != null) {
// if (host.isTarget() && infraHost.getTarget() == null) {
// Target target = new Target();
// target.setDisplayName(host.getIpv4() + "-Host");
// this.targetService.regist(target, probe);
// infraHost.setTarget(target);
// this.infraHostService.regist(infraHost);
// }
// return infraHost;
// } else {
// MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine;
// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os
// MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host
// InfraMachine infraMachine = new InfraMachine();
// infraMachine.setProbe(probe);
// infraMachine.setMetaInfraType(typeMachine);
// infraMachine.setMeta(host.getIpv4() + "-MACHINE");
// this.infraMachineService.regist(infraMachine);
// InfraOS infraOS = new InfraOS();
// infraOS.setInfraMachine(infraMachine);
// infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
// infraOS.setMetaInfraType(typeOS);
// infraOS.setProbe(probe);
// infraOS.setMeta(host.getIpv4() + "-OS");
// this.infraOSService.regist(infraOS);
// InfraHost newInfraHost = new InfraHost();
// newInfraHost.setIpv4(host.getIpv4());
// newInfraHost.setMac(host.getMac());
// newInfraHost.setInfraOS(infraOS);
// newInfraHost.setMetaInfraType(typeHost);
// newInfraHost.setProbe(probe);
// if (host.isTarget()) {
// Target target = new Target();
// target.setDisplayName(host.getIpv4() + "-Host");
// this.targetService.regist(target, probe);
// newInfraHost.setTarget(target);
// }
// this.infraHostService.regist(newInfraHost);
// infraHost = newInfraHost;
// }
// return infraHost;
// }
// this.createPort(infraHost, host, probe);
// }
// return true;
// }
// private void createService(InfraHost infraHost, Port port, Probe probe)
// throws OverflowException {
// MetaInfraType typeService = new MetaInfraType(7);
// String portType = "UDP";
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP
// || port.getPortType() == null) {
// portType = "TCP";
// }
// if (port.getServiceList() == null) {
// return;
// }
// // for(String key : port.getServices().keySet()) {
// for (com.loafle.overflow.model.discovery.Service service :
// port.getServiceList()) {
// // com.loafle.overflow.module.discovery.model.Service service =
// // port.getServices().get(key);
// InfraService dbInfraService = this.infraServiceService
// .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(),
// portType);
// if (dbInfraService != null) {
// if (service.isTarget() && dbInfraService.getTarget() == null) {
// Target targetService = new Target();
// targetService.setDisplayName(service.getServiceName());
// this.targetService.regist(targetService, probe);
// dbInfraService.setTarget(targetService);
// this.infraServiceService.regist(dbInfraService);
// }
// continue;
// }
// InfraService infraService = new InfraService();
// infraService.setInfraHost(infraHost);
// infraService.setPort(port.getPortNumber());
// infraService.setPortType(portType);
// infraService.setMetaInfraType(typeService);
// infraService.setProbe(probe);
// if (port.getPortType() == PortType.TLS) {
// infraService.setTlsType(true);
// }
// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
// if (service.isTarget()) {
// Target targetService = new Target();
// targetService.setDisplayName(service.getServiceName());
// this.targetService.regist(targetService, probe);
// infraService.setTarget(targetService);
// }
// this.infraServiceService.regist(infraService);
// }
// }
// private void createPort(InfraHost infraHost, Host host, Probe probe) throws
// OverflowException {
// // if(host.getPorts() == null) {
// // return;
// // }
// String portType = "UDP";
// MetaInfraType typePort = new MetaInfraType(6);
// InfraOS infraOS = infraHost.getInfraOS();
// // for( String key: host.getPorts().keySet()) {
// if (host.getPortList() == null) {
// return;
// }
// for (Port port : host.getPortList()) {
// // Port port = host.getPorts().get(key);
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP)
// {
// portType = "TCP";
// }
// InfraOSPort dbInfraOSPort =
// this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(),
// port.getPortNumber(),
// portType);
// if (dbInfraOSPort == null) {
// InfraOSPort infraOSPort = new InfraOSPort();
// infraOSPort.setInfraOS(infraOS);
// infraOSPort.setPort(port.getPortNumber());
// infraOSPort.setPortType(portType);
// infraOSPort.setProbe(probe);
// infraOSPort.setMetaInfraType(typePort);
// if (port.getPortType() == PortType.TLS) {
// infraOSPort.setTlsType(true);
// }
// infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
// this.infraOSPortService.regist(infraOSPort);
// }
// this.createService(infraHost, port, probe);
// }
// }
// private InfraHost createAndReadHost(Host host, Probe probe) throws
// OverflowException {
// InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4());
// if (infraHost != null) {
// if (host.isTarget() && infraHost.getTarget() == null) {
// Target target = new Target();
// target.setDisplayName(host.getIpv4() + "-Host");
// this.targetService.regist(target, probe);
// infraHost.setTarget(target);
// this.infraHostService.regist(infraHost);
// }
// return infraHost;
// } else {
// MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine;
// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os
// MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host
// InfraMachine infraMachine = new InfraMachine();
// infraMachine.setProbe(probe);
// infraMachine.setMetaInfraType(typeMachine);
// infraMachine.setMeta(host.getIpv4() + "-MACHINE");
// this.infraMachineService.regist(infraMachine);
// InfraOS infraOS = new InfraOS();
// infraOS.setInfraMachine(infraMachine);
// infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
// infraOS.setMetaInfraType(typeOS);
// infraOS.setProbe(probe);
// infraOS.setMeta(host.getIpv4() + "-OS");
// this.infraOSService.regist(infraOS);
// InfraHost newInfraHost = new InfraHost();
// newInfraHost.setIpv4(host.getIpv4());
// newInfraHost.setMac(host.getMac());
// newInfraHost.setInfraOS(infraOS);
// newInfraHost.setMetaInfraType(typeHost);
// newInfraHost.setProbe(probe);
// if (host.isTarget()) {
// Target target = new Target();
// target.setDisplayName(host.getIpv4() + "-Host");
// this.targetService.regist(target, probe);
// newInfraHost.setTarget(target);
// }
// this.infraHostService.regist(newInfraHost);
// infraHost = newInfraHost;
// }
// return infraHost;
// }
// }

View File

@ -31,148 +31,150 @@ import org.springframework.transaction.annotation.Transactional;
@org.springframework.stereotype.Service("TargetService")
public class CentralTargetService implements TargetService {
@Autowired
private TargetDAO targetDAO;
@Autowired
private CentralProbeService probeService;
@Autowired
private CentralInfraHostService infraHostService;
@Autowired
private CentralInfraServiceService infraServiceService;
@Autowired
private TargetDAO targetDAO;
@Autowired
private CentralProbeService probeService;
@Autowired
private CentralInfraHostService infraHostService;
@Autowired
private CentralInfraServiceService infraServiceService;
@Transactional
public Target regist(Target target, Probe probe) throws OverflowException {
this.probeService.increaseTargetCount(probe);
return this.targetDAO.save(target);
}
@Transactional
public Target regist(Target target, Probe probe) throws OverflowException {
this.probeService.increaseTargetCount(probe);
return this.targetDAO.save(target);
}
@Transactional
public void remove(Target target, Probe probe) throws OverflowException {
this.probeService.decreaseTargetCount(probe);
this.targetDAO.delete(target);
}
@Transactional
public void remove(Target target, Probe probe) throws OverflowException {
this.probeService.decreaseTargetCount(probe);
this.targetDAO.delete(target);
}
public Target read(String id) throws OverflowException {
return this.targetDAO.findById(Long.valueOf(id)).get();
}
public Target read(String id) throws OverflowException {
return this.targetDAO.findById(Long.valueOf(id)).get();
}
public Target modify(Target target) throws OverflowException {
return this.targetDAO.save(target);
}
public Target modify(Target target) throws OverflowException {
return this.targetDAO.save(target);
}
@Deprecated
public Target regist(Target target) throws OverflowException {
return this.targetDAO.save(target);
}
@Deprecated
public Target regist(Target target) throws OverflowException {
return this.targetDAO.save(target);
}
@Deprecated
public void remove(Target target) throws OverflowException {
this.targetDAO.delete(target);
}
@Deprecated
public void remove(Target target) throws OverflowException {
this.targetDAO.delete(target);
}
public Target increaseSensorCount(Target target) throws OverflowException {
Target t = this.targetDAO.findById(target.getId()).get();
t.setSensorCount(t.getSensorCount() + 1);
return this.targetDAO.save(t);
}
public Target increaseSensorCount(Target target) throws OverflowException {
Target t = this.targetDAO.findById(target.getId()).get();
t.setSensorCount(t.getSensorCount() + 1);
return this.targetDAO.save(t);
}
public Target decreaseSensorCount(Target target) throws OverflowException {
Target t = this.targetDAO.findById(target.getId()).get();
int count = t.getSensorCount();
if (t.getSensorCount() > 0) {
t.setSensorCount(count - 1);
}
return this.targetDAO.save(t);
public Target decreaseSensorCount(Target target) throws OverflowException {
Target t = this.targetDAO.findById(target.getId()).get();
int count = t.getSensorCount();
if (t.getSensorCount() > 0) {
t.setSensorCount(count - 1);
}
return this.targetDAO.save(t);
}
public Target readExistHostTarget(Long probeId, String ip) throws OverflowException {
InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip);
if (null == infraHost)
return null;
return this.targetDAO.findByInfraId(infraHost.getId());
}
public Target readExistHostTarget(Long probeId, String ip) throws OverflowException {
InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip);
if (null == infraHost)
return null;
return this.targetDAO.findByInfraId(infraHost.getId());
}
public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException {
InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber,
portType);
if (null == infraService)
return null;
return this.targetDAO.findByInfraId(infraService.getId());
}
public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException {
InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber,
portType);
if (null == infraService)
return null;
return this.targetDAO.findByInfraId(infraService.getId());
}
public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams));
// return null;
}
@Transactional
public List<Target> registDiscoveredTargets(Long probeId, List<Host> hosts, List<Service> services)
throws OverflowException {
List<Target> targets = new ArrayList<Target>();
targets.addAll(registDiscoveredHostTargets(probeId, hosts));
targets.addAll(this.registDiscoveredServiceTargets(probeId, services));
return targets;
}
public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams));
// return null;
}
private List<Target> registDiscoveredHostTargets(Long probeId, List<Host> hosts) throws OverflowException {
List<Target> targets = new ArrayList<>();
if (null == hosts)
return targets;
for (Host host : hosts) {
InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
Target target = new Target();
target.setInfra(infraHost);
String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? host.getIpv6() : host.getIpv4();
target.setDisplayName(displayName);
targets.add(this.targetDAO.save(target));
}
return targets;
}
@Transactional
public List<Target> registDiscoveredTargets(Long probeId, List<Host> hosts, List<Service> services)
throws OverflowException {
List<Target> targets = new ArrayList<Target>();
targets.addAll(registDiscoveredHostTargets(probeId, hosts));
targets.addAll(this.registDiscoveredServiceTargets(probeId, services));
return targets;
}
private List<Target> registDiscoveredServiceTargets(Long probeId, List<Service> services) throws OverflowException {
List<Target> targets = new ArrayList<>();
if (null == services)
return targets;
for (Service service : services) {
Host host = service.getPort().getHost();
InfraHost infraHost = null;
InfraHost existInfraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4());
InfraService infraService = null;
if (null != existInfraHost) {
infraHost = existInfraHost;
} else {
infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
infraService = this.registInfraServiceByDiscoveredService(infraHost, service, probeId);
}
Target target = new Target();
target.setInfra(infraService);
String displayName = service.getServiceName();
target.setDisplayName(displayName);
targets.add(this.targetDAO.save(target));
}
return targets;
private List<Target> registDiscoveredHostTargets(Long probeId, List<Host> hosts) throws OverflowException {
List<Target> targets = new ArrayList<>();
if (null == hosts)
return targets;
for (Host host : hosts) {
InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
Target target = new Target();
target.setInfra(infraHost);
String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? host.getIpv6()
: host.getIpv4();
target.setDisplayName(displayName);
targets.add(this.targetDAO.save(target));
}
return targets;
}
private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId) throws OverflowException {
InfraHost infraHost = new InfraHost();
infraHost.setMetaInfraType(new MetaInfraType(2));
infraHost.setProbe(new Probe(probeId));
infraHost.setIpv4(host.getIpv4());
infraHost.setIpv6(host.getIpv6());
infraHost.setMac(host.getMac());
return this.infraHostService.regist(infraHost);
}
private List<Target> registDiscoveredServiceTargets(Long probeId, List<Service> services) throws OverflowException {
List<Target> targets = new ArrayList<>();
if (null == services)
return targets;
for (Service service : services) {
Host host = service.getPort().getHost();
InfraHost infraHost = null;
InfraHost existInfraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4());
InfraService infraService = null;
if (null != existInfraHost) {
infraHost = existInfraHost;
} else {
infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
infraService = this.registInfraServiceByDiscoveredService(infraHost, service, probeId);
}
private InfraService registInfraServiceByDiscoveredService(InfraHost infraHost, Service service, Long probeId)
throws OverflowException {
InfraService infraService = new InfraService();
infraHost.setMetaInfraType(new MetaInfraType(7));
infraService.setInfraHost(infraHost);
infraService.setPort(service.getPort().getPortNumber());
infraService.setPortType(service.getPort().getPortType().toString());
infraService.setTlsType(service.getCryptoType() == CryptoType.TLS);
infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
return this.infraServiceService.regist(infraService);
Target target = new Target();
target.setInfra(infraService);
String displayName = service.getServiceName();
target.setDisplayName(displayName);
targets.add(this.targetDAO.save(target));
}
return targets;
}
private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId) throws OverflowException {
InfraHost infraHost = new InfraHost();
infraHost.setMetaInfraType(new MetaInfraType(2));
infraHost.setProbe(new Probe(probeId));
infraHost.setIpv4(host.getIpv4());
infraHost.setIpv6(host.getIpv6());
infraHost.setMac(host.getMac());
return this.infraHostService.regist(infraHost);
}
private InfraService registInfraServiceByDiscoveredService(InfraHost infraHost, Service service, Long probeId)
throws OverflowException {
InfraService infraService = new InfraService();
infraHost.setMetaInfraType(new MetaInfraType(7));
infraService.setInfraHost(infraHost);
infraService.setPort(service.getPort().getPortNumber());
infraService.setPortType(service.getPort().getPortType().toString());
infraService.setTlsType(service.getCryptoType() == CryptoType.TLS);
infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
return this.infraServiceService.regist(infraService);
}
}

View File

@ -6,16 +6,16 @@ import io.grpc.*;
public class ProxyServerInterceptor implements ServerInterceptor {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,
ServerCallHandler<ReqT, RespT> next) {
String clientType = headers.get(SessionMetadata.METADATA_CLIENT_TYPE_KEY);
String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY);
String targetID = headers.get(SessionMetadata.METADATA_TARGET_ID_KEY);
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,
ServerCallHandler<ReqT, RespT> next) {
String clientType = headers.get(SessionMetadata.METADATA_CLIENT_TYPE_KEY);
String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY);
String targetID = headers.get(SessionMetadata.METADATA_TARGET_ID_KEY);
Context ctx = Context.current().withValues(SessionMetadata.CTX_CLIENT_TYPE_KEY, clientType,
SessionMetadata.CTX_SESSION_ID_KEY, sessionID, SessionMetadata.CTX_TARGET_ID_KEY, targetID);
Context ctx = Context.current().withValues(SessionMetadata.CTX_CLIENT_TYPE_KEY, clientType,
SessionMetadata.CTX_SESSION_ID_KEY, sessionID, SessionMetadata.CTX_TARGET_ID_KEY, targetID);
return Contexts.interceptCall(ctx, call, headers, next);
}
return Contexts.interceptCall(ctx, call, headers, next);
}
}

View File

@ -34,13 +34,13 @@ public class ServiceProxy {
ServiceImpl serviceImpl = ctx.getBean(ServiceImpl.class);
server = NettyServerBuilder.forPort(port)
.addService(ServerInterceptors.intercept(serviceImpl, proxyServerInterceptor))
.build().start();
.addService(ServerInterceptors.intercept(serviceImpl, proxyServerInterceptor)).build().start();
logger.info("Server started, listening on " + port);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
// Use stderr here since the logger may have been reset by its JVM shutdown
// hook.
System.err.println("*** shutting down gRPC server since JVM is shutting down");
ServiceProxy.this.stop();
System.err.println("*** server shut down");
@ -105,4 +105,3 @@ public class ServiceProxy {
}
}

View File

@ -133,7 +133,7 @@ public class RedisMessagePublisher implements MessagePublisher {
results.add(json);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return results;

View File

@ -15,19 +15,19 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@PropertySource({ "classpath:database.properties", "classpath:mail.properties", "classpath:redis.properties",
"classpath:cache.properties" })
public class AppConfig {
// @Bean
// public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
// PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
//// ppc.setLocation(new ClassPathResource("database.properties"));
// ppc.setLocations(new Resource[] {
// new ClassPathResource("database.properties"),
// new ClassPathResource("mail.properties"),
// new ClassPathResource("redis.properties")
// });
// ppc.setIgnoreUnresolvablePlaceholders(true);
// @Bean
// public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
// PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
//// ppc.setLocation(new ClassPathResource("database.properties"));
// ppc.setLocations(new Resource[] {
// new ClassPathResource("database.properties"),
// new ClassPathResource("mail.properties"),
// new ClassPathResource("redis.properties")
// });
// ppc.setIgnoreUnresolvablePlaceholders(true);
//
// return ppc;
// }
// return ppc;
// }
@Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
@ -35,10 +35,10 @@ public class AppConfig {
// @Bean
// public Gson gson() {
// GsonBuilder builder = new GsonBuilder();
// builder.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.PRIVATE);
// // builder.excludeFieldsWithoutExposeAnnotation();
// return builder.create();
// GsonBuilder builder = new GsonBuilder();
// builder.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.PRIVATE);
// // builder.excludeFieldsWithoutExposeAnnotation();
// return builder.create();
// }
@Bean
public ObjectMapper getObjectMapper() {

View File

@ -10,17 +10,17 @@ import org.springframework.context.annotation.Configuration;
@EnableCaching
@Configuration
public class CacheConfiguration {
@Value("#{'${cache.cache-names}'.split(',')}")
private String[] cacheNames;
@Value("${cache.caffeine.spec}")
private String spec;
@Value("#{'${cache.cache-names}'.split(',')}")
private String[] cacheNames;
@Value("${cache.caffeine.spec}")
private String spec;
@Bean
public CacheManager cacheManager() {
//A EhCache based Cache manager
CaffeineCacheManager cacheManager = new CaffeineCacheManager(cacheNames);
cacheManager.setAllowNullValues(false);
cacheManager.setCacheSpecification(spec);
return cacheManager;
}
@Bean
public CacheManager cacheManager() {
// A EhCache based Cache manager
CaffeineCacheManager cacheManager = new CaffeineCacheManager(cacheNames);
cacheManager.setAllowNullValues(false);
cacheManager.setCacheSpecification(spec);
return cacheManager;
}
}

View File

@ -21,82 +21,79 @@ import javax.persistence.EntityManager;
import javax.sql.DataSource;
import java.util.Properties;
/**
* Created by root on 17. 6. 13.
*/
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = {"com.loafle.overflow"})
public class JdbcConfiguration implements TransactionManagementConfigurer {
@Value("${datasource.driver-class-name}")
private String driver;
@Value("${datasource.url}")
private String url;
@Value("${datasource.username}")
private String username;
@Value("${datasource.password}")
private String password;
@Value("${jpa.hibernate.dialect}")
private String dialect;
@Value("${jpa.hibernate.ddl-auto}")
private String hbm2ddlAuto;
@EnableJpaRepositories(basePackages = { "com.loafle.overflow" })
public class JdbcConfiguration implements TransactionManagementConfigurer {
@Value("${datasource.driver-class-name}")
private String driver;
@Value("${datasource.url}")
private String url;
@Value("${datasource.username}")
private String username;
@Value("${datasource.password}")
private String password;
@Value("${jpa.hibernate.dialect}")
private String dialect;
@Value("${jpa.hibernate.ddl-auto}")
private String hbm2ddlAuto;
@Bean
public DataSource configureDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
@Bean
public DataSource configureDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(configureDataSource());
entityManagerFactoryBean.setPackagesToScan("com.loafle.overflow");
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
Properties jpaProperties = new Properties();
jpaProperties.put(Environment.DIALECT, dialect);
jpaProperties.put(Environment.HBM2DDL_AUTO, hbm2ddlAuto);
jpaProperties.put(Environment.SHOW_SQL, true);
entityManagerFactoryBean.setJpaProperties(jpaProperties);
return entityManagerFactoryBean;
}
@Bean
@Qualifier(value = "transactionManager")
public PlatformTransactionManager annotationDrivenTransactionManager() {
return new JpaTransactionManager();
}
@Bean
public EntityManager entityManager() {
return entityManagerFactory().getObject().createEntityManager();
}
@Bean
public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(dataSource);
ClassPathResource initSqlResource = new ClassPathResource("/init.sql");
if (initSqlResource.exists()) {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
databasePopulator.addScript(initSqlResource);
databasePopulator.setIgnoreFailedDrops(true);
initializer.setDatabasePopulator(databasePopulator);
} else {
initializer.setEnabled(false);
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(configureDataSource());
entityManagerFactoryBean.setPackagesToScan("com.loafle.overflow");
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
Properties jpaProperties = new Properties();
jpaProperties.put(Environment.DIALECT, dialect);
jpaProperties.put(Environment.HBM2DDL_AUTO, hbm2ddlAuto);
jpaProperties.put(Environment.SHOW_SQL, true);
entityManagerFactoryBean.setJpaProperties(jpaProperties);
return entityManagerFactoryBean;
}
@Bean
@Qualifier(value = "transactionManager")
public PlatformTransactionManager annotationDrivenTransactionManager() {
return new JpaTransactionManager();
}
@Bean
public EntityManager entityManager() {
return entityManagerFactory().getObject().createEntityManager();
}
@Bean
public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(dataSource);
ClassPathResource initSqlResource = new ClassPathResource("/init.sql");
if (initSqlResource.exists()) {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
databasePopulator.addScript(initSqlResource);
databasePopulator.setIgnoreFailedDrops(true);
initializer.setDatabasePopulator(databasePopulator);
} else {
initializer.setEnabled(false);
}
return initializer;
}
return initializer;
}
}

View File

@ -18,63 +18,62 @@ import java.util.Properties;
@ComponentScan(basePackages = "com.loafle.overflow")
public class MailConfiguration {
@Value("${mail.host}")
private String host;
@Value("${mail.port}")
private int port;
@Value("${mail.username}")
private String username;
@Value("${mail.password}")
private String password;
@Value("${mail.protocol}")
private String protocol;
@Value("${mail.host}")
private String host;
@Value("${mail.port}")
private int port;
@Value("${mail.username}")
private String username;
@Value("${mail.password}")
private String password;
@Value("${mail.protocol}")
private String protocol;
@Bean
public JavaMailSenderImpl mailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
@Bean
public JavaMailSenderImpl mailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(this.host);
mailSender.setPort(this.port);
mailSender.setUsername(this.username);
mailSender.setPassword(this.password);
mailSender.setProtocol(this.protocol);
mailSender.setHost(this.host);
mailSender.setPort(this.port);
mailSender.setUsername(this.username);
mailSender.setPassword(this.password);
mailSender.setProtocol(this.protocol);
mailSender.setJavaMailProperties(getJavaMailProperties());
mailSender.setJavaMailProperties(getJavaMailProperties());
return mailSender;
}
return mailSender;
}
@Bean
public Properties getJavaMailProperties() {
Properties javaMailProperties = new Properties();
javaMailProperties.put("mail.smtp.starttls.enable", true);
javaMailProperties.put("mail.smtp.auth", true);
javaMailProperties.put("mail.transport.protocol", "smtp");
javaMailProperties.put("mail.debug", "true");
javaMailProperties.put("mail.smtps.ssl.checkserveridentity", true);
javaMailProperties.put("mail.smtps.ssl.trust", "*");
@Bean
public Properties getJavaMailProperties() {
Properties javaMailProperties = new Properties();
javaMailProperties.put("mail.smtp.starttls.enable", true);
javaMailProperties.put("mail.smtp.auth", true);
javaMailProperties.put("mail.transport.protocol", "smtp");
javaMailProperties.put("mail.debug", "true");
javaMailProperties.put("mail.smtps.ssl.checkserveridentity", true);
javaMailProperties.put("mail.smtps.ssl.trust", "*");
return javaMailProperties;
}
return javaMailProperties;
}
@Bean
public VelocityEngine getVelocityEngine() throws VelocityException, IOException {
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("/velocity.properties"));
return new VelocityEngine(properties);
}
@Bean
public VelocityEngine getVelocityEngine() throws VelocityException, IOException {
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("/velocity.properties"));
return new VelocityEngine(properties);
}
}
//
// @Value("${mail.properties.mail.smtp.auth}")
// private boolean smtpAuth;
// @Value("${mail.properties.mail.smtp.starttls.enable}")
// private boolean ttlEnable;
// @Value("${mail.transport.protocol}")
// private String transProtocol;
// @Value("${mail.smtps.ssl.checkserveridentity}")
// private boolean checkserver;
// @Value("${mail.smtps.ssl.trust}")
// private String sslTrust;
// @Value("${mail.properties.mail.smtp.auth}")
// private boolean smtpAuth;
// @Value("${mail.properties.mail.smtp.starttls.enable}")
// private boolean ttlEnable;
// @Value("${mail.transport.protocol}")
// private String transProtocol;
// @Value("${mail.smtps.ssl.checkserveridentity}")
// private boolean checkserver;
// @Value("${mail.smtps.ssl.trust}")
// private String sslTrust;

View File

@ -20,54 +20,53 @@ import java.util.Map;
@Configuration
public class RedisConfiguration {
@Value("${redis.host}")
private String host;
@Value("${redis.port}")
private int port;
@Value("#{'${redis.channels}'.split(',')}")
private List<String> channels;
@Value("${redis.host}")
private String host;
@Value("${redis.port}")
private int port;
@Value("#{'${redis.channels}'.split(',')}")
private List<String> channels;
@Bean
JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(host);
redisStandaloneConfiguration.setPort(port);
// redisStandaloneConfiguration.setDatabase(0);
// redisStandaloneConfiguration.setPassword(RedisPassword.of("password"));
@Bean
JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(host);
redisStandaloneConfiguration.setPort(port);
// redisStandaloneConfiguration.setDatabase(0);
// redisStandaloneConfiguration.setPassword(RedisPassword.of("password"));
JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();
jedisClientConfiguration.connectTimeout(Duration.ofSeconds(60));// 60s connection timeout
JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();
jedisClientConfiguration.connectTimeout(Duration.ofSeconds(60));// 60s connection timeout
JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(redisStandaloneConfiguration,
jedisClientConfiguration.build());
JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(redisStandaloneConfiguration,
jedisClientConfiguration.build());
// JedisConnectionFactory jedisConFactory = new JedisConnectionFactory();
// jedisConFactory.setHostName(host);
// jedisConFactory.setPort(port);
return jedisConFactory;
}
// JedisConnectionFactory jedisConFactory = new JedisConnectionFactory();
// jedisConFactory.setHostName(host);
// jedisConFactory.setPort(port);
return jedisConFactory;
}
@Bean
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
return template;
}
@Bean
MessagePublisher messagePublisher() {
return new RedisMessagePublisher(redisTemplate(), topics());
}
@Bean
Map<String, ChannelTopic> topics() {
Map<String, ChannelTopic> topicMap = new HashMap<>(this.channels.size());
for (String channel: this.channels) {
topicMap.put(channel, new ChannelTopic(channel));
}
return topicMap;
@Bean
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
return template;
}
@Bean
MessagePublisher messagePublisher() {
return new RedisMessagePublisher(redisTemplate(), topics());
}
@Bean
Map<String, ChannelTopic> topics() {
Map<String, ChannelTopic> topicMap = new HashMap<>(this.channels.size());
for (String channel : this.channels) {
topicMap.put(channel, new ChannelTopic(channel));
}
return topicMap;
}
}