zookeeperModel.js
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const model = require('../../../lib/model');
const {DegradeServer} = require('../../models');
const zookeeperHelpers = require('../../zookeeper/zookeeper-helpers');
const _ = require('lodash');
class ZookeeperModel extends model {
constructor(ctx) {
super(ctx);
}
async getConfigAll() {
return await DegradeServer.findAll();
}
async setPath(path, val) {
let degradeServer = await DegradeServer.findOne({
type: 'qcloud'
});
if (_.isEmpty(degradeServer)) {
return false;
}
return zookeeperHelpers.creator(`${degradeServer.ip}:${degradeServer.port}`, path, val, true); // return Boolean
}
async getPath(path) {
let degradeServer = await DegradeServer.findOne({
type: 'qcloud'
});
if (_.isEmpty(degradeServer)) {
return false;
}
return await zookeeperHelpers.getter(`${degradeServer.ip}:${degradeServer.port}`, path);
}
async removePath(path) {
let degradeServer = await DegradeServer.findOne({
type: 'qcloud'
});
if (_.isEmpty(degradeServer)) {
return false;
}
return await zookeeperHelpers.remove(`${degradeServer.ip}:${degradeServer.port}`, path);
}
}
module.exports = ZookeeperModel;