Ejemplo n.º 1
0
    def chk_and_launch_docker(self, user_id):
        if self.redirect_to_logged_in_instance(user_id):
            return

        nhops = int(self.get_argument('h', 0))
        numhopmax = JBoxCfg.get('numhopmax', 0)
        max_hop = nhops > numhopmax
        launched = self.try_launch_container(user_id, max_hop=max_hop)

        if launched:
            self.set_container_initialized(Compute.get_instance_local_ip(), user_id)
            self.rendertpl("loading.tpl",
                           user_id=user_id,
                           cfg=JBoxCfg.nv,
                           js_includes=JBPluginHandler.PLUGIN_JAVASCRIPTS)
            return

        self.unset_affinity()
        self.log_debug("at hop %d for user %s", nhops, user_id)
        if max_hop:
            if JBoxCfg.get('cloud_host.scale_down'):
                msg = "JuliaBox is experiencing a sudden surge. Please try in a few minutes while we increase our capacity."
            else:
                msg = "JuliaBox servers are fully loaded. Please try after sometime."
            self.log_error("Server maxed out. Can't launch container at hop %d for user %s", nhops, user_id)
            self.rendertpl("index.tpl", cfg=JBoxCfg.nv, state=self.state(error=msg, success=''))
        else:
            redirect_instance = Compute.get_redirect_instance_id()
            if redirect_instance is not None:
                redirect_ip = Compute.get_instance_local_ip(redirect_instance)
                self.set_redirect_instance_id(redirect_ip)
            self.redirect('/?h=' + str(nhops + 1))
Ejemplo n.º 2
0
    def post_auth_launch_container(self, user_id):
        for plugin in JBPluginHandler.jbox_get_plugins(JBPluginHandler.JBP_HANDLER_POST_AUTH):
            self.log_info("Passing user %r to post auth plugin %r", user_id, plugin)
            pass_allowed = plugin.process_user_id(self, user_id)
            if not pass_allowed:
                self.log_info('Login restricted for user %r by plugin %r', user_id, plugin)
                return

        jbuser = JBoxUserV2(user_id, create=True)

        if not JBPluginHandler.is_user_activated(jbuser):
            self.redirect('/?pending_activation=' + user_id)
            return

        self.set_authenticated(user_id)
        if jbuser.is_new:
            jbuser.save()

        if self.redirect_to_logged_in_instance(user_id):
            return

        # check if the current instance is appropriate for launching this
        if self.try_launch_container(user_id, max_hop=False):
            self.set_container_initialized(Compute.get_instance_local_ip(), user_id)
        else:
            # redirect to an appropriate instance
            redirect_instance = Compute.get_redirect_instance_id()
            if redirect_instance is not None:
                redirect_ip = Compute.get_instance_local_ip(redirect_instance)
                self.set_redirect_instance_id(redirect_ip)
        self.redirect('/')
Ejemplo n.º 3
0
    def chk_and_launch_docker(self, user_id):
        if self.redirect_to_logged_in_instance(user_id):
            return

        nhops = int(self.get_argument('h', 0))
        numhopmax = JBoxCfg.get('numhopmax', 0)
        max_hop = nhops > numhopmax
        launched = self.try_launch_container(user_id, max_hop=max_hop)

        if launched:
            self.set_container_initialized(Compute.get_instance_local_ip(), user_id)
            self.rendertpl("loading.tpl",
                           user_id=user_id,
                           cfg=JBoxCfg.nv,
                           js_includes=JBPluginHandler.PLUGIN_JAVASCRIPTS)
            return

        self.unset_affinity()
        self.log_debug("at hop %d for user %s", nhops, user_id)
        if max_hop:
            if JBoxCfg.get('cloud_host.scale_down'):
                msg = "JuliaBox is experiencing a sudden surge. Please try in a few minutes while we increase our capacity."
            else:
                msg = "JuliaBox servers are fully loaded. Please try after sometime."
            self.log_error("Server maxed out. Can't launch container at hop %d for user %s", nhops, user_id)
            self.rendertpl("index.tpl", cfg=JBoxCfg.nv, state=self.state(error=msg, success=''))
        else:
            redirect_instance = Compute.get_redirect_instance_id()
            if redirect_instance is not None:
                redirect_ip = Compute.get_instance_local_ip(redirect_instance)
                self.set_redirect_instance_id(redirect_ip)
            self.redirect('/?h=' + str(nhops + 1))
Ejemplo n.º 4
0
 def redirect_to_logged_in_instance(self, user_id):
     loggedin_instance = self.find_logged_in_instance(user_id)
     if loggedin_instance is not None \
             and loggedin_instance != Compute.get_instance_id() \
             and loggedin_instance != 'localhost':
         # redirect to the instance that has the user's session
         self.log_info("Already logged in to %s. Redirecting", loggedin_instance)
         redirect_ip = Compute.get_instance_local_ip(loggedin_instance)
         self.set_redirect_instance_id(redirect_ip)
         self.redirect('/')
         return True
     self.log_info("Logged in %s", "nowhere" if loggedin_instance is None else "here already")
     return False
Ejemplo n.º 5
0
    def post_auth_launch_container(self, user_id):
        jbuser = JBoxUserV2(user_id, create=True)
        if not JBPluginHandler.is_user_activated(jbuser):
            self.redirect('/?pending_activation=' + user_id)
            return

        self.set_authenticated(user_id)
        if jbuser.is_new:
            jbuser.save()

        if self.redirect_to_logged_in_instance(user_id):
            return

        # check if the current instance is appropriate for launching this
        if self.try_launch_container(user_id, max_hop=False):
            self.set_container_initialized(Compute.get_instance_local_ip(), user_id)
        else:
            # redirect to an appropriate instance
            redirect_instance = Compute.get_redirect_instance_id()
            if redirect_instance is not None:
                redirect_ip = Compute.get_instance_local_ip(redirect_instance)
                self.set_redirect_instance_id(redirect_ip)
        self.redirect('/')
Ejemplo n.º 6
0
    def post_auth_launch_container(self, user_id):
        jbuser = JBoxUserV2(user_id, create=True)
        if not JBPluginHandler.is_user_activated(jbuser):
            self.redirect('/?pending_activation=' + user_id)
            return

        self.set_authenticated(user_id)
        if jbuser.is_new:
            jbuser.save()

        if self.redirect_to_logged_in_instance(user_id):
            return

        # check if the current instance is appropriate for launching this
        if self.try_launch_container(user_id, max_hop=False):
            self.set_container_initialized(Compute.get_instance_local_ip(),
                                           user_id)
        else:
            # redirect to an appropriate instance
            redirect_instance = Compute.get_redirect_instance_id()
            if redirect_instance is not None:
                redirect_ip = Compute.get_instance_local_ip(redirect_instance)
                self.set_redirect_instance_id(redirect_ip)
        self.redirect('/')
Ejemplo n.º 7
0
 def redirect_to_logged_in_instance(self, user_id):
     loggedin_instance = self.find_logged_in_instance(user_id)
     if loggedin_instance is not None \
             and loggedin_instance != Compute.get_instance_id() \
             and loggedin_instance != 'localhost':
         # redirect to the instance that has the user's session
         self.log_info("Already logged in to %s. Redirecting",
                       loggedin_instance)
         redirect_ip = Compute.get_instance_local_ip(loggedin_instance)
         self.set_redirect_instance_id(redirect_ip)
         self.redirect('/')
         return True
     self.log_info(
         "Logged in %s",
         "nowhere" if loggedin_instance is None else "here already")
     return False