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
- Variables
- func MockCommand(name string, arg ...string) ([]byte, error)
- func MockFailedCommand(name string, arg ...string) ([]byte, error)
- func MockSignal(pid int, signal os.Signal) error
- func SyslogFields() log.Fields
- type AllFiles
- type Application
- type Command
- type Commands
- type CompactFormatter
- type Conf
- type Config
- type Consumer
- type Consumers
- type Context
- type DrunkHaproxy
- type Dumper
- type EventHandler
- type EventMessage
- type EventMessageWithConf
- type Filesystem
- type HandlerFunc
- type HapInstallation
- type Haproxy
- type Header
- type Loadbalancer
- type LoadbalancerFactory
- type MockCommands
- func (mc MockCommands) CheckerAbsent(newVersion string, isPanic bool) bool
- func (mc MockCommands) EvalSymLinks(path string) (string, error)
- func (mc MockCommands) Exists(path string) bool
- func (mc MockCommands) Linker(origin, destination string, isPanic bool) error
- func (mc MockCommands) MkdirAll(directory string) error
- func (mc MockCommands) ReadLinker(link string, isPanic bool) (string, error)
- func (mc MockCommands) Reader(path string, isPanic bool) ([]byte, error)
- func (mc MockCommands) ReaderEmpty(path string) ([]byte, error)
- func (mc MockCommands) Remover(path string, isPanic bool) error
- func (mc MockCommands) Renamer(oldPath, newPath string, isPanic bool) error
- func (mc MockCommands) Writer(path string, content []byte, perm os.FileMode, isPanic bool) error
- type OsCommands
- func (osCmd OsCommands) EvalSymLinks(path string) (string, error)
- func (osCmd OsCommands) Exists(path string) bool
- func (osCmd OsCommands) Linker(oldpath, newpath string, isPanic bool) error
- func (osCmd OsCommands) MkdirAll(path string) error
- func (osCmd OsCommands) ReadLinker(path string, isPanic bool) (string, error)
- func (osCmd OsCommands) Reader(path string, isPanic bool) ([]byte, error)
- func (osCmd OsCommands) Remover(path string, isPanic bool) (err error)
- func (osCmd OsCommands) Renamer(oldpath, newpath string, isPanic bool) error
- func (osCmd OsCommands) Writer(path string, content []byte, perm os.FileMode, isPanic bool) error
- type Platform
- type ReloadEvent
- type RestApi
- type SdkLogger
- type Signal
- type StoppableListener
- type Syslog
- type SyslogDir
- type TestContext
- type YesmanHaproxy
Constants ¶
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 ¶
var StoppedError = errors.New("Listener stopped")
Functions ¶
func SyslogFields ¶
Types ¶
type Application ¶
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 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
type Consumers ¶
type Consumers struct {
// contains filtered or unexported fields
}
func NewConsumers ¶
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) UpdateTimestamp ¶
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 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 (*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) RestartKilledHaproxy ¶
type Header ¶
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 LoadbalancerFactory ¶
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 (MockCommands) EvalSymLinks ¶
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)
type OsCommands ¶
type OsCommands struct { }
os implementation
func (OsCommands) EvalSymLinks ¶
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)
type ReloadEvent ¶
type ReloadEvent struct { Message *EventMessageWithConf F func(data *EventMessageWithConf) error }
ReloadEvent is focus on reload event
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) Stop ¶
func (sl *StoppableListener) Stop()
type TestContext ¶
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) RestartKilledHaproxy ¶
func (hap YesmanHaproxy) RestartKilledHaproxy() error
RestartKilledHaproxy restart a fake yesman haproxy