add port in gs_om tools
This commit is contained in:
@ -168,6 +168,7 @@ SPACE_LEN = 1
|
|||||||
STATE_LEN = 17
|
STATE_LEN = 17
|
||||||
SEPERATOR_LEN = 1
|
SEPERATOR_LEN = 1
|
||||||
IP_LEN = 16
|
IP_LEN = 16
|
||||||
|
PORT_LEN = 10
|
||||||
|
|
||||||
# GPHOME
|
# GPHOME
|
||||||
CLUSTER_TOOL_PATH = "/opt/huawei/wisequery"
|
CLUSTER_TOOL_PATH = "/opt/huawei/wisequery"
|
||||||
@ -1443,6 +1444,9 @@ class dbClusterInfo():
|
|||||||
outText = outText + (
|
outText = outText + (
|
||||||
"data_path : %s\n" %
|
"data_path : %s\n" %
|
||||||
dnInst.datadir)
|
dnInst.datadir)
|
||||||
|
outText = outText + (
|
||||||
|
"instance_port : %s\n" %
|
||||||
|
dnInst.port)
|
||||||
outText = outText + "type : " \
|
outText = outText + "type : " \
|
||||||
"Datanode\n"
|
"Datanode\n"
|
||||||
outText = outText + (
|
outText = outText + (
|
||||||
@ -1639,6 +1643,7 @@ class dbClusterInfo():
|
|||||||
dbState = ""
|
dbState = ""
|
||||||
primaryDbNum = 0
|
primaryDbNum = 0
|
||||||
primaryDbState = ""
|
primaryDbState = ""
|
||||||
|
portMap = {}
|
||||||
for dbNode in self.dbNodes:
|
for dbNode in self.dbNodes:
|
||||||
for dnInst in dbNode.datanodes:
|
for dnInst in dbNode.datanodes:
|
||||||
sshcmd = "gs_ctl query -D %s" % dnInst.datadir
|
sshcmd = "gs_ctl query -D %s" % dnInst.datadir
|
||||||
@ -1662,6 +1667,7 @@ class dbClusterInfo():
|
|||||||
roleStatus = res[0]
|
roleStatus = res[0]
|
||||||
res = re.findall(r'db_state\s*:\s*(\w+)', output)
|
res = re.findall(r'db_state\s*:\s*(\w+)', output)
|
||||||
dbState = res[0]
|
dbState = res[0]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
(status, output) = subprocess.getstatusoutput(sshcmd)
|
(status, output) = subprocess.getstatusoutput(sshcmd)
|
||||||
if status != 0 or output.find("exc_sql failed") > 0:
|
if status != 0 or output.find("exc_sql failed") > 0:
|
||||||
@ -1678,7 +1684,8 @@ class dbClusterInfo():
|
|||||||
res = re.findall(r'local_role\s*:\s*(\w+)', output)
|
res = re.findall(r'local_role\s*:\s*(\w+)', output)
|
||||||
roleStatus = res[0]
|
roleStatus = res[0]
|
||||||
res = re.findall(r'db_state\s*:\s*(\w+)', output)
|
res = re.findall(r'db_state\s*:\s*(\w+)', output)
|
||||||
dbState = res[0]
|
dbState = res[0]
|
||||||
|
|
||||||
if (dbState == "Need"):
|
if (dbState == "Need"):
|
||||||
detailInformation = re.findall(
|
detailInformation = re.findall(
|
||||||
r'detail_information\s*:\s*(\w+)', output)
|
r'detail_information\s*:\s*(\w+)', output)
|
||||||
@ -1707,6 +1714,11 @@ class dbClusterInfo():
|
|||||||
clusterState = 'Degraded'
|
clusterState = 'Degraded'
|
||||||
if dbState != "Normal":
|
if dbState != "Normal":
|
||||||
clusterState = 'Degraded'
|
clusterState = 'Degraded'
|
||||||
|
|
||||||
|
# get port info by guc
|
||||||
|
portMap[dbNode.name] = self.__getPortInfo(dbNode.name, \
|
||||||
|
hostName, dnInst.datadir, sshtool, mpprcFile)
|
||||||
|
|
||||||
if dnNodeCount == 1:
|
if dnNodeCount == 1:
|
||||||
clusterState = "Unavailable" if dbState != "Normal" \
|
clusterState = "Unavailable" if dbState != "Normal" \
|
||||||
else "Normal"
|
else "Normal"
|
||||||
@ -1732,25 +1744,17 @@ class dbClusterInfo():
|
|||||||
nodeLen = NODE_ID_LEN + SPACE_LEN + maxNodeNameLen + SPACE_LEN
|
nodeLen = NODE_ID_LEN + SPACE_LEN + maxNodeNameLen + SPACE_LEN
|
||||||
instanceLen = INSTANCE_ID_LEN + SPACE_LEN + (
|
instanceLen = INSTANCE_ID_LEN + SPACE_LEN + (
|
||||||
maxDataPathLen if cmd.dataPathQuery else 4)
|
maxDataPathLen if cmd.dataPathQuery else 4)
|
||||||
|
|
||||||
if cmd.azNameQuery:
|
if cmd.azNameQuery:
|
||||||
nodeLen += maxAzNameLen + SPACE_LEN
|
nodeLen += maxAzNameLen + SPACE_LEN
|
||||||
if cmd.portQuery:
|
if cmd.portQuery:
|
||||||
instanceLen += 7
|
instanceLen += 7
|
||||||
for i in range(dnNodeCount - 1):
|
|
||||||
outText = outText + ("%-*s%-*s%-*s%-*s| " % (nodeLen,
|
outText = outText + "%-*s%-*s%-*s%-*s%s\n" % (
|
||||||
"node",
|
nodeLen, " node", IP_LEN, "node_ip", PORT_LEN, "port", instanceLen, "instance",
|
||||||
IP_LEN,
|
|
||||||
"node_ip",
|
|
||||||
instanceLen,
|
|
||||||
"instance",
|
|
||||||
STATE_LEN,
|
|
||||||
"state"))
|
|
||||||
outText = outText + "%-*s%-*s%-*s%s\n" % (
|
|
||||||
nodeLen, "node", IP_LEN, "node_ip", instanceLen, "instance",
|
|
||||||
"state")
|
"state")
|
||||||
maxLen = self.nodeCount * (
|
maxLen = nodeLen + instanceLen + IP_LEN + SPACE_LEN + PORT_LEN + SPACE_LEN + \
|
||||||
nodeLen + instanceLen + IP_LEN + SPACE_LEN + STATE_LEN +
|
STATE_LEN + SPACE_LEN + SEPERATOR_LEN
|
||||||
SPACE_LEN + SEPERATOR_LEN)
|
|
||||||
seperatorLine = "-" * maxLen
|
seperatorLine = "-" * maxLen
|
||||||
outText = outText + seperatorLine + "\n"
|
outText = outText + seperatorLine + "\n"
|
||||||
i = 0
|
i = 0
|
||||||
@ -1763,30 +1767,65 @@ class dbClusterInfo():
|
|||||||
outText = outText + (
|
outText = outText + (
|
||||||
"%-*s " % (maxNodeNameLen, dbNode.name))
|
"%-*s " % (maxNodeNameLen, dbNode.name))
|
||||||
outText = outText + ("%-15s " % dnInst.listenIps[0])
|
outText = outText + ("%-15s " % dnInst.listenIps[0])
|
||||||
|
|
||||||
|
# port info
|
||||||
|
port = ""
|
||||||
|
if portMap[dbNode.name]:
|
||||||
|
port = portMap[dbNode.name]
|
||||||
|
else:
|
||||||
|
port = dnInst.port
|
||||||
|
outText = outText + ("%-10u " % port)
|
||||||
|
|
||||||
outText = outText + ("%u " % dnInst.instanceId)
|
outText = outText + ("%u " % dnInst.instanceId)
|
||||||
if cmd.portQuery:
|
|
||||||
outText = outText + ("%-*u " % (6, dnInst.port))
|
|
||||||
if cmd.dataPathQuery:
|
if cmd.dataPathQuery:
|
||||||
outText = outText + (
|
outText = outText + (
|
||||||
"%-*s " % (maxDataPathLen, dnInst.datadir))
|
"%-*s " % (maxDataPathLen, dnInst.datadir))
|
||||||
else:
|
else:
|
||||||
outText = outText + " "
|
outText = outText + " "
|
||||||
outText = outText + (
|
outText = outText + (
|
||||||
"%s " % self.__getDnRole(dnInst.instanceType))
|
"%3s " % self.__getDnRole(dnInst.instanceType))
|
||||||
if dnNodeCount == 1:
|
if dnNodeCount == 1:
|
||||||
outText = outText + ("%-7s" % "Primary")
|
outText = outText + ("%-7s" % "Primary")
|
||||||
else:
|
else:
|
||||||
outText = outText + ("%-7s" % roleStatusArray[i])
|
outText = outText + ("%-7s" % roleStatusArray[i])
|
||||||
outText = outText + (" %s" % dbStateArray[i])
|
outText = outText + (" %s" % dbStateArray[i])
|
||||||
if i < (dnNodeCount - 1):
|
|
||||||
outText = outText + " | "
|
outText = outText + "\n"
|
||||||
else:
|
|
||||||
outText = outText + "\n"
|
|
||||||
i += 1
|
i += 1
|
||||||
self.__fprintContent(outText, cmd.outputFile)
|
self.__fprintContent(outText, cmd.outputFile)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(ErrorCode.GAUSS_516["GAUSS_51652"] % str(e))
|
raise Exception(ErrorCode.GAUSS_516["GAUSS_51652"] % str(e))
|
||||||
|
|
||||||
|
def __getPortInfo(self, nodeName, hostName, dnpath, sshtool, mpprcFile=""):
|
||||||
|
"""
|
||||||
|
function: Get port info form guc result
|
||||||
|
"""
|
||||||
|
portcmd = "gs_guc check -D %s -c port" % dnpath
|
||||||
|
output = ""
|
||||||
|
if (nodeName != hostName):
|
||||||
|
(statusMap, output) = sshtool.getSshStatusOutput(
|
||||||
|
portcmd, [nodeName], mpprcFile)
|
||||||
|
if statusMap[nodeName] != "Success":
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
(status, output) = subprocess.getstatusoutput(portcmd)
|
||||||
|
if status != 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
DEFAULT_PORT = 5432
|
||||||
|
if not output:
|
||||||
|
return None
|
||||||
|
portpattern = re.compile("port=(\d+|NULL)")
|
||||||
|
result = portpattern.findall(output)
|
||||||
|
portvalue = ""
|
||||||
|
if len(result) > 0:
|
||||||
|
portvalue = result.pop()
|
||||||
|
if portvalue != "NULL":
|
||||||
|
return int(portvalue)
|
||||||
|
return DEFAULT_PORT
|
||||||
|
|
||||||
|
|
||||||
def __getDnRole(self, instanceType):
|
def __getDnRole(self, instanceType):
|
||||||
"""
|
"""
|
||||||
function : Get DnRole by instanceType
|
function : Get DnRole by instanceType
|
||||||
@ -1826,6 +1865,10 @@ class dbClusterInfo():
|
|||||||
for dbNode in self.dbNodes:
|
for dbNode in self.dbNodes:
|
||||||
for dnInst in dbNode.datanodes:
|
for dnInst in dbNode.datanodes:
|
||||||
dnNodeCount += 1
|
dnNodeCount += 1
|
||||||
|
# Update port by query on each node. Otherwise the port is modified
|
||||||
|
# but the static file is not, query result will be failure
|
||||||
|
port = self.__getPortInfo(dbNode.name, localHostName, dnInst.datadir, sshtool)
|
||||||
|
dnInst.port = port
|
||||||
self.__getDnState(dnInst, dbNode, localHostName, sshtool)
|
self.__getDnState(dnInst, dbNode, localHostName, sshtool)
|
||||||
if dnInst.localRole == "Primary":
|
if dnInst.localRole == "Primary":
|
||||||
primaryDbState = dnInst.state
|
primaryDbState = dnInst.state
|
||||||
@ -2054,15 +2097,15 @@ class dbClusterInfo():
|
|||||||
userProfile = "~/.bashrc"
|
userProfile = "~/.bashrc"
|
||||||
# build shell command
|
# build shell command
|
||||||
if os.getuid() == 0:
|
if os.getuid() == 0:
|
||||||
cmd = "su - %s -c 'source %s;gs_om -t status --detail|tail -1" % (
|
cmd = "su - %s -c 'source %s;gs_om -t status --detail" % (
|
||||||
user, userProfile)
|
user, userProfile)
|
||||||
else:
|
else:
|
||||||
cmd = "source %s;gs_om -t status --detail|tail -1" % (userProfile)
|
cmd = "source %s;gs_om -t status --detail" % (userProfile)
|
||||||
(status, output) = subprocess.getstatusoutput(cmd)
|
(status, output) = subprocess.getstatusoutput(cmd)
|
||||||
if status != 0:
|
if status != 0:
|
||||||
raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"]
|
raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"]
|
||||||
% cmd + " Error: \n%s" % output)
|
% cmd + " Error: \n%s" % output)
|
||||||
return output.split("\n")[0]
|
return output.split("\n")
|
||||||
|
|
||||||
def __readStaticConfigFile(self, staticConfigFile, user, isLCCluster=False,
|
def __readStaticConfigFile(self, staticConfigFile, user, isLCCluster=False,
|
||||||
ignoreLocalEnv=False):
|
ignoreLocalEnv=False):
|
||||||
@ -6059,12 +6102,15 @@ class dbClusterInfo():
|
|||||||
raise Exception(ErrorCode.GAUSS_504["GAUSS_50407"] +
|
raise Exception(ErrorCode.GAUSS_504["GAUSS_50407"] +
|
||||||
" Error: \n%s." % str(output) +
|
" Error: \n%s." % str(output) +
|
||||||
"The cmd is %s" % cmd)
|
"The cmd is %s" % cmd)
|
||||||
tempstatus = self.__getStatusByOM(user).split("|")
|
output_list = self.__getStatusByOM(user)
|
||||||
|
output_last_info = output_list[-1].split()
|
||||||
|
output_num = int(output_last_info[0])
|
||||||
|
tempstatus = output_list[-output_num:]
|
||||||
statusdic = {'Primary': 0, 'Standby': 1, 'Cascade': 3, 'Unknown': 9}
|
statusdic = {'Primary': 0, 'Standby': 1, 'Cascade': 3, 'Unknown': 9}
|
||||||
try:
|
try:
|
||||||
with open(simpleDNConfig, "w") as fp:
|
with open(simpleDNConfig, "w") as fp:
|
||||||
for dninfo in tempstatus:
|
for dninfo in tempstatus:
|
||||||
dnstatus = dninfo.split()[6]
|
dnstatus = dninfo.split()[7]
|
||||||
dnname = dninfo.split()[1]
|
dnname = dninfo.split()[1]
|
||||||
if dnstatus not in statusdic:
|
if dnstatus not in statusdic:
|
||||||
fp.write("%s=%d\n" %
|
fp.write("%s=%d\n" %
|
||||||
|
@ -131,7 +131,7 @@ class Resetreplconninfo():
|
|||||||
if status != 0:
|
if status != 0:
|
||||||
raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"]
|
raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"]
|
||||||
% cmd + " Error: \n%s" % output)
|
% cmd + " Error: \n%s" % output)
|
||||||
return output.split("\n")[-1]
|
return output.split("\n")
|
||||||
|
|
||||||
def resetRepl(self):
|
def resetRepl(self):
|
||||||
"""
|
"""
|
||||||
@ -139,18 +139,32 @@ class Resetreplconninfo():
|
|||||||
input : NA
|
input : NA
|
||||||
output: NA
|
output: NA
|
||||||
"""
|
"""
|
||||||
status_list = self.__getStatusByOM().split('|')
|
output_list = self.__getStatusByOM()
|
||||||
|
output_last_info = output_list[-1].split()
|
||||||
|
output_num = int(output_last_info[0])
|
||||||
|
status_list = output_list[-output_num:]
|
||||||
repl_list = ['replconninfo' + str(i) for i in
|
repl_list = ['replconninfo' + str(i) for i in
|
||||||
range(1, len(status_list))]
|
range(1, len(status_list))]
|
||||||
|
|
||||||
|
# each information index after split space. displayed as:
|
||||||
|
# node node_ip port instance state
|
||||||
|
# ------------------------------------------------------------------------------------------
|
||||||
|
# 1 ecs-66cc 192.168.0.1 5432 6001 /opt/install/data/dn P Primary Normal
|
||||||
|
# 2 ecs-6ac8 192.168.0.2 5432 6002 /opt/install/data/dn S Standby Normal
|
||||||
|
# If the displayed information is changed, please modify the idx value here.
|
||||||
|
nodename_split_idx = 1
|
||||||
|
nodeip_split_idx = 2
|
||||||
|
dndir_split_idx = 5
|
||||||
|
instype_split_id = 7
|
||||||
|
|
||||||
localhost = DefaultValue.GetHostIpOrName()
|
localhost = DefaultValue.GetHostIpOrName()
|
||||||
remote_ip_dict = {}
|
remote_ip_dict = {}
|
||||||
for info_all in status_list:
|
for info_all in status_list:
|
||||||
info = info_all.split()
|
info = info_all.split()
|
||||||
if info[1] == localhost:
|
if info[nodename_split_idx] == localhost:
|
||||||
local_dndir = info[4]
|
local_dndir = info[dndir_split_idx]
|
||||||
else:
|
else:
|
||||||
remote_ip_dict[info[2]] = info[6]
|
remote_ip_dict[info[nodeip_split_idx]] = info[instype_split_id]
|
||||||
head_cmd = "source %s;" % self.userProfile
|
head_cmd = "source %s;" % self.userProfile
|
||||||
for repl in repl_list:
|
for repl in repl_list:
|
||||||
cmd = head_cmd + 'gs_guc check -N %s -D %s -c "%s"' % \
|
cmd = head_cmd + 'gs_guc check -N %s -D %s -c "%s"' % \
|
||||||
|
Reference in New Issue
Block a user