Loading blockconnection.go +13 −13 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ func NewBlockConnection(op ClientOptions) (*BlockConnection, error) { func (conn *BlockConnection) NoOp() (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.NoOp(h) if err != nil { return callback.Status(), err Loading @@ -35,7 +35,7 @@ func (conn *BlockConnection) NoOp() (Status, error) { func (conn *BlockConnection) get(key []byte, getCmd kproto.Command_MessageType) (Record, Status, error) { callback := &GetCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) var err error = nil switch getCmd { Loading Loading @@ -71,7 +71,7 @@ func (conn *BlockConnection) GetPrevious(key []byte) (Record, Status, error) { func (conn *BlockConnection) GetKeyRange(r *KeyRange) ([][]byte, Status, error) { callback := &GetKeyRangeCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.GetKeyRange(r, h) if err != nil { return nil, callback.Status(), err Loading @@ -86,7 +86,7 @@ func (conn *BlockConnection) GetKeyRange(r *KeyRange) ([][]byte, Status, error) func (conn *BlockConnection) GetVersion(key []byte) ([]byte, Status, error) { callback := &GetVersionCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.GetVersion(key, h) if err != nil { return nil, callback.Status(), err Loading @@ -101,7 +101,7 @@ func (conn *BlockConnection) GetVersion(key []byte) ([]byte, Status, error) { func (conn *BlockConnection) Flush() (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.Flush(h) if err != nil { return callback.Status(), err Loading @@ -116,7 +116,7 @@ func (conn *BlockConnection) Flush() (Status, error) { func (conn *BlockConnection) Delete(entry *Record) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.Delete(entry, h) if err != nil { return callback.Status(), err Loading @@ -131,7 +131,7 @@ func (conn *BlockConnection) Delete(entry *Record) (Status, error) { func (conn *BlockConnection) Put(entry *Record) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.Put(entry, h) if err != nil { return callback.Status(), err Loading @@ -146,7 +146,7 @@ func (conn *BlockConnection) Put(entry *Record) (Status, error) { func (conn *BlockConnection) GetLog(logs []LogType) (Log, Status, error) { callback := &GetLogCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.GetLog(logs, h) if err != nil { return Log{}, callback.Status(), err Loading @@ -161,7 +161,7 @@ func (conn *BlockConnection) GetLog(logs []LogType) (Log, Status, error) { func (conn *BlockConnection) pinop(pin []byte, op kproto.Command_PinOperation_PinOpType) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) var err error = nil switch op { Loading Loading @@ -204,7 +204,7 @@ func (conn *BlockConnection) UnlockDevice(pin []byte) (Status, error) { func (conn *BlockConnection) UpdateFirmware(code []byte) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.UpdateFirmware(code, h) if err != nil { return callback.Status(), err Loading @@ -219,7 +219,7 @@ func (conn *BlockConnection) UpdateFirmware(code []byte) (Status, error) { func (conn *BlockConnection) SetClusterVersion(version int64) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.SetClusterVersion(version, h) if err != nil { return callback.Status(), err Loading @@ -234,7 +234,7 @@ func (conn *BlockConnection) SetClusterVersion(version int64) (Status, error) { func (conn *BlockConnection) SetLockPin(currentPin []byte, newPin []byte) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.SetLockPin(currentPin, newPin, h) if err != nil { return callback.Status(), err Loading @@ -249,7 +249,7 @@ func (conn *BlockConnection) SetLockPin(currentPin []byte, newPin []byte) (Statu func (conn *BlockConnection) SetErasePin(currentPin []byte, newPin []byte) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.SetErasePin(currentPin, newPin, h) if err != nil { return callback.Status(), err Loading getlog.go 0 → 100644 +322 −0 Original line number Diff line number Diff line package kinetic import ( kproto "github.com/yongzhy/kinetic-go/proto" ) type LogType int32 const ( _ LogType = iota LOG_UTILIZATIONS LogType = iota LOG_TEMPERATURES LogType = iota LOG_CAPACITIES LogType = iota LOG_CONFIGURATION LogType = iota LOG_STATISTICS LogType = iota LOG_MESSAGES LogType = iota LOG_LIMITS LogType = iota LOG_DEVICE LogType = iota ) var strLogType = map[LogType]string{ LOG_UTILIZATIONS: "LOG_UTILIZATIONS", LOG_TEMPERATURES: "LOG_TEMPERATURES", LOG_CAPACITIES: "LOG_CAPACITIES", LOG_CONFIGURATION: "LOG_CONFIGURATION", LOG_STATISTICS: "LOG_STATISTICS", LOG_MESSAGES: "LOG_MESSAGES", LOG_LIMITS: "LOG_LIMITS", LOG_DEVICE: "LOG_DEVICE", } func (l LogType) String() string { s, ok := strLogType[l] if ok { return s } return "Unknown LogType" } func convertLogTypeToProto(l LogType) kproto.Command_GetLog_Type { ret := kproto.Command_GetLog_INVALID_TYPE switch l { case LOG_UTILIZATIONS: ret = kproto.Command_GetLog_UTILIZATIONS case LOG_TEMPERATURES: ret = kproto.Command_GetLog_TEMPERATURES case LOG_CAPACITIES: ret = kproto.Command_GetLog_CAPACITIES case LOG_CONFIGURATION: ret = kproto.Command_GetLog_CONFIGURATION case LOG_STATISTICS: ret = kproto.Command_GetLog_STATISTICS case LOG_MESSAGES: ret = kproto.Command_GetLog_MESSAGES case LOG_LIMITS: ret = kproto.Command_GetLog_LIMITS case LOG_DEVICE: 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 = LOG_UTILIZATIONS case kproto.Command_GetLog_TEMPERATURES: ret = LOG_TEMPERATURES case kproto.Command_GetLog_CAPACITIES: ret = LOG_CAPACITIES case kproto.Command_GetLog_CONFIGURATION: ret = LOG_CONFIGURATION case kproto.Command_GetLog_STATISTICS: ret = LOG_STATISTICS case kproto.Command_GetLog_MESSAGES: ret = LOG_MESSAGES case kproto.Command_GetLog_LIMITS: ret = LOG_LIMITS case kproto.Command_GetLog_DEVICE: ret = LOG_DEVICE } return ret } type UtilizationLog struct { Name string Value float32 } type TemperatureLog struct { Name string Current float32 Minimum float32 Maximum float32 Target float32 } type CapacityLog struct { CapacityInBytes uint64 PortionFull float32 } type ConfigurationInterface struct { Name string MAC []byte Ipv4Addr []byte Ipv6Addr []byte } type ConfigurationLog struct { Vendor string Model string SerialNumber []byte WorldWideName []byte Version string CompilationDate string SourceHash string ProtocolVersion string ProtocolCompilationDate string ProtocolSourceHash string Interface []ConfigurationInterface Port int32 TlsPort int32 } type StatisticsLog struct { // TODO: Would it better just use the protocol Command_MessageType? Type MessageType Count uint64 Bytes uint64 } type LimitsLog struct { MaxKeySize uint32 MaxValueSize uint32 MaxVersionSize uint32 MaxTagSize uint32 MaxConnections uint32 MaxOutstandingReadRequests uint32 MaxOutstandingWriteRequests uint32 MaxMessageSize uint32 MaxKeyRangeCount uint32 MaxIdentityCount uint32 MaxPinSize uint32 MaxOperationCountPerBatch uint32 MaxBatchCountPerDevice uint32 } type DeviceLog struct { Name []byte } type Log struct { Utilizations []UtilizationLog Temperatures []TemperatureLog Capacity CapacityLog Configuration ConfigurationLog Statistics []StatisticsLog Messages []byte Limits LimitsLog Device DeviceLog } func getUtilizationLogFromProto(getlog *kproto.Command_GetLog) []UtilizationLog { utils := getlog.GetUtilizations() if utils != nil { ulog := make([]UtilizationLog, len(utils)) for k, v := range utils { ulog[k] = UtilizationLog{ Name: v.GetName(), Value: v.GetValue(), } } return ulog } else { return nil } } func getTemperatureLogFromProto(getlog *kproto.Command_GetLog) []TemperatureLog { temps := getlog.GetTemperatures() if temps != nil { templog := make([]TemperatureLog, len(temps)) for k, v := range temps { templog[k] = TemperatureLog{ Name: v.GetName(), Current: v.GetCurrent(), Minimum: v.GetMinimum(), Maximum: v.GetMaximum(), Target: v.GetTarget(), } } return templog } else { return nil } } func getCapacityLogFromProto(getlog *kproto.Command_GetLog) CapacityLog { var log CapacityLog capacity := getlog.GetCapacity() if capacity != nil { log = CapacityLog{ CapacityInBytes: capacity.GetNominalCapacityInBytes(), PortionFull: capacity.GetPortionFull(), } } return log } func getConfigurationInterfaceFromProto(conf *kproto.Command_GetLog_Configuration) []ConfigurationInterface { 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 inf } else { return nil } } func getConfigurationLogFromProto(getlog *kproto.Command_GetLog) ConfigurationLog { var log ConfigurationLog 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(), } } return log } func getStatisticsLogFromProto(getlog *kproto.Command_GetLog) []StatisticsLog { statics := getlog.GetStatistics() if statics != nil { slog := make([]StatisticsLog, len(statics)) for k, v := range statics { slog[k] = StatisticsLog{ Type: convertMessageTypeFromProto(v.GetMessageType()), Count: v.GetCount(), Bytes: v.GetBytes(), } } return slog } else { return nil } } func getLogMessageFromProto(getlog *kproto.Command_GetLog) []byte { return getlog.GetMessages() } func getLimitsLogFromProto(getlog *kproto.Command_GetLog) LimitsLog { var log LimitsLog 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 log } 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 } handler.go +6 −6 Original line number Diff line number Diff line Loading @@ -4,11 +4,11 @@ import ( kproto "github.com/yongzhy/kinetic-go/proto" ) type MessageHandler struct { type ResponseHandler struct { callback Callback } func (h *MessageHandler) Handle(cmd *kproto.Command, value []byte) error { func (h *ResponseHandler) Handle(cmd *kproto.Command, value []byte) error { klog.Info("Message handler called") if h.callback != nil { if cmd.Status != nil && cmd.Status.Code != nil { Loading @@ -26,17 +26,17 @@ func (h *MessageHandler) Handle(cmd *kproto.Command, value []byte) error { return nil } func (h *MessageHandler) Error(s Status) { func (h *ResponseHandler) Error(s Status) { if h.callback != nil { h.callback.Failure(s) } } func (h *MessageHandler) SetCallback(call Callback) { func (h *ResponseHandler) SetCallback(call Callback) { h.callback = call } func NewMessageHandler(call Callback) *MessageHandler { h := &MessageHandler{callback: call} func NewResponseHandler(call Callback) *ResponseHandler { h := &ResponseHandler{callback: call} return h } kinetic.go +101 −414 File changed.Preview size limit exceeded, changes collapsed. Show changes nonblockconnection.go +23 −23 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ func NewNonBlockConnection(op ClientOptions) (*NonBlockConnection, error) { return &NonBlockConnection{service}, nil } func (conn *NonBlockConnection) NoOp(h *MessageHandler) error { func (conn *NonBlockConnection) NoOp(h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_NOOP) Loading @@ -29,7 +29,7 @@ func (conn *NonBlockConnection) NoOp(h *MessageHandler) error { return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) get(key []byte, getType kproto.Command_MessageType, h *MessageHandler) error { func (conn *NonBlockConnection) get(key []byte, getType kproto.Command_MessageType, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(getType) Loading @@ -42,19 +42,19 @@ func (conn *NonBlockConnection) get(key []byte, getType kproto.Command_MessageTy return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) Get(key []byte, h *MessageHandler) error { func (conn *NonBlockConnection) Get(key []byte, h *ResponseHandler) error { return conn.get(key, kproto.Command_GET, h) } func (conn *NonBlockConnection) GetNext(key []byte, h *MessageHandler) error { func (conn *NonBlockConnection) GetNext(key []byte, h *ResponseHandler) error { return conn.get(key, kproto.Command_GETNEXT, h) } func (conn *NonBlockConnection) GetPrevious(key []byte, h *MessageHandler) error { func (conn *NonBlockConnection) GetPrevious(key []byte, h *ResponseHandler) error { return conn.get(key, kproto.Command_GETPREVIOUS, h) } func (conn *NonBlockConnection) GetKeyRange(r *KeyRange, h *MessageHandler) error { func (conn *NonBlockConnection) GetKeyRange(r *KeyRange, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_GETKEYRANGE) Loading @@ -72,7 +72,7 @@ func (conn *NonBlockConnection) GetKeyRange(r *KeyRange, h *MessageHandler) erro return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) GetVersion(key []byte, h *MessageHandler) error { func (conn *NonBlockConnection) GetVersion(key []byte, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_GETVERSION) Loading @@ -85,7 +85,7 @@ func (conn *NonBlockConnection) GetVersion(key []byte, h *MessageHandler) error return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) Flush(h *MessageHandler) error { func (conn *NonBlockConnection) Flush(h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_FLUSHALLDATA) Loading @@ -93,7 +93,7 @@ func (conn *NonBlockConnection) Flush(h *MessageHandler) error { return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) Delete(entry *Record, h *MessageHandler) error { func (conn *NonBlockConnection) Delete(entry *Record, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_DELETE) Loading @@ -111,7 +111,7 @@ func (conn *NonBlockConnection) Delete(entry *Record, h *MessageHandler) error { return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) Put(entry *Record, h *MessageHandler) error { func (conn *NonBlockConnection) Put(entry *Record, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_PUT) Loading @@ -130,7 +130,7 @@ func (conn *NonBlockConnection) Put(entry *Record, h *MessageHandler) error { return conn.service.submit(msg, cmd, entry.Value, h) } func (conn *NonBlockConnection) GetLog(logs []LogType, h *MessageHandler) error { func (conn *NonBlockConnection) GetLog(logs []LogType, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) types := make([]kproto.Command_GetLog_Type, len(logs)) Loading @@ -147,7 +147,7 @@ func (conn *NonBlockConnection) GetLog(logs []LogType, h *MessageHandler) error return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) pinop(pin []byte, op kproto.Command_PinOperation_PinOpType, h *MessageHandler) error { func (conn *NonBlockConnection) pinop(pin []byte, op kproto.Command_PinOperation_PinOpType, h *ResponseHandler) error { msg := newMessage(kproto.Message_PINAUTH) msg.PinAuth = &kproto.Message_PINauth{ Pin: pin, Loading @@ -164,24 +164,24 @@ func (conn *NonBlockConnection) pinop(pin []byte, op kproto.Command_PinOperation return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SecureErase(pin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) SecureErase(pin []byte, h *ResponseHandler) error { return conn.pinop(pin, kproto.Command_PinOperation_SECURE_ERASE_PINOP, h) } func (conn *NonBlockConnection) InstantErase(pin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) InstantErase(pin []byte, h *ResponseHandler) error { return conn.pinop(pin, kproto.Command_PinOperation_ERASE_PINOP, h) } func (conn *NonBlockConnection) LockDevice(pin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) LockDevice(pin []byte, h *ResponseHandler) error { return conn.pinop(pin, kproto.Command_PinOperation_LOCK_PINOP, h) } func (conn *NonBlockConnection) UnlockDevice(pin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) UnlockDevice(pin []byte, h *ResponseHandler) error { return conn.pinop(pin, kproto.Command_PinOperation_UNLOCK_PINOP, h) } func (conn *NonBlockConnection) UpdateFirmware(code []byte, h *MessageHandler) error { func (conn *NonBlockConnection) UpdateFirmware(code []byte, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SETUP) Loading @@ -195,7 +195,7 @@ func (conn *NonBlockConnection) UpdateFirmware(code []byte, h *MessageHandler) e return conn.service.submit(msg, cmd, code, h) } func (conn *NonBlockConnection) SetClusterVersion(version int64, h *MessageHandler) error { func (conn *NonBlockConnection) SetClusterVersion(version int64, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SETUP) Loading @@ -208,7 +208,7 @@ func (conn *NonBlockConnection) SetClusterVersion(version int64, h *MessageHandl return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SetLockPin(currentPin []byte, newPin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) SetLockPin(currentPin []byte, newPin []byte, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SECURITY) Loading @@ -222,7 +222,7 @@ func (conn *NonBlockConnection) SetLockPin(currentPin []byte, newPin []byte, h * return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SetErasePin(currentPin []byte, newPin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) SetErasePin(currentPin []byte, newPin []byte, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SECURITY) Loading @@ -236,15 +236,15 @@ func (conn *NonBlockConnection) SetErasePin(currentPin []byte, newPin []byte, h return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SetACL(h *MessageHandler) error { func (conn *NonBlockConnection) SetACL(h *ResponseHandler) error { return nil } func (conn *NonBlockConnection) MediaScan(h *MessageHandler) error { func (conn *NonBlockConnection) MediaScan(h *ResponseHandler) error { return nil } func (conn *NonBlockConnection) MediaOptimize(h *MessageHandler) error { func (conn *NonBlockConnection) MediaOptimize(h *ResponseHandler) error { return nil } Loading Loading
blockconnection.go +13 −13 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ func NewBlockConnection(op ClientOptions) (*BlockConnection, error) { func (conn *BlockConnection) NoOp() (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.NoOp(h) if err != nil { return callback.Status(), err Loading @@ -35,7 +35,7 @@ func (conn *BlockConnection) NoOp() (Status, error) { func (conn *BlockConnection) get(key []byte, getCmd kproto.Command_MessageType) (Record, Status, error) { callback := &GetCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) var err error = nil switch getCmd { Loading Loading @@ -71,7 +71,7 @@ func (conn *BlockConnection) GetPrevious(key []byte) (Record, Status, error) { func (conn *BlockConnection) GetKeyRange(r *KeyRange) ([][]byte, Status, error) { callback := &GetKeyRangeCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.GetKeyRange(r, h) if err != nil { return nil, callback.Status(), err Loading @@ -86,7 +86,7 @@ func (conn *BlockConnection) GetKeyRange(r *KeyRange) ([][]byte, Status, error) func (conn *BlockConnection) GetVersion(key []byte) ([]byte, Status, error) { callback := &GetVersionCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.GetVersion(key, h) if err != nil { return nil, callback.Status(), err Loading @@ -101,7 +101,7 @@ func (conn *BlockConnection) GetVersion(key []byte) ([]byte, Status, error) { func (conn *BlockConnection) Flush() (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.Flush(h) if err != nil { return callback.Status(), err Loading @@ -116,7 +116,7 @@ func (conn *BlockConnection) Flush() (Status, error) { func (conn *BlockConnection) Delete(entry *Record) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.Delete(entry, h) if err != nil { return callback.Status(), err Loading @@ -131,7 +131,7 @@ func (conn *BlockConnection) Delete(entry *Record) (Status, error) { func (conn *BlockConnection) Put(entry *Record) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.Put(entry, h) if err != nil { return callback.Status(), err Loading @@ -146,7 +146,7 @@ func (conn *BlockConnection) Put(entry *Record) (Status, error) { func (conn *BlockConnection) GetLog(logs []LogType) (Log, Status, error) { callback := &GetLogCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.GetLog(logs, h) if err != nil { return Log{}, callback.Status(), err Loading @@ -161,7 +161,7 @@ func (conn *BlockConnection) GetLog(logs []LogType) (Log, Status, error) { func (conn *BlockConnection) pinop(pin []byte, op kproto.Command_PinOperation_PinOpType) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) var err error = nil switch op { Loading Loading @@ -204,7 +204,7 @@ func (conn *BlockConnection) UnlockDevice(pin []byte) (Status, error) { func (conn *BlockConnection) UpdateFirmware(code []byte) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.UpdateFirmware(code, h) if err != nil { return callback.Status(), err Loading @@ -219,7 +219,7 @@ func (conn *BlockConnection) UpdateFirmware(code []byte) (Status, error) { func (conn *BlockConnection) SetClusterVersion(version int64) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.SetClusterVersion(version, h) if err != nil { return callback.Status(), err Loading @@ -234,7 +234,7 @@ func (conn *BlockConnection) SetClusterVersion(version int64) (Status, error) { func (conn *BlockConnection) SetLockPin(currentPin []byte, newPin []byte) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.SetLockPin(currentPin, newPin, h) if err != nil { return callback.Status(), err Loading @@ -249,7 +249,7 @@ func (conn *BlockConnection) SetLockPin(currentPin []byte, newPin []byte) (Statu func (conn *BlockConnection) SetErasePin(currentPin []byte, newPin []byte) (Status, error) { callback := &GenericCallback{} h := NewMessageHandler(callback) h := NewResponseHandler(callback) err := conn.nbc.SetErasePin(currentPin, newPin, h) if err != nil { return callback.Status(), err Loading
getlog.go 0 → 100644 +322 −0 Original line number Diff line number Diff line package kinetic import ( kproto "github.com/yongzhy/kinetic-go/proto" ) type LogType int32 const ( _ LogType = iota LOG_UTILIZATIONS LogType = iota LOG_TEMPERATURES LogType = iota LOG_CAPACITIES LogType = iota LOG_CONFIGURATION LogType = iota LOG_STATISTICS LogType = iota LOG_MESSAGES LogType = iota LOG_LIMITS LogType = iota LOG_DEVICE LogType = iota ) var strLogType = map[LogType]string{ LOG_UTILIZATIONS: "LOG_UTILIZATIONS", LOG_TEMPERATURES: "LOG_TEMPERATURES", LOG_CAPACITIES: "LOG_CAPACITIES", LOG_CONFIGURATION: "LOG_CONFIGURATION", LOG_STATISTICS: "LOG_STATISTICS", LOG_MESSAGES: "LOG_MESSAGES", LOG_LIMITS: "LOG_LIMITS", LOG_DEVICE: "LOG_DEVICE", } func (l LogType) String() string { s, ok := strLogType[l] if ok { return s } return "Unknown LogType" } func convertLogTypeToProto(l LogType) kproto.Command_GetLog_Type { ret := kproto.Command_GetLog_INVALID_TYPE switch l { case LOG_UTILIZATIONS: ret = kproto.Command_GetLog_UTILIZATIONS case LOG_TEMPERATURES: ret = kproto.Command_GetLog_TEMPERATURES case LOG_CAPACITIES: ret = kproto.Command_GetLog_CAPACITIES case LOG_CONFIGURATION: ret = kproto.Command_GetLog_CONFIGURATION case LOG_STATISTICS: ret = kproto.Command_GetLog_STATISTICS case LOG_MESSAGES: ret = kproto.Command_GetLog_MESSAGES case LOG_LIMITS: ret = kproto.Command_GetLog_LIMITS case LOG_DEVICE: 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 = LOG_UTILIZATIONS case kproto.Command_GetLog_TEMPERATURES: ret = LOG_TEMPERATURES case kproto.Command_GetLog_CAPACITIES: ret = LOG_CAPACITIES case kproto.Command_GetLog_CONFIGURATION: ret = LOG_CONFIGURATION case kproto.Command_GetLog_STATISTICS: ret = LOG_STATISTICS case kproto.Command_GetLog_MESSAGES: ret = LOG_MESSAGES case kproto.Command_GetLog_LIMITS: ret = LOG_LIMITS case kproto.Command_GetLog_DEVICE: ret = LOG_DEVICE } return ret } type UtilizationLog struct { Name string Value float32 } type TemperatureLog struct { Name string Current float32 Minimum float32 Maximum float32 Target float32 } type CapacityLog struct { CapacityInBytes uint64 PortionFull float32 } type ConfigurationInterface struct { Name string MAC []byte Ipv4Addr []byte Ipv6Addr []byte } type ConfigurationLog struct { Vendor string Model string SerialNumber []byte WorldWideName []byte Version string CompilationDate string SourceHash string ProtocolVersion string ProtocolCompilationDate string ProtocolSourceHash string Interface []ConfigurationInterface Port int32 TlsPort int32 } type StatisticsLog struct { // TODO: Would it better just use the protocol Command_MessageType? Type MessageType Count uint64 Bytes uint64 } type LimitsLog struct { MaxKeySize uint32 MaxValueSize uint32 MaxVersionSize uint32 MaxTagSize uint32 MaxConnections uint32 MaxOutstandingReadRequests uint32 MaxOutstandingWriteRequests uint32 MaxMessageSize uint32 MaxKeyRangeCount uint32 MaxIdentityCount uint32 MaxPinSize uint32 MaxOperationCountPerBatch uint32 MaxBatchCountPerDevice uint32 } type DeviceLog struct { Name []byte } type Log struct { Utilizations []UtilizationLog Temperatures []TemperatureLog Capacity CapacityLog Configuration ConfigurationLog Statistics []StatisticsLog Messages []byte Limits LimitsLog Device DeviceLog } func getUtilizationLogFromProto(getlog *kproto.Command_GetLog) []UtilizationLog { utils := getlog.GetUtilizations() if utils != nil { ulog := make([]UtilizationLog, len(utils)) for k, v := range utils { ulog[k] = UtilizationLog{ Name: v.GetName(), Value: v.GetValue(), } } return ulog } else { return nil } } func getTemperatureLogFromProto(getlog *kproto.Command_GetLog) []TemperatureLog { temps := getlog.GetTemperatures() if temps != nil { templog := make([]TemperatureLog, len(temps)) for k, v := range temps { templog[k] = TemperatureLog{ Name: v.GetName(), Current: v.GetCurrent(), Minimum: v.GetMinimum(), Maximum: v.GetMaximum(), Target: v.GetTarget(), } } return templog } else { return nil } } func getCapacityLogFromProto(getlog *kproto.Command_GetLog) CapacityLog { var log CapacityLog capacity := getlog.GetCapacity() if capacity != nil { log = CapacityLog{ CapacityInBytes: capacity.GetNominalCapacityInBytes(), PortionFull: capacity.GetPortionFull(), } } return log } func getConfigurationInterfaceFromProto(conf *kproto.Command_GetLog_Configuration) []ConfigurationInterface { 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 inf } else { return nil } } func getConfigurationLogFromProto(getlog *kproto.Command_GetLog) ConfigurationLog { var log ConfigurationLog 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(), } } return log } func getStatisticsLogFromProto(getlog *kproto.Command_GetLog) []StatisticsLog { statics := getlog.GetStatistics() if statics != nil { slog := make([]StatisticsLog, len(statics)) for k, v := range statics { slog[k] = StatisticsLog{ Type: convertMessageTypeFromProto(v.GetMessageType()), Count: v.GetCount(), Bytes: v.GetBytes(), } } return slog } else { return nil } } func getLogMessageFromProto(getlog *kproto.Command_GetLog) []byte { return getlog.GetMessages() } func getLimitsLogFromProto(getlog *kproto.Command_GetLog) LimitsLog { var log LimitsLog 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 log } 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 }
handler.go +6 −6 Original line number Diff line number Diff line Loading @@ -4,11 +4,11 @@ import ( kproto "github.com/yongzhy/kinetic-go/proto" ) type MessageHandler struct { type ResponseHandler struct { callback Callback } func (h *MessageHandler) Handle(cmd *kproto.Command, value []byte) error { func (h *ResponseHandler) Handle(cmd *kproto.Command, value []byte) error { klog.Info("Message handler called") if h.callback != nil { if cmd.Status != nil && cmd.Status.Code != nil { Loading @@ -26,17 +26,17 @@ func (h *MessageHandler) Handle(cmd *kproto.Command, value []byte) error { return nil } func (h *MessageHandler) Error(s Status) { func (h *ResponseHandler) Error(s Status) { if h.callback != nil { h.callback.Failure(s) } } func (h *MessageHandler) SetCallback(call Callback) { func (h *ResponseHandler) SetCallback(call Callback) { h.callback = call } func NewMessageHandler(call Callback) *MessageHandler { h := &MessageHandler{callback: call} func NewResponseHandler(call Callback) *ResponseHandler { h := &ResponseHandler{callback: call} return h }
nonblockconnection.go +23 −23 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ func NewNonBlockConnection(op ClientOptions) (*NonBlockConnection, error) { return &NonBlockConnection{service}, nil } func (conn *NonBlockConnection) NoOp(h *MessageHandler) error { func (conn *NonBlockConnection) NoOp(h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_NOOP) Loading @@ -29,7 +29,7 @@ func (conn *NonBlockConnection) NoOp(h *MessageHandler) error { return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) get(key []byte, getType kproto.Command_MessageType, h *MessageHandler) error { func (conn *NonBlockConnection) get(key []byte, getType kproto.Command_MessageType, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(getType) Loading @@ -42,19 +42,19 @@ func (conn *NonBlockConnection) get(key []byte, getType kproto.Command_MessageTy return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) Get(key []byte, h *MessageHandler) error { func (conn *NonBlockConnection) Get(key []byte, h *ResponseHandler) error { return conn.get(key, kproto.Command_GET, h) } func (conn *NonBlockConnection) GetNext(key []byte, h *MessageHandler) error { func (conn *NonBlockConnection) GetNext(key []byte, h *ResponseHandler) error { return conn.get(key, kproto.Command_GETNEXT, h) } func (conn *NonBlockConnection) GetPrevious(key []byte, h *MessageHandler) error { func (conn *NonBlockConnection) GetPrevious(key []byte, h *ResponseHandler) error { return conn.get(key, kproto.Command_GETPREVIOUS, h) } func (conn *NonBlockConnection) GetKeyRange(r *KeyRange, h *MessageHandler) error { func (conn *NonBlockConnection) GetKeyRange(r *KeyRange, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_GETKEYRANGE) Loading @@ -72,7 +72,7 @@ func (conn *NonBlockConnection) GetKeyRange(r *KeyRange, h *MessageHandler) erro return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) GetVersion(key []byte, h *MessageHandler) error { func (conn *NonBlockConnection) GetVersion(key []byte, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_GETVERSION) Loading @@ -85,7 +85,7 @@ func (conn *NonBlockConnection) GetVersion(key []byte, h *MessageHandler) error return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) Flush(h *MessageHandler) error { func (conn *NonBlockConnection) Flush(h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_FLUSHALLDATA) Loading @@ -93,7 +93,7 @@ func (conn *NonBlockConnection) Flush(h *MessageHandler) error { return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) Delete(entry *Record, h *MessageHandler) error { func (conn *NonBlockConnection) Delete(entry *Record, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_DELETE) Loading @@ -111,7 +111,7 @@ func (conn *NonBlockConnection) Delete(entry *Record, h *MessageHandler) error { return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) Put(entry *Record, h *MessageHandler) error { func (conn *NonBlockConnection) Put(entry *Record, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_PUT) Loading @@ -130,7 +130,7 @@ func (conn *NonBlockConnection) Put(entry *Record, h *MessageHandler) error { return conn.service.submit(msg, cmd, entry.Value, h) } func (conn *NonBlockConnection) GetLog(logs []LogType, h *MessageHandler) error { func (conn *NonBlockConnection) GetLog(logs []LogType, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) types := make([]kproto.Command_GetLog_Type, len(logs)) Loading @@ -147,7 +147,7 @@ func (conn *NonBlockConnection) GetLog(logs []LogType, h *MessageHandler) error return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) pinop(pin []byte, op kproto.Command_PinOperation_PinOpType, h *MessageHandler) error { func (conn *NonBlockConnection) pinop(pin []byte, op kproto.Command_PinOperation_PinOpType, h *ResponseHandler) error { msg := newMessage(kproto.Message_PINAUTH) msg.PinAuth = &kproto.Message_PINauth{ Pin: pin, Loading @@ -164,24 +164,24 @@ func (conn *NonBlockConnection) pinop(pin []byte, op kproto.Command_PinOperation return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SecureErase(pin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) SecureErase(pin []byte, h *ResponseHandler) error { return conn.pinop(pin, kproto.Command_PinOperation_SECURE_ERASE_PINOP, h) } func (conn *NonBlockConnection) InstantErase(pin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) InstantErase(pin []byte, h *ResponseHandler) error { return conn.pinop(pin, kproto.Command_PinOperation_ERASE_PINOP, h) } func (conn *NonBlockConnection) LockDevice(pin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) LockDevice(pin []byte, h *ResponseHandler) error { return conn.pinop(pin, kproto.Command_PinOperation_LOCK_PINOP, h) } func (conn *NonBlockConnection) UnlockDevice(pin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) UnlockDevice(pin []byte, h *ResponseHandler) error { return conn.pinop(pin, kproto.Command_PinOperation_UNLOCK_PINOP, h) } func (conn *NonBlockConnection) UpdateFirmware(code []byte, h *MessageHandler) error { func (conn *NonBlockConnection) UpdateFirmware(code []byte, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SETUP) Loading @@ -195,7 +195,7 @@ func (conn *NonBlockConnection) UpdateFirmware(code []byte, h *MessageHandler) e return conn.service.submit(msg, cmd, code, h) } func (conn *NonBlockConnection) SetClusterVersion(version int64, h *MessageHandler) error { func (conn *NonBlockConnection) SetClusterVersion(version int64, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SETUP) Loading @@ -208,7 +208,7 @@ func (conn *NonBlockConnection) SetClusterVersion(version int64, h *MessageHandl return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SetLockPin(currentPin []byte, newPin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) SetLockPin(currentPin []byte, newPin []byte, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SECURITY) Loading @@ -222,7 +222,7 @@ func (conn *NonBlockConnection) SetLockPin(currentPin []byte, newPin []byte, h * return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SetErasePin(currentPin []byte, newPin []byte, h *MessageHandler) error { func (conn *NonBlockConnection) SetErasePin(currentPin []byte, newPin []byte, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SECURITY) Loading @@ -236,15 +236,15 @@ func (conn *NonBlockConnection) SetErasePin(currentPin []byte, newPin []byte, h return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SetACL(h *MessageHandler) error { func (conn *NonBlockConnection) SetACL(h *ResponseHandler) error { return nil } func (conn *NonBlockConnection) MediaScan(h *MessageHandler) error { func (conn *NonBlockConnection) MediaScan(h *ResponseHandler) error { return nil } func (conn *NonBlockConnection) MediaOptimize(h *MessageHandler) error { func (conn *NonBlockConnection) MediaOptimize(h *ResponseHandler) error { return nil } Loading