Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,17 @@ private QueryApi getQueryApi() {


@Override
public void open() {
public void open() throws InterpreterException {

if (this.client == null) {
String token = getProperty(INFLUXDB_TOKEN_PROPERTY);
if (token == null || token.isBlank()) {
throw new InterpreterException("influxdb.token property is not set. Please configure the InfluxDB auth token.");
}

InfluxDBClientOptions opt = InfluxDBClientOptions.builder()
.url(getProperty(INFLUXDB_API_URL_PROPERTY))
.authenticateToken(getProperty(INFLUXDB_TOKEN_PROPERTY).toCharArray())
.authenticateToken(token.toCharArray())
.logLevel(LogLevel.valueOf(
getProperty(INFLUXDB_LOGLEVEL_PROPERTY, LogLevel.NONE.toString())))
.org(getProperty(INFLUXDB_ORG_PROPERTY))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package org.apache.zeppelin.influxdb;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
Expand Down Expand Up @@ -216,6 +218,42 @@ public void after() throws IOException {
}
}

@Test
void testOpenWithoutToken() {
properties.remove("influxdb.token");

InfluxDBInterpreter interpreter = new InfluxDBInterpreter(properties);

InterpreterException exception = assertThrows(InterpreterException.class, interpreter::open);

assertTrue(exception.getMessage().contains("influxdb.token"));
assertTrue(exception.getMessage().contains("not set"));
}

@Test
void testOpenWithEmptyToken() {
properties.setProperty("influxdb.token","");

InfluxDBInterpreter interpreter = new InfluxDBInterpreter(properties);

InterpreterException exception = assertThrows(InterpreterException.class, interpreter::open);

assertTrue(exception.getMessage().contains("influxdb.token"));
assertTrue(exception.getMessage().contains("not set"));
}

@Test
void testOpenWithBlankToken() {
properties.setProperty("influxdb.token"," ");

InfluxDBInterpreter interpreter = new InfluxDBInterpreter(properties);

InterpreterException exception = assertThrows(InterpreterException.class, interpreter::open);

assertTrue(exception.getMessage().contains("influxdb.token"));
assertTrue(exception.getMessage().contains("not set"));
}

@Test
void testSigleTable() throws InterpreterException {

Expand Down
Loading