Search in sources :

Example 16 with InfluxDBClient

use of com.influxdb.client.InfluxDBClient in project openhab-addons by openhab.

the class InfluxDBClientFacadeImpl method connect.

@Override
public boolean connect() {
    var clientOptions = InfluxDBClientOptions.builder().url(config.getUrl()).org(config.getOrganization()).bucket(config.getBucket()).authenticateToken(config.getToken().toCharArray()).build();
    final InfluxDBClient createdClient = InfluxDBClientFactory.create(clientOptions);
    this.client = createdClient;
    var currentQueryAPI = createdClient.getQueryApi();
    this.queryAPI = currentQueryAPI;
    boolean connected = checkConnectionStatus();
    if (connected) {
        logger.debug("Successfully connected to InfluxDB. Instance ready={}", createdClient.ready());
    } else {
        logger.warn("Not able to connect to InfluxDB with config {}", config);
    }
    return connected;
}
Also used : InfluxDBClient(com.influxdb.client.InfluxDBClient)

Example 17 with InfluxDBClient

use of com.influxdb.client.InfluxDBClient in project IginX by thulab.

the class InfluxDBStorage method testConnection.

private boolean testConnection() {
    Map<String, String> extraParams = meta.getExtraParams();
    String url = extraParams.get("url");
    try {
        InfluxDBClient client = InfluxDBClientFactory.create(url, extraParams.get("token").toCharArray());
        client.close();
    } catch (Exception e) {
        logger.error("test connection error: {}", e.getMessage());
        return false;
    }
    return true;
}
Also used : InfluxDBClient(com.influxdb.client.InfluxDBClient) PhysicalException(cn.edu.tsinghua.iginx.engine.physical.exception.PhysicalException) PhysicalTaskExecuteFailureException(cn.edu.tsinghua.iginx.engine.physical.exception.PhysicalTaskExecuteFailureException) StorageInitializationException(cn.edu.tsinghua.iginx.engine.physical.exception.StorageInitializationException) NonExecutablePhysicalTaskException(cn.edu.tsinghua.iginx.engine.physical.exception.NonExecutablePhysicalTaskException)

Example 18 with InfluxDBClient

use of com.influxdb.client.InfluxDBClient in project addons by smarthomej.

the class InfluxDB2RepositoryImpl method disconnect.

/**
 * Disconnect from InfluxDB server
 */
@Override
public void disconnect() {
    final InfluxDBClient currentClient = this.client;
    if (currentClient != null) {
        currentClient.close();
    }
    this.client = null;
}
Also used : InfluxDBClient(com.influxdb.client.InfluxDBClient)

Example 19 with InfluxDBClient

use of com.influxdb.client.InfluxDBClient in project influxdb-plugin by jenkinsci.

the class InfluxDbPublicationService method getInfluxDBClient.

private InfluxDBClient getInfluxDBClient(Run<?, ?> build, Target target) {
    StandardUsernamePasswordCredentials credentials = CredentialsProvider.findCredentialById(target.getCredentialsId(), StandardUsernamePasswordCredentials.class, build);
    InfluxDBClient influxDB;
    if (target.getOrganization() != null && !target.getOrganization().trim().isEmpty()) {
        InfluxDBClientOptions.Builder options = InfluxDBClientOptions.builder().url(target.getUrl()).org(target.getOrganization()).bucket(target.getDatabase());
        if (credentials != null) {
            // basic auth
            options.authenticate(credentials.getUsername(), credentials.getPassword().getPlainText().toCharArray());
        } else {
            // token auth
            StringCredentials c = CredentialsProvider.findCredentialById(target.getCredentialsId(), StringCredentials.class, build);
            assert c != null;
            options.authenticateToken(c.getSecret().getPlainText().toCharArray());
        }
        influxDB = InfluxDBClientFactory.create(options.build());
    } else {
        influxDB = credentials == null ? InfluxDBClientFactory.createV1(target.getUrl(), "", "".toCharArray(), target.getDatabase(), target.getRetentionPolicy()) : InfluxDBClientFactory.createV1(target.getUrl(), credentials.getUsername(), credentials.getPassword().getPlainText().toCharArray(), target.getDatabase(), target.getRetentionPolicy());
    }
    return influxDB;
}
Also used : StandardUsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials) InfluxDBClient(com.influxdb.client.InfluxDBClient) InfluxDBClientOptions(com.influxdb.client.InfluxDBClientOptions) StringCredentials(org.jenkinsci.plugins.plaincredentials.StringCredentials)

Example 20 with InfluxDBClient

use of com.influxdb.client.InfluxDBClient in project nifi-influxdb-bundle by influxdata.

the class AbstractInfluxDatabaseProcessor_2 method getInfluxDBClient.

/**
 * Get or create InfluxDBClient thought {@link InfluxDatabaseService_2}.
 *
 * @return InfluxDBClient instance
 */
public synchronized InfluxDBClient getInfluxDBClient(final ProcessContext context) {
    if (influxDBClient.get() == null) {
        try {
            InfluxDBClient influxDBClient = influxDatabaseService.create();
            configure(influxDBClient, context);
            this.influxDBClient.set(influxDBClient);
        } catch (Exception e) {
            String message = "Error while getting connection " + e.getLocalizedMessage();
            getLogger().error(message, e);
            throw new RuntimeException(message, e);
        }
        getLogger().info("InfluxDB connection created for host {}", new Object[] { influxDatabaseService.getDatabaseURL() });
    }
    return influxDBClient.get();
}
Also used : InfluxDBClient(com.influxdb.client.InfluxDBClient) InfluxException(com.influxdb.exceptions.InfluxException)

Aggregations

InfluxDBClient (com.influxdb.client.InfluxDBClient)24 InfluxDBClientOptions (com.influxdb.client.InfluxDBClientOptions)4 QueryApi (com.influxdb.client.QueryApi)3 Ready (com.influxdb.client.domain.Ready)3 IOException (java.io.IOException)3 lombok.val (lombok.val)3 Cancellable (com.influxdb.Cancellable)2 Query (com.influxdb.client.domain.Query)2 Point (com.influxdb.client.write.Point)2 GeneralSecurityException (java.security.GeneralSecurityException)2 InitializationException (org.apache.nifi.reporting.InitializationException)2 MockProcessContext (org.apache.nifi.util.MockProcessContext)2 MockProcessorInitializationContext (org.apache.nifi.util.MockProcessorInitializationContext)2 InfluxDatabaseService_2 (org.influxdata.nifi.services.InfluxDatabaseService_2)2 StandardInfluxDatabaseService_2 (org.influxdata.nifi.services.StandardInfluxDatabaseService_2)2 NonExecutablePhysicalTaskException (cn.edu.tsinghua.iginx.engine.physical.exception.NonExecutablePhysicalTaskException)1 PhysicalException (cn.edu.tsinghua.iginx.engine.physical.exception.PhysicalException)1 PhysicalTaskExecuteFailureException (cn.edu.tsinghua.iginx.engine.physical.exception.PhysicalTaskExecuteFailureException)1 StorageInitializationException (cn.edu.tsinghua.iginx.engine.physical.exception.StorageInitializationException)1 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)1