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
95 changes: 0 additions & 95 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2374,101 +2374,6 @@
If enabled, tracing information is sent to tracing server.
</description>
</property>
<property>
<name>ozone.recon.sql.db.driver</name>
<value>org.sqlite.JDBC</value>
<tag>OZONE, RECON</tag>
<description>
Database driver class name available on the
Ozone Recon classpath.
</description>
</property>
<property>
<name>ozone.recon.sql.db.jdbc.url</name>
<value>jdbc:sqlite:${ozone.recon.db.dir}/ozone_recon_sqlite.db</value>
<tag>OZONE, RECON</tag>
<description>
Ozone Recon SQL database jdbc url.
</description>
</property>
<property>
<name>ozone.recon.sql.db.username</name>
<value/>
<tag>OZONE, RECON</tag>
<description>
Ozone Recon SQL database username.
</description>
</property>
<property>
<name>ozone.recon.sql.db.password</name>
<value/>
<tag>OZONE, RECON</tag>
<description>
Ozone Recon database password.
</description>
</property>
<property>
<name>ozone.recon.sql.db.auto.commit</name>
<value>false</value>
<tag>OZONE, RECON</tag>
<description>
Sets the Ozone Recon database connection property of auto-commit to
true/false.
</description>
</property>
<property>
<name>ozone.recon.sql.db.conn.timeout</name>
<value>30000</value>
<tag>OZONE, RECON</tag>
<description>
Sets time in milliseconds before call to getConnection is timed out.
</description>
</property>
<property>
<name>ozone.recon.sql.db.conn.max.active</name>
<value>1</value>
<tag>OZONE, RECON</tag>
<description>
The max active connections to the SQL database. The default SQLite
database only allows single active connection, set this to a
reasonable value like 10, for external production database.
</description>
</property>
<property>
<name>ozone.recon.sql.db.conn.max.age</name>
<value>1800</value>
<tag>OZONE, RECON</tag>
<description>
Sets maximum time a connection can be active in seconds.
</description>
</property>
<property>
<name>ozone.recon.sql.db.conn.idle.max.age</name>
<value>3600</value>
<tag>OZONE, RECON</tag>
<description>
Sets maximum time to live for idle connection in seconds.
</description>
</property>
<property>
<name>ozone.recon.sql.db.conn.idle.test.period</name>
<value>60</value>
<tag>OZONE, RECON</tag>
<description>
This sets the time (in seconds), for a connection to remain idle before
sending a test query to the DB. This is useful to prevent a DB from
timing out connections on its end.
</description>
</property>
<property>
<name>ozone.recon.sql.db.conn.idle.test</name>
<value>SELECT 1</value>
<tag>OZONE, RECON</tag>
<description>
The query to send to the DB to maintain keep-alives and test for dead
connections.
</description>
</property>
<property>
<name>ozone.recon.task.thread.count</name>
<value>1</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_HTTP_ADDRESS_KEY;
import static org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_OM_SNAPSHOT_DB_DIR;
import static org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_SCM_DB_DIR;
import static org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_SQL_DB_JDBC_URL;
import static org.hadoop.ozone.recon.codegen.ReconSqlDbConfig.ConfigKeys.OZONE_RECON_SQL_DB_JDBC_URL;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -804,8 +804,8 @@ protected void configureRecon() throws IOException {
.getAbsolutePath());
conf.set(OZONE_RECON_SCM_DB_DIR,
tempNewFolder.getAbsolutePath());
conf.set(OZONE_RECON_SQL_DB_JDBC_URL, "jdbc:sqlite:" +
tempNewFolder.getAbsolutePath() + "/ozone_recon_sqlite.db");
conf.set(OZONE_RECON_SQL_DB_JDBC_URL, "jdbc:derby:" +
tempNewFolder.getAbsolutePath() + "/ozone_recon_derby.db");

conf.set(OZONE_RECON_HTTP_ADDRESS_KEY, "0.0.0.0:0");
conf.set(OZONE_RECON_DATANODE_ADDRESS_KEY, "0.0.0.0:0");
Expand Down
5 changes: 3 additions & 2 deletions hadoop-ozone/recon-codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
<artifactId>hadoop-ozone-common</artifactId>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.14.2.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,31 @@
*/
package org.hadoop.ozone.recon.codegen;

import static org.hadoop.ozone.recon.codegen.SqlDbUtils.DERBY_DRIVER_CLASS;
import static org.hadoop.ozone.recon.codegen.SqlDbUtils.createNewDerbyDatabase;

import java.io.File;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.util.Set;

import javax.sql.DataSource;

import org.apache.commons.io.FileUtils;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.hadoop.util.Time;
import org.hadoop.ozone.recon.schema.ReconSchemaDefinition;
import org.jooq.codegen.GenerationTool;
import org.jooq.meta.jaxb.Configuration;
import org.jooq.meta.jaxb.Database;
import org.jooq.meta.jaxb.Generate;
import org.jooq.meta.jaxb.Generator;
import org.jooq.meta.jaxb.Jdbc;
import org.jooq.meta.jaxb.Logging;
import org.jooq.meta.jaxb.Strategy;
import org.jooq.meta.jaxb.Target;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sqlite.SQLiteDataSource;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
Expand All @@ -55,10 +61,11 @@ public class JooqCodeGenerator {
private static final Logger LOG =
LoggerFactory.getLogger(JooqCodeGenerator.class);

private static final String SQLITE_DB =
System.getProperty("java.io.tmpdir") + "/recon-generated-schema";
private static final String JDBC_URL = "jdbc:sqlite:" + SQLITE_DB;

private static final String DB = Paths.get(
System.getProperty("java.io.tmpdir"),
"recon-generated-schema-" + Time.monotonicNow()).toString();
public static final String RECON_SCHEMA_NAME = "RECON";
private static final String JDBC_URL = "jdbc:derby:" + DB;
private final Set<ReconSchemaDefinition> allDefinitions;

@Inject
Expand All @@ -82,47 +89,51 @@ private void generateSourceCode(String outputDir) throws Exception {
Configuration configuration =
new Configuration()
.withJdbc(new Jdbc()
.withDriver("org.sqlite.JDBC")
.withUrl(JDBC_URL)
.withUser("sa")
.withPassword("sa"))
.withDriver(DERBY_DRIVER_CLASS)
.withUrl(JDBC_URL))
.withGenerator(new Generator()
.withDatabase(new Database()
.withName("org.jooq.meta.sqlite.SQLiteDatabase")
.withName("org.jooq.meta.derby.DerbyDatabase")
.withOutputSchemaToDefault(true)
.withIncludeTables(true)
.withIncludePrimaryKeys(true))
.withIncludePrimaryKeys(true)
.withInputSchema(RECON_SCHEMA_NAME))
.withGenerate(new Generate()
.withDaos(true)
.withEmptyCatalogs(true)
.withEmptySchemas(true))
.withEmptyCatalogs(true))
.withStrategy(new Strategy().withName(
"org.hadoop.ozone.recon.codegen.TableNamingStrategy"))
.withTarget(new Target()
.withPackageName("org.hadoop.ozone.recon.schema")
.withClean(true)
.withDirectory(outputDir)));
.withDirectory(outputDir)))
.withLogging(Logging.WARN);
GenerationTool.generate(configuration);
}

/**
* Provider for embedded datasource.
*/
static class LocalDataSourceProvider implements Provider<DataSource> {
private static SQLiteDataSource db;

private static EmbeddedDataSource dataSource;
static {
db = new SQLiteDataSource();
db.setUrl(JDBC_URL);
try {
createNewDerbyDatabase(JDBC_URL, RECON_SCHEMA_NAME);
} catch (Exception e) {
LOG.error("Error creating Recon Derby DB.", e);
}
dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName(DB);
dataSource.setUser(RECON_SCHEMA_NAME);
}

@Override
public DataSource get() {
return db;
return dataSource;
}

static void cleanup() {
FileUtils.deleteQuietly(new File(SQLITE_DB));
FileUtils.deleteQuietly(new File(DB));
}
}

Expand Down
Loading