From a6016d70fc67c4a68d0971be431fe937f3a5626a Mon Sep 17 00:00:00 2001 From: jisookim0513 Date: Fri, 31 Oct 2014 13:10:09 -0700 Subject: [PATCH] added deleted classes back --- .../metadata/MetadataStorageConnector.java | 50 +++++++ .../MetadataStorageConnectorConfig.java | 87 +++++++++++++ .../metadata/MetadataStorageTablesConfig.java | 123 ++++++++++++++++++ .../io/druid/db/SQLMetadataConnectorTest.java | 12 +- 4 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/io/druid/metadata/MetadataStorageConnector.java create mode 100644 common/src/main/java/io/druid/metadata/MetadataStorageConnectorConfig.java create mode 100644 common/src/main/java/io/druid/metadata/MetadataStorageTablesConfig.java diff --git a/common/src/main/java/io/druid/metadata/MetadataStorageConnector.java b/common/src/main/java/io/druid/metadata/MetadataStorageConnector.java new file mode 100644 index 00000000000..76d54b2ae80 --- /dev/null +++ b/common/src/main/java/io/druid/metadata/MetadataStorageConnector.java @@ -0,0 +1,50 @@ +/* + * 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; + +/** + */ +public interface MetadataStorageConnector +{ + public Void insertOrUpdate( + final String tableName, + final String keyColumn, + final String valueColumn, + final String key, + final byte[] value + ) throws Exception; + + + public byte[] lookup( + final String tableName, + final String keyColumn, + final String valueColumn, + final String key + ); + + public void createSegmentTable(); + + public void createRulesTable(); + + public void createConfigTable(); + + public void createTaskTables(); + +} \ No newline at end of file diff --git a/common/src/main/java/io/druid/metadata/MetadataStorageConnectorConfig.java b/common/src/main/java/io/druid/metadata/MetadataStorageConnectorConfig.java new file mode 100644 index 00000000000..050619fe12c --- /dev/null +++ b/common/src/main/java/io/druid/metadata/MetadataStorageConnectorConfig.java @@ -0,0 +1,87 @@ +/* + * 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.fasterxml.jackson.annotation.JsonProperty; + +/** + */ +public class MetadataStorageConnectorConfig +{ + @JsonProperty + private boolean createTables = true; + + @JsonProperty + private String connectURI = null; + + @JsonProperty + private String user = null; + + @JsonProperty + private String password = null; + + @JsonProperty + private boolean useValidationQuery = false; + + @JsonProperty + private String validationQuery = "SELECT 1"; + + public boolean isCreateTables() + { + return createTables; + } + + public String getConnectURI() + { + return connectURI; + } + + public String getUser() + { + return user; + } + + public String getPassword() + { + return password; + } + + public boolean isUseValidationQuery() + { + return useValidationQuery; + } + + public String getValidationQuery() { + return validationQuery; + } + + @Override + public String toString() + { + return "DbConnectorConfig{" + + "createTables=" + createTables + + ", connectURI='" + connectURI + '\'' + + ", user='" + user + '\'' + + ", password=****" + + ", useValidationQuery=" + useValidationQuery + + ", validationQuery='" + validationQuery + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/common/src/main/java/io/druid/metadata/MetadataStorageTablesConfig.java b/common/src/main/java/io/druid/metadata/MetadataStorageTablesConfig.java new file mode 100644 index 00000000000..3e56acca95a --- /dev/null +++ b/common/src/main/java/io/druid/metadata/MetadataStorageTablesConfig.java @@ -0,0 +1,123 @@ +/* + * 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.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + */ +public class MetadataStorageTablesConfig +{ + public static MetadataStorageTablesConfig fromBase(String base) + { + return new MetadataStorageTablesConfig(base, null, null, null, null, null, null); + } + + private static String defaultBase = "druid"; + + @JsonProperty("base") + private final String base; + + @JsonProperty("segments") + private final String segmentsTable; + + @JsonProperty("rules") + private final String rulesTable; + + @JsonProperty("config") + private final String configTable; + + @JsonProperty("tasks") + private final String tasksTable; + + @JsonProperty("taskLog") + private final String taskLogTable; + + @JsonProperty("taskLock") + private final String taskLockTable; + + @JsonCreator + public MetadataStorageTablesConfig( + @JsonProperty("base") String base, + @JsonProperty("segments") String segmentsTable, + @JsonProperty("rules") String rulesTable, + @JsonProperty("config") String configTable, + @JsonProperty("tasks") String tasksTable, + @JsonProperty("taskLog") String taskLogTable, + @JsonProperty("taskLock") String taskLockTable + ) + { + this.base = (base == null) ? defaultBase : base; + this.segmentsTable = makeTableName(segmentsTable, "segments"); + this.rulesTable = makeTableName(rulesTable, "rules"); + this.configTable = makeTableName(configTable, "config"); + this.tasksTable = makeTableName(tasksTable, "tasks"); + this.taskLogTable = makeTableName(taskLogTable, "tasklogs"); + this.taskLockTable = makeTableName(taskLockTable, "tasklocks"); + } + + private String makeTableName(String explicitTableName, String defaultSuffix) + { + if (explicitTableName == null) { + if (base == null) { + return null; + } + return String.format("%s_%s", base, defaultSuffix); + } + + return explicitTableName; + } + + public String getBase() + { + return base; + } + + public String getSegmentsTable() + { + return segmentsTable; + } + + public String getRulesTable() + { + return rulesTable; + } + + public String getConfigTable() + { + return configTable; + } + + public String getTasksTable() + { + return tasksTable; + } + + public String getTaskLogTable() + { + return taskLogTable; + } + + public String getTaskLockTable() + { + return taskLockTable; + } +} \ No newline at end of file diff --git a/server/src/test/java/io/druid/db/SQLMetadataConnectorTest.java b/server/src/test/java/io/druid/db/SQLMetadataConnectorTest.java index 97465b94a5e..42cd786955d 100644 --- a/server/src/test/java/io/druid/db/SQLMetadataConnectorTest.java +++ b/server/src/test/java/io/druid/db/SQLMetadataConnectorTest.java @@ -22,6 +22,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Suppliers; import com.google.common.base.Throwables; import io.druid.jackson.DefaultObjectMapper; +import io.druid.metadata.DerbyConnector; +import io.druid.metadata.MetadataStorageConnectorConfig; +import io.druid.metadata.MetadataStorageTablesConfig; import junit.framework.Assert; import org.junit.Before; import org.junit.Test; @@ -80,7 +83,7 @@ public class SQLMetadataConnectorTest public Void withHandle(Handle handle) throws Exception { for(String table : tables) { - Assert.assertTrue(String.format("table $s was not created!", table), connector.tableExists(handle, table)); + Assert.assertTrue(String.format("table $s was not created!", table), tableExists(handle, table)); } return null; @@ -167,4 +170,11 @@ public class SQLMetadataConnectorTest } } + private boolean tableExists(Handle handle, String tableName) + { + return !handle.createQuery("select * from SYS.SYSTABLES where tablename = :tableName") + .bind("tableName", tableName.toUpperCase()) + .list() + .isEmpty(); + } }