//@ sourceURL=/dapmanager-web/res/web-framework/js/service/clusterServiceStartProgress.js
$(document).ready(function () {
loadPropertiesSideMenu(lang, 'dap-manager-i18n', '/dapmanager-web/res/web-framework/i18n/', initMethod);
});
var globalKey;
var globalResult;
var globalInterval;
var globalTotalService = 0;
var globalFinishedService = 0;
var isStopCluster;
var clusterId;
var clusterName;
var startOrStopResult = true;
function initMethod() {
isStopCluster = parent.clusterServiceParams.isStopCluster;
clusterId = parent.clusterServiceParams.clusterId;
clusterName = parent.clusterServiceParams.clusterName;
var isStartingOrStopping = UrlParam.param("isStartingOrStopping");
$("#AllClusters").append('' + clusterName + ' ');
var params1 = {};
params1['commandCode'] = 13000993;
params1['clusterId'] = clusterId;
params1['isQueryProgress']= isStartingOrStopping;
var params2 = {};
params2['commandCode'] = 13000902;
params2['clusterId'] = clusterId;
if(isStopCluster == 1){
params1['commandCode'] = 13000994;
params2['commandCode'] = 13000901;
$("#startOrStopCluster").html(geti18nPropVal("com_zte_ums_ict_framework_ui_shutdown_cluster"));
$("#clusterOperating").html(geti18nPropVal("com_zte_ums_ict_framework_ui_cluster_stop_used_time"));
}
else{
$("#startOrStopCluster").html(geti18nPropVal("com_zte_ums_ict_framework_ui_start_cluster"));
$("#clusterOperating").html(geti18nPropVal("com_zte_ums_ict_framework_ui_cluster_start_used_time"));
}
$.ajax({
url: '/dapmanager-web/requestDispatcher',
async: false,
type: 'post',
data: params1,
dataType: 'json',
success: function (result) {
if(result.status == 0){
queryWizardRollback(result);
if(isStartingOrStopping == 0){
startOrStopAction(params2);
}
clearInterval(globalInterval);
globalInterval = setInterval(queryHostResult, 3000);
}
}
});
}
function startOrStopAction(params){
$.ajax({
url: "/dapmanager-web/requestDispatcher",
type: "post",
data: params,
cache: false,
async: false,
dataType: "json",
success: function (result) {
}
});
}
function queryWizardRollback(result) {
var _div = $("#wizardList");
var _ul = $(' ');
$(result.data).each(function(index,item){
var _li = $("
");
var _a = $('
');
_a.append('
');
_a.append('
'+item.serviceInstanceName+' ');
globalTotalService += 1;
var sum = 0;
var _ul2 = $('
');
$(item.roleBeans).each(function(index2,item2){
var _li2 = $("
");
var key = item.serviceInstanceName+"_"+item2.roleName;
var _a2 = $('
');
_a2.append('
');
_a2.append('
'+item2.roleName+' ');
_a2.append('
(0/'+item2.roleNum+') ');
_li2.append(_a2);
_ul2.append(_li2);
sum += item2.roleNum;
})
_a.append('
(0/'+sum+') ');
_li.append(_a);
_li.append(_ul2);
_ul.append(_li);
})
_div.append(_ul);
bindMenuClick();
}
function bindMenuClick() {
$('.inactive').click(function(){
if($(this).siblings('ul').css('display')=='none'){
$(this).addClass('active');
$(this).addClass('inactives');
$(this).siblings('ul').slideDown(100);
}else{
$(this).removeClass('active');
$(this).removeClass('inactives');
$(this).siblings('ul').slideUp(100);
}
})
$('.link').click(function(){
$('.link').removeClass("a-click");
$(this).addClass("a-click");
globalKey = $(this).attr("data-key");
var role2HostResult = globalResult.roleCommandRes[globalKey];
if(role2HostResult){
updateTime();
drawTable(role2HostResult.roleCommandBeans);
}
})
var firstService = $('.inactive:first');
$(firstService).addClass('active');
$(firstService).addClass('inactives');
$(firstService).siblings('ul').show().children('li');
var firstRole = $('.link:first');
$(firstRole).addClass("a-click");
globalKey = $(firstRole).attr("data-key");
}
function queryHostResult() {
var params = {};
params['commandCode'] = 13000992;
params['clusterId'] = clusterId;
$.ajax({
url: '/dapmanager-web/requestDispatcher',
async: false,
type: 'post',
data: params,
dataType: 'json',
success: function (result) {
if(result.status == 0){
queryHostRollback(result);
}
}
});
}
function queryHostRollback(result) {
globalResult = result.data;
var role2HostResult = globalResult.roleCommandRes[globalKey];
if(!role2HostResult){
return;
}
updateLeftWizard();
updateProgressBar();
updateTime();
drawTable(role2HostResult.roleCommandBeans);
}
function updateLeftWizard() {
var clear = true;
globalFinishedService = 0;
$('.link').each(function(){
var key = $(this).attr("data-key");
var role2HostResult = globalResult.roleCommandRes[key];
if(role2HostResult){
if($(this).find(".text-right").attr("data-finished") == "0"){
$(this).find(".text-right").html("("+role2HostResult.successNum+"/"+role2HostResult.allNum+")");
$(this).find(".text-right").attr("data-allNum",role2HostResult.allNum);
$(this).find(".text-right").attr("data-successNum",role2HostResult.successNum);
$(this).find(".text-right").attr("data-failedNum",role2HostResult.failedNum);
$(this).find(".text-right").attr("isExecuting",role2HostResult.isExecuting);
if(role2HostResult.failedNum > 0){
startOrStopResult = false;
}
if(role2HostResult.successNum + role2HostResult.failedNum != role2HostResult.allNum){
clear = false;
}
else{
if(role2HostResult.failedNum > 0 && role2HostResult.successNum == 0){
$(this).find('img').attr('src','../../css/images/clusterRoleBad.png');
}
else if(role2HostResult.failedNum > 0 && role2HostResult.successNum > 0){
$(this).find('img').attr('src','../../css/images/clusterRoleAlarm.png');
}
$(this).find(".text-right").attr("data-finished", "1");
}
}
}
})
$('#first-class > li').each(function(){
var isExecuting = 0;
var sumAllNum = 0;
var sumSuccessNum = 0;
var sumFailedNum = 0;
$(this).find('li').each(function(){
var allNum = parseInt($(this).find('.text-right').attr("data-allNum"));
var successNum = parseInt($(this).find('.text-right').attr("data-successNum"));
var failedNum = parseInt($(this).find('.text-right').attr("data-failedNum"));
sumAllNum += allNum;
sumSuccessNum += successNum;
sumFailedNum += failedNum;
if($(this).find('.text-right').attr("isExecuting") == "1"){
isExecuting = 1;
}
})
$(this).find('.text-right:first').html("("+sumSuccessNum+"/"+sumAllNum+")");
if(isExecuting == 1){
$(this).find('img:first').attr("src","../../css/images/loading.gif");
}
var instanceName = $(this).find('span:first').text();
var serviceStatus = globalResult.serviceStatusMap[instanceName];
if(isStopCluster == 1){
if(serviceStatus == "Stopped"){
globalFinishedService += 1;
$(this).find('img:first').attr("src","../../css/images/clusterServiceGood.png");
}
else if(serviceStatus == "Bad" || serviceStatus == "Unknown"){
globalFinishedService += 1;
$(this).find('img:first').attr("src","../../css/images/clusterServiceBad.png");
}
else if(serviceStatus == "Stop failed"){
globalFinishedService += 1;
$(this).find('img:first').attr("src","../../css/images/clusterServiceAlarm.png");
}
else{
clear = false;
}
}
else{
if(serviceStatus == "Good"){
globalFinishedService += 1;
$(this).find('img:first').attr("src","../../css/images/clusterServiceGood.png");
}
else if(serviceStatus == "Bad" || serviceStatus == "Unknown"){
globalFinishedService += 1;
$(this).find('img:first').attr("src","../../css/images/clusterServiceBad.png");
}
else if(serviceStatus == "Less well"){
globalFinishedService += 1;
$(this).find('img:first').attr("src","../../css/images/clusterServiceAlarm.png");
}
else{
clear = false;
}
}
});
if(clear){
clearInterval(globalInterval);
clusterStartOver();
}
}
function updateTime() {
var mapObj = globalResult.roleCommandRes[globalKey]
var startTime = mapObj.startTime;
var usedTime = mapObj.usedTime;
var successNum = mapObj.successNum;
var failedNum = mapObj.failedNum;
$("#startTime").html(startTime);
if(startTime != null){
var time = new Date(parseInt(startTime));
var timeStr = time.format("yyyy-MM-dd hh:mm:ss");
$("#startTime").html(timeStr);
}
$("#usedTime").html(usedTime);
if(usedTime != null){
$("#usedTime").html(timeConvert(usedTime / 1000));
}
$("#successNum").html(successNum);
$("#failedNum").html(failedNum);
}
function updateProgressBar() {
var percent = (parseInt(Math.round(globalFinishedService / globalTotalService * 10000) / 100.00) + "%");
var totalUsedTime = globalResult.usedTime;
$("#totalUsedTime").html(totalUsedTime);
if(totalUsedTime != null){
$("#totalUsedTime").html(timeConvert(totalUsedTime / 1000));
}
$("#totalPercent").html(percent);
$("#totalProgressBar").css("width",percent);
if(!startOrStopResult){
$("#totalProgressBar").css({"background-color": "red"});
}
}
function clusterStartOver() {
var totalUsedTime = globalResult.usedTime / 1000;
var hours = 0;
var minutes = 0;
var seconds = 0;
if (totalUsedTime > 60 && totalUsedTime < 60 * 60) {
minutes = parseInt(totalUsedTime / 60.0);
seconds = parseInt((parseFloat(totalUsedTime / 60.0) - parseInt(totalUsedTime / 60.0)) * 60);
}
else if (totalUsedTime >= 60 * 60 && totalUsedTime < 60 * 60 * 24) {
hours = parseInt(totalUsedTime / 3600.0);
minutes = parseInt((parseFloat(totalUsedTime / 3600.0) - parseInt(totalUsedTime / 3600.0)) * 60);
seconds = parseInt((parseFloat((parseFloat(totalUsedTime / 3600.0) - parseInt(totalUsedTime / 3600.0)) * 60) - parseInt((parseFloat(totalUsedTime / 3600.0) - parseInt(totalUsedTime / 3600.0)) * 60)) * 60);
}
else {
seconds = parseInt(totalUsedTime);
}
var allSuccessNum = 0;
var allFailedNum = 0;
var allRoleNum = 0;
$('#first-class > li').each(function(){
$(this).find('li').each(function(){
var allNum = parseInt($(this).find('.text-right').attr("data-allNum"));
var successNum = parseInt($(this).find('.text-right').attr("data-successNum"));
var failedNum = parseInt($(this).find('.text-right').attr("data-failedNum"));
allRoleNum += allNum;
allSuccessNum += successNum;
allFailedNum += failedNum;
})
})
var $span = '
'+geti18nPropVal("com_zte_ums_ict_framework_ui_cluster_start_result").formati18n(hours, minutes, seconds, allSuccessNum, allFailedNum)+' '
if(isStopCluster == 1){
$span = '
'+geti18nPropVal("com_zte_ums_ict_framework_ui_cluster_stop_result").formati18n(hours, minutes, seconds, allSuccessNum, allFailedNum)+' '
}
$("#over").append($span);
$("#starting").hide();
$("#over").show();
}
function drawTable(hostResult) {
initDataTablesOpt({
"bSort": true,
"bPaginate": true,//分页
"bFilter": true,//搜索框
"bInfo": true//分页信息
});
$('#hostResult').DataTable({
data: hostResult,
columnDefs: [
{
"targets": [0],
"width": "50%",
"render": function (data, type, row, meta) {
return row.hostIp+" ("+row.hostName+")";
}
},
{
"targets": [1],
"width": "25%",
"render": function (data, type, row, meta) {
var _div = "";
if(row.status == 0){
_div = '
'+geti18nPropVal("com_zte_ums_ict_framework_ui_cluster_start_host_process")+' ';
}
else if(row.status == 1){
_div = '
'+geti18nPropVal("com_zte_ums_ict_framework_ui_cluster_start_host_success")+' ';
}
else{
_div = '
'+geti18nPropVal("com_zte_ums_ict_framework_ui_cluster_start_host_fail")+' ';
}
return _div;
}
},
{
"targets": [2],
"width": "20%",
"bSortable": false,
"render": function (data, type, row, meta) {
if(row.status != 0){
return '
';
}
else{
return '
' + geti18nPropVal("com_zte_ums_ict_framework_ui_cluster_start_host_view") + '
';
}
}
}
]
});
}
function detailReport(logId) {
window.open("/dapmanager-web/res/web-framework/page/log/logpersist/summaryLogDetail.html?logId=" + logId);
}
function search() {
$('#hostResult').DataTable().search(
$("#search").val()
).draw();
}
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1, // month
"d+": this.getDate(), // day
"h+": this.getHours(), // hour
"m+": this.getMinutes(), // minute
"s+": this.getSeconds(), // second
"q+": Math.floor(( this.getMonth() + 3 ) / 3), // quarter
"S": this.getMilliseconds()
// millisecond
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, ( this.getFullYear() + "" ).substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ( "00" + o[k] )
.substr(( "" + o[k] ).length));
}
}
return format;
};
//时间转换 入参 秒
function timeConvert(time){
var hours = 0;
var minutes = 0;
var seconds = 0;
var timeStr = "";
if (time > 60 && time < 60 * 60) {
minutes = parseInt(time / 60.0);
seconds = parseInt((parseFloat(time / 60.0) - parseInt(time / 60.0)) * 60);
timeStr = minutes + "m" + seconds + "s";
}
else if (time >= 60 * 60 && time < 60 * 60 * 24) {
hours = parseInt(time / 3600.0);
minutes = parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60);
seconds = parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) - parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60);
timeStr = hours + "h" + minutes + "m" + seconds + "s";
}
else {
seconds = parseInt(time);
timeStr = seconds + "s";
}
return timeStr;
}