Commit 3533f9ca authored by Alain Takoudjou's avatar Alain Takoudjou

Add Instance parameters management to webrunner

parent 5ad93361
$(document).ready(function(){
$(".tabContents").hide(); // Hide all tab conten divs by default
$(".tabContents:first").show(); // Show the first div of tab content by default
$(".tabContents").hide(); // Hide all tab content divs by default
var hashes = window.location.href.split('#');
if (hashes.length == 2){
$("#tabContaier>ul li").each(function() {
var $tab = $(this).find("a");
if($tab.hasClass("active")) $tab.removeClass("active");
if ($tab.attr("href") == "#"+hashes[1]){
$tab.addClass("active");
$("#"+hashes[1]).show();
}
//alert($(this).attr("href"));
});
}
else{$(".tabContents:first").show();} // Show the first div of tab content by default
$("#tabContaier ul li a").click(function(){ //Fire the click event
if($(this).hasClass('active')){
return;
......
......@@ -4,5 +4,8 @@ String.prototype.toHtmlChar = function(){
'#':'#' };
return this.replace( /[<&>'"#]/g, function(s) { return c[s]; } );
}
String.prototype.trim = function () {
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
/**************************/
......@@ -18,8 +18,24 @@ $(document).ready( function() {
//User have double click on file in to the fileTree
loadFileContent(file);
}
$("#parameter").load($SCRIPT_ROOT + '/getParameterXml');
$("#update").click(function(){
alert($("#parameter").val());
if($("#parameter").val() == ""){
$("#error").Popup("Can not save empty value!", {type:'alert', duration:3000});
}
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + '/saveParameterXml',
data: {parameter: $("#parameter").val().trim()},
success: function(data){
if(data.code == 1){
$("#error").Popup("Instance parameters updated!", {type:'info', duration:3000});
}
else{
$("#error").Popup(data.result, {type:'error', duration:5000});
}
}
});
});
function loadFileContent(file){
......
......@@ -25,7 +25,7 @@
<div class="tabDetails">
<div id="tab1" class="tabContents">
<p>Add your instance parameters here and click on the update button</p>
<textarea class="parameter" id="parameter">&lt;?xml version='1.0' encoding='utf-8'?&gt;</textarea>
<textarea class="parameter" id="parameter"></textarea>
<input type="submit" name="update" id ="update" value="Update" class="button"/>
</div><!-- end tab1 -->
<div id="tab2" class="tabContents">
......@@ -50,10 +50,18 @@
</div><!-- end tab2 -->
<div id="tab3" class="tabContents">
<p>Uses parameters below to run your application</p>
<table cellpadding="0" cellspacing="0" width="100%">
{% for item in slap_status %}
<h2>{{ item[0 ]}}</h2>
<textarea rows=5 readonly>{{ item[1] }}</textarea><br>
<tr>
<th align='left' colspan='2'>Computer Partition {{ item[0]}}</th>
</tr>
{% for k in item[1] %}
<tr>
<td>{{k}}</td><td align='left'>{{item[1][k]}}</td>
</tr>
{% endfor %}
{% endfor %}
</table>
</div><!-- end tab3 -->
<div id="tab4" class="tabContents">
<div id="fileTree" class="file_tree_tabs"></div>
......
......@@ -25,6 +25,18 @@ class Popen(subprocess.Popen):
self.stdin.close()
self.stdin = None
html_escape_table = {
"&": "&amp;",
'"': "&quot;",
"'": "&apos;",
">": "&gt;",
"<": "&lt;",
}
def html_escape(text):
"""Produce entities within text."""
return "".join(html_escape_table.get(c,c) for c in text)
def updateProxy(config):
if not os.path.exists(config['instance_root']):
......@@ -66,10 +78,17 @@ def updateProxy(config):
'reference': partition_reference,
'tap': {'name': partition_reference},
})
#get instance parameter
param_path = os.path.join(config['runner_workdir'], ".parameter.xml")
xml_result = readParameters(param_path)
if type(xml_result) != type('') and xml_result.has_key('instance'):
partition_parameter_kw = xml_result['instance']
else:
partition_parameter_kw = None
computer.updateConfiguration(xml_marshaller.dumps(slap_config))
slap.registerOpenOrder().request(profile, partition_reference=partition_reference,
partition_parameter_kw=None, software_type=None, filter_kw=None,
state=None, shared=False)
partition_parameter_kw=partition_parameter_kw, software_type=None,
filter_kw=None, state=None, shared=False)
return True
def readPid(file):
......@@ -199,9 +218,9 @@ def recursifKill(pids):
for pid in pids:
ppids = pidppid(pid)
try:
os.kill(pid, signal.SIGKILL) #kill current process
os.kill(pid, signal.SIGKILL) #kill current process
except Exception:
pass
pass
recursifKill(ppids) #kill all children of this process
def pidppid(pid):
......@@ -276,8 +295,11 @@ def getSvcStatus(config):
regex = "(^unix:.+\.socket)|(^error:).*$"
supervisord = []
for item in result.split('\n'):
if item != "" and re.search(regex, item) == None:
supervisord.append(re.split('[\s,]+', item))
if item.strip() != "":
if re.search(regex, item, re.IGNORECASE) == None:
supervisord.append(re.split('[\s,]+', item))
else:
return [] #ignore because it is an error message
return supervisord
def getSvcTailProcess(config, process):
......@@ -558,12 +580,12 @@ def readParameters(path):
xmldoc = minidom.parse(path)
object = {}
for elt in xmldoc.childNodes:
sub_object = {}
for subnode in elt.childNodes:
if subnode.nodeType != subnode.TEXT_NODE:
sub_object[str(subnode.getAttribute('id'))] = str(subnode.
sub_object = {}
for subnode in elt.childNodes:
if subnode.nodeType != subnode.TEXT_NODE:
sub_object[str(subnode.getAttribute('id'))] = str(subnode.
childNodes[0].data)
object[str(elt.tagName)] = sub_object
object[str(elt.tagName)] = sub_object
return object
except Exception, e:
return str(e)
......
......@@ -359,8 +359,11 @@ def getPath():
else:
return jsonify(code=1, result=realfile)
@app.route("/loadParameterXml", methods=['POST'])
@app.route("/saveParameterXml", methods=['POST'])
def redParameterXml():
project = os.path.join(app.config['runner_workdir'], ".project")
if not os.path.exists(project):
return jsonify(code=0, result="Please first open a Software Release")
content = request.form['parameter']
param_path = os.path.join(app.config['runner_workdir'], ".parameter.xml")
f = open(param_path, 'w')
......@@ -370,13 +373,17 @@ def redParameterXml():
if type(result) == type(''):
return jsonify(code=0, result="XML Error: " + result)
else:
try:
updateProxy(app.config)
except Exeption:
return jsonify(code=0, result="An error occurred while applying your settings!")
return jsonify(code=1, result="")
@app.route("/getParameterXml", methods=['GET'])
def getParameterXml():
param_path = os.path.join(app.config['runner_workdir'], ".parameter.xml")
if os.path.exists(param_path):
content = open(param_path, 'w').read()
return jsonify(code=1, result=content)
content = open(param_path, 'r').read()
return html_escape(content)
else:
return jsonify(code=0, result="Error: Can not load default instance parameters")
\ No newline at end of file
return "&lt;?xml version='1.0' encoding='utf-8'?&gt;"
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment