Add support for DB2 database
Change-Id: I80712ff41b32f1347860de36598753dee9ce5d3e
This commit is contained in:
parent
dc663c42a7
commit
b1c919b4c3
@ -146,6 +146,51 @@ In $site_path/etc/secure.config:
|
||||
Visit SAP MaxDB's link:http://maxdb.sap.com/documentation/[documentation] for further
|
||||
information regarding using SAP MaxDB.
|
||||
|
||||
[[createdb_db2]]
|
||||
=== DB2
|
||||
|
||||
IBM DB2 is a supported database for running Gerrit Code Review. However it is
|
||||
recommended only for environments where you intend to run Gerrit on an existing
|
||||
DB2 installation to reduce administrative overhead.
|
||||
|
||||
Create a system wide user for the Gerrit application, and grant the user
|
||||
full rights on the newly created database:
|
||||
|
||||
----
|
||||
db2 => create database gerrit
|
||||
db2 => connect to gerrit
|
||||
db2 => grant connect,accessctrl,dataaccess,dbadm,secadm on database to gerrit2;
|
||||
----
|
||||
|
||||
JDBC driver db2jcc4.jar and db2jcc_license_cu.jar must be obtained
|
||||
from your DB2 distribution. Gerrit initialization process tries to copy
|
||||
it from a known location:
|
||||
|
||||
----
|
||||
/opt/ibm/db2/V10.5/java/db2jcc4.jar
|
||||
/opt/ibm/db2/V10.5/java/db2jcc_license_cu.jar
|
||||
----
|
||||
|
||||
If these files cannot be located at this place, then an alternative location
|
||||
can be provided during init step execution.
|
||||
|
||||
Sample database section in $site_path/etc/gerrit.config:
|
||||
|
||||
----
|
||||
[database]
|
||||
type = db2
|
||||
database = gerrit
|
||||
hostname = localhost
|
||||
username = gerrit2
|
||||
port = 50001
|
||||
----
|
||||
|
||||
Sample database section in $site_path/etc/secure.config:
|
||||
|
||||
----
|
||||
[database]
|
||||
password = secret_pasword
|
||||
----
|
||||
|
||||
GERRIT
|
||||
------
|
||||
|
@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2015 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.pgm.init;
|
||||
|
||||
import static com.google.gerrit.pgm.init.api.InitUtil.username;
|
||||
|
||||
import com.google.gerrit.pgm.init.api.Section;
|
||||
|
||||
|
||||
public class DB2Initializer implements DatabaseConfigInitializer {
|
||||
|
||||
@Override
|
||||
public void initConfig(Section databaseSection) {
|
||||
final String defPort = "50001";
|
||||
databaseSection.string("Server hostname", "hostname", "localhost");
|
||||
databaseSection.string("Server port", "port", defPort, false);
|
||||
databaseSection.string("Database name", "database", "gerrit");
|
||||
databaseSection.string("Database username", "username", username());
|
||||
databaseSection.password("username", "password");
|
||||
}
|
||||
}
|
@ -29,6 +29,8 @@ public class DatabaseConfigModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(SitePaths.class).toInstance(site);
|
||||
bind(DatabaseConfigInitializer.class).annotatedWith(
|
||||
Names.named("db2")).to(DB2Initializer.class);
|
||||
bind(DatabaseConfigInitializer.class).annotatedWith(
|
||||
Names.named("h2")).to(H2Initializer.class);
|
||||
bind(DatabaseConfigInitializer.class).annotatedWith(
|
||||
|
@ -84,6 +84,8 @@ class InitDatabase implements InitStep {
|
||||
libraries.mysqlDriver.downloadRequired();
|
||||
} else if (dci instanceof OracleInitializer) {
|
||||
libraries.oracleDriver.downloadRequired();
|
||||
} else if (dci instanceof DB2Initializer) {
|
||||
libraries.db2Driver.downloadRequired();
|
||||
}
|
||||
|
||||
dci.initConfig(database);
|
||||
|
@ -39,6 +39,8 @@ class Libraries {
|
||||
|
||||
/* final */LibraryDownloader bouncyCastleProvider;
|
||||
/* final */LibraryDownloader bouncyCastleSSL;
|
||||
/* final */LibraryDownloader db2Driver;
|
||||
/* final */LibraryDownloader db2DriverLicense;
|
||||
/* final */LibraryDownloader mysqlDriver;
|
||||
/* final */LibraryDownloader oracleDriver;
|
||||
|
||||
@ -87,16 +89,25 @@ class Libraries {
|
||||
LibraryDownloader dl = (LibraryDownloader) field.get(this);
|
||||
dl.setName(get(cfg, n, "name"));
|
||||
dl.setJarUrl(get(cfg, n, "url"));
|
||||
dl.setSHA1(get(cfg, n, "sha1"));
|
||||
dl.setSHA1(getOptional(cfg, n, "sha1"));
|
||||
dl.setRemove(get(cfg, n, "remove"));
|
||||
for (String d : cfg.getStringList("library", n, "needs")) {
|
||||
dl.addNeeds((LibraryDownloader) getClass().getDeclaredField(d).get(this));
|
||||
}
|
||||
}
|
||||
|
||||
private static String getOptional(Config cfg, String name, String key) {
|
||||
return doGet(cfg, name, key, false);
|
||||
}
|
||||
|
||||
private static String get(Config cfg, String name, String key) {
|
||||
return doGet(cfg, name, key, true);
|
||||
}
|
||||
|
||||
private static final String doGet(Config cfg, String name, String key,
|
||||
boolean required) {
|
||||
String val = cfg.getString("library", name, key);
|
||||
if (val == null || val.isEmpty()) {
|
||||
if ((val == null || val.isEmpty()) && required) {
|
||||
throw new IllegalStateException("Variable library." + name + "." + key
|
||||
+ " is required within " + RESOURCE_FILE);
|
||||
}
|
||||
|
@ -300,6 +300,8 @@ class LibraryDownloader {
|
||||
|
||||
private void verifyFileChecksum() {
|
||||
if (sha1 == null) {
|
||||
System.err.println();
|
||||
System.err.flush();
|
||||
return;
|
||||
}
|
||||
Hasher h = Hashing.sha1().newHasher();
|
||||
|
@ -39,3 +39,17 @@
|
||||
url = file:///u01/app/oracle/product/11.2.0/xe/jdbc/lib/ojdbc6.jar
|
||||
sha1 = 2f89cd9176772c3a6c261ce6a8e3d0d4425f5679
|
||||
remove = ojdbc6.jar
|
||||
|
||||
[library "db2Driver"]
|
||||
name = DB2 Type 4 JDBC driver (10.5)
|
||||
url = file:///opt/ibm/db2/V10.5/java/db2jcc4.jar
|
||||
sha1 = 9344d4fd41d6511f2d1d1deb7759056495b3a39b
|
||||
needs = db2DriverLicense
|
||||
remove = db2jcc4.jar
|
||||
|
||||
# Omit SHA-1 for license JAR as it's not stable and depends on the product
|
||||
# the customer has purchased.
|
||||
[library "db2DriverLicense"]
|
||||
name = DB2 Type 4 JDBC driver license (10.5)
|
||||
url = file:///opt/ibm/db2/V10.5/java/db2jcc_license_cu.jar
|
||||
remove = db2jcc_license_cu.jar
|
||||
|
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2015 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import static com.google.gerrit.server.schema.JdbcUtil.hostname;
|
||||
import static com.google.gerrit.server.schema.JdbcUtil.port;
|
||||
|
||||
import com.google.gerrit.server.config.ConfigSection;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
public class DB2 extends BaseDataSourceType {
|
||||
private Config cfg;
|
||||
|
||||
@Inject
|
||||
public DB2(@GerritServerConfig final Config cfg) {
|
||||
super("com.ibm.db2.jcc.DB2Driver");
|
||||
this.cfg = cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
final ConfigSection dbc = new ConfigSection(cfg, "database");
|
||||
b.append("jdbc:db2://");
|
||||
b.append(hostname(dbc.optional("hostname")));
|
||||
b.append(port(dbc.optional("port")));
|
||||
b.append("/");
|
||||
b.append(dbc.required("database"));
|
||||
return b.toString();
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ public class DataSourceModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("db2")).to(DB2.class);
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("h2")).to(H2.class);
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("jdbc")).to(JDBC.class);
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("mysql")).to(MySql.class);
|
||||
|
6
lib/BUCK
6
lib/BUCK
@ -26,9 +26,9 @@ define_license(name = 'DO_NOT_DISTRIBUTE')
|
||||
|
||||
maven_jar(
|
||||
name = 'gwtorm_client',
|
||||
id = 'com.google.gerrit:gwtorm:1.14-14-gf54f1f1',
|
||||
bin_sha1 = 'c02267e0245dd06930ea64a2d7c5ddc5ba6d9cfb',
|
||||
src_sha1 = '3d17ae8a173eb34d89098c748f28cddd5080adbc',
|
||||
id = 'com.google.gerrit:gwtorm:1.14-16-gc4e356a',
|
||||
bin_sha1 = '01225468065812bbe5f27972df6dafa9d796d833',
|
||||
src_sha1 = '3622460ed58684cb33f786e3748637c8eea324f9',
|
||||
license = 'Apache2.0',
|
||||
repository = GERRIT,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user