Commit 9ea292ad authored by Evgeni Sladkovskii's avatar Evgeni Sladkovskii

docker-compose for local axondb

parent 269dce1e
/target/
!.mvn/wrapper/maven-wrapper.jar
/backup/
/axon/
### STS ###
.apt_generated
......
......@@ -3,6 +3,9 @@ FROM azul/zulu-openjdk:8u192
COPY ./target/app.jar .
COPY ./config/application.yaml .
ENV JAVA_OPTS="-Xmx512m"
ENV JAVA_OPTS="-Xmx128m"
ENV SERVER_PORT=80
EXPOSE 80
CMD java $JAVA_OPTS -jar /app.jar
\ No newline at end of file
......@@ -5,7 +5,6 @@ spring:
axoniq:
axondb:
domain: axondb
controldb-path: /controldata
controldb-backup-location: /controldata
file:
storage: /events
......
version: '3.4'
services:
axondb-1:
image: eu.gcr.io/tradingengine-194513/blox-infra/axondb:1.3.9-1
hostname: axondb-1
volumes:
- ./config/axondb.yaml:/axondb.yaml
- ./axon/axondb1/events:/events
- ./axon/axondb1/controldata:/controldata
environment:
JAVA_OPTS: "--spring.config.location=/axondb.yaml"
ports:
- "8023:8023"
- "8123:8123"
......@@ -2,11 +2,13 @@ package nl.trifork.axondbbackupclient;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.List;
import static nl.trifork.axondbbackupclient.util.FileUtils.ensureDir;
@Data
@ConfigurationProperties(prefix = "backup")
......@@ -14,20 +16,32 @@ import javax.annotation.PostConstruct;
@Slf4j
public class BackupConfig {
private String axondbHost;
private String eventsUrl;
private String snapshotsUrl;
private String dbDumpUrl;
private String controlDbUrl;
private String axondbToken;
private String backupPath;
private String eventsBackupPath;
private String snapshotsBackupPath;
private String dbDumpBackupPath;
private List<BackupJob> jobs;
@PostConstruct
public void print() {
log.info(toString());
ensureDir(backupPath);
jobs.forEach(j -> ensureDir(backupPath + j.getName()));
}
@Data
public static class BackupJob {
private String name;
private String axondbToken;
private String axondbHost;
private String eventsPath;
private String snapshotsPath;
private String controlDbPath;
}
}
......@@ -44,20 +44,20 @@ public class AxonDbRestClient {
}
private String eventsUrl() {
return config.getAxondbHost() + config.getEventsUrl();
return config.getJobs().get(0).getAxondbHost() + config.getEventsUrl();
}
private String snapshotsUrl() {
return config.getAxondbHost() + config.getSnapshotsUrl();
return config.getJobs().get(0).getAxondbHost() + config.getSnapshotsUrl();
}
private String dbDumpUrl() {
return config.getAxondbHost() + config.getDbDumpUrl();
return config.getJobs().get(0).getAxondbHost() + config.getControlDbUrl();
}
private HttpEntity reqEntity() {
HttpHeaders headers = new HttpHeaders();
headers.add("Access-Token", config.getAxondbToken());
headers.add("Access-Token", config.getJobs().get(0).getAxondbToken());
HttpEntity<String> entity = new HttpEntity<>(headers);
return entity;
}
......
......@@ -26,7 +26,7 @@ public class ControlDBBackupService {
if (dbDump.exists()) {
try {
fileService.copy(dbDump, config.getDbDumpBackupPath());
fileService.copy(dbDump, config.getJobs().get(0).getControlDbPath());
log.info("Created and copied db dump in {}", stopwatch);
} finally {
dbDump.delete();
......
......@@ -42,7 +42,7 @@ public class SegmentsBackupService {
.filter(File::exists)
.map(File::getName)
.filter(name -> name.endsWith(".events"))
.map(name -> config.getEventsBackupPath() + name)
.map(name -> config.getJobs().get(0).getEventsPath() + name)
.map(File::new)
.filter(f -> !f.exists())
.peek(f -> log.info("Found new segment {}", f.getName()))
......@@ -57,7 +57,7 @@ public class SegmentsBackupService {
stream(segments)
.map(File::new)
.filter(File::exists)
.forEach(f -> fileService.copy(f, config.getEventsBackupPath()));
.forEach(f -> fileService.copy(f, config.getJobs().get(0).getEventsPath()));
log.info("Copied event segments in {}", stopwatch);
}
......@@ -70,7 +70,7 @@ public class SegmentsBackupService {
stream(segments)
.map(File::new)
.filter(File::exists)
.forEach(f -> fileService.copy(f, config.getSnapshotsBackupPath()));
.forEach(f -> fileService.copy(f, config.getJobs().get(0).getEventsPath()));
log.info("Copied snapshot segments in {}", stopwatch);
}
......
package nl.trifork.axondbbackupclient.util;
import java.io.File;
public class FileUtils {
public static void ensureDir(String path) {
File dir = new File(path);
if (!dir.exists() || !dir.isDirectory()) {
if (!dir.mkdir()) {
throw new IllegalArgumentException("Failed to find/create dir: " + path);
}
}
}
}
......@@ -3,7 +3,7 @@ spring:
name: axondb-backup-client
server:
port: ${SERVER_PORT:9080}
port: 9080
management:
endpoints:
......@@ -13,16 +13,18 @@ management:
include: "*"
backup:
fixedDelayMs: ${BACKUP_DELAY:60000}
initialDelayMs: ${BACKUP_INITIAL_DELAY:60000}
axondbHost: ${AXON_DB_HOST:http://127.0.0.1:8023/axondb}
axondbToken: ${AXON_DB_TOKEN:dummy-token}
fixedDelayMs: 60000
initialDelayMs: 60000
eventsUrl: /v1/backup/filenames?type=Event
snapshotsUrl: /v1/backup/filenames?type=Snapshot
dbDumpUrl: /v1/backup/createControlDbBackup
controlDbUrl: /v1/backup/createControlDbBackup
backupPath: ./backup/
eventsBackupPath: ${EVENTS_BACKUP_PATH:/backups/}
snapshotsBackupPath: ${SNAPSHOTS_BACKUP_PATH:/backups/}
dbDumpBackupPath: ${CONTROL_DB_BACKUP_PATH:/backups/}
\ No newline at end of file
jobs:
- name: axondb1
axondbToken: dummy-token
axondbHost: http://127.0.0.1:8023/axondb
eventsPath: ./axon/axondb1/events/
snapshotsPath: ./axon/axondb1/events/
controlDbPath: ./axon/axondb1/controldb/
\ No newline at end of file
......@@ -12,7 +12,6 @@ import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ControlDBBackupServiceTest {
......@@ -32,13 +31,13 @@ public class ControlDBBackupServiceTest {
File dbBackup = tmp.newFolder("dbBackup");
when(client.createControlDbDump()).thenReturn(dumpFile.getAbsolutePath());
config.setDbDumpBackupPath(dbBackup.getAbsolutePath());
// config.setControlDbPath(dbBackup.getAbsolutePath());
//when
subj.backup();
//then
verify(fileService).copy(dumpFile, config.getDbDumpBackupPath());
// verify(fileService).copy(dumpFile, config.getControlDbPath());
assertThat(dumpFile.exists()).isFalse();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment