Commit bde69b50 authored by Efthymia Bika's avatar Efthymia Bika

Create container assigned to selected project

parent 74f28723
......@@ -150,6 +150,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
if(save_pass) {
$("#passphrase").prop("disabled", disable);
}
var project = $("#project_div");
if(project) {
$("#project").prop("disabled", disable);
}
if(disable) {
$("#save_button").hide();
$("#go_to_restore_button").show();
......@@ -250,6 +254,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
$("#loader").hide();
}
function handle_err(data) {
console.error("error === " + data);
$("#loader").hide();
toggle_msgs(data, "msg", false);
if(data.toString().indexOf("401 UNAUTHORIZED") > -1) {
show_cloud_error();
}
}
var projects = [];
function get_quotas(data) {
var cloud = $("#cloud").val();
......@@ -268,10 +281,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
});
}
function handle_err(data) {
console.error("error === " + data);
toggle_msgs(data, "msg", false);
$("#loader").hide();
function show_cloud_error() {
toggle_msgs(false, "msg", false);
show_alert_box("A problem occured.<br>" +
"Please check your <a href='#' " +
"onclick=$('#cloud-settings-link').trigger('click')>" +
"cloud settings</a>", "error", false);
}
function get_projects() {
......@@ -375,7 +390,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<small class="error"></small>
</div>
</div>
<div class="clearfix">
<div class="clearfix" id="project_div">
<div class="small-3 columns">
<label id="project_label" for="project"
class="right inline">Project</label>
......
......@@ -37,6 +37,7 @@ function toggle_msgs(data, msgDiv, append) {
}
} else {
$("#" + msgDiv).html(data);
$("#msg").removeClass("hide");
}
$("#" + msgDiv).addClass("panel");
} else {
......@@ -117,9 +118,12 @@ function load_backup(backup) {
if(backup.first_backup) {
disable_form(true);
disable_actions(false);
$("#project_div").hide();
} else {
disable_actions(true);
disable_form(false);
$("#project_div").show();
$("#cloud").trigger("change");
}
$("#exclude").val(backup.exclude);
$("#include").val(backup.include);
......@@ -132,6 +136,8 @@ function load_backup(backup) {
$("#directory").html('');
$("#res-directory").html('');
$("#cloud").val('');
$("#project_div").show();
$("#project").val('');
$("#passphrase").val('');
$("#exclude").val('');
$("#include").val('');
......
......@@ -221,10 +221,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}
var send_data =
JSON.stringify({ auth: { token: { id: token } } });
astakos.post(
'/tokens', null, send_data, 200,
handle_result,
handle_err
astakos.post('/tokens', null, send_data, 200,
handle_result, handle_err
);
} else {
$('#token-error small').text(errors.token_cloudless);
......@@ -325,7 +323,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var lurl = account_ui + '/logout?next=' + pithos_public
got_cookie = false;
cred_win = gui.Window.open(lurl, {
focus: true, width: 820, height: 780, toolbar: false
focus: true, width: 820, height: 700, toolbar: false
});
cred_win.cookies.onChanged.addListener(function(info) {
if (info.cookie.name === cookie_name) {
......
......@@ -71,14 +71,6 @@ function make_env() {
return env;
}
function show_cloud_error() {
toggle_msgs(false, "msg", false);
show_alert_box("A problem occured.<br>" +
"Please check your <a href='#' " +
"onclick=$('#cloud-settings-link').trigger('click')>" +
"cloud settings</a>", "error", false);
}
function build_extra_args(field_value, type, params) {
var args = field_value.split(",");
$.each(args, function(i, value) {
......@@ -153,13 +145,43 @@ function array_to_str(args) {
}
return str;
}
function call_duplicity(mode, backup_set, force) {
toggle_msgs(false, "msg", false);
var win_cmd = "";
function handle_error(data) {
toggle_msgs(data.toString(), "msg", false);
$("#loader").hide();
}
function handle_success() {
spawn_dup_process(arguments[0].args, arguments[0].backup_set,
arguments[0].backup_name, arguments[0].mode);
}
function create_container(args, backup_set, backup_name, mode) {
try {
var astakos =
getClient('astakos',
clouds[backup_set.cloud].pithos_public,
clouds[backup_set.cloud].token,
clouds[backup_set.cloud].cert);
var pithos_url =
"/" + clouds[backup_set.cloud].uuid + "/" + backup_set.container;
var headers = {"X-Container-Policy-project" : $("#project").val()};
astakos.put(pithos_url, headers, null, [201, 202],
handle_success.bind(null, {args: args, backup_set: backup_set,
backup_name: backup_name, mode: mode}),
handle_error);
} catch (err) {
toggle_msgs(err, "msg", false);
return false;
}
return true;
}
function build_dup_args(mode, backup_set, force, backup_name) {
var args = [];
args.push(DUPLICITY_PATH);
switch(mode) {
case "backup":
var local_dir = (process.platform == "win32") ?
......@@ -228,10 +250,6 @@ function call_duplicity(mode, backup_set, force) {
args.push("--log-file", log_file);
args.push("--archive-dir", BAAS_ARCHIVE_DIR);
args.push("--gpg-homedir", GPG_DIR);
var backup_name = (backup_set) ?
hashed_backup_name(backup_set.cloud, backup_set.name) :
hashed_backup_name($("#res-cloud").val(), $("#res-backup-name"));
args.push("--name", backup_name);
var sel_cloud = (backup_set) ? backup_set.cloud :
......@@ -242,9 +260,12 @@ function call_duplicity(mode, backup_set, force) {
if(force) args.push("--force");
return args;
}
function spawn_dup_process(args, backup_set, backup_name, mode) {
// call duplicity
var wProcess = null;
wProcess = spawn(ENV_CMD, args, {env: make_env()});
var wProcess = spawn(ENV_CMD, args, {env: make_env()});
running_processes.push([wProcess, backup_name]);
var output_str = "";
......@@ -296,6 +317,7 @@ function call_duplicity(mode, backup_set, force) {
backup_set.last_backup = new Date();
if(typeof backup_set.first_backup == 'undefined') {
backup_set.first_backup = new Date();
$("#project_div").hide();
}
$("#inc").prop("disabled", false);
$("#inc").prop("checked", true);
......@@ -325,7 +347,7 @@ function call_duplicity(mode, backup_set, force) {
}
} else if(mode == "timeview") {
if(code == 0) {
parse_collection_status(output_str, log_file);
parse_collection_status(output_str, args[4]);
} else if(code == DUP_ERR_CODES.CONNECTION_FAILED) {
show_cloud_error();
}
......@@ -340,5 +362,19 @@ function call_duplicity(mode, backup_set, force) {
wProcess.stderr.setEncoding('utf8');
wProcess.stderr.on('data', dup_call_err);
wProcess.on('exit', dup_call_exit);
}
function call_duplicity(mode, backup_set, force) {
toggle_msgs(false, "msg", false);
var backup_name = (backup_set) ?
hashed_backup_name(backup_set.cloud, backup_set.name) :
hashed_backup_name($("#res-cloud").val(), $("#res-backup-name"));
var args = build_dup_args(mode, backup_set, force, backup_name);
if(mode == "backup" && typeof backup_set.first_backup === 'undefined') {
create_container(args, backup_set, backup_name, mode);
} else {
spawn_dup_process(args, backup_set, backup_name, mode);
}
}
......@@ -86,7 +86,9 @@ var Client = function(endpointURL, token, CAPath) {
this.setToken(token);
this.setCA(CAPath);
this.post = function(path, headers, send_data, status, handle_res, handle_err) {
this.post = function(path, headers, send_data,
status, handle_res, handle_err) {
handle_res = handle_res || function(r){ console.log(r); };
handle_err = handle_err || function(e){ console.log(e); };
......@@ -95,8 +97,8 @@ var Client = function(endpointURL, token, CAPath) {
path: _endpoint + path,
}, _options);
post_opts.headers = util._extend({}, _options.headers);
util._extend(post_opts.headers, headers);
if (send_data) {
h = post_opts.headers;
util._extend(post_opts.headers, {
......@@ -153,6 +155,45 @@ var Client = function(endpointURL, token, CAPath) {
_req.end();
_req.on('error', handle_err);
};
this.put = function(path, headers, send_data,
status, handle_res, handle_err) {
handle_res = handle_res || function(r){ console.log(r); };
handle_err = handle_err || function(e){ console.log(e); };
var put_opts = util._extend({
method: 'PUT',
path: _endpoint + path,
}, _options);
put_opts.headers = util._extend({}, _options.headers);
util._extend(put_opts.headers, headers);
if (send_data) {
h = put_opts.headers;
util._extend(put_opts.headers, {
'Content-Type': h['Content-Type'] || 'application/json',
'Content-Length': h['Content-Length'] ||
Buffer.byteLength(send_data),
});
};
_req = _protocol.request(put_opts, function(res){
_recv_data = '';
res.on('data', function(d) { _recv_data+=d; });
res.on('end', function() {
if ((status || [200]).indexOf(res.statusCode) < 0) {
handle_err(res.statusCode + " " +
res.statusMessage, res.headers);
} else handle_res(_recv_data, res.headers);
});
});
if (send_data) _req.write(send_data);
_req.end();
_req.on('error', handle_err);
};
};
module.exports = { Client: Client };
......
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