Skip to content

Commit

Permalink
fix after CR
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik committed Sep 5, 2023
1 parent 2a5e278 commit 5597d18
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 329 deletions.
8 changes: 4 additions & 4 deletions coap-gateway/service/clientObserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ func (c *session) replaceDeviceObserver(deviceObserverFuture *future.Future) *fu
}

// Replace deviceObserver instance in the client if Device Twin setting was changed for the device.
func (c *session) replaceDeviceObserverWithDeviceTwin(ctx context.Context, twinEnabled, forceResynchronization bool) (bool, error) {
func (c *session) replaceDeviceObserverWithDeviceTwin(ctx context.Context, twinEnabled, twinForceSynchronization bool) (bool, error) {
obs, err := c.getDeviceObserver(ctx)
if err != nil {
return false, err
}
prevTwinEnabled := obs.GetTwinEnabled()
deviceID := obs.GetDeviceID()
observationType := obs.GetObservationType()
twinEnabled = twinEnabled || forceResynchronization
if !forceResynchronization && prevTwinEnabled == twinEnabled {
twinEnabled = twinEnabled || twinForceSynchronization
if !twinForceSynchronization && prevTwinEnabled == twinEnabled {
return prevTwinEnabled, nil
}
deviceObserverFuture, setDeviceObserver := future.New()
Expand All @@ -69,7 +69,7 @@ func (c *session) replaceDeviceObserverWithDeviceTwin(ctx context.Context, twinE
observation.WithLogger(c.getLogger()),
observation.WithRequireBatchObserveEnabled(c.server.config.APIs.COAP.RequireBatchObserveEnabled),
observation.WithMaxETagsCountInRequest(c.server.config.DeviceTwin.MaxETagsCountInRequest),
observation.WithUseETags(!forceResynchronization && c.server.config.DeviceTwin.UseETags),
observation.WithUseETags(!twinForceSynchronization && c.server.config.DeviceTwin.UseETags),
)
if err != nil {
setDeviceObserver(nil, err)
Expand Down
36 changes: 18 additions & 18 deletions coap-gateway/service/observation/deviceObserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ type DeviceObserver struct {
}

type DeviceObserverConfig struct {
Logger log.Logger
ObservationType ObservationType
TwinEnabled bool
TwinEnabledSet bool
UseETags bool
RequireBatchObserveEnabled bool
LimitBatchObserveLatestETags uint32
Logger log.Logger
ObservationType ObservationType
TwinEnabled bool
TwinEnabledSet bool
UseETags bool
RequireBatchObserveEnabled bool
MaxETagsCountInRequest uint32
}

type ClientConn interface {
Expand Down Expand Up @@ -150,17 +150,17 @@ func (o LoggerOpt) Apply(opts *DeviceObserverConfig) {
}

// Limit of the number of latest etags acquired from event store.
type LimitBatchObserveLatestETagsOpt struct {
limitBatchObserveLatestETags uint32
type MaxETagsCountInRequestOpt struct {
maxETagsCountInRequest uint32
}

func (o LimitBatchObserveLatestETagsOpt) Apply(opts *DeviceObserverConfig) {
opts.LimitBatchObserveLatestETags = o.limitBatchObserveLatestETags
func (o MaxETagsCountInRequestOpt) Apply(opts *DeviceObserverConfig) {
opts.MaxETagsCountInRequest = o.maxETagsCountInRequest
}

func WithMaxETagsCountInRequest(v uint32) LimitBatchObserveLatestETagsOpt {
return LimitBatchObserveLatestETagsOpt{
limitBatchObserveLatestETags: v,
func WithMaxETagsCountInRequest(v uint32) MaxETagsCountInRequestOpt {
return MaxETagsCountInRequestOpt{
maxETagsCountInRequest: v,
}
}

Expand Down Expand Up @@ -204,7 +204,7 @@ func getETags(ctx context.Context, deviceID string, rdClient GrpcGatewayClient,
}
r, err := rdClient.GetLatestDeviceETags(ctx, &pbRD.GetLatestDeviceETagsRequest{
DeviceId: deviceID,
Limit: cfg.LimitBatchObserveLatestETags,
Limit: cfg.MaxETagsCountInRequest,
})
if err != nil {
cfg.Logger.Debugf("NewDeviceObserver: failed to get latest device(%v) etag: %v", deviceID, err)
Expand All @@ -223,9 +223,9 @@ func NewDeviceObserver(ctx context.Context, deviceID string, coapConn ClientConn
}

cfg := DeviceObserverConfig{
Logger: log.Get(),
LimitBatchObserveLatestETags: 8,
UseETags: true,
Logger: log.Get(),
MaxETagsCountInRequest: 8,
UseETags: true,
}
for _, o := range opts {
o.Apply(&cfg)
Expand Down
12 changes: 6 additions & 6 deletions coap-gateway/service/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,9 +936,9 @@ func (c *session) confirmDeviceMetadataUpdate(ctx context.Context, event *events
},
Status: commands.Status_OK,
}
if event.GetTwinForceResynchronization() {
r.Confirm = &commands.ConfirmDeviceMetadataUpdateRequest_TwinForceResynchronization{
TwinForceResynchronization: true,
if event.GetTwinForceSynchronization() {
r.Confirm = &commands.ConfirmDeviceMetadataUpdateRequest_TwinForceSynchronization{
TwinForceSynchronization: true,
}
} else {
r.Confirm = &commands.ConfirmDeviceMetadataUpdateRequest_TwinEnabled{
Expand All @@ -962,19 +962,19 @@ func (c *session) UpdateDeviceMetadata(ctx context.Context, event *events.Device
}
switch event.GetUpdatePending().(type) {
case *events.DeviceMetadataUpdatePending_TwinEnabled:
case *events.DeviceMetadataUpdatePending_TwinForceResynchronization:
case *events.DeviceMetadataUpdatePending_TwinForceSynchronization:
default:
return nil
}
sendConfirmCtx := authCtx.ToContext(ctx)

var errObs error
var previous bool
if event.GetTwinEnabled() || event.GetTwinForceResynchronization() {
if event.GetTwinEnabled() || event.GetTwinForceSynchronization() {
// if twin is enabled, we need to first update twin synchronization state to sync out
// and then synchronization state will be updated by other replaceDeviceObserverWithDeviceTwin
err = c.confirmDeviceMetadataUpdate(sendConfirmCtx, event)
previous, errObs = c.replaceDeviceObserverWithDeviceTwin(sendConfirmCtx, event.GetTwinEnabled(), event.GetTwinForceResynchronization())
previous, errObs = c.replaceDeviceObserverWithDeviceTwin(sendConfirmCtx, event.GetTwinEnabled(), event.GetTwinForceSynchronization())
} else {
// if twin is disabled, we to stop observation resources to disable all update twin synchronization state
previous, errObs = c.replaceDeviceObserverWithDeviceTwin(sendConfirmCtx, event.GetTwinEnabled(), false)
Expand Down
4 changes: 2 additions & 2 deletions grpc-gateway/pb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ Certain filters perform a logical "or" operation among the elements of t
| ----- | ---- | ----- | ----------- |
| device_id | [string](#string) | | |
| twin_enabled | [bool](#bool) | | |
| twin_force_resynchronization | [bool](#bool) | | force resynchronization IoT hub with the device resources and set twin_enabled to true. Use to address potential synchronization issues and prevent operational discrepancies. |
| twin_force_synchronization | [bool](#bool) | | force synchronization IoT hub with the device resources and set twin_enabled to true. Use to address potential synchronization issues and prevent operational discrepancies. |
| time_to_live | [int64](#int64) | | command validity in nanoseconds. 0 means forever and minimal value is 100000000 (100ms). |


Expand Down Expand Up @@ -1299,7 +1299,7 @@ https://github.com/openconnectivityfoundation/core/blob/master/schemas/oic.links
| ----- | ---- | ----- | ----------- |
| device_id | [string](#string) | | |
| twin_enabled | [bool](#bool) | | |
| twin_force_resynchronization | [bool](#bool) | | |
| twin_force_synchronization | [bool](#bool) | | |
| audit_context | [AuditContext](#resourceaggregate-pb-AuditContext) | | |
| event_metadata | [EventMetadata](#resourceaggregate-pb-EventMetadata) | | |
| valid_until | [int64](#int64) | | unix timestamp in nanoseconds (https://golang.org/pkg/time/#Time.UnixNano) when pending event is considered as expired. 0 means forever. |
Expand Down
6 changes: 3 additions & 3 deletions grpc-gateway/pb/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -3042,10 +3042,10 @@ <h3 id="grpcgateway.pb.UpdateDeviceMetadataRequest">UpdateDeviceMetadataRequest<
</tr>

<tr>
<td>twin_force_resynchronization</td>
<td>twin_force_synchronization</td>
<td><a href="#bool">bool</a></td>
<td></td>
<td><p>force resynchronization IoT hub with the device resources and set twin_enabled to true. Use to address potential synchronization issues and prevent operational discrepancies. </p></td>
<td><p>force synchronization IoT hub with the device resources and set twin_enabled to true. Use to address potential synchronization issues and prevent operational discrepancies. </p></td>
</tr>

<tr>
Expand Down Expand Up @@ -3515,7 +3515,7 @@ <h3 id="resourceaggregate.pb.DeviceMetadataUpdatePending">DeviceMetadataUpdatePe
</tr>

<tr>
<td>twin_force_resynchronization</td>
<td>twin_force_synchronization</td>
<td><a href="#bool">bool</a></td>
<td></td>
<td><p> </p></td>
Expand Down
10 changes: 5 additions & 5 deletions grpc-gateway/pb/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@
"twinEnabled": {
"type": "boolean"
},
"twinForceResynchronization": {
"twinForceSynchronization": {
"type": "boolean",
"description": "force resynchronization IoT hub with the device resources and set twin_enabled to true. Use to address potential synchronization issues and prevent operational discrepancies."
"description": "force synchronization IoT hub with the device resources and set twin_enabled to true. Use to address potential synchronization issues and prevent operational discrepancies."
},
"timeToLive": {
"type": "string",
Expand Down Expand Up @@ -1414,7 +1414,7 @@
"twinEnabled": {
"type": "boolean"
},
"twinForceResynchronization": {
"twinForceSynchronization": {
"type": "boolean"
},
"auditContext": {
Expand Down Expand Up @@ -2101,10 +2101,10 @@
"$ref": "#/definitions/pbCommandMetadata",
"description": "when status is SYNCING, this field contains the connection id. To update state to IN_SYNC, this field must be same as the one in the previous message."
},
"forceResynchronizationAt": {
"forceSynchronizationAt": {
"type": "string",
"format": "int64",
"description": "unix timestamp in nanoseconds (https://golang.org/pkg/time/#Time.UnixNano) when the force resynchronization has been started. 0 means force resynchronization has never started."
"description": "unix timestamp in nanoseconds (https://golang.org/pkg/time/#Time.UnixNano) when the force synchronization has been started. 0 means force synchronization has never started."
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions grpc-gateway/pb/updateDeviceMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (req *UpdateDeviceMetadataRequest) ToRACommand(ctx context.Context) (*comma
},
}

if req.GetTwinForceResynchronization() {
r.Update = &commands.UpdateDeviceMetadataRequest_TwinForceResynchronization{
TwinForceResynchronization: req.GetTwinForceResynchronization(),
if req.GetTwinForceSynchronization() {
r.Update = &commands.UpdateDeviceMetadataRequest_TwinForceSynchronization{
TwinForceSynchronization: req.GetTwinForceSynchronization(),
}
} else {
r.Update = &commands.UpdateDeviceMetadataRequest_TwinEnabled{
Expand Down
47 changes: 23 additions & 24 deletions grpc-gateway/pb/updateDeviceMetadata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion grpc-gateway/pb/updateDeviceMetadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ message UpdateDeviceMetadataRequest{
reserved 2;
string device_id = 1;
bool twin_enabled = 4;
bool twin_force_resynchronization = 5; // force resynchronization IoT hub with the device resources and set twin_enabled to true. Use to address potential synchronization issues and prevent operational discrepancies.
bool twin_force_synchronization = 5; // force synchronization IoT hub with the device resources and set twin_enabled to true. Use to address potential synchronization issues and prevent operational discrepancies.
int64 time_to_live = 3; // command validity in nanoseconds. 0 means forever and minimal value is 100000000 (100ms).

// ShadowSynchronization shadow_synchronization = 2; replaced by twin_enabled
Expand Down
Loading

0 comments on commit 5597d18

Please sign in to comment.