From a68e9d553116acf2877d9fd2d9bbfdb42eb9e7c5 Mon Sep 17 00:00:00 2001 From: snoop Date: Fri, 14 Apr 2017 17:23:32 +0900 Subject: [PATCH] moved getclient --- connection_pool.go | 10 ---------- crawler_manager.go | 13 +++++++++++-- crawler_runner.go | 3 +++ 3 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 connection_pool.go diff --git a/connection_pool.go b/connection_pool.go deleted file mode 100644 index 0f3fa10..0000000 --- a/connection_pool.go +++ /dev/null @@ -1,10 +0,0 @@ -package crawler_manager - -import "google.golang.org/grpc" - -type GRPCPool struct { -} - -func (c *GRPCPool)GetClient(container string,port string) (*grpc.ClientConn, error) { - return grpc.Dial("localhost:50000", grpc.WithInsecure()) -} diff --git a/crawler_manager.go b/crawler_manager.go index 26ecd93..e68ea35 100644 --- a/crawler_manager.go +++ b/crawler_manager.go @@ -11,7 +11,7 @@ import ( "io/ioutil" - + "google.golang.org/grpc" ) const ( @@ -26,7 +26,7 @@ const ( ) -type crawler_manager struct { +type CrawlerManager struct { } @@ -44,6 +44,15 @@ func init() { } +func (c *CrawlerManager)GetClient(container string,port string) (*grpc.ClientConn, error) { + + port = portMap[container] + + return grpc.Dial("localhost:"+port, grpc.WithInsecure()) +} + + + func ReadConfig(path string ) *config.Config { bytes, err := ioutil.ReadFile(path) diff --git a/crawler_runner.go b/crawler_runner.go index adc3e99..60f7c54 100644 --- a/crawler_runner.go +++ b/crawler_runner.go @@ -37,6 +37,9 @@ func RunContainer(container *string, cpm *map[string][]string) { log.Println(*container + " run success port:" , currentPort , "pid:", cmd.Process.Pid ) //write pid file container_pid_port ioutil.WriteFile(PidFolder+*container+"_"+strconv.Itoa(cmd.Process.Pid)+ "_"+strconv.Itoa(currentPort), []byte(""), os.ModePerm) + + portMap[*container] = strconv.Itoa(currentPort) + currentPort++ break;