-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgetlog.go
executable file
·362 lines (333 loc) · 11.9 KB
/
getlog.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/**
* Copyright 2013-2016 Seagate Technology LLC.
*
* This Source Code Form is subject to the terms of the Mozilla
* Public License, v. 2.0. If a copy of the MPL was not
* distributed with this file, You can obtain one at
* https://mozilla.org/MP:/2.0/.
*
* This program is distributed in the hope that it will be useful,
* but is provided AS-IS, WITHOUT ANY WARRANTY; including without
* the implied warranty of MERCHANTABILITY, NON-INFRINGEMENT or
* FITNESS FOR A PARTICULAR PURPOSE. See the Mozilla Public
* License for more details.
*
* See www.openkinetic.org for more project information
*/
package kinetic
import (
kproto "github.com/Kinetic/kinetic-go/proto"
)
// LogType defines what type of information to retrieve by GetLog.
type LogType int32
// LogType values
const (
_ LogType = iota
LogTypeUtilizations LogType = iota
LogTypeTemperatures LogType = iota
LogTypeCapacities LogType = iota
LogTypeConfiguration LogType = iota
LogTypeStatistics LogType = iota
LogTypeMessages LogType = iota
LogTypeLimits LogType = iota
LogTypeDevice LogType = iota
)
var strLogType = map[LogType]string{
LogTypeUtilizations: "LOG_UTILIZATIONS",
LogTypeTemperatures: "LOG_TEMPERATURES",
LogTypeCapacities: "LOG_CAPACITIES",
LogTypeConfiguration: "LOG_CONFIGURATION",
LogTypeStatistics: "LOG_STATISTICS",
LogTypeMessages: "LOG_MESSAGES",
LogTypeLimits: "LOG_LIMITS",
LogTypeDevice: "LOG_DEVICE",
}
func (l LogType) String() string {
str, ok := strLogType[l]
if ok {
return str
}
return "Unknown LogType"
}
func convertLogTypeToProto(l LogType) kproto.Command_GetLog_Type {
ret := kproto.Command_GetLog_INVALID_TYPE
switch l {
case LogTypeUtilizations:
ret = kproto.Command_GetLog_UTILIZATIONS
case LogTypeTemperatures:
ret = kproto.Command_GetLog_TEMPERATURES
case LogTypeCapacities:
ret = kproto.Command_GetLog_CAPACITIES
case LogTypeConfiguration:
ret = kproto.Command_GetLog_CONFIGURATION
case LogTypeStatistics:
ret = kproto.Command_GetLog_STATISTICS
case LogTypeMessages:
ret = kproto.Command_GetLog_MESSAGES
case LogTypeLimits:
ret = kproto.Command_GetLog_LIMITS
case LogTypeDevice:
ret = kproto.Command_GetLog_DEVICE
}
return ret
}
func convertLogTypeFromProto(l kproto.Command_GetLog_Type) LogType {
var ret LogType
switch l {
case kproto.Command_GetLog_UTILIZATIONS:
ret = LogTypeUtilizations
case kproto.Command_GetLog_TEMPERATURES:
ret = LogTypeTemperatures
case kproto.Command_GetLog_CAPACITIES:
ret = LogTypeCapacities
case kproto.Command_GetLog_CONFIGURATION:
ret = LogTypeConfiguration
case kproto.Command_GetLog_STATISTICS:
ret = LogTypeStatistics
case kproto.Command_GetLog_MESSAGES:
ret = LogTypeMessages
case kproto.Command_GetLog_LIMITS:
ret = LogTypeLimits
case kproto.Command_GetLog_DEVICE:
ret = LogTypeDevice
}
return ret
}
// UtilizationLog for kinetic device utilization information.
type UtilizationLog struct {
Name string // Name of the device utlity
Value float32 // Value of device utility
}
// TemperatureLog for kinetic device tempture.
type TemperatureLog struct {
Name string // Name of the device
Current float32 // Current Temperature
Minimum float32 // Minimum Temperature for drive
Maximum float32 // Maximum Tempture for drive
Target float32 // Target Temperature for drive
}
// CapacityLog for kinetic device capacity information.
type CapacityLog struct {
CapacityInBytes uint64 // total capacity of hard disk, in bytes
PortionFull float32 // remaining capacity of hard disk
}
// ConfigurationInterface for kinetic device network interfaces information.
type ConfigurationInterface struct {
Name string // network device name
MAC []byte // network device mac address
Ipv4Addr []byte // network device ipv4 address
Ipv6Addr []byte // network device ipv6 address
}
// ConfigurationLog for kinetic device configuration information.
type ConfigurationLog struct {
Vendor string // Vendor name
Model string // Device model
SerialNumber []byte // Device serial number
WorldWideName []byte // Device world wide name
Version string // Device version
CompilationDate string // Device service code compilation date
SourceHash string // Device service source code repository hash value
ProtocolVersion string // Device supported protocol version
ProtocolCompilationDate string // Device supported protocol compilation date
ProtocolSourceHash string // Device supported protocol source code repository hash value
Interface []ConfigurationInterface // Device interfaces as list
Port int32 // Service port
TLSPort int32 // TLS service port
CurrentPowerLevel PowerLevel // Device current power level, valid value only POWER_HIBERNATE or POWER_OPERATIONAL
}
// StatisticsLog information for each type of MessageType.
// Count is total number of Type message processed.
// Bytes is the sum of the data that is in the data portion.
// This does not include the command description.
// For P2P operations, this is the amount of data moved between drives
type StatisticsLog struct {
// TODO: Would it better just use the protocol Command_MessageType?
Type MessageType
Count uint64
Bytes uint64
}
// LimitsLog defines max values.
type LimitsLog struct {
MaxKeySize uint32 // max key size
MaxValueSize uint32 // max value size
MaxVersionSize uint32 // max version size
MaxTagSize uint32 // max tag size
MaxConnections uint32 // max connection
MaxOutstandingReadRequests uint32 // max out standing read request
MaxOutstandingWriteRequests uint32 // max out standing write request
MaxMessageSize uint32 // max message size
MaxKeyRangeCount uint32 // max key range count
MaxIdentityCount uint32 // max identity count
MaxPinSize uint32 //
MaxOperationCountPerBatch uint32 //
MaxBatchCountPerDevice uint32 //
}
// DeviceLog is to ask the device to send back the
// log of a certain name in the value field. The limit of each
// log is 1m byte.
//
// Proprietary names should be prefaced by the vendor name so that name
// collisions do not happen in the future. An example could be names that
// start with “com.WD” would be for Western Digital devices.
//
// If the name is not found, the get log returns NOT_FOUND.
//
// There can be only one Device in the list of logs that can be retrieved.!
type DeviceLog struct {
Name []byte
}
// Log is the top level structure that groups all the log information
type Log struct {
Utilizations []UtilizationLog // List of utilization information of the drive
Temperatures []TemperatureLog // List of tempeture inforamtion of the drive
Capacity *CapacityLog // Capacity information of the drive
Configuration *ConfigurationLog // Configuration information of the drive
Statistics []StatisticsLog // List of statistic information from the drive
Messages []byte // Kinetic log messages from the drive
Limits *LimitsLog // Limits information from the drive
Device *DeviceLog
}
func getUtilizationLogFromProto(getlog *kproto.Command_GetLog) (log []UtilizationLog) {
log = nil
utils := getlog.GetUtilizations()
if utils != nil {
log = make([]UtilizationLog, len(utils))
for k, v := range utils {
log[k] = UtilizationLog{
Name: v.GetName(),
Value: v.GetValue(),
}
}
}
return
}
func getTemperatureLogFromProto(getlog *kproto.Command_GetLog) (log []TemperatureLog) {
log = nil
temps := getlog.GetTemperatures()
if temps != nil {
log = make([]TemperatureLog, len(temps))
for k, v := range temps {
log[k] = TemperatureLog{
Name: v.GetName(),
Current: v.GetCurrent(),
Minimum: v.GetMinimum(),
Maximum: v.GetMaximum(),
Target: v.GetTarget(),
}
}
}
return
}
func getCapacityLogFromProto(getlog *kproto.Command_GetLog) (log *CapacityLog) {
log = nil
capacity := getlog.GetCapacity()
if capacity != nil {
log = &CapacityLog{
CapacityInBytes: capacity.GetNominalCapacityInBytes(),
PortionFull: capacity.GetPortionFull(),
}
}
return
}
func getConfigurationInterfaceFromProto(conf *kproto.Command_GetLog_Configuration) (inf []ConfigurationInterface) {
inf = nil
pinf := conf.GetInterface()
if pinf != nil {
inf = make([]ConfigurationInterface, len(pinf))
for k, v := range pinf {
inf[k] = ConfigurationInterface{
Name: v.GetName(),
MAC: v.GetMAC(),
Ipv4Addr: v.GetIpv4Address(),
Ipv6Addr: v.GetIpv6Address(),
}
}
}
return
}
func getConfigurationLogFromProto(getlog *kproto.Command_GetLog) (log *ConfigurationLog) {
log = nil
conf := getlog.GetConfiguration()
if conf != nil {
log = &ConfigurationLog{
Vendor: conf.GetVendor(),
Model: conf.GetModel(),
SerialNumber: conf.GetSerialNumber(),
WorldWideName: conf.GetWorldWideName(),
Version: conf.GetVersion(),
CompilationDate: conf.GetCompilationDate(),
SourceHash: conf.GetSourceHash(),
ProtocolVersion: conf.GetProtocolVersion(),
ProtocolCompilationDate: conf.GetProtocolCompilationDate(),
ProtocolSourceHash: conf.GetProtocolSourceHash(),
Interface: getConfigurationInterfaceFromProto(conf),
Port: conf.GetPort(),
TLSPort: conf.GetTlsPort(),
CurrentPowerLevel: convertPowerLevelFromProto(conf.GetCurrentPowerLevel()),
}
}
return
}
func getStatisticsLogFromProto(getlog *kproto.Command_GetLog) (log []StatisticsLog) {
log = nil
statics := getlog.GetStatistics()
if statics != nil {
log := make([]StatisticsLog, len(statics))
for k, v := range statics {
log[k] = StatisticsLog{
Type: convertMessageTypeFromProto(v.GetMessageType()),
Count: v.GetCount(),
Bytes: v.GetBytes(),
}
}
}
return
}
func getLogMessageFromProto(getlog *kproto.Command_GetLog) []byte {
return getlog.GetMessages()
}
func getLimitsLogFromProto(getlog *kproto.Command_GetLog) (log *LimitsLog) {
log = nil
limits := getlog.GetLimits()
if limits != nil {
log = &LimitsLog{
MaxKeySize: limits.GetMaxKeySize(),
MaxValueSize: limits.GetMaxValueSize(),
MaxVersionSize: limits.GetMaxVersionSize(),
MaxTagSize: limits.GetMaxTagSize(),
MaxConnections: limits.GetMaxConnections(),
MaxOutstandingReadRequests: limits.GetMaxOutstandingReadRequests(),
MaxOutstandingWriteRequests: limits.GetMaxOutstandingWriteRequests(),
MaxMessageSize: limits.GetMaxMessageSize(),
MaxKeyRangeCount: limits.GetMaxKeyRangeCount(),
MaxIdentityCount: limits.GetMaxIdentityCount(),
MaxPinSize: limits.GetMaxPinSize(),
MaxOperationCountPerBatch: limits.GetMaxOperationCountPerBatch(),
MaxBatchCountPerDevice: limits.GetMaxBatchCountPerDevice(),
}
}
return
}
func getDeviceLogFromProto(getlog *kproto.Command_GetLog) *DeviceLog {
//TODO: Need more details
return &DeviceLog{
Name: getlog.GetDevice().GetName(),
}
}
func getLogFromProto(resp *kproto.Command) Log {
var logs Log
getlog := resp.GetBody().GetGetLog()
if getlog != nil {
logs = Log{
Utilizations: getUtilizationLogFromProto(getlog),
Temperatures: getTemperatureLogFromProto(getlog),
Capacity: getCapacityLogFromProto(getlog),
Configuration: getConfigurationLogFromProto(getlog),
Statistics: getStatisticsLogFromProto(getlog),
Messages: getLogMessageFromProto(getlog),
Limits: getLimitsLogFromProto(getlog),
Device: getDeviceLogFromProto(getlog),
}
}
return logs
}