def test_compose_serialize(): url = "url" username = "******" password = "******" client = ReliableHttpClient(url, {}, username, password, retry_policy) assert client.connection_string == get_connection_string(url, username, password)
def refresh_configuration(self): credentials = getattr(conf, 'kernel_' + self.language + '_credentials')() ret = (credentials['username'], credentials['password'], credentials['url']) assert(ret[2]) (username, password, url) = ret self.url = url self.connection_string = get_connection_string(url, username, password)
def refresh_configuration(self): credentials = getattr(conf, 'kernel_' + self.language + '_credentials')() ret = (credentials['username'], credentials['password'], credentials['url']) assert (ret[2]) (username, password, url) = ret self.url = url self.connection_string = get_connection_string(url, username, password)
def run(self): connection_string = get_connection_string(self.address_widget.value, self.user_widget.value, self.password_widget.value) self.endpoints[self.address_widget.value] = connection_string self.ipython_display.writeln("Added endpoint {}".format(self.address_widget.value)) # We need to call the refresh method because drop down in Tab 2 for endpoints wouldn't refresh with the new # value otherwise. self.refresh_method()
def run(self): connection_string = get_connection_string(self.address_widget.value, self.user_widget.value, self.password_widget.value) self.endpoints[self.address_widget.value] = connection_string self.ipython_display.writeln("Added endpoint {}".format( self.address_widget.value)) # We need to call the refresh method because drop down in Tab 2 for endpoints wouldn't refresh with the new # value otherwise. self.refresh_method()
def test_build_session(): factory = LivyClientFactory() connection_string = get_connection_string("url", "user", "pass") kind = Constants.session_kind_pyspark properties = {"kind": kind} ipython_display = MagicMock() session = factory.create_session(ipython_display, connection_string, properties, "1", True) assert session.kind == kind assert session.id == "1" assert session.started_sql_context assert session.properties == properties
def test_serialize(self): url = "url" username = "******" password = "******" connection_string = get_connection_string(url, username, password) http_client = MagicMock() http_client.connection_string = connection_string kind = Constants.session_kind_spark conf.override_all({"status_sleep_seconds": 0.01, "statement_sleep_seconds": 0.01}) session = self._create_session(kind=kind, http_client=http_client) conf.load() serialized = session.get_state().to_dict() assert serialized["connectionstring"] == connection_string assert serialized["id"] == "-1" assert serialized["kind"] == kind assert serialized["sqlcontext"] == False assert serialized["version"] == "0.0.0" assert len(serialized.keys()) == 5
def __init__(self, implementation, implementation_version, language, language_version, language_info, kernel_conf_name, session_language, client_name, **kwargs): # Required by Jupyter - Override self.implementation = implementation self.implementation_version = implementation_version self.language = language self.language_version = language_version self.language_info = language_info # Override self.kernel_conf_name = kernel_conf_name self.session_language = session_language self.client_name = client_name super(SparkKernelBase, self).__init__(**kwargs) self._logger = Log(self.client_name) self._session_started = False self._fatal_error = None self._ipython_display = IpythonDisplay() self.user_command_parser = UserCommandParser() # Disable warnings for test env in HDI requests.packages.urllib3.disable_warnings() if not kwargs.get("testing", False): configuration = self._get_configuration() if not configuration: # _get_configuration() sets the error for us so we can just return now. # The kernel is not in a good state and all do_execute calls will # fail with the fatal error. return (username, password, url) = configuration self.connection_string = get_connection_string(url, username, password) self._load_magics_extension() if conf.use_auto_viz(): self._register_auto_viz()
def test_serialize(self): url = "url" username = "******" password = "******" connection_string = get_connection_string(url, username, password) http_client = MagicMock() http_client.connection_string = connection_string kind = constants.SESSION_KIND_SPARK conf.override_all({ "status_sleep_seconds": 0.01, "statement_sleep_seconds": 0.01 }) session = self._create_session(kind=kind, http_client=http_client) conf.load() serialized = session.get_state().to_dict() assert serialized["connectionstring"] == connection_string assert serialized["id"] == "-1" assert serialized["kind"] == kind assert serialized["sqlcontext"] == False assert serialized["version"] == "0.0.0" assert len(serialized.keys()) == 5
def test_serialize(): url = "url" username = "******" password = "******" connection_string = get_connection_string(url, username, password) http_client = MagicMock() http_client.connection_string = connection_string kind = SESSION_KIND_SPARK session_id = "-1" sql_created = False session = MagicMock() session.get_state.return_value = LivySessionState(session_id, connection_string, kind, sql_created) client = LivyClient(session) client.start() serialized = client.serialize() assert serialized["connectionstring"] == connection_string assert serialized["id"] == "-1" assert serialized["kind"] == kind assert serialized["sqlcontext"] == sql_created assert serialized["version"] == "0.0.0" assert len(serialized.keys()) == 5
def _setup(): global kernel, user_ev, pass_ev, url_ev, execute_cell_mock, do_shutdown_mock, conn_str, ipython_display, parser usr = "******" pwd = "p" url = "url" conn_str = get_connection_string(url, usr, pwd) kernel = TestSparkKernel() kernel.use_auto_viz = False kernel.kernel_conf_name = "python" kernel.username_conf_name = user_ev kernel.password_conf_name = pass_ev kernel.url_conf_name = url_ev kernel.session_language = "python" kernel.connection_string = conn_str kernel._execute_cell_for_user = execute_cell_mock = MagicMock() kernel._do_shutdown_ipykernel = do_shutdown_mock = MagicMock() kernel._ipython_display = ipython_display = MagicMock() parser = MagicMock() parser.parse_user_command.return_value = (UserCommandParser.run_command, False, None, "my code") kernel.user_command_parser = parser
def test_serialize(): url = "url" username = "******" password = "******" connection_string = get_connection_string(url, username, password) http_client = MagicMock() http_client.connection_string = connection_string kind = Constants.session_kind_spark session_id = "-1" sql_created = False session = MagicMock() session.get_state.return_value = LivySessionState(session_id, connection_string, kind, sql_created) client = LivyClient(session) client.start() serialized = client.serialize() assert serialized["connectionstring"] == connection_string assert serialized["id"] == "-1" assert serialized["kind"] == kind assert serialized["sqlcontext"] == sql_created assert serialized["version"] == "0.0.0" assert len(serialized.keys()) == 5
def test_obj_to_str(): cs = csutil.get_connection_string(host, "user", "pass") assert_equals(connection_string, cs)
def __init__(self, spark_controller, ipywidget_factory, ipython_display, endpoints, endpoints_dropdown_widget, refresh_method): # This is nested super(AddEndpointWidget, self).__init__(spark_controller, ipywidget_factory, ipython_display, True) widget_width = "800px" self.endpoints = endpoints self.endpoints_dropdown_widget = endpoints_dropdown_widget self.refresh_method = refresh_method self.address_widget = self.ipywidget_factory.get_text( description='Address:', value='http://example.com/livy', width=widget_width ) self.user_widget = self.ipywidget_factory.get_text( description='Username:'******'username', width=widget_width ) self.password_widget = self.ipywidget_factory.get_text( description='Password:'******'password', width=widget_width ) self.conn_string_widget = self.ipywidget_factory.get_text( description='Connection String:', value=get_connection_string(self.address_widget.value, self.user_widget.value, self.password_widget.value), width=widget_width ) # Sync values def parts_to_conn(name, old_value, new_value): url = self.address_widget.value user = self.user_widget.value password = self.password_widget.value conn_str = get_connection_string(url, user, password) self.conn_string_widget.value = conn_str def conn_to_parts(name, old_value, new_value): try: conn_str = self.conn_string_widget.value cso = get_connection_string_elements(conn_str) self.address_widget.value = cso.url self.user_widget.value = cso.username self.password_widget.value = cso.password except ValueError: pass self.address_widget.on_trait_change(parts_to_conn, "value") self.user_widget.on_trait_change(parts_to_conn, "value") self.password_widget.on_trait_change(parts_to_conn, "value") self.conn_string_widget.on_trait_change(conn_to_parts, "value") # Submit widget self.submit_widget = self.ipywidget_factory.get_submit_button( description='Add endpoint' ) self.children = [self.ipywidget_factory.get_html(value="<br/>", width=widget_width), self.address_widget, self.user_widget, self.password_widget, self.conn_string_widget, self.ipywidget_factory.get_html(value="<br/>", width=widget_width), self.submit_widget] for child in self.children: child.parent_widget = self
def parts_to_conn(name, old_value, new_value): url = self.address_widget.value user = self.user_widget.value password = self.password_widget.value conn_str = get_connection_string(url, user, password) self.conn_string_widget.value = conn_str
def connection_string(self): return get_connection_string(self._url, self._username, self._password)
def __init__(self, spark_controller, ipywidget_factory, ipython_display, endpoints, endpoints_dropdown_widget, refresh_method): # This is nested super(AddEndpointWidget, self).__init__(spark_controller, ipywidget_factory, ipython_display, True) widget_width = "800px" self.endpoints = endpoints self.endpoints_dropdown_widget = endpoints_dropdown_widget self.refresh_method = refresh_method self.address_widget = self.ipywidget_factory.get_text( description='Address:', value='http://example.com/livy', width=widget_width) self.user_widget = self.ipywidget_factory.get_text( description='Username:'******'username', width=widget_width) self.password_widget = self.ipywidget_factory.get_text( description='Password:'******'password', width=widget_width) self.conn_string_widget = self.ipywidget_factory.get_text( description='Connection String:', value=get_connection_string(self.address_widget.value, self.user_widget.value, self.password_widget.value), width=widget_width) # Sync values def parts_to_conn(name, old_value, new_value): url = self.address_widget.value user = self.user_widget.value password = self.password_widget.value conn_str = get_connection_string(url, user, password) self.conn_string_widget.value = conn_str def conn_to_parts(name, old_value, new_value): try: conn_str = self.conn_string_widget.value cso = get_connection_string_elements(conn_str) self.address_widget.value = cso.url self.user_widget.value = cso.username self.password_widget.value = cso.password except ValueError: pass self.address_widget.on_trait_change(parts_to_conn, "value") self.user_widget.on_trait_change(parts_to_conn, "value") self.password_widget.on_trait_change(parts_to_conn, "value") self.conn_string_widget.on_trait_change(conn_to_parts, "value") # Submit widget self.submit_widget = self.ipywidget_factory.get_submit_button( description='Add endpoint') self.children = [ self.ipywidget_factory.get_html(value="<br/>", width=widget_width), self.address_widget, self.user_widget, self.password_widget, self.conn_string_widget, self.ipywidget_factory.get_html(value="<br/>", width=widget_width), self.submit_widget ] for child in self.children: child.parent_widget = self