summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-06-01 08:55:20 -0700
committerShawn O. Pearce <sop@google.com>2009-06-01 12:47:33 -0700
commit2e66c1abb40edeb13209abf986b714deaab6e551 (patch)
treeb1c4245c2f982df15ea39e5f8e2cdeecc30f0037
parente21a864864feec0ab23f80a490018751efa8f4eb (diff)
Create a utility to export system_config to gerrit.config
This tool can be used to help an admin convert their system settings data over to the new format. Currently only sshd_port has been moved to sshd.listenAddress so that is the only property moved by the tool. Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r--src/main/java/com/google/gerrit/pgm/ConvertSystemConfig.java87
-rw-r--r--src/main/java/com/google/gerrit/server/GerritServer.java4
-rw-r--r--src/main/webapp/WEB-INF/sql/upgrade011_012.sql6
-rw-r--r--src/main/webapp/WEB-INF/sql/upgrade011_012_part1.sql4
-rw-r--r--src/main/webapp/WEB-INF/sql/upgrade011_012_part2.sql4
5 files changed, 97 insertions, 8 deletions
diff --git a/src/main/java/com/google/gerrit/pgm/ConvertSystemConfig.java b/src/main/java/com/google/gerrit/pgm/ConvertSystemConfig.java
new file mode 100644
index 0000000000..88dd1eb9de
--- /dev/null
+++ b/src/main/java/com/google/gerrit/pgm/ConvertSystemConfig.java
@@ -0,0 +1,87 @@
+// Copyright (C) 2009 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;
+
+import com.google.gerrit.client.reviewdb.ReviewDb;
+import com.google.gerrit.server.GerritServer;
+import com.google.gwtorm.client.OrmException;
+import com.google.gwtorm.jdbc.JdbcSchema;
+
+import org.spearce.jgit.lib.RepositoryConfig;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/** Export system_config from schema version 11 to gerrit.config file. */
+public class ConvertSystemConfig {
+ public static void main(final String[] argv) throws OrmException,
+ SQLException, IOException {
+ final ReviewDb db = GerritServer.createDatabase().open();
+ try {
+ final Statement s = ((JdbcSchema) db).getConnection().createStatement();
+ try {
+ final ResultSet r = s.executeQuery("SELECT * FROM system_config");
+ if (r.next()) {
+ final File sitePath = new File(r.getString("site_path"));
+ final File file = new File(sitePath, "gerrit.config");
+ final RepositoryConfig config = new RepositoryConfig(null, file);
+ String action;
+ try {
+ config.load();
+ action = "Updated";
+ } catch (FileNotFoundException noFile) {
+ action = "Created";
+ }
+ export(config, r);
+ config.save();
+ System.err.println(action + " " + file);
+ }
+ } finally {
+ s.close();
+ }
+ } finally {
+ db.close();
+ }
+ }
+
+ private static void export(RepositoryConfig config, ResultSet rs)
+ throws SQLException {
+ sshd(config, rs);
+ }
+
+ private static void sshd(RepositoryConfig config, ResultSet rs)
+ throws SQLException {
+ int port = rs.getInt("sshd_port");
+ if (port == 29418) {
+ config.unsetString("sshd", null, "listenaddress");
+ } else {
+ config.setString("sshd", null, "listenaddress", "*:" + port);
+ }
+ }
+
+ private static void copy(RepositoryConfig config, String section, String key,
+ ResultSet rs, String colName) throws SQLException {
+ final String value = rs.getString(colName);
+ if (value != null) {
+ config.setString(section, null, key, value);
+ } else {
+ config.unsetString(section, null, key);
+ }
+ }
+}
diff --git a/src/main/java/com/google/gerrit/server/GerritServer.java b/src/main/java/com/google/gerrit/server/GerritServer.java
index 4e13f0181e..06a96a1c7f 100644
--- a/src/main/java/com/google/gerrit/server/GerritServer.java
+++ b/src/main/java/com/google/gerrit/server/GerritServer.java
@@ -376,7 +376,7 @@ public class GerritServer {
return r;
}
- private Database<ReviewDb> createDatabase() throws OrmException {
+ public static Database<ReviewDb> createDatabase() throws OrmException {
final String dsName = "java:comp/env/jdbc/ReviewDb";
try {
datasource = (DataSource) new InitialContext().lookup(dsName);
@@ -397,7 +397,7 @@ public class GerritServer {
return new Database<ReviewDb>(datasource, ReviewDb.class);
}
- private Properties readGerritDataSource() throws OrmException {
+ private static Properties readGerritDataSource() throws OrmException {
final Properties srvprop = new Properties();
String name = System.getProperty("GerritServer");
if (name == null) {
diff --git a/src/main/webapp/WEB-INF/sql/upgrade011_012.sql b/src/main/webapp/WEB-INF/sql/upgrade011_012.sql
deleted file mode 100644
index e8b8e6d393..0000000000
--- a/src/main/webapp/WEB-INF/sql/upgrade011_012.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- Upgrade: schema_version 11 to 12
---
-
-ALTER TABLE system_config DROP COLUMN sshd_port;
-
-UPDATE schema_version SET version_nbr = 12;
diff --git a/src/main/webapp/WEB-INF/sql/upgrade011_012_part1.sql b/src/main/webapp/WEB-INF/sql/upgrade011_012_part1.sql
new file mode 100644
index 0000000000..5545ebc139
--- /dev/null
+++ b/src/main/webapp/WEB-INF/sql/upgrade011_012_part1.sql
@@ -0,0 +1,4 @@
+-- Upgrade: schema_version 11 to 12 (part 1)
+--
+
+UPDATE schema_version SET version_nbr = 12;
diff --git a/src/main/webapp/WEB-INF/sql/upgrade011_012_part2.sql b/src/main/webapp/WEB-INF/sql/upgrade011_012_part2.sql
new file mode 100644
index 0000000000..e99e665138
--- /dev/null
+++ b/src/main/webapp/WEB-INF/sql/upgrade011_012_part2.sql
@@ -0,0 +1,4 @@
+-- Upgrade: schema_version 11 to 12 (part 2)
+--
+
+ALTER TABLE system_config DROP COLUMN sshd_port;