Ejemplo n.º 1
0
func main() {
	logger = cocaine.NewLogger()
	binds := map[string]cocaine.EventHandler{
		"get": get,
	}
	Worker := cocaine.NewWorker()
	Worker.Loop(binds)
}
Ejemplo n.º 2
0
func mustCreateLogger() Logger {
	log, err := cocaine.NewLogger()
	if err != nil {
		// panic(fmt.Sprintf("Unable to create Cocaine logger, but must %v", err))
		l := loggerLogrus{Logger: logrus.StandardLogger()}
		logrus.SetLevel(logrus.DebugLevel)
		return &l
	}
	return log
}
Ejemplo n.º 3
0
func dummy(request *cocaine.Request, response *cocaine.Response) {
	logger := cocaine.NewLogger()
	logger.Info("FROM HANDLER")
	<-request.Read()
	logger.Info("AFTER READ")
	response.Write("Hello! I'm GO worker")
	logger.Info("AFTER WRITE")
	response.Close()
	logger.Info("AFTER CLOSE")
}
Ejemplo n.º 4
0
func main() {
	logger = cocaine.NewLogger()
	storage, _ = cocaine.NewStorage("localhost", 10053)
	binds := map[string]cocaine.EventHandler{
		"testevent": dummy,
		"echo":      echo,
		"test":      app_list,
		"http":      http_test}
	Worker := cocaine.NewWorker()
	Worker.Loop(binds)
}
Ejemplo n.º 5
0
func main() {
	var err error
	logger, err = cocaine.NewLogger()
	binds := map[string]cocaine.EventHandler{
		"send": Send,
	}
	Worker, err := cocaine.NewWorker()
	if err != nil {
		log.Fatal(err)
	}
	Worker.Loop(binds)
}
Ejemplo n.º 6
0
func NewGofetcher() *Gofetcher {
	logger, err := cocaine.NewLogger()
	if err != nil {
		fmt.Printf("Could not initialize logger due to error: %v", err)
		return nil
	}
	transport := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		Dial: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: KeepAliveTimeout * time.Second,
			DualStack: true,
		}).Dial,
		TLSHandshakeTimeout: 10 * time.Second,
	}
	gofetcher := Gofetcher{logger, transport, ""}
	return &gofetcher
}
Ejemplo n.º 7
0
func main() {
	runtime.GOMAXPROCS(10)
	var err error
	logger, err = cocaine.NewLogger()
	binds := map[string]cocaine.EventHandler{
		"handleTask": handleTask,
	}

	ctxParsing = &parsing.ParsingContext{
		Ctx:      context.Background(),
		Resolver: slave.NewLocalResolver(),
	}

	Worker, err := cocaine.NewWorker()
	if err != nil {
		log.Fatal(err)
	}
	Worker.Loop(binds)
}
Ejemplo n.º 8
0
func Parsing(task Task) (err error) {
	log := cocaine.NewLogger()
	log.Info("Start ", task)
	defer log.Close()

	//Wrap it
	log.Debug("Create configuration manager")
	cfgManager := cocaine.NewService(common.CFGMANAGER)
	defer cfgManager.Close()

	log.Debug("Fetch configuration file")
	res := <-cfgManager.Call("enqueue", "parsing", task.Config)
	if err = res.Err(); err != nil {
		return
	}
	var rawCfg []byte
	if err = res.Extract(&rawCfg); err != nil {
		return
	}
	var cfg common.ParsingConfig
	common.Encode(rawCfg, &cfg)

	res = <-cfgManager.Call("enqueue", "common", "")
	if err = res.Err(); err != nil {
		return
	}
	if err = res.Extract(&rawCfg); err != nil {
		return
	}
	var combainerCfg common.CombainerConfig
	common.Encode(rawCfg, &combainerCfg)

	common.MapUpdate(&(combainerCfg.CloudCfg.DF), &(cfg.DF))
	cfg.DF = combainerCfg.CloudCfg.DF
	common.MapUpdate(&(combainerCfg.CloudCfg.DS), &(cfg.DS))
	cfg.DS = combainerCfg.CloudCfg.DS
	common.MapUpdate(&(combainerCfg.CloudCfg.DG), &(cfg.DG))
	cfg.DG = combainerCfg.CloudCfg.DG

	fetcherType, err := common.GetType(cfg.DF)
	if err != nil {
		return
	}

	log.Info(fmt.Sprintf("Use %s for fetching data", fetcherType))
	fetcher := cocaine.NewService(fetcherType)
	defer fetcher.Close()

	fetcherTask := common.FetcherTask{
		Target:    task.Host,
		StartTime: task.PrevTime,
		EndTime:   task.CurrTime,
	}

	ft := struct {
		Config map[string]interface{} "Config"
		Task   common.FetcherTask     "Task"
	}{cfg.DF, fetcherTask}

	js, _ := common.Pack(ft)

	res = <-fetcher.Call("enqueue", "get", js)
	if err = res.Err(); err != nil {
		return
	}

	var t []byte
	if err = res.Extract(&t); err != nil {
		return
	}

	// ParsingApp stage
	parserApp := cocaine.NewService(common.PARSINGAPP)
	defer parserApp.Close()
	taskToParser, err := common.Pack([]interface{}{cfg.Parser, t})
	if err != nil {
		return
	}
	res = <-parserApp.Call("enqueue", "parse", taskToParser)
	if err = res.Err(); err != nil {
		return
	}
	var z interface{}
	if err = res.Extract(&z); err != nil {
		return
	}

	// Datagrid stage
	dgType, err := common.GetType(cfg.DG)
	if err != nil {
		return
	}

	log.Info(fmt.Sprintf("Use %s for handle data", dgType))
	datagrid := cocaine.NewService(dgType)
	defer datagrid.Close()
	taskToDatagrid, err := common.Pack([]interface{}{cfg.DG, z})
	if err != nil {
		return
	}
	res = <-datagrid.Call("enqueue", "put", taskToDatagrid)
	if err = res.Err(); err != nil {
		return
	}
	var token string
	if err = res.Extract(&token); err != nil {
		return
	}
	log.Info(token)
	defer func() {
		taskToDatagrid, _ = common.Pack([]interface{}{cfg.DG, token})
		<-datagrid.Call("enqueue", "drop", taskToDatagrid)
	}()

	log.Info("Stop ", task)
	return nil
}