Open Kilda Java Documentation
create_tables.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # Copyright 2017 Telstra Open Source
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 
17 
18 import happybase
19 import sys
20 
21 host = 'hbase.pendev'
22 port = 9090
23 
24 new_tables = ['tsdb', 'tsdb-uid', 'tsdb-tree', 'tsdb-meta']
25 
26 connection = happybase.Connection(host=host, port=port)
27 existing_tables = connection.tables()
28 
29 
30 def create_table(table):
31  if (table == 'tsdb') or (table == 'tsdb-tree'):
32  families = {'t': dict(max_versions=1, compression='none',
33  bloom_filter_type='ROW')}
34  elif table == 'tsdb-uid':
35  families = {'id': dict(compression='none', bloom_filter_type='ROW'),
36  'name': dict(compression='none', bloom_filter_type='ROW')}
37  elif table == 'tsdb-meta':
38  families = {'name': dict(compression='none', bloom_filter_type='ROW')}
39  else:
40  sys.exit("Unknown table {} was requested.".format(table))
41 
42  print "Creating {}".format(table)
43  connection.create_table(table, families)
44  if table not in connection.tables():
45  sys.exit("Could not create {}".format(table))
46 
47 
48 for table in new_tables[:]:
49  if table in existing_tables:
50  print "{} exist".format(table)
51  new_tables.remove(table)
52 
53 if len(new_tables) > 0:
54  for table in new_tables:
55  create_table(table)
56 else:
57  print "All OpenTSDB tables already created"
def create_table(table)