-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.go
125 lines (113 loc) · 3 KB
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* lvcl is a simple program clustering libvirt servers
* Copyright (C) 2020 Adam Prycki (email: [email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package main
import "fmt"
import "time"
//import "json"
const(
msgModCore=iota
msgModLoggr
msgModExchn
msgModBrain
msgModExchnHeartbeat
msgModBrainController
msgModClient
msgModConfig
rpcHeartbeat
brainRpcElectNominate
brainRpcElectAsk
brainRpcAskForMasterNode
brainRpcHaveMasterNodeReply
brainRpcHaveMasterNodeReplyNil
brainRpcSendingStats
brianRpcSendingClusterResources
brianMasterSendUpdatedResources
exchangeAskAboutClientNode
exchangeNotifyAboutClient
exchangeNotifyClientDisconnect
exchangeSendClientID
exchangeClientDisconnected
clientAskAboutStatus
clientAskAboutStatusReply
clientListenToClusterLogger
loggerForwardMessageToClient
loggerForwardMessageToClientStop
clientPrintText
clientPrintTextLogger
clientPrintTextStatus
clientAskResStateChange
clientAskResStateChangeReply
confUpdateResState
confNotifAboutEpoch
confNotifAboutEpochUpdate
confNotifAboutEpochUpdateAsk
brainNotifyAboutEpoch
brainNotifyAboutEpochUpdate
brainNotifyAboutEpochUpdateAsk
brainNotifyMasterAboutResourceFailure
brainNotifyMasterAboutLocalResources
brainNotifyAboutNewClusterEvent
)
type message struct{
SrcHost string
DestHost string
SrcMod uint
DestMod uint
ConfHash string
Time time.Time
RpcFunc uint
Argv []string
Epoch uint64
Cres []Cluster_resource
Custom1 interface{}
Custom2 interface{}
Custom3 interface{}
}
func (pm *message)dump(){
fmt.Printf("%+v \n", *pm)}
/* TODO replace with something faster */
/* TODO ADD LOGGER LOGGING */
//func (pm *message)validate() bool {
func Newmessage() *message {
var m message
m.SrcHost=config.MyHostname
return &m}
func (m *message)setStr(s *string){
m.Argv=append(m.Argv,*s)}
func (m *message)heartbeatGetTime() *time.Time {
t,err := time.Parse(config.HeartbeatTimeFormat, m.Argv[0])
if err != nil {
lg.err("heartbeatGetTime time.Parse error", err)}
return &t}
func (m *message)destMod_src() string {
switch m.DestMod {
case msgModCore:
return "Core"
case msgModLoggr:
return "logger"
case msgModExchn:
return "Exchange"
case msgModBrain:
return "Brain"
case msgModClient:
return "Client"
case msgModConfig:
return "Config"
default:
return "error"}}