Exemple #1
0
// int *cauchy_original_coding_matrix(int k, int m, int w);
// int *jerasure_matrix_to_bitmatrix(k, m, w, matrix);
func GenerateCRSBitMatrix(k, m, w int) []int {
	gom := make([]int, 0)

	matrix := C.cauchy_original_coding_matrix(C.int(k), C.int(m), C.int(w))
	if matrix == nil {
		log.Fatal("erasure: cannot make matrix")
	}
	bitmatrix := C.jerasure_matrix_to_bitmatrix(C.int(k), C.int(m), C.int(w), matrix)
	if bitmatrix == nil {
		log.Fatal("erasure: cannot make matrix")
	}
	length := int(k * m * w * w)
	hdr := reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(bitmatrix)),
		Len:  length,
		Cap:  length,
	}
	matrixSlice := *(*[]C.int)(unsafe.Pointer(&hdr))

	for _, e := range matrixSlice {
		gom = append(gom, int(e))
	}

	return gom
}
Exemple #2
0
func InstallAction(c *cli.Context) {
	if c.Bool("debug") {
		log.SetOutputLevel(log.Ldebug)
	}
	if len(c.Args()) < 1 {
		log.Fatal("Need at lease one argument")
	}
	// log.Println(GOBIN)
	pkgName := c.Args().First()
	// TODO: use myname for now
	if len(strings.Split(pkgName, "/")) == 1 {
		pkgName = "gobuild-official/" + pkgName
	}

	prompt("Repository %v", pkgName)
	dest, err := downloadSource(pkgName)
	if err != nil {
		log.Fatal(err)
	}

	err = deployPackage(pkgName, dest, GOBIN)
	if err != nil {
		log.Fatal(err)
	}

	prompt("Program [%s] installed", pkgName)
}
Exemple #3
0
func init() {
	cfg := new(config)
	in, err := ioutil.ReadFile("config.yaml")
	if err != nil {
		log.Fatal(err)
	}
	err = goyaml.Unmarshal(in, cfg)
	if err != nil {
		log.Fatal(err)
	}

	flag.Parse()
	log.SetOutputLevel(log.Ldebug)

	if *environment == "development" {
		opts = &cfg.Development
	} else {
		opts = &cfg.Production
	}

	fmt.Println("== environment:", *environment, "==")
	utils.Dump(opts)

	conf.ACCESS_KEY = opts.AccessKey
	conf.SECRET_KEY = opts.SecretKey

	// render html templates from templates directory
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	InitRouter()
}
Exemple #4
0
func main() {
	var err error
	err = database.InitDB(opts.Driver, opts.DataSource)
	if err != nil {
		log.Fatal(err)
	}
	log.Info("gobuild service stated ...")

	http.Handle("/", m)
	http.Handle("/websocket/", websocket.Handler(WsBuildServer))
	http.HandleFunc("/hello", HelloServer)

	if *secure {
		go func() {
			er := http.ListenAndServeTLS(":443", "bin/ssl.crt", "bin/ssl.key", nil)
			if er != nil {
				log.Error(er)
			}
		}()
	}
	err = http.ListenAndServe(opts.ListenAddr, nil)
	if err != nil {
		log.Fatal(err)
	}
}
Exemple #5
0
func wrap(f interface{}) func(*cli.Context) {
	return func(ctx *cli.Context) {
		if ctx.GlobalBool("debug") {
			log.SetOutputLevel(log.Ldebug)
		}

		sockPath := filepath.Join(GOSUV_HOME, "gosuv.sock")
		if err := testConnection("unix", sockPath); err != nil {
			log.Fatal(err)
		}

		conn, err := connect(ctx)
		if err != nil {
			log.Fatal(err)
		}
		defer conn.Close()
		programClient := pb.NewProgramClient(conn)
		gosuvClient := pb.NewGoSuvClient(conn)

		inj := inject.New()
		inj.Map(programClient)
		inj.Map(gosuvClient)
		inj.Map(ctx)
		inj.Invoke(f)
	}
}
Exemple #6
0
func runUpdate(c *cli.Context) {
	cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
	if cmd == "" {
		return
	}

	setup(path.Join(setting.LogRootPath, "update.log"))

	args := c.Args()
	if len(args) != 3 {
		qlog.Fatal("received less 3 parameters")
	} else if args[0] == "" {
		qlog.Fatal("refName is empty, shouldn't use")
	}

	//updateEnv(args[0], args[1], args[2])

	userName := os.Getenv("userName")
	userId, _ := strconv.ParseInt(os.Getenv("userId"), 10, 64)
	//repoId := os.Getenv("repoId")
	repoUserName := os.Getenv("repoUserName")
	repoName := os.Getenv("repoName")

	models.Update(args[0], args[1], args[2], userName, repoUserName, repoName, userId)
}
Exemple #7
0
func AddAction(ctx *cli.Context, client pb.GoSuvClient) {
	name := ctx.String("name")
	if name == "" {
		name = filepath.Base(ctx.Args()[0])
	}

	dir, _ := os.Getwd()

	if len(ctx.Args()) < 1 {
		log.Fatal("need at least one args")
	}
	cmdName := ctx.Args().First()
	cmdPath, err := exec.LookPath(cmdName)
	if err != nil {
		log.Fatal(err)
	}

	req := new(pb.ProgramInfo)
	req.Name = ctx.String("name")
	req.Directory = dir
	req.Command = append([]string{cmdPath}, ctx.Args().Tail()...)
	req.Environ = ctx.StringSlice("env")

	res, err := client.Create(context.Background(), req)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(res.Message)
}
Exemple #8
0
func actionShutdown(c *cli.Context) error {
	restart := c.Bool("restart")
	if restart {
		log.Fatal("Restart not implemented.")
	}
	ret, err := postForm("/api/shutdown", nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(ret.Value)
	return nil
}
Exemple #9
0
func main() {
	kingpin.Version(VERSION)
	kingpin.CommandLine.VersionFlag.Short('v')
	kingpin.CommandLine.HelpFlag.Short('h')
	kingpin.Parse()

	if !cfg.Server.Enable && localAddr == "" {
		kingpin.Usage()
		return
	}
	if !cfg.Debug {
		log.SetOutputLevel(log.Linfo)
	} else {
		log.SetOutputLevel(log.Ldebug)
	}

	pURL, err := parseURL(localAddr, cfg.Proto)
	if err != nil {
		log.Fatal(err)
	}

	if cfg.Server.Enable {
		_, port, _ := net.SplitHostPort(pURL.Host)
		if port == "" {
			port = "80"
		}
		addr := net.JoinHostPort("0.0.0.0", port)
		if cfg.Server.Domain == "" {
			cfg.Server.Domain = "localhost" //cfg.Server.Addr
		}
		fmt.Printf("proxylocal: server listen on %v, domain is %v\n", addr, cfg.Server.Domain)
		ps := pxlocal.NewProxyServer(cfg.Server.Domain)
		log.Fatal(http.ListenAndServe(addr, ps))
	}

	// var localAddr = flag.Arg(0)
	// if !regexp.MustCompile("^(http|https|tcp)://").MatchString(localAddr) {
	// 	if _, err := strconv.Atoi(localAddr); err == nil { // only contain port
	// 		localAddr = "localhost:" + localAddr
	// 	} else {
	// 		//localAddr += ":80"
	// 	}
	// 	localAddr = cfg.Proto + "://" + localAddr
	// }

	// pURL, err := url.Parse(localAddr)
	fmt.Println("proxy URL:", pURL)
	pxlocal.StartAgent(pURL, cfg.SubDomain, cfg.Server.Addr, cfg.ProxyPort, cfg.Data)
}
Exemple #10
0
func StartAgent(pURL *url.URL, subdomain, serverAddr string, remoteListenPort int, data string) {
	log.Debug("start proxy", pURL)
	if !regexp.MustCompile("^http[s]://").MatchString(serverAddr) {
		serverAddr = "http://" + serverAddr
	}
	sURL, err := url.Parse(serverAddr)
	if err != nil {
		log.Fatal(err)
	}

	sURL.Path = "/ws"
	log.Debug("server host:", sURL.Host)
	conn, err := net.Dial("tcp", sURL.Host)
	if err != nil {
		log.Fatal(err)
	}
	// specify remote listen port
	sURL.Scheme = "ws"
	query := sURL.Query()
	query.Add("protocol", pURL.Scheme)
	query.Add("subdomain", subdomain)
	query.Add("data", data)
	if remoteListenPort != 0 {
		query.Add("port", strconv.Itoa(remoteListenPort))
	}
	sURL.RawQuery = query.Encode()

	log.Debug(sURL)
	wsclient, _, err := websocket.NewClient(conn, sURL, nil, 1024, 1024)
	if err != nil {
		log.Fatal(err)
	}
	defer wsclient.Close()
	go idleWsSend(wsclient)

	for {
		var msg Msg
		if err := wsclient.ReadJSON(&msg); err != nil {
			fmt.Println("client exit: " + err.Error())
			break
		}
		log.Debug("recv:", msg)

		// sURL: serverURL
		rnl := NewRevNetListener()
		go handleRevConn(pURL, rnl)
		handleWsMsg(msg, sURL, rnl)
	}
}
Exemple #11
0
func readConfig() {
	flag.Parse()
	if !FileExists(*cfgFile) {
		log.Fatal("Need config file")
	}
	parseCfgFile(*cfgFile, m)
}
Exemple #12
0
func (r transportImpl) RoundTrip(req *http.Request) (resp *http.Response, err error) {

	h := Route[req.Host]
	if h == nil {
		log.Fatal("Server not found:", req.Host)
	}

	cp := *req
	cp.Body = &mockServerRequestBody{req.Body, false}
	req = &cp

	rw := httptest.NewRecorder()
	h.ServeHTTP(rw, req)

	ctlen := int64(-1)
	if v := rw.HeaderMap.Get("Content-Length"); v != "" {
		ctlen, _ = strconv.ParseInt(v, 10, 64)
	}

	return &http.Response{
		Status:           "",
		StatusCode:       rw.Code,
		Header:           rw.HeaderMap,
		Body:             ioutil.NopCloser(rw.Body),
		ContentLength:    ctlen,
		TransferEncoding: nil,
		Close:            false,
		Trailer:          nil,
		Request:          req,
	}, nil
}
Exemple #13
0
func actionConfigTest(c *cli.Context) error {
	if _, _, err := newSupervisorHandler(); err != nil {
		log.Fatal(err)
	}
	log.Println("test is successful")
	return nil
}
Exemple #14
0
func ServeAddr(addr string) error {
	InitServer()

	t := tango.New()
	t.Group("/api", func(g *tango.Group) {
		g.Get("/version", versionHandler)
		g.Post("/shutdown", shutdownHandler)
		g.Post("/programs", addHandler)
		g.Get("/programs", statusHandler)
	})

	go t.Run(addr)

	lis, err := net.Listen("unix", filepath.Join(GOSUV_HOME, "gosuv.sock"))
	if err != nil {
		log.Fatal(err)
	}
	handleSignal(lis)

	pbServ := &PbSuvServer{}
	pbProgram := &PbProgram{}

	grpcServ := grpc.NewServer()
	pb.RegisterGoSuvServer(grpcServ, pbServ)
	pb.RegisterProgramServer(grpcServ, pbProgram)

	pbServ.lis = lis
	grpcServ.Serve(lis)
	return fmt.Errorf("Address: %s has been used", addr)
}
Exemple #15
0
func init() {
	var err error
	logfd, err = os.OpenFile("build.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
	if err != nil {
		log.Fatal("create build.log file failed:", err)
	}
}
Exemple #16
0
func actionReload(c *cli.Context) error {
	ret, err := postForm("/api/reload", nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(ret.Value)
	return nil
}
Exemple #17
0
func VersionAction(ctx *cli.Context, client pb.GoSuvClient) {
	fmt.Printf("Client: %s\n", GOSUV_VERSION)
	res, err := client.Version(context.Background(), &pb.NopRequest{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Server: %s\n", res.Message)
}
Exemple #18
0
func actionStartServer(c *cli.Context) error {
	suv, hdlr, err := newSupervisorHandler()
	if err != nil {
		log.Fatal(err)
	}
	auth := cfg.Server.HttpAuth
	if auth.Enabled {
		hdlr = httpauth.SimpleBasicAuth(auth.User, auth.Password)(hdlr)
	}
	http.Handle("/", hdlr)

	addr := cfg.Server.Addr
	if c.Bool("foreground") {
		suv.AutoStartPrograms()
		log.Printf("server listen on %v", addr)
		log.Fatal(http.ListenAndServe(addr, nil))
	} else {
		if checkServerStatus() == nil {
			fmt.Println("server is already running")
			return nil
		}
		logPath := filepath.Join(defaultConfigDir, "gosuv.log")
		logFd, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
		if err != nil {
			log.Fatalf("create file %s failed: %v", logPath, err)
		}
		cmd := exec.Command(os.Args[0], "start-server", "-f")
		cmd.Stdout = logFd
		cmd.Stderr = logFd
		err = cmd.Start()
		if err != nil {
			log.Fatal(err)
		}
		select {
		case err = <-GoFunc(cmd.Wait):
			log.Fatalf("server started failed, %v", err)
		case <-time.After(200 * time.Millisecond):
			showAddr := addr
			if strings.HasPrefix(addr, ":") {
				showAddr = "0.0.0.0" + addr
			}
			fmt.Printf("server started, listening on %s\n", showAddr)
		}
	}
	return nil
}
Exemple #19
0
func StatusAction(client pb.GoSuvClient) {
	res, err := client.Status(context.Background(), &pb.NopRequest{})
	if err != nil {
		log.Fatal(err)
	}
	for _, ps := range res.GetPrograms() {
		fmt.Printf("%-10s\t%-8s\t%s\n", ps.Name, ps.Status, ps.Extra)
	}
}
Exemple #20
0
func actionStatus(c *cli.Context) error {
	err := checkServerStatus()
	if err != nil {
		log.Fatal(err)
	} else {
		log.Println("Server is running, OK.")
	}
	return nil
}
Exemple #21
0
func AddAction(ctx *cli.Context) {
	name := ctx.String("name")
	dir, _ := os.Getwd()
	if len(ctx.Args()) < 1 {
		log.Fatal("need at least one args")
	}
	if name == "" {
		name = ctx.Args()[0]
	}
	log.Println(ctx.Args().Tail())
	log.Println([]string(ctx.Args()))
	log.Println(ctx.Args().Tail())
	log.Println(ctx.StringSlice("env"))
	log.Println("Dir:", dir)
	cmdName := ctx.Args().First()
	log.Println("cmd name:", cmdName)
	cmdPath, err := exec.LookPath(cmdName)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("program: %s has been added\n", strconv.Quote(name))
	p := &ProgramInfo{
		Name:    name,
		Dir:     dir,
		Command: append([]string{cmdPath}, ctx.Args().Tail()...),
		Environ: ctx.StringSlice("env"),
	}
	res, err := goreq.Request{
		Method: "POST",
		Uri:    buildURI(ctx, "/api/programs"),
		Body:   p,
	}.Do()
	if err != nil {
		log.Fatal(err)
	}
	var jres JSONResponse
	if res.StatusCode != http.StatusOK {
		log.Fatal(res.Body.ToString())
	}
	if err = res.Body.FromJsonTo(&jres); err != nil {
		log.Fatal(err)
	}
	fmt.Println(jres.Message)
}
Exemple #22
0
func main() {

	gomod, err := py.NewGoModule("foo", "", new(FooModule))
	if err != nil {
		log.Fatal("NewGoModule failed:", err)
	}
	defer gomod.Decref()

	code, err := py.Compile(pyCode, "", py.FileInput)
	if err != nil {
		log.Fatal("Compile failed:", err)
	}
	defer code.Decref()

	mod, err := py.ExecCodeModule("test", code.Obj())
	if err != nil {
		log.Fatal("ExecCodeModule failed:", err)
	}
	defer mod.Decref()
}
Exemple #23
0
func newLogger(logPath string) {
	os.MkdirAll(path.Dir(logPath), os.ModePerm)

	f, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.ModePerm)
	if err != nil {
		qlog.Fatal(err)
	}

	qlog.SetOutput(f)
	qlog.Info("Start logging serv...")
}
Exemple #24
0
// New construct a selector with the given objects and type
func New(objects []interface{}, t Type) Selector {
	switch t {
	case T_ROUNDROUBIN:
		return NewRoundRobinSelector(objects)
	case T_FAILOVER:
		return NewFailoverSelector(objects)
	default:
		log.Fatal("Selector: unknown type", t)
	}
	panic("unreachable")
}
Exemple #25
0
func main() {

	conf := Config{
		Addr:    ":7090",
		MgoAddr: "127.0.0.1:27017",
		MgoDB:   "short",
		MgoColl: "short",
	}

	log.Fatal(Run(conf))
}
Exemple #26
0
func newUpdateLogger(execDir string) {
	logPath := execDir + "/log/update.log"
	os.MkdirAll(path.Dir(logPath), os.ModePerm)

	f, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.ModePerm)
	if err != nil {
		qlog.Fatal(err)
	}

	qlog.SetOutput(f)
	qlog.Info("Start logging update...")
}
Exemple #27
0
func TailAction(ctx *cli.Context, client pb.ProgramClient) {
	req := &pb.TailRequest{
		Name:   ctx.Args().First(),
		Number: int32(ctx.Int("number")),
		Follow: ctx.Bool("follow"),
	}
	tailc, err := client.Tail(context.Background(), req)
	if err != nil {
		log.Fatal(err)
	}
	for {
		line, err := tailc.Recv()
		if err == io.EOF {
			return
		}
		if err != nil {
			log.Fatal(err)
		}
		fmt.Print(line.Line)
	}
}
Exemple #28
0
func newLogger(execDir string) {
	logPath := execDir + "/log/webdav.log"
	os.MkdirAll(path.Dir(logPath), os.ModePerm)

	f, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.ModePerm)
	if err != nil {
		qlog.Fatal(err)
	}

	logger = qlog.New(f, "", qlog.Ldate|qlog.Ltime)
	logger.Info("Start logging webdav...")
}
Exemple #29
0
func main() {
	MkdirIfNoExists(GOSUV_HOME)

	if err := loadRConfig(); err != nil {
		log.Fatal(err)
	}
	initCli()

	app.HideHelp = false
	app.HideVersion = true
	app.RunAndExitOnError()
}
Exemple #30
0
func newSelector(objects []interface{}, useActive bool) Selector {
	if len(objects) == 0 {
		log.Fatal("Selector init with empty objects")
	}

	return &selector{
		objects:    objects,
		active:     rand.Intn(len(objects)),
		failureMap: make(map[int]*backoff),
		useActive:  useActive,
	}
}