Ejemplo n.º 1
0
    def post(self, zapp_id):
        """Write the parameters in the description and start the ZApp."""
        uid, role = get_auth(self)
        if uid is None:
            return self.redirect(self.get_argument('next', u'/login'))

        manifest_index = int(zapp_id.split('-')[-1])
        zapp_id = "-".join(zapp_id.split('-')[:-1])
        zapps = zapp_shop.zshop_read_manifest(zapp_id)
        zapp = zapps[manifest_index]

        exec_name = self.get_argument('exec_name')

        app_descr = self._set_parameters(zapp.zoe_description, zapp.parameters,
                                         role)

        try:
            self.get_argument('download_json')
            self.set_header('Content-Type', 'application/json')
            self.set_header('Content-Disposition',
                            'attachment; filename={}.json'.format(zapp_id))
            self.write(app_descr)
            self.finish()
            return
        except MissingArgumentError:
            new_id = self.api_endpoint.execution_start(uid, role, exec_name,
                                                       app_descr)

        self.redirect(self.reverse_url('execution_inspect', new_id))
Ejemplo n.º 2
0
    def get(self, zapp_id):
        """Home page with authentication."""
        uid, role = get_auth(self)
        if uid is None:
            return self.redirect(self.get_argument('next', u'/login'))

        manifest_index = int(zapp_id.split('-')[-1])
        zapp_id = "-".join(zapp_id.split('-')[:-1])
        zapps = zapp_shop.zshop_read_manifest(zapp_id)
        zapp = zapps[manifest_index]

        template_vars = {
            "uid":
            uid,
            "role":
            role,
            'zapp':
            zapp,
            'max_core_limit':
            get_conf().max_core_limit,
            'max_memory_limit':
            get_conf().max_memory_limit,
            'resources_are_customizable':
            role == "admin"
            or (role != "guest" and
                (role == "user" and not get_conf().no_user_edit_limits_web)),
            'additional_volumes':
            get_conf().additional_volumes
        }
        self.render('zapp_start.html', **template_vars)
Ejemplo n.º 3
0
    def get(self, page=0):
        """Home page with authentication."""
        uid, role = get_auth(self)
        if uid is None:
            self.redirect(self.get_argument('next', u'/login'))
            return

        page = int(page)
        executions_count = self.api_endpoint.execution_count(uid, role)
        executions = self.api_endpoint.execution_list(
            uid,
            role,
            base=page * self.PAGINATION_ITEM_COUNT,
            limit=self.PAGINATION_ITEM_COUNT)

        template_vars = {
            "uid": uid,
            "role": role,
            'executions': sorted(executions, key=lambda e: e.id, reverse=True),
            'current_page': page,
            'max_page':
            math.ceil(executions_count / self.PAGINATION_ITEM_COUNT),
            'last_page': len(executions) < self.PAGINATION_ITEM_COUNT
        }
        self.render('execution_list.html', **template_vars)
Ejemplo n.º 4
0
    def get(self, execution_id):
        """Gather details about an execution."""
        uid, role = get_auth(self)
        if uid is None:
            self.redirect(self.get_argument('next', u'/login'))
            return

        e = self.api_endpoint.execution_by_id(uid, role, execution_id)

        services_info, endpoints = self.api_endpoint.execution_endpoints(
            uid, role, e)

        endpoints = self.api_endpoint.execution_endpoints(uid, role, e)[1]

        template_vars = {
            "uid": uid,
            "role": role,
            "e": e,
            "services_info": services_info,
            "endpoints": endpoints,
        }

        if get_conf().enable_plots and e.time_start is not None:
            grafana_url_template = 'http://bigfoot-m2.eurecom.fr/grafana/dashboard/db/zoe-executions?orgId=1&from={}&to={}&var-execution_id={}&refresh=1y'
            if e.time_end is None:
                e_time_end = int(time.time() * 1000)
            else:
                e_time_end = int((e.time_end - datetime.datetime(1970, 1, 1)) /
                                 datetime.timedelta(seconds=1) * 1000)
            e_time_start = int((e.time_start - datetime.datetime(1970, 1, 1)) /
                               datetime.timedelta(seconds=1) * 1000)
            template_vars['grafana_url'] = grafana_url_template.format(
                e_time_start, e_time_end, execution_id)

        self.render('execution_inspect.html', **template_vars)
Ejemplo n.º 5
0
    def get(self, execution_id: int):
        """Restart an already defined (and not running) execution."""
        uid, role = get_auth(self)

        e = self.api_endpoint.execution_by_id(uid, role, execution_id)
        new_id = self.api_endpoint.execution_start(uid, role, e.name, e.description)

        self.redirect(self.reverse_url('execution_inspect', new_id))
Ejemplo n.º 6
0
def execution_restart(execution_id):
    uid, role = get_auth(request)
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)

    e = config.api_endpoint.execution_by_id(uid, role, execution_id)
    new_id = config.api_endpoint.execution_start(uid, role, e.name, e.description)

    return redirect(url_for('web.execution_inspect', execution_id=new_id))
Ejemplo n.º 7
0
def execution_restart(execution_id):
    uid, role = get_auth(request)
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)

    e = config.api_endpoint.execution_by_id(uid, role, execution_id)
    new_id = config.api_endpoint.execution_start(uid, role, e.name,
                                                 e.description)

    return redirect(url_for('web.execution_inspect', execution_id=new_id))
Ejemplo n.º 8
0
    def get(self, execution_id: int):
        """Terminate an execution."""
        uid, role = get_auth(self)

        success, message = self.api_endpoint.execution_terminate(uid, role, execution_id)
        if not success:
            raise zoe_api.exceptions.ZoeException(message)

        self.redirect(self.reverse_url('home_user'))
Ejemplo n.º 9
0
 def open(self, *args, **kwargs):
     """Invoked when a new WebSocket is opened."""
     log.debug('WebSocket opened')
     uid, role = get_auth(self)
     if uid is None:
         self.close(401, "Unauthorized")
     else:
         self.uid = uid
         self.role = role
Ejemplo n.º 10
0
def execution_delete(execution_id):
    uid, role = get_auth(request)
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)

    success, message = config.api_endpoint.execution_delete(uid, role, execution_id)
    if not success:
        raise zoe_api.exceptions.ZoeException(message)

    return redirect(url_for('web.home_user'))
Ejemplo n.º 11
0
def execution_delete(execution_id):
    uid, role = get_auth(request)
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)

    success, message = config.api_endpoint.execution_delete(
        uid, role, execution_id)
    if not success:
        raise zoe_api.exceptions.ZoeException(message)

    return redirect(url_for('web.home_user'))
Ejemplo n.º 12
0
    def post(self):
        """Start an execution."""
        uid, role = get_auth(self)

        app_descr_json = self.request.files['file'][0]['body'].decode('utf-8')
        app_descr = json.loads(app_descr_json)
        exec_name = self.get_argument('exec_name')

        new_id = self.api_endpoint.execution_start(uid, role, exec_name, app_descr)

        self.redirect(self.reverse_url('execution_inspect', new_id))
Ejemplo n.º 13
0
    def get(self, execution_id: int):
        """Restart an already defined (and not running) execution."""
        uid, role = get_auth(self)
        if uid is None:
            return self.redirect(self.get_argument('next', u'/login'))

        e = self.api_endpoint.execution_by_id(uid, role, execution_id)
        new_id = self.api_endpoint.execution_start(uid, role, e.name,
                                                   e.description)

        self.redirect(self.reverse_url('execution_inspect', new_id))
Ejemplo n.º 14
0
def execution_start():
    uid, role = get_auth(request)
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)

    app_descr_json = request.files['file'].read().decode('utf-8')
    app_descr = json.loads(app_descr_json)
    exec_name = request.form['exec_name']

    new_id = config.api_endpoint.execution_start(uid, role, exec_name, app_descr)

    return redirect(url_for('web.execution_inspect', execution_id=new_id))
Ejemplo n.º 15
0
    def get(self, execution_id: int):
        """Terminate an execution."""
        uid, role = get_auth(self)
        if uid is None:
            return self.redirect(self.get_argument('next', u'/login'))

        success, message = self.api_endpoint.execution_terminate(
            uid, role, execution_id)
        if not success:
            raise zoe_api.exceptions.ZoeException(message)

        self.redirect(self.reverse_url('home_user'))
Ejemplo n.º 16
0
def execution_start():
    uid, role = get_auth(request)
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)

    app_descr_json = request.files['file'].read().decode('utf-8')
    app_descr = json.loads(app_descr_json)
    exec_name = request.form['exec_name']

    new_id = config.api_endpoint.execution_start(uid, role, exec_name,
                                                 app_descr)

    return redirect(url_for('web.execution_inspect', execution_id=new_id))
Ejemplo n.º 17
0
    def get(self, zapp_id):
        """Home page with authentication."""
        uid, role_ = get_auth(self)
        if uid is None:
            return self.redirect(self.get_argument('next', u'/login'))

        self.set_header("Content-type", "image/png")

        manifest_index = int(zapp_id.split('-')[-1])
        zapp_id = "-".join(zapp_id.split('-')[:-1])
        zapps = zapp_shop.zshop_read_manifest(zapp_id)
        zapp = zapps[manifest_index]
        self.write(zapp_shop.get_logo(zapp))
Ejemplo n.º 18
0
    def get(self, service_id):
        """Gather details about an execution."""
        uid, role = get_auth(self)
        if uid is None:
            return self.redirect(self.get_argument('next', u'/login'))

        service = self.api_endpoint.service_by_id(uid, role, service_id)

        template_vars = {
            "uid": uid,
            "role": role,
            "service": service,
        }
        self.render('service_logs.html', **template_vars)
Ejemplo n.º 19
0
    def get(self):
        """Home page with authentication."""
        uid, role = get_auth(self)
        if uid is None:
            return self.redirect(self.get_argument('next', u'/login'))

        executions = self.api_endpoint.execution_list(uid, role)

        template_vars = {
            "uid": uid,
            "role": role,
            'executions': sorted(executions, key=lambda e: e.id, reverse=True)
        }
        self.render('execution_list.html', **template_vars)
Ejemplo n.º 20
0
    def get(self):
        """Home page with authentication."""
        uid, role = get_auth(self)
        if uid is None:
            return self.redirect(self.get_argument('next', u'/login'))

        zapps = zapp_shop.zshop_list_apps(role)

        template_vars = {
            "uid": uid,
            "role": role,
            'zapps': zapps,
        }
        self.render('zapp_shop.html', **template_vars)
Ejemplo n.º 21
0
    def get(self, execution_id):
        """Gather details about an execution."""
        uid, role = get_auth(self)

        e = self.api_endpoint.execution_by_id(uid, role, execution_id)

        services_info = []
        for service in e.services:
            services_info.append(self.api_endpoint.service_by_id(uid, role, service.id))

        template_vars = {
            "e": e,
            "services_info": services_info
        }
        self.render('execution_inspect.html', **template_vars)
Ejemplo n.º 22
0
    def get(self):
        """Home page with authentication."""
        uid, role = get_auth(self)
        if uid is None:
            self.redirect(self.get_argument('next', u'/login'))
            return

        filters = {"user_id": uid, "limit": 5}
        last_executions = self.api_endpoint.execution_list(
            uid, role, **filters)

        filters = {"user_id": uid, "status": "running"}
        last_running_executions = self.api_endpoint.execution_list(
            uid, role, **filters)

        filters = {"user_id": uid, "status": "submitted"}
        last_running_executions += self.api_endpoint.execution_list(
            uid, role, **filters)

        filters = {"user_id": uid, "status": "scheduled"}
        last_running_executions += self.api_endpoint.execution_list(
            uid, role, **filters)

        filters = {"user_id": uid, "status": "starting"}
        last_running_executions += self.api_endpoint.execution_list(
            uid, role, **filters)

        running_reservations = [
            e.total_reservations for e in last_running_executions
        ]
        total_memory = sum([r.memory.max for r in running_reservations])
        total_cores = sum([r.cores.max for r in running_reservations])

        template_vars = {
            "uid":
            uid,
            "role":
            role,
            "total_memory":
            total_memory,
            "total_cores":
            total_cores,
            'last_executions':
            sorted(last_executions, key=lambda e: e.id),
            'running_executions':
            sorted(last_running_executions, key=lambda e: e.id)
        }
        self.render('home_user.html', **template_vars)
Ejemplo n.º 23
0
def execution_inspect(execution_id):
    uid, role = get_auth(request)
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)

    e = config.api_endpoint.execution_by_id(uid, role, execution_id)

    services_info = {}
    if e.service_list is not None:
        for s in e.service_list:
            services_info[s.id] = config.api_endpoint.service_inspect(uid, role, s)

    template_vars = {
        "e": e,
        "services": e.service_list,
        "services_info": services_info
    }
    return render_template('execution_inspect.html', **template_vars)
Ejemplo n.º 24
0
def execution_inspect(execution_id):
    uid, role = get_auth(request)
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)

    e = config.api_endpoint.execution_by_id(uid, role, execution_id)

    services_info = {}
    if e.service_list is not None:
        for s in e.service_list:
            services_info[s.id] = config.api_endpoint.service_inspect(
                uid, role, s)

    template_vars = {
        "e": e,
        "services": e.service_list,
        "services_info": services_info
    }
    return render_template('execution_inspect.html', **template_vars)
Ejemplo n.º 25
0
    def get(self, execution_id):
        """Gather details about an execution."""
        uid, role = get_auth(self)
        if uid is None:
            return self.redirect(self.get_argument('next', u'/login'))

        e = self.api_endpoint.execution_by_id(uid, role, execution_id)

        services_info, endpoints = self.api_endpoint.execution_endpoints(
            uid, role, e)

        endpoints = self.api_endpoint.execution_endpoints(uid, role, e)[1]

        template_vars = {
            "uid": uid,
            "role": role,
            "e": e,
            "services_info": services_info,
            "endpoints": endpoints,
        }
        self.render('execution_inspect.html', **template_vars)
Ejemplo n.º 26
0
Archivo: start.py Proyecto: townie/zoe
def home_user():
    uid, role = get_auth(request)
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)

    if role == 'user' or role == 'admin':
        executions = config.api_endpoint.execution_list(uid, role)

        template_vars = {
            'executions': executions,
            'is_admin': role == 'admin',
        }
        return render_template('home_user.html', **template_vars)
    else:
        template_vars = {
            'refresh': randint(2, 8),
            'execution_status': 'Please wait...',
            'execution_urls': [],
        }

        app_descr = json.load(open('contrib/zoeapps/eurecom_aml_lab.json', 'r'))
        execution = config.api_endpoint.execution_list(uid, role, name='aml-lab')
        if len(execution) == 0 or execution[0]['status'] == 'terminated' or execution[0]['status'] == 'finished':
            config.api_endpoint.execution_start(uid, role, 'aml-lab', app_descr)
            template_vars['execution_status'] = 'submitted'
            return render_template('home_guest.html', **template_vars)
        else:
            execution = execution[0]
            if execution['status'] != 'running':
                template_vars['execution_status'] = execution['status']
                return render_template('home_guest.html', **template_vars)
            else:
                template_vars['refresh'] = -1
                cont_api = ZoeServiceAPI(get_conf().master_url, guest_identifier, guest_password)
                template_vars['execution_status'] = execution['status']
                for c_id in execution['services']:
                    c = cont_api.get(c_id)
                    ip = list(c['ip_address'].values())[0]  # FIXME how to decide which network is the right one?
                    for p in c['ports']:
                        template_vars['execution_urls'].append(('{}'.format(p['name']), '{}://{}:{}{}'.format(p['protocol'], ip, p['port_number'], p['path'])))
                return render_template('home_guest.html', **template_vars)
Ejemplo n.º 27
0
Archivo: start.py Proyecto: nuaays/zoe
    def get(self):
        """Home page with authentication."""
        uid, role = get_auth(self)

        if role == 'user' or role == 'admin':
            executions = self.api_endpoint.execution_list(uid, role)

            template_vars = {
                'executions': sorted(executions, key=lambda e: e.id),
                'is_admin': role == 'admin',
            }
            self.render('home_user.html', **template_vars)
        else:
            template_vars = {
                'refresh': randint(2, 8),
                'execution_status': 'Please wait...',
                'execution_urls': [],
            }

            app_descr = json.load(open('contrib/zoeapps/eurecom_aml_lab.json', 'r'))
            execution = self.api_endpoint.execution_list(uid, role, name='aml-lab')
            if len(execution) == 0 or execution[0]['status'] == 'terminated' or execution[0]['status'] == 'finished':
                self.api_endpoint.execution_start(uid, role, 'aml-lab', app_descr)
                template_vars['execution_status'] = 'submitted'
                return self.render('home_guest.html', **template_vars)
            else:
                execution = execution[0]
                if execution['status'] != 'running':
                    template_vars['execution_status'] = execution['status']
                    return self.render('home_guest.html', **template_vars)
                else:
                    template_vars['refresh'] = -1
                    template_vars['execution_status'] = execution['status']
                    # for c_id in execution['services']:
                    #    c = cont_api.get(c_id)
                    #    ip = list(c['ip_address'].values())[0]  # FIXME how to decide which network is the right one?
                    #    for p in c['ports']:
                    #        template_vars['execution_urls'].append(('{}'.format(p['name']), '{}://{}:{}{}'.format(p['protocol'], ip, p['port_number'], p['path'])))
                    return self.render('home_guest.html', **template_vars)
Ejemplo n.º 28
0
    def get(self):
        """Status and statistics page."""
        uid, role = get_auth(self)
        if uid is None or role != 'admin':
            self.redirect(self.get_argument('next', u'/login'))
            return

        stats = self.api_endpoint.statistics_scheduler(uid, role)
        if stats is None:
            raise ZoeException('Cannot retrieve statistics from the Zoe master')

        executions_in_queue = {}
        for exec_id in stats['queue']:
            executions_in_queue[exec_id] = self.api_endpoint.execution_by_id(uid, role, exec_id)
        for exec_id in stats['running_queue']:
            executions_in_queue[exec_id] = self.api_endpoint.execution_by_id(uid, role, exec_id)

        services_per_node = {}
        for node in stats['platform_stats']['nodes']:
            services_per_node[node['name']] = self.api_endpoint.sql.services.select(backend_host=node['name'], backend_status='started')
            for service in services_per_node[node['name']]:
                if service.id not in node['service_stats']:
                    node['service_stats'][service.id] = {
                        'mem_limit': 0,
                        'core_limit': 0
                    }

        max_service_count = max([len(services_per_node[name]) for name in services_per_node])

        template_vars = {
            "uid": uid,
            "role": role,
            "stats": stats,
            "executions_in_queue": executions_in_queue,
            "services_per_node": services_per_node,
            "max_service_count": max_service_count
        }

        self.render('status.html', **template_vars)
Ejemplo n.º 29
0
def execution_define():
    get_auth(request)

    return render_template('execution_new.html')
Ejemplo n.º 30
0
    def get(self):
        """Define a new execution."""
        get_auth(self)

        self.render('execution_new.html')
Ejemplo n.º 31
0
def execution_define():
    get_auth(request)

    return render_template('execution_new.html')