예제 #1
0
def parseCommandLine():
    """
    function: parseCommandLine
    input: NA
    output: NA
    """
    try:
        paraLine = sys.argv[1]
        paraLine = DefaultValue.encodeParaline(paraLine,
                                               DefaultValue.BASE_DECODE)
        paraLine = paraLine.strip()
        paraList = paraLine.split("*==SYMBOL==*")
        opts, args = getopt.getopt(
            paraList[1:], "U:C:D:T:P:l:hX:",
            ["help", "alarm=", "gucXml", "vc_mode", "dws-mode"])
    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]))

    global g_opts
    g_opts = CmdOptions()

    for (key, value) in opts:
        if (key == "-h" or key == "--help"):
            usage()
            sys.exit(0)
        elif (key == "-U"):
            g_opts.clusterUser = value
        elif (key == "-D"):
            g_opts.dataGucParams.append(value)
        elif (key == "-T"):
            g_opts.configType = value
        elif (key == "-P"):
            g_opts.clusterStaticConfigFile = value
        elif (key == "-l"):
            g_opts.logFile = os.path.realpath(value)
        elif (key == "--alarm"):
            g_opts.alarmComponent = value
        elif (key == "--gucXml"):
            g_opts.gucXml = True
        elif (key == "--vc_mode"):
            g_opts.vcMode = True
        elif (key == "--dws-mode"):
            g_opts.dws_mode = True
        elif key == "-X":
            g_opts.clusterConf = os.path.realpath(value)
        Parameter.checkParaVaild(key, value)
예제 #2
0
    def updateInstanceConfig(self):
        """
        function: Update instances config on all nodes
        input : NA
        output: NA
        """
        self.context.logger.log(
            "Updating instance configuration on all nodes.")
        # update instances config on all nodes
        cmdParam = ""
        paralistdn = [
            param.split('=')[0].strip() for param in self.context.dataGucParam
        ]
        if ("autovacuum" not in paralistdn):
            self.context.dataGucParam.append("autovacuum=on")

        # get the --dn-guc parameter values
        for param in self.context.dataGucParam:
            cmdParam += "*==SYMBOL==*-D*==SYMBOL==*%s" % param
        # check the --alarm-component parameter
        if (self.context.alarm_component != ""):
            cmdParam += "*==SYMBOL==*--alarm=%s" % self.context.alarm_component

        # create tmp file for guc parameters
        # comm_max_datanode and max_process_memory
        self.context.logger.debug("create tmp_guc file.")
        tmpGucPath = DefaultValue.getTmpDirFromEnv(self.context.user)
        tmpGucFile = "%s/tmp_guc" % tmpGucPath
        cmd = g_file.SHELL_CMD_DICT["createFile"] % (
            tmpGucFile, DefaultValue.MAX_DIRECTORY_MODE, tmpGucFile)
        DefaultValue.execCommandWithMode(cmd, "Install applications",
                                         self.context.sshTool,
                                         self.context.isSingle,
                                         self.context.mpprcFile)
        self.context.logger.debug("Create tmp_guc file successfully.")

        # get the master datanode number
        primaryDnNum = DefaultValue.getPrimaryDnNum(self.context.clusterInfo)
        self.context.logger.debug("get master datanode number : %s" %
                                  primaryDnNum)
        # get the physic memory of all node and choose the min one
        physicMemo = DefaultValue.getPhysicMemo(self.context.sshTool,
                                                self.context.isSingle)
        self.context.logger.debug("get physic memory value : %s" % physicMemo)
        # get the datanode number in all nodes and choose the max one
        dataNodeNum = DefaultValue.getDataNodeNum(self.context.clusterInfo)
        self.context.logger.debug("get min datanode number : %s" % dataNodeNum)

        # write the value in tmp file
        self.context.logger.debug("Write value in tmp_guc file.")
        gucValueContent = str(primaryDnNum) + "," + str(
            physicMemo) + "," + str(dataNodeNum)
        cmd = g_file.SHELL_CMD_DICT["overWriteFile"] % (gucValueContent,
                                                        tmpGucFile)
        DefaultValue.execCommandWithMode(cmd, "Install applications",
                                         self.context.sshTool,
                                         self.context.isSingle,
                                         self.context.mpprcFile)
        self.context.logger.debug("Write tmp_guc file successfully.")

        # update instances config
        cmd = "source %s;" % self.context.mpprcFile
        cmd += "%s " % (OMCommand.getLocalScript("Local_Config_Instance"))
        paraLine = \
            "*==SYMBOL==*-U*==SYMBOL==*%s%s*==SYMBOL==*-l*==SYMBOL==*%s" % (
                self.context.user, cmdParam, self.context.localLog)
        if (self.context.dws_mode):
            paraLine += "*==SYMBOL==*--dws-mode"
        # get the --gucXml parameter
        if (self.checkMemAndCores()):
            paraLine += "*==SYMBOL==*--gucXml"
        paraLine += "*==SYMBOL==*-X*==SYMBOL==*%s" % self.context.xmlFile
        cmd += DefaultValue.encodeParaline(paraLine, DefaultValue.BASE_ENCODE)

        self.context.logger.debug(
            "Command for updating instances configuration: %s" % cmd)
        DefaultValue.execCommandWithMode(cmd, "update instances configuration",
                                         self.context.sshTool,
                                         self.context.isSingle)
        self.context.logger.debug("Successfully configured node instance.")