mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
HA: Fix MySQL formatting
This commit is contained in:
parent
3c3d2230ca
commit
51bc6c2ea8
2 changed files with 18 additions and 9 deletions
12
ha/ha.go
12
ha/ha.go
|
|
@ -65,7 +65,8 @@ var mysqlObservers = struct {
|
|||
}
|
||||
|
||||
func (h *HA) updateOwnInstance(env *Environment) error {
|
||||
_, err := h.super.Dbw.SqlExec(mysqlObservers.updateIcingadbInstanceById,
|
||||
_, err := h.super.Dbw.SqlExec(
|
||||
mysqlObservers.updateIcingadbInstanceById,
|
||||
"UPDATE icingadb_instance SET endpoint_id = ?, heartbeat = ?,"+
|
||||
" icinga2_version = ?, icinga2_start_time = ? WHERE id = ?",
|
||||
env.Icinga2.EndpointId, h.lastHeartbeat, env.Icinga2.Version,
|
||||
|
|
@ -74,7 +75,8 @@ func (h *HA) updateOwnInstance(env *Environment) error {
|
|||
}
|
||||
|
||||
func (h *HA) takeOverInstance(env *Environment) error {
|
||||
_, err := h.super.Dbw.SqlExec(mysqlObservers.updateIcingadbInstanceByEnvironmentId,
|
||||
_, err := h.super.Dbw.SqlExec(
|
||||
mysqlObservers.updateIcingadbInstanceByEnvironmentId,
|
||||
"UPDATE icingadb_instance SET id = ?, endpoint_id = ?, heartbeat = ?,"+
|
||||
" icinga2_version = ?, icinga2_start_time = ? WHERE environment_id = ?",
|
||||
h.uid[:], env.Icinga2.EndpointId, h.lastHeartbeat, env.Icinga2.Version,
|
||||
|
|
@ -83,7 +85,8 @@ func (h *HA) takeOverInstance(env *Environment) error {
|
|||
}
|
||||
|
||||
func (h *HA) insertInstance(env *Environment) error {
|
||||
_, err := h.super.Dbw.SqlExec(mysqlObservers.insertIntoIcingadbInstance,
|
||||
_, err := h.super.Dbw.SqlExec(
|
||||
mysqlObservers.insertIntoIcingadbInstance,
|
||||
"INSERT INTO icingadb_instance(id, environment_id, endpoint_id, heartbeat, responsible,"+
|
||||
" icinga2_version, icinga2_start_time) VALUES (?, ?, ?, ?, 'y', ?, ?)",
|
||||
h.uid[:], h.super.EnvId, env.Icinga2.EndpointId,
|
||||
|
|
@ -92,7 +95,8 @@ func (h *HA) insertInstance(env *Environment) error {
|
|||
}
|
||||
|
||||
func (h *HA) getInstance() (bool, uuid.UUID, int64, error) {
|
||||
rows, err := h.super.Dbw.SqlFetchAll(mysqlObservers.selectIdHeartbeatFromIcingadbInstanceByEnvironmentId,
|
||||
rows, err := h.super.Dbw.SqlFetchAll(
|
||||
mysqlObservers.selectIdHeartbeatFromIcingadbInstanceByEnvironmentId,
|
||||
"SELECT id, heartbeat from icingadb_instance where environment_id = ? LIMIT 1",
|
||||
h.super.EnvId,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ func TestHA_InsertInstance(t *testing.T) {
|
|||
err := ha.insertInstance(&Environment{})
|
||||
require.NoError(t, err, "insertInstance should not return an error")
|
||||
|
||||
rows, err := ha.super.Dbw.SqlFetchAll(mysqlObservers.selectIdHeartbeatFromIcingadbInstanceByEnvironmentId,
|
||||
rows, err := ha.super.Dbw.SqlFetchAll(
|
||||
mysqlObservers.selectIdHeartbeatFromIcingadbInstanceByEnvironmentId,
|
||||
"SELECT id, heartbeat from icingadb_instance where environment_id = ? LIMIT 1",
|
||||
ha.super.EnvId,
|
||||
)
|
||||
|
|
@ -81,9 +82,11 @@ func TestHA_checkResponsibility(t *testing.T) {
|
|||
_, err := ha.super.Dbw.SqlExec(mysqlTestObserver, "TRUNCATE TABLE icingadb_instance")
|
||||
require.NoError(t, err, "This test needs a working MySQL connection!")
|
||||
|
||||
_, err = ha.super.Dbw.SqlExec(mysqlObservers.insertIntoIcingadbInstance,
|
||||
_, err = ha.super.Dbw.SqlExec(
|
||||
mysqlObservers.insertIntoIcingadbInstance,
|
||||
"INSERT INTO icingadb_instance(id, environment_id, heartbeat, responsible, icinga2_version, icinga2_start_time) VALUES (?, ?, ?, 'y', '', 0)",
|
||||
ha.uid[:], ha.super.EnvId, 0)
|
||||
ha.uid[:], ha.super.EnvId, 0,
|
||||
)
|
||||
|
||||
require.NoError(t, err, "This test needs a working MySQL connection!")
|
||||
|
||||
|
|
@ -95,9 +98,11 @@ func TestHA_checkResponsibility(t *testing.T) {
|
|||
_, err = ha.super.Dbw.SqlExec(mysqlTestObserver, "TRUNCATE TABLE icingadb_instance")
|
||||
require.NoError(t, err, "This test needs a working MySQL connection!")
|
||||
|
||||
_, err = ha.super.Dbw.SqlExec(mysqlObservers.insertIntoIcingadbInstance,
|
||||
_, err = ha.super.Dbw.SqlExec(
|
||||
mysqlObservers.insertIntoIcingadbInstance,
|
||||
"INSERT INTO icingadb_instance(id, environment_id, heartbeat, responsible, icinga2_version, icinga2_start_time) VALUES (?, ?, ?, 'y', '', 0)",
|
||||
ha.uid[:], ha.super.EnvId, time.Now().Unix())
|
||||
ha.uid[:], ha.super.EnvId, time.Now().Unix(),
|
||||
)
|
||||
|
||||
ha.isActive = false
|
||||
ha.checkResponsibility(&Environment{})
|
||||
|
|
|
|||
Loading…
Reference in a new issue