diff --git a/server/args.go b/server/args.go index cfed4d8..27c740a 100644 --- a/server/args.go +++ b/server/args.go @@ -28,8 +28,8 @@ type Args struct { EsPort string PrometheusPort string NotifierPort string - JSONRPCPort *int - JSONRPCHTTPPort *int + JSONRPCPort int + JSONRPCHTTPPort int EsIndex string RefreshDelta int CacheTTL int @@ -127,7 +127,7 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args { esPort := parser.String("", "esport", &argparse.Options{Required: false, Help: "elasticsearch port", Default: DefaultEsPort}) prometheusPort := parser.String("", "prometheus-port", &argparse.Options{Required: false, Help: "prometheus port", Default: DefaultPrometheusPort}) notifierPort := parser.String("", "notifier-port", &argparse.Options{Required: false, Help: "notifier port", Default: DefaultNotifierPort}) - jsonRPCPort := parser.Int("", "json-rpc-port", &argparse.Options{Required: false, Help: "JSON RPC port", Validate: validatePort, Default: DefaultJSONRPCPort}) + jsonRPCPort := parser.Int("", "json-rpc-port", &argparse.Options{Required: false, Help: "JSON RPC port", Validate: validatePort}) jsonRPCHTTPPort := parser.Int("", "json-rpc-http-port", &argparse.Options{Required: false, Help: "JSON RPC over HTTP port", Validate: validatePort}) esIndex := parser.String("", "esindex", &argparse.Options{Required: false, Help: "elasticsearch index name", Default: DefaultEsIndex}) refreshDelta := parser.Int("", "refresh-delta", &argparse.Options{Required: false, Help: "elasticsearch index refresh delta in seconds", Default: DefaultRefreshDelta}) @@ -166,6 +166,11 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args { log.Fatalln(parser.Usage(err)) } + // Use default JSON RPC port only if *neither* JSON RPC arg is specified. + if *jsonRPCPort == 0 && *jsonRPCHTTPPort == 0 { + *jsonRPCPort = DefaultJSONRPCPort + } + args := &Args{ CmdType: SearchCmd, Host: *host, @@ -176,8 +181,8 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args { EsPort: *esPort, PrometheusPort: *prometheusPort, NotifierPort: *notifierPort, - JSONRPCPort: jsonRPCPort, - JSONRPCHTTPPort: jsonRPCHTTPPort, + JSONRPCPort: *jsonRPCPort, + JSONRPCHTTPPort: *jsonRPCHTTPPort, EsIndex: *esIndex, RefreshDelta: *refreshDelta, CacheTTL: *cacheTTL, diff --git a/server/federation_test.go b/server/federation_test.go index 78d9038..850500f 100644 --- a/server/federation_test.go +++ b/server/federation_test.go @@ -46,7 +46,6 @@ func removeFile(fileName string) { // makeDefaultArgs creates a default set of arguments for testing the server. func makeDefaultArgs() *server.Args { - port := server.DefaultJSONRPCPort args := &server.Args{ CmdType: server.ServeCmd, Host: server.DefaultHost, @@ -56,7 +55,7 @@ func makeDefaultArgs() *server.Args { EsPort: server.DefaultEsPort, PrometheusPort: server.DefaultPrometheusPort, NotifierPort: server.DefaultNotifierPort, - JSONRPCPort: &port, + JSONRPCPort: server.DefaultJSONRPCPort, EsIndex: server.DefaultEsIndex, RefreshDelta: server.DefaultRefreshDelta, CacheTTL: server.DefaultCacheTTL, diff --git a/server/jsonrpc_service.go b/server/jsonrpc_service.go index 90f20ca..9c29ef4 100644 --- a/server/jsonrpc_service.go +++ b/server/jsonrpc_service.go @@ -55,8 +55,8 @@ func (s *Server) StartJsonRPC() error { defer s.sessionManager.stop() // Set up the pure JSONRPC server with persistent connections/sessions. - for s.Args.JSONRPCPort != nil { - port := ":" + strconv.FormatUint(uint64(*s.Args.JSONRPCPort), 10) + for s.Args.JSONRPCPort != 0 { + port := ":" + strconv.FormatUint(uint64(s.Args.JSONRPCPort), 10) laddr, err := net.ResolveTCPAddr("tcp", port) if err != nil { log.Errorf("ResoveIPAddr: %v\n", err) @@ -67,6 +67,7 @@ func (s *Server) StartJsonRPC() error { log.Errorf("ListenTCP: %v\n", err) break } + log.Infof("JSONRPC server listening on %s", listener.Addr().String()) acceptConnections := func(listener net.Listener) { for { conn, err := listener.Accept() @@ -83,7 +84,7 @@ func (s *Server) StartJsonRPC() error { } // Set up the JSONRPC over HTTP server. - for s.Args.JSONRPCHTTPPort != nil { + for s.Args.JSONRPCHTTPPort != 0 { s1 := gorilla_rpc.NewServer() // Create a new RPC server // Register the type of data requested as JSON, with custom codec. s1.RegisterCodec(&gorillaRpcCodec{gorilla_json.NewCodec()}, "application/json") @@ -112,7 +113,8 @@ func (s *Server) StartJsonRPC() error { r := gorilla_mux.NewRouter() r.Handle("/rpc", s1) - port := ":" + strconv.FormatUint(uint64(*s.Args.JSONRPCHTTPPort), 10) + port := ":" + strconv.FormatUint(uint64(s.Args.JSONRPCHTTPPort), 10) + log.Infof("HTTP JSONRPC server listening on %s", port) log.Fatal(http.ListenAndServe(port, r)) break }