Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/openmldb-tool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ jobs:
apt-get update && apt-get install -y rsync
- name: install openmldb
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git fetch --tags --force
VERSION=$(git describe --always --tags `git rev-list --tags --max-count=1`)
VERSION=${VERSION#v}
bash test/test-tool/openmldb-deploy/install_with_name.sh ${VERSION}
- name: run test
run: |
cp -f tools/tool.py test/test-tool/openmldb-deploy/cases/
cp -f tools/* openmldb/tools/
cp -rf tools/* openmldb/tools/
python3 -m pytest test/test-tool/openmldb-deploy/cases --junit-xml=pytest.xml
- name: clear env
run: |
Expand Down
2 changes: 1 addition & 1 deletion test/test-tool/openmldb-deploy/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [[ -z ${VERSION} ]]; then
VERSION=0.7.2
fi
echo "version: ${VERSION}"
curl -SLo openmldb.tar.gz "https://github.com/4paradigm/OpenMLDB/releases/download/v${VERSION}/openmldb-${VERSION}-linux.tar.gz"
curl -SLo openmldb.tar.gz "https://github.com/4paradigm/OpenMLDB/releases/download/v${VERSION}/openmldb-${VERSION}-linux-x86_64.tar.gz"
mkdir -p "openmldb"
tar xzf openmldb.tar.gz -C "openmldb" --strip-components 1
pushd "openmldb"
Expand Down
6 changes: 3 additions & 3 deletions test/test-tool/openmldb-deploy/install_with_name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [[ -z ${VERSION} ]]; then
VERSION=0.7.2
fi
echo "version: ${VERSION}"
curl -SLo openmldb.tar.gz "https://github.com/4paradigm/OpenMLDB/releases/download/v${VERSION}/openmldb-${VERSION}-linux.tar.gz"
curl -SLo openmldb.tar.gz "https://github.com/4paradigm/OpenMLDB/releases/download/v${VERSION}/openmldb-${VERSION}-linux-x86_64.tar.gz"
mkdir -p "openmldb"
tar xzf openmldb.tar.gz -C "openmldb" --strip-components 1
pushd "openmldb"
Expand All @@ -32,7 +32,7 @@ rm -f bin/*.sh

/bin/cp -f ../test/test-tool/openmldb-deploy/hosts conf/hosts
sed -i"" -e "s/OPENMLDB_VERSION=[0-9]\.[0-9]\.[0-9]/OPENMLDB_VERSION=${VERSION}/g" conf/openmldb-env.sh
sh sbin/deploy-all.sh
bash sbin/deploy-all.sh

for (( i=0; i<=2; i++ ))
do
Expand All @@ -53,7 +53,7 @@ do
echo "--use_name=true" >> ${conf_file}
done

sh sbin/start-all.sh
bash sbin/start-all.sh
popd

pushd test/test-tool/openmldb-deploy
Expand Down
8 changes: 4 additions & 4 deletions tools/openmldb_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,21 @@ def BalanceInDatabase(executor, endpoints, db):
is_leader = True if record[4] == "leader" else False
is_alive = True if record[5] == "yes" else False
partition = Partition(record[0], record[1], record[2], record[3], is_leader, is_alive, record[6])
all_dict.setdefault(partition.GetEndpoint(), []);
all_dict.setdefault(partition.GetEndpoint(), [])
all_dict[partition.GetEndpoint()].append(partition)
endpoint_partition_map.setdefault(partition.GetEndpoint(), set())
endpoint_partition_map[partition.GetEndpoint()].add(partition.GetKey())
replica_map.setdefault(partition.GetKey(), 0)
replica_map[partition.GetKey()] += 1
for endpoint in endpoints:
if endpoint not in all_dict:
all_dict.setdefault(endpoint, []);
all_dict.setdefault(endpoint, [])
endpoint_partition_map.setdefault(endpoint, set())

start_endpoint = random.choice(endpoints)
while True:
migrate_out_endpoint = start_endpoint;
migrate_in_endpoint = start_endpoint;
migrate_out_endpoint = start_endpoint
migrate_in_endpoint = start_endpoint
for endpoint in endpoints:
if len(all_dict[endpoint]) > len(all_dict[migrate_out_endpoint]) : migrate_out_endpoint = endpoint
if len(all_dict[endpoint]) < len(all_dict[migrate_in_endpoint]) : migrate_in_endpoint = endpoint
Expand Down
42 changes: 21 additions & 21 deletions tools/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(self, openmldb_bin_path, zk_cluster, zk_root_path):
def Connect(self):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=showns")
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK() or status.GetMsg().find("zk client init failed") != -1:
return Status(-1, "get ns failed")
result = self.ParseResult(output)
Expand All @@ -108,7 +108,7 @@ def Connect(self):
self.endpoint_map[record[0]] = record[0]
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=showtablet")
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK():
return Status(-1, "get tablet failed")
result = self.ParseResult(output)
Expand All @@ -126,7 +126,7 @@ def Connect(self):
"--interactive=false"]
return Status()

def RunWithRetuncode(self, command,
def RunWithReturncode(self, command,
universal_newlines = True,
useshell = USE_SHELL,
env = os.environ):
Expand All @@ -147,7 +147,7 @@ def RunWithRetuncode(self, command,
def GetNsLeader(self):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=showns")
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if status.OK():
result = self.ParseResult(output)
for record in result:
Expand Down Expand Up @@ -175,7 +175,7 @@ def ParseResult(self, output):
def GetAutofailover(self):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=confget auto_failover")
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK():
return status, None
if output.find("true") != -1:
Expand All @@ -185,13 +185,13 @@ def GetAutofailover(self):
def SetAutofailover(self, value):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=confset auto_failover " + value)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
return status

def GetAllDatabase(self):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=showdb")
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK():
return status, None
dbs = []
Expand All @@ -205,7 +205,7 @@ def GetTableInfo(self, database, table_name = ''):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=showtable " + table_name)
cmd.append("--database=" + database)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK():
return status, None
result = []
Expand Down Expand Up @@ -260,7 +260,7 @@ def ParseTableInfoJson(self, table_info):

def GetTablePartition(self, database, table_name):
status, result = self.GetTableInfo(database, table_name)
if not status.OK:
if not status.OK():
return status, None
return self.ParseTableInfo(result)

Expand All @@ -278,7 +278,7 @@ def GetTableStatus(self, endpoint, tid = '', pid = ''):
cmd = list(self.tablet_base_cmd)
cmd.append("--endpoint=" + self.endpoint_map[endpoint])
cmd.append("--cmd=gettablestatus " + tid + " " + pid)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK():
log.error("gettablestatus failed on " + str(cmd))
return status, None
Expand All @@ -296,7 +296,7 @@ def GetTableStatus(self, endpoint, tid = '', pid = ''):
def ShowTableStatus(self, pattern = '%'):
cmd = list(self.sql_base_cmd)
cmd.append("--cmd=show table status like '{pattern}';".format(pattern = pattern))
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK():
log.error("show table status failed")
return status, None
Expand Down Expand Up @@ -352,7 +352,7 @@ def GetLeaderFollowerOffset(self, endpoint, tid, pid):
cmd = list(self.tablet_base_cmd)
cmd.append("--endpoint=" + self.endpoint_map[endpoint])
cmd.append("--cmd=getfollower {} {}".format(tid, pid))
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK():
return status
return Status(), self.ParseResult(output)
Expand All @@ -361,7 +361,7 @@ def RecoverTablePartition(self, database, name, pid, endpoint, sync = False):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=recovertable {} {} {}".format(name, pid, endpoint))
cmd.append("--database=" + database)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if status.OK() and output.find("recover table ok") != -1:
if sync and not self.WaitingOP(database, name, pid).OK():
return Status(-1, "recovertable failed")
Expand All @@ -374,7 +374,7 @@ def UpdateTableAlive(self, database, name, pid, endpoint, is_alive):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=updatetablealive {} {} {} {}".format(name, pid, endpoint, is_alive))
cmd.append("--database=" + database)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if status.OK() and output.find("update ok") != -1:
return Status()
return Status(-1, "update table alive failed")
Expand All @@ -383,7 +383,7 @@ def ChangeLeader(self, database, name, pid, endpoint = "auto", sync = False):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=changeleader {} {} {}".format(name, pid, endpoint))
cmd.append("--database=" + database)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if status.OK() and sync and not self.WaitingOP(database, name, pid).OK():
return Status(-1, "changer leader failed")
return status
Expand All @@ -392,7 +392,7 @@ def ShowOpStatus(self, database, name = '', pid = ''):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=showopstatus {} {} ".format(name, pid))
cmd.append("--database=" + database)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK():
return status, None
return Status(), self.ParseResult(output)
Expand All @@ -401,7 +401,7 @@ def CancelOp(self, database, op_id):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=cancelop {}".format(op_id))
cmd.append("--database=" + database)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
return status

def Migrate(self, database, name, pid, src_endpoint, desc_endpoint, sync = False):
Expand All @@ -410,7 +410,7 @@ def Migrate(self, database, name, pid, src_endpoint, desc_endpoint, sync = False
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=migrate {} {} {} {}".format(src_endpoint, name, pid, desc_endpoint))
cmd.append("--database=" + database)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if status.OK() and output.find("migrate ok") != -1:
if sync and not self.WaitingOP(database, name, pid).OK():
return Status(-1, "migrate failed")
Expand All @@ -420,7 +420,7 @@ def Migrate(self, database, name, pid, src_endpoint, desc_endpoint, sync = False
def ShowTablet(self):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=showtablet")
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if not status.OK():
return status, None
return Status(), self.ParseResult(output)
Expand All @@ -429,7 +429,7 @@ def AddReplica(self, database, name, pid, endpoint, sync = False):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=addreplica {} {} {}".format(name, pid, endpoint))
cmd.append("--database=" + database)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if status.OK() and output.find("ok") != -1:
if sync and not self.WaitingOP(database, name, pid).OK():
return Status(-1, "addreplica failed")
Expand All @@ -440,7 +440,7 @@ def DelReplica(self, database, name, pid, endpoint, sync = False):
cmd = list(self.ns_base_cmd)
cmd.append("--cmd=delreplica {} {} {}".format(name, pid, endpoint))
cmd.append("--database=" + database)
status, output = self.RunWithRetuncode(cmd)
status, output = self.RunWithReturncode(cmd)
if status.OK() and output.find("ok") != -1:
if sync and not self.WaitingOP(database, name, pid).OK():
return Status(-1, "delreplica failed")
Expand Down
Loading