Search in sources :

Example 1 with InfluxDBClientOptions

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();
}
Also used : Arrays(java.util.Arrays) InfluxDBClientFactory(com.influxdb.client.InfluxDBClientFactory) Authorization(com.influxdb.client.domain.Authorization) Permission(com.influxdb.client.domain.Permission) PermissionResource(com.influxdb.client.domain.PermissionResource) TestRunner(org.apache.nifi.util.TestRunner) InfluxDBClient(com.influxdb.client.InfluxDBClient) After(org.junit.After) Organization(com.influxdb.client.domain.Organization) QueryApi(com.influxdb.client.QueryApi) InfluxDBClientOptions(com.influxdb.client.InfluxDBClientOptions) Bucket(com.influxdb.client.domain.Bucket) Authorization(com.influxdb.client.domain.Authorization) Bucket(com.influxdb.client.domain.Bucket) InfluxDBClientOptions(com.influxdb.client.InfluxDBClientOptions) Permission(com.influxdb.client.domain.Permission) PermissionResource(com.influxdb.client.domain.PermissionResource)

Example 2 with InfluxDBClientOptions

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();
}
Also used : InfluxDBClient(com.influxdb.client.InfluxDBClient) InfluxDBClientOptions(com.influxdb.client.InfluxDBClientOptions)

Example 3 with InfluxDBClientOptions

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);
    }
}
Also used : InfluxDBClientOptions(com.influxdb.client.InfluxDBClientOptions)

Example 4 with InfluxDBClientOptions

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();
}
Also used : InfluxDBClient(com.influxdb.client.InfluxDBClient) InfluxDBClientOptions(com.influxdb.client.InfluxDBClientOptions)

Aggregations

InfluxDBClientOptions (com.influxdb.client.InfluxDBClientOptions)4 InfluxDBClient (com.influxdb.client.InfluxDBClient)3 InfluxDBClientFactory (com.influxdb.client.InfluxDBClientFactory)1 QueryApi (com.influxdb.client.QueryApi)1 Authorization (com.influxdb.client.domain.Authorization)1 Bucket (com.influxdb.client.domain.Bucket)1 Organization (com.influxdb.client.domain.Organization)1 Permission (com.influxdb.client.domain.Permission)1 PermissionResource (com.influxdb.client.domain.PermissionResource)1 Arrays (java.util.Arrays)1 TestRunner (org.apache.nifi.util.TestRunner)1 After (org.junit.After)1