<template>
|
<div class="all">
|
<div class="cluster-guanli" v-if="showCurCluster">
|
<cloud-node :nodes="innerNodes"></cloud-node>
|
|
<div class="bar">
|
<div class="title">集群名称</div>
|
<div class="input-area">
|
<div class="text" v-show="!isFillingName">
|
{{ ruleForm.clustername }}
|
</div>
|
<el-input
|
v-show="isFillingName"
|
size="mini"
|
v-model="selfForm.clustername"
|
placeholder="请输入内容"
|
></el-input>
|
<span
|
class="icon iconfont"
|
@click="startInput(1)"
|
v-show="!isFillingName"
|
></span
|
>
|
<span
|
class="icon iconfont"
|
@click="clearInput(1)"
|
v-show="isFillingName"
|
></span
|
>
|
<span
|
class="icon iconfont"
|
@click="updateCluster(1)"
|
v-show="isFillingName"
|
></span
|
>
|
</div>
|
</div>
|
<div class="bar">
|
<div class="title">集群ID</div>
|
<div class="input-area">
|
<div class="text">{{ clusterid }}</div>
|
</div>
|
</div>
|
<div class="bar">
|
<div class="title">集群密码</div>
|
<div class="input-area">
|
<div class="text">{{ ruleForm.clusterpwd }}</div>
|
</div>
|
</div>
|
<div class="bar">
|
<div class="title">集群IP</div>
|
<div class="input-area">
|
<div class="text" v-show="!isFillingIp">{{ ruleForm.virtualIp }}</div>
|
|
<ip-input
|
v-if="isFillingIp"
|
:ip="selfForm.virtualIp"
|
:on-blur="onIpBlur"
|
class="ip-input-comp"
|
></ip-input>
|
<span
|
class="icon iconfont"
|
v-show="!isFillingIp"
|
@click="startInput(2)"
|
></span
|
>
|
<span
|
class="icon iconfont"
|
@click="clearInput(2)"
|
v-show="isFillingIp"
|
></span
|
>
|
<span
|
class="icon iconfont"
|
@click="updateCluster(2)"
|
v-show="isFillingIp"
|
></span
|
>
|
</div>
|
</div>
|
|
<div class="exit" @click="exitCluster">退出集群</div>
|
</div>
|
|
<div class="cluster-content">
|
<div class="cluster-center" ref="left" v-if="!showCurCluster">
|
<div class="menu-item" @click="isCreate = true">创建集群</div>
|
<div class="menu-item" @click="isCreate = false">加入已有集群</div>
|
</div>
|
<div class="cluster-right" v-if="!showCurCluster">
|
<div class="create-new" v-if="isCreate">
|
<el-form
|
:model="ruleForm"
|
:rules="rules"
|
ref="ruleForm"
|
label-width="150px"
|
>
|
<el-form-item label="集群名称" prop="clustername">
|
<el-input
|
v-model="ruleForm.clustername"
|
placeholder="手动输入, 如“集群A”"
|
size="small"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="集群ID">
|
<el-input
|
v-model="clusterid"
|
placeholder="不允许输入,保存后回显"
|
disabled
|
size="small"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="集群密码" prop="clusterpwd">
|
<el-input
|
v-model="ruleForm.clusterpwd"
|
placeholder="请输入6位密码,或点击生成"
|
size="small"
|
>
|
<el-button type="text" slot="suffix" @click="getPSW"
|
>生成密码</el-button
|
>
|
</el-input>
|
</el-form-item>
|
<el-form-item label="集群IP" prop="virtualIp">
|
<ip-input
|
:ip="ruleForm.virtualIp"
|
:on-blur="onIpBlur"
|
class="ip-input-comp"
|
></ip-input>
|
</el-form-item>
|
</el-form>
|
<div class="save-btn" @click="saveCluster('ruleForm')">保存</div>
|
</div>
|
<div class="join-exist" v-if="!isCreate">
|
<el-form
|
:model="joinForm"
|
:rules="joinRules"
|
ref="joinForm"
|
class="join-form"
|
label-width="150px"
|
v-loading="joinLoading"
|
>
|
<el-form-item label="集群ID" prop="clusterid">
|
<el-input v-model="joinForm.clusterid" size="small"></el-input>
|
</el-form-item>
|
|
<el-form-item label="IP地址" prop="clusterip">
|
<el-input
|
v-model="joinForm.clusterip"
|
placeholder="请输入集群内任意IP地址"
|
size="small"
|
autocomplete="new-password"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="集群密码" prop="clusterpwd">
|
<el-input
|
v-model="joinForm.clusterpwd"
|
placeholder="请输入集群密码"
|
show-password
|
autocomplete="new-password"
|
size="small"
|
>
|
<el-button
|
type="text"
|
slot="suffix"
|
@click="searchColony"
|
v-show="!searchDis"
|
>搜索集群</el-button
|
>
|
<el-button
|
type="text"
|
slot="suffix"
|
v-show="searchDis"
|
@click="stopSearch"
|
>
|
<i class="el-icon-loading"></i>停止搜索
|
</el-button>
|
</el-input>
|
</el-form-item>
|
</el-form>
|
|
<div class="save-btn" @click="join('joinForm')">加入集群</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import {
|
createSerfCluster,
|
randomPwd,
|
search,
|
getSearchNodes,
|
stopSearching,
|
findCluster,
|
updateClusterName,
|
joinCluster,
|
leave,
|
getVrrp,
|
setVrrp,
|
createESNode,
|
addESNode,
|
getEsClusterInfo,
|
} from "@/api/clusterManage";
|
import cloudNode from "../components/CloudNode";
|
import ipInput from "@/components/subComponents/IPInput";
|
import { isIPv4 } from "@/scripts/validate";
|
|
export default {
|
data() {
|
const checkPwd = (rule, value, callback) => {
|
if (!value) {
|
return callback(new Error("密码不能为空"));
|
}
|
setTimeout(() => {
|
if (value.length != 6) {
|
callback(new Error("密码应为6位!"));
|
} else {
|
callback();
|
}
|
}, 1000);
|
};
|
return {
|
innerNodes: [],
|
intervalTimer: null,
|
isFillingName: false,
|
isFillingIp: false,
|
inputName: "",
|
inputIp: "",
|
serverIp: "",
|
members: [],
|
virtualIp: "192.168.1.188",
|
searchDis: false,
|
ruleForm: {
|
clustername: "",
|
clusterpwd: "",
|
virtualIp: "",
|
},
|
selfForm: {
|
virtualIp: "",
|
clustername: "",
|
},
|
joinForm: {
|
clusterid: "",
|
clusterip: "",
|
clusterpwd: "",
|
},
|
isSearch: false,
|
showCurCluster: true,
|
loading: false,
|
joinLoading: false,
|
isHasColony: false,
|
clusterid: "",
|
searchNum: "",
|
scheduleId: "",
|
isCreate: true,
|
rules: {
|
clustername: [
|
{ required: true, message: "请输入集群名称", trigger: "change" },
|
],
|
clusterpwd: [{ validator: checkPwd, trigger: "change" }],
|
virtualIp: [{ required: true, validator: isIPv4, trigger: "change" }],
|
},
|
joinRules: {
|
clusterid: [
|
{ required: true, message: "请输入集群ID", trigger: "change" },
|
],
|
clusterip: [{ required: true, validator: isIPv4, trigger: "change" }],
|
clusterpwd: [{ validator: checkPwd, trigger: "change" }],
|
},
|
};
|
},
|
components: {
|
cloudNode,
|
ipInput,
|
},
|
mounted() {
|
this.findCluster();
|
let _this = this;
|
this.intervalTimer = setInterval(() => {
|
_this.findCluster();
|
}, 30000);
|
},
|
beforeDestroy() {
|
clearInterval(this.intervalTimer);
|
},
|
props: ["barName"],
|
methods: {
|
async createCluster(json) {
|
let res = await createSerfCluster(json);
|
this.$notify({
|
title: res.success ? "成功" : "失败",
|
message: res.msg,
|
type: res.success ? "success" : "error",
|
});
|
},
|
//搜索集群
|
async getSearchNodes() {
|
let res = await getSearchNodes();
|
if (res && res.success) {
|
let list = res.data.map((i) => {
|
let obj = {};
|
obj.cluster_id = i.clusterID ? i.clusterID : "";
|
obj.create_time = i.create_time ? i.create_time : "";
|
obj.id = i.nodeID ? i.nodeID : "";
|
obj.node_id = i.nodeID ? i.nodeID : "";
|
obj.Address = i.nodeAddress ? i.nodeAddress : "";
|
obj.nodeName = i.nodeAddress ? i.nodeAddress : "";
|
obj.role = i.role ? i.role : "pc";
|
return obj;
|
});
|
list.map((i) => {
|
let found = this.members.find((element) => {
|
return element.node_id === i.node_id;
|
});
|
if (found === undefined) {
|
this.members.push(i);
|
}
|
});
|
}
|
},
|
async joinCluster(json) {
|
let res = await joinCluster(json);
|
if (res.success) {
|
this.members = []
|
}
|
this.$notify({
|
title: res.success ? "成功" : "失败",
|
message: res.msg,
|
type: res.success ? "success" : "error"
|
});
|
},
|
join(formName) {
|
let _this = this;
|
this.$refs[formName].validate((valid) => {
|
if (valid) {
|
_this.joinLoading = true;
|
let nodeIps = _this.members.map((i) => {
|
return i.Address;
|
});
|
let data = {
|
clusterId: _this.joinForm.clusterid,
|
password: _this.joinForm.clusterpwd,
|
nodeIps: [_this.joinForm.clusterip],
|
};
|
_this
|
.joinCluster(data)
|
.then(() => {
|
_this.joinLoading = false;
|
_this.findCluster();
|
})
|
.catch((e) => {
|
_this.joinLoading = false;
|
});
|
} else {
|
return false;
|
}
|
});
|
},
|
setSchedule() {
|
this.scheduleId = window.setInterval(() => {
|
this.getSearchNodes();
|
}, 1000);
|
},
|
async searchColony() {
|
this.isSearch = true;
|
this.$refs["joinForm"].clearValidate();
|
this.$refs["joinForm"].validateField("clusterpwd");
|
if (this.joinForm.clusterpwd.trim().length === 6) {
|
this.members = [];
|
const data = {
|
password: this.joinForm.clusterpwd,
|
};
|
this.search(data)
|
.then(() => {
|
this.setSchedule();
|
})
|
.catch(() => {
|
this.searchDis = false;
|
this.loading = false;
|
this.isSearch = false;
|
});
|
} else {
|
this.searchDis = false;
|
this.loading = false;
|
this.isSearch = false;
|
return false;
|
}
|
},
|
async search(data) {
|
let res = await search(data);
|
if (res && res.success) {
|
this.searchNum = res.data;
|
}
|
this.searchDis = true;
|
this.loading = true;
|
window.setTimeout(() => {
|
this.stopSearch();
|
}, 10 * 1000);
|
},
|
async stopSearch() {
|
if (!this.loading) {
|
return true;
|
}
|
stopSearching({
|
searchNum: this.searchNum,
|
})
|
.then((res) => {
|
this.loading = false;
|
this.searchDis = false;
|
window.clearInterval(this.scheduleId);
|
})
|
.catch((err) => {
|
this.$notify({
|
type: "error",
|
duration: 1000,
|
message: "停止搜索报错!",
|
});
|
});
|
},
|
saveCluster(formName) {
|
this.$refs[formName].validate((valid) => {
|
if (valid) {
|
let data = {
|
clusterId: this.clusterid,
|
clusterName: this.ruleForm.clustername,
|
password: this.ruleForm.clusterpwd,
|
virtualIp: this.ruleForm.virtualIp,
|
};
|
this.createCluster(data).then(() => {
|
this.findCluster();
|
});
|
} else {
|
return false;
|
}
|
});
|
},
|
getPSW() {
|
var chars =
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
var uuid = [];
|
|
for (let i = 0; i < 6; i++) {
|
uuid[i] = chars[0 | (Math.random() * 50)];
|
}
|
|
this.ruleForm.clusterpwd = uuid.join("");
|
},
|
exitCluster() {
|
clearInterval(this.intervalTimer);
|
this.showCurCluster = false;
|
this.ruleForm.virtualIp = "";
|
this.ruleForm.clustername = "";
|
this.ruleForm.clusterpwd = "";
|
this.clusterid = "";
|
},
|
clearInput(typ) {
|
if (typ == 1) {
|
this.selfForm.clustername = "";
|
this.isFillingName = false;
|
} else {
|
this.selfForm.virtualIp = "";
|
this.isFillingIp = false;
|
}
|
},
|
async randomPwd() {
|
let res = await randomPwd();
|
if (res && res.success) {
|
this.ruleForm.clusterpwd = res.data;
|
}
|
},
|
startInput(typ) {
|
if (typ == 1) {
|
this.selfForm.clustername = this.ruleForm.clustername;
|
this.isFillingName = true;
|
} else {
|
this.selfForm.virtualIp = this.ruleForm.virtualIp;
|
this.isFillingIp = true;
|
}
|
},
|
onIpBlur(ip) {
|
console.log(ip);
|
this.ruleForm.virtualIp = ip;
|
},
|
async updateCluster(v) {
|
if (v == 1) {
|
this.ruleForm.clustername = this.selfForm.clustername;
|
}
|
if (this.ruleForm.clustername === "") {
|
this.$message({
|
type: "error",
|
message: "集群名称不能为空",
|
});
|
return;
|
}
|
const data = {
|
clusterName: this.ruleForm.clustername,
|
virtualIp: this.ruleForm.virtualIp,
|
};
|
let res = await updateClusterName(data);
|
if (res.success) {
|
this.findCluster();
|
}
|
this.$notify({
|
title: res.success ? "成功" : "失败",
|
message: res.msg,
|
type: res.success ? "success" : "error",
|
});
|
this.isFillingIp = false;
|
this.isFillingName = false;
|
},
|
async findCluster() {
|
let res = await findCluster();
|
if (res && res.success) {
|
if (res.data && res.data.clusterId) {
|
this.isHasColony = true;
|
this.clusterid = res.data.clusterId;
|
this.ruleForm.clustername = res.data.clusterName;
|
this.ruleForm.clusterpwd = "******";
|
this.ruleForm.virtualIp = res.data.virtualIp;
|
this.isSearch = false;
|
this.innerNodes = res.data.nodes.map((i) => {
|
let obj = {};
|
obj.device_type = i.device_type;
|
obj.workType = i.device_type.substr(2, 2);
|
obj.hardwareType = i.device_type.substr(4, 2);
|
obj.cluster_id = i.cluster_id;
|
obj.clusterName = res.data.clusterName;
|
obj.create_time = i.create_time;
|
obj.id = i.id;
|
obj.node_id = i.node_id;
|
obj.node_ip = i.node_ip;
|
obj.nodeName = i.node_name;
|
obj.Address = i.node_ip;
|
obj.role = i.drift_state ? i.drift_state : "pc";
|
return obj;
|
});
|
} else {
|
this.isHasColony = false;
|
}
|
}
|
},
|
clearInnerNodes() {
|
this.innerNodes = [];
|
},
|
},
|
};
|
</script>
|
<style lang="scss">
|
.all {
|
width: 100%;
|
}
|
.cluster-guanli {
|
margin: 0 auto;
|
width: 520px;
|
.bar {
|
height: 40px;
|
background-color: rgba(248, 248, 248, 1);
|
margin-bottom: 10px;
|
display: flex;
|
box-sizing: border-box;
|
padding: 0 20px;
|
justify-content: space-between;
|
align-items: center;
|
.input-area {
|
display: flex;
|
width: 340px;
|
height: 30px;
|
line-height: 30px;
|
justify-content: inherit;
|
// padding: 0 20px;
|
box-sizing: border-box;
|
}
|
}
|
.exit {
|
background-color: #3d68e1;
|
width: 240px;
|
height: 40px;
|
margin: 0 auto;
|
border-radius: 10px;
|
color: #fff;
|
line-height: 40px;
|
font-size: 14px;
|
margin-top: 20px;
|
}
|
}
|
.cluster-content {
|
height: 100%;
|
display: flex;
|
flex-direction: row;
|
flex: 1;
|
flex-basis: auto;
|
box-sizing: border-box;
|
.cluster-center {
|
height: 100%;
|
width: 280px;
|
overflow: auto;
|
box-sizing: border-box;
|
flex-shrink: 0;
|
padding: 10px;
|
// background-color: lightpink;
|
.menu-item {
|
background-color: #f8f8f8;
|
height: 40px;
|
margin-bottom: 10px;
|
border-radius: 8px;
|
line-height: 40px;
|
font-size: 14px;
|
}
|
}
|
.cluster-right {
|
flex: 1;
|
flex-basis: auto;
|
overflow: auto;
|
// background-color: rgba(240, 242, 245, 1);
|
box-sizing: border-box;
|
position: relative;
|
padding: 20px 40px;
|
// .create-new .join-exist {
|
.el-form-item.is-required:not(.is-no-asterisk)
|
> .el-form-item__label:before,
|
.el-form-item.is-required:not(.is-no-asterisk)
|
.el-form-item__label-wrap
|
> .el-form-item__label:before {
|
display: none;
|
}
|
.el-form-item {
|
margin-bottom: 10px;
|
height: 50px;
|
background: #f8f8f8;
|
padding: 4px 20px;
|
-webkit-box-sizing: border-box;
|
box-sizing: border-box;
|
border-radius: 10px;
|
.el-form-item__label {
|
text-align: left;
|
line-height: 42px;
|
}
|
}
|
.el-form-item__content {
|
line-height: 40px;
|
position: relative;
|
font-size: 14px;
|
}
|
.ip-input-container {
|
max-width: none !important;
|
}
|
// }
|
.ntp-bar {
|
height: 40px;
|
background-color: rgba(248, 248, 248, 1);
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
padding: 0 10px;
|
border-radius: 10px;
|
margin-bottom: 10px;
|
.title {
|
min-width: 70px;
|
}
|
.input-area {
|
min-width: 400px;
|
height: 30px;
|
background-color: rgba(240, 240, 240, 1);
|
border-radius: 10px;
|
line-height: 30px;
|
font-size: 14px;
|
}
|
}
|
.int-bar {
|
height: 40px;
|
background-color: rgba(248, 248, 248, 1);
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
padding: 0 10px;
|
border-radius: 10px;
|
margin-bottom: 10px;
|
.title {
|
min-width: 70px;
|
}
|
.right {
|
min-width: 400px;
|
display: flex;
|
align-items: center;
|
height: 30px;
|
.input-area {
|
background-color: rgba(240, 240, 240, 1);
|
border-radius: 10px;
|
line-height: 30px;
|
width: -webkit-fill-available;
|
|
font-size: 14px;
|
}
|
.test {
|
width: 70px;
|
}
|
}
|
}
|
.save-btn {
|
background-color: #3d68e1;
|
width: 240px;
|
height: 40px;
|
margin: 0 auto;
|
border-radius: 10px;
|
color: #fff;
|
line-height: 40px;
|
font-size: 14px;
|
margin-top: 20px;
|
}
|
}
|
}
|
</style>
|