create web application

This commit is contained in:
2016-12-21 17:48:36 +01:00
parent 35054b00b8
commit d1e39513f3
65 changed files with 805 additions and 43 deletions

5
pdb-api/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
/bin/
/build/
/.settings/
/.classpath
/.project

4
pdb-api/build.gradle Normal file
View File

@@ -0,0 +1,4 @@
dependencies {
}

View File

@@ -1,13 +1,11 @@
package org.lucares.performance.db;
package org.lucares.pdb.api;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
public class Entry {
public static final Comparator<Entry> BY_DATE = new EntryByDateComparator();
/**
* A special {@link Entry} that can be used as poison object for
@@ -29,7 +27,7 @@ public class Entry {
this.value = value;
}
Entry(final long epochMilli, final long value, final Tags tags) {
public Entry(final long epochMilli, final long value, final Tags tags) {
if (value < 0 || value > MAX_VALUE) {
throw new IllegalArgumentException("value must be between 0 and " + MAX_VALUE + ", but was " + value);
}
@@ -54,7 +52,7 @@ public class Entry {
return value;
}
long getEpochMilli() {
public long getEpochMilli() {
return epochMilli;
}

View File

@@ -1,4 +1,4 @@
package org.lucares.performance.db;
package org.lucares.pdb.api;
import java.util.List;
import java.util.stream.Collectors;

View File

@@ -1,4 +1,4 @@
package org.lucares.performance.db;
package org.lucares.pdb.api;
import java.util.ArrayList;
import java.util.Arrays;

View File

@@ -1,4 +1,4 @@
package org.lucares.performance.db;
package org.lucares.pdb.api;
public class Tag {
private final String key;

View File

@@ -1,4 +1,4 @@
package org.lucares.performance.db;
package org.lucares.pdb.api;
import java.util.Collections;
import java.util.HashMap;
@@ -21,15 +21,6 @@ public class Tags {
private Tags(final Map<String, Tag> tags) {
this.tags = tags;
ensureNoInternalFields();
}
private void ensureNoInternalFields() {
tags.keySet().forEach(key -> {
if (Fields.isInternalField(key)) {
throw new IllegalArgumentException(key + " is an internal field. Choose another prefix.");
}
});
}
public static Tags create() {

View File

@@ -15,7 +15,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.stream.Stream;
import org.lucares.performance.db.Entry;
import org.lucares.pdb.api.Entry;
import org.lucares.performance.db.FileUtils;
import org.lucares.performance.db.PerformanceDb;

View File

@@ -19,10 +19,10 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.Tags;
import org.lucares.performance.db.BlockingQueueIterator;
import org.lucares.performance.db.Entry;
import org.lucares.performance.db.PerformanceDb;
import org.lucares.performance.db.Tags;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.MappingIterator;

View File

@@ -15,7 +15,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.lucares.performance.db.Entry;
import org.lucares.pdb.api.Entry;
import org.lucares.performance.db.FileUtils;
import org.lucares.performance.db.PerformanceDb;
import org.lucares.recommind.logs.TcpIngestor;

5
pdb-ui/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
/bin/
/build/
/.settings/
/.classpath
/.project

7
pdb-ui/build.gradle Normal file
View File

@@ -0,0 +1,7 @@
dependencies {
compile project(':performanceDb')
compile("org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE")
testCompile("org.springframework.boot:spring-boot-starter-test:1.4.2.RELEASE")
}

View File

@@ -0,0 +1,12 @@
package org.lucares.pdbui;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("org.lucares.pdbui")
// @PropertySource("classpath:/config.system.properties")
// @PropertySource("classpath:/config.user.properties")
public class MySpringConfiguration {
}

View File

@@ -0,0 +1,14 @@
package org.lucares.pdbui;
import java.nio.file.Paths;
import org.springframework.boot.SpringApplication;
public class MyWebapp {
public static final String IMAGE_DIR = Paths.get("/tmp/images").toFile().getAbsolutePath() + "/";
public static void main(final String[] args) throws Exception {
SpringApplication.run(MySpringConfiguration.class, args);
}
}

View File

@@ -0,0 +1,34 @@
package org.lucares.pdbui;
import org.lucares.pdbui.domain.PlotRequest;
import org.lucares.pdbui.domain.PlotResponse;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class PdbController {
private final PdbRepository pdbRepository;
public PdbController(final PdbRepository pdbRepository) {
this.pdbRepository = pdbRepository;
}
@RequestMapping(path = "/plots", //
method = RequestMethod.POST, //
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, //
produces = MediaType.APPLICATION_JSON_UTF8_VALUE //
)
@ResponseBody
PlotResponse createPlot(@RequestBody final PlotRequest request) {
System.out.println(request.getQuery());
return new PlotResponse("img/abc.png");
}
}

View File

@@ -0,0 +1,19 @@
package org.lucares.pdbui;
import org.lucares.performance.db.PerformanceDb;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.stereotype.Repository;
@Repository
public class PdbRepository implements DisposableBean {
private final PerformanceDb db;
public PdbRepository(final PerformanceDb db) {
this.db = db;
}
@Override
public void destroy() {
db.close();
}
}

View File

@@ -0,0 +1,14 @@
package org.lucares.pdbui;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/img/**").addResourceLocations("file:" + MyWebapp.IMAGE_DIR);
}
}

View File

@@ -0,0 +1,18 @@
package org.lucares.pdbui.domain;
public class PlotRequest {
private String query;
public String getQuery() {
return query;
}
public void setQuery(final String query) {
this.query = query;
}
@Override
public String toString() {
return query;
}
}

View File

@@ -0,0 +1,31 @@
package org.lucares.pdbui.domain;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PlotResponse {
private List<String> imageUrls = new ArrayList<>();
public PlotResponse() {
super();
}
public PlotResponse(final String... imageUrls) {
this.imageUrls.addAll(Arrays.asList(imageUrls));
}
public List<String> getImageUrls() {
return imageUrls;
}
public void setImageUrls(final List<String> imageUrls) {
this.imageUrls = imageUrls;
}
@Override
public String toString() {
return String.valueOf(imageUrls);
}
}

View File

@@ -0,0 +1 @@
db.base=/tmp/db

View File

@@ -0,0 +1 @@
db.base=/home/andi/ws/performanceDb/db

View File

@@ -0,0 +1,55 @@
body {
margin:0;
padding:0;
}
@font-face {
font-family: 'FontAwesome';
src: url('../fonts/fontawesome-webfont.eot?v=4.7.0');
src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'), url('../fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
font-weight: normal;
font-style: normal;
}
#top-menu-bar {
background-color: black;
color: white;
padding: 3px;
}
#logo {
font-weight: bold;
}
#search-bar {
background-color: #aaa;
text-align: right;
padding-bottom:3px;
}
#search-bar #search-query {
width:100%;
padding:2;
border:0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#search-bar #search-submit {
margin-right:3px;
}
#result-view {
background: red;
font-size: 32px;
}
#result-view i {
background: white;
display:inline;
font-style:normal;
line-height: 1.2em;
}

View File

@@ -0,0 +1,34 @@
.fa {
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* makes the font 33% larger relative to the icon container */
.fa-lg {
font-size: 1.33333333em;
line-height: 0.75em;
vertical-align: -15%;
}
.fa-2x {
font-size: 2em;
}
.fa-3x {
font-size: 3em;
}
.fa-4x {
font-size: 4em;
}
.fa-5x {
font-size: 5em;
}
.fa-search:before {
content: "\f002";
}
.fa-icons:before {
content: "\f002";
}

View File

@@ -0,0 +1,8 @@
body, p, td, th, textarea
{
font-family: sans-serif;
}
textarea {
font-size:1.2em;
}

View File

@@ -0,0 +1,2 @@
/font-awesome-4.7.0/
/font-awesome-4.7.0.zip

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/search.js"></script>
<link rel="stylesheet" type="text/css" href="css/typography.css">
<link rel="stylesheet" type="text/css" href="css/design.css">
<link rel="stylesheet" type="text/css" href="css/icons.css">
</head>
<body>
<div id="top-menu-bar">
<div id="logo">LOGO</div>
</div>
<div id="search-bar">
<textarea id="search-query"></textarea>
<button id="search-submit"><i class="fa fa-search"> Search</i></button>
</div>
<div id="result-view">
</div>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,39 @@
$(document).ready(function(){
$('#search-submit').click(function(event){
event.preventDefault(); // prevent submit of form which would reload the page
var request = {};
request['query'] = $('#search-query').val();
var success = function(response){
$('#result-view').text("SUCCESS: "+response.imageUrls);
};
var error = function(e) {
//var response = JSON.parse(e.responseText);
$('#result-view').text("FAILED: " + JSON.stringify(e));
};
postJson("plots", request, success, error);
});
});
function postJson(url, requestData, successCallback, errorCallback) {
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(requestData),
contentType: 'application/json'
})
.done(successCallback)
.fail(errorCallback);
}

View File

@@ -0,0 +1,11 @@
package org.lucares.pdbui;
import org.lucares.pdbui.MySpringConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
@SpringBootTest
@Import(MySpringConfiguration.class)
public class MySpringTestConfiguration {
}

View File

@@ -0,0 +1,24 @@
package org.lucares.pdbui;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MySpringTestConfiguration.class)
public class TimeTest {
// @Autowired
// private PdbController timeController;
//
// @Test
// public void testReturnedTimeIsNow() throws Exception {
// final Date before = new Date();
//
// final Date now = timeController.time();
// final Date after = new Date();
//
// Assert.assertTrue(before.compareTo(now) <= 0);
// Assert.assertTrue(now.compareTo(after) <= 0);
// }
}

5
pdb-utils/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
/bin/
/build/
/.settings/
/.classpath
/.project

4
pdb-utils/build.gradle Normal file
View File

@@ -0,0 +1,4 @@
dependencies {
}

View File

@@ -0,0 +1,99 @@
package org.lucares.pdb.api;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
public class Entry {
/**
* A special {@link Entry} that can be used as poison object for
* {@link BlockingQueueIterator}.
*/
public static final Entry POISON = new Entry(0, -1);
public static final long MAX_VALUE = 0xFF_FF_FF_FFL;
private final long epochMilli;
private final long value;
private final Tags tags;
public Entry(final OffsetDateTime date, final long value, final Tags tags) {
this.tags = tags;
this.epochMilli = date.toInstant().toEpochMilli();
this.value = value;
}
public Entry(final long epochMilli, final long value, final Tags tags) {
if (value < 0 || value > MAX_VALUE) {
throw new IllegalArgumentException("value must be between 0 and " + MAX_VALUE + ", but was " + value);
}
this.epochMilli = epochMilli;
this.value = value;
this.tags = tags;
}
private Entry(final long epochMilli, final long value) {
this.epochMilli = epochMilli;
this.value = value;
this.tags = null;
}
public OffsetDateTime getDate() {
final Instant instant = Instant.ofEpochMilli(epochMilli);
return OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
}
public long getValue() {
return value;
}
public long getEpochMilli() {
return epochMilli;
}
public Tags getTags() {
return tags;
}
@Override
public String toString() {
final OffsetDateTime date = getDate();
return date.format(DateTimeFormatter.ISO_ZONED_DATE_TIME) + " = " + value + " (" + tags + ")";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (epochMilli ^ (epochMilli >>> 32));
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
result = prime * result + (int) (value ^ (value >>> 32));
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Entry other = (Entry) obj;
if (epochMilli != other.epochMilli)
return false;
if (tags == null) {
if (other.tags != null)
return false;
} else if (!tags.equals(other.tags))
return false;
if (value != other.value)
return false;
return true;
}
}

View File

@@ -0,0 +1,32 @@
package org.lucares.pdb.api;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class GroupResult {
private final Tags groupedBy;
private final Stream<Entry> entries;
public GroupResult(final Stream<Entry> entries, final Tags groupedBy) {
this.entries = entries;
this.groupedBy = groupedBy;
}
/**
* @return {@link Stream} unbound, unordered and non-parallel
*/
public Stream<Entry> asStream() {
return entries;
}
public List<Entry> asList() {
return entries.collect(Collectors.toList());
}
public Tags getGroupedBy() {
return groupedBy;
}
}

View File

@@ -0,0 +1,30 @@
package org.lucares.pdb.api;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class Result {
private final List<GroupResult> groupResults;
public Result(final GroupResult... groupResults) {
this(Arrays.asList(groupResults));
}
public Result(final Collection<GroupResult> groupResults) {
this.groupResults = new ArrayList<>(groupResults);
}
public GroupResult singleGroup() {
if (groupResults.size() != 1) {
throw new IllegalStateException("the result does not contain exactly one group");
}
return groupResults.get(0);
}
public List<GroupResult> getGroups() {
return new ArrayList<>(groupResults);
}
}

View File

@@ -0,0 +1,57 @@
package org.lucares.pdb.api;
public class Tag {
private final String key;
private final String value;
public Tag(final String key, final String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
@Override
public String toString() {
return key + "=" + value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Tag other = (Tag) obj;
if (key == null) {
if (other.key != null)
return false;
} else if (!key.equals(other.key))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
}

View File

@@ -0,0 +1,136 @@
package org.lucares.pdb.api;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.function.BiConsumer;
public class Tags {
static final Tags EMPTY = new Tags();
private final Map<String, Tag> tags;
private Tags() {
super();
tags = Collections.emptyMap();
}
private Tags(final Map<String, Tag> tags) {
this.tags = tags;
}
public static Tags create() {
return EMPTY;
}
public static Tags create(final String key1, final String value1, final String key2, final String value2) {
final Map<String, Tag> tags = new HashMap<>(2);
tags.put(key1, new Tag(key1, value1));
tags.put(key2, new Tag(key2, value2));
return new Tags(tags);
}
public static Tags create(final String key, final String value) {
final Map<String, Tag> tags = new HashMap<>(1);
tags.put(key, new Tag(key, value));
return new Tags(tags);
}
public Tags copyAdd(final String key, final String value) {
Objects.requireNonNull(key, "key must not be null");
Objects.requireNonNull(value, "value must not be null");
final Map<String, Tag> newTags = new HashMap<>(tags);
newTags.put(key, new Tag(key, value));
return new Tags(newTags);
}
public Tags copyAddIfNotNull(final String key, final String value) {
final Tags result;
if (value != null) {
result = copyAdd(key, value);
} else {
result = this;
}
return result;
}
public String getValue(final String key) {
final Tag tag = tags.get(key);
final String value = tag != null ? tag.getValue() : null;
return value;
}
public Set<String> getKeys() {
return new TreeSet<>(tags.keySet());
}
public void forEach(final BiConsumer<String, String> keyValueConsumer) {
for (final Map.Entry<String, Tag> e : tags.entrySet()) {
keyValueConsumer.accept(e.getKey(), e.getValue().getValue());
}
}
@Override
public String toString() {
return String.valueOf(tags);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Tags other = (Tags) obj;
if (tags == null) {
if (other.tags != null)
return false;
} else if (!tags.equals(other.tags))
return false;
return true;
}
public String abbreviatedRepresentation() {
final StringBuilder result = new StringBuilder();
final int maxLength = 200;
final SortedSet<String> keys = new TreeSet<>(tags.keySet());
final int cutAt = maxLength / (keys.size() * 2 + 2);
for (final String key : keys) {
final String value = tags.get(key).getValue();
result.append(substr(key, cutAt));
result.append("-");
result.append(substr(value, cutAt));
result.append("_");
}
return substr(result.toString(), maxLength);
}
private static String substr(final String s, final int maxLength) {
return s.substring(0, Math.min(maxLength, s.length()));
}
}

View File

@@ -1,9 +1,7 @@
dependencies {
//compile 'com.fasterxml.jackson.core:jackson-databind:2.8.5'
compile 'org.lucares:ludb:1.0.20161002111352'
//compile 'commons-io:commons-io:2.5'
//compile 'joda-time:joda-time:2.9.6'
compile project(':pdb-api')
compile 'org.lucares:ludb:1.0.20161217184921'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.5'
compile 'org.mapdb:mapdb:3.0.2'
}

View File

@@ -2,6 +2,8 @@ package org.lucares.performance.db;
import java.util.List;
import org.lucares.pdb.api.Tags;
class Group {
private final Tags tags;

View File

@@ -6,6 +6,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.lucares.pdb.api.Tags;
public class Grouping {
public static final String NO_GROUPING = null;

View File

@@ -2,6 +2,8 @@ package org.lucares.performance.db;
import java.io.File;
import org.lucares.pdb.api.Tags;
class PdbFile {
private final Tags tags;

View File

@@ -10,6 +10,9 @@ import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.Tags;
public class PdbFileIterator implements Iterator<Entry>, AutoCloseable {
private final static Logger LOGGER = Logger.getLogger(PdbFileIterator.class.getCanonicalName());

View File

@@ -8,6 +8,9 @@ import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Optional;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.Tags;
class PdbReader implements AutoCloseable {
private static final int BYTES_PER_VALUE = 4;

View File

@@ -6,6 +6,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Logger;
import org.lucares.pdb.api.Entry;
class PdbWriter implements AutoCloseable {
private final static Logger LOGGER = Logger.getLogger(PdbWriter.class.getCanonicalName());

View File

@@ -9,6 +9,8 @@ import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lucares.pdb.api.Tags;
public class PdbWriterManager implements AutoCloseable {
private final static Logger LOGGER = Logger.getLogger(PdbWriterManager.class.getCanonicalName());

View File

@@ -15,6 +15,10 @@ import java.util.logging.Logger;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.GroupResult;
import org.lucares.pdb.api.Result;
import org.lucares.pdb.api.Tags;
import org.lucares.performance.db.PdbWriterManager.PdbWriterSupplier;
public class PerformanceDb implements AutoCloseable {
@@ -84,6 +88,7 @@ public class PerformanceDb implements AutoCloseable {
final Entry entry = entryOptional.get();
final Tags tags = entry.getTags();
TagsUtils.ensureNoInternalFields(tags);
final OffsetDateTime date = entry.getDate();
final PdbWriter writer = manager.get(tags, date);

View File

@@ -1,5 +1,7 @@
package org.lucares.performance.db;
import org.lucares.pdb.api.Tags;
final class Query {
static String createQuery(final Tags tags) {
final StringBuilder result = new StringBuilder();

View File

@@ -17,8 +17,7 @@ import org.lucares.ludb.Field;
import org.lucares.ludb.FieldExistsException;
import org.lucares.ludb.FieldType;
import org.lucares.ludb.H2DB;
import liquibase.exception.LiquibaseException;
import org.lucares.pdb.api.Tags;
public class TagsToFile implements AutoCloseable, CollectionUtils {
@@ -28,16 +27,12 @@ public class TagsToFile implements AutoCloseable, CollectionUtils {
public TagsToFile(final Path dataDirectory) {
super();
this.dataDirectory = dataDirectory;
db = new H2DB(new File(dataDirectory.toFile(), "lu.db"));
try {
db = new H2DB(new File(dataDirectory.toFile(), "lu.db"));
try {
db.createField(Fields.DATE_OFFSET, FieldType.STRING);
} catch (final FieldExistsException e) {
// TODO @ahr ludb needs a hasField method, or a
// createIfNotExists
}
} catch (final LiquibaseException e) {
throw new RuntimeException(e);
db.createField(Fields.DATE_OFFSET, FieldType.STRING);
} catch (final FieldExistsException e) {
// TODO @ahr ludb needs a hasField method, or a
// createIfNotExists
}
}

View File

@@ -0,0 +1,13 @@
package org.lucares.performance.db;
import org.lucares.pdb.api.Tags;
class TagsUtils {
static void ensureNoInternalFields(final Tags tags) {
tags.getKeys().forEach(key -> {
if (Fields.isInternalField(key)) {
throw new IllegalArgumentException(key + " is an internal field. Choose another prefix.");
}
});
}
}

View File

@@ -2,7 +2,10 @@ package org.lucares.performance.db;
import java.util.Comparator;
import org.lucares.pdb.api.Entry;
public class EntryByDateComparator implements Comparator<Entry> {
public static final Comparator<Entry> INSTANCE = new EntryByDateComparator();
@Override
public int compare(final Entry o1, final Entry o2) {

View File

@@ -4,6 +4,7 @@ import java.io.File;
import java.io.Serializable;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -159,6 +160,7 @@ public class ObjectMapperTest {
private final ConcurrentMap<Long, TagEntry> mapObjects;
@SuppressWarnings("unchecked")
public TagDBMapDB() {
db = DBMaker.fileDB("/tmp/file4.db").fileMmapEnable().make();
@@ -227,7 +229,7 @@ public class ObjectMapperTest {
}
{
final long start = System.nanoTime();
final TagDBJson actualTagDB = om.readValue(file, TagDBJson.class);
om.readValue(file, TagDBJson.class);
System.out.println("json read: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
}
@@ -246,6 +248,7 @@ public class ObjectMapperTest {
{
final long start = System.nanoTime();
final TagDBH2 tagDB = new TagDBH2();
tagDB.close();
System.out.println("h2 read: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
}
@@ -301,19 +304,22 @@ public class ObjectMapperTest {
tagDB.addTagEntry(e);
}
}
}
}
}
public static void main(final String[] args) throws Exception {
// System.out.println(System.getProperty("java.class.path"));
System.out.println(System.getProperty("java.class.path"));
TimeUnit.SECONDS.sleep(5);
System.out.println("start: " + OffsetDateTime.now());
try (H2DB h2 = new H2DB(new File("/tmp/h2" + UUID.randomUUID().toString()))) {
System.out.println("done");
}
System.out.println("stop: " + OffsetDateTime.now());
TimeUnit.SECONDS.sleep(20);
TimeUnit.SECONDS.sleep(10);
System.out.println("closing");
}

View File

@@ -6,6 +6,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.time.OffsetDateTime;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.Tags;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

View File

@@ -6,6 +6,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.time.OffsetDateTime;
import org.lucares.pdb.api.Tags;
import org.lucares.performance.db.PdbWriterManager.PdbWriterSupplier;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;

View File

@@ -12,6 +12,10 @@ import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.commons.collections4.CollectionUtils;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.GroupResult;
import org.lucares.pdb.api.Result;
import org.lucares.pdb.api.Tags;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -147,9 +151,10 @@ public class PerformanceDbTest {
final List<Entry> actualEntriesAll = db.get(Query.createQuery(tagsCommon)).singleGroup().asList();
final List<Entry> expectedAll = CollectionUtils.collate(entriesOne,
CollectionUtils.collate(entriesTwo, entriesThree, Entry.BY_DATE), Entry.BY_DATE);
CollectionUtils.collate(entriesTwo, entriesThree, EntryByDateComparator.INSTANCE),
EntryByDateComparator.INSTANCE);
actualEntriesAll.sort(Entry.BY_DATE);
actualEntriesAll.sort(EntryByDateComparator.INSTANCE);
Assert.assertEquals(actualEntriesAll, expectedAll);
}

View File

@@ -6,6 +6,7 @@ import java.nio.file.Path;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import org.lucares.pdb.api.Tags;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;