OW2 Consortium contrail

Compare Revisions

Ignore whitespace Rev 2665 → Rev 2666

/trunk/conpaas/conpaas-frontend/www/ajax/taskfarm_sample.php
38,20 → 38,14
 
function unlink_paths($paths) {
foreach ($paths as $file => $path) {
$path = str_replace('@', '', $path);
unlink($path);
}
}
 
$paths = array();
foreach (array('botFile', 'clusterFile') as $file) {
$path = '/tmp/'.$_FILES[$file]['name'];
if (move_uploaded_file($_FILES[$file]['tmp_name'], $path) === false) {
echo json_encode(array(
'error' => 'could not move uploaded file '.$file
));
unlink_paths($paths);
exit();
}
$path = $_FILES[$file]['tmp_name'];
// build the cURL parameter
$paths[$file] = '@'.$path;
}
/trunk/conpaas/conpaas-frontend/www/taskfarm.php
51,184 → 51,16
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script src="js/jquery-1.5.js"></script>
<script src="js/jquery.form.js"></script>
<script src="js/conpaas.js"></script>
</head>
<body>
<script type="text/javascript">
 
var sid = <?php echo $sid; ?>;
/* core functionality */
function isStableState(state) {
return state == 'INIT' || state == 'RUNNING' ||
state == 'STOPPED' || state == 'ERROR';
}
 
var poll_success_cb = null;
var poll_success_cb_param = null;
var poll_error_cb = null;
 
function pollState(delay) {
delay = (typeof delay == 'undefined') ? 1000 : delay + 1000;
count = delay / 1000;
showLoading(true, 'executing, please wait...');
$.ajax({
url: 'ajax/getState.php?sid=<?php echo $sid;?>',
dataType: 'json',
type: 'get',
success: function (response) {
if (typeof response.error != 'undefined') {
showLoading(false);
if (poll_error_cb != null) {
poll_error_cb(response.error);
} else {
alert('pollState() error: ' + response.error);
}
return;
}
if (typeof response.state != 'undefined') {
if (isStableState(response.state)) {
showLoading(false);
freezeInput(false);
if (poll_success_cb != null) {
poll_success_cb(poll_success_cb_param);
poll_success_cb = null;
poll_error_cb = null;
poll_success_cb_param = null;
}
} else {
setTimeout('pollState(' + delay + ');', delay);
}
}
},
error: function() {
showLoading(false);
alert('pollState(): Error loading the state');
}
});
}
 
function showLoading(show, msg) {
show = (typeof show == 'undefined') ? true : show;
msg = (typeof msg == 'undefined') ? 'loading...' : msg;
 
if (show) {
$('#loading b').html(msg);
$('#loading').show();
} else {
$('#loading').hide();
}
}
 
function freezeInput(freeze) {
buttonsSelector = '#startSample, #startExec';
if (freeze) {
$(buttonsSelector).attr('disabled', 'disabled');
} else {
$(buttonsSelector).removeAttr('disabled');
}
}
 
/*
* make request that places the service into transient states, so it
* may need polling
* fields: params: {url, method, success, error, status, poll}
*/
function transientRequest(params) {
params.method =
(typeof params.method == 'undefined') ? 'get' : params.method;
params.success =
(typeof params.success == 'undefined') ? null : params.success;
params.error =
(typeof params.error == 'undefined') ? null : params.error;
params.poll =
(typeof params.poll == 'undefined') ? true : params.poll;
params.data =
(typeof params.data == 'undefined') ? {} : params.data;
 
freezeInput(true);
showLoading(true, params.status);
$.ajax({
url: params.url, type: params.method, dataType: 'json',
data: params.data,
success: function(response) {
if (typeof response.error != 'undefined' && response.error != null ) {
freezeInput(false);
showLoading(false);
if (params.error != null) {
params.error(response.error);
} else {
alert('transientRequest() error: ' + response.error);
}
return;
}
if (typeof params.poll != 'undefined' &&
params.poll == true) {
poll_success_cb = params.success;
poll_error_cb = params.error;
poll_success_cb_param = response;
pollState();
return;
}
freezeInput(false);
showLoading(false);
if (params.success != null) {
params.success(response);
}
},
error: function(response) {
freezeInput(false);
showLoading(false);
alert('transientRequest(): Error sending the request');
}
});
}
</script>
 
<?php echo $page->renderHeader(); ?>
<?php echo PageStatus()->setId('loading'); ?>
 
<div class="pagecontent">
<?php echo $page->renderTopMenu(); ?>
 
<script>
$(document).ready(function() {
$('#name').click(function() {
newname = prompt("Enter a new name", $('#name').html());
if (newname != null && newname != "") {
$.ajax({
url: 'ajax/saveName.php?sid='+sid,
type: 'post',
dataType: 'json',
data: {
name: newname,
},
success: function(response) {
if (response.save == 1) {
$('#name').html(newname);
}
}
});
}
});
 
$('#terminate').click(function() {
if (!confirm('After termination, the service will be completely'
+ ' destroyed. Are you sure you want to continue?')) {
return;
}
transientRequest({
url: 'ajax/terminateService.php?sid='+sid,
method: 'post',
success: function(response) {
window.location = 'index.php';
},
status: 'terminating service...',
poll: false
});
});
 
});
</script>
 
<?php if ($service->isConfigurable()): ?>
 
<div class="form-section">
274,51 → 106,6
</table>
</form>
<div class="clear"></div>
<script type="text/javascript">
 
$(document).ready(function() {
$('#fileForm').ajaxForm({
dataType: 'json',
success: function(response) {
$('.additional .loading').toggleClass('invisible');
if (typeof response.error != 'undefined' && response.error != null) {
alert('Error: ' + response.error);
$('#botFile').val('');
$('#xmlFile').val('');
return;
}
$('.additional .positive').show();
setTimeout('$(".additional .positive").fadeOut();', 1000);
// request ended ok
$('#botFile').val('');
$('#xmlFile').val('');
// poll sample phase
poll_success_cb = function (param) {
window.location.reload();
}
freezeInput(true);
pollState();
},
error: function(error) {
alert('#fileForm.ajaxForm() error: ' + response.error);
}
});
 
$('#startSample').click(function() {
if ($('#botFile').val() == '') {
alert('Please choose a .bot file');
return;
}
if ($('#xmlFile').val() == '') {
alert('Please choose a .xml file');
return;
}
$('.additional .loading').toggleClass('invisible');
$('#fileForm').submit();
});
});
 
</script>
</div>
 
<?php if ($service->hasSamplingResults()): ?>
354,114 → 141,7
</table>
</div>
 
<script type="text/javascript">
google.load('visualization', '1.0', {'packages':['corechart']});
var samplingResults = null;
var chart = null;
 
function executionScheduleSelected(e) {
selectedSampling = samplingResults[$('#samplings').attr('selectedIndex')];
scheduleIndex = chart.getSelection()[0].row;
$('#scheduleDetails').html(selectedSampling.schedules[scheduleIndex]);
console.log(scheduleIndex);
}
 
function drawChart(schedules) {
var data = new google.visualization.DataTable();
data.addColumn('number', 'Execution Time');
data.addColumn('number', 'Cost');
$.each(schedules, function (index, schedule) {
budget = parseInt(schedule.split('\t')[1]);
console.log(schedule.split('\t'));
data.addRow([(index + 1) * 15, budget]);
});
var options = {
width: 400, height: 240,
title: 'Execution Options',
pointSize: 3,
hAxis: {
title: 'Time Needed (minutes)',
minValue: 0
},
vAxis: {
title: 'Budget/Cost'
}
};
chart = new google.visualization.LineChart(document.getElementById('executionChart'));
google.visualization.events.addListener(chart, 'select', executionScheduleSelected);
chart.draw(data, options);
}
 
function loadSamplingResults() {
$.ajax({
url: 'ajax/taskfarm_getSamplingResults.php?sid=' + sid,
type: 'get',
dataType: 'json',
success: function(response) {
if (typeof response.error != 'undefined' && response.error != null) {
alert('Error loading sampling results: ' + response.error);
return;
}
samplingResults = response;
$('#samplings').empty();
$.each(samplingResults, function (index, sampling) {
$('#samplings').append($("<option></option>")
.attr("value", sampling.timestamp)
.text(sampling.name));
});
updateExecutionOptions();
}
});
}
 
function updateExecutionOptions() {
selectedSampling = $('#samplings').attr('selectedIndex');
options = samplingResults[selectedSampling].schedules;
drawChart(options);
}
 
$(document).ready(function() {
 
$('#samplings').change(function() {
updateExecutionOptions();
});
 
$('#startExec').click(function() {
if (chart.getSelection().length == 0) {
alert('Please select an execution option');
return;
}
executionOption = chart.getSelection()[0];
$.ajax({
url: 'ajax/taskfarm_runExecution.php',
type: 'post',
data: {
sid: sid,
schedulesFile: samplingResults[$('#samplings').attr('selectedIndex')].timestamp,
scheduleNo: executionOption.row
},
dataType: 'json',
success: function(response) {
if (typeof response.error != 'undefined' && response.error != null) {
alert('Error running execution: ' + response.error);
return;
}
console.log("execution started");
pollState();
}
});
});
 
loadSamplingResults();
});
</script>
<?php endif; ?>
<?php if (!$service->isStable()): ?>
<script type="text/javascript">
freezeInput(true);
pollState();
</script>
<?php endif; ?>
 
<?php else: ?>
<div class="box infobox">
472,5 → 152,8
 
</div>
<?php echo $page->renderFooter(); ?>
<?php echo $page->generateJSGetParams(); ?>
<script type="text/javascript" src="js/servicepage.js"></script>
<script type="text/javascript" src="js/taskfarm.js"></script>
</body>
</html>
/trunk/conpaas/conpaas-frontend/www/lib/service/taskfarm/__init__.php
42,6 → 42,14
return $state;
}
 
public function getNodeInfo($node) {
return false;
}
 
public function getAccessLocation() {
return false;
}
 
/**
* TODO: request implementation of this call in the TaskFarm backend
*/
/trunk/conpaas/conpaas-frontend/www/js/taskfarm.js
New file
0,0 → 1,190
/*
* Copyright (C) 2010-2012 Contrail consortium.
*
* This file is part of ConPaaS, an integrated runtime environment
* for elastic cloud applications.
*
* ConPaaS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* ConPaaS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ConPaaS. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @require conpaas.js, servicepage.js
*/
conpaas.ui = (function (this_module) {
/**
* conpaas.ui.TaskFarmPage
*/
this_module.TaskFarmPage = conpaas.new_constructor(
/* extends */conpaas.ui.ServicePage,
/* constructor */function (server, service) {
this.server = server;
this.service = service;
this.setupPoller_();
this.chart = null;
this.samplingResults = null;
},
/* methods */{
freezeInput: function (freeze) {
var buttonsSelector = '#startSample, #startExec';
if (freeze) {
$(buttonsSelector).attr('disabled', 'disabled');
} else {
$(buttonsSelector).removeAttr('disabled');
}
},
loadSamplingResults: function () {
var that = this;
this.server.req('ajax/taskfarm_getSamplingResults.php',
{sid: this.service.sid}, 'get', function (response) {
that.samplingResults = response;
$('#samplings').empty();
$.each(that.samplingResults, function (index, sampling) {
$('#samplings').append($("<option></option>")
.attr("value", sampling.timestamp)
.text(sampling.name));
});
});
},
drawChart: function (schedules) {
var data = new google.visualization.DataTable(),
options,
that = this;
data.addColumn('number', 'Execution Time');
data.addColumn('number', 'Cost');
$.each(schedules, function (index, schedule) {
budget = parseInt(schedule.split('\t')[1]);
console.log(schedule.split('\t'));
data.addRow([(index + 1) * 15, budget]);
});
options = {
width: 400, height: 240,
title: 'Execution Options',
pointSize: 3,
hAxis: {
title: 'Time Needed (minutes)',
minValue: 0
},
vAxis: {
title: 'Budget/Cost'
}
};
this.chart = new google.visualization.LineChart(
document.getElementById('executionChart'));
google.visualization.events.addListener(chart, 'select', function () {
var selectedSampling,
scheduleIndex;
selectedSampling = that.samplingResults[$('#samplings').attr(
'selectedIndex')];
scheduleIndex = that.chart.getSelection()[0].row;
$('#scheduleDetails').html(
selectedSampling.schedules[scheduleIndex]);
console.log(scheduleIndex);
});
this.chart.draw(data, options);
},
attachHandlers: function () {
var that = this;
// first attach parent handlers
conpaas.ui.ServicePage.prototype.attachHandlers.call(this);
// ajaxify the file form
$('#fileForm').ajaxForm({
dataType: 'json',
success: function(response) {
$('.additional .loading').toggleClass('invisible');
$('.additional .positive').show();
setTimeout(function () {
$(".additional .positive").fadeOut();
}, 1000);
$('#botFile').val('');
$('#xmlFile').val('');
that.displayInfo('performing sampling...');
that.freezeInput(true);
that.pollState(function () {
window.location.reload();
}, function () {
that.freezeInput(false);
});
},
error: function(response) {
that.poller.stop();
// show the error
that.server.handleError({name: 'service error',
details: response.error});
}
});
$('#startSample').click(function () {
if ($('#botFile').val() == '') {
alert('Please choose a .bot file');
return;
}
if ($('#xmlFile').val() == '') {
alert('Please choose a .xml file');
return;
}
$('.additional .loading').toggleClass('invisible');
$('#fileForm').submit();
});
$('#samplings').change(this, this.onSampleChange);
$('#startExec').click(this, this.onStartExec);
},
onSampleChange: function (event) {
var page = event.data,
selectedSampling;
selectedSampling = $('#samplings').attr('selectedIndex');
options = page.samplingResults[selectedSampling].schedules;
page.drawChart(options);
},
onStartExec: function (event) {
var page = event.data,
executionOption,
selections = page.chart.getSelection();
if (selections.length == 0) {
alert('Please select an execution option');
return;
}
executionOption = selections[0];
page.server.req('ajax/taskfarm_runExecution.php', {
sid: page.service.sid,
schedulesFile: page.samplingResults[$('#samplings').attr('selectedIndex')].timestamp,
scheduleNo: executionOptions.row
}, 'post', function (response) {
page.displayInfo('performing sampling...');
page.freezeInput(true);
page.pollState(function () {
window.location.reload();
}, function () {
page.freezeInput(false);
});
});
}
});
 
return this_module;
}(conpaas.ui || {}));
 
// load the google visualization API
google.load('visualization', '1.0', {'packages':['corechart']});
 
$(document).ready(function () {
var service,
page,
sid = GET_PARAMS['sid'],
server = new conpaas.http.Xhr();
 
server.req('ajax/getService.php', {sid: sid}, 'get', function (data) {
service = new conpaas.model.Service(data.sid, data.state,
data.instanceRoles, data.reachable);
page = new conpaas.ui.TaskFarmPage(server, service);
page.attachHandlers();
page.loadSamplingResults();
});
});