This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
/
DiffScriptGenerationTestResultD.rb
137 lines (123 loc) · 5.96 KB
/
DiffScriptGenerationTestResultD.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
###############################################################################
# HBase Schema Update Script
#
# Summary:
#
# * Create 0 tables.
#
# * Alter 0 tables.
#
# * Drop 1 table:
# createMe
#
# * Ignore 0 tables.
###############################################################################
###############################################################################
# Initialization
###############################################################################
include Java
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.HColumnDescriptor
import org.apache.hadoop.hbase.HConstants
import org.apache.hadoop.hbase.HTableDescriptor
import org.apache.hadoop.hbase.client.HBaseAdmin
import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.util.Bytes
conf = HBaseConfiguration.new
admin = HBaseAdmin.new(conf)
preErrors = Array.new
preWarnings = Array.new
postErrors = Array.new
###############################################################################
# Utility methods
###############################################################################
def compare(errs, obj, action, attr, val)
if (obj.getValue(attr).to_s != val)
errs << "Object '#{obj.getNameAsString()}', which is targeted for #{action} by this script, should have had a value of \"#{val}\" for #{attr}, but it was \"#{obj.getValue(attr)}\" instead.\n"
end
end
###############################################################################
# Pre Validation
#
# This step makes sure that the existing schema on the cluster matches what you
# think should be there. It will emit warnings for problems that won't make the
# script fail; it will emit errors and exit if it encounters any problems that
# will make the script fail.
###############################################################################
# Table 'createMe' should exist
tablename = "createMe"
if !admin.tableExists(tablename)
preErrors << "Table '#{tablename}' should exist, but it does not.\n"
end
# Table 'createMe' will warn if it doesn't match the expected definition.
if admin.tableExists(tablename)
table = admin.getTableDescriptor(tablename.bytes.to_a)
compare(preWarnings, table, "drop", "DEFERRED_LOG_FLUSH", "false")
compare(preWarnings, table, "drop", "IS_META", "false")
compare(preWarnings, table, "drop", "IS_ROOT", "false")
compare(preWarnings, table, "drop", "MAX_FILESIZE", "268435456")
compare(preWarnings, table, "drop", "MEMSTORE_FLUSHSIZE", "67108864")
compare(preWarnings, table, "drop", "OWNER", "ivarley")
compare(preWarnings, table, "drop", "READONLY", "false")
compare(preWarnings, table, "drop", "fullSchema", "<table isReadOnly=\"false\" maxFileSizeMB=\"256\" memStoreFlushSizeMB=\"64\" name=\"createMe\" owner=\"ivarley\" useDeferredLogFlush=\"false\"><key><keyPart inverted=\"false\" length=\"15\" name=\"createMeKeyPart1\" type=\"String\"/><keyPart inverted=\"true\" length=\"15\" name=\"createMeKeyPart2\" type=\"Timestamp\"/></key><columnFamilies><columnFamily blockCache=\"true\" blockSizeKB=\"64\" bloomFilter=\"NONE\" inMemory=\"false\" maxVersions=\"3\" name=\"createMeColumnFamily1\" replicationScope=\"0\" timeToLiveMS=\"2147483647\"><column name=\"createMeColumn1\" type=\"String\"/><column name=\"createMeColumn2\" type=\"Timestamp\"/><column name=\"createMeColumn3\" type=\"Byte\"/></columnFamily></columnFamilies></table>")
# Column family: createMeColumnFamily1
cfname = "createMeColumnFamily1"
cf = table.getFamily(cfname.bytes.to_a)
compare(preWarnings, cf, "drop", "BLOCKCACHE", "true")
compare(preWarnings, cf, "drop", "BLOCKSIZE", "65536")
compare(preWarnings, cf, "drop", "BLOOMFILTER", "NONE")
compare(preWarnings, cf, "drop", "COMPRESSION", "NONE")
compare(preWarnings, cf, "drop", "DATA_BLOCK_ENCODING", "NONE")
compare(preWarnings, cf, "drop", "ENCODE_ON_DISK", "true")
compare(preWarnings, cf, "drop", "IN_MEMORY", "false")
compare(preWarnings, cf, "drop", "KEEP_DELETED_CELLS", "false")
compare(preWarnings, cf, "drop", "MIN_VERSIONS", "0")
compare(preWarnings, cf, "drop", "REPLICATION_SCOPE", "0")
compare(preWarnings, cf, "drop", "TTL", "2147483647")
compare(preWarnings, cf, "drop", "VERSIONS", "3")
end
# If any pre-validations had errors, report them and exit the script.
if (preErrors.length > 0)
puts "There were #{preErrors.length} error(s) and #{preWarnings.length} warning(s) during table pre-validation:"
print "#{preErrors.collect{|msg| "Error: " + msg}}"
print "#{preWarnings.collect{|msg| "Warning: " + msg}}"
raise
exit
elsif (preWarnings.length > 0)
puts "Pre-validations successful with #{preWarnings.length} warnings:"
print "#{preWarnings.collect{|msg| "Warning: " + msg}}"
else
puts "Pre-validations successful."
end
###############################################################################
# Modifications
#
# This step actually modifies the schema on the cluster.
###############################################################################
# Drop Table: createMe
tablename = "createMe"
table = HTableDescriptor.new(tablename)
if admin.tableExists(tablename)
if admin.isTableEnabled(tablename)
puts "Disabling table '#{tablename}' prior to dropping it ..."
admin.disableTable(tablename)
end
puts "Dropping table '#{tablename}' ..."
admin.deleteTable(tablename)
end
puts "Dropped table '#{tablename}'"
puts "Table creations & modifications successful."
###############################################################################
# Post Validation
#
# This step ensures that changes were successful, and that the resulting schema
# on the cluster matches what you want to be there.
###############################################################################
# Table 'createMe' should not exist
tablename = "createMe"
if admin.tableExists(tablename)
preErrors << "Table '#{tablename}' should not already exist, but it does.\n"
end
puts "Post-validation successful."
puts "Script complete. Share and enjoy."
exit