-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* InfluxDB2 addition with errors * Ready to test out influxdb2 * InfluxDB 2.0 working * Removed bucket and measurement change option. InfluxDB 2.0 seems stable
- Loading branch information
1 parent
85dc5fd
commit f0ea388
Showing
38 changed files
with
627 additions
and
130 deletions.
There are no files selected for viewing
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
19 changes: 19 additions & 0 deletions
19
client/src/main/java/me/retrodaredevil/okhttp3/OkHttpUtil.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,19 @@ | ||
package me.retrodaredevil.okhttp3; | ||
|
||
import okhttp3.OkHttpClient; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public final class OkHttpUtil { | ||
private OkHttpUtil() { throw new UnsupportedOperationException(); } | ||
|
||
public static OkHttpClient.Builder createBuilder(OkHttpProperties okHttpProperties) { | ||
return new OkHttpClient.Builder() | ||
.retryOnConnectionFailure(okHttpProperties.isRetryOnConnectionFailure()) | ||
.callTimeout(okHttpProperties.getCallTimeoutMillis(), TimeUnit.MILLISECONDS) | ||
.connectTimeout(okHttpProperties.getConnectTimeoutMillis(), TimeUnit.MILLISECONDS) | ||
.readTimeout(okHttpProperties.getReadTimeoutMillis(), TimeUnit.MILLISECONDS) | ||
.writeTimeout(okHttpProperties.getWriteTimeoutMillis(), TimeUnit.MILLISECONDS) | ||
.pingInterval(okHttpProperties.getPingIntervalMillis(), TimeUnit.MILLISECONDS); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...retrodaredevil/solarthing/config/databases/implementations/InfluxDb2DatabaseSettings.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,64 @@ | ||
package me.retrodaredevil.solarthing.config.databases.implementations; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; | ||
import me.retrodaredevil.influxdb.influxdb2.InfluxDb2Properties; | ||
import me.retrodaredevil.okhttp3.OkHttpProperties; | ||
import me.retrodaredevil.solarthing.annotations.Nullable; | ||
import me.retrodaredevil.solarthing.config.databases.DatabaseSettings; | ||
import me.retrodaredevil.solarthing.config.databases.DatabaseType; | ||
import me.retrodaredevil.solarthing.config.databases.SimpleDatabaseType; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
@JsonDeserialize(builder = InfluxDb2DatabaseSettings.Builder.class) | ||
@JsonTypeName("influxdb2") | ||
public class InfluxDb2DatabaseSettings implements DatabaseSettings { | ||
public static final DatabaseType TYPE = new SimpleDatabaseType("influxdb2"); | ||
|
||
private final InfluxDb2Properties influxDbProperties; | ||
private final OkHttpProperties okHttpProperties; | ||
|
||
public InfluxDb2DatabaseSettings(InfluxDb2Properties influxDbProperties, OkHttpProperties okHttpProperties) { | ||
requireNonNull(this.influxDbProperties = influxDbProperties); | ||
requireNonNull(this.okHttpProperties = okHttpProperties); | ||
} | ||
|
||
@Override | ||
public DatabaseType getDatabaseType() { | ||
return TYPE; | ||
} | ||
|
||
public InfluxDb2Properties getInfluxDbProperties() { | ||
return influxDbProperties; | ||
} | ||
public OkHttpProperties getOkHttpProperties() { | ||
return okHttpProperties; | ||
} | ||
|
||
@JsonPOJOBuilder | ||
public static class Builder { | ||
private InfluxDb2Properties influxDbProperties; | ||
private OkHttpProperties okHttpProperties; | ||
|
||
public InfluxDb2DatabaseSettings build() { | ||
return new InfluxDb2DatabaseSettings(influxDbProperties, okHttpProperties); | ||
} | ||
|
||
@JsonUnwrapped | ||
public Builder setInfluxDbProperties(InfluxDb2Properties influxDbProperties) { | ||
this.influxDbProperties = influxDbProperties; | ||
return this; | ||
} | ||
|
||
@JsonUnwrapped | ||
public Builder setOkHttpProperties(OkHttpProperties okHttpProperties) { | ||
this.okHttpProperties = okHttpProperties; | ||
return this; | ||
} | ||
|
||
} | ||
} |
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
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
68 changes: 68 additions & 0 deletions
68
client/src/main/java/me/retrodaredevil/solarthing/influxdb/PointUtil.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,68 @@ | ||
package me.retrodaredevil.solarthing.influxdb; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fasterxml.jackson.databind.node.ValueNode; | ||
import me.retrodaredevil.solarthing.annotations.TagKeys; | ||
import me.retrodaredevil.solarthing.packets.DocumentedPacket; | ||
import me.retrodaredevil.solarthing.packets.DocumentedPacketType; | ||
import me.retrodaredevil.solarthing.packets.Packet; | ||
import me.retrodaredevil.solarthing.packets.identification.Identifiable; | ||
import me.retrodaredevil.solarthing.packets.identification.Identifier; | ||
import me.retrodaredevil.solarthing.packets.identification.SupplementaryIdentifier; | ||
|
||
import java.util.*; | ||
|
||
public final class PointUtil { | ||
private PointUtil() { throw new UnsupportedOperationException(); } | ||
|
||
public static Map<String, String> getTags(Packet packet) { | ||
Map<String, String> r = new HashMap<>(); | ||
if(packet instanceof Identifiable){ | ||
Identifier identifier = ((Identifiable) packet).getIdentifier(); | ||
r.put("identifier", identifier.getRepresentation()); | ||
if(identifier instanceof SupplementaryIdentifier){ | ||
SupplementaryIdentifier supplementaryIdentifier = (SupplementaryIdentifier) identifier; | ||
r.put("identifier_supplementaryTo", supplementaryIdentifier.getSupplementaryTo().getRepresentation()); | ||
} | ||
} | ||
if(packet instanceof DocumentedPacket){ | ||
DocumentedPacket documentedPacket = (DocumentedPacket) packet; | ||
DocumentedPacketType type = documentedPacket.getPacketType(); | ||
r.put("packetType", type.toString()); | ||
} | ||
return r; | ||
} | ||
public static Collection<String> getTagKeys(Class<?> clazz){ | ||
/* | ||
Why we have to do this: https://stackoverflow.com/questions/26910620/class-getannotations-getdeclaredannotations-returns-empty-array-for-subcla#26911089 | ||
*/ | ||
Collection<String> tagKeys = new HashSet<>(); | ||
for(Class<?> interfaceClass : clazz.getInterfaces()){ | ||
tagKeys.addAll(getTagKeys(interfaceClass)); | ||
} | ||
TagKeys[] tagKeysAnnotations = clazz.getAnnotationsByType(TagKeys.class); // since Java 8, but that's fine | ||
for(TagKeys tagKeysAnnotation : tagKeysAnnotations){ | ||
tagKeys.addAll(Arrays.asList(tagKeysAnnotation.value())); | ||
} | ||
return tagKeys; | ||
} | ||
public static Set<Map.Entry<String, ValueNode>> flattenJsonObject(ObjectNode object) { | ||
Map<String, ValueNode> r = new LinkedHashMap<>(); | ||
for (Iterator<Map.Entry<String, JsonNode>> it = object.fields(); it.hasNext(); ) { | ||
Map.Entry<String, JsonNode> entry = it.next(); | ||
String key = entry.getKey(); | ||
JsonNode element = entry.getValue(); | ||
if (element.isValueNode() && !element.isNull()) { | ||
r.put(key, (ValueNode) element); | ||
} else if(element.isObject()){ | ||
Set<Map.Entry<String, ValueNode>> flat = flattenJsonObject((ObjectNode) element); | ||
for(Map.Entry<String, ValueNode> subEntry : flat){ | ||
r.put(key + "." + subEntry.getKey(), subEntry.getValue()); | ||
} | ||
} | ||
// ignore nulls and arrays | ||
} | ||
return r.entrySet(); | ||
} | ||
} |
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
19 changes: 12 additions & 7 deletions
19
...umentedMeasurementPacketPointCreator.java → ...umentedMeasurementPacketPointCreator.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 |
---|---|---|
@@ -1,25 +1,30 @@ | ||
package me.retrodaredevil.solarthing.influxdb; | ||
package me.retrodaredevil.solarthing.influxdb.influxdb1; | ||
|
||
import me.retrodaredevil.solarthing.influxdb.PointUtil; | ||
import me.retrodaredevil.solarthing.packets.DocumentedPacket; | ||
import me.retrodaredevil.solarthing.packets.DocumentedPacketType; | ||
import me.retrodaredevil.solarthing.packets.Packet; | ||
import me.retrodaredevil.solarthing.packets.identification.Identifiable; | ||
import me.retrodaredevil.solarthing.packets.identification.Identifier; | ||
import org.influxdb.dto.Point; | ||
|
||
import java.util.Map; | ||
|
||
public enum DocumentedMeasurementPacketPointCreator implements PacketPointCreator { | ||
INSTANCE; | ||
@Override | ||
public Point.Builder createBuilder(Packet packet) { | ||
if(packet instanceof DocumentedPacket){ | ||
DocumentedPacket documentedPacket = (DocumentedPacket) packet; | ||
DocumentedPacketType type = documentedPacket.getPacketType(); | ||
if(packet instanceof Identifiable){ | ||
Identifier identifier = ((Identifiable) packet).getIdentifier(); | ||
return Point.measurement(type.toString()).tag("identifier", identifier.getRepresentation()); | ||
} | ||
return Point.measurement(type.toString()); | ||
return apply(Point.measurement(type.toString()), packet); | ||
} | ||
return apply(Point.measurement(packet.getClass().getSimpleName()), packet); | ||
} | ||
private static Point.Builder apply(Point.Builder point, Packet packet) { | ||
for (Map.Entry<String, String> entry : PointUtil.getTags(packet).entrySet()) { | ||
point.tag(entry.getKey(), entry.getValue()); | ||
} | ||
return Point.measurement(packet.getClass().getSimpleName()); | ||
return point; | ||
} | ||
} |
Oops, something went wrong.