Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update to work with alternate rake file

  • Loading branch information...
commit 2bce6bb6a24f5277a2dfcc523b6286a73bb08075 1 parent 0c3e3e9
@mudphone mudphone authored
View
44 lib/hbase_migrations/hbase_admin.rb
@@ -1,4 +1,24 @@
+module HbaseCommandConstants
+ COLUMN = "COLUMN"
+ COLUMNS = "COLUMNS"
+ TIMESTAMP = "TIMESTAMP"
+ NAME = org.apache.hadoop.hbase.HConstants::NAME
+ VERSIONS = org.apache.hadoop.hbase.HConstants::VERSIONS
+ IN_MEMORY = org.apache.hadoop.hbase.HConstants::IN_MEMORY
+ STOPROW = "STOPROW"
+ STARTROW = "STARTROW"
+ ENDROW = STOPROW
+ LIMIT = "LIMIT"
+ METHOD = "METHOD"
+ MAXLENGTH = "MAXLENGTH"
+ CACHE_BLOCKS = "CACHE_BLOCKS"
+
+ include_class Java::org.apache.hadoop.hbase.HColumnDescriptor
+end
+
class HbaseAdmin
+ include HbaseCommandConstants
+
attr_reader :configuration
def initialize(server)
@@ -120,4 +140,28 @@ def makeColumnName(arg)
arg
end
+ def hcd(arg)
+ # Return a new HColumnDescriptor made of passed args
+ # TODO: This is brittle code.
+ # Here is current HCD constructor:
+ # public HColumnDescriptor(final byte [] familyName, final int maxVersions,
+ # final String compression, final boolean inMemory,
+ # final boolean blockCacheEnabled, final int blocksize,
+ # final int maxValueLength,
+ # final int timeToLive, final boolean bloomFilter) {
+ name = arg[NAME]
+ raise ArgumentError.new("Column family " + arg + " must have a name") unless name
+ name = makeColumnName(name)
+ # TODO: What encoding are Strings in jruby?
+ return HColumnDescriptor.new(name.to_java_bytes,
+ # JRuby uses longs for ints. Need to convert. Also constants are String
+ arg[VERSIONS]? JInteger.new(arg[VERSIONS]): HColumnDescriptor::DEFAULT_VERSIONS,
+ arg[HColumnDescriptor::COMPRESSION]? arg[HColumnDescriptor::COMPRESSION]: HColumnDescriptor::DEFAULT_COMPRESSION,
+ arg[IN_MEMORY]? JBoolean.valueOf(arg[IN_MEMORY]): HColumnDescriptor::DEFAULT_IN_MEMORY,
+ arg[HColumnDescriptor::BLOCKCACHE]? JBoolean.valueOf(arg[HColumnDescriptor::BLOCKCACHE]): HColumnDescriptor::DEFAULT_BLOCKCACHE,
+ arg[HColumnDescriptor::BLOCKSIZE]? JInteger.valueOf(arg[HColumnDescriptor::BLOCKSIZE]): HColumnDescriptor::DEFAULT_BLOCKSIZE,
+ arg[HColumnDescriptor::TTL]? JInteger.new(arg[HColumnDescriptor::TTL]): HColumnDescriptor::DEFAULT_TTL,
+ arg[HColumnDescriptor::BLOOMFILTER]? JBoolean.valueOf(arg[HColumnDescriptor::BLOOMFILTER]): HColumnDescriptor::DEFAULT_BLOOMFILTER)
+ end
+
end
View
2  lib/hbase_migrations/hbase_connection.rb
@@ -18,7 +18,7 @@ def update_schema_version(user,env,new_version)
end
def initialize_schema_information(user,env)
- admin = HbaseAdmin.new(@server)
+ admin = HbaseAdmin.new(@server)
admin.create('schema_versions','version') unless admin.exists('schema_versions')
table = HbaseTable.new(@configuration,'schema_versions')
View
3  lib/hbase_migrations/migration.rb
@@ -18,7 +18,8 @@ def initialize(name)
class Migration
extend HbaseCommands
-
+ include HbaseCommandConstants
+
@@verbose = true
class << self
View
10 lib/hbase_migrations/migrator.rb
@@ -44,13 +44,18 @@ def current_version
end
def migrate
+ puts "start of migration"
+
migration_classes.each do |migration_class|
- if reached_target_version?(migration_class.version)
+ if reached_target_version?(migration_class.version)
+ puts "reached target version"
break
end
+ puts "check for relevance"
next if irrelevant_migration?(migration_class.version)
+ puts "migration..."
migration_class.migrate(@direction)
set_schema_version(migration_class.version)
end
@@ -80,6 +85,7 @@ def assert_unique_migration_version(migrations, version)
end
def migration_files
+ puts "migrations_path: #{@migrations_path}"
files = Dir["#{@migrations_path}/[0-9]*_*.rb"].sort_by do |f|
m = migration_version_and_name(f)
raise IllegalMigrationNameError.new(f) unless m
@@ -125,4 +131,4 @@ def irrelevant_migration?(version)
end
end
-end
+end
View
8 tasks/databases.rake
@@ -1,9 +1,11 @@
namespace :hbase do
+ MIGRATE_DIR = "hbase/migrate/"
+
desc "Migrate the hbase through scripts in hb/migrate. Target specific version with VERSION=x. "
task :migrate => :check do
HbaseMigrations::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
- HbaseMigrations::Migrator.migrate("hbase/migrate/",
+ HbaseMigrations::Migrator.migrate(MIGRATE_DIR,
server,
ENV["USER"],
ENV["ENV"],
@@ -14,7 +16,7 @@ namespace :hbase do
task :rollback => :check do
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
version = HbaseMigrations::Migrator.current_version(server,ENV["USER"], ENV["ENV"]) - step
- HbaseMigrations::Migrator.migrate('hb/migrate/', server, ENV["USER"], ENV["ENV"] , version)
+ HbaseMigrations::Migrator.migrate(MIGRATE_DIR, server, ENV["USER"], ENV["ENV"] , version)
end
desc "Retrieves the current schema version number"
@@ -24,7 +26,7 @@ namespace :hbase do
desc "Raises an error if there are pending migrations"
task :abort_if_pending_migrations => :check do
- pending_migrations = HbaseMigrations::Migrator.new(:up, 'hb/migrate', server, ENV["USER"], ENV["ENV"]).pending_migrations
+ pending_migrations = HbaseMigrations::Migrator.new(:up, MIGRATE_DIR, server, ENV["USER"], ENV["ENV"]).pending_migrations
if pending_migrations.any?
puts "You have #{pending_migrations.size} pending migrations:"
Please sign in to comment.
Something went wrong with that request. Please try again.