Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CHARYBDEFS_PORT env variable as the Thrift port if set #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cookbook/recipes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import errno

import sys
import os

sys.path.append('gen-py')
from server import server
Expand All @@ -27,7 +28,9 @@ def usage():


def connect():
transport = TSocket.TSocket('127.0.0.1', 9090)
envPort = os.getenv('CHARIBEFS_PORT', '')
hashangayasri marked this conversation as resolved.
Show resolved Hide resolved
port = int(envPort) if envPort else 9090
transport = TSocket.TSocket('127.0.0.1', port)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = server.Client(protocol)
Expand Down
4 changes: 3 additions & 1 deletion python_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

try:

transport = TSocket.TSocket('127.0.0.1', 9090)
envPort = os.getenv('CHARIBEFS_PORT', '')
port = int(envPort) if envPort else 9090
transport = TSocket.TSocket('127.0.0.1', port)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = server.Client(protocol)
Expand Down
11 changes: 11 additions & 0 deletions server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ void server_thread()
{
int port = 9090;

if(const char* envPort = std::getenv("CHARIBEFS_PORT")) {
char *end;
const long envPortValue = strtol(envPort, &end, 10);
if (envPort == end) {
port = static_cast<int>(envPortValue);
} else {
std::cerr << "Invalid port : " << envPort <<
". Using the default value : " << port << std::endl;
}
}

init_valid_methods();

std::cout << "Server Thread started" << std::endl;
Expand Down
4 changes: 3 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def has_message(method, message):


def connect():
transport = TSocket.TSocket('127.0.0.1', 9090)
envPort = os.getenv('CHARIBEFS_PORT', '')
port = int(envPort) if envPort else 9090
transport = TSocket.TSocket('127.0.0.1', port)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = server.Client(protocol)
Expand Down
4 changes: 3 additions & 1 deletion tests/python_client
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ from thrift.protocol import TBinaryProtocol

try:

transport = TSocket.TSocket('127.0.0.1', 9090)
envPort = os.getenv('CHARIBEFS_PORT', '')
port = int(envPort) if envPort else 9090
transport = TSocket.TSocket('127.0.0.1', port)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = server.Client(protocol)
Expand Down