Skip to content

Commit ce3d97a

Browse files
committed
Merge branch '3.0.1_release' into 'master'
V3.0.1 See merge request oceanbase/ob-deploy!269
2 parents 974dffe + 5efeab1 commit ce3d97a

File tree

13 files changed

+180
-34
lines changed

13 files changed

+180
-34
lines changed

core.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,7 @@ def export_to_ocp(self, name):
13101310
return False
13111311
self._call_stdio('verbose', 'Get Deploy by name')
13121312
deploy = self.deploy_manager.get_deploy_config(name)
1313+
self.set_deploy(deploy)
13131314
if not deploy:
13141315
self._call_stdio('error', 'No such deploy: %s.' % name)
13151316
return False
@@ -1328,12 +1329,6 @@ def export_to_ocp(self, name):
13281329
self.set_repositories(repositories)
13291330
ssh_clients = self.get_clients(deploy_config, repositories)
13301331

1331-
self._call_stdio('verbose', 'get plugins by mocking an ocp repository.')
1332-
# search and get all related plugins using a mock ocp repository
1333-
mock_ocp_repository = Repository(const.COMP_OCP_SERVER_CE, "/")
1334-
mock_ocp_repository.version = "4.2.1"
1335-
repositories.extend([mock_ocp_repository])
1336-
13371332
# search and install oceanbase-ce-utils, just log warning when failed since it can be installed after takeover
13381333
repositories_utils_map = self.get_repositories_utils(repositories)
13391334
if not repositories_utils_map:
@@ -1342,6 +1337,12 @@ def export_to_ocp(self, name):
13421337
if not self.install_utils_to_servers(repositories, repositories_utils_map):
13431338
self._call_stdio('warn', 'Failed to install utils to servers')
13441339

1340+
self._call_stdio('verbose', 'get plugins by mocking an ocp repository.')
1341+
# search and get all related plugins using a mock ocp repository
1342+
mock_ocp_repository = Repository(const.COMP_OCP_SERVER_CE, "/")
1343+
mock_ocp_repository.version = "4.2.1"
1344+
repositories.extend([mock_ocp_repository])
1345+
self.set_deploy(None)
13451346
workflow = self.get_workflows('take_over', repositories=[mock_ocp_repository] + self.repositories, no_found_act='ignore')
13461347
if not self.run_workflow(workflow, deploy_config=deploy_config, repositories=[mock_ocp_repository] + self.repositories, no_found_act='ignore', **{mock_ocp_repository.name: {'cluster_config': cluster_config, 'clients': ssh_clients}}):
13471348
return False

plugins/general/0.1/chown_dir.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def dir_read_check(client, path):
7272
if not new_client.execute_command(chown_cmd):
7373
stdio.stop_loading('stop_loading', 'fail')
7474
return False
75+
chown_dir_flags = False
7576
dir_read_check(new_client, server_config['home_path'])
7677

7778
return plugin_context.return_true()

plugins/ocp-server/4.2.1/connect.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,27 @@ def status(self, stdio=None):
7676
return False
7777

7878
def info(self, stdio=None):
79-
resp = self._request('GET', '/api/v2/info', stdio=stdio)
79+
resp = self._request('GET', '/api/v2/info', stdio=stdio, auth=self.auth)
8080
if resp.code == 200:
8181
return resp.content
8282

8383
def upload_packages(self, files, stdio=None):
84-
resp = self._request('POST', '/api/v2/software-packages', files=files, stdio=stdio)
84+
resp = self._request('POST', '/api/v2/software-packages', files=files, stdio=stdio, auth=self.auth)
8585
if resp.code == 200:
8686
return resp.content
8787

8888
def take_over_precheck(self, data, stdio=None):
89-
resp = self._request('POST', '/api/v2/ob/clusters/takeOverPreCheck', data=data, stdio=stdio)
89+
resp = self._request('POST', '/api/v2/ob/clusters/takeOverPreCheck', data=data, stdio=stdio, auth=self.auth)
9090
if resp.code == 200:
9191
return resp.content
9292

9393
def get_host_types(self, stdio=None):
94-
resp = self._request('GET', '/api/v2/compute/hostTypes', stdio=stdio)
94+
resp = self._request('GET', '/api/v2/compute/hostTypes', stdio=stdio, auth=self.auth)
9595
if resp.code == 200:
9696
return resp.content
9797

9898
def create_host_type(self, data, stdio=None):
99-
resp = self._request('POST', '/api/v2/compute/hostTypes', data=data, stdio=stdio)
99+
resp = self._request('POST', '/api/v2/compute/hostTypes', data=data, stdio=stdio, auth=self.auth)
100100
if resp.code == 200:
101101
return resp.content
102102
else:
@@ -106,7 +106,7 @@ def create_host_type(self, data, stdio=None):
106106
raise Exception("failed to create host type: %s" % msg)
107107

108108
def list_credentials(self, stdio=None):
109-
resp = self._request('GET', '/api/v2/profiles/me/credentials', stdio=stdio)
109+
resp = self._request('GET', '/api/v2/profiles/me/credentials', stdio=stdio, auth=self.auth)
110110
if resp.code == 200:
111111
return resp.content
112112
else:
@@ -116,7 +116,7 @@ def list_credentials(self, stdio=None):
116116
raise Exception("failed to query credentials: %s" % msg)
117117

118118
def create_credential(self, data, stdio=None):
119-
resp = self._request('POST', '/api/v2/profiles/me/credentials', data=data, stdio=stdio)
119+
resp = self._request('POST', '/api/v2/profiles/me/credentials', data=data, stdio=stdio, auth=self.auth)
120120
if resp.code == 200:
121121
return resp.content
122122
else:
@@ -126,7 +126,7 @@ def create_credential(self, data, stdio=None):
126126
raise Exception("failed to create credential: %s" % msg)
127127

128128
def take_over(self, data, stdio=None):
129-
resp = self._request('POST', '/api/v2/ob/clusters/takeOver', data=data, stdio=stdio)
129+
resp = self._request('POST', '/api/v2/ob/clusters/takeOver', data=data, stdio=stdio, auth=self.auth)
130130
if resp.code == 200:
131131
return resp.content
132132
else:
@@ -135,14 +135,14 @@ def take_over(self, data, stdio=None):
135135
msg = resp.content['error']['message']
136136
raise Exception("failed to do take over: %s" % msg)
137137

138-
def _request(self, method, api, data=None, files=None, retry=5, stdio=None):
138+
def _request(self, method, api, data=None, files=None, retry=5, stdio=None, auth=None):
139139
url = self.url_prefix + api
140140
headers = {'Content-Type': 'application/json'} if not files else {}
141141
try:
142142
if data is not None:
143143
data = json.dumps(data)
144144
stdio.verbose('send http request method: {}, url: {}, data: {}, files: {}'.format(method, url, data, files))
145-
resp = requests.request(method, url, data=data, files=files, verify=False, headers=headers, auth=self.auth)
145+
resp = requests.request(method, url, data=data, files=files, verify=False, headers=headers, auth=auth)
146146
return_code = resp.status_code
147147
content = resp.content
148148
except Exception as e:

plugins/ocp-server/4.2.1/start.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from tool import get_option
3030

3131

32-
def start(plugin_context, start_env=None, *args, **kwargs):
32+
def start(plugin_context, multi_process_flag=False, start_env=None, *args, **kwargs):
3333

3434
EXCLUDE_KEYS = plugin_context.get_variable('EXCLUDE_KEYS')
3535
CONFIG_MAPPER = plugin_context.get_variable('CONFIG_MAPPER')
@@ -146,7 +146,7 @@ def start(plugin_context, start_env=None, *args, **kwargs):
146146
success = False
147147
continue
148148
client.write_file(server_pid[server], os.path.join(home_path, 'run/ocp-server.pid'))
149-
if len(cluster_config.servers) > 1:
149+
if not multi_process_flag and len(cluster_config.servers) > 1:
150150
break
151151
if len(cluster_config.servers) > 1 and node_num == 1:
152152
time.sleep(60)

web/src/component/MetaDBConfig/DataBaseNodeConfig.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { useEffect, useState } from 'react';
1010
import { useModel } from 'umi';
1111

1212
import ServerTags from '@/pages/Obdeploy/ServerTags';
13-
import { serversValidator } from '@/utils';
1413
import { getAllServers } from '@/utils/helper';
1514
import styles from './index.less';
15+
import { IPserversValidator } from '@/utils';
1616

1717
interface DataBaseNodeConfigProps {
1818
tableFormRef: React.MutableRefObject<
@@ -151,7 +151,14 @@ export default function DataBaseNodeConfig({
151151
},
152152
{
153153
validator: (_: any, value: string[]) => {
154-
return serversValidator(_, value, 'OBServer');
154+
return IPserversValidator(
155+
_,
156+
value,
157+
allOBServer,
158+
'OBServer',
159+
allZoneOBServer,
160+
finalValidate,
161+
);
155162
},
156163
},
157164
],

web/src/pages/Obdeploy/NodeConfig.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { getObdInfo } from '@/services/ob-deploy-web/Info';
2-
import { getErrorInfo, handleQuit, serverReg, serversValidator } from '@/utils';
2+
import {
3+
getErrorInfo,
4+
handleQuit,
5+
IPserversValidator,
6+
serverReg,
7+
serversValidator,
8+
} from '@/utils';
39
import { getAllServers } from '@/utils/helper';
410
import { intl } from '@/utils/intl';
511
import useRequest from '@/utils/useRequest';
@@ -59,7 +65,12 @@ export default function NodeConfig() {
5965
errorsList,
6066
} = useModel('global');
6167
const { components = {}, auth, home_path } = configData || {};
62-
const { oceanbase = {}, ocpexpress = {}, obproxy = {}, obconfigserver = {} } = components;
68+
const {
69+
oceanbase = {},
70+
ocpexpress = {},
71+
obproxy = {},
72+
obconfigserver = {},
73+
} = components;
6374
const [form] = ProForm.useForm();
6475
const [editableForm] = ProForm.useForm();
6576
const finalValidate = useRef<boolean>(false);
@@ -167,7 +178,6 @@ export default function NodeConfig() {
167178
servers: item?.servers?.map((server) => ({ ip: server })),
168179
})),
169180
};
170-
171181
setConfigData({
172182
...configData,
173183
components: newComponents,
@@ -458,7 +468,14 @@ export default function NodeConfig() {
458468
},
459469
{
460470
validator: (_: any, value: string[]) =>
461-
serversValidator(_, value, 'OBServer'),
471+
IPserversValidator(
472+
_,
473+
value,
474+
allOBServer,
475+
'OBServer',
476+
allZoneOBServer,
477+
finalValidate,
478+
),
462479
},
463480
],
464481
},
@@ -643,7 +660,6 @@ export default function NodeConfig() {
643660
editableItem?.id,
644661
'servers',
645662
]);
646-
647663
if (editorServers.length) {
648664
if (!rootService || !editorServers.includes(rootService)) {
649665
newRootService = editorServers[0];

web/src/utils/index.tsx

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,125 @@ export const updateClusterNameReg = /^[a-zA-Z][a-zA-Z0-9_-]{0,30}[a-zA-Z0-9]$/;
225225
//用户格式:以英文字母开头,可包含英文、数字、下划线和连字符,且不超过32位
226226
export const nameReg = /^[a-zA-Z][a-zA-Z0-9_-]{0,31}$/;
227227

228+
const checkIsRepeatByAllServers = (allZoneServers: any, id: string) => {
229+
let currentServers: string[] = [],
230+
otherServers: string[] = [];
231+
Object.keys(allZoneServers).forEach((key) => {
232+
if (id === key) {
233+
currentServers = [...allZoneServers[key]];
234+
} else {
235+
otherServers = [...otherServers, ...allZoneServers[key]];
236+
}
237+
});
238+
for (let server of currentServers) {
239+
if (otherServers.includes(server)) {
240+
return true;
241+
}
242+
}
243+
return false;
244+
};
245+
246+
const checkIp = (value: string[], type: 'OBServer' | 'OBProxy'): ResultType => {
247+
let response: ResultType = { success: false, msg: '' };
248+
if (value && value.length) {
249+
value.some((item) => {
250+
response.success = serverReg.test(item.trim());
251+
return !serverReg.test(item.trim());
252+
});
253+
}
254+
if (!response.success) {
255+
response.msg =
256+
type === 'OBServer'
257+
? intl.formatMessage({
258+
id: 'OBD.src.utils.EnterTheCorrectIpAddress',
259+
defaultMessage: '请输入正确的 IP 地址',
260+
})
261+
: intl.formatMessage({
262+
id: 'OBD.src.utils.SelectTheCorrectObproxyNode',
263+
defaultMessage: '请选择正确的 OBProxy 节点',
264+
});
265+
}
266+
return response;
267+
};
268+
269+
const checkIsRepeatByPreServers = (
270+
preAllServers: string[],
271+
inputServer: string,
272+
) => {
273+
if (preAllServers.includes(inputServer)) {
274+
return true;
275+
}
276+
return false;
277+
};
278+
279+
const checkRepeat = (
280+
finalValidate,
281+
allZoneServers,
282+
id,
283+
inputServer,
284+
preAllServers,
285+
type,
286+
) => {
287+
let response: ResultType = { msg: '', success: true };
288+
if (type === 'OBProxy') return response;
289+
if (finalValidate.current) {
290+
response.success = !checkIsRepeatByAllServers(allZoneServers, id);
291+
} else {
292+
response.success = !checkIsRepeatByPreServers(preAllServers, inputServer);
293+
}
294+
if (!response.success) {
295+
response.msg = intl.formatMessage({
296+
id: 'OBD.src.utils.DoNotEnterDuplicateNodes',
297+
defaultMessage: '禁止输入重复节点',
298+
});
299+
}
300+
return response;
301+
};
302+
303+
type ResultType = {
304+
success: boolean;
305+
msg: string;
306+
};
307+
const resultHandlePipeline = (...results: ResultType[]): ResultType => {
308+
for (let result of results) {
309+
if (!result.success) {
310+
return result;
311+
}
312+
}
313+
return {
314+
success: true,
315+
msg: '',
316+
};
317+
};
318+
export const IPserversValidator = (
319+
_: any,
320+
value: string[],
321+
preAllServers: string[],
322+
type: 'OBServer' | 'OBProxy',
323+
allZoneServers?: any,
324+
finalValidate?: any,
325+
) => {
326+
let result: ResultType = {
327+
success: false,
328+
msg: '',
329+
},
330+
inputServer = value[0];
331+
let id = _.field?.split('.')[0];
332+
result = resultHandlePipeline(
333+
checkIp(value, type),
334+
checkRepeat(
335+
finalValidate,
336+
allZoneServers,
337+
id,
338+
inputServer,
339+
preAllServers,
340+
type,
341+
),
342+
);
343+
if (!result.success) return Promise.reject(new Error(result.msg));
344+
return Promise.resolve();
345+
};
346+
228347
export const ocpServersValidator = (_: any, value: string[]) => {
229348
let validtor = true;
230349
if (value && value.length) {

workflows/ocp-server/4.2.1/add_component.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def add_component(plugin_context, workflow, *args, **kwargs):
2828

2929
workflow.add(const.STAGE_SECOND, 'parameter_pre', 'ocp_const', 'cursor_check', 'start', 'health_check', 'stop_pre')
3030
workflow.add_with_component(const.STAGE_SECOND, 'general', 'stop')
31-
workflow.add(const.STAGE_SECOND, 'start', 'health_check', 'bootstrap')
31+
workflow.add_with_kwargs(const.STAGE_SECOND, {'multi_process_flag': True}, 'start')
32+
workflow.add(const.STAGE_SECOND, 'health_check', 'bootstrap')
3233

3334
plugin_context.return_true()

workflows/ocp-server/4.2.1/reinstall.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@
2525

2626
def reinstall(plugin_context, workflow, *args, **kwargs):
2727
workflow.add(const.STAGE_FIRST, 'parameter_pre')
28-
workflow.add_with_kwargs(const.STAGE_FIRST, {'is_reinstall': True}, 'cursor_check', 'start', 'health_check', 'stop', 'start', 'health_check')
28+
workflow.add_with_kwargs(const.STAGE_FIRST, {'is_reinstall': True}, 'cursor_check', 'start')
29+
workflow.add_with_component(const.STAGE_FIRST, 'general', 'stop')
30+
workflow.add_with_kwargs(const.STAGE_FIRST, {'is_reinstall': True, 'multi_process_flag': True}, 'start', 'health_check')
2931
plugin_context.return_true()

workflows/ocp-server/4.2.1/restart.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def restart(plugin_context, workflow, *args, **kwargs):
3838
if not plugin_context.cluster_config.depends:
3939
workflow.add_with_kwargs(const.STAGE_FIRST, {'need_connect': False}, 'cursor_check')
4040
workflow.add_with_kwargs(const.STAGE_FIRST, {'cursor': cursor if cursor else None, 'need_bootstrap': need_bootstrap,
41-
'clients': new_clients if new_clients else clients, 'new_cluster_config': new_cluster_config,
41+
'clients': new_clients if new_clients else clients, 'new_cluster_config': new_cluster_config, 'multi_process_flag': True,
4242
'cluster_config': new_cluster_config if new_cluster_config else cluster_config}, 'parameter_pre', 'ocp_const', 'start', 'health_check')
4343

4444
finally_plugins = plugin_context.get_variable('finally_plugins')
@@ -55,6 +55,3 @@ def restart(plugin_context, workflow, *args, **kwargs):
5555

5656
return plugin_context.return_true()
5757

58-
59-
60-

0 commit comments

Comments
 (0)