diff --git a/services/webapp/code/rosetta/core_app/templates/components/task.html b/services/webapp/code/rosetta/core_app/templates/components/task.html index 624b72f7105cf9689267c347ac8110dee699518d..84df41423594d0fb309692d83f3b8b2f33cbe8c7 100644 --- a/services/webapp/code/rosetta/core_app/templates/components/task.html +++ b/services/webapp/code/rosetta/core_app/templates/components/task.html @@ -44,10 +44,10 @@ <!-- <a href="/computing/?uuid={{ task.computing.uuid }}" no_style="color:{{task.computing.color}}"><i class="fa fa-external-link" ></i></a><br/> --> <div style="margin-top:2px"> - {% if task.verified_status == "running" %} + {% if task.status == "running" %} <b>Status:</b> <font color="green">running</font> {% else %} - <b>Status:</b> {{ task.verified_status }} + <b>Status:</b> {{ task.status }} {% endif %} </div> </div> @@ -63,8 +63,8 @@ <!-- Connect --> {% if task.interface_port %} - {% if task.verified_status == "running" %} - <a href="/task_connect/?uuid={{task.uuid}}" class="btn btn-connect" target="_blank">Connect</a> + {% if task.status == "running" %} + <a href="/task_connect/?uuid={{task.uuid}}" class="btn btn-connect">Connect</a> {% else %} <a href="" class="btn btn-disabled">Connect</a> {% endif %} diff --git a/services/webapp/code/rosetta/core_app/templates/task_connect.html b/services/webapp/code/rosetta/core_app/templates/task_connect.html index a618660768330a35f467547d5f5adcbf3de6a487..a373418b59f058f6c9305c78645e7f3ad7582549 100644 --- a/services/webapp/code/rosetta/core_app/templates/task_connect.html +++ b/services/webapp/code/rosetta/core_app/templates/task_connect.html @@ -3,6 +3,7 @@ {% include "navigation.html"%} <!-- with body_args="style='background: #202020'" --> <center> + <div style="width:370px;"> <form class="form-signin" role="form" action='/direct_connect/{{data.task.uuid}}/' method='POST'> {% csrf_token %} @@ -14,6 +15,14 @@ <p style="font-size: 16px;"> <br /> + {% if not data.task.interface_status == 'running' %} + <br/> + <div class="alert alert-warning" role="alert"><i class="fa fa-warning"></i> the task interface is not up, cannot connect.</div> + Please check the <a href="/task_log/?uuid={{ data.task.uuid }}&action=viewlog">task logs</a>. + <br/><br/> + <i>Note: if you just launched the task, this alert might be due to the normal task startup time.</i> + {% else %} + {% if not data.task.requires_proxy_auth %} {% if data.task.container.interface_auth_user %} User: <input style="margin-bottom:15px;" type="username" class="form-control" value="{{ data.task.container.interface_auth_user }}"name='username' readonly > @@ -75,14 +84,14 @@ <b>Port:</b> <code>{{ data.task.tcp_tunnel_port}}</code> </p> {% endif %} - + {% endif%} </p> </form> </div> <br /><br /> - + {% if data.task.interface_status == 'running' %} {% if data.task.requires_proxy_auth %} <p style="margin-left:10px; font-size:0.9em; color:rgb(200,200,200); max-width:600px"> <i class="fa fa-info-warning" style="color:#337ab7"></i> @@ -90,6 +99,7 @@ to a web browser which supports embedding user credentials in the connection URL (as Chorme, Edge or Firefox). </p> {% endif %} + {% endif %} <br /><br /><br /> </center> diff --git a/services/webapp/code/rosetta/core_app/views.py b/services/webapp/code/rosetta/core_app/views.py index 7d63b91905249863e9384ba5af6c00bd9abc0d98..5353604b529c526d6f430141baec9a5ffa450b07 100644 --- a/services/webapp/code/rosetta/core_app/views.py +++ b/services/webapp/code/rosetta/core_app/views.py @@ -339,38 +339,10 @@ def account(request): - #========================= # Tasks view #========================= -def set_verified_status(task): - # Chech status with ping - if task.status == 'running': - logger.debug('Task is running, check if startup completed') - - logger.debug('Trying to establish connection on: "{}:{}"'.format(task.interface_ip,task.interface_port)) - s = socket.socket() - try: - s.settimeout(1) - s.connect((task.interface_ip, task.interface_port)) - # Not necessary, we just check that the container interfcae is up - #if not s.recv(10): - # logger.debug('No data read from socket') - # raise Exception('Could not read any data from socket') - except Exception as e: - logger.debug('Could not connect to socket') - if (pytz.UTC.localize(datetime.datetime.now())-task.created) > datetime.timedelta(hours=1): - task.verified_status = 'not working / killed' - else: - task.verified_status = 'starting up...' - else: - task.verified_status = 'running' - finally: - s.close() - else: - task.verified_status = task.status - @private_view def tasks(request): @@ -397,8 +369,7 @@ def tasks(request): task = Task.objects.get(user=request.user, uuid=uuid) except Task.DoesNotExist: raise ErrorMessage('Task does not exists or no access rights') - - set_verified_status(task) + data['task'] = task # Task actions @@ -479,7 +450,6 @@ def tasks(request): # Update task statuses for task in tasks: task.update_status() - set_verified_status(task) # Set task and tasks variables data['task'] = None @@ -1154,7 +1124,6 @@ def task_connect(request): if not task_uuid: raise ErrorMessage('Empty task uuid') - # Get the task task = Task.objects.get(uuid=task_uuid) @@ -1164,6 +1133,28 @@ def task_connect(request): # Ensure that the tunnel and proxy are set up setup_tunnel_and_proxy(task) + # Check if task interface is up + if task.status == 'running': + logger.debug('Checking if task interface is running by trying to establish connection via local tunnel on port "{}"'.format(task.tcp_tunnel_port)) + s = socket.socket() + try: + s.settimeout(1) + s.connect(('127.0.0.1', task.tcp_tunnel_port)) + # Not necessary, we just check that the container interfcae is up + #if not s.recv(10): + # logger.debug('No data read from socket') + # raise Exception('Could not read any data from socket') + except Exception: + logger.debug('Could not connect to task interface') + task.interface_status = 'unknown' + else: + logger.debug('task interface is answering') + task.interface_status = 'running' + finally: + s.close() + else: + task.interface_status = 'unknown' + data ={} data['task'] = task