예제 #1
0
    def _do_not_call_start_session(self, line, cell="", local_ns=None):
        # Starts a session unless session is already created or a fatal error occurred. Returns True when session is
        # created successfully.
        # No need to add the handle_expected_exceptions decorator to this since we manually catch all
        # exceptions when starting the session.

        if self.fatal_error:
            self.ipython_display.send_error(self.fatal_error_message)
            return False

        if not self.session_started:
            skip = False
            properties = conf.get_session_properties(self.language)
            self.session_started = True

            try:
                self.spark_controller.add_session(self.session_name, self.endpoint, skip, properties)
            except Exception as e:
                self.fatal_error = True
                self.fatal_error_message = conf.fatal_error_suggestion().format(e)
                self.logger.error(u"Error creating session: {}".format(e))
                self.ipython_display.send_error(self.fatal_error_message)
                return False

        return self.session_started
예제 #2
0
    def _do_not_call_start_session(self, line, cell="", local_ns=None):
        # Starts a session unless session is already created or a fatal error occurred. Returns True when session is
        # created successfully.
        # No need to add the handle_expected_exceptions decorator to this since we manually catch all
        # exceptions when starting the session.

        if self.fatal_error:
            self.ipython_display.send_error(self.fatal_error_message)
            return False

        if not self.session_started:
            skip = False
            properties = conf.get_session_properties(self.language)
            self.session_started = True

            try:
                self.spark_controller.add_session(self.session_name,
                                                  self.endpoint, skip,
                                                  properties)
            except Exception as e:
                self.fatal_error = True
                self.fatal_error_message = conf.fatal_error_suggestion(
                ).format(e)
                self.logger.error(u"Error creating session: {}".format(e))
                self.ipython_display.send_error(self.fatal_error_message)
                return False

        return self.session_started
예제 #3
0
def test_retry_start_session_when_retry_fatal_error_is_allowed():
    e = ValueError(
        "Failed to create the SqlContext.\nError, '{}'".format("Exception"))
    magic.spark_controller.add_session = MagicMock(side_effect=e)
    magic.language = constants.LANG_SCALA
    magic.ipython_display = ipython_display
    magic.ipython_display.send_error = MagicMock()
    magic.allow_retry_fatal = True

    # first session creation - failed
    session_created = magic._do_not_call_start_session("")
    magic.spark_controller.add_session.assert_called_once_with(
        magic.session_name, magic.endpoint, False,
        {"kind": constants.SESSION_KIND_SPARK})
    assert not session_created
    assert magic.fatal_error
    assert magic.fatal_error_message == conf.fatal_error_suggestion().format(
        str(e))

    # retry session creation - successful
    magic.spark_controller.add_session = MagicMock()
    session_created = magic._do_not_call_start_session("")
    magic.spark_controller.add_session.assert_called_once_with(
        magic.session_name, magic.endpoint, False,
        {"kind": constants.SESSION_KIND_SPARK})
    print(session_created)
    assert session_created
    assert magic.session_started
    assert not magic.fatal_error
    assert magic.fatal_error_message == u''

    # show error message only once
    assert magic.ipython_display.send_error.call_count == 1
예제 #4
0
def test_start_session_displays_fatal_error_when_session_throws():
    e = ValueError("Failed to create the SqlContext.\nError, '{}'".format("Exception"))
    magic.spark_controller.add_session = MagicMock(side_effect=e)
    magic.language = constants.LANG_SCALA
    magic.ipython_display = ipython_display
    magic.ipython_display.send_error = MagicMock()

    magic._do_not_call_start_session("Test Line")

    magic.spark_controller.add_session.assert_called_once_with(magic.session_name, magic.endpoint, False,
                                                               {"kind": constants.SESSION_KIND_SPARK})
    assert magic.fatal_error
    assert magic.fatal_error_message == conf.fatal_error_suggestion().format(str(e))
def test_start_session_displays_fatal_error_when_session_throws():
    e = ValueError("Failed to create the SqlContext.\nError, '{}'".format("Exception"))
    magic.spark_controller.add_session = MagicMock(side_effect=e)
    magic.language = constants.LANG_SCALA
    magic.ipython_display = ipython_display
    magic.ipython_display.send_error = MagicMock()

    magic._do_not_call_start_session("Test Line")

    magic.spark_controller.add_session.assert_called_once_with(magic.session_name, magic.endpoint, False,
                                                               {"kind": constants.SESSION_KIND_SPARK})
    assert magic.fatal_error
    assert magic.fatal_error_message == conf.fatal_error_suggestion().format(str(e))
예제 #6
0
    def _do_not_call_start_session(self, line, cell="", local_ns=None):
        # Starts a session unless session is already created or a fatal error occurred. Returns True when session is
        # created successfully.
        # No need to add the handle_expected_exceptions decorator to this since we manually catch all
        # exceptions when starting the session.

        if self.fatal_error:
            self.ipython_display.send_error(self.fatal_error_message)
            return False

        if not self.session_started:
            skip = False
            properties = conf.get_session_properties(self.language)
            self.session_started = True

            try:
                self.spark_controller.add_session(self.session_name,
                                                  self.endpoint, skip,
                                                  properties)
            except Exception as e:
                self.fatal_error = True
                self.fatal_error_message = conf.fatal_error_suggestion(
                ).format(e)
                self.logger.error(u"Error creating session: {}".format(e))
                self.ipython_display.send_error(self.fatal_error_message)
                return False

            ## ^^ signifyd_initialization
            session_init_file = os.environ.get("SESSION_INIT_FILE")
            if session_init_file:
                session_init_file = os.path.expanduser(session_init_file)
                if os.path.exists(session_init_file):
                    with open(session_init_file) as filep:
                        self.logger.info(
                            "Initialize session with %s. session_name=%s, endpoint=%s"
                            % (session_init_file, self.session_name,
                               self.endpoint))
                        code = filep.read()
                        (success, out) = self.spark_controller.run_command(
                            Command(code), self.session_name)
                        self.logger.info("return %s => %s" % (success, out))
            ## $$

        return self.session_started
예제 #7
0
 def _repeat_fatal_error(self):
     """Throws an error that has already been queued."""
     error = conf.fatal_error_suggestion().format(self._fatal_error)
     self.logger.error(error)
     self.ipython_display.send_error(error)
     return self._complete_cell()
예제 #8
0
 def _repeat_fatal_error(self):
     """Throws an error that has already been queued."""
     error = conf.fatal_error_suggestion().format(self._fatal_error)
     self.logger.error(error)
     self.ipython_display.send_error(error)
     return self._complete_cell()