Commit 4fa285b7 authored by Stefano Alberto Russo's avatar Stefano Alberto Russo
Browse files

Moved the task interface status check to the connect view. Connecting to a...

Moved the task interface status check to the connect view. Connecting to a task now does not open in a new window anymore.
parent 3b716a0e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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 %}
+12 −2
Original line number Diff line number Diff line
@@ -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>

+23 −32
Original line number Diff line number Diff line
@@ -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):

@@ -398,7 +370,6 @@ def tasks(request):
            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