You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aggregation-platform/plugins/kubernetes/ts/replicationControllers.ts

205 lines
7.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/// <reference path="../../includes.ts"/>
/// <reference path="kubernetesHelpers.ts"/>
/// <reference path="kubernetesPlugin.ts"/>
module Kubernetes {
export var ReplicationControllers = controller("ReplicationControllers",
["$scope", "OracleStatusModel", "KubernetesModel", "KubernetesReplicationControllers", "KubernetesPods", "KubernetesState", "$templateCache", "$location", "$routeParams", "$http", "$timeout", "KubernetesApiURL",
($scope, OracleStatusModel, KubernetesModel: Kubernetes.KubernetesModelService, KubernetesReplicationControllers:ng.resource.IResourceClass<any>, KubernetesPods:ng.resource.IResourceClass<any>, KubernetesState,
$templateCache, $location:ng.ILocationService, $routeParams, $http, $timeout, KubernetesApiURL) => {
$scope.kubernetes = KubernetesState;
$scope.model = KubernetesModel;
$scope.tableConfig = {
data: 'model.replicationControllers',
showSelectionCheckbox: true,
enableRowClickSelection: false,
multiSelect: true,
selectedItems: [],
filterOptions: {
filterText: $location.search()["q"] || ''
},
columnDefs: [
{ field: '_key',
displayName: '服务名称',
cellTemplate: $templateCache.get("idTemplate.html")
},
//{ 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: '$pods[0].$eventCount',
displayName: '服务启动日志',
cellTemplate: $templateCache.get("eventSummaryTemplate.html")
},
{ field: '$podCounters',
displayName: '服务状态',
cellTemplate: $templateCache.get("podCountsAndLinkTemplate.html"),
customSortField: (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;
}
}
}
]
}
Kubernetes.initShared($scope, $location, $http, $timeout, $routeParams, KubernetesModel, KubernetesState, KubernetesApiURL);
$scope.deletePrompt = (selected) => {
if (angular.isString(selected)) {
selected = [{
id: selected
}];
}
UI.multiItemConfirmActionDialog(<UI.MultiItemConfirmActionOptions>{
collection: selected,
index: 'metadata.name',
onClose: (result:boolean) => {
if (result) {
function deleteSelected(selected:Array<KubePod>, next:KubePod) {
if (next) {
log.debug("deleting: ", getName(next));
Kubernetes.resizeController($http, KubernetesApiURL, next, 0, () => {
log.debug("updated number of replicas");
KubernetesReplicationControllers.delete({
id: getName(next)
}, undefined, () => {
log.debug("deleted: ", getName(next));
if(next.metadata.labels.style === "oracle"){
console.log("delete " + next.metadata.name);
Kubernetes.connectOracle($http, $timeout, "/cancelOracleConection", "", getName(next), 0);
}
deleteSelected(selected, selected.shift());
}, (error) => {
log.debug("Error deleting: ", error);
deleteSelected(selected, selected.shift());
});
});
/*KubernetesReplicationControllers.delete({
id: getName(next)
}, undefined, () => {
log.debug("deleted: ", getName(next));
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',
custom: "该服务删除后将会清除oracle对应服务的端口等资源占用但不删除数据文件是否删除请确认",
customClass: "alert alert-warning",
cancelText: "取消"
}).open();
}
$scope.createRCs= () => {
var xhr= new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {//4表示数据已经调用完成
if (xhr.status == 200) {//HTTP的状态码
var obj=JSON.parse(xhr.responseText);
console.log(obj.path);
var name = Kubernetes.getRandomString(8);
//console.log(name + "=====" +port);
var object = {
"name": name,
"labels": {
"name" : name
},
"path": obj.path,
}
Kubernetes.createRC(object, (rc) =>{
Kubernetes.connectOracle($http, $timeout, "/connectToOracle", "", getName(rc), 0);
});
}else if(xhr.status == 403){
alert("两次创建oracle服务时间间隔需要超过1分钟!");
}else{
}
}
};
xhr.open("POST", "/oracleAppPath", false);//与服务器连接并发送
xhr.send(null);
}
$scope.stopPrompt = (selected) =>{
if (angular.isString(selected)) {
selected = [{
id: selected
}];
}
UI.multiItemConfirmActionDialog(<UI.MultiItemConfirmActionOptions>{
collection: selected,
index: 'metadata.name',
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"){
console.log("stop " + next.metadata.name);
Kubernetes.connectOracle($http, $timeout, "/cancelOracleConection", "", getName(next), 0);
}
stopSelected(selected, selected.shift());
});
}
}
stopSelected(selected, selected.shift());
}
},
title: '是否需要停止oracle服务',
action: '以下的oracle服务将会被停止:',
okText: '停止',
okClass: 'btn-danger',
custom: "该服务停止后将无法继续提供连接访问服务,但可通过启动按钮重新启动该服务以进行访问。是否停止,请确认",
customClass: "alert alert-warning",
cancelText: "取消"
}).open();
}
$scope.reStartPrompt = (selected) => {
function startSelected(selected:Array<KubePod>, next:KubePod){
if(next){
if(next.$replicas === 0)
Kubernetes.resizeController($http, KubernetesApiURL, next, 1, () => {
console.log("restart " + next.metadata.name);
Kubernetes.connectOracle($http, $timeout, "/connectToOracle", "", getName(next), 0);
startSelected(selected, selected.shift());
});
}
}
startSelected(selected, selected.shift());
}
}]);
}