use of com.influxdb.client.InfluxDBClient in project nifi-influxdb-bundle by influxdata.
the class AbstractTestGetInfluxDatabase_2 method before.
@Before
public void before() throws IOException, GeneralSecurityException, InitializationException {
InfluxDBClient mockInfluxDBClient = Mockito.mock(InfluxDBClient.class);
mockQueryApi = Mockito.mock(QueryApi.class);
Mockito.doAnswer(invocation -> mockQueryApi).when(mockInfluxDBClient).getQueryApi();
Mockito.doAnswer(invocation -> {
if (queryOnErrorValue != null) {
// noinspection unchecked
Consumer<Exception> onError = invocation.getArgument(3, Consumer.class);
onError.accept(queryOnErrorValue);
}
queryOnResponseRecords.forEach(record -> {
// noinspection unchecked
BiConsumer<Cancellable, String> onRecord = invocation.getArgument(2, BiConsumer.class);
onRecord.accept(Mockito.mock(Cancellable.class), record);
});
boolean wasException = queryOnErrorValue != null;
try {
return queryAnswer.answer(invocation);
} catch (Exception e) {
wasException = true;
throw e;
} finally {
if (!wasException) {
Runnable onComplete = invocation.getArgument(4, Runnable.class);
onComplete.run();
}
}
}).when(mockQueryApi).queryRaw(Mockito.any(Query.class), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any());
processor = Mockito.spy(new GetInfluxDatabase_2());
runner = TestRunners.newTestRunner(processor);
runner.setProperty(GetInfluxDatabase_2.ORG, "my-org");
runner.setProperty(GetInfluxDatabase_2.QUERY, "from(bucket:\"my-bucket\") |> range(start: 0) |> last()");
runner.setProperty(GetInfluxDatabase_2.INFLUX_DB_SERVICE, "influxdb-service");
InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
Mockito.doAnswer(invocation -> mockInfluxDBClient).when(influxDatabaseService).create();
runner.addControllerService("influxdb-service", influxDatabaseService);
runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
runner.enableControllerService(influxDatabaseService);
MockProcessContext context = new MockProcessContext(processor);
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
logger = initContext.getLogger();
processor.initialize(initContext);
processor.onScheduled(runner.getProcessContext());
processor.initWriterFactory(runner.getProcessContext());
}
use of com.influxdb.client.InfluxDBClient in project influxdb-plugin by jenkinsci.
the class InfluxDbPublicationService method perform.
public void perform(Run<?, ?> build, TaskListener listener, EnvVars env) {
// Logging
listener.getLogger().println("[InfluxDB Plugin] Collecting data...");
// Renderer to use for the metrics
ProjectNameRenderer measurementRenderer = new ProjectNameRenderer(customPrefix, customProjectName);
// Points to write
List<Point> pointsToWrite = new ArrayList<>();
// Basic metrics
JenkinsBasePointGenerator jGen = new JenkinsBasePointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, jenkinsEnvParameterField, customPrefix, measurementName, env);
addPoints(pointsToWrite, jGen, listener);
CustomDataPointGenerator cdGen = new CustomDataPointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix, customData, customDataTags, measurementName);
if (cdGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] Custom data found. Writing to InfluxDB...");
addPoints(pointsToWrite, cdGen, listener);
} else {
logger.log(Level.FINE, "Data source empty: Custom Data");
}
CustomDataMapPointGenerator cdmGen = new CustomDataMapPointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix, customDataMap, customDataMapTags);
if (cdmGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] Custom data map found. Writing to InfluxDB...");
addPoints(pointsToWrite, cdmGen, listener);
} else {
logger.log(Level.FINE, "Data source empty: Custom Data Map");
}
try {
CoberturaPointGenerator cGen = new CoberturaPointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix);
if (cGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] Cobertura data found. Writing to InfluxDB...");
addPoints(pointsToWrite, cGen, listener);
}
} catch (NoClassDefFoundError ignore) {
logger.log(Level.FINE, "Plugin skipped: Cobertura");
}
try {
RobotFrameworkPointGenerator rfGen = new RobotFrameworkPointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix);
if (rfGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] Robot Framework data found. Writing to InfluxDB...");
addPoints(pointsToWrite, rfGen, listener);
}
} catch (NoClassDefFoundError ignore) {
logger.log(Level.FINE, "Plugin skipped: Robot Framework");
}
try {
JacocoPointGenerator jacoGen = new JacocoPointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix);
if (jacoGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] JaCoCo data found. Writing to InfluxDB...");
addPoints(pointsToWrite, jacoGen, listener);
}
} catch (NoClassDefFoundError ignore) {
logger.log(Level.FINE, "Plugin skipped: JaCoCo");
}
try {
PerformancePointGenerator perfGen = new PerformancePointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix);
if (perfGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] Performance data found. Writing to InfluxDB...");
addPoints(pointsToWrite, perfGen, listener);
}
} catch (NoClassDefFoundError ignore) {
logger.log(Level.FINE, "Plugin skipped: Performance");
}
JUnitPointGenerator junitGen = new JUnitPointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix, env);
if (junitGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] JUnit data found. Writing to InfluxDB...");
addPoints(pointsToWrite, junitGen, listener);
} else {
logger.log(Level.FINE, "Plugin skipped: JUnit");
}
SonarQubePointGenerator sonarGen = new SonarQubePointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix, env);
if (sonarGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] SonarQube data found. Writing to InfluxDB...");
addPoints(pointsToWrite, sonarGen, listener);
} else {
logger.log(Level.FINE, "Plugin skipped: SonarQube");
}
SerenityJsonSummaryFile serenityJsonSummaryFile = new SerenityJsonSummaryFile(env.get("WORKSPACE"));
SerenityPointGenerator serenityGen = new SerenityPointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix, serenityJsonSummaryFile);
if (serenityGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] Serenity data found. Writing to InfluxDB...");
addPoints(pointsToWrite, serenityGen, listener);
} else {
logger.log(Level.FINE, "Plugin skipped: Serenity");
}
ChangeLogPointGenerator changeLogGen = new ChangeLogPointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix);
if (changeLogGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] Change Log data found. Writing to InfluxDB...");
addPoints(pointsToWrite, changeLogGen, listener);
} else {
logger.log(Level.FINE, "Data source empty: Change Log");
}
try {
PerfPublisherPointGenerator perfPublisherGen = new PerfPublisherPointGenerator(build, listener, measurementRenderer, timestamp, jenkinsEnvParameterTag, customPrefix);
if (perfPublisherGen.hasReport()) {
listener.getLogger().println("[InfluxDB Plugin] Performance Publisher data found. Writing to InfluxDB...");
addPoints(pointsToWrite, perfPublisherGen, listener);
}
} catch (NoClassDefFoundError ignore) {
logger.log(Level.FINE, "Plugin skipped: Performance Publisher");
}
for (Target target : selectedTargets) {
try {
new URL(target.getUrl());
} catch (MalformedURLException e) {
String logMessage = String.format("[InfluxDB Plugin] Skipping target '%s' due to invalid URL '%s'", target.getDescription(), target.getUrl());
logger.log(Level.WARNING, logMessage);
listener.getLogger().println(logMessage);
continue;
}
String logMessage = String.format("[InfluxDB Plugin] Publishing data to target '%s' (url='%s', database='%s')", target.getDescription(), target.getUrl(), target.getDatabase());
logger.log(Level.FINE, logMessage);
listener.getLogger().println(logMessage);
try (InfluxDBClient influxDB = getInfluxDBClient(build, target)) {
writeToInflux(target, influxDB, pointsToWrite);
}
}
listener.getLogger().println("[InfluxDB Plugin] Completed.");
}
use of com.influxdb.client.InfluxDBClient 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.InfluxDBClient in project addons by smarthomej.
the class InfluxDB2RepositoryImpl method checkConnectionStatus.
/**
* Check if connection is currently ready
*
* @return True if its ready, otherwise false
*/
@Override
public boolean checkConnectionStatus() {
final InfluxDBClient currentClient = client;
if (currentClient != null) {
Ready ready = currentClient.ready();
boolean isUp = ready != null && ready.getStatus() == Ready.StatusEnum.READY;
if (isUp) {
logger.debug("database status is OK");
} else {
logger.warn("database not ready");
}
return isUp;
} else {
logger.warn("checkConnection: database is not connected");
return false;
}
}
use of com.influxdb.client.InfluxDBClient in project pulsar by yahoo.
the class InfluxDBClientBuilderImpl method build.
@Override
public InfluxDBClient build(InfluxDBSinkConfig influxDBSinkConfig) {
val options = InfluxDBClientOptions.builder().url(influxDBSinkConfig.getInfluxdbUrl()).authenticateToken(influxDBSinkConfig.getToken().toCharArray()).org(influxDBSinkConfig.getOrganization()).bucket(influxDBSinkConfig.getBucket()).logLevel(LogLevel.valueOf(influxDBSinkConfig.getLogLevel().toUpperCase())).build();
InfluxDBClient influxDBClient = InfluxDBClientFactory.create(options);
if (!influxDBSinkConfig.isGzipEnable()) {
return influxDBClient;
}
influxDBClient.enableGzip();
return influxDBClient;
}
Aggregations