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.
128 lines
4.3 KiB
128 lines
4.3 KiB
9 years ago
|
/// <reference path="../../includes.ts"/>
|
||
|
/// <reference path="kubernetesHelpers.ts"/>
|
||
|
/// <reference path="kubernetesPlugin.ts"/>
|
||
|
|
||
|
module Kubernetes {
|
||
|
|
||
|
// controller for the status icon cell
|
||
|
export var PodStatus = controller("PodStatus", ["$scope", ($scope) => {
|
||
|
$scope.statusMapping = (text) => {
|
||
|
return statusTextToCssClass(text);
|
||
|
}
|
||
|
}]);
|
||
|
|
||
|
_module.controller("Kubernetes.TermController", ($scope, TerminalService) => {
|
||
|
$scope.canConnectTo = (container) => {
|
||
|
if (container.securityContext && container.securityContext.privileged) {
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
$scope.openTerminal = (selfLink, containerName) => {
|
||
|
var id = TerminalService.newTerminal(selfLink, containerName);
|
||
|
log.debug("Created terminal, id: ", id);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// controller that deals with the labels per pod
|
||
|
export var Labels = controller("Labels", ["$scope", "$location", ($scope, $location) => {
|
||
|
$scope.labels = [];
|
||
|
var labelKeyWeights = {
|
||
|
"name": 1,
|
||
|
"replicationController": 2,
|
||
|
"group": 3
|
||
|
};
|
||
|
$scope.$watch('entity', (newValue, oldValue) => {
|
||
|
if (newValue) {
|
||
|
// log.debug("labels: ", newValue);
|
||
|
// massage the labels a bit
|
||
|
$scope.labels = [];
|
||
|
angular.forEach(Core.pathGet($scope.entity, ["metadata", "labels"]), (value, key) => {
|
||
|
if (key === 'fabric8' || key === 'style' || key === 'status') {
|
||
|
// TODO not sure what this is for, the container type?
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
$scope.labels.push({
|
||
|
key: key,
|
||
|
title: value
|
||
|
});
|
||
|
});
|
||
|
|
||
|
// lets sort by key but lets make sure that we weight certain labels so they are first
|
||
|
$scope.labels = $scope.labels.sort((a, b) => {
|
||
|
function getWeight(key) {
|
||
|
return labelKeyWeights[key] || 1000;
|
||
|
}
|
||
|
var n1 = a["key"];
|
||
|
var n2 = b["key"];
|
||
|
var w1 = getWeight(n1);
|
||
|
var w2 = getWeight(n2);
|
||
|
var diff = w1 - w2;
|
||
|
if (diff < 0) {
|
||
|
return -1;
|
||
|
} else if (diff > 0) {
|
||
|
return 1;
|
||
|
}
|
||
|
if (n1 && n2) {
|
||
|
if (n1 > n2) {
|
||
|
return 1;
|
||
|
} else if (n1 < n2) {
|
||
|
return -1;
|
||
|
} else {
|
||
|
return 0;
|
||
|
}
|
||
|
} else {
|
||
|
if (n1 === n2) {
|
||
|
return 0;
|
||
|
} else if (n1) {
|
||
|
return 1;
|
||
|
} else {
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
$scope.handleClick = (entity, labelType:string, value) => {
|
||
|
// log.debug("handleClick, entity: ", entity, " key: ", labelType, " value: ", value);
|
||
|
$scope.$emit('labelFilterUpdate', value.title)
|
||
|
}
|
||
|
|
||
|
$scope.labelClass = containerLabelClass;
|
||
|
}]);
|
||
|
|
||
|
//服务状态过滤
|
||
|
export var Status = controller('Status', ["$scope", "$http", "$interval", "$location", "KubernetesApiURL", ($scope, $http, $interval, $location, KubernetesApiURL) => {
|
||
|
$scope.$watch('entity', (newValue, oldValue) => {
|
||
|
if(newValue){
|
||
|
//console.log($scope.entity.metadata.labels);
|
||
|
if($scope.entity.metadata.labels.status === "0" && $scope.entity.metadata.labels.lock === "0"){
|
||
|
var labels =
|
||
|
Kubernetes.updateReplicationControllerLabels($http, KubernetesApiURL, $scope.entity, {"style": "oracle", "status": "0", "lock": "1"});
|
||
|
var ip = $scope.entity.$pods[0].$host + ":" + $scope.entity.$pods[0].spec.containers[0].ports[0].hostPort;
|
||
|
var timer = $interval(() => {
|
||
|
$http({
|
||
|
url:'/connectToOracle',
|
||
|
method:'POST',
|
||
|
params:{param: ip}
|
||
|
}).success(function(data,header,config,status){
|
||
|
if(header === 200){
|
||
|
console.log(data);
|
||
|
$interval.cancel(timer);
|
||
|
}
|
||
|
}).error(function(data,header,config,status){
|
||
|
|
||
|
});
|
||
|
}, 60000, 10);
|
||
|
|
||
|
timer.then(() => {
|
||
|
console.log("All Connect Done!");
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
},true);
|
||
|
}]);
|
||
|
}
|