Loading blockconnection.go +14 −0 Original line number Diff line number Diff line Loading @@ -419,6 +419,20 @@ func (conn *BlockConnection) MediaOptimize(op *MediaOperation, pri Priority) (St return callback.Status(), err } // SetPowerLevel sets device power level func (conn *BlockConnection) SetPowerLevel(p PowerLevel) (Status, error) { callback := &GenericCallback{} h := NewResponseHandler(callback) err := conn.nbc.SetPowerLevel(p, h) if err != nil { return callback.Status(), err } err = conn.nbc.Listen(h) return callback.Status(), err } // Close the connection to kientic device func (conn *BlockConnection) Close() { conn.nbc.Close() Loading connection_test.go +14 −0 Original line number Diff line number Diff line Loading @@ -150,6 +150,9 @@ func TestBlockPut_valueOverflow(t *testing.T) { // TestBlockPut_tagOverflow test key buffer length than MaxTagSize // TODO: drive implementation using UNSOLICITEDSTATUS. func TestBlockPut_tagOverflow(t *testing.T) { if blockConn.nbc.service.device.Limits.MaxTagSize > 0xFFFF { t.Skip("Max tag checking not implemented yet, skip this test") } entry := Record{ Key: []byte("key"), Value: []byte("value"), Loading Loading @@ -277,6 +280,17 @@ func TestBlockMediaOptimize(t *testing.T) { } } func TestSetPowerLevel(t *testing.T) { status, err := blockConn.SetPowerLevel(POWER_HIBERNATE) if err != nil || status.Code != OK { t.Fatal("Blocking SetPowerLevel Failure: ", err, status.String()) } status, err = blockConn.SetPowerLevel(POWER_OPERATIONAL) if err != nil || status.Code != OK { t.Fatal("Blocking SetPowerLevel Failure: ", err, status.String()) } } func TestBlockSetClusterVersion(t *testing.T) { status, err := blockConn.SetClusterVersion(1) if err != nil || status.Code != OK { Loading getlog.go +2 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,7 @@ type ConfigurationLog struct { 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. Loading Loading @@ -272,6 +273,7 @@ func getConfigurationLogFromProto(getlog *kproto.Command_GetLog) (log *Configura Interface: getConfigurationInterfaceFromProto(conf), Port: conf.GetPort(), TlsPort: conf.GetTlsPort(), CurrentPowerLevel: convertPowerLevelFromProto(conf.GetCurrentPowerLevel()), } } return Loading kinetic.go +168 −94 Original line number Diff line number Diff line Loading @@ -120,6 +120,8 @@ const ( MESSAGE_END_BATCH_RESPONSE MessageType = iota MESSAGE_ABORT_BATCH MessageType = iota MESSAGE_ABORT_BATCH_RESPONSE MessageType = iota MESSAGE_SET_POWER_LEVEL MessageType = iota MESSAGE_SET_POWER_LEVEL_RESPONSE MessageType = iota ) var strMessageType = map[MessageType]string{ Loading Loading @@ -161,6 +163,8 @@ var strMessageType = map[MessageType]string{ MESSAGE_END_BATCH_RESPONSE: "END_BATCH_RESPONSE", MESSAGE_ABORT_BATCH: "ABORT_BATCH", MESSAGE_ABORT_BATCH_RESPONSE: "ABORT_BATCH_RESPONSE", MESSAGE_SET_POWER_LEVEL: "SET_POWER_LEVEL", MESSAGE_SET_POWER_LEVEL_RESPONSE: "SET_POWER_LEVEL_RESPONSE", } func (m MessageType) String() string { Loading Loading @@ -250,6 +254,10 @@ func convertMessageTypeToProto(m MessageType) kproto.Command_MessageType { ret = kproto.Command_ABORT_BATCH case MESSAGE_ABORT_BATCH_RESPONSE: ret = kproto.Command_ABORT_BATCH_RESPONSE case MESSAGE_SET_POWER_LEVEL: ret = kproto.Command_SET_POWER_LEVEL case MESSAGE_SET_POWER_LEVEL_RESPONSE: ret = kproto.Command_SET_POWER_LEVEL_RESPONSE } return ret } Loading Loading @@ -333,6 +341,10 @@ func convertMessageTypeFromProto(m kproto.Command_MessageType) MessageType { ret = MESSAGE_ABORT_BATCH case kproto.Command_ABORT_BATCH_RESPONSE: ret = MESSAGE_ABORT_BATCH_RESPONSE case kproto.Command_SET_POWER_LEVEL: ret = MESSAGE_SET_POWER_LEVEL case kproto.Command_SET_POWER_LEVEL_RESPONSE: ret = MESSAGE_SET_POWER_LEVEL_RESPONSE } return ret } Loading Loading @@ -560,6 +572,7 @@ const ( ACL_PERMISSION_P2POP ACLPermission = iota // Can do a peer to peer operation ACL_PERMISSION_GETLOG ACLPermission = iota // Can get log ACL_PERMISSION_SECURITY ACLPermission = iota // Can set up the security of device ACL_PERMISSION_POWER_MANAGEMENT ACLPermission = iota // Can set power level ) var strACLPermission = map[ACLPermission]string{ Loading @@ -571,6 +584,7 @@ var strACLPermission = map[ACLPermission]string{ ACL_PERMISSION_P2POP: "ACL_PERMISSION_P2POP", ACL_PERMISSION_GETLOG: "ACL_PERMISSION_GETLOG", ACL_PERMISSION_SECURITY: "ACL_PERMISSION_SECURITY", ACL_PERMISSION_POWER_MANAGEMENT: "ACL_PERMISSION_POWER_MANAGEMENT", } func (p ACLPermission) String() string { Loading Loading @@ -600,6 +614,8 @@ func convertACLPermissionToProto(perm ACLPermission) kproto.Command_Security_ACL ret = kproto.Command_Security_ACL_GETLOG case ACL_PERMISSION_SECURITY: ret = kproto.Command_Security_ACL_SECURITY case ACL_PERMISSION_POWER_MANAGEMENT: ret = kproto.Command_Security_ACL_POWER_MANAGEMENT } return ret } Loading @@ -623,6 +639,8 @@ func convertACLPermissionFromProto(perm kproto.Command_Security_ACL_Permission) ret = ACL_PERMISSION_GETLOG case kproto.Command_Security_ACL_SECURITY: ret = ACL_PERMISSION_SECURITY case kproto.Command_Security_ACL_POWER_MANAGEMENT: ret = ACL_PERMISSION_POWER_MANAGEMENT } return ret } Loading Loading @@ -701,3 +719,59 @@ type BatchStatus struct { DoneSequence []int64 // All sequence Ids of those commands (PUT/DELETE) performed successfully in the batch FailedSequence int64 // Non 0 value means the first failed operation sequence in the batch, 0 means no failure } // PowerLevel type PowerLevel int32 const ( _ PowerLevel = iota POWER_OPERATIONAL PowerLevel = iota POWER_HIBERNATE PowerLevel = iota POWER_SHUTDOWN PowerLevel = iota POWER_FAIL PowerLevel = iota ) var strPowerLevel = map[PowerLevel]string{ POWER_OPERATIONAL: "OPERATIONAL", POWER_HIBERNATE: "HIBERNATE", POWER_SHUTDOWN: "SHUTDOWN", POWER_FAIL: "FAIL", } func (p PowerLevel) String() string { str, ok := strPowerLevel[p] if ok { return str } return "Unknown Power Level" } func convertPowerLevelToProto(p PowerLevel) kproto.Command_PowerLevel { var ret kproto.Command_PowerLevel switch p { case POWER_OPERATIONAL: ret = kproto.Command_OPERATIONAL case POWER_HIBERNATE: ret = kproto.Command_HIBERNATE case POWER_SHUTDOWN: ret = kproto.Command_SHUTDOWN case POWER_FAIL: ret = kproto.Command_FAIL } return ret } func convertPowerLevelFromProto(p kproto.Command_PowerLevel) PowerLevel { var ret PowerLevel switch p { case kproto.Command_OPERATIONAL: ret = POWER_OPERATIONAL case kproto.Command_HIBERNATE: ret = POWER_HIBERNATE case kproto.Command_SHUTDOWN: ret = POWER_SHUTDOWN case kproto.Command_FAIL: ret = POWER_FAIL } return ret } nonblockconnection.go +16 −0 Original line number Diff line number Diff line Loading @@ -490,6 +490,22 @@ func (conn *NonBlockConnection) MediaOptimize(op *MediaOperation, pri Priority, return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SetPowerLevel(p PowerLevel, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SET_POWER_LEVEL) level := convertPowerLevelToProto(p) cmd.Body = &kproto.Command_Body{ Power: &kproto.Command_PowerManagement{ Level: &level, }, } return conn.service.submit(msg, cmd, nil, h) } // Listen waits and read response message from device, then call ResponseHandler // in queue to process received message. func (conn *NonBlockConnection) Listen(h *ResponseHandler) error { Loading Loading
blockconnection.go +14 −0 Original line number Diff line number Diff line Loading @@ -419,6 +419,20 @@ func (conn *BlockConnection) MediaOptimize(op *MediaOperation, pri Priority) (St return callback.Status(), err } // SetPowerLevel sets device power level func (conn *BlockConnection) SetPowerLevel(p PowerLevel) (Status, error) { callback := &GenericCallback{} h := NewResponseHandler(callback) err := conn.nbc.SetPowerLevel(p, h) if err != nil { return callback.Status(), err } err = conn.nbc.Listen(h) return callback.Status(), err } // Close the connection to kientic device func (conn *BlockConnection) Close() { conn.nbc.Close() Loading
connection_test.go +14 −0 Original line number Diff line number Diff line Loading @@ -150,6 +150,9 @@ func TestBlockPut_valueOverflow(t *testing.T) { // TestBlockPut_tagOverflow test key buffer length than MaxTagSize // TODO: drive implementation using UNSOLICITEDSTATUS. func TestBlockPut_tagOverflow(t *testing.T) { if blockConn.nbc.service.device.Limits.MaxTagSize > 0xFFFF { t.Skip("Max tag checking not implemented yet, skip this test") } entry := Record{ Key: []byte("key"), Value: []byte("value"), Loading Loading @@ -277,6 +280,17 @@ func TestBlockMediaOptimize(t *testing.T) { } } func TestSetPowerLevel(t *testing.T) { status, err := blockConn.SetPowerLevel(POWER_HIBERNATE) if err != nil || status.Code != OK { t.Fatal("Blocking SetPowerLevel Failure: ", err, status.String()) } status, err = blockConn.SetPowerLevel(POWER_OPERATIONAL) if err != nil || status.Code != OK { t.Fatal("Blocking SetPowerLevel Failure: ", err, status.String()) } } func TestBlockSetClusterVersion(t *testing.T) { status, err := blockConn.SetClusterVersion(1) if err != nil || status.Code != OK { Loading
getlog.go +2 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,7 @@ type ConfigurationLog struct { 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. Loading Loading @@ -272,6 +273,7 @@ func getConfigurationLogFromProto(getlog *kproto.Command_GetLog) (log *Configura Interface: getConfigurationInterfaceFromProto(conf), Port: conf.GetPort(), TlsPort: conf.GetTlsPort(), CurrentPowerLevel: convertPowerLevelFromProto(conf.GetCurrentPowerLevel()), } } return Loading
kinetic.go +168 −94 Original line number Diff line number Diff line Loading @@ -120,6 +120,8 @@ const ( MESSAGE_END_BATCH_RESPONSE MessageType = iota MESSAGE_ABORT_BATCH MessageType = iota MESSAGE_ABORT_BATCH_RESPONSE MessageType = iota MESSAGE_SET_POWER_LEVEL MessageType = iota MESSAGE_SET_POWER_LEVEL_RESPONSE MessageType = iota ) var strMessageType = map[MessageType]string{ Loading Loading @@ -161,6 +163,8 @@ var strMessageType = map[MessageType]string{ MESSAGE_END_BATCH_RESPONSE: "END_BATCH_RESPONSE", MESSAGE_ABORT_BATCH: "ABORT_BATCH", MESSAGE_ABORT_BATCH_RESPONSE: "ABORT_BATCH_RESPONSE", MESSAGE_SET_POWER_LEVEL: "SET_POWER_LEVEL", MESSAGE_SET_POWER_LEVEL_RESPONSE: "SET_POWER_LEVEL_RESPONSE", } func (m MessageType) String() string { Loading Loading @@ -250,6 +254,10 @@ func convertMessageTypeToProto(m MessageType) kproto.Command_MessageType { ret = kproto.Command_ABORT_BATCH case MESSAGE_ABORT_BATCH_RESPONSE: ret = kproto.Command_ABORT_BATCH_RESPONSE case MESSAGE_SET_POWER_LEVEL: ret = kproto.Command_SET_POWER_LEVEL case MESSAGE_SET_POWER_LEVEL_RESPONSE: ret = kproto.Command_SET_POWER_LEVEL_RESPONSE } return ret } Loading Loading @@ -333,6 +341,10 @@ func convertMessageTypeFromProto(m kproto.Command_MessageType) MessageType { ret = MESSAGE_ABORT_BATCH case kproto.Command_ABORT_BATCH_RESPONSE: ret = MESSAGE_ABORT_BATCH_RESPONSE case kproto.Command_SET_POWER_LEVEL: ret = MESSAGE_SET_POWER_LEVEL case kproto.Command_SET_POWER_LEVEL_RESPONSE: ret = MESSAGE_SET_POWER_LEVEL_RESPONSE } return ret } Loading Loading @@ -560,6 +572,7 @@ const ( ACL_PERMISSION_P2POP ACLPermission = iota // Can do a peer to peer operation ACL_PERMISSION_GETLOG ACLPermission = iota // Can get log ACL_PERMISSION_SECURITY ACLPermission = iota // Can set up the security of device ACL_PERMISSION_POWER_MANAGEMENT ACLPermission = iota // Can set power level ) var strACLPermission = map[ACLPermission]string{ Loading @@ -571,6 +584,7 @@ var strACLPermission = map[ACLPermission]string{ ACL_PERMISSION_P2POP: "ACL_PERMISSION_P2POP", ACL_PERMISSION_GETLOG: "ACL_PERMISSION_GETLOG", ACL_PERMISSION_SECURITY: "ACL_PERMISSION_SECURITY", ACL_PERMISSION_POWER_MANAGEMENT: "ACL_PERMISSION_POWER_MANAGEMENT", } func (p ACLPermission) String() string { Loading Loading @@ -600,6 +614,8 @@ func convertACLPermissionToProto(perm ACLPermission) kproto.Command_Security_ACL ret = kproto.Command_Security_ACL_GETLOG case ACL_PERMISSION_SECURITY: ret = kproto.Command_Security_ACL_SECURITY case ACL_PERMISSION_POWER_MANAGEMENT: ret = kproto.Command_Security_ACL_POWER_MANAGEMENT } return ret } Loading @@ -623,6 +639,8 @@ func convertACLPermissionFromProto(perm kproto.Command_Security_ACL_Permission) ret = ACL_PERMISSION_GETLOG case kproto.Command_Security_ACL_SECURITY: ret = ACL_PERMISSION_SECURITY case kproto.Command_Security_ACL_POWER_MANAGEMENT: ret = ACL_PERMISSION_POWER_MANAGEMENT } return ret } Loading Loading @@ -701,3 +719,59 @@ type BatchStatus struct { DoneSequence []int64 // All sequence Ids of those commands (PUT/DELETE) performed successfully in the batch FailedSequence int64 // Non 0 value means the first failed operation sequence in the batch, 0 means no failure } // PowerLevel type PowerLevel int32 const ( _ PowerLevel = iota POWER_OPERATIONAL PowerLevel = iota POWER_HIBERNATE PowerLevel = iota POWER_SHUTDOWN PowerLevel = iota POWER_FAIL PowerLevel = iota ) var strPowerLevel = map[PowerLevel]string{ POWER_OPERATIONAL: "OPERATIONAL", POWER_HIBERNATE: "HIBERNATE", POWER_SHUTDOWN: "SHUTDOWN", POWER_FAIL: "FAIL", } func (p PowerLevel) String() string { str, ok := strPowerLevel[p] if ok { return str } return "Unknown Power Level" } func convertPowerLevelToProto(p PowerLevel) kproto.Command_PowerLevel { var ret kproto.Command_PowerLevel switch p { case POWER_OPERATIONAL: ret = kproto.Command_OPERATIONAL case POWER_HIBERNATE: ret = kproto.Command_HIBERNATE case POWER_SHUTDOWN: ret = kproto.Command_SHUTDOWN case POWER_FAIL: ret = kproto.Command_FAIL } return ret } func convertPowerLevelFromProto(p kproto.Command_PowerLevel) PowerLevel { var ret PowerLevel switch p { case kproto.Command_OPERATIONAL: ret = POWER_OPERATIONAL case kproto.Command_HIBERNATE: ret = POWER_HIBERNATE case kproto.Command_SHUTDOWN: ret = POWER_SHUTDOWN case kproto.Command_FAIL: ret = POWER_FAIL } return ret }
nonblockconnection.go +16 −0 Original line number Diff line number Diff line Loading @@ -490,6 +490,22 @@ func (conn *NonBlockConnection) MediaOptimize(op *MediaOperation, pri Priority, return conn.service.submit(msg, cmd, nil, h) } func (conn *NonBlockConnection) SetPowerLevel(p PowerLevel, h *ResponseHandler) error { msg := newMessage(kproto.Message_HMACAUTH) cmd := newCommand(kproto.Command_SET_POWER_LEVEL) level := convertPowerLevelToProto(p) cmd.Body = &kproto.Command_Body{ Power: &kproto.Command_PowerManagement{ Level: &level, }, } return conn.service.submit(msg, cmd, nil, h) } // Listen waits and read response message from device, then call ResponseHandler // in queue to process received message. func (conn *NonBlockConnection) Listen(h *ResponseHandler) error { Loading