Esempio n. 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")
	}
}
Esempio n. 2
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())
}
Esempio n. 3
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")
	}
}
Esempio n. 4
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.
}
Esempio n. 5
0
func main() {
	leverutil.UpdateLoggingSettings()

	app := cli.NewApp()
	app.Name = "lever"
	app.Usage = "Command line interface for Lever OS"
	// TODO: Need proper installation logic for bash completion to work.
	app.EnableBashCompletion = true
	app.Version = Version
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:        "env, E",
			Value:       "dev.lever",
			EnvVar:      "LEVEROS_ENV",
			Usage:       "The name of the environment to act on.",
			Destination: &flagEnv,
		},
		cli.StringFlag{
			Name:   "host, H",
			Value:  "",
			EnvVar: "LEVEROS_IP_PORT",
			Usage: "The address to direct the client to, if different from " +
				"the env name. The CLI attempts to auto-detect the host when " +
				"env name ends with .lever, as it is assumed that a local " +
				"installation is trying to be contacted.",
			Destination: &flagHost,
		},
	}
	app.Commands = []cli.Command{
		{
			Name:      "deploy",
			Usage:     "Deploy a directory as a Lever service.",
			ArgsUsage: "[<dir>]",
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:        "admin",
					Value:       "admin.lever",
					Usage:       "The admin environment to call.",
					Destination: &flagAdminEnv,
				},
			},
			Action: actionDeploy,
		},
		{
			Name: "invoke",
			Usage: "Invoke a Lever method with provided args. If the " +
				"first <jsonarg> is --, then args are assumed to be of type " +
				"bytes and are read from standard input.",
			ArgsUsage: "<url> [jsonargs...]",
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name: "pretty",
					Usage: "Pretty print the JSON reply. " +
						"No effect if the reply is of type bytes.",
					Destination: &flagPrettyPrint,
				},
			},
			Action: actionInvoke,
		},
		{
			Name: "stream",
			Usage: "Invoke a Lever streaming method with provided args. " +
				"The stream communication takes place via standard I/O. " +
				"While it is possible for the stream itself to be of type " +
				"bytes, this command does not allow for the args of the " +
				"invokation to be of type bytes.",
			ArgsUsage: "<url> [jsonargs...]",
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name: "bytes",
					Usage: "Stdin will be interpreted as byte " +
						"chunks rather than JSON.",
					Destination: &flagBytes,
				},
				cli.BoolFlag{
					Name: "pretty",
					Usage: "Pretty print the JSON reply. " +
						"No effect if the reply is of type bytes.",
					Destination: &flagPrettyPrint,
				},
			},
			Action: actionStream,
		},
	}

	err := app.Run(os.Args)
	if err != nil {
		logger.WithFields("err", err).Fatal("")
	}
}