300 lines
12 KiB
TypeScript
300 lines
12 KiB
TypeScript
/// <reference path="../../includes.ts"/>
|
||
/// <reference path="kubernetesHelpers.ts"/>
|
||
/// <reference path="kubernetesPlugin.ts"/>
|
||
/// <reference path="kubernetesModel.ts"/>
|
||
/// <reference path="../../configs/ts/customAlert.ts"/>
|
||
module Kubernetes {
|
||
|
||
export var ReplicationControllers = controller("ReplicationControllers",
|
||
["$scope", "KubernetesModel", "KubernetesReplicationControllers", "KubernetesPods", "ConfigsModel", "KubernetesState", "$templateCache", "$location", "$routeParams", "$http", "$timeout", "KubernetesApiURL",
|
||
($scope, KubernetesModel: Kubernetes.KubernetesModelService, KubernetesReplicationControllers:ng.resource.IResourceClass<any>, KubernetesPods:ng.resource.IResourceClass<any>, ConfigsModel, KubernetesState,
|
||
$templateCache, $location:ng.ILocationService, $routeParams, $http, $timeout, KubernetesApiURL) => {
|
||
|
||
$scope.kubernetes = KubernetesState;
|
||
$scope.configs = ConfigsModel;
|
||
$scope.model = KubernetesModel;
|
||
|
||
$scope.tableConfig = {
|
||
data: 'model.replicationControllers',
|
||
showSelectionCheckbox: true,
|
||
enableRowClickSelection: false,
|
||
multiSelect: true,
|
||
selectedItems: [],
|
||
filterOptions: {
|
||
filterText: $location.search()["q"] || ''
|
||
},
|
||
columnDefs: [
|
||
{ field: '$oracleName',
|
||
displayName: '服务名称',
|
||
cellTemplate: $templateCache.get("idTemplate.html"),
|
||
customSortField: (field) => {
|
||
return field;
|
||
}
|
||
},
|
||
//{ field: '$replicas',
|
||
// displayName: 'Scale',
|
||
// cellTemplate:$templateCache.get("desiredReplicas.html")
|
||
//},
|
||
{ field: '$pods.age',
|
||
displayName: '启动时间',
|
||
cellTemplate:$templateCache.get("ageTemplate.html")
|
||
},
|
||
{ field: '$labelsText',
|
||
displayName: '数据标签',
|
||
cellTemplate: $templateCache.get("labelTemplate.html")
|
||
},
|
||
{ field: '$pods',
|
||
displayName: '连接参数',
|
||
cellTemplate: $templateCache.get("connectParamTemplate.html")
|
||
},
|
||
{ field: '$podCounters',
|
||
displayName: '服务状态',
|
||
cellTemplate: $templateCache.get("podCountsAndLinkTemplate.html"),
|
||
customSortField: (field) => {
|
||
console.log(field);
|
||
if(field.$podCounters.ready ){
|
||
return 3;
|
||
}else if(field.$podCounters.valid || field.$podCounters.waiting){
|
||
return 2;
|
||
}else if(field.$podCounters.error){
|
||
return 0;
|
||
}else{
|
||
return 1;
|
||
}
|
||
}
|
||
},
|
||
{ field: '$extractStatus',
|
||
displayName: '数据汇总状态',
|
||
cellTemplate: $templateCache.get("dataSummaryTemplate.html")
|
||
},
|
||
{
|
||
field: '$checkStatus',
|
||
displayName: '检验状态',
|
||
cellTemplate: $templateCache.get("dataCheckStatus.html")
|
||
}
|
||
],
|
||
sortInfo: {
|
||
sortBy: "$oracleName",
|
||
ascending: false
|
||
}
|
||
}
|
||
|
||
Kubernetes.initShared($scope, $location, $http, $timeout, $routeParams, KubernetesModel, KubernetesState, KubernetesApiURL);
|
||
|
||
$scope.deletePrompt = (selected) => {
|
||
if (angular.isString(selected)) {
|
||
selected = [{
|
||
id: selected
|
||
}];
|
||
}
|
||
var extractItems = checkForExtract(selected);
|
||
if(extractItems.length == 0){
|
||
UI.multiItemConfirmActionDialog(<UI.MultiItemConfirmActionOptions>{
|
||
collection: selected,
|
||
index: '$alias',
|
||
onClose: (result:boolean) => {
|
||
if (result) {
|
||
function deleteSelected(selected:Array<KubePod>, next:KubePod) {
|
||
if (next) {
|
||
Kubernetes.resizeController($http, KubernetesApiURL, next, 0, () => {
|
||
KubernetesReplicationControllers.delete({
|
||
id: getName(next)
|
||
}, undefined, () => {
|
||
if(next.metadata.labels.style === "oracle"){
|
||
Kubernetes.connectOracle($http, $timeout, "/java/console/api/cancelOracleConection", "delete", next, 0);
|
||
}
|
||
deleteSelected(selected, selected.shift());
|
||
}, (error) => {
|
||
log.debug("Error deleting: ", error);
|
||
deleteSelected(selected, selected.shift());
|
||
});
|
||
});
|
||
}
|
||
}
|
||
deleteSelected(selected, selected.shift());
|
||
}
|
||
},
|
||
title: '是否需要删除oracle服务?',
|
||
action: '以下的oracle服务将会被删除:',
|
||
okText: '删除',
|
||
okClass: 'btn-danger sj_btn_cir',
|
||
custom: "该服务删除后将会清除oracle对应服务的端口等资源占用,但不删除数据文件,是否删除,请确认!",
|
||
customClass: "alert alert-warning sj_alert-warning",
|
||
cancelText: "取消",
|
||
cancelClass: 'sj_btn_grey'
|
||
}).open();
|
||
}else{
|
||
var name = "";
|
||
angular.forEach(extractItems, (item) => {
|
||
name += item.$oracleName + ",";
|
||
})
|
||
//alert("删除服务失败:" + name + "服务正在执行汇总操作,不能被删除");
|
||
Configs.customAlert("提示", "操作失败:正在执行汇总操作的服务不能被删除!", '',null, 0, "error");
|
||
}
|
||
}
|
||
|
||
$scope.createRCs= () => {
|
||
$http({
|
||
url: '/java/console/api/cancelOracleConection',
|
||
dataType: 'json',
|
||
method:'POST',
|
||
params:{param: "data"}
|
||
}).success(function(data,header,config,status){
|
||
console.log("success");
|
||
}).error(function(data,header,config,status){
|
||
//log.warn("Failed to connect " + connectParam + " " + data + " " + status);
|
||
});
|
||
}
|
||
|
||
$scope.stopPrompt = (selected) =>{
|
||
if (angular.isString(selected)) {
|
||
selected = [{
|
||
id: selected
|
||
}];
|
||
}
|
||
var extractItems = checkForExtract(selected);
|
||
if(extractItems.length == 0){
|
||
UI.multiItemConfirmActionDialog(<UI.MultiItemConfirmActionOptions>{
|
||
collection: selected,
|
||
index: '$alias',
|
||
onClose: (result:boolean) => {
|
||
if (result) {
|
||
function stopSelected(selected:Array<KubePod>, next:KubePod) {
|
||
if (next) {
|
||
Kubernetes.resizeController($http, KubernetesApiURL, next, 0, () => {
|
||
if(next.metadata.labels.style === "oracle"){
|
||
Kubernetes.connectOracle($http, $timeout, "/java/console/api/cancelOracleConection", "stop", next, 0);
|
||
}
|
||
stopSelected(selected, selected.shift());
|
||
});
|
||
}
|
||
}
|
||
stopSelected(selected, selected.shift());
|
||
}
|
||
},
|
||
title: '是否需要停止oracle服务?',
|
||
action: '以下的oracle服务将会被停止:',
|
||
okText: '停止',
|
||
okClass: 'btn-danger sj_btn_cir',
|
||
custom: "该服务停止后将无法继续提供连接访问服务,但可通过启动按钮重新启动该服务以进行访问。是否停止,请确认",
|
||
customClass: "alert alert-warning sj_alert-warning",
|
||
cancelText: "取消",
|
||
cancelClass: 'sj_btn_grey'
|
||
}).open();
|
||
}else{
|
||
var name = "";
|
||
angular.forEach(extractItems, (item) => {
|
||
name += item.$oracleName + ",";
|
||
})
|
||
//alert("停止服务失败:" + name + "服务正在执行汇总操作,不能停止");
|
||
Configs.customAlert("提示", "操作失败:正在执行汇总操作的服务不能被停止!", '',null, 0, "error");
|
||
}
|
||
};
|
||
|
||
$scope.reStartPrompt = (selected) => {
|
||
function startSelected(selected:Array<KubePod>, next:KubePod){
|
||
if(next){
|
||
console.log(getLabels(next).status);
|
||
if(next.$replicas === 0){
|
||
Kubernetes.resizeController($http, KubernetesApiURL, next, 1, () => {
|
||
Kubernetes.connectOracle($http, $timeout, "/java/console/api/connectOracle", "reStart", next, 200);
|
||
startSelected(selected, selected.shift());
|
||
});
|
||
}else{
|
||
if(getLabels(next).status == "1")
|
||
Kubernetes.connectOracle($http, $timeout, "/java/console/api/connectOracle", "reStart", next, 200);
|
||
startSelected(selected, selected.shift());
|
||
}
|
||
}
|
||
}
|
||
startSelected(selected, selected.shift());
|
||
};
|
||
|
||
/**
|
||
处理抽取标准表
|
||
**/
|
||
$scope.extractOracle = (selected) =>{
|
||
var answer = false;
|
||
for (var i = 0; i < ConfigsModel.oracleParam.length; ++i) {
|
||
if(ConfigsModel.oracleParam[i].type == 1){
|
||
answer = true
|
||
break;
|
||
}
|
||
}
|
||
if(answer == false){
|
||
/**
|
||
提示没有配置标准表汇总库
|
||
**/
|
||
Configs.customAlert("提示", "操作失败:没有配置默认的标准表汇总库", '',null, 0, "error");
|
||
return;
|
||
}
|
||
// 检查数据库是否已启动
|
||
var result = checkIsStartSuccess(selected);
|
||
if(result.length > 0){
|
||
Configs.customAlert("提示", "操作失败:选择服务中存在未启动的数据库,请先启动服务", '',null, 0, "error");
|
||
return;
|
||
}
|
||
var answer = false;
|
||
var selectedItem = null;
|
||
for (var i = 0; i < ConfigsModel.oracleParam.length; ++i) {
|
||
if(ConfigsModel.oracleParam[i].type == 1){
|
||
selectedItem = ConfigsModel.oracleParam[i];
|
||
answer = true
|
||
break;
|
||
}
|
||
}
|
||
if(answer == false){
|
||
/**
|
||
提示没有配置标准表汇总库
|
||
**/
|
||
Configs.customAlert("提示", "操作失败:没有配置默认的标准表汇总库", '',null, 0, "error");
|
||
return;
|
||
}
|
||
|
||
Kubernetes.extractDataToOracle($http, "/java/console/api/oracle/standardextract", selected, selectedItem);
|
||
}
|
||
|
||
$scope.extractClick = {
|
||
items: null,
|
||
selectedItem: {name: "当前没有可用的汇总库"},
|
||
dialog: new UI.Dialog(),
|
||
onOk: () => {
|
||
var extractClick = $scope.extractClick;
|
||
extractClick.items = $scope.tableConfig.selectedItems;
|
||
Kubernetes.extractDataToOracle($http, "/java/console/api/oracle", extractClick.items, extractClick.selectedItem);
|
||
//extractClick.selectedItem = $scope.filterReplicationControllers[0] || "";
|
||
extractClick.dialog.close();
|
||
},
|
||
open: (selected) => {
|
||
var extractClick = $scope.extractClick;
|
||
if($scope.configs && $scope.configs.oracleParam instanceof Array && $scope.configs.oracleParam.length>0)
|
||
extractClick.selectedItem = $scope.configs.oracleParam[0];
|
||
var result = checkIsStartSuccess($scope.tableConfig.selectedItems);
|
||
if(result.length >0){
|
||
Configs.customAlert("提示", "操作失败:选择服务中存在未启动的数据库,请先启动服务", '',null, 0, "error");
|
||
return;
|
||
}
|
||
|
||
/**
|
||
检查数据库是否正在抽取
|
||
**/
|
||
if(checkRCIsExtracting(selected)){
|
||
Configs.customAlert("提示", "操作失败:选择的数据库中有正在执行汇总的数据库,请勿重复执行汇总操作", '',null, 0, "error");
|
||
return;
|
||
}
|
||
extractClick.dialog.open();
|
||
/*extractData.selectedItem = $scope.filterReplicationControllers[0] || "";
|
||
extractData.items = selected;*/
|
||
$timeout(() => {
|
||
$('#newDataName').focus();
|
||
}, 50);
|
||
},
|
||
close: () => {
|
||
$scope.extractClick.selectedItem = {name: "当前没有可用的汇总库"};
|
||
$scope.extractClick.dialog.close();
|
||
}
|
||
};
|
||
|
||
}]);
|
||
}
|