Skip to content

Commit 9d08ea5

Browse files
option to start hpo with different port
Signed-off-by: kusumachalasani <[email protected]>
1 parent d707b8d commit 9d08ea5

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

deploy_hpo.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ hpo_ns=""
3636
# docker: loop timeout is turned off by default
3737
timeout=-1
3838
service_type="both"
39+
service_port="8085"
3940

4041
# source the helpers script
4142
source ${SCRIPTS_DIR}/cluster-helpers.sh
@@ -70,7 +71,7 @@ function check_cluster_type() {
7071
esac
7172
}
7273

73-
VALID_ARGS=$(getopt -o ac:d:o:n:strb --long non_interactive,cluster_type:,configmaps:,container_image:,namespace:,start,terminate,rest,both -- "$@")
74+
VALID_ARGS=$(getopt -o ac:d:o:n:p:strb --long non_interactive,cluster_type:,configmaps:,container_image:,namespace:,start,terminate,rest,both,port: -- "$@")
7475
if [[ $? -ne 0 ]]; then
7576
usage
7677
exit 1;
@@ -102,6 +103,10 @@ while [ : ]; do
102103
hpo_ns="$2"
103104
shift 2
104105
;;
106+
-p | --port)
107+
service_port="$2"
108+
shift 2
109+
;;
105110
-s | --start)
106111
setup=1
107112
shift
@@ -142,7 +147,7 @@ SERVICE_STATUS_DOCKER=$(${CONTAINER_RUNTIME} ps | grep hpo_docker_container)
142147
# Call the proper setup function based on the cluster_type
143148
if [ ${setup} == 1 ]; then
144149
if [ ${cluster_type} = "native" ]; then
145-
${cluster_type}_start ${service_type}
150+
${cluster_type}_start ${service_type} ${service_port}
146151
elif [ ${cluster_type} = "operate-first" ]; then
147152
echo
148153
echo "Info: Access HPO at ${Op_first_URL}"

scripts/cluster-helpers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ function native_start() {
9393
cp experiment.html experiment_torestore.html
9494

9595
if [ "$1" = "REST" ]; then
96-
python3 -u src/service.py "REST"
96+
python3 -u src/service.py "REST" "$2"
9797
else
98-
python3 -u src/service.py "BOTH"
98+
python3 -u src/service.py "BOTH" "$2"
9999
fi
100100
}
101101

src/rest_service.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,12 @@ def get_search_create_study(search_space_json, operation):
322322
return response
323323

324324

325-
def main():
326-
server = HTTPServer((HPOSupportedTypes.SERVER_HOSTNAME, HPOSupportedTypes.SERVER_PORT), HTTPRequestHandler)
327-
logger.info("Access REST Service at http://%s:%s" % ("localhost", HPOSupportedTypes.SERVER_PORT))
328-
server.serve_forever()
325+
def main(server_port=8085):
326+
hpo_instance = HPOSupportedTypes(server_port=server_port)
327+
server = HTTPServer((HPOSupportedTypes.SERVER_HOSTNAME, hpo_instance.SERVER_PORT), HTTPRequestHandler)
328+
logger.info("Access REST Service at http://%s:%s" % ("localhost", hpo_instance.SERVER_PORT))
329+
server.serve_forever()
329330

330331

331332
if __name__ == '__main__':
332-
main()
333+
main(server_port=8085)

src/service.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ def signal_handler(sig, frame):
2929

3030
def main():
3131

32-
logger.info('Starting HPO service')
33-
if ( len(sys.argv) == 1 ) or ( len(sys.argv) == 2 and sys.argv[1] == "BOTH" ):
32+
if ( len(sys.argv) == 1 ) or ( len(sys.argv) == 2 and sys.argv[1] == "BOTH" ) or ( len(sys.argv) == 3 and sys.argv[1] == "BOTH" ):
3433
import grpc_service
3534
gRPCservice = threading.Thread(target=grpc_service.serve)
3635
gRPCservice.daemon = True
3736
gRPCservice.start()
38-
39-
restService = threading.Thread(target=rest_service.main)
37+
if (sys.argv[2] != ''):
38+
server_port = int(sys.argv[2])
39+
else:
40+
server_port=8085
41+
restService = threading.Thread(target=rest_service.main, args=(server_port,))
4042
restService.daemon = True
4143
restService.start()
4244

src/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ class HPOSupportedTypes:
2828
N_JOBS = 1
2929
N_TRIALS = 10
3030
SERVER_HOSTNAME = "0.0.0.0"
31-
SERVER_PORT = 8092
31+
#SERVER_PORT = 8085
3232
API_ENDPOINT = "/experiment_trials"
3333
CONTENT_TYPE = "application/json"
3434

35+
def __init__(self, server_port=None):
36+
if server_port is not None:
37+
self.SERVER_PORT = server_port
38+
3539

3640
class HPOErrorConstants:
3741
INVALID_OPERATION = "Invalid Operation value!"

0 commit comments

Comments
 (0)