diff --git a/common/src/main/java/io/druid/metadata/MetadataStorageConnectorConfig.java b/common/src/main/java/io/druid/metadata/MetadataStorageConnectorConfig.java index 07447c36a74..329f0de1d26 100644 --- a/common/src/main/java/io/druid/metadata/MetadataStorageConnectorConfig.java +++ b/common/src/main/java/io/druid/metadata/MetadataStorageConnectorConfig.java @@ -29,7 +29,7 @@ public class MetadataStorageConnectorConfig private boolean createTables = true; @JsonProperty - private String connectURI = null; + private String connectURI = "jdbc:derby://localhost:1527/druid;create=true"; @JsonProperty private String user = null; diff --git a/server/src/main/java/io/druid/guice/DerbyMetadataStorageDruidModule.java b/server/src/main/java/io/druid/guice/DerbyMetadataStorageDruidModule.java index 5dfed2ca4a6..c698da8f0ed 100644 --- a/server/src/main/java/io/druid/guice/DerbyMetadataStorageDruidModule.java +++ b/server/src/main/java/io/druid/guice/DerbyMetadataStorageDruidModule.java @@ -21,11 +21,11 @@ package io.druid.guice; import com.google.inject.Binder; import com.google.inject.Key; -import com.google.inject.Provides; import io.druid.metadata.DerbyConnector; +import io.druid.metadata.DerbyMetadataStorage; +import io.druid.metadata.MetadataStorage; import io.druid.metadata.MetadataStorageConnector; import io.druid.metadata.SQLMetadataConnector; -import org.skife.jdbi.v2.IDBI; public class DerbyMetadataStorageDruidModule extends SQLMetadataStorageDruidModule { @@ -42,6 +42,11 @@ public class DerbyMetadataStorageDruidModule extends SQLMetadataStorageDruidModu createBindingChoices(binder, TYPE); super.configure(binder); + PolyBind.optionBinder(binder, Key.get(MetadataStorage.class)) + .addBinding(TYPE) + .to(DerbyMetadataStorage.class) + .in(LazySingleton.class); + PolyBind.optionBinder(binder, Key.get(MetadataStorageConnector.class)) .addBinding(TYPE) .to(DerbyConnector.class) diff --git a/server/src/main/java/io/druid/guice/MetadataDbConfigModule.java b/server/src/main/java/io/druid/guice/MetadataConfigModule.java similarity index 96% rename from server/src/main/java/io/druid/guice/MetadataDbConfigModule.java rename to server/src/main/java/io/druid/guice/MetadataConfigModule.java index 71b27b9793f..be08f43fa72 100644 --- a/server/src/main/java/io/druid/guice/MetadataDbConfigModule.java +++ b/server/src/main/java/io/druid/guice/MetadataConfigModule.java @@ -21,12 +21,12 @@ package io.druid.guice; import com.google.inject.Binder; import com.google.inject.Module; -import io.druid.metadata.MetadataStorageConnectorConfig; import io.druid.metadata.MetadataRuleManagerConfig; import io.druid.metadata.MetadataSegmentManagerConfig; +import io.druid.metadata.MetadataStorageConnectorConfig; import io.druid.metadata.MetadataStorageTablesConfig; -public class MetadataDbConfigModule implements Module +public class MetadataConfigModule implements Module { @Override public void configure(Binder binder) diff --git a/server/src/main/java/io/druid/guice/SQLMetadataStorageDruidModule.java b/server/src/main/java/io/druid/guice/SQLMetadataStorageDruidModule.java index f69c68e0119..96468ac075e 100644 --- a/server/src/main/java/io/druid/guice/SQLMetadataStorageDruidModule.java +++ b/server/src/main/java/io/druid/guice/SQLMetadataStorageDruidModule.java @@ -25,6 +25,7 @@ import com.google.inject.Module; import io.druid.indexer.MetadataStorageUpdaterJobHandler; import io.druid.indexer.SQLMetadataStorageUpdaterJobHandler; import io.druid.indexing.overlord.IndexerMetadataStorageCoordinator; +import io.druid.metadata.MetadataStorage; import io.druid.metadata.MetadataStorageActionHandlerFactory; import io.druid.metadata.IndexerSQLMetadataStorageCoordinator; import io.druid.metadata.MetadataRuleManager; @@ -62,6 +63,9 @@ public class SQLMetadataStorageDruidModule implements Module PolyBind.createChoiceWithDefault( binder, PROPERTY, Key.get(MetadataStorageConnector.class), null, defaultPropertyValue ); + PolyBind.createChoiceWithDefault( + binder, PROPERTY, Key.get(MetadataStorage.class), Key.get(MetadataStorage.class), defaultPropertyValue + ); PolyBind.createChoiceWithDefault( binder, PROPERTY, Key.get(SQLMetadataConnector.class), null, defaultPropertyValue ); diff --git a/server/src/main/java/io/druid/initialization/Initialization.java b/server/src/main/java/io/druid/initialization/Initialization.java index 32c6e89e93e..7bd7fc6e1fb 100644 --- a/server/src/main/java/io/druid/initialization/Initialization.java +++ b/server/src/main/java/io/druid/initialization/Initialization.java @@ -45,7 +45,7 @@ import io.druid.guice.IndexingServiceDiscoveryModule; import io.druid.guice.JacksonConfigManagerModule; import io.druid.guice.LifecycleModule; import io.druid.guice.LocalDataStorageDruidModule; -import io.druid.guice.MetadataDbConfigModule; +import io.druid.guice.MetadataConfigModule; import io.druid.guice.ParsersModule; import io.druid.guice.QueryRunnerFactoryModule; import io.druid.guice.QueryableModule; @@ -333,7 +333,7 @@ public class Initialization new QueryRunnerFactoryModule(), new DiscoveryModule(), new ServerViewModule(), - new MetadataDbConfigModule(), + new MetadataConfigModule(), new DerbyMetadataStorageDruidModule(), new JacksonConfigManagerModule(), new IndexingServiceDiscoveryModule(), diff --git a/server/src/main/java/io/druid/metadata/DerbyConnector.java b/server/src/main/java/io/druid/metadata/DerbyConnector.java index 70ba42f7fc6..ad57c55be00 100644 --- a/server/src/main/java/io/druid/metadata/DerbyConnector.java +++ b/server/src/main/java/io/druid/metadata/DerbyConnector.java @@ -19,15 +19,11 @@ package io.druid.metadata; -import com.google.api.client.repackaged.com.google.common.base.Throwables; import com.google.common.base.Supplier; import com.google.inject.Inject; -import org.apache.derby.drda.NetworkServerControl; +import org.apache.commons.dbcp2.BasicDataSource; import org.skife.jdbi.v2.DBI; import org.skife.jdbi.v2.Handle; -import org.skife.jdbi.v2.tweak.ConnectionFactory; - -import java.net.InetAddress; public class DerbyConnector extends SQLMetadataConnector { @@ -37,10 +33,20 @@ public class DerbyConnector extends SQLMetadataConnector @Inject public DerbyConnector(Supplier config, Supplier dbTables) { - this(config, dbTables, new DBI(getConnectionFactory("druidDerbyDb"))); + super(config, dbTables); + + final BasicDataSource datasource = getDatasource(); + datasource.setDriverClassLoader(getClass().getClassLoader()); + datasource.setDriverClassName("org.apache.derby.jdbc.ClientDriver"); + + this.dbi = new DBI(datasource); } - public DerbyConnector(Supplier config, Supplier dbTables, DBI dbi) + public DerbyConnector( + Supplier config, + Supplier dbTables, + DBI dbi + ) { super(config, dbTables); this.dbi = dbi; @@ -63,15 +69,4 @@ public class DerbyConnector extends SQLMetadataConnector @Override public DBI getDBI() { return dbi; } - - private static ConnectionFactory getConnectionFactory(String dbName) - { - try { - NetworkServerControl server = new NetworkServerControl(InetAddress.getByName("localhost"),1527); - server.start(null); - } catch (Exception e) { - throw Throwables.propagate(e); - } - return new DerbyConnectionFactory(dbName); - } } diff --git a/server/src/main/java/io/druid/metadata/DerbyMetadataStorage.java b/server/src/main/java/io/druid/metadata/DerbyMetadataStorage.java new file mode 100644 index 00000000000..647b1ffb791 --- /dev/null +++ b/server/src/main/java/io/druid/metadata/DerbyMetadataStorage.java @@ -0,0 +1,69 @@ +/* + * Druid - a distributed column store. + * Copyright (C) 2012, 2013 Metamarkets Group Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package io.druid.metadata; + +import com.google.common.base.Throwables; +import com.metamx.common.lifecycle.LifecycleStart; +import com.metamx.common.lifecycle.LifecycleStop; +import org.apache.derby.drda.NetworkServerControl; + +import java.net.InetAddress; + +/** + */ +public class DerbyMetadataStorage extends MetadataStorage +{ + private final NetworkServerControl server; + + public DerbyMetadataStorage() + { + try { + this.server = new NetworkServerControl(InetAddress.getByName("localhost"), 1527); + } + catch (Exception e) { + throw Throwables.propagate(e); + } + + } + + @Override + @LifecycleStart + public void start() + { + try { + server.start(null); + } + catch (Exception e) { + throw Throwables.propagate(e); + } + } + + @Override + @LifecycleStop + public void stop() + { + try { + server.shutdown(); + } + catch (Exception e) { + throw Throwables.propagate(e); + } + } +} diff --git a/server/src/main/java/io/druid/metadata/MetadataStorage.java b/server/src/main/java/io/druid/metadata/MetadataStorage.java new file mode 100644 index 00000000000..2bdd3378385 --- /dev/null +++ b/server/src/main/java/io/druid/metadata/MetadataStorage.java @@ -0,0 +1,21 @@ +package io.druid.metadata; + +import com.metamx.common.lifecycle.LifecycleStart; +import com.metamx.common.lifecycle.LifecycleStop; + +/** + */ +public abstract class MetadataStorage +{ + @LifecycleStart + public void start() + { + // do nothing + } + + @LifecycleStop + public void stop() + { + // do nothing + } +} diff --git a/services/src/main/java/io/druid/cli/CliCoordinator.java b/services/src/main/java/io/druid/cli/CliCoordinator.java index b1f670350bb..9470b4c1542 100644 --- a/services/src/main/java/io/druid/cli/CliCoordinator.java +++ b/services/src/main/java/io/druid/cli/CliCoordinator.java @@ -29,18 +29,19 @@ import com.metamx.common.concurrent.ScheduledExecutorFactory; import com.metamx.common.logger.Logger; import io.airlift.command.Command; import io.druid.client.indexing.IndexingServiceClient; -import io.druid.metadata.MetadataRuleManager; -import io.druid.metadata.MetadataRuleManagerConfig; -import io.druid.metadata.MetadataRuleManagerProvider; -import io.druid.metadata.MetadataSegmentManager; -import io.druid.metadata.MetadataSegmentManagerConfig; -import io.druid.metadata.MetadataSegmentManagerProvider; import io.druid.guice.ConfigProvider; import io.druid.guice.Jerseys; import io.druid.guice.JsonConfigProvider; import io.druid.guice.LazySingleton; import io.druid.guice.LifecycleModule; import io.druid.guice.ManageLifecycle; +import io.druid.metadata.MetadataRuleManager; +import io.druid.metadata.MetadataRuleManagerConfig; +import io.druid.metadata.MetadataRuleManagerProvider; +import io.druid.metadata.MetadataSegmentManager; +import io.druid.metadata.MetadataSegmentManagerConfig; +import io.druid.metadata.MetadataSegmentManagerProvider; +import io.druid.metadata.MetadataStorage; import io.druid.server.coordinator.DruidCoordinator; import io.druid.server.coordinator.DruidCoordinatorConfig; import io.druid.server.coordinator.LoadQueueTaskMaster; @@ -49,9 +50,9 @@ import io.druid.server.http.BackwardsCompatibleInfoResource; import io.druid.server.http.CoordinatorDynamicConfigsResource; import io.druid.server.http.CoordinatorRedirectInfo; import io.druid.server.http.CoordinatorResource; -import io.druid.server.http.MetadataResource; import io.druid.server.http.DatasourcesResource; import io.druid.server.http.InfoResource; +import io.druid.server.http.MetadataResource; import io.druid.server.http.RedirectFilter; import io.druid.server.http.RedirectInfo; import io.druid.server.http.RulesResource; @@ -93,6 +94,8 @@ public class CliCoordinator extends ServerRunnable ConfigProvider.bind(binder, DruidCoordinatorConfig.class); + binder.bind(MetadataStorage.class).in(ManageLifecycle.class); + JsonConfigProvider.bind(binder, "druid.manager.segments", MetadataSegmentManagerConfig.class); JsonConfigProvider.bind(binder, "druid.manager.rules", MetadataRuleManagerConfig.class);