本文整理了Java中org.influxdb.InfluxDB.databaseExists()
方法的一些代码示例,展示了InfluxDB.databaseExists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InfluxDB.databaseExists()
方法的具体详情如下:
包路径:org.influxdb.InfluxDB
类名称:InfluxDB
方法名:databaseExists
[英]Check if a database exists.
[中]检查数据库是否存在。
代码示例来源:origin: apache/cloudstack
/**
* Creates connection to InfluxDB. If the database does not exist, it throws a CloudRuntimeException. </br>
* @note the user can configure the database name on parameter 'stats.output.influxdb.database.name'; such database must be yet created and configured by the user.
* The Default name for the database is 'cloudstack_stats'.
*/
protected InfluxDB createInfluxDbConnection() {
String influxDbQueryUrl = String.format("http://%s:%s/", externalStatsHost, externalStatsPort);
InfluxDB influxDbConnection = InfluxDBFactory.connect(influxDbQueryUrl);
if (!influxDbConnection.databaseExists(databaseName)) {
throw new CloudRuntimeException(String.format("Database with name %s does not exist in influxdb host %s:%s", databaseName, externalStatsHost, externalStatsPort));
}
return influxDbConnection;
}
代码示例来源:origin: org.apereo.cas/cas-server-support-influxdb-core
public InfluxDbConnectionFactory(final String url, final String uid,
final String psw, final String dbName,
final boolean dropDatabase) {
if (StringUtils.isBlank(dbName) || StringUtils.isBlank(url)) {
throw new IllegalArgumentException("Database name/url cannot be blank and must be specified");
}
val builder = new OkHttpClient.Builder();
this.influxDb = InfluxDBFactory.connect(url, uid, psw, builder);
this.influxDb.enableGzip();
if (dropDatabase) {
this.influxDb.deleteDatabase(dbName);
}
if (!this.influxDb.databaseExists(dbName)) {
this.influxDb.createDatabase(dbName);
}
this.influxDb.setLogLevel(InfluxDB.LogLevel.NONE);
if (LOGGER.isDebugEnabled()) {
this.influxDb.setLogLevel(InfluxDB.LogLevel.FULL);
} else if (LOGGER.isInfoEnabled()) {
this.influxDb.setLogLevel(InfluxDB.LogLevel.BASIC);
} else if (LOGGER.isWarnEnabled()) {
this.influxDb.setLogLevel(InfluxDB.LogLevel.HEADERS);
} else if (LOGGER.isErrorEnabled()) {
this.influxDb.setLogLevel(InfluxDB.LogLevel.NONE);
}
}
代码示例来源:origin: org.apache.camel/camel-influxdb
private void doInsert(Exchange exchange, String dataBaseName, String retentionPolicy) throws InvalidPayloadException {
if (!endpoint.isBatch()) {
Point p = exchange.getIn().getMandatoryBody(Point.class);
try {
LOG.debug("Writing point {}", p.lineProtocol());
if (!connection.databaseExists(dataBaseName)) {
LOG.debug("Database {} doesn't exist. Creating it...", dataBaseName);
connection.createDatabase(dataBaseName);
}
connection.write(dataBaseName, retentionPolicy, p);
} catch (Exception ex) {
exchange.setException(new CamelInfluxDbException(ex));
}
} else {
BatchPoints batchPoints = exchange.getIn().getMandatoryBody(BatchPoints.class);
try {
LOG.debug("Writing BatchPoints {}", batchPoints.lineProtocol());
connection.write(batchPoints);
} catch (Exception ex) {
exchange.setException(new CamelInfluxDbException(ex));
}
}
}
代码示例来源:origin: apache/bahir-flink
/**
* Initializes the connection to InfluxDB by either cluster or sentinels or single server.
*/
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
influxDBClient = InfluxDBFactory.connect(influxDBConfig.getUrl(), influxDBConfig.getUsername(), influxDBConfig.getPassword());
if (!influxDBClient.databaseExists(influxDBConfig.getDatabase())) {
if(influxDBConfig.isCreateDatabase()) {
influxDBClient.createDatabase(influxDBConfig.getDatabase());
}
else {
throw new RuntimeException("This " + influxDBConfig.getDatabase() + " database does not exist!");
}
}
influxDBClient.setDatabase(influxDBConfig.getDatabase());
if (influxDBConfig.getBatchActions() > 0) {
influxDBClient.enableBatch(influxDBConfig.getBatchActions(), influxDBConfig.getFlushDuration(), influxDBConfig.getFlushDurationTimeUnit());
}
if (influxDBConfig.isEnableGzip()) {
influxDBClient.enableGzip();
}
}
内容来源于网络,如有侵权,请联系作者删除!