def verifySchemaFunctionality(cls): ''' We verify that the system can operate with SCHEMA functionality. ''' from beaver.component.phoenix import Phoenix from beaver.component.hbase import HBase from beaver.component.rollingupgrade.ruUpgrade import UpgradePerNode HBASE_HOME = Config.get('hbase', 'HBASE_HOME') HBASE_CONF_DIR = os.path.join(HBASE_HOME, "conf") #We verify the schema functionality. HBASE_CHANGES = {} HBASE_CHANGES['hbase-site.xml'] = {} HBASE_CHANGES['hbase-site.xml'][ 'phoenix.schema.isNamespaceMappingEnabled'] = 'true' HBASE_CHANGES['hbase-site.xml'][ 'phoenix.schema.mapSystemTablesToNamespace'] = 'true' TEST_TABLE_A = 'Table_A' SCHEMA_1 = 'SCHEMA_1' masterNodes = HBase.getAllMasterNodes() regionNodes = HBase.getRegionServers() hbase_allnodes = masterNodes + regionNodes gateway_node = Machine.getfqdn() if gateway_node not in hbase_allnodes: hbase_allnodes.append(gateway_node) HBase.stopHBaseCluster() HBase.modifyConfig(changes=HBASE_CHANGES, nodeSelection={'nodes': hbase_allnodes}) util.copy_back_to_original_config(HBase.getModifiedConfigPath(), HBASE_CONF_DIR, file_list=["hbase-site.xml"], node_list=hbase_allnodes) HBase.startHBaseCluster(HBase.getModifiedConfigPath()) #We grant permissions to all tables. Phoenix.grantPermissionsToSystemTables(schemaFunctionalityEnabled=True) #We check that we can still query the original table. cls.verifyBasicTable() #We check that we can create/query schemas. exit_code, stdout = Phoenix.runSQLLineCmds( 'CREATE SCHEMA IF NOT EXISTS %s;' % SCHEMA_1) if exit_code != 0: UpgradePerNode.reportProgress( "[FAILED][PHOENIX][Smoke] Creation of schema %s failed due to exitcode = %s " % (SCHEMA_1, exit_code)) else: UpgradePerNode.reportProgress( "[PASSED][PHOENIX][Smoke] Schema creation %s succeeded." % (SCHEMA_1)) #we create tables inside that schema primaryKey = {'name': 'ID', 'type': 'BIGINT'} columns = [{ 'name': 'FirstName', 'type': 'VARCHAR(30)' }, { 'name': 'SecondName', 'type': 'VARCHAR(30)' }, { 'name': 'City', 'type': 'VARCHAR(30)' }] exit_code, stdout = Phoenix.createTable(SCHEMA_1 + '.' + TEST_TABLE_A, primaryKey, columns) if exit_code != 0: UpgradePerNode.reportProgress( "[FAILED][PHOENIX][Smoke] Table creation %s on schema %s failed due to exitcode = %s " % (TEST_TABLE_A, SCHEMA_1, exit_code)) else: UpgradePerNode.reportProgress( "[PASSED][PHOENIX][Smoke] Table creation %s on schema %s succeeded." % (TEST_TABLE_A, SCHEMA_1)) #We insert some data into the table through upsert. for i in range(0, 5): exit_code, stdout = Phoenix.runSQLLineCmds( 'UPSERT INTO %s VALUES (%s, "name_%s","secondName_%s","city_%s");' % (SCHEMA_1 + '.' + TEST_TABLE_A, str(i), str(i), str(i), str(i))) if exit_code != 0: UpgradePerNode.reportProgress( "[FAILED][PHOENIX][Smoke] Table UPSERT %s on schema %s failed due to exitcode = %s " % (TEST_TABLE_A, SCHEMA_1, exit_code)) else: UpgradePerNode.reportProgress( "[PASSED][PHOENIX][Smoke] Table UPSERT %s on schema %s succeeded." % (TEST_TABLE_A, SCHEMA_1)) #We verify that the data has been correctly inserted exit_code, stdout = Phoenix.runSQLLineCmds( 'SELECT * FROM %s WHERE ID=3;' % (SCHEMA_1 + '.' + TEST_TABLE_A)) if exit_code != 0: UpgradePerNode.reportProgress( "[FAILED][PHOENIX][Smoke] Table SELECT %s on schema %s failed due to exitcode = %s " % (TEST_TABLE_A, SCHEMA_1, exit_code)) else: UpgradePerNode.reportProgress( "[PASSED][PHOENIX][Smoke] Table SELECT %s on schema %s succeeded." % (TEST_TABLE_A, SCHEMA_1)) if stdout.find('name_3') == -1 or stdout.find( 'secondName_3') == -1 or stdout.find('city_3') == -1: UpgradePerNode.reportProgress( "[FAILED][PHOENIX][Smoke] Table SELECT %s on schema %s returned the wrong results: %s" % (TEST_TABLE_A, SCHEMA_1, stdout)) else: UpgradePerNode.reportProgress( "[PASSED][PHOENIX][Smoke] Table SELECT %s on schema %s succeeded." % (TEST_TABLE_A, SCHEMA_1)) #We verify that we can drop the schemas with tables on it. exit_code, stdout = Phoenix.runSQLLineCmds('DROP SCHEMA %s;' % SCHEMA_1) if exit_code != 0: UpgradePerNode.reportProgress( "[FAILED][PHOENIX][Smoke] Schema drop failed due to exitcode = %s " % (exit_code)) else: UpgradePerNode.reportProgress( "[PASSED][PHOENIX][Smoke] Schema drop succeeded.") #We verify that the schema has been dropped. exit_code, stdout = Phoenix.runSQLLineCmds( 'SELECT TABLE_NAME FROM SYSTEM.CATALOG WHERE SCHEMA = %s' % SCHEMA_1, outputFormat='xmlattr') if exit_code != 0: UpgradePerNode.reportProgress( "[FAILED][PHOENIX][Smoke] Schema drop failed due to exitcode = %s " % (exit_code)) else: UpgradePerNode.reportProgress( "[PASSED][PHOENIX][Smoke] Schema drop succeeded.") if stdout.find(TEST_TABLE_A) != 0: UpgradePerNode.reportProgress( "[FAILED][PHOENIX][Smoke] Table %s did not drop on drop schema command " % (TEST_TABLE_A)) else: UpgradePerNode.reportProgress( "[PASSED][PHOENIX][Smoke] Table %s successfuly dropped." % TEST_TABLE_A)
from beaver.component.slider import Slider logger = logging.getLogger(__name__) CWD = os.path.dirname(os.path.realpath(__file__)) HADOOPQA_USER = Config.get('hadoop', 'HADOOPQA_USER') ARTIFACTS_DIR = Config.getEnv("ARTIFACTS_DIR") INPUT_FILE = 'inputFile' PHOENIX_HOME = Config.get('phoenix', 'PHOENIX_HOME') SQLLINE_SCRIPT = os.path.join('.', 'sqlline.py') SQLLINE_THIN_SCRIPT = '/usr/bin/phoenix-sqlline-thin' PSQL_SCRIPT = os.path.join('.', 'psql.py') HBASE_LIB_DIR = os.path.join(Config.get('hbase', 'HBASE_HOME'), 'lib') HBASE_CONF_DIR = HBase.getModifiedConfigPath() if HBASE_CONF_DIR is None or HBASE_CONF_DIR == '' or not os.path.exists( HBASE_CONF_DIR): HBASE_CONF_DIR = Config.get('hbase', 'HBASE_CONF_DIR') HADOOP_CMD = Config.get('hadoop', 'HADOOP_CMD') HBASE_USER = None if Hadoop.isSecure(): HBASE_USER = Config.get('hbase', 'HBASE_USER') HOST = Machine.getfqdn() ZK_HOST = util.getPropertyValueFromConfigXMLFile( os.path.join(HBASE_CONF_DIR, 'hbase-site.xml'), "hbase.zookeeper.quorum").split(',')[0] ZK_PORT = util.getPropertyValueFromConfigXMLFile(