2017-04-14 02:29:55 +00:00
|
|
|
package crawler_manager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"log"
|
|
|
|
g "loafle.com/overflow/crawler_go/grpc"
|
|
|
|
"context"
|
2017-04-14 07:23:42 +00:00
|
|
|
|
2017-04-14 02:29:55 +00:00
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func CallAdd() {
|
|
|
|
|
|
|
|
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("did not connect: %v", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
cc := g.NewConfigClient(conn)
|
|
|
|
|
|
|
|
in := &g.Input{}
|
|
|
|
|
|
|
|
in.Id = "test_redis_sid"
|
|
|
|
in.Name = g.Crawlers_HEALTH_REDIS
|
|
|
|
|
|
|
|
out, err := cc.Add(context.Background(), in)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
log.Println(out)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-14 07:23:42 +00:00
|
|
|
func CallInit2(address string, cpm *map[string][]string) bool {
|
|
|
|
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("did not connect: %v", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
cc := g.NewConfigClient(conn)
|
|
|
|
|
|
|
|
in := &g.Init{}
|
|
|
|
|
|
|
|
in.Path = "/home/snoop/develop/path/go/src/loafle.com/overflow/crawler_go/config/"
|
|
|
|
//in.Name = g.Crawlers(g.Crawlers_value[""])
|
|
|
|
in.Name = g.Crawlers_HEALTH_REDIS
|
|
|
|
|
|
|
|
inArr := &g.InputArray{}
|
|
|
|
inArr.In = append(inArr.In, in)
|
|
|
|
|
|
|
|
outInit, errInit := cc.Init(context.Background(), inArr)
|
|
|
|
if errInit != nil {
|
|
|
|
log.Println(errInit)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.Println(outInit)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func CallInit(crawlerName string, path string) {
|
2017-04-14 02:29:55 +00:00
|
|
|
|
2017-04-14 07:23:42 +00:00
|
|
|
port := portMap[crawlerName]
|
2017-04-14 02:29:55 +00:00
|
|
|
|
|
|
|
conn, err := grpc.Dial(address+port, grpc.WithInsecure())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("did not connect: %v", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
cc := g.NewConfigClient(conn)
|
|
|
|
|
|
|
|
in := &g.Init{}
|
|
|
|
|
|
|
|
in.Path = filepath.Dir(path)+ "/"
|
|
|
|
|
2017-04-14 07:23:42 +00:00
|
|
|
in.Name = g.Crawlers(g.Crawlers_value[crawlerName])
|
2017-04-14 02:29:55 +00:00
|
|
|
|
|
|
|
inArr := &g.InputArray{}
|
|
|
|
inArr.In = append(inArr.In, in)
|
|
|
|
|
|
|
|
outInit, errInit := cc.Init(context.Background(), inArr)
|
|
|
|
if errInit != nil {
|
|
|
|
log.Println(errInit)
|
|
|
|
}
|
|
|
|
log.Println(outInit)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func CallRemove() {
|
|
|
|
|
|
|
|
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("did not connect: %v", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
cc := g.NewConfigClient(conn)
|
|
|
|
|
|
|
|
inR := &g.Input{}
|
|
|
|
inR.Id = "123123"
|
|
|
|
inR.Name = g.Crawlers_HEALTH_DNS
|
|
|
|
|
|
|
|
outRem, errRem := cc.Remove(context.Background(), inR)
|
|
|
|
if errRem != nil {
|
|
|
|
log.Println(errRem)
|
|
|
|
}
|
|
|
|
log.Println(outRem)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func CallGet() {
|
|
|
|
conn, err := grpc.Dial("localhost:50000", grpc.WithInsecure())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("did not connect: %v", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
c := g.NewDataClient(conn)
|
|
|
|
|
|
|
|
in := &g.Input{
|
|
|
|
Name: g.Crawlers_HEALTH_REDIS,
|
|
|
|
Id: "test_redis_sid",
|
|
|
|
}
|
|
|
|
|
|
|
|
out, err := c.Get(context.Background(), in)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("could not greet: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var check bool
|
|
|
|
json.Unmarshal(out.Data, &check)
|
|
|
|
log.Println(check)
|
|
|
|
}
|