Beispiel #1
0
func StartWebServer() error {
	conf, err := config.GetConfig()
	if err != nil {
		return err
	}

	var hystrixTimeout time.Duration
	conf.Hystrix.Timeout = strings.TrimSpace(conf.Hystrix.Timeout)
	if conf.Hystrix.Timeout != "" {
		hystrixTimeout, err = time.ParseDuration(conf.Hystrix.Timeout)
		if err != nil || hystrixTimeout < time.Millisecond {
			hystrixTimeout = time.Second
			log15.Error("Use default time", "module", "hystrix", "timeout", hystrixTimeout)
		}
	}

	hystrix.ConfigureCommand("waitFor", hystrix.CommandConfig{
		Timeout:                int(int64(hystrixTimeout) / int64(time.Millisecond)), // converted into Millisecond.
		MaxConcurrentRequests:  conf.Hystrix.MaxConcurrentRequests,
		ErrorPercentThreshold:  conf.Hystrix.ErrorPercentThreshold,
		RequestVolumeThreshold: conf.Hystrix.RequestVolumeThreshold,
		SleepWindow:            conf.Hystrix.SleepWindow,
	})

	e := echo.New()
	e.Post("/api/v1/tweet", createTweetV1)
	e.Get("/api/v1/tweets/:id", getAllTweetForV1)
	e.Get("/api/v1/wait/:timeout", waitFor)
	e.Get("/api/v1/wait_protected/:timeout", waitForProtected)
	e.Static("/", "www/static/")
	logsrv := log15.New("pid", os.Getpid(), "addr", conf.Web.Address)
	return listenAndServer(logsrv, conf.Web.Address, handlers.LoggingHandler(os.Stdout, handlers.CompressHandler(e.Router())))
}
Beispiel #2
0
func initDb() gorm.DB {
	config := conf.GetConfig()
	dbConfig := config.DB

	db, err := gorm.Open("mysql", fmt.Sprintf("%s:%s@/%s?charset=utf8&parseTime=True&loc=Local",
		dbConfig.User, dbConfig.Password, dbConfig.DBname))

	if err != nil {
		fmt.Print(err.Error())
	}

	db.DB()
	db.DB().Ping()
	db.DB().SetMaxIdleConns(dbConfig.MaxIdleConns)
	db.DB().SetMaxOpenConns(dbConfig.MaxOpenConns)

	db.SingularTable(true)

	// New tables should be put here.
	var tables []interface{}
	tables = append(tables, &m.Developer{}, &m.System{}, &m.Deploy{})
	for _, table := range tables {
		if config.DevMode {
			//			db.DropTable(table)
		}
		db.AutoMigrate(table)
	}
	return db
}
Beispiel #3
0
func GetSession() (*gocql.Session, error) {
	once.Do(func() {
		var conf *config.Config
		conf, err = config.GetConfig()
		if err != nil {
			return
		}
		cluster := gocql.NewCluster(conf.Cassandra.Cluster...)
		cluster.Keyspace = conf.Cassandra.Keyspace
		cluster.Consistency = gocql.Quorum
		session, err = cluster.CreateSession()
	})
	return session, err
}
Beispiel #4
0
// Run ...
func Run(manager *manager.Manager, port uint) {
	path := filepath.Join(config.GetConfig().DataDir, "skizze.aof")
	storage := storage.NewAOF(path)

	lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) // RPC port
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	g := grpc.NewServer()

	server = &serverStruct{manager, g, storage}
	pb.RegisterSkizzeServer(g, server)
	server.replay()
	_ = g.Serve(lis)
}
Beispiel #5
0
func main() {
	var port uint
	flag.UintVar(&port, "p", 3596, "specifies the port for Skizze to run on")
	flag.Parse()

	//TODO: Add arguments for dataDir and infoDir

	err := os.Setenv("SKIZZE_PORT", strconv.Itoa(int(port)))
	utils.PanicOnError(err)

	logger.Infof("Starting Skizze...")
	logger.Infof("Using data dir: %s", config.GetConfig().DataDir)
	//server, err := server.New()
	//utils.PanicOnError(err)
	//server.Run()
	mngr := manager.NewManager()
	if p, err := strconv.Atoi(os.Getenv("SKIZZE_PORT")); err == nil {
		server.Run(mngr, uint(p))
	}
}
Beispiel #6
0
func main() {
	var (
		err       error
		cmdConfig *config.CommandLineConfiguration
		cfg       *config.Config
		m         *martini.ClassicMartini
		log       *logging.Logger
	)
	cmdConfig, err = config.GetCommandLineConfiguration()
	if err != nil {
		panic(err)
	}
	cfg, err = config.GetConfig(cmdConfig.ConfigFilePath)
	if err != nil {
		panic(err)
	}
	defer cfg.Logger.LogFile.Close()
	log, err = logger.GetLogger(&cfg.Logger)
	if err != nil {
		panic(err)
	}
	session, err := db.GetSession(&cfg.DatabaseConnectOpts)
	if err != nil {
		panic(err)
	}
	m = martini.Classic()
	m.Map(log)
	m.Map(&cfg.WebSocketConfig)
	m.Map(&cfg.HttpServer)
	m.Map(&cfg)
	m.Map(session)
	m.Use(render.Renderer(render.Options{
		Layout: "base",
	}))
	routing.Configure(m)
	log.Info("Listening")
	m.RunOnAddr(cfg.ListenHost + ":" + cfg.ListenPort)
	log.Info("Listening")
}
func listenAndServer(log log15.Logger, addr string, handler http.Handler) error {
	conf, err := config.GetConfig()
	if err != nil {
		return err
	}

	conf.Endless.DefaultHammerTime = strings.TrimSpace(conf.Endless.DefaultHammerTime)

	if conf.Endless.DefaultHammerTime != "" {
		duration, err := time.ParseDuration(conf.Endless.DefaultHammerTime)
		if err == nil {
			endless.DefaultHammerTime = duration
		} else {
			log.Error("Bad format", log15.Ctx{"module": "Endless", "DefaultHammerTime": conf.Endless.DefaultHammerTime, "error": err})
		}
	}

	var terminated int32
	srv := endless.NewServer(addr, handler)
	preHookFunc := func() {
		atomic.StoreInt32(&terminated, 1)
	}
	srv.RegisterSignalHook(endless.PRE_SIGNAL, syscall.SIGHUP, preHookFunc)
	srv.RegisterSignalHook(endless.PRE_SIGNAL, syscall.SIGINT, preHookFunc)
	srv.RegisterSignalHook(endless.PRE_SIGNAL, syscall.SIGTERM, preHookFunc)

	log.Info("Launching server")
	err = srv.ListenAndServe()
	if atomic.LoadInt32(&terminated) == 0 {
		if err != nil {
			log.Error("During startup, error has occurred", "error", err)
		}
		return err
	} else {
		log.Info("Server is going to shutdown")
		return nil
	}
}
Beispiel #8
0
func TestCreateDeleteDom(t *testing.T) {
	config.Reset()
	utils.SetupTests()
	defer utils.TearDownTests()

	path := filepath.Join(config.GetConfig().DataDir, "skizze.aof")
	aof := NewAOF(path)
	aof.Run()

	dom := createDom("test1")
	err := aof.Append(CreateDom, dom)
	if err != nil {
		t.Error("Expected no error, got", err)
	}

	dom = createDom("test2")
	err = aof.Append(CreateDom, dom)
	if err != nil {
		t.Error("Expected no error, got", err)
	}

	// Create new AOF
	aof = NewAOF(path)

	for {
		e, err2 := aof.Read()
		if err2 != nil {
			if err2.Error() != "EOF" {
				t.Error("Expected no error, got", err2)
			}
			break
		}
		dom := &pb.Domain{}
		err = proto.Unmarshal(e.raw, dom)
		if err != nil {
			t.Error("Expected no error, got", err)
			break
		}
	}
	aof.Run()

	dom = createDom("test3")

	if err = aof.Append(CreateDom, dom); err != nil {
		t.Error("Expected no error, got", err)
	}

	dom = new(pb.Domain)
	dom.Name = utils.Stringp("test1")

	if err = aof.Append(DeleteDom, dom); err != nil {
		t.Error("Expected no error, got", err)
	}

	aof = NewAOF(path)
	for {
		e, err := aof.Read()
		if err != nil {
			if err.Error() != "EOF" {
				t.Error("Expected no error, got", err)
			}
			break
		}
		dom := &pb.Domain{}
		err = proto.Unmarshal(e.raw, dom)
		if err != nil {
			t.Error("Expected no error, got", err)
			break
		}
	}
}
Beispiel #9
0
func TestCreateDeleteSketch(t *testing.T) {
	config.Reset()
	utils.SetupTests()
	defer utils.TearDownTests()

	path := filepath.Join(config.GetConfig().DataDir, "skizze.aof")
	aof := NewAOF(path)
	aof.Run()

	sketch := createSketch("skz1", pb.SketchType_CARD)
	err := aof.Append(CreateDom, sketch)
	if err != nil {
		t.Error("Expected no error, got", err)
	}

	sketch = createSketch("skz2", pb.SketchType_FREQ)
	err = aof.Append(CreateDom, sketch)
	if err != nil {
		t.Error("Expected no error, got", err)
	}

	// Create new AOF
	aof = NewAOF(path)
	for {
		e, err2 := aof.Read()
		if err2 != nil {
			if err2.Error() != "EOF" {
				t.Error("Expected no error, got", err2)
			}
			break
		}
		sketch := &pb.Sketch{}
		err = proto.Unmarshal(e.raw, sketch)
		if err != nil {
			t.Error("Expected no error, got", err)
		}
	}
	aof.Run()

	sketch = createSketch("skz3", pb.SketchType_RANK)
	err = aof.Append(CreateDom, sketch)
	if err != nil {
		t.Error("Expected no error, got", err)
	}

	sketch = createSketch("skz1", pb.SketchType_RANK)
	if err = aof.Append(DeleteDom, sketch); err != nil {
		t.Error("Expected no error, got", err)
	}

	addReq := &pb.AddRequest{
		Sketch: sketch,
		Values: []string{"foo", "bar", "hello", "world"},
	}
	if err = aof.Append(4, addReq); err != nil {
		t.Error("Expected no error, got", err)
	}

	aof = NewAOF(path)
	for {
		e, err := aof.Read()
		if err != nil {
			if err.Error() != "EOF" {
				t.Error("Expected no error, got", err)
			}
			break
		}
		if e.op == Add {
			req := &pb.AddRequest{}
			err = proto.Unmarshal(e.raw, req)
		} else {
			sketch := &pb.Sketch{}
			err = proto.Unmarshal(e.raw, sketch)
		}
		if err != nil {
			t.Error("Expected no error, got", err)
		}
	}
}
Beispiel #10
0
import (
	"config"
	"controllers"
	dbUtils "db-utils"
	"github.com/gin-gonic/contrib/sessions"
	"github.com/gin-gonic/gin"
	"github.com/golang/appengine/log"
	"google.golang.org/appengine"
	"google.golang.org/appengine/user"
	"models"
	"net/http"
	"strings"
)

var store = sessions.NewCookieStore([]byte(config.GetConfig().AuthKey))

var db = dbUtils.DB

func updateDevPending() gin.HandlerFunc {
	return func(c *gin.Context) {
		var developer models.Developer
		developer.LoggedUser(&db, c)
		if developer.Name == "" || developer.GithubAccount == "" {
			c.HTML(http.StatusAccepted, "user.tmpl", gin.H{
				"developer": &developer,
			})
			c.Abort()
			return
		}
	}