Пример #1
0
func main() {
	println("executor started")
	log.SetHighlighting(false)
	f, err := os.Create("executor.log")
	if err != nil {
		println(err.Error())
	}

	log.SetOutput(f)
	log.Warning("executor start...")
	pwd, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}

	se := &ShellExecutor{pwd: pwd, finish: make(chan string),
		process: make(map[string]*contex)}
	driver := mesos.ExecutorDriver{
		Executor: &mesos.Executor{
			Registered:   se.OnRegister,
			KillTask:     se.OnKillTask,
			LaunchTask:   se.OnLaunchTask,
			Shutdown:     se.OnShutdown,
			Error:        se.OnError,
			Disconnected: se.OnDisconnected,
		},
	}

	go se.EventLoop()

	driver.Init()
	defer driver.Destroy()

	driver.Run()
}
Пример #2
0
func main() {
	writer := io.Writer(os.Stdout)
	logging.SetOutput(writer)

	r := mux.NewRouter()

	r.HandleFunc("/images", images.PostHandler).Methods("POST")
	r.HandleFunc("/images", images.GetsHandler).Methods("GET")
	r.HandleFunc("/images/{serviceName}", images.GetHandler).Methods("GET")
	r.HandleFunc("/images/{serviceName}", images.DeleteHandler).Methods("DELETE")

	r.HandleFunc("/gerrit", images.GerritHandler).Methods("POST")

	http.ListenAndServe(":8080", r)
}
Пример #3
0
func main() {
	flag.Parse()
	// show tables
	log.SetOutput(os.Stderr)

	db, err := NewMysqlDb()
	if err != nil {
		log.Fatal(err)
	}

	r, err := db.Query("SHOW TABLES")
	var tbls []string

	for r.Next() {
		var tblName string
		r.Scan(&tblName)
		tbls = append(tbls, tblName)
	}
	r.Close()

	var shards []ShardInfo
	for _, tbl := range tbls {
		r, err := db.Query("SHOW COLUMNS FROM " + tbl)
		if err != nil {
			log.Fatal(err)
		}

		var priKey string
		var uniqueKey string
		var mulKeys []string
		for r.Next() {
			values := make([]sql.RawBytes, 6)
			scanArgs := make([]interface{}, 6)
			for i := range values {
				scanArgs[i] = &values[i]
			}
			err := r.Scan(scanArgs...)
			if err != nil {
				log.Fatal(err)
			}
			if string(values[3]) == "UNI" {
				uniqueKey = string(values[0])
			} else if string(values[3]) == "MUL" {
				mulKeys = append(mulKeys, string(values[0]))
			} else if string(values[3]) == "PRI" {
				priKey = string(values[0])
			}
		}
		mulKey := strings.Join(mulKeys, ",")

		var key string
		if len(uniqueKey) > 0 {
			key = uniqueKey
		} else if len(mulKey) > 0 {
			key = mulKey
		} else if len(priKey) > 0 {
			key = priKey
		} else {
			log.Warning("illgial table", tbl)
			r.Close()
			break
		}
		info := ShardInfo{
			Table: tbl,
			Key:   key,
		}
		if len(*cacheType) > 0 {
			info.RowCacheType = *cacheType
		}
		shards = append(shards, info)
		r.Close()
	}

	shardsJson, _ := json.Marshal(shards)

	buf := bytes.NewBuffer(nil)

	t := template.Must(template.New("cfg_tmpl").Parse(tmpl))
	t.Execute(buf, &struct {
		DbName string
		Shards string
	}{
		*dbName,
		string(shardsJson),
	})

	// prettyify
	var ret interface{}
	err = json.Unmarshal(buf.Bytes(), &ret)
	if err != nil {
		log.Fatal(err)
	}

	b, err := json.MarshalIndent(ret, "", "    ")
	if err != nil {
		log.Fatal(err)
	}

	os.Stdout.Write(b)
}