Skip to content

Commit

Permalink
refactor: queue open ports (UPC#1709)
Browse files Browse the repository at this point in the history
Queue open ports requests one by one
Wait for open ports request before showing redirections
  • Loading branch information
frankiejol authored Feb 16, 2022
1 parent fffe566 commit 4e15051
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
10 changes: 8 additions & 2 deletions lib/Ravada/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ our %COMMAND = (
,important=> {
limit => 20
,priority => 1
,commands => ['clone','start','start_clones','shutdown_clones','create','open_iptables','list_network_interfaces','list_isos','ping_backend','refresh_machine','open_exposed_ports']
,commands => ['clone','start','start_clones','shutdown_clones','create','open_iptables','list_network_interfaces','list_isos','ping_backend','refresh_machine']
}

,iptables => {
limit => 1
,priority => 2
,commands => ['open_exposed_ports']
}
);
lock_hash %COMMAND;
Expand Down Expand Up @@ -782,7 +788,7 @@ sub _validate_start_domain($self) {
next if !$req;
next if $req->at_time;
next if $command eq 'start' && !$req->after_request();
$self->after_request($req->id) if $req->id < $self->id;
$self->after_request($req->id) if $req && $req->id < $self->id;
}
}

Expand Down
16 changes: 14 additions & 2 deletions public/js/ravada.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@
ws.onmessage = function(event) {
var data = JSON.parse(event.data);
if (data === null || typeof(data) == undefined ) {
console.log("close");
ws.close();
window.location.href="/";
return;
Expand Down Expand Up @@ -1001,7 +1000,6 @@
var already_subscribed_to_domain = false;
$scope.copy_password= function(driver) {
$scope.view_password=1;
console.log("copy-password "+driver);
var copyTextarea = document.querySelector('.js-copytextarea-'+driver);
if (copyTextarea) {
copyTextarea.select();
Expand Down Expand Up @@ -1046,9 +1044,20 @@
already_subscribed_to_domain = true;
$scope.id_domain=data.id_domain;
$scope.subscribe_domain_info(url, data.id_domain);
$scope.open_ports(url, data.id_domain, id_request);
}
}
}
$scope.open_ports = function(url, id_domain, id_request) {
$http.post('/request/open_exposed_ports/'
,JSON.stringify(
{ 'id_domain': id_domain
,'after_request': id_request
})
).then(function(response) {
$scope.request_open_ports = true;
});
}
$scope.subscribe_domain_info= function(url, id_domain) {
already_subscribed_to_domain = true;
var ws = new WebSocket(url);
Expand Down Expand Up @@ -1090,6 +1099,9 @@
redirected_display=true;
}
}
if ($scope.request_open_ports && $scope.domain.ip && $scope.domain.requests == 0) {
$scope.request_open_ports_done = true;
}

}
}
Expand Down
11 changes: 8 additions & 3 deletions templates/main/run_request.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<div class="jumbotron" ng-cloak="">

<h2><%=l 'Running' %> {{domain.name}}</h2>

<div class="alert alert-warning">
<%=l 'A viewer is required to run the virtual machines.' %>
<a href="/requirements"><%=l 'Read more.' %></a>
Expand Down Expand Up @@ -43,8 +42,14 @@
<li><b><%=l 'Memory' %>:</b> {{domain.memory}}</li>
<li><b>CPUs:</b> {{domain.nrVirtCpu}}</li>
</ul>
<h3 ng-show="domain.ports.length">Open ports</h3>
<div class="container pl-5">
<h3 ng-show="domain.ports.length">Open ports
<i ng-hide="request_open_ports && request_open_ports_done"
class="fas fa-sync-alt fa-spin"></i>
</h3>

<div class="container pl-5"
ng-show="request_open_ports && request_open_ports_done">

<table border="0">
<tr ng-repeat="port in domain.ports">
<td align="right">
Expand Down

0 comments on commit 4e15051

Please sign in to comment.