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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations