use of com.influxdb.client.InfluxDBClientOptions in project nifi-influxdb-bundle by influxdata.
the class AbstractITInfluxDB_2 method init.
protected void init() throws Exception {
influxDBClient = InfluxDBClientFactory.create(INFLUX_DB_2, "my-token".toCharArray());
organization = influxDBClient.getOrganizationsApi().findOrganizations().stream().filter(it -> it.getName().equals("my-org")).findFirst().orElseThrow(IllegalStateException::new);
bucketName = "nifi-bucket-" + System.currentTimeMillis();
Bucket bucket = influxDBClient.getBucketsApi().createBucket(bucketName, null, organization);
PermissionResource resource = new PermissionResource();
resource.setId(bucket.getId());
resource.setOrgID(organization.getId());
resource.setType(PermissionResource.TypeEnum.BUCKETS);
//
// Add Permissions to read and write to the Bucket
//
Permission readBucket = new Permission();
readBucket.setResource(resource);
readBucket.setAction(Permission.ActionEnum.READ);
Permission writeBucket = new Permission();
writeBucket.setResource(resource);
writeBucket.setAction(Permission.ActionEnum.WRITE);
Authorization authorization = influxDBClient.getAuthorizationsApi().createAuthorization(organization, Arrays.asList(readBucket, writeBucket));
String token = authorization.getToken();
influxDBClient.close();
InfluxDBClientOptions options = InfluxDBClientOptions.builder().url(INFLUX_DB_2).authenticateToken(token.toCharArray()).org(organization.getId()).bucket(bucket.getId()).build();
influxDBClient = InfluxDBClientFactory.create(options);
queryApi = influxDBClient.getQueryApi();
}
use of com.influxdb.client.InfluxDBClientOptions in project addons by smarthomej.
the class InfluxDB2RepositoryImpl method connect.
/**
* Connect to InfluxDB server
*
* @return True if successful, otherwise false
*/
@Override
public boolean connect() {
InfluxDBClientOptions.Builder optionsBuilder = InfluxDBClientOptions.builder().url(configuration.getUrl()).org(configuration.getDatabaseName()).bucket(configuration.getRetentionPolicy());
char[] token = configuration.getTokenAsCharArray();
if (token.length > 0) {
optionsBuilder.authenticateToken(token);
} else {
optionsBuilder.authenticate(configuration.getUser(), configuration.getPassword().toCharArray());
}
InfluxDBClientOptions clientOptions = optionsBuilder.build();
final InfluxDBClient createdClient = InfluxDBClientFactory.create(clientOptions);
this.client = createdClient;
queryAPI = createdClient.getQueryApi();
writeAPI = createdClient.getWriteApi();
logger.debug("Successfully connected to InfluxDB. Instance ready={}", createdClient.ready());
return checkConnectionStatus();
}
use of com.influxdb.client.InfluxDBClientOptions in project zeppelin by apache.
the class InfluxDBInterpreter method open.
@Override
public void open() throws InterpreterException {
if (this.client == null) {
InfluxDBClientOptions opt = InfluxDBClientOptions.builder().url(getProperty(INFLUXDB_API_URL_PROPERTY)).authenticateToken(getProperty(INFLUXDB_TOKEN_PROPERTY).toCharArray()).logLevel(LogLevel.valueOf(getProperty(INFLUXDB_LOGLEVEL_PROPERTY, LogLevel.NONE.toString()))).org(getProperty(INFLUXDB_ORG_PROPERTY)).build();
this.client = InfluxDBClientFactory.create(opt);
}
}
use of com.influxdb.client.InfluxDBClientOptions in project openhab-addons by openhab.
the class InfluxDB2RepositoryImpl method connect.
/**
* Connect to InfluxDB server
*
* @return True if successful, otherwise false
*/
@Override
public boolean connect() {
InfluxDBClientOptions.Builder optionsBuilder = InfluxDBClientOptions.builder().url(configuration.getUrl()).org(configuration.getDatabaseName()).bucket(configuration.getRetentionPolicy());
char[] token = configuration.getTokenAsCharArray();
if (token.length > 0) {
optionsBuilder.authenticateToken(token);
} else {
optionsBuilder.authenticate(configuration.getUser(), configuration.getPassword().toCharArray());
}
InfluxDBClientOptions clientOptions = optionsBuilder.build();
final InfluxDBClient createdClient = InfluxDBClientFactory.create(clientOptions);
this.client = createdClient;
logger.debug("Succesfully connected to InfluxDB. Instance ready={}", createdClient.ready());
queryAPI = createdClient.getQueryApi();
writeAPI = createdClient.getWriteApi();
return checkConnectionStatus();
}
Aggregations