From 9a18d9139948f481c7563ba54f1097ecffa19295 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Fri, 13 Dec 2013 13:35:12 -0600 Subject: [PATCH] Move things around. --- commands/pilosa-cruncher/cruncher.go | 28 ++++------------------------ core/service.go | 6 +----- cruncher/cruncher.go | 27 +++++++++++++++------------ 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/commands/pilosa-cruncher/cruncher.go b/commands/pilosa-cruncher/cruncher.go index 0efe20441..865431d5b 100644 --- a/commands/pilosa-cruncher/cruncher.go +++ b/commands/pilosa-cruncher/cruncher.go @@ -1,31 +1,11 @@ package main import ( - "pilosa/core" - "pilosa/db" - "flag" - "log" + "pilosa/cruncher" + "pilosa/config" ) -var tcpLoc string -var httpLoc string - -func init() { - flag.StringVar(&tcpLoc, "l", "127.0.0.1:1300", "ip:port to listen on (tcp)") - flag.StringVar(&httpLoc, "h", "127.0.0.1:1400", "ip:port to listen on (http)") - flag.Parse() -} - func main() { - tcp, err := db.NewLocation(tcpLoc) - if err != nil { - log.Fatal("Location not valid:", tcpLoc) - } - http, err := db.NewLocation(httpLoc) - if err != nil { - log.Fatal("Location not valid:", httpLoc) - } - - service := core.NewService(tcp, http) - service.Run() + cruncher := cruncher.NewCruncher() + cruncher.Run(config.GetInt("port_tcp")) } diff --git a/core/service.go b/core/service.go index f3233c879..0c2e461f4 100644 --- a/core/service.go +++ b/core/service.go @@ -9,7 +9,6 @@ import ( "net" "encoding/gob" "pilosa/db" - "pilosa/config" ) type Stats struct { @@ -32,7 +31,6 @@ type Service struct { PortHttp string Etcd *etcd.Client Cluster *db.Cluster - Cruncher *Cruncher TopologyMapper *TopologyMapper ProcessMapper *ProcessMapper ProcessMap *ProcessMap @@ -40,9 +38,8 @@ type Service struct { Dispatcher *Dispatcher } -func NewService(tcp, http *db.Location) *Service { +func NewService() *Service { service := new(Service) - service.Cruncher = new(Cruncher) service.Etcd = etcd.NewClient(nil) service.Cluster = db.NewCluster() service.TopologyMapper = &TopologyMapper{service, "/pilosa/0"} @@ -63,7 +60,6 @@ func (service *Service) GetSignals() (chan os.Signal, chan os.Signal) { func (service *Service) Run() { log.Println("Running service...") go service.TopologyMapper.Run() - go service.Cruncher.Run(config.GetInt("port_tcp")) sigterm, sighup := service.GetSignals() for { diff --git a/cruncher/cruncher.go b/cruncher/cruncher.go index ceef6a8ce..51aee8ecb 100644 --- a/cruncher/cruncher.go +++ b/cruncher/cruncher.go @@ -3,24 +3,27 @@ package cruncher import ( "github.com/davecgh/go-spew/spew" "pilosa/index" + "pilosa/core" ) type Cruncher struct { + core.Service close_chan chan bool } func (cruncher *Cruncher) Run(port int) { - spew.Dump("Cruncher.Run") - spew.Dump(port) - web_api:= index.NewFragmentContainer() -// web_api.AddFragment("general", "25", 0, "AAA-BBB-CCC") -// web_api.AddFragment("general", "25", 1, "AAA-BBB-CCC") -// web_api.AddFragment("general", "25", 2, "AAA-BBB-CCC") - -started:= make(chan bool) -go web_api.RunServer(port , cruncher.close_chan ,started ) -<-started -//server is listening and going - + spew.Dump("Cruncher.Run") + spew.Dump(port) + web_api:= index.NewFragmentContainer() + started:= make(chan bool) + go web_api.RunServer(port , cruncher.close_chan ,started ) + cruncher.Service.Run() + <-started +} + +func NewCruncher() *Cruncher { + service := core.NewService() + cruncher := Cruncher{*service, make(chan bool)} + return &cruncher }