Example #1
0
 def getZooLogDir(cls, logoutput=False):
     '''
 Returns Zookeeper log directory (String).
 '''
     matchObjList = None
     if Machine.isHumboldt():
         try:
             from beaver.component.hbase import HBase
             #get some zookeeper node
             hmaster_nodes = HBase.getAllMasterNodes()
             if hmaster_nodes:
                 zkNode = hmaster_nodes[0]
             if zkNode:
                 Machine.copyToLocal(None, zkNode, ZOOKEEPER_ENV_FILE,
                                     Machine.getTempDir())
                 REMOTE_ZOOKEEPER_ENV_FILE = os.path.join(
                     Machine.getTempDir(), 'zookeeper-env.sh')
                 matchObjList = util.findMatchingPatternInFile(
                     REMOTE_ZOOKEEPER_ENV_FILE,
                     "export ZOO_LOG_DIR=(.*)",
                     return0Or1=False)
         except Exception:
             pass
     if not matchObjList:
         #gateway should have the config file.
         matchObjList = util.findMatchingPatternInFile(
             ZOOKEEPER_ENV_FILE,
             "export ZOO_LOG_DIR=(.*)",
             return0Or1=False)
     returnValue = None
     if matchObjList:
         returnValue = matchObjList[0].group(1)
     if logoutput:
         logger.info("Zookeeper.getZooLogDir returns %s", returnValue)
     return returnValue
Example #2
0
    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)