Skip to content

Commit

Permalink
Add Influx retention policy property bindings to spring legacy module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Schneider committed Jul 19, 2018
1 parent 111e0d0 commit 11f2606
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CreateDatabaseQueryBuilder {
private static final String QUERY_MANDATORY_TEMPLATE = "CREATE DATABASE %s";
private static final String RETENTION_POLICY_INTRODUCTION = " WITH";
private static final String DURATION_CLAUSE_TEMPLATE = " DURATION %s";
private static final String REPLICATION_FACTOR_CLAUSE_TEMPLATE = " REPLICATION %s";
private static final String REPLICATION_FACTOR_CLAUSE_TEMPLATE = " REPLICATION %d";
private static final String SHARD_DURATION_CLAUSE_TEMPLATE = " SHARD DURATION %s";
private static final String NAME_CLAUSE_TEMPLATE = " NAME %s";

Expand All @@ -54,8 +54,8 @@ CreateDatabaseQueryBuilder setRetentionDuration(@Nullable String retentionDurati
return this;
}

CreateDatabaseQueryBuilder setRetentionReplicationFactor(@Nullable String retentionReplicationFactor) {
if (!isEmpty(retentionReplicationFactor)) {
CreateDatabaseQueryBuilder setRetentionReplicationFactor(@Nullable Integer retentionReplicationFactor) {
if (retentionReplicationFactor != null) {
retentionPolicyClauses[1] = String.format(REPLICATION_FACTOR_CLAUSE_TEMPLATE, retentionReplicationFactor);
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,24 @@ default String retentionPolicy() {
}

/**
* @return time period for which influx should retain data in the current database (e.g. 2h, 52w)
* @return Time period for which influx should retain data in the current database (e.g. 2h, 52w).
*/
@Nullable
default String retentionDuration(){
return get(prefix() + ".retentionDuration");
}

/**
* @return how many copies of the data are stored in the cluster. Must be 1 for a single node instance
* @return How many copies of the data are stored in the cluster. Must be 1 for a single node instance.
*/
@Nullable
default String retentionReplicationFactor(){
return get(prefix() + ".retentionReplicationFactor");
default Integer retentionReplicationFactor(){
String v = get(prefix() + ".retentionReplicationFactor");
return v == null ? null : Integer.parseInt(v);
}

/**
* @return the time range covered by a shard group
/**
* @return The time range covered by a shard group (e.g. 2h, 52w).
*/
@Nullable
default String retentionShardDuration(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void oneClauseInRetentionPolicy() {
void allClausesInRetentionPolicy() {
String query = createDatabaseQueryBuilder.setRetentionPolicyName("dummy_policy")
.setRetentionDuration("2d")
.setRetentionReplicationFactor("1")
.setRetentionReplicationFactor(1)
.setRetentionShardDuration("3")
.build();
assertEquals("CREATE DATABASE dummy_database_0 WITH DURATION 2d REPLICATION 1 SHARD DURATION 3 NAME dummy_policy", query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ public class InfluxProperties extends StepRegistryProperties {
*/
private Boolean autoCreateDb;

/**
* Time period for which influx should retain data in the current database (e.g. 2h, 52w)
*/
private String retentionDuration;

/**
* How many copies of the data are stored in the cluster. Must be 1 for a single node instance.
*/
private Integer retentionReplicationFactor;

/**
* The time range covered by a shard group (e.g. 2h, 52w).
*/
private String retentionShardDuration;

public String getDb() {
return this.db;
}
Expand Down Expand Up @@ -132,4 +147,28 @@ public Boolean getAutoCreateDb() {
public void setAutoCreateDb(Boolean autoCreateDb) {
this.autoCreateDb = autoCreateDb;
}

public String getRetentionDuration() {
return retentionDuration;
}

public void setRetentionDuration(String retentionDuration) {
this.retentionDuration = retentionDuration;
}

public Integer getRetentionReplicationFactor() {
return retentionReplicationFactor;
}

public void setRetentionReplicationFactor(Integer retentionReplicationFactor) {
this.retentionReplicationFactor = retentionReplicationFactor;
}

public String getRetentionShardDuration() {
return retentionShardDuration;
}

public void setRetentionShardDuration(String retentionShardDuration) {
this.retentionShardDuration = retentionShardDuration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,22 @@ public String password() {

@Override
public String retentionPolicy() {
return get(InfluxProperties::getRetentionPolicy,
InfluxConfig.super::retentionPolicy);
return get(InfluxProperties::getRetentionPolicy, InfluxConfig.super::retentionPolicy);
}

@Override
public Integer retentionReplicationFactor() {
return get(InfluxProperties::getRetentionReplicationFactor, InfluxConfig.super::retentionReplicationFactor);
}

@Override
public String retentionDuration() {
return get(InfluxProperties::getRetentionDuration, InfluxConfig.super::retentionDuration);
}

@Override
public String retentionShardDuration() {
return get(InfluxProperties::getRetentionShardDuration, InfluxConfig.super::retentionShardDuration);
}

@Override
Expand Down

0 comments on commit 11f2606

Please sign in to comment.