Beispiel #1
0
func main() {
	config.Initialize()
	leverutil.UpdateLoggingSettings()

	server, err := leverapi.NewServer()
	if err != nil {
		logger.WithFields("err", err).Fatal("Cannot create Lever server")
	}

	as, err := store.NewAerospike()
	if err != nil {
		logger.WithFields("err", err).Fatal("Cannot get aerospike client")
	}
	ad, err := admin.NewAdmin(as)
	if err != nil {
		logger.WithFields("err", err).Fatal("Cannot create Admin obj")
	}
	err = server.RegisterHandlerObject(ad)
	if err != nil {
		logger.WithFields("err", err).Fatal("Cannot register Lever handler")
	}

	err = server.Serve()
	if err != nil {
		logger.WithFields("err", err).Fatal("Error while serving")
	}
}
Beispiel #2
0
func main() {
	config.Initialize()

	err := config.UploadFile(FileFlag.Get(), ServiceFlag.Get())
	if err != nil {
		log.Fatalf("Unable to upload config: %v\n", err)
	}
}
Beispiel #3
0
func TestMain(m *testing.M) {
	config.Initialize()
	leverutil.UpdateLoggingSettings()

	logger.Info("Deploying...")
	err := admin.DeployServiceDir(
		core.AdminEnvFlag.Get(), core.DefaultDevAliasFlag.Get(),
		core.DefaultDevEnvFlag.Get(), serviceName)
	if err != nil {
		logger.WithFields("err", err).Fatal("Error when deploying")
	}
	logger.Info("Deployed")
	client, err = api.NewClient()
	if err != nil {
		logger.WithFields("err", err).Fatal("Error getting client")
	}
	client.ForceHost = core.DefaultDevAliasFlag.Get()
	leverService = client.Service(core.DefaultDevEnvFlag.Get(), serviceName)
	logger.Info("Running tests...")
	os.Exit(m.Run())
}
Beispiel #4
0
func main() {
	config.Initialize()
	leverutil.UpdateLoggingSettings()

	as, err := store.NewAerospike()
	if err != nil {
		logger.WithFields("err", err).Fatal("Failed to get aerospike client")
	}

	err = store.InitServiceTable(as)
	if err != nil {
		logger.WithFields("err", err).Fatal("Failed to init service table")
	}

	err = store.NewEnv(as, core.AdminEnvFlag.Get(), "The admin environment")
	if err != nil {
		logger.WithFields("err", err).Warning("Failed to create admin env")
	}

	err = store.NewEnv(as, core.DefaultDevEnvFlag.Get(), "The default environment")
	if err != nil {
		logger.WithFields("err", err).Warning("Failed to create new env")
	}

	err = store.NewService(
		as, core.AdminEnvFlag.Get(), "admin", "The admin environment", true)
	if err != nil {
		logger.WithFields("err", err).Warning("Failed to create admin service")
	}
	err = store.SetServiceLiveCodeVersion(
		as, core.AdminEnvFlag.Get(), "admin", 1)
	if err != nil {
		logger.WithFields("err", err).Warning(
			"Failed to set admin live code version")
	}
}
Beispiel #5
0
func main() {
	config.Initialize()
	leverutil.UpdateLoggingSettings()

	logger.WithFields(
		"version", Version,
		"gitHash", GitHash,
	).Info("Starting up...")

	_, err := devlogger.NewDevLogger(ExternalIPFlag.Get())
	if err != nil {
		logger.WithFields("err", err).Fatal("Cannot start devlogger")
	}

	// Docker.
	dockerLocal := dockerutil.NewDockerLocal()
	dockerSwarm := dockerutil.NewDockerSwarm()

	// Own regional IP.
	ownIP, err := dockerutil.GetOwnEnvIPv4(
		dockerLocal, hostman.RegionalNetworkFlag.Get())
	if err != nil {
		logger.WithFields("err", err).Fatal("Error getting own regional IPv4")
	}
	// Own GRPC address.
	grpcAddr := ownIP + ":" + InternalGRPCListenPortFlag.Get()

	// Start internal GRPC server.
	listener, err := net.Listen("tcp", grpcAddr)
	if err != nil {
		logger.WithFields(
			"err", err,
			"listenAddr", grpcAddr,
		).Fatal("Could not start listening")
	}
	grpcServer := grpc.NewServer()

	// GRPC client pool.
	grpcPool, err := scale.NewGRPCPool()
	if err != nil {
		logger.WithFields("err", err).Fatal("Cannot create GRPC pool")
	}

	// Start finder.
	as, err := store.NewAerospike()
	if err != nil {
		logger.WithFields("err", err).Fatal("Cannot get aerospike client")
	}
	finder := host.NewFinder(dockerSwarm, as)

	// Start host manager.
	proxyInAddr := ownIP + ":" + host.EnvInListenPortFlag.Get()
	manager, err := hostman.NewManager(
		grpcServer, grpcPool, dockerLocal, grpcAddr, proxyInAddr)
	if err != nil {
		logger.WithFields("err", err).Fatal("Cannot create host manager")
	}

	// Start proxy.
	_, err = host.NewLeverProxy(manager, finder, ownIP, grpcPool)
	if err != nil {
		logger.WithFields("err", err).Fatal("Cannot create Lever proxy")
	}

	// Start fleettracker.
	_, err = fleettracker.NewFleetTracker(
		grpcServer, grpcPool, dockerSwarm, grpcAddr)
	if err != nil {
		logger.WithFields("err", err).Fatal("Error starting fleettracker")
	}

	// Start API server.
	_, err = apiserver.NewServer()
	if err != nil {
		logger.WithFields("err", err).Fatal("Error starting API server")
	}

	logger.Info("\n" +
		"    _                       ___  ___ \n" +
		"   | |   _____ _____ _ _   / _ \\/ __|\n" +
		"   | |__/ -_) V / -_) '_| | (_) \\__ \\\n" +
		"   |____\\___|\\_/\\___|_|    \\___/|___/\n" +
		"   v" + Version + "\n" +
		"                       Ready to serve\n")

	// GRPC enter loop.
	err = grpcServer.Serve(listener)
	if err != nil {
		logger.WithFields("err", err).Fatal("Error in internal GRPC server")
	}

	// TODO: Ideally we should trap signals and shut down properly.
}