Class InfluxDbConnector

java.lang.Object
edu.ie3.datamodel.io.connectors.InfluxDbConnector
All Implemented Interfaces:
DataConnector

public class InfluxDbConnector extends Object implements 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.
  • Field Details

  • 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 database
      scenarioName - the name of the simulation scenario which will be used in influxDB measurement names
      databaseName - the name of the database the session should be set to
      createDb - true if the connector should create the database if it doesn't exist yet, false otherwise
      logLevel - log level of the InfluxDB.LogLevel logger
      batchOptions - 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 connector
      scenarioName - the name of the scenario
      databaseName - the name of the database the session should be set to
      createDb - true if the connector should create the database if it doesn't exist yet, false otherwise
    • InfluxDbConnector

      public InfluxDbConnector(String url, String databaseName, String scenarioName)
      Initializes a new InfluxDbConnector with the given url, databaseName and scenario name.
      Parameters:
      url - the connection url for the influxDB database
      databaseName - the name of the database to which the connection should be established
      scenarioName - the name of the simulation scenario which will be used in influxDB measurement names
    • InfluxDbConnector

      public InfluxDbConnector(String url, String databaseName)
      Initializes a new InfluxDbConnector with the given url, databaseName and NO_SCENARIO as scenario parameter
      Parameters:
      url - the connection url for the influxDB database
      databaseName - the name of the database to which the connection should be established
  • Method Details

    • createDb

      public final org.influxdb.dto.QueryResult createDb(String databaseName)
      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

      public Boolean 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 interface DataConnector
    • getSession

      public org.influxdb.InfluxDB getSession()
      Return the session of this connector
      Returns:
      influx db session
    • getScenarioName

      public String getScenarioName()
    • parseQueryResult

      public static Map<String,Set<Map<String,String>>> parseQueryResult(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,String>>> parseQueryResult(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 query
      measurementNames - 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,String>>> parseResult(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 query
      measurementNames - 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

      public static Set<Map<String,String>> parseSeries(org.influxdb.dto.QueryResult.Series series)
      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

      public static Map<String,String> parseValueList(List<?> valueList, String[] columns)
      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 columns
      columns - Array of column names
      Returns:
      Map of (field name to field value) for one result entity