Skip to content

Commit

Permalink
Make the contracts complient with edgex-go on device admin/oper statu…
Browse files Browse the repository at this point in the history
…s update

Device admin and operating status update implementation have been changed
in edgex-go so that the status data is sent in the request body instead of being part of the URL
(see edgexfoundry/edgex-go#1361)

But go-mod-core-contracts wasn't updated accordingly.
This PR makes go-mod-core-contracts Device interface complient with the
implementation within edgex-go.

Fix: #272

Signed-off-by: Diana Atanasova <dianaa@vmware.com>
  • Loading branch information
difince committed Aug 26, 2020
1 parent 06f35a9 commit ab261ba
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions clients/metadata/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/edgexfoundry/go-mod-core-contracts/clients"
"github.com/edgexfoundry/go-mod-core-contracts/clients/interfaces"
"github.com/edgexfoundry/go-mod-core-contracts/models"
"github.com/edgexfoundry/go-mod-core-contracts/requests/states/admin"
"github.com/edgexfoundry/go-mod-core-contracts/requests/states/operating"
)

// DeviceClient defines the interface for interactions with the Device endpoint on core-metadata.
Expand Down Expand Up @@ -54,9 +56,9 @@ type DeviceClient interface {
// Update the specified device
Update(ctx context.Context, dev models.Device) error
// UpdateAdminState modifies a device's AdminState for the specified device ID
UpdateAdminState(ctx context.Context, id string, adminState string) error
UpdateAdminState(ctx context.Context, id string, req admin.UpdateRequest) error
// UpdateAdminStateByName modifies a device's AdminState according to the specified device name
UpdateAdminStateByName(ctx context.Context, name string, adminState string) error
UpdateAdminStateByName(ctx context.Context, name string, req admin.UpdateRequest) error
// UpdateLastConnected updates a device's last connected timestamp according to the specified device ID
UpdateLastConnected(ctx context.Context, id string, time int64) error
// UpdateLastConnectedByName updates a device's last connected timestamp according to the specified device name
Expand All @@ -66,9 +68,9 @@ type DeviceClient interface {
// UpdateLastReportedByName updates a device's last reported timestamp according to the specified device name
UpdateLastReportedByName(ctx context.Context, name string, time int64) error
// UpdateOpState updates a device's last OperatingState according to the specified device ID
UpdateOpState(ctx context.Context, id string, opState string) error
UpdateOpState(ctx context.Context, id string, req operating.UpdateRequest) error
// UpdateOpStateByName updates a device's last OperatingState according to the specified device name
UpdateOpStateByName(ctx context.Context, name string, opState string) error
UpdateOpStateByName(ctx context.Context, name string, req operating.UpdateRequest) error
}

type deviceRestClient struct {
Expand Down Expand Up @@ -170,24 +172,20 @@ func (d *deviceRestClient) UpdateLastReportedByName(ctx context.Context, name st
return err
}

func (d *deviceRestClient) UpdateOpState(ctx context.Context, id string, opState string) error {
_, err := clients.PutRequest(ctx, "/"+id+"/opstate/"+opState, nil, d.urlClient)
return err
func (d *deviceRestClient) UpdateOpState(ctx context.Context, id string, req operating.UpdateRequest) error {
return clients.UpdateRequest(ctx, "/"+id, req, d.urlClient)
}

func (d *deviceRestClient) UpdateOpStateByName(ctx context.Context, name string, opState string) error {
_, err := clients.PutRequest(ctx, "/name/"+url.QueryEscape(name)+"/opstate/"+opState, nil, d.urlClient)
return err
func (d *deviceRestClient) UpdateOpStateByName(ctx context.Context, name string, req operating.UpdateRequest) error {
return clients.UpdateRequest(ctx, "/name/"+url.QueryEscape(name), req, d.urlClient)
}

func (d *deviceRestClient) UpdateAdminState(ctx context.Context, id string, adminState string) error {
_, err := clients.PutRequest(ctx, "/"+id+"/adminstate/"+adminState, nil, d.urlClient)
return err
func (d *deviceRestClient) UpdateAdminState(ctx context.Context, id string, req admin.UpdateRequest) error {
return clients.UpdateRequest(ctx, "/"+id, req, d.urlClient)
}

func (d *deviceRestClient) UpdateAdminStateByName(ctx context.Context, name string, adminState string) error {
_, err := clients.PutRequest(ctx, "/name/"+url.QueryEscape(name)+"/adminstate/"+adminState, nil, d.urlClient)
return err
func (d *deviceRestClient) UpdateAdminStateByName(ctx context.Context, name string, req admin.UpdateRequest) error {
return clients.UpdateRequest(ctx, "/name/"+url.QueryEscape(name), req, d.urlClient)
}

func (d *deviceRestClient) Delete(ctx context.Context, id string) error {
Expand Down

0 comments on commit ab261ba

Please sign in to comment.