Removed HTTP-Logger (deprecated)

This commit is contained in:
George Kalampokis 2020-06-10 13:18:04 +03:00
parent 56da83d1e8
commit 33423b92f6
18 changed files with 3 additions and 658 deletions

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dmp-backend</groupId>
<artifactId>logging</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>eu.eudat</groupId>
<artifactId>dmp-backend</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.6.RELEASE</version>
</dependency>
</dependencies>
</project>

View File

@ -1,48 +0,0 @@
package eu.eudat.core.logger;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
/**
* Created by ikalyvas on 5/30/2018.
*/
public interface Logger {
<T> void debug(T model);
<T> void debug(T model,String message);
<T> void debug(String message);
<T extends Exception> void debug(T exception);
<T extends Exception> void debug(T exception,String message);
<T> void warn(T model);
<T> void warn(T model,String message);
<T> void warn(String message);
<T extends Exception> void warn(T exception);
<T extends Exception> void warn(T exception,String message);
<T> void info(String message);
<T> void info(T model);
<T> void info(T model,String message);
<T extends RuntimeException> void info(T exception);
<T extends RuntimeException> void info(T exception,String message);
<T> void error(T loggingModel);
<E extends Exception,P> void error(ApiExceptionLoggingModel<E,P> model);
<T extends Exception> void error(T exception);
<T extends Exception> void error(T exception,String message);
}

View File

@ -1,57 +0,0 @@
package eu.eudat.core.logger.common;
import org.json.JSONObject;
import org.springframework.core.env.Environment;
import types.LoggingOutputType;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* Created by ikalyvas on 5/30/2018.
*/
public abstract class AbstractBatchLogger {
private Map<String, Object> concurrentHashMap = new ConcurrentHashMap<String, Object>();
public AbstractBatchLogger(Environment environment) {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(() -> this.outputData(), Long.parseLong(environment.getProperty("http-logger.initial-delay")), Long.parseLong(environment.getProperty("http-logger.delay")), TimeUnit.SECONDS);
}
public abstract LoggingOutputType logOutputType();
public <T> void put(String key, T data) {
this.concurrentHashMap.put(key, data);
}
public void clear() {
this.concurrentHashMap.clear();
}
private Map<String, Object> getAndClear() {
Map<String, Object> map = new HashMap<>();
map.putAll(this.concurrentHashMap);
this.concurrentHashMap.keySet().removeAll(map.keySet());
return map;
}
public String tranformLog() {
if (this.concurrentHashMap.size() > 0) {
Map<String, Collection<Object>> transformedMap = new HashMap<>();
transformedMap.put("entries", this.getAndClear().values());
if (this.logOutputType().equals(LoggingOutputType.JSON))
return new JSONObject(transformedMap).toString();
if (this.logOutputType().equals(LoggingOutputType.FILE))
return transformedMap.toString(); //TODO actual implementation of file Logger
else throw new RuntimeException("Unsupported LoggingOutputType type");
} else return null;
}
public abstract void outputData();
}

View File

@ -1,287 +0,0 @@
package eu.eudat.core.logger.remote.http;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import eu.eudat.core.logger.Logger;
import eu.eudat.core.logger.common.AbstractBatchLogger;
import eu.eudat.core.models.LoggingModel;
import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
import eu.eudat.core.models.exception.ExceptionLoggingModel;
import eu.eudat.core.models.simple.SimpleAuditModel;
import eu.eudat.core.models.simple.SimpleLoggingModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import types.LoggingOutputType;
import types.LoggingType;
import java.util.HashMap;
import java.util.Map;
/**
* Created by ikalyvas on 5/30/2018.
*/
//@Service("logger")
public class HttpRemoteLogger extends AbstractBatchLogger implements Logger {
private RestTemplate rest;
private HttpHeaders headers;
private Environment environment;
//@Autowired
public HttpRemoteLogger(Environment environment) {
super(environment);
this.rest = new RestTemplate();
this.headers = new HttpHeaders();
this.environment = environment;
headers.add("Content-Type", "application/json");
headers.add("Accept", "*/*");
}
@Override
public void outputData() {
try {
String log = this.tranformLog();
if (log != null) {
HttpEntity<String> requestEntity = new HttpEntity(log, headers);
ResponseEntity<String> Object = rest.exchange(this.environment.getProperty("http-logger.server-address"), HttpMethod.POST, requestEntity, String.class);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public LoggingOutputType logOutputType() {
return LoggingOutputType.JSON;
}
@Override
public <T> void debug(T model) {
LoggingModel<T> loggingModel = new SimpleLoggingModel<>();
loggingModel.setData(model);
loggingModel.setType(LoggingType.DEBUG);
this.put(String.valueOf(model.hashCode()), loggingModel);
}
@Override
public <T> void debug(T model, String message) {
LoggingModel<T> loggingModel = new SimpleLoggingModel<>();
loggingModel.setData(model);
loggingModel.setMessage(message);
loggingModel.setType(LoggingType.DEBUG);
this.put(String.valueOf(model.hashCode()), loggingModel);
}
@Override
public <T> void debug(String message) {
LoggingModel<T> loggingModel = new SimpleLoggingModel<>();
loggingModel.setMessage(message);
loggingModel.setType(LoggingType.DEBUG);
this.put(String.valueOf(message.hashCode()), loggingModel);
}
@Override
public <T extends Exception> void debug(T exception) {
ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel();
Map<String, String> map = new HashMap<>();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(exception);
map.put("exception", json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
exceptionLoggingModel.setData(map);
exceptionLoggingModel.setType(LoggingType.DEBUG);
this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel);
}
@Override
public <T extends Exception> void debug(T exception, String message) {
ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel();
Map<String, String> map = new HashMap<>();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(exception);
map.put("exception", json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
exceptionLoggingModel.setData(map);
exceptionLoggingModel.setMessage(message);
exceptionLoggingModel.setType(LoggingType.DEBUG);
this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel);
}
@Override
public <T> void warn(T model) {
LoggingModel<T> loggingModel = new SimpleLoggingModel<>();
loggingModel.setData(model);
loggingModel.setType(LoggingType.WARNING);
this.put(String.valueOf(model.hashCode()), loggingModel);
}
@Override
public <T> void warn(T model, String message) {
LoggingModel<T> loggingModel = new SimpleLoggingModel<>();
loggingModel.setData(model);
loggingModel.setMessage(message);
loggingModel.setType(LoggingType.WARNING);
this.put(String.valueOf(model.hashCode()), loggingModel);
}
@Override
public <T> void warn(String message) {
LoggingModel<T> loggingModel = new SimpleLoggingModel<>();
loggingModel.setMessage(message);
loggingModel.setType(LoggingType.WARNING);
this.put(String.valueOf(message.hashCode()), loggingModel);
}
@Override
public <T extends Exception> void warn(T exception) {
ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel();
Map<String, String> map = new HashMap<>();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(exception);
map.put("exception", json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
exceptionLoggingModel.setData(map);
exceptionLoggingModel.setType(LoggingType.WARNING);
this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel);
}
@Override
public <T extends Exception> void warn(T exception, String message) {
ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel();
Map<String, String> map = new HashMap<>();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(exception);
map.put("exception", json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
exceptionLoggingModel.setData(map);
exceptionLoggingModel.setMessage(message);
exceptionLoggingModel.setType(LoggingType.WARNING);
this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel);
}
@Override
public <T> void info(String message) {
SimpleAuditModel<T> simpleAuditModel = new SimpleAuditModel<>();
simpleAuditModel.setMessage(message);
simpleAuditModel.setType(LoggingType.INFO);
this.put(String.valueOf(simpleAuditModel.hashCode()), simpleAuditModel);
}
@Override
public <T> void info(T model) {
SimpleAuditModel<T> simpleAuditModel = new SimpleAuditModel<>();
simpleAuditModel.setData(model);
simpleAuditModel.setType(LoggingType.INFO);
this.put(String.valueOf(model.hashCode()), simpleAuditModel);
}
@Override
public <T> void info(T model, String message) {
SimpleAuditModel<T> simpleAuditModel = new SimpleAuditModel<>();
simpleAuditModel.setData(model);
simpleAuditModel.setMessage(message);
simpleAuditModel.setType(LoggingType.INFO);
this.put(String.valueOf(model.hashCode()), simpleAuditModel);
}
@Override
public <T extends RuntimeException> void info(T exception) {
ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel();
Map<String, String> map = new HashMap<>();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(exception);
map.put("exception", json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
exceptionLoggingModel.setData(map);
exceptionLoggingModel.setType(LoggingType.INFO);
this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel);
}
@Override
public <T extends RuntimeException> void info(T exception, String message) {
ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel();
Map<String, String> map = new HashMap<>();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(exception);
map.put("exception", json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
exceptionLoggingModel.setData(map);
exceptionLoggingModel.setMessage(message);
exceptionLoggingModel.setType(LoggingType.INFO);
this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel);
}
@Override
public <E extends Exception, P> void error(ApiExceptionLoggingModel<E, P> model) {
this.put(String.valueOf(model.hashCode()), model);
}
@Override
public <T> void error(T model) {
LoggingModel<T> loggingModel = new SimpleLoggingModel<>();
loggingModel.setType(LoggingType.DEBUG);
loggingModel.setData(model);
this.put(String.valueOf(model.hashCode()), loggingModel);
}
@Override
public <T extends Exception> void error(T exception) {
ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel();
Map<String, String> map = new HashMap<>();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(exception);
map.put("exception", json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
exceptionLoggingModel.setData(map);
exceptionLoggingModel.setType(LoggingType.ERROR);
this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel);
}
@Override
public <T extends Exception> void error(T exception, String message) {
ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel();
Map<String, String> map = new HashMap<>();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(exception);
map.put("exception", json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
exceptionLoggingModel.setData(map);
exceptionLoggingModel.setMessage(message);
exceptionLoggingModel.setType(LoggingType.ERROR);
this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel);
}
}

View File

@ -1,8 +0,0 @@
package eu.eudat.core.models;
/**
* Created by ikalyvas on 5/30/2018.
*/
public abstract class AuditModel<T> extends LoggingModel<T>{
}

View File

@ -1,36 +0,0 @@
package eu.eudat.core.models;
import types.LoggingType;
/**
* Created by ikalyvas on 5/30/2018.
*/
public abstract class LoggingModel<T> {
private T data;
private LoggingType type;
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public LoggingType getType() {
return type;
}
public void setType(LoggingType type) {
this.type = type;
}
}

View File

@ -1,35 +0,0 @@
package eu.eudat.core.models.exception;
import eu.eudat.core.models.LoggingModel;
import org.springframework.http.HttpStatus;
import java.util.Map;
/**
* Created by ikalyvas on 6/12/2018.
*/
public class ApiExceptionLoggingModel<E, P> extends LoggingModel<E> {
private HttpStatus code;
private P user;
private final String indexType = "api-exception-logging";
public String getIndexType() {
return indexType;
}
public P getUser() {
return user;
}
public void setUser(P user) {
this.user = user;
}
public HttpStatus getCode() {
return code;
}
public void setCode(HttpStatus code) {
this.code = code;
}
}

View File

@ -1,21 +0,0 @@
package eu.eudat.core.models.exception;
import eu.eudat.core.models.LoggingModel;
import java.util.Map;
/**
* Created by ikalyvas on 5/30/2018.
*/
public class ExceptionLoggingModel extends LoggingModel<Map<String, String>> {
private final String indexType = "exception-logging";
public String getIndexType() {
return indexType;
}
@Override
public Map<String, String> getData() {
return super.getData();
}
}

View File

@ -1,14 +0,0 @@
package eu.eudat.core.models.simple;
import eu.eudat.core.models.AuditModel;
/**
* Created by ikalyvas on 5/30/2018.
*/
public class SimpleAuditModel<T> extends AuditModel<T> {
private final String indexType = "simple-audit";
public String getIndexType() {
return indexType;
}
}

View File

@ -1,14 +0,0 @@
package eu.eudat.core.models.simple;
import eu.eudat.core.models.LoggingModel;
/**
* Created by ikalyvas on 5/30/2018.
*/
public class SimpleLoggingModel<T> extends LoggingModel<T> {
private final String indexType = "simple-logging";
public String getIndexType() {
return indexType;
}
}

View File

@ -1,29 +0,0 @@
package types;
/**
* Created by ikalyvas on 5/30/2018.
*/
public enum LoggingOutputType {
FILE(0), JSON(1);
private Integer value;
private LoggingOutputType(Integer value) {
this.value = value;
}
public Integer getValue() {
return value;
}
public static LoggingOutputType fromInteger(Integer value) {
switch (value) {
case 0:
return FILE;
case 1:
return JSON;
default:
throw new RuntimeException("Unsupported Logging LoggingOutputType");
}
}
}

View File

@ -1,33 +0,0 @@
package types;
/**
* Created by ikalyvas on 5/30/2018.
*/
public enum LoggingType {
WARNING(0), ERROR(1), INFO(2), DEBUG(3);
private Integer value;
private LoggingType(Integer value) {
this.value = value;
}
public Integer getValue() {
return value;
}
public static LoggingType fromInteger(Integer value) {
switch (value) {
case 0:
return WARNING;
case 1:
return ERROR;
case 2:
return INFO;
case 3:
return DEBUG;
default:
throw new RuntimeException("Unsupported LoggingType");
}
}
}

View File

@ -1,6 +1,5 @@
package eu.eudat.controllers;
import eu.eudat.core.logger.Logger;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.exceptions.datasetprofile.DatasetProfileNewVersionException;
import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption;

View File

@ -1,6 +1,5 @@
package eu.eudat.controllers;
import eu.eudat.core.logger.Logger;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.validators.*;
import org.springframework.web.bind.WebDataBinder;
@ -9,18 +8,12 @@ import org.springframework.web.bind.annotation.InitBinder;
public abstract class BaseController {
/*private Logger logger;*/
private ApiContext apiContext;
public ApiContext getApiContext() {
return apiContext;
}
/*public Logger getLoggerService() {
return logger;
}*/
public BaseController(ApiContext apiContext) {
this.apiContext = apiContext;

View File

@ -1,26 +1,18 @@
package eu.eudat.controllers.controllerhandler;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import types.LoggingType;
import javax.annotation.Priority;
import java.util.HashMap;
import java.util.Map;
/**
* Created by ikalyvas on 6/12/2018.
@ -30,31 +22,10 @@ import java.util.Map;
public class ControllerErrorHandler {
private static final Logger logger = LoggerFactory.getLogger(ControllerErrorHandler.class);
// private Logger logger;
/*@Autowired
public ControllerErrorHandler(Logger logger) {
this.logger = logger;
}*/
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ResponseItem<Exception> processValidationError(Principal principal, Exception ex) throws Exception {
ApiExceptionLoggingModel<String, Principal> apiExceptionLoggingModel = new ApiExceptionLoggingModel<>();
apiExceptionLoggingModel.setCode(HttpStatus.BAD_REQUEST);
apiExceptionLoggingModel.setUser(principal);
Map<String, String> exceptionMap = new HashMap<>();
ObjectWriter ow = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false).writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(ex);
exceptionMap.put("exception", json);
apiExceptionLoggingModel.setData(ow.writeValueAsString(exceptionMap));
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
apiExceptionLoggingModel.setMessage(ex.getMessage());
apiExceptionLoggingModel.setType(LoggingType.ERROR);
logger.error(ex.getMessage(), ex);
return new ResponseItem<Exception>().message(ex.getMessage()).status(ApiMessageCode.DEFAULT_ERROR_MESSAGE);
}

View File

@ -1,24 +1,19 @@
package eu.eudat.logic.services.utilities;
import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.dao.entities.InvitationDao;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Invitation;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.models.data.mail.SimpleMail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import types.LoggingType;
import javax.mail.MessagingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@ -27,12 +22,10 @@ import java.util.stream.Collectors;
@Service("invitationService")
public class InvitationServiceImpl implements InvitationService {
private static final Logger logger = LoggerFactory.getLogger(InvitationServiceImpl.class);
// private Logger logger;
private Environment environment;
@Autowired
public InvitationServiceImpl(/*Logger logger,*/ Environment environment) {
// this.logger = logger;
public InvitationServiceImpl(Environment environment) {
this.environment = environment;
}

View File

@ -11,9 +11,6 @@ elasticsearch.port = 9200
elasticsearch.username=elastic
elasticsearch.password=
####################ELK OVERRIDES CONFIGURATIONS##########
http-logger.server-address = http://logstash:31311
####################PDF OVERRIDES CONFIGURATIONS##########
pdf.converter.url=http://docsbox-web/

View File

@ -11,9 +11,6 @@ elasticsearch.port = 9200
elasticsearch.username=elastic
elasticsearch.password=
####################ELK OVERRIDES CONFIGURATIONS##########
http-logger.server-address = http://logstash:31311
####################PDF OVERRIDES CONFIGURATIONS##########
pdf.converter.url=http://docsbox-web/