From 24559489568d12f6e241a296df2ebaa1abf17871 Mon Sep 17 00:00:00 2001 From: xq2005 Date: Sat, 25 Dec 2010 02:17:00 +0000 Subject: [PATCH] list condition and response associations git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@8509 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/monitor/rmcmon.js | 218 ++++++++++++++++++++++------ xCAT-server/lib/xcat/plugins/web.pm | 31 +++- 2 files changed, 194 insertions(+), 55 deletions(-) diff --git a/xCAT-UI/js/monitor/rmcmon.js b/xCAT-UI/js/monitor/rmcmon.js index a0555bf7d..2fcd7f4b3 100644 --- a/xCAT-UI/js/monitor/rmcmon.js +++ b/xCAT-UI/js/monitor/rmcmon.js @@ -4,6 +4,8 @@ var globalAllNodesNum = 0; var globalFinishNodesNum = 0; var globalSelectedAttributes = ''; var globalTimeStamp; +var globalCondition = ''; +var globalResponse = new Object(); function loadRmcMon(){ //find the rmcmon tab @@ -624,6 +626,7 @@ function showConfigureDia(){ }); } +/*===========RMC Event Tab============*/ /** * load the rmc event tab. * @@ -655,7 +658,69 @@ function loadRmcEvent(){ }); } -/*===========RMC Event Tab============*/ +/** + * get all conditions + * + * + * @return + * + */ +function getConditions(){ + if ('' == globalCondition){ + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'lscondition', + msg : '' + }, + + success : function(data){ + globalCondition = data.rsp[0]; + } + }); + } +} + +/** + * get all response + * + * + * @return + * + */ +function getResponse(){ + var tempFlag = false; + //get all response first + for (var i in globalResponse){ + tempFlag = true; + break; + } + if (!tempFlag){ + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'lsresponse', + msg : '' + }, + + success : function(data){ + var resps = data.rsp[0].split(';'); + for(var i in resps){ + var name = resps[i]; + name = name.substr(1, (name.length - 2)); + globalResponse[name] = 1; + } + } + }); + } +} + /** * show all the event in the rmc event tab * @@ -677,6 +742,10 @@ function showEventLog(data){ //add the configure button loadRmcEventConfig(); + //get conditions and responses, save in the global + getConditions(); + getResponse(); + var eventTable = new DataTable('lsEventTable'); eventTable.init(['Time', 'Type', 'Content']); @@ -735,12 +804,64 @@ function loadRmcEventConfig(){ * */ function mkCondRespDia(){ - var diaDiv = $('
'); - diaDiv.append('under construction.'); + var diaDiv = $('
'); + + //2 fieldset conditions, response + diaDiv.append('
Predefined Condition
'); + diaDiv.append('
ResponsePlase select condition first.
'); + + + + //add the conditions into fieldset + if ('' == globalCondition){ + diaDiv.find('#mkAssCond').append('Getting predefined conditions, open this dislogue later.'); + } + else{ + diaDiv.find('#mkAssCond').append(createConditionTable(globalCondition)); + } + + //change the response field when click the condition + diaDiv.find('input:radio').bind('click', function(){ + diaDiv.find('#mkAssResp').empty().append('ResponseGetting response').append(createLoader()); + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'lscondresp;"' + $(this).attr('value') + '"', + msg : '' + }, + + success : function(data){ + var tempHash = new Object(); + var showStr = ''; + if (data.rsp[0]){ + var names = data.rsp[0].split(';'); + for (var i in names){ + var name = names[i]; + name = name.substr(1, name.length - 2); + tempHash[name] = 1; + } + } + + for(var name in globalResponse){ + if(tempHash[name]){ + showStr += '' + name; + } + else{ + showStr += '' + name; + } + } + + diaDiv.find('#mkAssResp').empty().append('Response').append(showStr); + } + }); + }); diaDiv.dialog({ modal: true, - width: 400, + width: 570, close: function(event, ui){ $(this).remove(); }, @@ -777,14 +898,31 @@ function rmCondRespDia(){ */ function chCondScopeDia(){ var diaDiv = $('
'); + //3 fieldset to show conditions, group and status diaDiv.append('
Predefined Condition
'); diaDiv.append('
Group
'); diaDiv.append('
'); + //add the groups into fieldset + var groups = $.cookie('groups').split(','); + for (var i in groups){ + var tempStr = '' + groups[i]; + diaDiv.find('#changeGroup').append(tempStr); + } + + //add the conditions into fieldset + if ('' == globalCondition){ + diaDiv.find('#changePreCond').append('Getting predefined conditions, open this dislogue later.'); + } + else{ + diaDiv.find('#changePreCond').append(createConditionTable(globalCondition)); + } + + //create the dislogue diaDiv.dialog({ modal: true, - width: 570, - close: function(event, ui){ + width: 570, + close: function(event, ui){ $(this).remove(); }, buttons: { @@ -839,47 +977,6 @@ function chCondScopeDia(){ } } }); - - $('#changePreCond').append('Getting predefined conditions.'); - $('#changePreCond').append(createLoader()); - var groups = $.cookie('groups').split(','); - for (var i in groups){ - var tempStr = '' + groups[i]; - $('#changeGroup').append(tempStr); - } - - $.ajax({ - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'webrun', - tgt : '', - args : 'lscondition', - msg : '' - }, - - success : function(data){ - $('#changePreCond').empty(); - var conditions = data.rsp[0].split(';'); - var name = ''; - var showStr = 'Predefined Condition'; - for (var i in conditions){ - name = conditions[i]; - name = name.substr(1, name.length - 2); - if (0 == i % 2){ - showStr += '' ; - } - else{ - showStr += ''; - } - } - showStr += '
' + name + '' + name + '
'; - - $('#changePreCond').append(showStr); - //adjust the dialog's position - $('#chScopeDiaDiv').dialog( "option", "position", 'center' ); - } - }); } /** @@ -909,4 +1006,31 @@ function mkResponseDia(){ } } }); +} + +/** + * create the condition table for dialogue + * + * @param + + * @return + * + */ +function createConditionTable(cond){ + var conditions = cond.split(';'); + var name = ''; + var showStr = ''; + for (var i in conditions){ + name = conditions[i]; + name = name.substr(1, name.length - 2); + if (0 == i % 2){ + showStr += '' ; + } + else{ + showStr += ''; + } + } + showStr += '
' + name + '' + name + '
'; + + return showStr; } \ No newline at end of file diff --git a/xCAT-server/lib/xcat/plugins/web.pm b/xCAT-server/lib/xcat/plugins/web.pm index 23471c540..d48fb328d 100644 --- a/xCAT-server/lib/xcat/plugins/web.pm +++ b/xCAT-server/lib/xcat/plugins/web.pm @@ -258,7 +258,7 @@ sub web_mkcondition{ push (@nodes, @temp[0]); } - #xCAT::Utils->runcmd('chcondition -n ' + join(',', @nodes) + '-m m ' + $conditionName); + xCAT::Utils->runcmd('chcondition -n ' + join(',', @nodes) + '-m m ' + $conditionName); $callback->( { data => 'Change scope success.' } ); } @@ -267,7 +267,7 @@ sub web_mkcondition{ sub web_lsresp { my ( $request, $callback, $sub_req ) = @_; my $names = ''; - my @temp = (); + my @temp; my $retInfo = xCAT::Utils->runcmd('lsresponse -d', -1, 1); shift @$retInfo; @@ -283,14 +283,29 @@ sub web_lsresp { sub web_lscondresp { my ( $request, $callback, $sub_req ) = @_; - my @ret = `lscondresp`; - shift @ret; - shift @ret; + my $names = ''; + my @temp; + #if there is condition name, then we only show the condition linked associations. + if ($request->{arg}->[1]){ + my $cmd = 'lscondresp -d ' . $request->{arg}->[1]; + my $retInfo = xCAT::Utils->runcmd($cmd, -1, 1); + if (2 > @$retInfo){ + $callback->( { data => '' } ); + return; + } - foreach my $line (@ret) { - chomp $line; - $callback->( { data => $line } ); + shift @$retInfo; + shift @$retInfo; + for my $line (@$retInfo){ + @temp = split(':', $line); + $names = $names . @temp[1] . ';'; + } } + else{ + } + + $names = substr($names, 0, (length($names) - 1)); + $callback->( { data => $names } ); } sub web_gettab {