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;