-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite the workload classes to use a fluent style w/ mixins so that …
…the structure of what's being cons'ed together is much more immediately clear. Fixed a bug in the docId having a space in it (I presume that was unintentional) Signed-off-by: Greg Schohn <greg.schohn@gmail.com>
- Loading branch information
1 parent
d90a448
commit 9078313
Showing
13 changed files
with
285 additions
and
322 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
DataGenerator/src/main/java/org/opensearch/migrations/data/ElasticsearchType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.opensearch.migrations.data; | ||
|
||
public enum ElasticsearchType { | ||
DATE("date"), | ||
GEO_POINT("geo_point"), | ||
INTEGER("integer"), | ||
KEYWORD("keyword"), | ||
LONG("long"), | ||
TEXT("text"), | ||
SCALED_FLOAT("scaled_float"), | ||
IP("ip"), | ||
NESTED("nested"); | ||
|
||
private final String value; | ||
|
||
ElasticsearchType(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
DataGenerator/src/main/java/org/opensearch/migrations/data/FieldBuilders.java
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
DataGenerator/src/main/java/org/opensearch/migrations/data/IFieldCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.opensearch.migrations.data; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
/** | ||
* Helpers to build fields for index mappings. | ||
*/ | ||
public interface IFieldCreator { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
|
||
default ObjectNode createField(ElasticsearchType type) { | ||
return mapper.createObjectNode().put("type", type.getValue()); | ||
} | ||
|
||
default ObjectNode fieldGeoPoint() { return createField(ElasticsearchType.GEO_POINT); } | ||
default ObjectNode fieldInt() { return createField(ElasticsearchType.INTEGER); } | ||
default ObjectNode fieldIP() { return createField(ElasticsearchType.IP); } | ||
default ObjectNode fieldKeyword() { return createField(ElasticsearchType.KEYWORD); } | ||
default ObjectNode fieldLong() { return createField(ElasticsearchType.LONG); } | ||
default ObjectNode fieldNested() { return createField(ElasticsearchType.NESTED); } | ||
default ObjectNode fieldText() { return createField(ElasticsearchType.TEXT); } | ||
|
||
default ObjectNode fieldRawTextKeyword() { | ||
return mapper.createObjectNode() | ||
.put("type", "text") | ||
.set("fields", mapper.createObjectNode() | ||
.set("raw", createField(ElasticsearchType.KEYWORD))); | ||
} | ||
|
||
default ObjectNode fieldScaledFloat(int scalingFactor) { | ||
return createField(ElasticsearchType.SCALED_FLOAT) | ||
.put("scaling_factor", scalingFactor); | ||
} | ||
default ObjectNode fieldScaledFloat() { return fieldScaledFloat(100); } | ||
|
||
default ObjectNode fieldDate() { return createField(ElasticsearchType.DATE); } | ||
default ObjectNode fieldDateISO() { | ||
return fieldDate().put("format", "yyyy-MM-dd HH:mm:ss"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
DataGenerator/src/main/java/org/opensearch/migrations/data/IRandomDataBuilders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.opensearch.migrations.data; | ||
|
||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Random; | ||
|
||
/** Shared ways to build random data */ | ||
public interface IRandomDataBuilders { | ||
ZoneId UTC_ZONE = ZoneId.of("UTC"); | ||
DateTimeFormatter SIMPLE_DATE_PATTERN = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
int ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000; | ||
|
||
default long randomTime(long timeFrom, Random random) { | ||
return timeFrom - random.nextInt(ONE_DAY_IN_MILLIS); | ||
} | ||
|
||
default String randomTimeISOString(long timeFrom, Random random) { | ||
var timeMillis = randomTime(timeFrom, random); | ||
var timeInstant = Instant.ofEpochMilli(timeMillis).atZone(UTC_ZONE); | ||
return SIMPLE_DATE_PATTERN.format(timeInstant); | ||
} | ||
|
||
default double randomDouble(Random random, double min, double max) { | ||
return min + (max - min) * random.nextDouble(); | ||
} | ||
|
||
default String randomElement(String[] elements, Random random) { | ||
return elements[random.nextInt(elements.length)]; | ||
} | ||
|
||
default int randomElement(int[] elements, Random random) { | ||
return elements[random.nextInt(elements.length)]; | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
DataGenerator/src/main/java/org/opensearch/migrations/data/RandomDataBuilders.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.