From af1d0c71935f96da91d9bd15cfabc64ec8180e01 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Fri, 8 Mar 2019 10:35:03 +0100 Subject: [PATCH] Move host into host package & readd Row into configobject package --- configobject/configobject.go | 8 ++++++++ configobject/{ => host}/host.go | 15 +++++++++------ main.go | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) rename configobject/{ => host}/host.go (93%) diff --git a/configobject/configobject.go b/configobject/configobject.go index 279013d0..bc7a27b6 100644 --- a/configobject/configobject.go +++ b/configobject/configobject.go @@ -1,2 +1,10 @@ package configobject +type Row interface { + InsertValues() []interface{} + UpdateValues() []interface{} + GetId() string + SetId(id string) +} + +type RowFactory func() Row \ No newline at end of file diff --git a/configobject/host.go b/configobject/host/host.go similarity index 93% rename from configobject/host.go rename to configobject/host/host.go index e4c114cd..9b9289c7 100644 --- a/configobject/host.go +++ b/configobject/host/host.go @@ -1,9 +1,11 @@ -package configobject +package host import ( "git.icinga.com/icingadb/icingadb-json-decoder" + "git.icinga.com/icingadb/icingadb-main/configobject" "git.icinga.com/icingadb/icingadb-main/supervisor" "git.icinga.com/icingadb/icingadb-utils" + log "github.com/sirupsen/logrus" ) type Host struct { @@ -50,7 +52,7 @@ type Host struct { CommandEndpointId string `json:"command_endpoint_id"` } -func NewHost() icingadb_json_decoder.Row { +func NewHost() configobject.Row { h := Host{ EnvId: icingadb_utils.DecodeChecksum(icingadb_utils.Sha1("default")), CheckPeriod: "check_period", @@ -63,13 +65,13 @@ func NewHost() icingadb_json_decoder.Row { return &h } -func (h Host) InsertValues() []interface{} { +func (h *Host) InsertValues() []interface{} { v := h.UpdateValues() return append([]interface{}{icingadb_utils.Checksum(h.Id)}, v...) } -func (h Host) UpdateValues() []interface{} { +func (h *Host) UpdateValues() []interface{} { v := make([]interface{}, 0) v = append( @@ -119,11 +121,11 @@ func (h Host) UpdateValues() []interface{} { return v } -func (h Host) GetId() string { +func (h *Host) GetId() string { return h.Id } -func (h Host) SetId(id string) { +func (h *Host) SetId(id string) { h.Id = id } @@ -160,6 +162,7 @@ func HostOperator(super *supervisor.Supervisor) error { hosts[ret.Id] = ret.Row.(*Host) count-- if 0 == count { + log.Info("Hosts done") close(chBack) } } diff --git a/main.go b/main.go index 363dd5ef..05c753bf 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "git.icinga.com/icingadb/icingadb-connection" "git.icinga.com/icingadb/icingadb-ha" "git.icinga.com/icingadb/icingadb-json-decoder" - "git.icinga.com/icingadb/icingadb-main/configobject" + "git.icinga.com/icingadb/icingadb-main/configobject/host" "git.icinga.com/icingadb/icingadb-main/supervisor" "log" ) @@ -38,7 +38,7 @@ func main() { go icingadb_json_decoder.DecodePool(super.ChDecode, chErr, 16) go func() { - chErr <- configobject.HostOperator(&super) + chErr <- host.HostOperator(&super) }() for {