Package edu.ie3.datamodel.io.connectors
Class InfluxDbConnector
java.lang.Object
edu.ie3.datamodel.io.connectors.InfluxDbConnector
- All Implemented Interfaces:
DataConnector
Implements a DataConnector for InfluxDB. InfluxDB is a time series database and as such, it can
only handle time based data.
Entities will be persisted as measurement points, which consist of a time, one or more tags, one or more values and a measurement name. In contrast to values, tags should only contain metadata. A measurement name is the equivalent of the name of a table in relational data models.
Entities will be persisted as measurement points, which consist of a time, one or more tags, one or more values and a measurement name. In contrast to values, tags should only contain metadata. A measurement name is the equivalent of the name of a table in relational data models.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionInfluxDbConnector
(String url, String databaseName) Initializes a new InfluxDbConnector with the given url, databaseName andNO_SCENARIO
as scenario parameterInfluxDbConnector
(String url, String databaseName, String scenarioName) Initializes a new InfluxDbConnector with the given url, databaseName and scenario name.InfluxDbConnector
(String url, String databaseName, String scenarioName, boolean createDb, org.influxdb.InfluxDB.LogLevel logLevel, org.influxdb.BatchOptions batchOptions) Initializes a new InfluxDbConnector with the given url, databaseName and scenario name.InfluxDbConnector
(org.influxdb.InfluxDB session, String scenarioName, String databaseName, boolean createDb) Initializes a new InfluxDbConnector with the given influxDb session, the databaseName and scenario name. -
Method Summary
Modifier and TypeMethodDescriptionfinal org.influxdb.dto.QueryResult
Create the database of this connector if it doesn't exist yetorg.influxdb.InfluxDB
Return the session of this connectorChecks if the given connection parameters are valid, so that a connection can be establishedparseQueryResult
(org.influxdb.dto.QueryResult queryResult) Parses the result of an influxQL query for all measurements (e.g.parseQueryResult
(org.influxdb.dto.QueryResult queryResult, String... measurementNames) Parses the result of one or multiple influxQL queries for the given measurements (e.g.parseResult
(org.influxdb.dto.QueryResult.Result result, String... measurementNames) Parses the result of one influxQL query for the given measurements (e.g.parseSeries
(org.influxdb.dto.QueryResult.Series series) Parses the results for a single measurement seriesparseValueList
(List<?> valueList, String[] columns) Parses a list of values and maps them to field names using the given column name and ordervoid
shutdown()
-
Field Details
-
NO_SCENARIO
- See Also:
-
WEATHER_SCENARIO
- See Also:
-
-
Constructor Details
-
InfluxDbConnector
public InfluxDbConnector(String url, String databaseName, String scenarioName, boolean createDb, org.influxdb.InfluxDB.LogLevel logLevel, org.influxdb.BatchOptions batchOptions) Initializes a new InfluxDbConnector with the given url, databaseName and scenario name.- Parameters:
url
- the connection url for the influxDB databasescenarioName
- the name of the simulation scenario which will be used in influxDB measurement namesdatabaseName
- the name of the database the session should be set tocreateDb
- true if the connector should create the database if it doesn't exist yet, false otherwiselogLevel
- log level of theInfluxDB.LogLevel
loggerbatchOptions
- write options to write batch operations
-
InfluxDbConnector
public InfluxDbConnector(org.influxdb.InfluxDB session, String scenarioName, String databaseName, boolean createDb) Initializes a new InfluxDbConnector with the given influxDb session, the databaseName and scenario name.- Parameters:
session
- the influxdb session that should be managed by this connectorscenarioName
- the name of the scenariodatabaseName
- the name of the database the session should be set tocreateDb
- true if the connector should create the database if it doesn't exist yet, false otherwise
-
InfluxDbConnector
Initializes a new InfluxDbConnector with the given url, databaseName and scenario name.- Parameters:
url
- the connection url for the influxDB databasedatabaseName
- the name of the database to which the connection should be establishedscenarioName
- the name of the simulation scenario which will be used in influxDB measurement names
-
InfluxDbConnector
Initializes a new InfluxDbConnector with the given url, databaseName andNO_SCENARIO
as scenario parameter- Parameters:
url
- the connection url for the influxDB databasedatabaseName
- the name of the database to which the connection should be established
-
-
Method Details
-
createDb
Create the database of this connector if it doesn't exist yet- Parameters:
databaseName
- the name of the database that should be created- Returns:
- the result of the create database query
-
isConnectionValid
Checks if the given connection parameters are valid, so that a connection can be established- Returns:
- true, if the database returned the ping
-
shutdown
public void shutdown()- Specified by:
shutdown
in interfaceDataConnector
-
getSession
public org.influxdb.InfluxDB getSession()Return the session of this connector- Returns:
- influx db session
-
getScenarioName
-
parseQueryResult
public static Map<String,Set<Map<String, parseQueryResultString>>> (org.influxdb.dto.QueryResult queryResult) Parses the result of an influxQL query for all measurements (e.g. weather)- Parameters:
queryResult
- Result of an influxDB query- Returns:
- Map of (measurement name to Set of maps of (field name : field value)) for each result entity)
-
parseQueryResult
public static Map<String,Set<Map<String, parseQueryResultString>>> (org.influxdb.dto.QueryResult queryResult, String... measurementNames) Parses the result of one or multiple influxQL queries for the given measurements (e.g. weather). If no measurement names are given, all results are parsed and returned- Parameters:
queryResult
- Result of an influxDB querymeasurementNames
- Names of measurements that should be parsed. If none are given, all measurements will be parsed- Returns:
- Map of (measurement name to Set of maps of (field name : field value) for each result entity)
-
parseResult
public static Map<String,Set<Map<String, parseResultString>>> (org.influxdb.dto.QueryResult.Result result, String... measurementNames) Parses the result of one influxQL query for the given measurements (e.g. weather). If no measurement names are given, all results are parsed and returned- Parameters:
result
- Specific result of an influxDB querymeasurementNames
- Names of measurements that should be parsed. If none are given, all measurements will be parsed- Returns:
- Map of (measurement name to Set of maps of (field name : field value) for each result entity)
-
parseSeries
Parses the results for a single measurement series- Parameters:
series
- A measurement series of an influxDB query result- Returns:
- Set of maps of (field name to field value) for each result entity
-
parseValueList
Parses a list of values and maps them to field names using the given column name and order- Parameters:
valueList
- List of values, sorted by column in columnscolumns
- Array of column names- Returns:
- Map of (field name to field value) for one result entity
-