382 lines
14 KiB
JavaScript
382 lines
14 KiB
JavaScript
/// <reference path="../../includes.ts"/>
|
|
/// <reference path="./kubernetesHelpers.ts"/>
|
|
var Kubernetes;
|
|
(function (Kubernetes) {
|
|
Kubernetes.hostPorts = [];
|
|
/**
|
|
* Sorts the the ip field
|
|
*
|
|
* @param ip the ip such as '10.1.2.13'
|
|
* @returns {any}
|
|
*/
|
|
function sortByPodIp(ip) {
|
|
// i guess there is maybe nicer ways of sort this without parsing and slicing
|
|
var regex = /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
|
|
var groups = regex.exec(ip);
|
|
if (angular.isDefined(groups)) {
|
|
var g1 = ("00" + groups[1]).slice(-3);
|
|
var g2 = ("00" + groups[2]).slice(-3);
|
|
var g3 = ("00" + groups[3]).slice(-3);
|
|
var g4 = ("00" + groups[4]).slice(-3);
|
|
var answer = g1 + g2 + g3 + g4;
|
|
return answer;
|
|
}
|
|
else {
|
|
return 0;
|
|
}
|
|
}
|
|
Kubernetes.sortByPodIp = sortByPodIp;
|
|
function ramdomPort() {
|
|
var hostPort = Math.floor(30000 + Math.random() * (65535 - 30000));
|
|
while (Kubernetes.hostPorts.indexOf(hostPort) === 0) {
|
|
hostPort = Math.floor(30000 + Math.random() * (65535 - 30000));
|
|
}
|
|
Kubernetes.hostPorts.push(hostPort);
|
|
return hostPort;
|
|
}
|
|
Kubernetes.ramdomPort = ramdomPort;
|
|
function getRandomString(len) {
|
|
len = len || 32;
|
|
var $chars = 'abcdefhijkmnprstwxyz'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
|
|
var maxPos = $chars.length;
|
|
var pwd = '';
|
|
for (var i = 0; i < len; i++) {
|
|
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
|
|
}
|
|
return pwd;
|
|
}
|
|
Kubernetes.getRandomString = getRandomString;
|
|
var resourceRCTemplate = (function () {
|
|
function resourceRCTemplate() {
|
|
this.image = "oracle:utf8";
|
|
this.names = ["oradata"];
|
|
}
|
|
resourceRCTemplate.prototype.createRC = function (Obj) {
|
|
var labels = {
|
|
"style": "oracle",
|
|
"status": "0",
|
|
"isExtract": Obj.isExtract + "" || "0",
|
|
"isTarget": Obj.isTarget
|
|
};
|
|
for (var item in Obj.labels)
|
|
labels[item] = Obj.labels[item];
|
|
return {
|
|
"apiVersion": Kubernetes.defaultApiVersion,
|
|
"kind": "ReplicationController",
|
|
"metadata": {
|
|
"name": Obj.name,
|
|
"labels": labels,
|
|
"annotations": Obj.annotations
|
|
},
|
|
"spec": {
|
|
replicas: Obj.replicas || 1,
|
|
"template": this.createTemplate(Obj)
|
|
}
|
|
};
|
|
};
|
|
resourceRCTemplate.prototype.createVolumeMounts = function () {
|
|
var volumeMounts = [];
|
|
for (var item in this.names) {
|
|
if (this.names[item] === 'flash-recovery-area')
|
|
volumeMounts.push({
|
|
"name": this.names[item],
|
|
"mountPath": "/opt/oracle/app/flash_recovery_area"
|
|
});
|
|
else
|
|
volumeMounts.push({
|
|
"name": this.names[item],
|
|
"mountPath": "/opt/oracle/app/" + this.names[item]
|
|
});
|
|
}
|
|
return volumeMounts;
|
|
};
|
|
resourceRCTemplate.prototype.createVolumes = function (rootPath) {
|
|
var volumes = [];
|
|
for (var item in this.names) {
|
|
if (this.names[item] === 'flash-recovery-area')
|
|
volumes.push({
|
|
"name": this.names[item],
|
|
"hostPath": {
|
|
"path": rootPath + "flash_recovery_area"
|
|
}
|
|
});
|
|
else
|
|
volumes.push({
|
|
"name": this.names[item],
|
|
"hostPath": {
|
|
"path": rootPath + this.names[item]
|
|
}
|
|
});
|
|
}
|
|
return volumes;
|
|
};
|
|
resourceRCTemplate.prototype.createContainers = function (Obj) {
|
|
var containers = [];
|
|
containers.push({
|
|
"name": "oracle",
|
|
"image": this.image,
|
|
"imagePullPolicy": "IfNotPresent",
|
|
"command": ["/assets/entrypoint.sh"],
|
|
"ports": [{
|
|
"containerPort": 1521,
|
|
"hostPort": Obj.port || ramdomPort()
|
|
}],
|
|
"resources": {
|
|
"cpu": "100m",
|
|
"memory": "3Gi"
|
|
},
|
|
"volumeMounts": this.createVolumeMounts()
|
|
});
|
|
return containers;
|
|
};
|
|
resourceRCTemplate.prototype.createTemplate = function (Obj) {
|
|
return {
|
|
"metadata": {
|
|
//"name": Obj.name,
|
|
"labels": Obj.labels
|
|
},
|
|
"spec": {
|
|
"terminationGracePeriodSeconds": 0,
|
|
"containers": this.createContainers(Obj),
|
|
"volumes": this.createVolumes(Obj.path)
|
|
}
|
|
};
|
|
};
|
|
return resourceRCTemplate;
|
|
})();
|
|
Kubernetes.resourceRCTemplate = resourceRCTemplate;
|
|
function labelToChinese(labels) {
|
|
var answer = {};
|
|
angular.forEach(labels, function (value, key) {
|
|
answer[key] = labelChangeToChines(value, key);
|
|
});
|
|
return answer;
|
|
}
|
|
Kubernetes.labelToChinese = labelToChinese;
|
|
function findSameNameReplicationControllers(replicationControllers, name) {
|
|
var names = [];
|
|
replicationControllers.forEach(function (rc) {
|
|
var rcName = Kubernetes.getName(rc);
|
|
if (rcName.indexof(name) !== -1)
|
|
names.push(rcName);
|
|
});
|
|
if (names.length === 0) {
|
|
return name + "_1";
|
|
}
|
|
else {
|
|
var max = 0;
|
|
names.forEach(function (value) {
|
|
var answer = value.split("_");
|
|
var key = parseInt(answer[1]);
|
|
if (max < key)
|
|
max = key;
|
|
});
|
|
return name + (max + 1);
|
|
}
|
|
}
|
|
Kubernetes.findSameNameReplicationControllers = findSameNameReplicationControllers;
|
|
function isFilterRC(rc) {
|
|
var answer = false;
|
|
angular.forEach(Core.pathGet(rc, ["metadata", "labels"]), function (value, key) {
|
|
if (key === 'isTarget' && value === 'true') {
|
|
answer = true;
|
|
}
|
|
});
|
|
return answer;
|
|
}
|
|
Kubernetes.isFilterRC = isFilterRC;
|
|
function isInclude(rcs, rc) {
|
|
for (var i in rcs) {
|
|
if (Kubernetes.getName(rcs[i]) === Kubernetes.getName(rc))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
Kubernetes.isInclude = isInclude;
|
|
function labelChangeToChines(value, key) {
|
|
var trueValue = '';
|
|
switch (key) {
|
|
case 'type':
|
|
if (value === '01')
|
|
trueValue = '财政';
|
|
else if (value === '02')
|
|
trueValue = '社保';
|
|
else
|
|
trueValue = value;
|
|
break;
|
|
case 'batch':
|
|
if (value === 'A')
|
|
trueValue = '批次A';
|
|
else if (value === 'B')
|
|
trueValue = '批次B';
|
|
else
|
|
trueValue = value;
|
|
break;
|
|
case 'region':
|
|
trueValue = Kubernetes.getCountyByCode(value);
|
|
break;
|
|
case 'system':
|
|
trueValue = Kubernetes.getSystemNameById(value);
|
|
break;
|
|
case 'version':
|
|
var reg = new RegExp('^[0-9]$').exec(value);
|
|
if (reg)
|
|
trueValue = '版本' + reg[0];
|
|
else
|
|
trueValue = value;
|
|
break;
|
|
case 'isTarget':
|
|
if (value === 'true')
|
|
trueValue = '汇总数据库';
|
|
else
|
|
trueValue = value;
|
|
break;
|
|
default:
|
|
trueValue = value;
|
|
}
|
|
return trueValue;
|
|
}
|
|
Kubernetes.labelChangeToChines = labelChangeToChines;
|
|
function checkForExit(replicationControllers, selectItem) {
|
|
for (var index in replicationControllers) {
|
|
var replicas = replicationControllers[index];
|
|
if (Kubernetes.getName(replicas) == selectItem._key && getAnnotationValueBykey(replicas, "year") == selectItem["year"])
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
Kubernetes.checkForExit = checkForExit;
|
|
function getAnnotationValueBykey(replicationController, key) {
|
|
var annotations = Kubernetes.getAnnotations(replicationController);
|
|
if (annotations && annotations != undefined) {
|
|
return annotations[key];
|
|
}
|
|
}
|
|
/*
|
|
启动oracle时检查是否正在迁移
|
|
*/
|
|
function checkForCreateOracle(transferTasks, selectItems) {
|
|
var result = [];
|
|
angular.forEach(selectItems, function (item) {
|
|
if (checkForExitTask(transferTasks, item))
|
|
result.push(item);
|
|
});
|
|
return result;
|
|
}
|
|
Kubernetes.checkForCreateOracle = checkForCreateOracle;
|
|
function checkForExitTask(transferTasks, selectItem) {
|
|
for (var index in transferTasks) {
|
|
var task = transferTasks[index];
|
|
if (task["_key"] == selectItem["_key"] && selectItem["year"] == task.labels.dataYear) {
|
|
if (task.status == 2 || task.status == 3)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
/**
|
|
|
|
**/
|
|
function checkForExtract(replicationControllers) {
|
|
var result = [];
|
|
angular.forEach(replicationControllers, function (replicas) {
|
|
var labels = Kubernetes.getLabels(replicas);
|
|
if (labels["isExtract"] == "1")
|
|
result.push(replicas);
|
|
});
|
|
return result;
|
|
}
|
|
Kubernetes.checkForExtract = checkForExtract;
|
|
function checkIsStartSuccess(replicationControllers) {
|
|
var result = [];
|
|
angular.forEach(replicationControllers, function (replicas) {
|
|
var labels = Kubernetes.getLabels(replicas);
|
|
if (labels["status"] != "2")
|
|
result.push(replicas);
|
|
});
|
|
return result;
|
|
}
|
|
Kubernetes.checkIsStartSuccess = checkIsStartSuccess;
|
|
;
|
|
/*
|
|
检查数据否已挂载使用或正在迁移。
|
|
*/
|
|
function checkForMigration(replicationControllers, transferTasks, selectItem, type) {
|
|
var message = "";
|
|
for (var index in selectItem) {
|
|
var item = selectItem[index];
|
|
var id = null;
|
|
if (type == 'manager')
|
|
id = item.id;
|
|
if (type == 'verify')
|
|
id = item.dataId;
|
|
/*
|
|
检查迁移文件是否正在迁移
|
|
*/
|
|
for (i in transferTasks) {
|
|
/*if(transferTasks[i]["_key"] == item["_key"] && (transferTasks[i]["status"] == "1" || transferTasks[i]["status"] == "0") && item["year"] == transferTasks[i].labels.dataYear){
|
|
message = "数据正在迁移"
|
|
return message;
|
|
}*/
|
|
if (transferTasks[i].fkid == id && (transferTasks[i]["status"] == "1" || transferTasks[i]["status"] == "0")) {
|
|
message = "数据正在迁移";
|
|
return message;
|
|
}
|
|
}
|
|
/**
|
|
数据是否在热区,如果在则需要判断数据是否已启动
|
|
*/
|
|
if (item["mark"] == 1)
|
|
continue;
|
|
/*
|
|
检查迁移文件是否已挂载使用
|
|
*/
|
|
for (var i in replicationControllers) {
|
|
var labels = Kubernetes.getLabels(replicationControllers[i]);
|
|
if (Kubernetes.getName(replicationControllers[i]) == item._key && getAnnotationValueBykey(replicationControllers[i], "year") == item["year"]) {
|
|
message = "数据正在使用";
|
|
return message;
|
|
}
|
|
}
|
|
}
|
|
return message;
|
|
}
|
|
Kubernetes.checkForMigration = checkForMigration;
|
|
function eliminateChechBoxClick() {
|
|
var element = $("#tableConfig > thead > tr input:checkbox");
|
|
if (element.is(':checked'))
|
|
element.click();
|
|
}
|
|
Kubernetes.eliminateChechBoxClick = eliminateChechBoxClick;
|
|
/*
|
|
是否已存在当前
|
|
*/
|
|
function alreadyExitInFolder(selectedItems, selectNode) {
|
|
var childNodes = selectNode.childNodes;
|
|
for (var i in selectedItems) {
|
|
var itemName = selectedItems[i].regionalismCode + "_" + selectedItems[i].systemCode;
|
|
for (var j in childNodes) {
|
|
if (childNodes[j].name == itemName) {
|
|
var childrens = childNodes[j].childNodes;
|
|
for (var k in childrens)
|
|
if (childrens[k].name == selectedItems[i].dataVersion)
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
Kubernetes.alreadyExitInFolder = alreadyExitInFolder;
|
|
function alreadyExitInCluster(selectedItems, volumePath) {
|
|
for (var i in selectedItems) {
|
|
if (selectedItems[i].datapath.startWith(volumePath)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
Kubernetes.alreadyExitInCluster = alreadyExitInCluster;
|
|
})(Kubernetes || (Kubernetes = {}));
|
|
//# sourceMappingURL=utilHelpers.js.map
|