Skip to content

Commit 0d7ad75

Browse files
committed
[Improvenet: add ZSha2Helper]
1 parent 35ca1ac commit 0d7ad75

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.zstack.utils.zsha2;
2+
3+
import org.zstack.utils.ShellResult;
4+
import org.zstack.utils.ShellUtils;
5+
import org.zstack.utils.Utils;
6+
import org.zstack.utils.gson.JSONObjectUtil;
7+
import org.zstack.utils.logging.CLogger;
8+
import org.zstack.utils.path.PathUtil;
9+
10+
11+
/**
12+
* Created by mingjian.deng on 2020/4/2.
13+
*/
14+
public class ZSha2Helper {
15+
private static final CLogger logger = Utils.getLogger(ZSha2Helper.class);
16+
17+
public static boolean isMNHaEnvironment() {
18+
return PathUtil.exists("/usr/local/bin/zsha2");
19+
}
20+
21+
public static ZSha2Info getInfo() {
22+
ShellResult result = ShellUtils.runAndReturn("sudo -i /usr/local/bin/zsha2 status", false);
23+
if (!result.isReturnCode(0)) {
24+
throw new RuntimeException(String.format("cannot get zsha2 status, because %s", result.getStderr()));
25+
}
26+
27+
result = ShellUtils.runAndReturn("/usr/local/bin/zsha2 show-config");
28+
if (!result.isReturnCode(0)) {
29+
throw new RuntimeException(String.format("cannot get zsha2 config, because %s, maybe you need upgrade zsha2", result.getStderr()));
30+
}
31+
32+
ZSha2Info info = JSONObjectUtil.toObject(result.getStdout(), ZSha2Info.class);
33+
34+
info.setMaster(ShellUtils.runAndReturn(String.format(
35+
"ip addr show %s | grep -q '[^0-9]%s[^0-9]'", info.getNic(), info.getDbvip())).isReturnCode(0));
36+
return info;
37+
}
38+
39+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.zstack.utils.zsha2;
2+
3+
/**
4+
* Created by mingjian.deng on 2020/4/2.
5+
*/
6+
public class ZSha2Info {
7+
private String nodeip;
8+
private String peerip;
9+
private String dbvip;
10+
private String nic;
11+
private boolean isMaster;
12+
13+
public String getNodeip() {
14+
return nodeip;
15+
}
16+
17+
public void setNodeip(String nodeip) {
18+
this.nodeip = nodeip;
19+
}
20+
21+
public String getPeerip() {
22+
return peerip;
23+
}
24+
25+
public void setPeerip(String peerip) {
26+
this.peerip = peerip;
27+
}
28+
29+
public String getDbvip() {
30+
return dbvip;
31+
}
32+
33+
public void setDbvip(String dbvip) {
34+
this.dbvip = dbvip;
35+
}
36+
37+
public String getNic() {
38+
return nic;
39+
}
40+
41+
public void setNic(String nic) {
42+
this.nic = nic;
43+
}
44+
45+
public boolean isMaster() {
46+
return isMaster;
47+
}
48+
49+
public void setMaster(boolean master) {
50+
isMaster = master;
51+
}
52+
}

0 commit comments

Comments
 (0)