internal

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

* Copyright (C) 2016 VSCT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *

* Copyright (C) 2016 VSCT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *

* Copyright (C) 2016 VSCT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *

* Copyright (C) 2016 VSCT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *

Index

Constants

View Source
const (
	SUCCESS    int = iota // configuration application has succeed
	UNCHANGED  int = iota // configuration has not been changed
	ERR_SYSLOG int = iota // error during syslog configuration change
	ERR_CONF   int = iota // error with given configuration
	ERR_RELOAD int = iota // error during haproxy reload
	MAX_STATUS int = iota // technical status for enumerating status
)

status of applying a new configuration

Variables

View Source
var StoppedError = errors.New("Listener stopped")

Functions

func MockCommand

func MockCommand(name string, arg ...string) ([]byte, error)

func MockFailedCommand

func MockFailedCommand(name string, arg ...string) ([]byte, error)

func MockSignal

func MockSignal(pid int, signal os.Signal) error

func SyslogFields

func SyslogFields() log.Fields

Types

type AllFiles

type AllFiles struct {
	ConfigFile     string
	SyslogFile     string
	PidFile        string
	ConfigArchive  string
	Binary         string
	BinaryArchive  string
	Version        string
	VersionArchive string
}

type Application

type Application struct {
	Path     string
	Config   string
	Scripts  string
	Archives string
}

type Command

type Command func(name string, arg ...string) ([]byte, error)

type abstraction for exec.Command(...).Output()

type Commands

type Commands interface {
	Reader(path string, isPanic bool) ([]byte, error)
	Writer(path string, content []byte, perm os.FileMode, isPanic bool) error
	Renamer(oldpath, newpath string, isPanic bool) error
	Exists(path string) bool
	Linker(oldpath, newpath string, isPanic bool) error
	Remover(path string, isPanic bool) error
	ReadLinker(path string, isPanic bool) (string, error)
	MkdirAll(path string) error
	EvalSymLinks(path string) (string, error)
}

commands

type CompactFormatter

type CompactFormatter struct {
}

log formatter

func (*CompactFormatter) Format

func (f *CompactFormatter) Format(entry *log.Entry) ([]byte, error)

type Conf

type Conf struct {
	Haproxy []byte `json:"haproxy"`
	Syslog  []byte `json:"syslog"`
	Bind    string `json:"bind"`
	Version string `json:"haproxyVersion,omitempty"`
}

Conf providing in nsq message from admin

type Config

type Config struct {
	LookupdAddresses []string                   `toml:"LookupdAddresses"`
	ProducerAddr     string                     `toml:"ProducerAddr"`
	ProducerRestAddr string                     `toml:"ProducerRestAddr"`
	ClusterID        string                     `toml:"ClusterId"`
	Port             int32                      `toml:"Port"`
	HapHome          string                     `toml:"HapHome"`
	ID               string                     `toml:"Id"`
	Hap              map[string]HapInstallation `toml:"Hap"`
	Sudo             bool                       `toml:"Sudo"`
}

Config contains all sidekick configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig builds a default config

func (Config) IsMaster

func (config Config) IsMaster(vip string) (bool, error)

IsMaster answers true if vip points to current sidekick ip

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

type Consumers

type Consumers struct {
	// contains filtered or unexported fields
}

func NewConsumers

func NewConsumers(config Config, nsqConfig nsq.Config, sdkLogger SdkLogger) Consumers

func (Consumers) PutAndStartConsumer

func (consumers Consumers) PutAndStartConsumer(topic string, handler func(message *nsq.Message) error)

create nsq consumer for given topic and with given handler to consumers and store in this consumer store. if topic has already a consumer, it will be overriden by the new one.

func (Consumers) RestartConsumers

func (consumers Consumers) RestartConsumers()

stop all consumers and restart theim

type Context

type Context struct {
	CorrelationID string `json:"correlationId"`
	Timestamp     int64  `json:"timestamp"`
	Application   string `json:"application"`
	Platform      string `json:"platform"`
}

Context is for tracing current process and local processing

func (Context) Fields

func (ctx Context) Fields(fields log.Fields) *log.Entry

Fields for logging with context headers

func (Context) UpdateTimestamp

func (ctx Context) UpdateTimestamp() Context

UpdateTimestamp update the timestamp of the current context

type DrunkHaproxy

type DrunkHaproxy struct {
	// contains filtered or unexported fields
}

func (DrunkHaproxy) ApplyConfiguration

func (hap DrunkHaproxy) ApplyConfiguration(data *EventMessageWithConf) (int, error)

func (DrunkHaproxy) Delete

func (hap DrunkHaproxy) Delete() error

func (DrunkHaproxy) Fake

func (hap DrunkHaproxy) Fake() bool

func (DrunkHaproxy) RestartKilledHaproxy

func (hap DrunkHaproxy) RestartKilledHaproxy() error

func (DrunkHaproxy) Stop

func (hap DrunkHaproxy) Stop() error

type Dumper

type Dumper func(context Context, filename string, newConf []byte)

type abstraction for dumping content to a file

type EventHandler

type EventHandler interface {
	HandleMessage(data *EventMessageWithConf) error
}

EventHandler handler on EventMessageWithConf

type EventMessage

type EventMessage struct {
	Header Header `json:"header"`
}

EventMessage is main type for messages

func (EventMessage) Clone

func (eventMessage EventMessage) Clone(source string) EventMessage

Clone is method for cloning an EventMessage with just the header, a new source and a new timestamp

func (EventMessage) Context

func (eventMessage EventMessage) Context() Context

Context is a method for retrieving Context from an EventMessage

type EventMessageWithConf

type EventMessageWithConf struct {
	EventMessage
	Conf Conf `json:"conf,omitempty"`
}

EventMessageWithConf type of messages with Conf type additionally

func (EventMessageWithConf) CloneWithConf

func (eventMessage EventMessageWithConf) CloneWithConf(source string) EventMessageWithConf

CloneWithConf clones an EventMessage with he header, a new source and a new timestamp and the conf

type Filesystem

type Filesystem struct {
	Home        string
	Application Application
	Platform    Platform
	Syslog      SyslogDir
	Commands    Commands
	Files       AllFiles
}

func NewFilesystem

func NewFilesystem(home, application, platform string) Filesystem

create a new filesystem based on user home, application and platform

func (*Filesystem) Mkdirs

func (fs *Filesystem) Mkdirs(context Context)

create all given directories

type HandlerFunc

type HandlerFunc func(data *EventMessageWithConf) error

HandlerFunc type

func (HandlerFunc) HandleMessage

func (h HandlerFunc) HandleMessage(m *EventMessageWithConf) error

HandleMessage handles EventMessageWithConf

type HapInstallation

type HapInstallation struct {
	Path string
}

HapInstallation contains path to haproxy binary

type Haproxy

type Haproxy struct {
	Config     *Config    // nsqConfig of sidekick
	Context    *Context   // context of this haproxy (current application/platform/correlationid etc...)
	Filesystem Filesystem // filesystem with haproxy configuration files
	Command    Command    // wrapping os command execution
	Dumper     Dumper     // wrapping for dumping contents on files
	Signal     Signal     // signal abstraction for sending signal
}

Haproxy manager for a given Application/Platform

func NewHaproxy

func NewHaproxy(config *Config, context *Context) *Haproxy

create a new haproxy

func (*Haproxy) ApplyConfiguration

func (hap *Haproxy) ApplyConfiguration(event *EventMessageWithConf) (status int, err error)

ApplyConfiguration write the new configuration and reload A rollback is called on failure

func (*Haproxy) Delete

func (hap *Haproxy) Delete() error

delete configuration files

func (Haproxy) Fake

func (hap Haproxy) Fake() bool

func (*Haproxy) RestartKilledHaproxy

func (hap *Haproxy) RestartKilledHaproxy() error

func (*Haproxy) Stop

func (hap *Haproxy) Stop() error

stop haproxy process

type Header struct {
	CorrelationID string `json:"correlationId"`
	Application   string `json:"application"`
	Platform      string `json:"platform"`
	Timestamp     int64  `json:"timestamp"`
	Source        string `json:"source"`
}

Header of nsq message

type Loadbalancer

type Loadbalancer interface {
	ApplyConfiguration(data *EventMessageWithConf) (int, error)
	Stop() error
	Delete() error
	Fake() bool
	RestartKilledHaproxy() error
}

type LoadbalancerFactory

type LoadbalancerFactory struct {
	Fake       string
	Properties *Config
}

func NewLoadbalancerFactory

func NewLoadbalancerFactory() *LoadbalancerFactory

func (*LoadbalancerFactory) CreateHaproxy

func (factory *LoadbalancerFactory) CreateHaproxy(context Context) Loadbalancer

type MockCommands

type MockCommands struct{}

func (MockCommands) CheckerAbsent

func (mc MockCommands) CheckerAbsent(newVersion string, isPanic bool) bool
func (mc MockCommands) EvalSymLinks(path string) (string, error)

func (MockCommands) Exists

func (mc MockCommands) Exists(path string) bool

func (MockCommands) Linker

func (mc MockCommands) Linker(origin, destination string, isPanic bool) error

func (MockCommands) MkdirAll

func (mc MockCommands) MkdirAll(directory string) error

func (MockCommands) ReadLinker

func (mc MockCommands) ReadLinker(link string, isPanic bool) (string, error)

func (MockCommands) Reader

func (mc MockCommands) Reader(path string, isPanic bool) ([]byte, error)

func (MockCommands) ReaderEmpty

func (mc MockCommands) ReaderEmpty(path string) ([]byte, error)

func (MockCommands) Remover

func (mc MockCommands) Remover(path string, isPanic bool) error

func (MockCommands) Renamer

func (mc MockCommands) Renamer(oldPath, newPath string, isPanic bool) error

func (MockCommands) Writer

func (mc MockCommands) Writer(path string, content []byte, perm os.FileMode, isPanic bool) error

type OsCommands

type OsCommands struct {
}

os implementation

func (osCmd OsCommands) EvalSymLinks(path string) (string, error)

func (OsCommands) Exists

func (osCmd OsCommands) Exists(path string) bool

func (OsCommands) Linker

func (osCmd OsCommands) Linker(oldpath, newpath string, isPanic bool) error

func (OsCommands) MkdirAll

func (osCmd OsCommands) MkdirAll(path string) error

func (OsCommands) ReadLinker

func (osCmd OsCommands) ReadLinker(path string, isPanic bool) (string, error)

func (OsCommands) Reader

func (osCmd OsCommands) Reader(path string, isPanic bool) ([]byte, error)

func (OsCommands) Remover

func (osCmd OsCommands) Remover(path string, isPanic bool) (err error)

func (OsCommands) Renamer

func (osCmd OsCommands) Renamer(oldpath, newpath string, isPanic bool) error

func (OsCommands) Writer

func (osCmd OsCommands) Writer(path string, content []byte, perm os.FileMode, isPanic bool) error

type Platform

type Platform struct {
	Path   string
	Logs   string
	Errors string
	Dump   string
}

type ReloadEvent

type ReloadEvent struct {
	Message *EventMessageWithConf
	F       func(data *EventMessageWithConf) error
}

ReloadEvent is focus on reload event

func (*ReloadEvent) Execute

func (re *ReloadEvent) Execute() error

Execute execute ReloadEvent

type RestApi

type RestApi struct {
	// contains filtered or unexported fields
}

func NewRestApi

func NewRestApi(properties *Config, consumers Consumers) *RestApi

func (*RestApi) Start

func (api *RestApi) Start() error

func (*RestApi) Stop

func (api *RestApi) Stop()

type SdkLogger

type SdkLogger struct {
	Logrus *log.Logger
}

SdkLogger logger type

func (SdkLogger) Output

func (sdkLogger SdkLogger) Output(calldepth int, s string) error

Output just calls a log

type Signal

type Signal func(pid int, signal os.Signal) error

type abstraction for os.Signal

type StoppableListener

type StoppableListener struct {
	*net.TCPListener          //Wrapped listener
	StopChan         chan int //Channel used only to indicate listener should shutdown
}

func NewListener

func NewListener(l net.Listener) (*StoppableListener, error)

func (*StoppableListener) Accept

func (sl *StoppableListener) Accept() (net.Conn, error)

func (*StoppableListener) Stop

func (sl *StoppableListener) Stop()

type Syslog

type Syslog struct {
	// contains filtered or unexported fields
}

func NewSyslog

func NewSyslog(properties *Config) *Syslog

func (*Syslog) Restart

func (syslog *Syslog) Restart() error

restart calls external shell script to reload syslog It returns error if the reload fails

type SyslogDir

type SyslogDir struct {
	Path   string
	Config string
	Logs   string
}

type TestContext

type TestContext struct {
	Links     map[string]string
	Renames   map[string]string
	Removed   []string
	Command   string
	Signal    os.Signal
	Writes    map[string]string
	PidExists bool
}

type YesmanHaproxy

type YesmanHaproxy struct {
	// contains filtered or unexported fields
}

YesmanHaproxy is an haproxy fake process which always return yes

func (YesmanHaproxy) ApplyConfiguration

func (hap YesmanHaproxy) ApplyConfiguration(data *EventMessageWithConf) (int, error)

ApplyConfiguration always successes

func (YesmanHaproxy) Delete

func (hap YesmanHaproxy) Delete() error

Delete this fake haproxy

func (YesmanHaproxy) Fake

func (hap YesmanHaproxy) Fake() bool

Fake return true

func (YesmanHaproxy) RestartKilledHaproxy

func (hap YesmanHaproxy) RestartKilledHaproxy() error

RestartKilledHaproxy restart a fake yesman haproxy

func (YesmanHaproxy) Stop

func (hap YesmanHaproxy) Stop() error

Stop this fake haproxy

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL