├── .gitignore ├── LICENSE.txt ├── NOTICE.txt ├── README.rst ├── pom.xml └── src └── main ├── java └── com │ └── larsgeorge │ └── hadoop │ └── hbase │ ├── ColumnDefinition.java │ ├── HBaseManager.java │ └── TableSchema.java └── resources └── schema.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .classpath 3 | .settings 4 | target/ 5 | .idea/ 6 | *.iml -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | 205 | APACHE HADOOP SUBCOMPONENTS: 206 | 207 | The Apache Hadoop project contains subcomponents with separate copyright 208 | notices and license terms. Your use of the source code for the these 209 | subcomponents is subject to the terms and conditions of the following 210 | licenses. 211 | 212 | For the org.apache.hadoop.util.bloom.* classes: 213 | 214 | /** 215 | * 216 | * Copyright (c) 2005, European Commission project OneLab under contract 217 | * 034819 (http://www.one-lab.org) 218 | * All rights reserved. 219 | * Redistribution and use in source and binary forms, with or 220 | * without modification, are permitted provided that the following 221 | * conditions are met: 222 | * - Redistributions of source code must retain the above copyright 223 | * notice, this list of conditions and the following disclaimer. 224 | * - Redistributions in binary form must reproduce the above copyright 225 | * notice, this list of conditions and the following disclaimer in 226 | * the documentation and/or other materials provided with the distribution. 227 | * - Neither the name of the University Catholique de Louvain - UCL 228 | * nor the names of its contributors may be used to endorse or 229 | * promote products derived from this software without specific prior 230 | * written permission. 231 | * 232 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 233 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 234 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 235 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 236 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 237 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 238 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 239 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 240 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 241 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 242 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 243 | * POSSIBILITY OF SUCH DAMAGE. 244 | */ 245 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | This product includes software developed by The Apache Software 2 | Foundation (http://www.apache.org/). 3 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | HBase Schema Manager 2 | ==================== 3 | 4 | A small maven based application that allows to create and change HBase tables using an external XML schema file. 5 | 6 | Usage 7 | ----- 8 | 9 | See the sample ``schema.xml`` for a start. You can define as many named configurations within one schema file as you wish. The same is true for tables and, within each table, the column family definitions. Once you have created your schema file use it like this:: 10 | 11 | java -jar hbase-schema-manager-1.0.0.jar [] [] 12 | 13 | where "options" can be:: 14 | 15 | -c,--create-config creates a config from the tables. 16 | -l,--list lists all tables but performs no further action. 17 | -n,--dryrun do not create or change tables, just print out 18 | actions. 19 | -p,--client-port the zookeeper client port to use, default: 2181 20 | -q,--quorum the list of quorum servers, e.g. 21 | "foo.com,bar.com" 22 | -v,--verbose print verbose output. 23 | 24 | Notes: 25 | - If no configuration name was given then the first one found is used or in case of using "-c" it defaults to "new". 26 | - The list of quorum server is without ports and comma separated. 27 | 28 | Example:: 29 | 30 | java -jar hbase-schema-manager-1.0.0.jar -v -l schema.xml 31 | 32 | You can create a config from an existing cluster like so:: 33 | 34 | java -jar hbase-schema-manager-1.0.0.jar -c new-schema1.xml 35 | 36 | or:: 37 | 38 | java -jar hbase-schema-manager-1.0.0.jar -c -q localhost - cluster1 > new-schema2.xml 39 | 40 | Notes: 41 | Using "-" for the schema file is redirecting the output to standard out. 42 | 43 | More info can be found here http://www.larsgeorge.com/2009/05/hbase-schema-manager.html 44 | 45 | Building 46 | -------- 47 | 48 | How to setup and run this maven enabled application? 49 | 50 | 1. git clone git://github.com/larsgeorge/hbase-schema-manager.git 51 | 2. Download hbase-0.89.20100924.jar from http://archive.apache.org/dist/hbase/hbase-0.89.20100924/hbase-0.89.20100924/hbase-0.89.20100924.jar 52 | 3. mvn install:install-file -DgroupId=org.apache.hadoop -DartifactId=hbase -Dversion=0.89.20100924 -Dpackaging=jar -Dfile= 53 | 4. mvn package 54 | 5. Go to target and find hbase-schema-manager-1.0.0.jar 55 | 56 | How to use this application for further development with Eclipse? 57 | 58 | 1. mvn eclipse:clean eclipse:eclipse 59 | 2. Open Eclipse 60 | 3. File->Import->Existing Project into Workspace 61 | 4. Define classpath variable M2_REPO= 62 | 5. Done 63 | 64 | Cheers -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.larsgeorge 5 | hbase-schema-manager 6 | jar 7 | 1.0.0 8 | HBase Schema Manager 9 | 10 | http://github.com/larsgeorge/hbase-schema-manager 11 | 12 | 13 | http://github.com/larsgeorge/hbase-schema-manager 14 | scm:git:git://github.com/larsgeorge/hbase-schema-manager.git 15 | scm:git:git://github.com/larsgeorge/hbase-schema-manager.git 16 | 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 0.20-append-r1044525 22 | 0.91.0-SNAPSHOT 23 | 24 | 25 | 26 | 27 | 28 | org.apache.maven.plugins 29 | maven-compiler-plugin 30 | 2.0.2 31 | 32 | 1.6 33 | 1.6 34 | 35 | 36 | 37 | org.apache.maven.plugins 38 | maven-shade-plugin 39 | 1.4 40 | 41 | 42 | package 43 | 44 | shade 45 | 46 | 47 | 48 | 50 | 51 | com.larsgeorge.hadoop.hbase.HBaseManager 52 | ${project.version} 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | commons-logging 66 | commons-logging 67 | 1.1.1 68 | 69 | 70 | log4j 71 | log4j 72 | 1.2.16 73 | 74 | 75 | commons-cli 76 | commons-cli 77 | 1.2 78 | 79 | 80 | commons-lang 81 | commons-lang 82 | 2.5 83 | 84 | 85 | commons-collections 86 | commons-collections 87 | 3.2.1 88 | 89 | 90 | commons-configuration 91 | commons-configuration 92 | 1.6 93 | 94 | 95 | commons-collections 96 | commons-collections 97 | 98 | 99 | commons-lang 100 | commons-lang 101 | 102 | 103 | commons-logging 104 | commons-logging 105 | 106 | 107 | commons-digester 108 | commons-digester 109 | 110 | 111 | commons-beanutils-core 112 | commons-beanutils 113 | 114 | 115 | 116 | 117 | org.apache.hadoop 118 | hadoop-core 119 | ${hadoop-version} 120 | 121 | 122 | commons-cli 123 | commons-cli 124 | 125 | 126 | xmlenc 127 | xmlenc 128 | 129 | 130 | commons-httpclient 131 | commons-httpclient 132 | 133 | 134 | commons-codec 135 | commons-codec 136 | 137 | 138 | commons-net 139 | commons-net 140 | 141 | 142 | org.mortbay.jetty 143 | jetty 144 | 145 | 146 | org.mortbay.jetty 147 | jetty-util 148 | 149 | 150 | tomcat 151 | jasper-runtime 152 | 153 | 154 | tomcat 155 | jasper-compiler 156 | 157 | 158 | org.mortbay.jetty 159 | jsp-api-2.1 160 | 161 | 162 | org.mortbay.jetty 163 | jsp-2.1 164 | 165 | 166 | commons-el 167 | commons-el 168 | 169 | 170 | net.java.dev.jets3t 171 | jets3t 172 | 173 | 174 | org.mortbay.jetty 175 | servlet-api-2.5 176 | 177 | 178 | net.sf.kosmosfs 179 | kfs 180 | 181 | 182 | hsqldb 183 | hsqldb 184 | 185 | 186 | oro 187 | oro 188 | 189 | 190 | org.eclipse.jdt 191 | core 192 | 193 | 194 | 195 | 196 | org.apache.zookeeper 197 | zookeeper 198 | 3.3.2 199 | 200 | 201 | log4j 202 | log4j 203 | 204 | 205 | jline 206 | jline 207 | 208 | 209 | 210 | 211 | org.apache.hbase 212 | hbase 213 | ${hbase-version} 214 | 215 | 216 | commons-lang 217 | commons-lang 218 | 219 | 220 | com.google.guava 221 | guava 222 | 223 | 224 | commons-logging 225 | commons-logging 226 | 227 | 228 | log4j 229 | log4j 230 | 231 | 232 | org.apache.hadoop 233 | avro 234 | 235 | 236 | org.apache.zookeeper 237 | zookeeper 238 | 239 | 240 | org.apache.thrift 241 | thrift 242 | 243 | 244 | org.jruby 245 | jruby-complete 246 | 247 | 248 | org.slf4j 249 | slf4j-api 250 | 251 | 252 | org.slf4j 253 | slf4j-log4j12 254 | 255 | 256 | com.google.protobuf 257 | protobuf-java 258 | 259 | 260 | com.sun.jersey 261 | jersey-core 262 | 263 | 264 | com.sun.jersey 265 | jersey-json 266 | 267 | 268 | com.sun.jersey 269 | jersey-server 270 | 271 | 272 | javax.ws.rs 273 | jsr311-api 274 | 275 | 276 | javax.xml.bind 277 | jaxb-api 278 | 279 | 280 | stax 281 | stax-api 282 | 283 | 284 | commons-cli 285 | commons-cli 286 | 287 | 288 | commons-codec 289 | commons-codec 290 | 291 | 292 | commons-httpclient 293 | commons-httpclient 294 | 295 | 296 | org.mortbay.jetty 297 | jetty 298 | 299 | 300 | org.mortbay.jetty 301 | jetty-util 302 | 303 | 304 | org.mortbay.jetty 305 | jsp-2.1 306 | 307 | 308 | org.mortbay.jetty 309 | jsp-api-2.1 310 | 311 | 312 | org.mortbay.jetty 313 | servlet-api-2.5 314 | 315 | 316 | tomcat 317 | jasper-compiler 318 | 319 | 320 | tomcat 321 | jasper-runtime 322 | 323 | 324 | 325 | 326 | 327 | 328 | -------------------------------------------------------------------------------- /src/main/java/com/larsgeorge/hadoop/hbase/ColumnDefinition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package com.larsgeorge.hadoop.hbase; 21 | 22 | import org.apache.hadoop.hbase.HColumnDescriptor; 23 | 24 | /** 25 | * Describes a column and its features. 26 | * 27 | * @author Lars George 28 | */ 29 | public class ColumnDefinition { 30 | 31 | private String name; 32 | private String description; 33 | private int maxVersions = HColumnDescriptor.DEFAULT_VERSIONS; 34 | private String compression = HColumnDescriptor.DEFAULT_COMPRESSION; 35 | private boolean inMemory = HColumnDescriptor.DEFAULT_IN_MEMORY; 36 | private boolean blockCacheEnabled = HColumnDescriptor.DEFAULT_BLOCKCACHE; 37 | private int blockSize = HColumnDescriptor.DEFAULT_BLOCKSIZE; 38 | private int timeToLive = HColumnDescriptor.DEFAULT_TTL; 39 | private String bloomFilter = HColumnDescriptor.DEFAULT_BLOOMFILTER; 40 | private final int replicationScope = HColumnDescriptor.DEFAULT_REPLICATION_SCOPE; 41 | 42 | public String getColumnName() { 43 | return name; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public void setName(final String name) { 51 | this.name = name; 52 | } 53 | 54 | public String getDescription() { 55 | return description; 56 | } 57 | 58 | public void setDescription(final String description) { 59 | this.description = description; 60 | } 61 | 62 | public int getMaxVersions() { 63 | return maxVersions; 64 | } 65 | 66 | public void setMaxVersions(final int maxVersions) { 67 | this.maxVersions = maxVersions; 68 | } 69 | 70 | public String getCompression() { 71 | return compression; 72 | } 73 | 74 | public void setCompression(final String compression) { 75 | this.compression = compression; 76 | } 77 | 78 | public boolean isInMemory() { 79 | return inMemory; 80 | } 81 | 82 | public void setInMemory(final boolean inMemory) { 83 | this.inMemory = inMemory; 84 | } 85 | 86 | public boolean isBlockCacheEnabled() { 87 | return blockCacheEnabled; 88 | } 89 | 90 | public void setBlockCacheEnabled(final boolean blockCacheEnabled) { 91 | this.blockCacheEnabled = blockCacheEnabled; 92 | } 93 | 94 | public void setBlockSize(final int blockSize) { 95 | this.blockSize = blockSize; 96 | } 97 | 98 | public int getBlockSize() { 99 | return blockSize; 100 | } 101 | 102 | public int getTimeToLive() { 103 | return timeToLive; 104 | } 105 | 106 | public void setTimeToLive(final int timeToLive) { 107 | this.timeToLive = timeToLive; 108 | } 109 | 110 | public String getBloomFilter() { 111 | return bloomFilter; 112 | } 113 | 114 | public void setBloomFilter(final String bloomFilter) { 115 | this.bloomFilter = bloomFilter; 116 | } 117 | 118 | public int getReplicationScope() { 119 | return replicationScope; 120 | } 121 | 122 | @Override 123 | public String toString() { 124 | return "name -> " + name 125 | + "\n description -> " + description 126 | + "\n maxVersions -> " + maxVersions 127 | + "\n compression -> " + compression 128 | + "\n inMemory -> " + inMemory 129 | + "\n blockCacheEnabled -> " + blockCacheEnabled 130 | + "\n blockSize -> " + blockSize 131 | + "\n timeToLive -> " + timeToLive 132 | + "\n bloomFilter -> " + bloomFilter 133 | + "\n replicationScope -> " + replicationScope; 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/com/larsgeorge/hadoop/hbase/HBaseManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package com.larsgeorge.hadoop.hbase; 21 | 22 | import java.io.BufferedOutputStream; 23 | import java.io.FileOutputStream; 24 | import java.io.IOException; 25 | import java.io.OutputStream; 26 | import java.io.PrintStream; 27 | import java.util.ArrayList; 28 | import java.util.Collection; 29 | import java.util.List; 30 | 31 | import org.apache.commons.cli.CommandLine; 32 | import org.apache.commons.cli.CommandLineParser; 33 | import org.apache.commons.cli.HelpFormatter; 34 | import org.apache.commons.cli.Options; 35 | import org.apache.commons.cli.ParseException; 36 | import org.apache.commons.cli.PosixParser; 37 | import org.apache.commons.configuration.ConfigurationException; 38 | import org.apache.commons.configuration.XMLConfiguration; 39 | import org.apache.hadoop.conf.Configuration; 40 | import org.apache.hadoop.hbase.HBaseConfiguration; 41 | import org.apache.hadoop.hbase.HColumnDescriptor; 42 | import org.apache.hadoop.hbase.HTableDescriptor; 43 | import org.apache.hadoop.hbase.client.HBaseAdmin; 44 | import org.apache.hadoop.hbase.util.Bytes; 45 | 46 | /** 47 | * Provides the functionality to create and maintain HBase tables. 48 | * 49 | * @author Lars George 50 | */ 51 | public class HBaseManager { 52 | 53 | private HBaseAdmin _hbaseAdmin; 54 | private String schemaFileName = null; 55 | private String configName = null; 56 | private boolean verbose = false; 57 | private int configNum = -1; 58 | private XMLConfiguration config = null; 59 | private String configBaseKey = null; 60 | private ArrayList schemas = null; 61 | private HTableDescriptor[] remoteTables = null; 62 | private CommandLine cmd = null; 63 | private String quorum = null; 64 | private String zkPort = null; 65 | 66 | /** 67 | * Creates a new instance of this class and parses the given command line 68 | * parameters. 69 | * 70 | * @param args The command line parameters. 71 | * @throws ParseException When the command line parameters are borked. 72 | * @throws ConfigurationException When the XML based configuration is broken. 73 | */ 74 | public HBaseManager(final String[] args) throws ParseException, ConfigurationException { 75 | parseArgs(args); 76 | verbose = cmd.hasOption("v"); 77 | boolean createConfig = cmd.hasOption("c"); 78 | if (!createConfig) { 79 | readConfiguration(); 80 | } else { 81 | final String[] rem = cmd.getArgs(); 82 | schemaFileName = rem[0]; 83 | if (verbose) { 84 | System.out.println("schema filename: " + schemaFileName); 85 | } 86 | configName = rem.length > 1 ? rem[1] : "new"; 87 | if (verbose) { 88 | System.out.println("configuration used: " + configName); 89 | } 90 | quorum = cmd.getOptionValue("q"); 91 | if (cmd.hasOption("p")) { 92 | zkPort = cmd.getOptionValue("p"); 93 | } 94 | if (quorum == null) { 95 | System.err.println("ERROR: zookeeper quorum not specified, use -q option."); 96 | System.exit(-9); 97 | } 98 | } 99 | } 100 | 101 | /** 102 | * Reads a previously created configuration. 103 | * 104 | * @throws ConfigurationException When the XML based configuration is broken. 105 | */ 106 | private void readConfiguration() throws ConfigurationException { 107 | final String[] rem = cmd.getArgs(); 108 | schemaFileName = rem[0]; 109 | if (verbose) { 110 | System.out.println("schema filename: " + schemaFileName); 111 | } 112 | configName = rem.length > 1 ? rem[1] : null; 113 | if (verbose) { 114 | System.out.println("configuration used: " + (configName != null ? configName : "default")); 115 | } 116 | config = new XMLConfiguration(schemaFileName); 117 | configNum = getConfigurationNumber(config, configName); 118 | if (verbose) { 119 | System.out.println("using config number: " + (configNum == -1 ? "default" : configNum)); 120 | } 121 | configBaseKey = configNum == -1 ? "configuration." : "configuration(" + configNum + ")."; 122 | schemas = new ArrayList(); 123 | readTableSchemas(); 124 | if (verbose) { 125 | System.out.println("table schemas read from config: \n " + schemas); 126 | } 127 | } 128 | 129 | /** 130 | * Parse the command line parameters. 131 | * 132 | * @param args The parameters to parse. 133 | * @throws ParseException When the parsing of the parameters fails. 134 | */ 135 | private void parseArgs(final String[] args) throws ParseException { 136 | // create options 137 | final Options options = new Options(); 138 | options.addOption("l", "list", false, "lists all tables but performs no further action."); 139 | options.addOption("n", "dryrun", false, "do not create or change tables, just print out actions."); 140 | options.addOption("c", "create-config", false, "creates a config from the tables."); 141 | options.addOption("q", "quorum", true, "the list of quorum servers, e.g. \"foo.com,bar.com\""); 142 | options.addOption("p", "client-port", true, "the zookeeper client port to use, default: 2181"); 143 | options.addOption("v", "verbose", false, "print verbose output."); 144 | // check if we are missing parameters 145 | if (args.length == 0) { 146 | final HelpFormatter formatter = new HelpFormatter(); 147 | formatter.printHelp("HBaseManager [] [] []", options); 148 | System.exit(-1); 149 | } 150 | final CommandLineParser parser = new PosixParser(); 151 | cmd = parser.parse(options, args); 152 | } 153 | 154 | /** 155 | * Reads the table schemas from the configuration. 156 | */ 157 | private void readTableSchemas() { 158 | final int maxTables = config.getMaxIndex(configBaseKey + "schema.table"); 159 | // iterate over tables 160 | for (int t = 0; t <= maxTables; t++) { 161 | final String base = configBaseKey + "schema.table(" + t + ")."; 162 | final TableSchema ts = new TableSchema(); 163 | ts.setName(config.getString(base + "name")); 164 | if (config.containsKey(base + "description")) { 165 | ts.setDescription(config.getString(base + "description")); 166 | } 167 | if (config.containsKey(base + "deferred_log_flush")) { 168 | ts.setDeferredLogFlush(config.getBoolean(base + "deferred_log_flush")); 169 | } 170 | if (config.containsKey(base + "max_file_size")) { 171 | ts.setMaxFileSize(config.getLong(base + "max_file_size")); 172 | } 173 | if (config.containsKey(base + "memstore_flush_size")) { 174 | ts.setMemStoreFlushSize(config.getLong(base + "memstore_flush_size")); 175 | } 176 | if (config.containsKey(base + "read_only")) { 177 | ts.setReadOnly(config.getBoolean(base + "read_only")); 178 | } 179 | final int maxCols = config.getMaxIndex(base + "column_family"); 180 | // iterate over column families 181 | for (int c = 0; c <= maxCols; c++) { 182 | final String base2 = base + "column_family(" + c + ")."; 183 | final ColumnDefinition cd = new ColumnDefinition(); 184 | cd.setName(config.getString(base2 + "name")); 185 | cd.setDescription(config.getString(base2 + "description")); 186 | String val = config.getString(base2 + "max_versions"); 187 | if (val != null && val.length() > 0) { 188 | cd.setMaxVersions(Integer.parseInt(val)); 189 | } 190 | val = config.getString(base2 + "compression"); 191 | if (val != null && val.length() > 0) { 192 | cd.setCompression(val); 193 | } 194 | val = config.getString(base2 + "in_memory"); 195 | if (val != null && val.length() > 0) { 196 | cd.setInMemory(Boolean.parseBoolean(val)); 197 | } 198 | val = config.getString(base2 + "block_cache_enabled"); 199 | if (val != null && val.length() > 0) { 200 | cd.setBlockCacheEnabled(Boolean.parseBoolean(val)); 201 | } 202 | val = config.getString(base2 + "block_size"); 203 | if (val != null && val.length() > 0) { 204 | cd.setBlockSize(Integer.parseInt(val)); 205 | } 206 | val = config.getString(base2 + "time_to_live"); 207 | if (val != null && val.length() > 0) { 208 | cd.setTimeToLive(Integer.parseInt(val)); 209 | } 210 | val = config.getString(base2 + "bloom_filter"); 211 | if (val != null && val.length() > 0) { 212 | cd.setBloomFilter(val); 213 | } 214 | val = config.getString(base2 + "replication_scope"); 215 | if (val != null && val.length() > 0) { 216 | //cd.setScope(Integer.parseInt(val)); Add in 0.90 217 | System.err.println("WARN: cannot set replication scope!"); 218 | } 219 | ts.addColumn(cd); 220 | } 221 | schemas.add(ts); 222 | } 223 | } 224 | 225 | /** 226 | * Processes the schema file. 227 | * 228 | * @throws IOException When creating or changing the table fails. 229 | */ 230 | private void process() throws IOException { 231 | // create HBase admin interface 232 | _hbaseAdmin = new HBaseAdmin(getConfiguration()); 233 | // iterate over table schemas 234 | if (cmd.hasOption("l")) { 235 | listTables(); 236 | } else if (cmd.hasOption("c")) { 237 | createConfiguration(); 238 | } else { 239 | for (final TableSchema schema : schemas) { 240 | createOrChangeTable(schema, !cmd.hasOption("n")); 241 | } 242 | } 243 | } 244 | 245 | /** 246 | * List the remote tables. 247 | * 248 | * @throws IOException When the connection to the cluster fails. 249 | */ 250 | private void listTables() throws IOException { 251 | getTables(true); 252 | System.out.println("tables found: " + remoteTables.length); 253 | for (final HTableDescriptor d : remoteTables) { 254 | System.out.println(" " + d.getNameAsString()); 255 | } 256 | } 257 | 258 | /** 259 | * Creates a configuration from a cluster scan. 260 | * 261 | * @throws IOException When reading the remote tables fails. 262 | */ 263 | private void createConfiguration() throws IOException { 264 | if (verbose) { 265 | System.out.println("creating configuration..."); 266 | } 267 | OutputStream out = "-".equals(schemaFileName) ? System.out : new FileOutputStream(schemaFileName); 268 | PrintStream w = new PrintStream(new BufferedOutputStream(out), false, "UTF-8"); 269 | w.println(""); 270 | w.println(""); 271 | w.println(" "); 272 | w.println(" " + configName + ""); 273 | //w.println(" " + description + ""); 274 | w.println(" " + quorum + ""); 275 | if (zkPort != null) { 276 | w.println(" " + zkPort + ""); 277 | } 278 | w.println(" "); 279 | // iterate over the remote tables 280 | getTables(true); 281 | System.out.println("tables found: " + remoteTables.length); 282 | for (final HTableDescriptor d : remoteTables) { 283 | w.println(" "); 284 | w.println(" " + d.getNameAsString() + ""); 285 | //w.println(" " + tableDescription + ""); 286 | w.println(" "); 287 | w.println(" " + d.isDeferredLogFlush() + ""); 288 | w.println(" "); 289 | w.println(" " + d.getMaxFileSize() + ""); 290 | w.println(" "); 291 | w.println(" " + d.getMemStoreFlushSize() + ""); 292 | w.println(" "); 293 | w.println(" " + d.isReadOnly() + ""); 294 | for (HColumnDescriptor col : d.getColumnFamilies()) { 295 | w.println(" "); 296 | w.println(" " + col.getNameAsString() + ""); 297 | //w.println(" " + columnDescription + ""); 298 | w.println(" "); 299 | w.println(" " + col.getMaxVersions() + ""); 300 | w.println(" "); 301 | w.println(" " + col.getCompressionType() + ""); 302 | w.println(" "); 303 | w.println(" " + col.isInMemory() + ""); 304 | w.println(" "); 305 | w.println(" " + col.isBlockCacheEnabled() + ""); 306 | w.println(" "); 307 | w.println(" " + col.getBlocksize() + ""); 308 | w.println(" "); 310 | w.println(" " + col.getTimeToLive() + ""); 311 | w.println(" "); 312 | w.println(" " + col.getBloomFilterType() + ""); 313 | w.println(" "); 314 | w.println(" " + col.getScope() + ""); 315 | w.println(" "); 316 | } 317 | w.println("
"); 318 | } 319 | w.println("
"); 320 | w.println("
"); 321 | w.println("
"); 322 | w.flush(); 323 | w.close(); 324 | } 325 | 326 | 327 | /** 328 | * Creates a new HBase configuration instance. 329 | * 330 | * @return The new HBase configuration. 331 | */ 332 | private Configuration getConfiguration() { 333 | final Configuration hbaseConfig = HBaseConfiguration.create(); 334 | String master = getStringProperty("hbase_master", null); 335 | if (master != null) { 336 | hbaseConfig.set("hbase.master", master); 337 | } 338 | String q = getStringProperty("zookeeper_quorum", quorum); 339 | if (q != null) { 340 | hbaseConfig.set("hbase.zookeeper.quorum", q); 341 | } else { 342 | System.err.println("ERROR: ZooKeeper quorum not set!"); 343 | System.exit(-10); 344 | } 345 | String p = getStringProperty("zookeeper_client_port", zkPort); 346 | if (p != null) { 347 | hbaseConfig.set("hbase.zookeeper.property.clientPort", p); 348 | } 349 | if (verbose) { 350 | System.out.println("hbase.master -> " + hbaseConfig.get("hbase.master")); 351 | System.out.println("zookeeper.quorum -> " + hbaseConfig.get("hbase.zookeeper.quorum")); 352 | System.out.println("zookeeper.clientPort -> " + hbaseConfig.get("hbase.zookeeper.property.clientPort")); 353 | } 354 | return hbaseConfig; 355 | } 356 | 357 | /** 358 | * Helps addressing the correct configuration. 359 | * 360 | * @param key The key to get the value for. 361 | * @return The value or null. 362 | */ 363 | private String getStringProperty(final String key, final String defValue) { 364 | return config != null ? config.getString(configBaseKey + key, defValue) : defValue; 365 | } 366 | 367 | /** 368 | * Determines the configuration number to use. If the parameter name 369 | * is null then the first config is returned. 370 | * 371 | * @param config The configuration to search. 372 | * @param name The name to look for. 373 | * @return The matched number. 374 | */ 375 | @SuppressWarnings("rawtypes") 376 | private int getConfigurationNumber(final XMLConfiguration config, final String name) { 377 | if (name == null) { 378 | return -1; 379 | } 380 | final Object p = config.getProperty("configuration.name"); 381 | // we could get a collection or straight string based on the cardinality 382 | if (p instanceof Collection) { 383 | int n = 0; 384 | for (final Object o : (Collection) p) { 385 | if (o.toString().equalsIgnoreCase(name)) { 386 | return n; 387 | } 388 | n++; 389 | } 390 | } else if (p.toString().equalsIgnoreCase(name)) { 391 | return 0; 392 | } 393 | return -1; 394 | } 395 | 396 | /** 397 | * Creates a new table. 398 | * 399 | * @param schema The external schema describing the table. 400 | * @param createOrChange True means create table if non existent. 401 | * @return The internal table container. 402 | * @throws IOException When the table creation fails. 403 | */ 404 | private void createOrChangeTable(final TableSchema schema, final boolean createOrChange) throws IOException { 405 | HTableDescriptor desc = null; 406 | if (verbose) { 407 | System.out.println("authoritative -> " + createOrChange); 408 | } 409 | if (verbose) { 410 | System.out.println("name -> " + schema.getName()); 411 | } 412 | if (verbose) { 413 | System.out.println("tableExists -> " + tableExists(schema.getName(), false)); 414 | } 415 | if (tableExists(schema.getName(), false)) { 416 | desc = getTable(schema.getName(), false); 417 | // only check for changes if we are allowed to 418 | if (createOrChange) { 419 | System.out.println("checking table " + desc.getNameAsString() + "..."); 420 | final HTableDescriptor d = convertSchemaToDescriptor(schema); 421 | // compute differences 422 | final List modCols = new ArrayList(); 423 | for (final HColumnDescriptor cd : desc.getFamilies()) { 424 | final HColumnDescriptor cd2 = d.getFamily(cd.getName()); 425 | if (cd2 != null && !cd.equals(cd2)) { 426 | modCols.add(cd2); 427 | } 428 | } 429 | final List delCols = new ArrayList(desc.getFamilies()); 430 | delCols.removeAll(d.getFamilies()); 431 | final List addCols = new ArrayList(d.getFamilies()); 432 | addCols.removeAll(desc.getFamilies()); 433 | // check if we had a column that was changed, added or deleted, or table properties hhave changed 434 | if (modCols.size() > 0 || addCols.size() > 0 || delCols.size() > 0 || !hasSameProperties(desc, d)) { 435 | // yes, then disable table and iterate over changes 436 | System.out.println("disabling table..."); 437 | _hbaseAdmin.disableTable(schema.getName()); 438 | if (verbose) { 439 | System.out.println("table disabled"); 440 | } 441 | if (modCols.size() > 0 || addCols.size() > 0 || delCols.size() > 0) { 442 | for (final HColumnDescriptor col : modCols) { 443 | if (verbose) { 444 | System.out.println("found different column -> " + col); 445 | } 446 | _hbaseAdmin.modifyColumn(schema.getName(), col.getNameAsString(), col); 447 | } 448 | for (final HColumnDescriptor col : addCols) { 449 | if (verbose) { 450 | System.out.println("found new column -> " + col); 451 | } 452 | _hbaseAdmin.addColumn(schema.getName(), col); 453 | } 454 | for (final HColumnDescriptor col : delCols) { 455 | if (verbose) { 456 | System.out.println("found removed column -> " + col); 457 | } 458 | _hbaseAdmin.deleteColumn(schema.getName(), col.getNameAsString() + ":"); 459 | } 460 | } else if (!hasSameProperties(desc, d)) { 461 | System.out.println("found different table properties..."); 462 | _hbaseAdmin.modifyTable(Bytes.toBytes(schema.getName()), d); 463 | } 464 | // enable again and reload details 465 | System.out.println("enabling table..."); 466 | _hbaseAdmin.enableTable(schema.getName()); 467 | System.out.println("table enabled"); 468 | desc = getTable(schema.getName(), false); 469 | System.out.println("table changed"); 470 | } else { 471 | System.out.println("no changes detected!"); 472 | } 473 | } 474 | } else if (createOrChange) { 475 | desc = convertSchemaToDescriptor(schema); 476 | System.out.println("creating table " + desc.getNameAsString() + "..."); 477 | _hbaseAdmin.createTable(desc); 478 | System.out.println("table created"); 479 | } 480 | } 481 | 482 | /** 483 | * Compares the properties of two tables. 484 | * 485 | * @param desc1 The first table. 486 | * @param desc2 The second table. 487 | * @return true when the tables have the same properties. 488 | */ 489 | private boolean hasSameProperties(HTableDescriptor desc1, HTableDescriptor desc2) { 490 | return desc1.isDeferredLogFlush() == desc2.isDeferredLogFlush() && 491 | desc1.getMaxFileSize() == desc2.getMaxFileSize() && 492 | desc1.getMemStoreFlushSize() == desc2.getMemStoreFlushSize() && 493 | desc1.isReadOnly() == desc2.isReadOnly(); 494 | } 495 | 496 | /** 497 | * Converts the XML based schema to a version HBase can take natively. 498 | * 499 | * @param schema The schema with the all tables. 500 | * @return The converted schema as a HBase object. 501 | */ 502 | private HTableDescriptor convertSchemaToDescriptor(final TableSchema schema) { 503 | HTableDescriptor desc; 504 | desc = new HTableDescriptor(schema.getName()); 505 | desc.setDeferredLogFlush(schema.isDeferredLogFlush()); 506 | desc.setMaxFileSize(schema.getMaxFileSize()); 507 | desc.setMemStoreFlushSize(schema.getMemStoreFlushSize()); 508 | desc.setReadOnly(schema.isReadOnly()); 509 | final Collection cols = schema.getColumns(); 510 | for (final ColumnDefinition col : cols) { 511 | final HColumnDescriptor cd = new HColumnDescriptor(Bytes.toBytes(col.getColumnName()), col.getMaxVersions(), 512 | col.getCompression(), col.isInMemory(), col.isBlockCacheEnabled(), col.getBlockSize(), col.getTimeToLive(), 513 | col.getBloomFilter(), col.getReplicationScope()); 514 | desc.addFamily(cd); 515 | } 516 | return desc; 517 | } 518 | 519 | /** 520 | * Returns a table descriptor or null if it does not exist. 521 | * 522 | * @param name The name of the table. 523 | * @param force Force a reload of the tables from the server. 524 | * @return The table descriptor or null. 525 | * @throws IOException When the communication to HBase fails. 526 | */ 527 | private synchronized HTableDescriptor getTable(final String name, final boolean force) throws IOException { 528 | if (remoteTables == null || force) { 529 | remoteTables = _hbaseAdmin.listTables(); 530 | } 531 | for (final HTableDescriptor d : remoteTables) { 532 | if (d.getNameAsString().equals(name)) { 533 | return d; 534 | } 535 | } 536 | return null; 537 | } 538 | 539 | /** 540 | * Checks if a table exists. This is done cached so that multiple META table 541 | * scans are avoided, which would happen otherwise calling 542 | * HBaseAdmin.tableExists() directly. Scans are not fast! 543 | * 544 | * @param name The table name to check. 545 | * @param force If a remote check should be enforced. 546 | * @return true if it exists, false otherwise. 547 | * @throws IOException When reading the remote table list fails. 548 | */ 549 | private boolean tableExists(final String name, final boolean force) throws IOException { 550 | getTables(force); 551 | for (final HTableDescriptor d : remoteTables) { 552 | if (d.getNameAsString().equals(name)) { 553 | return true; 554 | } 555 | } 556 | return false; 557 | } 558 | 559 | /** 560 | * Gets the list of tables from the master. 561 | * 562 | * @param force If a remote check should be enforced. 563 | * @throws IOException When reading the remote table list fails. 564 | */ 565 | private void getTables(final boolean force) throws IOException { 566 | if (remoteTables == null || force) { 567 | remoteTables = _hbaseAdmin.listTables(); 568 | } 569 | } 570 | 571 | /** 572 | * Main method starting the processing. 573 | * 574 | * @param args The command line parameters. 575 | */ 576 | public static void main(final String[] args) { 577 | try { 578 | final HBaseManager hm = new HBaseManager(args); 579 | hm.process(); 580 | System.out.println("done."); 581 | } catch (final Exception e) { 582 | e.printStackTrace(); 583 | } 584 | } 585 | 586 | } 587 | -------------------------------------------------------------------------------- /src/main/java/com/larsgeorge/hadoop/hbase/TableSchema.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package com.larsgeorge.hadoop.hbase; 21 | 22 | import org.apache.hadoop.hbase.HTableDescriptor; 23 | 24 | import java.util.Collection; 25 | import java.util.HashMap; 26 | 27 | /** 28 | * Describes a table. 29 | * 30 | * @author Lars George 31 | */ 32 | public class TableSchema { 33 | 34 | private String name = null; 35 | private String description = null; 36 | private boolean deferredLogFlush = HTableDescriptor.DEFAULT_DEFERRED_LOG_FLUSH; 37 | private long maxFileSize = HTableDescriptor.DEFAULT_MAX_FILESIZE; 38 | private long memStoreFlushSize = HTableDescriptor.DEFAULT_MEMSTORE_FLUSH_SIZE; 39 | private boolean readOnly = false; 40 | 41 | private final HashMap columns = new HashMap(); 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public void setName(final String name) { 48 | this.name = name; 49 | } 50 | 51 | public String getDescription() { 52 | return description; 53 | } 54 | 55 | public void setDescription(final String description) { 56 | this.description = description; 57 | } 58 | 59 | public boolean isDeferredLogFlush() { 60 | return deferredLogFlush; 61 | } 62 | 63 | public void setDeferredLogFlush(boolean deferredLogFlush) { 64 | this.deferredLogFlush = deferredLogFlush; 65 | } 66 | 67 | public long getMaxFileSize() { 68 | return maxFileSize; 69 | } 70 | 71 | public void setMaxFileSize(long maxFileSize) { 72 | this.maxFileSize = maxFileSize; 73 | } 74 | 75 | public long getMemStoreFlushSize() { 76 | return memStoreFlushSize; 77 | } 78 | 79 | public void setMemStoreFlushSize(long memStoreFlushSize) { 80 | this.memStoreFlushSize = memStoreFlushSize; 81 | } 82 | 83 | public boolean isReadOnly() { 84 | return readOnly; 85 | } 86 | 87 | public void setReadOnly(boolean readOnly) { 88 | this.readOnly = readOnly; 89 | } 90 | 91 | public void addColumn(final ColumnDefinition column) { 92 | columns.put(column.getName(), column); 93 | } 94 | 95 | public Collection getColumns() { 96 | return columns.values(); 97 | } 98 | 99 | public ColumnDefinition getColumnDefinition(final String name) { 100 | return columns.get(name); 101 | } // getColumnDefinition 102 | 103 | @Override 104 | public String toString() { 105 | return "name -> " + name + "\n description -> " + description + "\n columns -> " + columns; 106 | } 107 | 108 | } // TableSchema 109 | 110 | -------------------------------------------------------------------------------- /src/main/resources/schema.xml: -------------------------------------------------------------------------------- 1 | 2 | 23 | 24 | 25 | local 26 | Configuration for the HBase cluster. 27 | localhost 28 | 2181 29 | 30 | 31 | tablename 32 | A table 33 | 50000000 34 | false 35 | 36 | columnA 37 | Column A. 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | columnB 57 | Column B. 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
76 |
77 |
78 |
79 | --------------------------------------------------------------------------------