Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

dashboard clusterinfo support: develop basic of tidb-offline #1201

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
17 changes: 17 additions & 0 deletions roles/tidb_offline/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

- name: generate delete_tidb_topo script
template:
src: "delete_tidb_topo.sh.j2"
dest: "{{ deploy_dir }}/scripts/delete_tidb_topo.sh"
mode: "0755"

- name: delete stopped tidb information from dashboard
shell: ./delete_tidb_topo.sh
args:
chdir: "{{ deploy_dir }}/scripts"

- name: delete delete_tidb_topo scripts
file:
path: "{{ deploy_dir }}/scripts/delete_tidb_topo.sh"
state: absent
14 changes: 14 additions & 0 deletions roles/tidb_offline/templates/delete_tidb_topo.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

{% set all_pd = [] -%}
{% set pd_hosts = groups.pd_servers %}
{% for host in pd_hosts -%}
{% set pd_ip = hostvars[host].ansible_host | default(hostvars[host].inventory_hostname) -%}
{% set pd_port = hostvars[host].pd_client_port -%}
{% set _ = all_pd.append("%s:%s" % (pd_ip, pd_port)) -%}
{% endfor -%}

{% set my_ip = hostvars[host].ansible_host | default(hostvars[host].inventory_hostname) -%}

python2 delete_tidb_topo.py --pd {{ all_pd | join(',') }} --tidb {{ my_ip }}:{{ tidb_port }}
9 changes: 4 additions & 5 deletions scripts/dashboard_topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import json
import argparse

ComponentToRegister = ('alertmanager', 'grafana', 'pd', 'prometheus')
ComponentToRegister = ('alertmanager', 'grafana', 'prometheus')
Components = ComponentToRegister + ('pd', )


def parse_opts():
Expand All @@ -18,7 +19,7 @@ def parse_opts():
"""
parser = argparse.ArgumentParser(description="Parse output.")
# pd is involved because we need to send http request
for target in ComponentToRegister:
for target in Components:
parser.add_argument("--{}".format(target),
help="the address list of {}".format(target))
args, unknown = parser.parse_known_args()
Expand Down Expand Up @@ -108,7 +109,5 @@ def concat_to_address(ip, port):
'prometheus': prometheus_address,
}

for comp in ComponentToRegister:
if comp == 'pd':
continue
for comp in Components:
request_topo(comp, mapping[comp], pd_address_zero)
62 changes: 62 additions & 0 deletions scripts/delete_tidb_topo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import print_function, \
unicode_literals

import urllib2
import base64
import json
import argparse

Components = ('tidb', 'pd')


def parse_opts():
"""
parse_opts parse the input of involved components and pd address.
"""
parser = argparse.ArgumentParser(description="Parse output.")
# pd is involved because we need to send http request
for target in Components:
parser.add_argument("--{}".format(target),
help="the address list of {}".format(target))
args, unknown = parser.parse_known_args()
return args


def etcd_delete(etcd_url, key):
encoded_key = base64.b64encode(key)
data = json.dumps({
"key": encoded_key,
})
req = urllib2.Request('http://' + etcd_url + '/v3/kv/deleterange',
data=data,
headers={'Content-Type': 'application/json'})
try:
resp = urllib2.urlopen(req)
data = json.load(resp)
return data
except urllib2.HTTPError as error:
raise error


def delete_tidb_topo(tidb_list, pd_address):
try:
for tidb in tidb_list.split(','):
# tidb is ip:port
etcd_delete(pd_address, '/topology/tidb/' + tidb + '/info')
etcd_delete(pd_address, '/topology/tidb/' + tidb + '/ttl')
return False
except:
return True


if __name__ == '__main__':
args = parse_opts()

pd_address = args.pd
pd_address_zero = pd_address.split(',')[0]

tidb_list = args.tidb

for pd in pd_address.split(','):
if delete_tidb_topo(tidb_list, pd):
return
4 changes: 4 additions & 0 deletions stop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@
state: stopped
msg: "the TiDB port {{ tidb_port }} is not down"

- roles:
- tidb_offline


- hosts: pump_servers
tags:
Expand Down Expand Up @@ -326,3 +329,4 @@
port: "{{ grafana_port }}"
state: stopped
msg: "the grafana port {{ grafana_port }} is not down"