move TcpIngestor to pdb-ui
and start it in the web application. Also use the spring way of handling property files.
This commit is contained in:
@@ -3,6 +3,11 @@ apply plugin: 'application'
|
|||||||
|
|
||||||
|
|
||||||
mainClassName = "org.lucares.pdbui.PdbWebapp"
|
mainClassName = "org.lucares.pdbui.PdbWebapp"
|
||||||
|
applicationDefaultJvmArgs = [
|
||||||
|
"-Dspring.profiles.active=production",
|
||||||
|
"-Dspring.config.location=.",
|
||||||
|
"-Ddb.base=data"
|
||||||
|
]
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':performanceDb')
|
compile project(':performanceDb')
|
||||||
@@ -15,3 +20,7 @@ dependencies {
|
|||||||
|
|
||||||
testCompile("org.springframework.boot:spring-boot-starter-test:1.5.2.RELEASE")
|
testCompile("org.springframework.boot:spring-boot-starter-test:1.5.2.RELEASE")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
exclude 'application-dev.properties'
|
||||||
|
}
|
||||||
21
pdb-ui/src/main/java/org/lucares/pdbui/Ingestion.java
Normal file
21
pdb-ui/src/main/java/org/lucares/pdbui/Ingestion.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package org.lucares.pdbui;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Ingestion {
|
||||||
|
|
||||||
|
private final Ingestor tcpIngestor;
|
||||||
|
|
||||||
|
public Ingestion(final Ingestor tcpIngestor) {
|
||||||
|
this.tcpIngestor = tcpIngestor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void start() throws Exception {
|
||||||
|
tcpIngestor.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
7
pdb-ui/src/main/java/org/lucares/pdbui/Ingestor.java
Normal file
7
pdb-ui/src/main/java/org/lucares/pdbui/Ingestor.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package org.lucares.pdbui;
|
||||||
|
|
||||||
|
public interface Ingestor {
|
||||||
|
|
||||||
|
void start() throws Exception;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,12 +2,11 @@ package org.lucares.pdbui;
|
|||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@EnableAsync
|
||||||
@ComponentScan("org.lucares.pdbui")
|
@ComponentScan("org.lucares.pdbui")
|
||||||
@PropertySource("classpath:/config.system.properties")
|
|
||||||
@PropertySource("classpath:/config.user.properties")
|
|
||||||
public class MySpringConfiguration {
|
public class MySpringConfiguration {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,23 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.lucares.ludb.Proposal;
|
import org.lucares.ludb.Proposal;
|
||||||
import org.lucares.performance.db.PerformanceDb;
|
import org.lucares.performance.db.PerformanceDb;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class PdbRepository implements DisposableBean {
|
public class PdbRepository implements DisposableBean {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(PdbRepository.class);
|
||||||
|
|
||||||
private final PerformanceDb db;
|
private final PerformanceDb db;
|
||||||
|
|
||||||
public PdbRepository(@Value("${db.base}") final String dbBaseDir) {
|
public PdbRepository(@Value("${db.base}") final String dbBaseDir) {
|
||||||
final Path dataDirectory = Paths.get(dbBaseDir);
|
final Path dataDirectory = Paths.get(dbBaseDir);
|
||||||
|
|
||||||
|
LOGGER.info("using database in {}", dataDirectory.toAbsolutePath());
|
||||||
|
|
||||||
this.db = new PerformanceDb(dataDirectory);
|
this.db = new PerformanceDb(dataDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.lucares.recommind.logs;
|
package org.lucares.pdbui;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -20,19 +20,27 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
import org.lucares.pdb.api.Entry;
|
import org.lucares.pdb.api.Entry;
|
||||||
import org.lucares.pdb.api.Tags;
|
import org.lucares.pdb.api.Tags;
|
||||||
import org.lucares.performance.db.BlockingQueueIterator;
|
import org.lucares.performance.db.BlockingQueueIterator;
|
||||||
import org.lucares.performance.db.PerformanceDb;
|
import org.lucares.performance.db.PerformanceDb;
|
||||||
|
import org.lucares.recommind.logs.Config;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.MappingIterator;
|
import com.fasterxml.jackson.databind.MappingIterator;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.ObjectReader;
|
import com.fasterxml.jackson.databind.ObjectReader;
|
||||||
|
|
||||||
public class TcpIngestor implements AutoCloseable {
|
@Component
|
||||||
|
public class TcpIngestor implements Ingestor, AutoCloseable, DisposableBean {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(TcpIngestor.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(TcpIngestor.class);
|
||||||
private static final Logger METRICS_LOGGER = LoggerFactory.getLogger("org.lucares.metrics.tcpIngestor");
|
private static final Logger METRICS_LOGGER = LoggerFactory.getLogger("org.lucares.metrics.tcpIngestor");
|
||||||
|
|
||||||
@@ -158,6 +166,13 @@ public class TcpIngestor implements AutoCloseable {
|
|||||||
LOGGER.debug("performance db open");
|
LOGGER.debug("performance db open");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public TcpIngestor(final PdbRepository pdbRepository) {
|
||||||
|
db = pdbRepository.getDb();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
@Override
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
|
|
||||||
final ArrayBlockingQueue<Entry> queue = new ArrayBlockingQueue<>(1);
|
final ArrayBlockingQueue<Entry> queue = new ArrayBlockingQueue<>(1);
|
||||||
@@ -182,8 +197,7 @@ public class TcpIngestor implements AutoCloseable {
|
|||||||
|
|
||||||
private Void listen(final ArrayBlockingQueue<Entry> queue) throws IOException {
|
private Void listen(final ArrayBlockingQueue<Entry> queue) throws IOException {
|
||||||
Thread.currentThread().setName("socket-listener");
|
Thread.currentThread().setName("socket-listener");
|
||||||
try (ServerSocket serverSocket = new ServerSocket(
|
try (ServerSocket serverSocket = new ServerSocket(PORT);) {
|
||||||
PORT/* , 10, InetAddress.getLocalHost() */);) {
|
|
||||||
LOGGER.info("listening on port " + PORT);
|
LOGGER.info("listening on port " + PORT);
|
||||||
|
|
||||||
serverSocket.setSoTimeout((int) TimeUnit.MILLISECONDS.toMillis(100));
|
serverSocket.setSoTimeout((int) TimeUnit.MILLISECONDS.toMillis(100));
|
||||||
@@ -226,6 +240,12 @@ public class TcpIngestor implements AutoCloseable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
LOGGER.debug("stopping accept thread");
|
LOGGER.debug("stopping accept thread");
|
||||||
@@ -238,7 +258,7 @@ public class TcpIngestor implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
LOGGER.debug("closing database");
|
LOGGER.debug("closing database");
|
||||||
db.close();
|
db.close();
|
||||||
LOGGER.debug("close done");
|
LOGGER.info("destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(final String[] args) throws Exception {
|
public static void main(final String[] args) throws Exception {
|
||||||
1
pdb-ui/src/main/resources/application-dev.properties
Normal file
1
pdb-ui/src/main/resources/application-dev.properties
Normal file
@@ -0,0 +1 @@
|
|||||||
|
db.base=/home/andi/ws/performanceDb/db
|
||||||
4
pdb-ui/src/main/resources/application.properties
Normal file
4
pdb-ui/src/main/resources/application.properties
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
db.base=${java.io.tmpdir}/db
|
||||||
|
|
||||||
|
path.tmp=${java.io.tmpdir}/pdb/tmp
|
||||||
|
path.output=${java.io.tmpdir}/pdb/out
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
db.base=/tmp/db
|
|
||||||
|
|
||||||
path.tmp=/tmp/pdb/tmp
|
|
||||||
path.output=/tmp/pdb/out
|
|
||||||
@@ -19,9 +19,9 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.lucares.pdb.api.Entry;
|
import org.lucares.pdb.api.Entry;
|
||||||
|
import org.lucares.pdbui.TcpIngestor;
|
||||||
import org.lucares.performance.db.FileUtils;
|
import org.lucares.performance.db.FileUtils;
|
||||||
import org.lucares.performance.db.PerformanceDb;
|
import org.lucares.performance.db.PerformanceDb;
|
||||||
import org.lucares.recommind.logs.TcpIngestor;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
Reference in New Issue
Block a user