Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Adding json rpc library with tests #1

Merged
merged 5 commits into from
Feb 24, 2017
Merged

Conversation

MrMeemus
Copy link
Contributor

Adding the json rpc library support module. This module should support basic request/response scenario with any bytestream. Not sure about the file structure, priority is getting the source out and reviewed.

@msftclas
Copy link

Hi @MrMeemus, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor. If you're full-time or an intern, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@MrMeemus
Copy link
Contributor Author

@pensivebrian is added to the review. #Closed

@MrMeemus
Copy link
Contributor Author

@abhisheksinha89 is added to the review. #Closed

json_content = json.dumps(content_body)
header = self.HEADER.format(str(len(json_content)))

self.stream.write(header.encode("ascii"))
Copy link
Contributor Author

@MrMeemus MrMeemus Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ascii" [](start = 40, length = 7)

Will change to single quotes to be consistent through out the file #Resolved


def read_response(self):
# Using a mutable list to hold the value since a immutable string passed by reference won't change the value
message_content = [""]
Copy link
Contributor Author

@MrMeemus MrMeemus Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing notion of a message to just headers and body content. i.e try_read_message_headers -> try_read_headers #Resolved

…t; removing notion of a message since that is client/server specific
from io import BytesIO
import json

class JSON_RPC_Writer(object):
Copy link

@abhisheksinha89 abhisheksinha89 Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON_RPC_Writer [](start = 6, length = 15)

Class names should use the CapWords convention. https://www.python.org/dev/peps/pep-0008/#class-names #Resolved

Copy link
Member

@pensivebrian pensivebrian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Looking forward to using these classes.


self.stream.write(header.encode("ascii"))
self.stream.write(json_content.encode(self.encoding))

Copy link
Member

@pensivebrian pensivebrian Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a flush after the last write? #Resolved


class JSON_RPC_Reader(object):
# \r\n
CR = 13
Copy link
Member

@pensivebrian pensivebrian Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a '\r' is more clear - can we use that instead? #Pending

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would require us to slice the byte array to decode in a contiguous array since each byte is a int and doesn't support decode;i.e buffer[scanoffset:scanoffset+3].decode('ascii') == '\r\n\r\n' which I think could introduce unecessary checks like if the offset + 3 exceeds the boundaries. Checking byte by it's numeric value looks cleaner IMO. Let me know what you think.


In reply to: 102364905 [](ancestors = 102364905)

class JSON_RPC_Reader(object):
# \r\n
CR = 13
LF = 10
Copy link
Member

@pensivebrian pensivebrian Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing, I think a '\n' is more clear than the numeric constant. #ByDesign

message_content = [""]
while (self.read_next_chunk()):
# If we can't read a header, read the next chunk
if (self.read_state == "Header" and not self.try_read_message_headers()):
Copy link
Member

@pensivebrian pensivebrian Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the == "Header" case sensitive? #Pending

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it is, The plan is to add Enums to contain the state. Which should come out in the next iteration


In reply to: 102365093 [](ancestors = 102365093)

if (self.read_state == "Header" and not self.try_read_message_headers()):
continue
# If we read the header, try the content. If that fails, read the next chunk
if (self.read_state == "Content" and not self.try_read_message_content(message_content)):
Copy link
Member

@pensivebrian pensivebrian Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, is == "Content" case sensitive? #Pending

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


In reply to: 102365133 [](ancestors = 102365133)

from io import BytesIO
import unittest

class JSON_RPC_Test(unittest.TestCase):
Copy link
Member

@pensivebrian pensivebrian Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some case-sensitivity tests? #Resolved

if encoding is None:
self.encoding = 'UTF-8'

def send_request(self, method, params, id):
Copy link
Member

@pensivebrian pensivebrian Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default id = null? #Resolved

@@ -0,0 +1,175 @@
# --------------------------------------------------------------------------------------------
Copy link
Member

@pensivebrian pensivebrian Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this into a src/common folder? Also, do we really need 'json/rpc' directories? We only have a few files, so all of them in the json-rpc seems sensible. #Resolved

@@ -0,0 +1,106 @@
# --------------------------------------------------------------------------------------------
Copy link
Member

@pensivebrian pensivebrian Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this into a tests sub-folder from the code? #Resolved

…of json rpc lib, added skeleton folder structure for future cli tools, added test setup, added dev set up files for installing dependencies and running tests
Copy link
Member

@pensivebrian pensivebrian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Only minor changes.

@@ -0,0 +1,2 @@
Microsoft XPlat Cli common module
Copy link
Member

@pensivebrian pensivebrian Feb 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: CLI #Resolved

@@ -4,9 +4,18 @@
# --------------------------------------------------------------------------------------------
Copy link
Member

@pensivebrian pensivebrian Feb 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can use use single quotes in this file instead on double quotes - seems to be the Python convention. #Resolved

@@ -0,0 +1,3 @@
enum34==1.1.6
pip==9.0.1
setuptools==30.4.0
Copy link
Member

@pensivebrian pensivebrian Feb 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is 'setuptools' used for? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setuptools builds the package so we can use setup.py


In reply to: 103035860 [](ancestors = 103035860)

author='Microsoft Corporation',
author_email='ssdteng@microsoft.com',
url='https://github.com/Microsoft/sql-xplat-cli/',
)
Copy link
Member

@pensivebrian pensivebrian Feb 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a newline to get rid of the warning? #Resolved

@MrMeemus
Copy link
Contributor Author

Merging json rpc library with tests, dev set up, and basic folder structure.

@MrMeemus MrMeemus merged commit 08eca25 into dev Feb 24, 2017
@MrMeemus MrMeemus deleted the feature/json_rpc_library branch February 27, 2017 17:11
pensivebrian added a commit that referenced this pull request Aug 17, 2017
We have a 2 threads:
Thread #1 runs in a loop polling the response queue
Thread #2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue

Since thread #1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, #2 doesn’t preempt the CPU due to #1 taking all of the CPU cycles, so no response is processed.

Fix is simple – thread #1 needs to sleep so thread #2 can get scheduled and get it’s work done.
pensivebrian added a commit that referenced this pull request Aug 17, 2017
Fix perf issue where main event loop takes 100% of CPU

We have a 2 threads:
Thread #1 runs in a loop polling the response queue
Thread #2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue

Since thread #1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, #2 doesn’t preempt the CPU due to #1 taking all of the CPU cycles, so no response is processed.

Fix is simple – thread #1 needs to sleep so thread #2 can get scheduled and get it’s work done.
MrMeemus added a commit that referenced this pull request Sep 1, 2017
* Use SqlToolsService built on .NET Core 2.0 and a build script updates (#131)

* Bump version to 1.0.0a19

* Use .NET Core 2.0 RTM built sqltoolsservice

* Add build script to upload to azure blob storage

* Upgrade to VS 2017

* Remove 3.3 as supported Python version

* Fix perf issue where main event loop takes 100% of CPU (#132)

Fix perf issue where main event loop takes 100% of CPU

We have a 2 threads:
Thread #1 runs in a loop polling the response queue
Thread #2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue

Since thread #1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, #2 doesn’t preempt the CPU due to #1 taking all of the CPU cycles, so no response is processed.

Fix is simple – thread #1 needs to sleep so thread #2 can get scheduled and get it’s work done.

* Refine event loop perf fix in main.py

Refine event loop perf fix in main.py

* Fixing regular expression

Previous regex would result in release:a1 and release_version: 12.
Modified the regex for part Release to only pick up lower case letters.

* Adding missing forward slash on test pypi url

* fixing typos/grammar (#138)

fixing typos/grammar.

* Updating to release version 1.0.0a20.
MrMeemus added a commit that referenced this pull request Oct 13, 2017
* Use SqlToolsService built on .NET Core 2.0 and a build script updates (#131)

* Bump version to 1.0.0a19

* Use .NET Core 2.0 RTM built sqltoolsservice

* Add build script to upload to azure blob storage

* Upgrade to VS 2017

* Remove 3.3 as supported Python version

* Fix perf issue where main event loop takes 100% of CPU (#132)

Fix perf issue where main event loop takes 100% of CPU

We have a 2 threads:
Thread #1 runs in a loop polling the response queue
Thread #2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue

Since thread #1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, #2 doesn’t preempt the CPU due to #1 taking all of the CPU cycles, so no response is processed.

Fix is simple – thread #1 needs to sleep so thread #2 can get scheduled and get it’s work done.

* Refine event loop perf fix in main.py

Refine event loop perf fix in main.py

* Fixing regular expression

Previous regex would result in release:a1 and release_version: 12.
Modified the regex for part Release to only pick up lower case letters.

* Adding missing forward slash on test pypi url

* fixing typos/grammar (#138)

fixing typos/grammar.

* Updating to release version 1.0.0a20.

* Create doc for official msft docs page

* Updated documentation page with usage_guide

* Added link to download adventureworks

* Updated with sqlcmd usage

* Added in run and cloud shell support

* Update/consolidate linux install (#153)

* universal linux wheel gen and setup update.

* Updating version cfg.

* Updating sqltoolsservice container.

* Updating spacing for flake8.

* Updating team email. (#154)
MrMeemus added a commit that referenced this pull request Nov 10, 2017
* Merge release 1.0.0a21 (#155)

* Use SqlToolsService built on .NET Core 2.0 and a build script updates (#131)

* Bump version to 1.0.0a19

* Use .NET Core 2.0 RTM built sqltoolsservice

* Add build script to upload to azure blob storage

* Upgrade to VS 2017

* Remove 3.3 as supported Python version

* Fix perf issue where main event loop takes 100% of CPU (#132)

Fix perf issue where main event loop takes 100% of CPU

We have a 2 threads:
Thread #1 runs in a loop polling the response queue
Thread #2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue

Since thread #1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, #2 doesn’t preempt the CPU due to #1 taking all of the CPU cycles, so no response is processed.

Fix is simple – thread #1 needs to sleep so thread #2 can get scheduled and get it’s work done.

* Refine event loop perf fix in main.py

Refine event loop perf fix in main.py

* Fixing regular expression

Previous regex would result in release:a1 and release_version: 12.
Modified the regex for part Release to only pick up lower case letters.

* Adding missing forward slash on test pypi url

* fixing typos/grammar (#138)

fixing typos/grammar.

* Updating to release version 1.0.0a20.

* Create doc for official msft docs page

* Updated documentation page with usage_guide

* Added link to download adventureworks

* Updated with sqlcmd usage

* Added in run and cloud shell support

* Update/consolidate linux install (#153)

* universal linux wheel gen and setup update.

* Updating version cfg.

* Updating sqltoolsservice container.

* Updating spacing for flake8.

* Updating team email. (#154)

* Updating mssqltoolsservice to be integrated as a package of mssqlscripter.

* Updating sqltoolsservice to be loaded from the repro instead of storage account.

* Fix index file generation for daily storage account.

* Fixing manylinux1 tag.

* Updating platform tag for win x64.

* Renaming sqltoolsservice win x64 folder.

* Adding platform tags for win_amd64, manylinux1_x86_64, manylinux1_i686.

* version bumping to 1.0.0a22.

* Flake8 format fixes.

* Erroring out when build receives invalid flag.
MrMeemus added a commit that referenced this pull request Nov 17, 2017
* Use SqlToolsService built on .NET Core 2.0 and a build script updates (#131)

* Bump version to 1.0.0a19

* Use .NET Core 2.0 RTM built sqltoolsservice

* Add build script to upload to azure blob storage

* Upgrade to VS 2017

* Remove 3.3 as supported Python version

* Fix perf issue where main event loop takes 100% of CPU (#132)

Fix perf issue where main event loop takes 100% of CPU

We have a 2 threads:
Thread #1 runs in a loop polling the response queue
Thread #2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue

Since thread #1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, #2 doesn’t preempt the CPU due to #1 taking all of the CPU cycles, so no response is processed.

Fix is simple – thread #1 needs to sleep so thread #2 can get scheduled and get it’s work done.

* Refine event loop perf fix in main.py

Refine event loop perf fix in main.py

* Fixing regular expression

Previous regex would result in release:a1 and release_version: 12.
Modified the regex for part Release to only pick up lower case letters.

* Adding missing forward slash on test pypi url

* fixing typos/grammar (#138)

fixing typos/grammar.

* Updating to release version 1.0.0a20.

* Create doc for official msft docs page

* Updated documentation page with usage_guide

* Added link to download adventureworks

* Updated with sqlcmd usage

* Added in run and cloud shell support

* Update/consolidate linux install (#153)

* universal linux wheel gen and setup update.

* Updating version cfg.

* Updating sqltoolsservice container.

* Updating spacing for flake8.

* Updating team email. (#154)

* Fixing resource warning for sqltoolsservice (#158)

* Fixing resource warning for sqltoolsservice by closing stdout after killing process.

* Shortening sleep time during shutdown.

* Fixing missing bracket.

* Updating doc's after repro rename (#160)

* Updating files after repro rename.

* Fixing flake8 issues.

* Ron/platform wheels support (#161)

* Merge release 1.0.0a21 (#155)

* Use SqlToolsService built on .NET Core 2.0 and a build script updates (#131)

* Bump version to 1.0.0a19

* Use .NET Core 2.0 RTM built sqltoolsservice

* Add build script to upload to azure blob storage

* Upgrade to VS 2017

* Remove 3.3 as supported Python version

* Fix perf issue where main event loop takes 100% of CPU (#132)

Fix perf issue where main event loop takes 100% of CPU

We have a 2 threads:
Thread #1 runs in a loop polling the response queue
Thread #2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue

Since thread #1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, #2 doesn’t preempt the CPU due to #1 taking all of the CPU cycles, so no response is processed.

Fix is simple – thread #1 needs to sleep so thread #2 can get scheduled and get it’s work done.

* Refine event loop perf fix in main.py

Refine event loop perf fix in main.py

* Fixing regular expression

Previous regex would result in release:a1 and release_version: 12.
Modified the regex for part Release to only pick up lower case letters.

* Adding missing forward slash on test pypi url

* fixing typos/grammar (#138)

fixing typos/grammar.

* Updating to release version 1.0.0a20.

* Create doc for official msft docs page

* Updated documentation page with usage_guide

* Added link to download adventureworks

* Updated with sqlcmd usage

* Added in run and cloud shell support

* Update/consolidate linux install (#153)

* universal linux wheel gen and setup update.

* Updating version cfg.

* Updating sqltoolsservice container.

* Updating spacing for flake8.

* Updating team email. (#154)

* Updating mssqltoolsservice to be integrated as a package of mssqlscripter.

* Updating sqltoolsservice to be loaded from the repro instead of storage account.

* Fix index file generation for daily storage account.

* Fixing manylinux1 tag.

* Updating platform tag for win x64.

* Renaming sqltoolsservice win x64 folder.

* Adding platform tags for win_amd64, manylinux1_x86_64, manylinux1_i686.

* version bumping to 1.0.0a22.

* Flake8 format fixes.

* Erroring out when build receives invalid flag.

* Fixing tag for win64

* Update libunwind8 install for CentOS

* Ron/sqltoolsservice update (#163)

* Updating sqltoolsservice with self contained version.

* Refreshing sqltoolsservice again.

* Making mssql-scripter executable and adding null checks in main.py

* Adding clean up step to remove build directory after each build.

* Fixing path for build directory.

* Removing 'pypi' from upload step.

* Flake 8 extra line fix.
dzsquared pushed a commit that referenced this pull request Jun 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants