Skip to content

Commit

Permalink
#78 - configuration migration to startup-parameters library
Browse files Browse the repository at this point in the history
  • Loading branch information
akorobov committed Feb 15, 2024
1 parent 94ac689 commit 06b3bcb
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 56 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ export JSON_ADAPTER_BIND_ADDRESS=127.0.0.1 # json adapter bind address
export JSON_ADAPTER_PORT=28080 # json adapter port
export JSON_ADAPTER_PATH=/save-logs # json adapter path
export JSON_ADAPTER_TOKEN=token # json adapter token
export SPHINX_HOST=localhost # sphinx host
export SPHINX_PORT=9312 # sphinx port
export SPHINX_CONNECT_TIMEOUT=30000 # sphinx connect timeout
export SPHINX_QUERY_INDEXES=index1,index2 # comma separated query indexes
export LOG_STORAGE_CAPACITY=1000 # log broadcasting service storage capacity (web terminal page)
export LOGBACK_PROGRAM=programName # logback program name
export LOGBACK_TCP_PORT=4713 # port for logback tcp adapter
export LOGBACK_UDP_PORT=4713 # port for logback udp adapter
```
Start server uber-jar:
```shell
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.payneteasy.srvlog.adapter.logback;

import com.payneteasy.startup.parameters.AStartupParameter;

public interface ILogbackAdapterConfig {

@AStartupParameter(name = "LOGBACK_PROGRAM", value = "paynet")
String getProgram();

@AStartupParameter(name = "LOGBACK_TCP_PORT", value = "4713")
int getTcpPort();

@AStartupParameter(name = "LOGBACK_UDP_PORT", value = "4713")
int getUdpPort();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
import com.payneteasy.srvlog.adapter.utils.IRunnableFactory;
import com.payneteasy.srvlog.data.LogData;
import com.payneteasy.srvlog.service.ILogCollector;
import com.payneteasy.startup.parameters.StartupParametersFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.net.Socket;

@Service
public class LogbackTCPAdapter extends AbstractTCPLoggerAdapter {

private static final ILogbackAdapterConfig adapterConfig = StartupParametersFactory
.getStartupParameters(ILogbackAdapterConfig.class);

@Autowired
public LogbackTCPAdapter(
ILogCollector logCollector,
@Value("${logbackProgram}") String program,
@Value("${logbackTCPPort}") int serverPort) {
public LogbackTCPAdapter(ILogCollector logCollector) {
super(logCollector, adapterConfig.getProgram(), adapterConfig.getTcpPort());
}

public LogbackTCPAdapter(ILogCollector logCollector, String program, int serverPort) {
super(logCollector, program, serverPort);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.payneteasy.srvlog.adapter.udp.IDatagramProcessor;
import com.payneteasy.srvlog.data.LogData;
import com.payneteasy.srvlog.service.ILogCollector;
import com.payneteasy.startup.parameters.StartupParametersFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.ByteArrayInputStream;
Expand All @@ -16,14 +16,18 @@
@Service
public class LogbackUDPAdapter extends AbstractUDPLoggerAdapter {

@Autowired
public LogbackUDPAdapter(
ILogCollector logCollector,
@Value("${logbackProgram}") String program,
@Value("${logbackUDPPort}") int serverPort) {
private static final ILogbackAdapterConfig adapterConfig = StartupParametersFactory
.getStartupParameters(ILogbackAdapterConfig.class);

public LogbackUDPAdapter(ILogCollector logCollector, String program, int serverPort) {
super(serverPort, program, logCollector);
}

@Autowired
public LogbackUDPAdapter(ILogCollector logCollector) {
super(adapterConfig.getUdpPort(), adapterConfig.getProgram(), logCollector);
}

@Override
protected String getLoggerTypeName() {
return "logback";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.payneteasy.srvlog.service.impl;

import com.payneteasy.startup.parameters.AStartupParameter;

public interface ILogBroadcastingConfig {

@AStartupParameter(name = "LOG_STORAGE_CAPACITY", value = "1000")
int getProgramLogStorageCapacity();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.payneteasy.srvlog.service.impl;

import com.payneteasy.startup.parameters.AStartupParameter;

public interface ISphinxConfig {

@AStartupParameter(name = "SPHINX_HOST", value = "localhost")
String getHost();

@AStartupParameter(name = "SPHINX_PORT", value = "9312")
int getPort();

@AStartupParameter(name = "SPHINX_CONNECT_TIMEOUT", value = "30000")
int getConnectTimeout();

@AStartupParameter(name = "SPHINX_QUERY_INDEXES", value = "srvlog_index_main,srvlog_index_delta")
String getQueryIndexes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.payneteasy.srvlog.data.LogData;
import com.payneteasy.srvlog.service.ILogBroadcastingService;
import com.payneteasy.startup.parameters.StartupParametersFactory;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.websocket.api.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import org.eclipse.jetty.websocket.api.Session;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -37,14 +36,19 @@ public class LogBroadcastingServiceImpl implements ILogBroadcastingService {

private final ConcurrentMap<String, ConcurrentMap<String, InMemoryLogStorage>> logStorage = new ConcurrentHashMap<>();

private static final ILogBroadcastingConfig logBroadcastingConfig = StartupParametersFactory
.getStartupParameters(ILogBroadcastingConfig.class);
private static final int DEFAULT_PROGRAM_LOG_STORAGE_CAPACITY = 1000;

private final int programLogStorageCapacity;

@Autowired
public LogBroadcastingServiceImpl(@Value("${programLogStorageCapacity}") int programLogStorageCapacity) {
this.programLogStorageCapacity = programLogStorageCapacity > 0 ?
programLogStorageCapacity : DEFAULT_PROGRAM_LOG_STORAGE_CAPACITY;
public LogBroadcastingServiceImpl() {
this.programLogStorageCapacity = logBroadcastingConfig.getProgramLogStorageCapacity() > 0 ?
logBroadcastingConfig.getProgramLogStorageCapacity() : DEFAULT_PROGRAM_LOG_STORAGE_CAPACITY;
}

public LogBroadcastingServiceImpl(int programLogStorageCapacity) {
this.programLogStorageCapacity = programLogStorageCapacity;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import com.payneteasy.srvlog.data.LogLevel;
import com.payneteasy.srvlog.service.IIndexerService;
import com.payneteasy.srvlog.service.IndexerServiceException;
import com.payneteasy.startup.parameters.StartupParametersFactory;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sphx.api.SphinxClient;
import org.sphx.api.SphinxException;
import org.sphx.api.SphinxMatch;
import org.sphx.api.SphinxResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -28,17 +28,8 @@ public class SphinxIndexerService implements IIndexerService{

private static final Logger LOG = LoggerFactory.getLogger(SphinxIndexerService.class);

@Value( "${sphinxHost}" )
private String host;

@Value( "${sphinxPort}" )
private int port;

@Value( "${sphinxConnectTimeout}" )
private int connectTimeout;

@Value( "${sphinxQueryIndexes}" )
private String sphinxQueryIndexes;
private static final ISphinxConfig sphinxConfig = StartupParametersFactory
.getStartupParameters(ISphinxConfig.class);

@Override
public List<Long> search(Date from, Date to, List<Integer> facilities, List<Integer> severities, List<Integer> hosts, String pattern, Integer offset, Integer limit) throws IndexerServiceException {
Expand Down Expand Up @@ -83,8 +74,8 @@ private void setLimits(Integer offset, Integer limit, SphinxClient sphinxClient)
}

private SphinxClient createSphinxClient() {
SphinxClient sphinxClient = new SphinxClient(host, port);
sphinxClient.SetConnectTimeout(connectTimeout);
SphinxClient sphinxClient = new SphinxClient(sphinxConfig.getHost(), sphinxConfig.getPort());
sphinxClient.SetConnectTimeout(sphinxConfig.getConnectTimeout());
return sphinxClient;
}

Expand All @@ -108,7 +99,7 @@ private boolean errorOccuredWhileQuerying(SphinxClient sphinxClient, SphinxResul
private SphinxResult querySphinx(String pattern, SphinxClient sphinxClient) throws IndexerServiceException {
SphinxResult result;
try {
result = sphinxClient.Query(pattern, sphinxQueryIndexes);
result = sphinxClient.Query(pattern, sphinxConfig.getQueryIndexes());
} catch (SphinxException e) {
LOG.error("While sending query to Sphinx Daemon", e);
throw new IndexerServiceException("While sending query to Sphinx Daemon", e);
Expand Down Expand Up @@ -263,19 +254,4 @@ private int[] toIntArray(List<Integer> list) {
return array;
}

public void setHost(String host) {
this.host = host;
}

public void setPort(int port) {
this.port = port;
}

public int getPort() {
return port;
}

public void setConnectTimeout(int connectTimeout) {
this.connectTimeout = connectTimeout;
}
}
1 change: 0 additions & 1 deletion srvlog-service/src/main/resources/inMemoryLog.properties

This file was deleted.

3 changes: 0 additions & 3 deletions srvlog-service/src/main/resources/logbackAdapter.properties

This file was deleted.

4 changes: 0 additions & 4 deletions srvlog-service/src/main/resources/sphinxclient.properties

This file was deleted.

0 comments on commit 06b3bcb

Please sign in to comment.