Ejemplo n.º 1
0
    def __checkOsUser(self):
        """
        function: Check if user exists and get $GAUSSHOME
        input : NA
        output: NA
        """
        if not self.cleanUser:
            self.logger.log("Skipping user check. ")
            return

        self.logger.log("Checking OS user.")
        try:
            DefaultValue.checkUser(self.user, False)
        except Exception as e:
            raise Exception(str(e))

        # Get GAUSSHOME
        cmd = "echo $GAUSSHOME 2>/dev/null"
        (status, output) = subprocess.getstatusoutput(cmd)
        if (status != 0):
            self.logger.debug("The cmd is %s " % cmd)
            raise Exception(ErrorCode.GAUSS_518["GAUSS_51802"] % "$GAUSSHOME" +
                            " Error:\n%s" % output)

        gaussHome = output.strip()
        if (gaussHome == ""):
            raise Exception(ErrorCode.GAUSS_518["GAUSS_51800"] % "$GAUSSHOME")

        if (gaussHome != self.installPath):
            self.logger.debug("$GAUSSHOME: %s." % gaussHome)
            self.logger.debug("Installation path parameter: %s." %
                              self.installPath)
            raise Exception(ErrorCode.GAUSS_518["GAUSS_51807"])
        self.logger.log("Successfully checked OS user.")
Ejemplo n.º 2
0
def checkUserExist():
    """
    function: check user exists
    input : NA
    output: NA
    """
    if (g_clusterUser == ""):
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % "U" + ".")
    DefaultValue.checkUser(g_clusterUser, False)
Ejemplo n.º 3
0
 def checkEnv(self):
     """
     function: check if GAUSS_ENV is 2
     input : NA
     output: NA
     """
     try:
         DefaultValue.checkUser(self.user)
     except Exception as e:
         self.logger.exitWithError(str(e))
Ejemplo n.º 4
0
def main():
    """
    function: main function
    input : NA
    output: NA
    """
    try:
        opts, args = getopt.getopt(sys.argv[1:], "U:C:D:i:l:h", ["help"])
    except Exception as e:
        usage()
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e))

    if (len(args) > 0):
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] %
                               str(args[0]))

    logFile = ""
    dataParams = []
    instanceIds = []

    for (key, value) in opts:
        if (key == "-h" or key == "--help"):
            usage()
            sys.exit(0)
        elif (key == "-U"):
            clusterUser = value
        elif (key == "-D"):
            dataParams.append(value)
        elif (key == "-l"):
            logFile = os.path.realpath(value)
        elif (key == "-i"):
            if (value.isdigit()):
                instanceIds.append(int(value))
            else:
                GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] %
                                       "i")

        Parameter.checkParaVaild(key, value)

    # check if user exist and is the right user
    DefaultValue.checkUser(clusterUser)

    # check log dir
    if (logFile == ""):
        logFile = DefaultValue.getOMLogPath(DefaultValue.LOCAL_LOG_FILE,
                                            clusterUser, "", "")

    try:
        checker = CheckNodeEnv(logFile, clusterUser, dataParams, instanceIds)
        checker.run()

        sys.exit(0)
    except Exception as e:
        GaussLog.exitWithError(str(e))
Ejemplo n.º 5
0
def checkParameter():
    """
    """
    # check if user exist and is the right user
    if (g_opts.clusterUser == ""):
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".")
    try:
        DefaultValue.checkUser(g_opts.clusterUser, False)
    except Exception as e:
        GaussLog.exitWithError(str(e))

    if (g_opts.logFile == ""):
        g_opts.logFile = DefaultValue.getOMLogPath(DefaultValue.LOCAL_LOG_FILE,
                                                   g_opts.clusterUser, "")

    for param in g_opts.dbInitParams:
        if (__checkInitdbParams(param.strip()) != 0):
            GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % param)
def checkParameter():
    """
    function: Check parameter from command line
    input : NA
    output: NA
    """
    # check if user exist and is the right user
    DefaultValue.checkUser(g_opts.user)
    # check log file
    if (g_opts.logFile == ""):
        g_opts.logFile = DefaultValue.getOMLogPath(DefaultValue.LOCAL_LOG_FILE,
                                                   g_opts.user, "")
    # check if absolute path
    if (not os.path.isabs(g_opts.logFile)):
        GaussLog.exitWithError(ErrorCode.GAUSS_502["GAUSS_50213"] % "log")
    # check if installed SSD
    if not DefaultValue.checkSSDInstalled():
        GaussLog.exitWithError(ErrorCode.GAUSS_530["GAUSS_53008"])
Ejemplo n.º 7
0
    def __checkParameters(self):
        """
        function: Check parameter from command line
        input : NA
        output: NA
        """
        try:
            opts, args = getopt.getopt(sys.argv[1:], "U:l:", ["help"])
        except getopt.GetoptError as e:
            GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e))

        if (len(args) > 0):
            GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] %
                                   str(args[0]))

        logFile = ""
        for key, value in opts:
            if (key == "-U"):
                self.user = value
            elif (key == "-l"):
                logFile = value
            elif (key == "--help"):
                self.usage()
                sys.exit(0)
            else:
                GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] %
                                       key)

            Parameter.checkParaVaild(key, value)

        if (self.user == ""):
            GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' +
                                   ".")
        try:
            DefaultValue.checkUser(self.user, False)
        except Exception as e:
            GaussLog.exitWithError(str(e))

        if (logFile == ""):
            logFile = DefaultValue.getOMLogPath(DefaultValue.LOCAL_LOG_FILE,
                                                self.user, "")

        self.logger = GaussLog(logFile, "CleanOsUser")
        self.logger.ignoreErr = True
    def getDnPeerInstance(self, user):
        """  
        function :  Get the Peer instance of DN
        input : user
        output : Idlist
        """
        global g_clusterInfo
        global g_instanceInfo
        global g_clusterInfoInitialized
        if not g_clusterInfoInitialized:
            DefaultValue.checkUser(user)
            g_clusterInfo = dbClusterInfo()
            g_clusterInfo.initFromStaticConfig(user)
            g_clusterInfoInitialized = True
        dbNode = g_clusterInfo.getDbNodeByName(self.name)
        Idlist = {}
        for dnInst in self.datanodes:
            # get the instance info
            g_instanceInfo = None
            for instInfo in dbNode.datanodes:
                if instInfo.instanceId == dnInst.instanceId:
                    g_instanceInfo = instInfo
                    break
            if not g_instanceInfo:
                raise Exception(ErrorCode.GAUSS_516["GAUSS_51620"] % "DN")

            # construct the instance name
            peerInsts = g_clusterInfo.getPeerInstance(g_instanceInfo)
            if (len(peerInsts) != 2 and len(peerInsts) != 1):
                raise Exception(ErrorCode.GAUSS_516["GAUSS_51603"] %
                                g_instanceInfo.datadir)

            dnMasterInst = None
            dnStandbyInst = None
            if (g_instanceInfo.instanceType == MASTER_INSTANCE):
                dnMasterInst = g_instanceInfo
                for instIndex in range(len(peerInsts)):
                    if (peerInsts[instIndex].instanceType == STANDBY_INSTANCE):
                        dnStandbyInst = peerInsts[instIndex]
                        Idlist[dnMasterInst.instanceId] = \
                            dnStandbyInst.instanceId
        return Idlist
Ejemplo n.º 9
0
def checkParameter():
    """
    function: checkParameter
    input: NA
    output: NA
    """
    # check if user exist and is the right user
    if (g_opts.clusterUser == ""):
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".")
    DefaultValue.checkUser(g_opts.clusterUser)

    if (g_opts.configType
            not in [CONFIG_ALL_FILE, CONFIG_GS_FILE, CONFIG_PG_FILE]):
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % 'T' +
                               " Value: %s." % g_opts.configType)

    if (g_opts.logFile == ""):
        g_opts.logFile = DefaultValue.getOMLogPath(DefaultValue.LOCAL_LOG_FILE,
                                                   g_opts.clusterUser, "")

    if (g_opts.alarmComponent == ""):
        g_opts.alarmComponent = DefaultValue.ALARM_COMPONENT_PATH
Ejemplo n.º 10
0
def checkParameter():
    """
    function: check parameter for different action
    input : NA
    output: NA
    """

    # check if user exist and is the right user
    if (g_opts.user != ''):
        DefaultValue.checkUser(g_opts.user)
        tmpDir = DefaultValue.getTmpDirFromEnv(g_opts.user)
        if (not os.path.exists(tmpDir)):
            GaussLog.exitWithError(ErrorCode.GAUSS_502["GAUSS_50201"]
                                   % ("temporary directory[" + tmpDir + "]"))

    # check the -t parameter
    if (g_opts.action == ""):
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 't' + '.')
    if (g_opts.action not in list(actioItemMap.keys())):
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % "t")

    if (g_opts.logFile == ""):
        dirName = os.path.dirname(os.path.realpath(__file__))
        g_opts.logFile = os.path.join(dirName, "gaussdb_localcheck.log")
def main():
    """
    function: main function:
              1.parse parameter
              2.check $GAUSS_ENV
    input : NA
    output: NA
    """
    try:
        (opts, args) = getopt.getopt(sys.argv[1:], "U:h:t:", ["help"])
    except Exception as e:
        usage()
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e))

    if (len(args) > 0):
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] %
                               str(args[0]))

    DBUser = ""
    checkInstall = "preinstall"
    for (key, value) in opts:
        if (key == "-h" or key == "--help"):
            usage()
            sys.exit(0)
        elif (key == "-U"):
            DBUser = value
        elif (key == "-t"):
            checkInstall = value
        else:
            GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key)
        # check para vaild
        Parameter.checkParaVaild(key, value)

    # check user
    if (DBUser == ""):
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".")

    try:
        execUser = pwd.getpwuid(os.getuid()).pw_name
        if (execUser != DBUser):
            GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % "U")
        # Check if user exists and if is the right user
        DefaultValue.checkUser(DBUser, False)
    except Exception as e:
        GaussLog.exitWithError(str(e))
    # check if have done preinstall for this user
    cmd = "echo $GAUSS_ENV 2>/dev/null"
    (status, output) = subprocess.getstatusoutput(cmd)
    if (status != 0):
        GaussLog.exitWithError(ErrorCode.GAUSS_518["GAUSS_51802"] %
                               "GAUSS_ENV")
    if checkInstall == "preinstall":
        if (output.strip() == PREINSTALL_FLAG
                or output.strip() == INSTALL_FLAG):
            GaussLog.printMessage("Successfully checked GAUSS_ENV.")
            sys.exit(0)
        else:
            GaussLog.exitWithError(ErrorCode.GAUSS_518["GAUSS_51805"] %
                                   "GAUSS_ENV")
    elif checkInstall == "install" and output.strip() == INSTALL_FLAG:
        GaussLog.exitWithError(ErrorCode.GAUSS_518["GAUSS_51806"])
    def outputNodeStatus(self, stdout, user, showDetail=False):
        """  
        function :  output the status of node
        input : stdout, user
        output : NA
        """
        global g_clusterInfo
        global g_instanceInfo
        global g_clusterInfoInitialized
        if not g_clusterInfoInitialized:
            DefaultValue.checkUser(user)
            g_clusterInfo = dbClusterInfo()
            g_clusterInfo.initFromStaticConfig(user)
            g_clusterInfoInitialized = True
        dbNode = g_clusterInfo.getDbNodeByName(self.name)
        instName = ""
        # print node information
        print("%-20s: %s" % ("node", str(self.id)), file=stdout)
        print("%-20s: %s" % ("node_name", self.name), file=stdout)
        if (self.isNodeHealthy()):
            print("%-20s: %s\n" %
                  ("node_state", DbClusterStatus.OM_NODE_STATUS_NORMAL),
                  file=stdout)
        else:
            print("%-20s: %s\n" %
                  ("node_state", DbClusterStatus.OM_NODE_STATUS_ABNORMAL),
                  file=stdout)

        if (not showDetail):
            return

        # coordinator status
        for inst in self.coordinators:
            # get the instance info
            g_instanceInfo = None
            for instInfo in dbNode.coordinators:
                if instInfo.instanceId == inst.instanceId:
                    g_instanceInfo = instInfo
                    break
            if not g_instanceInfo:
                raise Exception(ErrorCode.GAUSS_516["GAUSS_51620"] % "CN")
            # construct the instance name
            instName = "cn_%s" % g_instanceInfo.instanceId
            # print CN instance information
            print("Coordinator", file=stdout)
            print("%-20s: %d" % ("    node", inst.nodeId), file=stdout)
            print("%-20s: %s" % ("    instance_name", instName), file=stdout)
            print("%-20s: %s" % ("    listen_IP", g_instanceInfo.listenIps),
                  file=stdout)
            print("%-20s: %d" % ("    port", g_instanceInfo.port), file=stdout)
            print("%-20s: %s" % ("    data_path", inst.datadir), file=stdout)
            print("%-20s: %s" % ("    instance_state", inst.status),
                  file=stdout)
            print("", file=stdout)

        for inst in self.gtms:
            # get the instance info
            g_instanceInfo = None
            for instInfo in dbNode.gtms:
                if instInfo.instanceId == inst.instanceId:
                    g_instanceInfo = instInfo
                    break
            if not g_instanceInfo:
                raise Exception(ErrorCode.GAUSS_516["GAUSS_51620"] % "GTM")
            # construct the instance name
            instName = "gtm_%s" % g_instanceInfo.instanceId
            # print gtm instance information
            print("GTM", file=stdout)
            print("%-20s: %d" % ("    node", inst.nodeId), file=stdout)
            print("%-20s: %s" % ("    instance_name", instName), file=stdout)
            print("%-20s: %s" % ("    listen_IP", g_instanceInfo.listenIps),
                  file=stdout)
            print("%-20s: %d" % ("    port", g_instanceInfo.port), file=stdout)
            print("%-20s: %s" % ("    data_path", inst.datadir), file=stdout)
            print("%-20s: %s" % ("    instance_state", inst.status),
                  file=stdout)
            print("%-20s: %s" % ("    conn_state", inst.connStatus),
                  file=stdout)
            print("%-20s: %s" % ("    reason", inst.reason), file=stdout)
            print("", file=stdout)

        i = 1
        for inst in self.datanodes:
            # get the instance info
            g_instanceInfo = None
            for instInfo in dbNode.datanodes:
                if instInfo.instanceId == inst.instanceId:
                    g_instanceInfo = instInfo
                    break
            if not g_instanceInfo:
                raise Exception(ErrorCode.GAUSS_516["GAUSS_51620"] % "DN")
            # construct the instance name
            peerInsts = g_clusterInfo.getPeerInstance(g_instanceInfo)
            instName = \
                ClusterInstanceConfig. \
                    setReplConninfoForSinglePrimaryMultiStandbyCluster(
                    g_instanceInfo, peerInsts, g_clusterInfo)[1]

            # print DB instance information
            print("Datanode%d" % i, file=stdout)
            print("%-20s: %d" % ("    node", inst.nodeId), file=stdout)
            print("%-20s: %s" % ("    instance_name", instName), file=stdout)
            print("%-20s: %s" % ("    listen_IP", g_instanceInfo.listenIps),
                  file=stdout)
            print("%-20s: %s" % ("    HA_IP", g_instanceInfo.haIps),
                  file=stdout)
            print("%-20s: %d" % ("    port", g_instanceInfo.port), file=stdout)
            print("%-20s: %s" % ("    data_path", inst.datadir), file=stdout)
            print("%-20s: %s" % ("    instance_state", inst.status),
                  file=stdout)
            print("%-20s: %s" % ("    HA_state", inst.haStatus), file=stdout)
            print("%-20s: %s" % ("    reason", inst.reason), file=stdout)
            print("", file=stdout)

            i += 1
        # print fenced UDF status
        for inst in self.fencedUDFs:
            print("Fenced UDF", file=stdout)
            print("%-20s: %d" % ("    node", inst.nodeId), file=stdout)
            print("%-20s: %s" % ("    listen_IP", dbNode.backIps[0]),
                  file=stdout)
            print("%-20s: %s" % ("    instance_state", inst.status),
                  file=stdout)
Ejemplo n.º 13
0
def main():
    """
    function: main function
             1.parse command line
             2.check if user exist and is the right user
             3.check log file
             4.check backupPara and backupBin
             5.check tmpBackupDir
             6.do backup
    input : NA
    output: NA
    """
    try:
        opts, args = getopt.getopt(sys.argv[1:], "U:P:B:l:pbhi",
                                   ["position=", "backupdir=", \
                                    "nodeName=", "parameter", "binary_file",
                                    "logpath=", "help", "ingore_miss"])
    except getopt.GetoptError as e:
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e))
    if (len(args) > 0):
        GaussLog.exitWithError(
            ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0]))

    global g_clusterUser
    global g_ignoreMiss
    tmpBackupDir = ""
    backupDir = ""
    backupPara = False
    backupBin = False
    logFile = ""
    nodeName = ""
    for key, value in opts:
        if (key == "-h" or key == "--help"):
            usage()
            sys.exit(0)
        elif (key == "-U"):
            g_clusterUser = value.strip()
        elif (key == "-P" or key == "--position"):
            tmpBackupDir = value.strip()
        elif (key == "-B" or key == "--backupdir"):
            backupDir = value.strip()
        elif (key == "-p" or key == "--parameter"):
            backupPara = True
        elif (key == "-b" or key == "--binary_file"):
            backupBin = True
        elif (key == "-i" or key == "--ingore_miss"):
            g_ignoreMiss = True
        elif (key == "-l" or key == "--logpath"):
            logFile = value.strip()
        elif (key == "--nodeName"):
            nodeName = value.strip()
        else:
            GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % value)

        Parameter.checkParaVaild(key, value)

    if (g_ignoreMiss):
        gaussHome = DefaultValue.getEnv("GAUSSHOME")
        if not gaussHome:
            return

    # check if user exist and is the right user
    checkUserParameter()
    DefaultValue.checkUser(g_clusterUser, False)
    # check log file
    checkLogFile(logFile)
    # check backupPara and backupBin
    checkBackupPara(backupPara, backupBin)
    # check tmpBackupDir
    checkTmpBackupDir(tmpBackupDir)
    try:
        LocalBackuper = LocalBackup(logFile, g_clusterUser, tmpBackupDir,
                                    backupDir, backupPara, backupBin, nodeName)
        LocalBackuper.run()
    except Exception as e:
        GaussLog.exitWithError(str(e))