Beispiel #1
0
    def setSegments(self, segmentData, faultStrategy):
        lines = segmentData.strip().split("\n")

        assert len(lines[1].split("+")) == len(
            lines[0].split("|"))  # verify header is listed

        self.__configurationProvider = configurationImplTest.GpConfigurationProviderForTesting(
        )
        self.__configurationProvider.setFaultStrategy(faultStrategy)
        for line in lines[2:len(lines)]:
            row = [s.strip() for s in line.strip().split("|")]

            dbId = int(row[0])
            contentId = int(row[1])
            role = row[2]
            preferredRole = row[3]
            mode = row[4]
            status = row[5]
            hostName = row[6]
            address = row[7]
            port = int(row[8])
            dataDirectory = row[9]
            replicationPort = None if row[10] == "" else int(row[10])

            segment = GpDB(content=contentId,
                           preferred_role=preferredRole,
                           dbid=dbId,
                           role=role,
                           mode=mode,
                           status=status,
                           hostname=hostName,
                           address=address,
                           port=port,
                           datadir=dataDirectory,
                           replicationPort=replicationPort)

            self.__configurationProvider.addTestSegment(segment)

        registerConfigurationProvider(self.__configurationProvider)

        self.__fileSystemProvider = fileSystemImplTest.GpFileSystemProviderForTest(
        )
        fileSystemInterface.registerFileSystemProvider(
            self.__fileSystemProvider)
        osInterface.registerOsProvider(osImplTest.GpOsProviderForTest())
        faultProberInterface.registerFaultProber(
            faultProberImplTest.GpFaultProberImplForTest())
        pass
Beispiel #2
0
    def setSegments(self, segmentData, faultStrategy):
        lines = segmentData.strip().split("\n")
        
        assert len(lines[1].split("+")) == len(lines[0].split("|")) # verify header is listed

        self.__configurationProvider = configurationImplTest.GpConfigurationProviderForTesting()
        self.__configurationProvider.setFaultStrategy(faultStrategy)
        for line in lines[2:len(lines)]:
            row = [s.strip() for s in line.strip().split("|")]


            dbId = int(row[0])
            contentId = int(row[1])
            role = row[2]
            preferredRole = row[3]
            mode = row[4]
            status = row[5]
            hostName = row[6]
            address = row[7]
            port = int(row[8])
            dataDirectory = row[9]
            replicationPort = None if row[10] == "" else int(row[10])

            segment = GpDB(content=contentId,
                           preferred_role=preferredRole,
                           dbid=dbId,
                           role=role,
                           mode=mode,
                           status=status,
                           hostname=hostName,
                           address=address,
                           port=port,
                           datadir=dataDirectory,
                           replicationPort=replicationPort)

            self.__configurationProvider.addTestSegment(segment)

        registerConfigurationProvider( self.__configurationProvider )

        self.__fileSystemProvider = fileSystemImplTest.GpFileSystemProviderForTest()
        fileSystemInterface.registerFileSystemProvider(self.__fileSystemProvider)
        osInterface.registerOsProvider(osImplTest.GpOsProviderForTest())
        faultProberInterface.registerFaultProber(faultProberImplTest.GpFaultProberImplForTest())
        pass
Beispiel #3
0
def simple_main_locked(createOptionParserFn, createCommandFn, mainOptions):
    """
    Not to be called externally -- use simple_main instead
    """
    logger = gplog.get_default_logger()

    configurationInterface.registerConfigurationProvider(
        configurationImplGpdb.GpConfigurationProviderUsingGpdbCatalog())
    fileSystemInterface.registerFileSystemProvider(
        fileSystemImplOs.GpFileSystemProviderUsingOs())
    osInterface.registerOsProvider(osImplNative.GpOsProviderUsingNative())
    faultProberInterface.registerFaultProber(
        faultProberImplGpdb.GpFaultProberImplGpdb())

    commandObject = None
    parser = None

    forceQuiet = mainOptions is not None and mainOptions.get(
        "forceQuietOutput")
    options = None

    if mainOptions is not None and mainOptions.get("programNameOverride"):
        global gProgramName
        gProgramName = mainOptions.get("programNameOverride")
    suppressStartupLogMessage = mainOptions is not None and mainOptions.get(
        "suppressStartupLogMessage")

    useHelperToolLogging = mainOptions is not None and mainOptions.get(
        "useHelperToolLogging")
    nonuser = True if mainOptions is not None and mainOptions.get(
        "setNonuserOnToolLogger") else False
    exit_status = 1

    try:
        execname = getProgramName()
        hostname = unix.getLocalHostname()
        username = unix.getUserName()

        parser = createOptionParserFn()
        (options, args) = parser.parse_args()

        if useHelperToolLogging:
            gplog.setup_helper_tool_logging(execname, hostname, username)
        else:
            gplog.setup_tool_logging(execname,
                                     hostname,
                                     username,
                                     logdir=options.ensure_value(
                                         "logfileDirectory", None),
                                     nonuser=nonuser)

        if forceQuiet:
            gplog.quiet_stdout_logging()
        else:
            if options.ensure_value("verbose", False):
                gplog.enable_verbose_logging()
            if options.ensure_value("quiet", False):
                gplog.quiet_stdout_logging()

        if options.ensure_value("masterDataDirectory", None) is not None:
            options.master_data_directory = os.path.abspath(
                options.masterDataDirectory)

        if not suppressStartupLogMessage:
            logger.info("Starting %s with args: %s" %
                        (gProgramName, ' '.join(sys.argv[1:])))

        commandObject = createCommandFn(options, args)
        exitCode = commandObject.run()
        exit_status = exitCode

    except ProgramArgumentValidationException, e:
        if e.shouldPrintHelp():
            parser.print_help()
        logger.error("%s: error: %s" % (gProgramName, e.getMessage()))
        exit_status = 2
Beispiel #4
0
def simple_main_locked(createOptionParserFn, createCommandFn, mainOptions):
    """
    Not to be called externally -- use simple_main instead
    """
    logger = gplog.get_default_logger()

    configurationInterface.registerConfigurationProvider(
        configurationImplGpdb.GpConfigurationProviderUsingGpdbCatalog())
    fileSystemInterface.registerFileSystemProvider(fileSystemImplOs.GpFileSystemProviderUsingOs())
    osInterface.registerOsProvider(osImplNative.GpOsProviderUsingNative())
    faultProberInterface.registerFaultProber(faultProberImplGpdb.GpFaultProberImplGpdb())

    commandObject = None
    parser = None

    forceQuiet = mainOptions is not None and mainOptions.get("forceQuietOutput")
    options = None

    if mainOptions is not None and mainOptions.get("programNameOverride"):
        global gProgramName
        gProgramName = mainOptions.get("programNameOverride")
    suppressStartupLogMessage = mainOptions is not None and mainOptions.get("suppressStartupLogMessage")

    useHelperToolLogging = mainOptions is not None and mainOptions.get("useHelperToolLogging")
    nonuser = True if mainOptions is not None and mainOptions.get("setNonuserOnToolLogger") else False
    exit_status = 1

    # NOTE: if this logic is changed then also change test_main in testUtils.py
    try:
        execname = getProgramName()
        hostname = unix.getLocalHostname()
        username = unix.getUserName()

        parser = createOptionParserFn()
        (options, args) = parser.parse_args()

        if useHelperToolLogging:
            gplog.setup_helper_tool_logging(execname, hostname, username)
        else:
            gplog.setup_tool_logging(execname, hostname, username,
                                     logdir=options.ensure_value("logfileDirectory", None), nonuser=nonuser)

        if forceQuiet:
            gplog.quiet_stdout_logging()
        else:
            if options.ensure_value("verbose", False):
                gplog.enable_verbose_logging()
            if options.ensure_value("quiet", False):
                gplog.quiet_stdout_logging()

        if options.ensure_value("masterDataDirectory", None) is not None:
            options.master_data_directory = os.path.abspath(options.masterDataDirectory)

        if not suppressStartupLogMessage:
            logger.info("Starting %s with args: %s" % (gProgramName, ' '.join(sys.argv[1:])))

        commandObject = createCommandFn(options, args)
        exitCode = commandObject.run()
        exit_status = exitCode

    except ProgramArgumentValidationException, e:
        if e.shouldPrintHelp():
            parser.print_help()
        logger.error("%s: error: %s" % (gProgramName, e.getMessage()))
        exit_status = 2
Beispiel #5
0
def simple_main_locked(createOptionParserFn, createCommandFn, mainOptions):
    """
    Not to be called externally -- use simple_main instead
    """
    logger = gplog.get_default_logger()

    configurationInterface.registerConfigurationProvider(
        configurationImplGpdb.GpConfigurationProviderUsingGpdbCatalog())
    fileSystemInterface.registerFileSystemProvider(fileSystemImplOs.GpFileSystemProviderUsingOs())
    osInterface.registerOsProvider(osImplNative.GpOsProviderUsingNative())
    faultProberInterface.registerFaultProber(faultProberImplGpdb.GpFaultProberImplGpdb())

    commandObject = None
    parser = None

    forceQuiet = mainOptions is not None and mainOptions.get("forceQuietOutput")
    options = None

    if mainOptions is not None and mainOptions.get("programNameOverride"):
        global gProgramName
        gProgramName = mainOptions.get("programNameOverride")
    suppressStartupLogMessage = mainOptions is not None and mainOptions.get("suppressStartupLogMessage")

    useHelperToolLogging = mainOptions is not None and mainOptions.get("useHelperToolLogging")
    nonuser = True if mainOptions is not None and mainOptions.get("setNonuserOnToolLogger") else False
    exit_status = 1

    try:
        execname = getProgramName()
        hostname = unix.getLocalHostname()
        username = unix.getUserName()

        parser = createOptionParserFn()
        (options, args) = parser.parse_args()

        if useHelperToolLogging:
            gplog.setup_helper_tool_logging(execname, hostname, username)
        else:
            gplog.setup_tool_logging(execname, hostname, username,
                                     logdir=options.ensure_value("logfileDirectory", None), nonuser=nonuser)

        if forceQuiet:
            gplog.quiet_stdout_logging()
        else:
            if options.ensure_value("verbose", False):
                gplog.enable_verbose_logging()
            if options.ensure_value("quiet", False):
                gplog.quiet_stdout_logging()

        if options.ensure_value("coordinatorDataDirectory", None) is not None:
            options.coordinator_data_directory = os.path.abspath(options.coordinatorDataDirectory)

        if not suppressStartupLogMessage:
            logger.info("Starting %s with args: %s" % (gProgramName, ' '.join(sys.argv[1:])))

        commandObject = createCommandFn(options, args)
        exitCode = commandObject.run()
        exit_status = exitCode

    except ProgramArgumentValidationException as e:
        if e.shouldPrintHelp():
            parser.print_help()
        logger.error("%s: error: %s" % (gProgramName, e.getMessage()))
        exit_status = 2
    except ExceptionNoStackTraceNeeded as e:
        logger.error("%s error: %s" % (gProgramName, e))
        exit_status = 2
    except UserAbortedException as e:
        logger.info("User abort requested, Exiting...")
        exit_status = 4
    except ExecutionError as e:
        logger.fatal("Error occurred: %s\n Command was: '%s'\n"
                     "rc=%d, stdout='%s', stderr='%s'" % \
                     (e.summary, e.cmd.cmdStr, e.cmd.results.rc, e.cmd.results.stdout,
                      e.cmd.results.stderr))
        exit_status = 2
    except Exception as e:
        if options is None:
            logger.exception("%s failed.  exiting...", gProgramName)
        else:
            if options.ensure_value("verbose", False):
                logger.exception("%s failed.  exiting...", gProgramName)
            else:
                logger.fatal("%s failed. (Reason='%s') exiting..." % (gProgramName, e))
        exit_status = 2
    except KeyboardInterrupt:
        exit_status = 2
    finally:
        if commandObject:
            commandObject.cleanup()
    sys.exit(exit_status)