Exemplo n.º 1
0
// PackageName is the name of this package.
const PackageName = "core"

const (
	// RPCMethodHandler represents the gRPC method handling Lever RPCs.
	RPCMethodHandler = "HandleRPC"
	// StreamingRPCMethodHandler represents the gRPC method handling streaming
	// Lever RPCs.
	StreamingRPCMethodHandler = "HandleStreamingRPC"
)

var (
	// InstanceListenPortFlag is the port Lever instances listen on for
	// Lever RPCs.
	InstanceListenPortFlag = config.DeclareString(
		PackageName, "instanceListenPort", "3837")
	// InternalEnvironmentSuffixFlag represents the ending of the environment
	// host name to which RPCs can be routed to directly (via internal proxies).
	InternalEnvironmentSuffixFlag = config.DeclareString(
		PackageName, "internalEnvSufix", ".lever")

	// DefaultDevAliasFlag is the actual address of the default Lever
	// environment used for local development.
	DefaultDevAliasFlag = config.DeclareString(
		PackageName, "defaultDevAlias", getDefaultLeverOSIPPort())
	// DefaultDevEnvFlag is the default Lever environment used for local
	// development.
	DefaultDevEnvFlag = config.DeclareString(
		PackageName, "defaultDevEnv", "dev.lever")
	// AdminEnvFlag is the admin Lever environment.
	AdminEnvFlag = config.DeclareString(
Exemplo n.º 2
0
	"strings"
	"sync"

	leverapi "github.com/leveros/leveros/api"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/core"
	"github.com/leveros/leveros/host"
	"github.com/leveros/leveros/leverutil"
)

// PackageName is the name of this package.
const PackageName = "apiserver"

var (
	// ListenPortFlag is the port the API server should listen on.
	ListenPortFlag = config.DeclareString(PackageName, "listenPort", "3503")
	// DisableAPIServerFlag disables the creation of an HTTP API server.
	DisableAPIServerFlag = config.DeclareBool(PackageName, "disableAPIServer")
)

var logger = leverutil.GetLogger(PackageName, "Server")

const maxNonChanRequestSize = 512 * 1024 // 512 KiB

var bufferedReaderPool = &sync.Pool{
	New: func() interface{} {
		return bufio.NewReaderSize(nil, maxNonChanRequestSize)
	},
}

var bufferPool = &sync.Pool{
Exemplo n.º 3
0
// PackageName is the name of this package.
const PackageName = cmd.PackageName + ".leveroshost"

var (
	// Version is the version of Lever OS. This variable is set at build time.
	Version string
	// GitHash is the git hash of Lever OS. This variable is set at build time.
	GitHash string
)

var logger = leverutil.GetLogger(PackageName, "main")

var (
	// InternalGRPCListenPortFlag is the port to listen to for internal GRPC
	// connections.
	InternalGRPCListenPortFlag = config.DeclareString(
		PackageName, "internalGRPCListenPort", "3501")
	// ExternalIPFlag is the host's external IP address.
	ExternalIPFlag = config.DeclareString(
		PackageName, "externalIP", "127.0.0.1")
)

func main() {
	config.Initialize()
	leverutil.UpdateLoggingSettings()

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

	_, err := devlogger.NewDevLogger(ExternalIPFlag.Get())
Exemplo n.º 4
0
	"strings"
	"sync"

	dockerapi "github.com/fsouza/go-dockerclient"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/core"
	"github.com/leveros/leveros/devlogger"
	"github.com/leveros/leveros/leverutil"
)

// PackageName is the name of this package.
const PackageName = "dockerutil"

var (
	// DockerSwarmFlag is the docker swarm endpoint.
	DockerSwarmFlag = config.DeclareString(
		PackageName, "dockerSwarm", "unix:///var/run/docker.sock")
	// DockerLocalFlag is the local docker endpoint.
	DockerLocalFlag = config.DeclareString(
		PackageName, "dockerLocal", "unix:///var/run/docker.sock")

	// LeverCodeHostDirFlag is the location on the host (outside docker) of the
	// mounted customer code directory, containing all code from all
	// environments and services.
	LeverCodeHostDirFlag = config.DeclareString(
		PackageName, "leverCodeHostDir", "/tmp/leveros/custcodetree")

	// DisableRemoveContainerFlag causes Lever containers to not be
	// removed (on errors, on exit etc).
	DisableRemoveContainerFlag = config.DeclareBool(
		PackageName, "disableRemoveContainer")
)
Exemplo n.º 5
0
// Package main uploads a config file to consul.
package main

import (
	"log"

	"github.com/leveros/leveros/config"
)

var (
	// FileFlag is the config file to upload to consul.
	FileFlag = config.DeclareString("", "file", "")
	// ServiceFlag is the service the config belongs to.
	ServiceFlag = config.DeclareString("", "service", "")
)

func main() {
	config.Initialize()

	err := config.UploadFile(FileFlag.Get(), ServiceFlag.Get())
	if err != nil {
		log.Fatalf("Unable to upload config: %v\n", err)
	}
}
Exemplo n.º 6
0
	aerospike "github.com/aerospike/aerospike-client-go"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/scale"
)

const leverOSNamespace = "leveros"

var (
	// AerospikeFromConsulFlag indicates whether Consul should be used to get
	// an Aerospike client.
	AerospikeFromConsulFlag = config.DeclareBool(
		PackageName, "aerospikeFromConsul")
	// AerospikeFixedAddrFlag indicates a fixed address which is used if
	// AerospikeFromConsulFlag is false.
	AerospikeFixedAddrFlag = config.DeclareString(
		PackageName, "aerospikeFixedAddr", "leverosaerospike:3000")
)

// NewAerospike returns a new Aerospike client.
func NewAerospike() (as *aerospike.Client, err error) {
	var target string
	if AerospikeFromConsulFlag.Get() {
		for retry := 0; retry < 15; retry++ {
			target, _, err = scale.DereferenceService("aerospike")
			if err == nil {
				break
			}
			if err == scale.ErrServiceNotFound ||
				strings.Contains(err.Error(), "network is unreachable") ||
				strings.Contains(err.Error(), "no such host") {
				time.Sleep(1 * time.Second)
Exemplo n.º 7
0
	// establish.
	ConnectionConnectTimeoutFlag = config.DeclareDuration(
		PackageName, "connectionConnectTimeout", 20*time.Second)

	// DisableProxyExtFlag enables listening to the external interface
	// (regional LB).
	DisableProxyExtFlag = config.DeclareBool(
		PackageName, "disableProxyExt")
	// DisableProxyInOutFlag enables listening to requests going to or coming
	// from a local environment.
	DisableProxyInOutFlag = config.DeclareBool(
		PackageName, "disableProxyInOut")

	// EnvOutListenPortFlag is the environment listen port for outward
	// connections. This port is accessible only from within the env network.
	EnvOutListenPortFlag = config.DeclareString(
		PackageName, "envOutListenPort", "3838")
	// EnvInListenPortFlag is the listen port for inward connections.
	EnvInListenPortFlag = config.DeclareString(
		PackageName, "envInListenPort", "3500")
	// EnvExtListenPortFlag is the listen port for external connections.
	EnvExtListenPortFlag = config.DeclareString(
		PackageName, "envExtListenPort", "3502")
)

// LeverProxy is a proxy server that mediates Lever RPCs from the outside world
// to Lever containers and RPCs between Lever containers. The In / Out
// terminology is relative to the Lever containers (not to the proxy).
type LeverProxy struct {
	// Server for connections via unix socket file for RPC's going *out* of
	// Lever containers.
	outServer *http2stream.HTTP2Server
Exemplo n.º 8
0
	"github.com/leveros/leveros/core"
	"github.com/leveros/leveros/dockerutil"
	"github.com/leveros/leveros/leverutil"
	"github.com/leveros/leveros/scale"
	"golang.org/x/net/context"
	"google.golang.org/grpc"
)

// ManagerService is the name of the host manager internal service.
const ManagerService = "leverhostmanager"

var (
	// InstanceIDFlag is the instance ID of the manager. Note: This is
	// a different instance ID than leverutil.InstanceIDFlag because they
	// serve different things.
	InstanceIDFlag = config.DeclareString(
		PackageName, "managerInstanceID", leverutil.RandomID())

	// RegionalNetworkFlag is the name of the Docker network that the proxy
	// uses internally.
	RegionalNetworkFlag = config.DeclareString(
		PackageName, "regionalNetwork", "leveros_default")
)

// KeepAliveFun is a function that should be called on every event on a stream
// to signal the manager that the unerlying infrastructure is still being used.
type KeepAliveFun func(resourceName, levResResourceID, levResSessionID string)

type envEntry struct {
	// Guard the following, as well as network creation / destruction.
	envLock        sync.Mutex
	networkID      string
Exemplo n.º 9
0
	"fmt"
	"strings"
	"time"

	"github.com/leveros/go-syslog"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/leverutil"
	"github.com/leveros/leveros/scale"
)

// PackageName is the name of this package.
const PackageName = "devlogger"

var (
	// DevLoggerListenPortFlag is the port to listen to for syslog messages.
	DevLoggerListenPortFlag = config.DeclareString(
		PackageName, "devLoggerListenPort", "6514")
	// InstanceIDFlag is the instance ID of the devlogger. Note: This is a
	// different instance ID than leverutil.InstanceIDFlag because they serve
	// different things.
	InstanceIDFlag = config.DeclareString(
		PackageName, "instanceID", leverutil.RandomID())
	// DisableFlag disables the devlogger server.
	DisableFlag = config.DeclareBool(PackageName, "disable")
)

var logger = leverutil.GetLogger(PackageName, "DevLogger")

// DevLoggerService is the name of the devlogger internal service.
const DevLoggerService = "devlogger"

// DevLogger is a syslog server meant to be used only for dev instances of
Exemplo n.º 10
0
package leverutil

import (
	"math/rand"
	"sync"
	"time"

	"github.com/leveros/leveros/config"
)

// PackageName is the name of this package.
const PackageName = "leverutil"

var (
	// ServiceFlag is the service name that will be attached to log entries.
	ServiceFlag = config.DeclareString("", "service", "")
	// InstanceIDFlag is the instance ID that will be attached to log entries.
	InstanceIDFlag = config.DeclareString("", "instanceID", RandomID())

	// ContainerNameFlag is the name of the container this is running as (needs
	// to be set correctly from command line arg). This is used to determine
	// the containerID.
	ContainerNameFlag = config.DeclareString("", "containerName", "")
)

var (
	baseRand     = rand.New(rand.NewSource(time.Now().UnixNano()))
	baseRandLock sync.Mutex
)

var randPool = &sync.Pool{
Exemplo n.º 11
0
	"google.golang.org/grpc"
)

// PackageName is the name of this package.
const PackageName = "fleettracker"

var logger = leverutil.GetLogger(PackageName, "fleettracker")

// FleetTrackerService is the name of the fleettracker internal service.
const FleetTrackerService = "fleettracker"

var (
	// InstanceIDFlag is the instance ID of the fleettracker. Note: This is a
	// different instance ID than leverutil.InstanceIDFlag because they serve
	// different things.
	InstanceIDFlag = config.DeclareString(
		PackageName, "instanceID", leverutil.RandomID())
	// TTLFlag is the time after a service expires in fleettracker. If no RPC
	// event comes up during this span of time for a Lever service, fleettracker
	// stops keeping track of its stats (it is assumed all its instances
	// have expired anyway).
	TTLFlag = config.DeclareDuration(PackageName, "ttl", 20*time.Minute)
)

// FleetTracker ensures that each Lever service has the right number of
// instances in its fleet. It spins up or kills instances as necessary.
type FleetTracker struct {
	grpcPool   *scale.GRPCPool
	docker     *dockerapi.Client
	serviceSKA *scale.SelfKeepAlive

	// Guard the following.
Exemplo n.º 12
0
	"time"

	consulapi "github.com/hashicorp/consul/api"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/leverutil"
	"github.com/miekg/dns"
)

var (
	discoveryLogger = leverutil.GetLogger(PackageName, "discovery")
)

var (
	// DNSServerFlag is the DNS server address in format <ip>:<port>. Used for
	// service discovery.
	DNSServerFlag = config.DeclareString(
		PackageName, "dnsServer", "leverosconsul:8600")
)

// ErrServiceNotFound is an error that is returned when a service with provided
// name is not found.
var ErrServiceNotFound = fmt.Errorf("Service not found")

const (
	consulResourcePrefix       = "res/"
	consulConstrResourcePrefix = "constrres/"
)

// GetOwnNodeName returns the node name of the current node.
func GetOwnNodeName() (string, error) {
	consul := config.GetConsulClient()
	return consul.Agent().NodeName()
Exemplo n.º 13
0
package leverutil

import (
	"fmt"

	"github.com/Sirupsen/logrus"
	"github.com/leveros/leveros/config"
	prefixed "github.com/x-cray/logrus-prefixed-formatter"
)

var (
	// LoggingFormatFlag is the format of log lines.
	LoggingFormatFlag = config.DeclareString(
		PackageName, "loggingFormat", "colortext")
	// LoggingLevelFlag is the minimum level to log.
	LoggingLevelFlag = config.DeclareString(
		PackageName, "loggingLevel", "info")
	// LogInstanceAndServiceFlag causes all loggers to also log the instance ID
	// and service name of the process. Useful if logs from multiple sources
	// are merged and need to be filtered afterwards.
	LogInstanceAndServiceFlag = config.DeclareBool(
		PackageName, "logInstanceAndService")
)

// UpdateLoggingSettings initializes logging based on config params.
func UpdateLoggingSettings() {
	format := LoggingFormatFlag.Get()
	switch format {
	case "colortext":
		logrus.SetFormatter(&prefixed.TextFormatter{
			ShortTimestamp: true,