diff --git a/internal/application/command.go b/internal/application/command.go index 2366ccba8..59b91c696 100644 --- a/internal/application/command.go +++ b/internal/application/command.go @@ -134,7 +134,7 @@ func (c *CommandProcessor) ReadDeviceResource() (res *dtos.Event, e edgexErr.Edg lc.Debugf("Application - readDeviceResource: reading deviceResource: %s; %s: %s", c.deviceResource.Name, common.CorrelationHeader, c.correlationID) // check provided deviceResource is not write-only - if c.deviceResource.Properties.ReadWrite == common.DeviceResourceWriteOnly { + if c.deviceResource.Properties.ReadWrite == v2.ReadWrite_W { errMsg := fmt.Sprintf("deviceResource %s is marked as write-only", c.deviceResource.Name) return res, edgexErr.NewCommonEdgeX(edgexErr.KindNotAllowed, errMsg, nil) } @@ -201,7 +201,7 @@ func (c *CommandProcessor) ReadCommand() (res *dtos.Event, e edgexErr.EdgeX) { } // check the deviceResource isn't write-only - if dr.Properties.ReadWrite == common.DeviceResourceWriteOnly { + if dr.Properties.ReadWrite == v2.ReadWrite_W { errMsg := fmt.Sprintf("deviceResource %s in GET command %s is marked as write-only", drName, c.cmd) return res, edgexErr.NewCommonEdgeX(edgexErr.KindNotAllowed, errMsg, nil) } @@ -239,7 +239,7 @@ func (c *CommandProcessor) WriteDeviceResource() edgexErr.EdgeX { lc.Debugf("Application - writeDeviceResource: writing deviceResource: %s; %s: %s", c.deviceResource.Name, common.CorrelationHeader, c.correlationID) // check provided deviceResource is not read-only - if c.deviceResource.Properties.ReadWrite == common.DeviceResourceReadOnly { + if c.deviceResource.Properties.ReadWrite == v2.ReadWrite_R { errMsg := fmt.Sprintf("deviceResource %s is marked as read-only", c.deviceResource.Name) return edgexErr.NewCommonEdgeX(edgexErr.KindNotAllowed, errMsg, nil) } @@ -335,7 +335,7 @@ func (c *CommandProcessor) WriteCommand() edgexErr.EdgeX { } // check the deviceResource isn't read-only - if dr.Properties.ReadWrite == common.DeviceResourceReadOnly { + if dr.Properties.ReadWrite == v2.ReadWrite_R { errMsg := fmt.Sprintf("deviceResource %s in SET command %s is marked as read-only", drName, c.cmd) return edgexErr.NewCommonEdgeX(edgexErr.KindNotAllowed, errMsg, nil) } diff --git a/internal/common/apperror.go b/internal/common/apperror.go deleted file mode 100644 index 694e086b0..000000000 --- a/internal/common/apperror.go +++ /dev/null @@ -1,49 +0,0 @@ -// -*- Mode: Go; indent-tabs-mode: t -*- -// -// Copyright (C) 2018 IOTech Ltd -// -// SPDX-License-Identifier: Apache-2.0 - -package common - -import "net/http" - -type AppError interface { - Error() error - Message() string - Code() int -} - -type appError struct { - err error - msg string - code int -} - -func (a appError) Error() error { - return a.err -} - -func (a appError) Message() string { - return a.msg -} - -func (a appError) Code() int { - return a.code -} - -func NewNotFoundError(msg string, err error) AppError { - return appError{err: err, msg: msg, code: http.StatusNotFound} -} - -func NewServerError(msg string, err error) AppError { - return appError{err: err, msg: msg, code: http.StatusInternalServerError} -} - -func NewBadRequestError(msg string, err error) AppError { - return appError{err: err, msg: msg, code: http.StatusBadRequest} -} - -func NewLockedError(msg string, err error) AppError { - return appError{err: err, msg: msg, code: http.StatusLocked} -} diff --git a/internal/common/consts.go b/internal/common/consts.go index a04e82e17..dd1c23bc7 100644 --- a/internal/common/consts.go +++ b/internal/common/consts.go @@ -1,7 +1,7 @@ // -*- mode: Go; indent-tabs-mode: t -*- // // Copyright (C) 2017-2018 Canonical Ltd -// Copyright (C) 2018-2020 IOTech Ltd +// Copyright (C) 2018-2021 IOTech Ltd // Copyright (c) 2019 Intel Corporation // // SPDX-License-Identifier: Apache-2.0 @@ -16,35 +16,13 @@ import ( const ( EnvInstanceName = "EDGEX_INSTANCE_NAME" - Colon = ":" - HttpScheme = "http://" - HttpProto = "HTTP" - ConfigStemDevice = "edgex/devices/" ConfigMajorVersion = "1.0/" - APICallbackRoute = clients.ApiCallbackRoute - APIValueDescriptorRoute = clients.ApiValueDescriptorRoute - APIPingRoute = clients.ApiPingRoute - APIVersionRoute = clients.ApiVersionRoute - APIMetricsRoute = clients.ApiMetricsRoute - APIConfigRoute = clients.ApiConfigRoute - APIAllCommandRoute = clients.ApiDeviceRoute + "/all/{command}" - APIIdCommandRoute = clients.ApiDeviceRoute + "/{id}/{command}" - APINameCommandRoute = clients.ApiDeviceRoute + "/name/{name}/{command}" - APIDiscoveryRoute = clients.ApiBase + "/discovery" - APITransformRoute = clients.ApiBase + "/debug/transformData/{transformData}" - APIV2SecretRoute = v2.ApiBase + "/secret" - IdVar string = "id" - NameVar string = "name" - CommandVar string = "command" - GetCmdMethod string = "get" - SetCmdMethod string = "set" - - DeviceResourceReadOnly string = "R" - DeviceResourceWriteOnly string = "W" + GetCmdMethod = "get" + SetCmdMethod = "set" CorrelationHeader = clients.CorrelationHeader URLRawQuery = "urlRawQuery" diff --git a/internal/common/utils.go b/internal/common/utils.go index e8ffa2dc9..88815d1ee 100644 --- a/internal/common/utils.go +++ b/internal/common/utils.go @@ -9,7 +9,6 @@ package common import ( "context" - "sync" "time" "github.com/edgexfoundry/go-mod-core-contracts/v2/clients" @@ -19,22 +18,6 @@ import ( "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos/requests" ) -var ( - previousOrigin int64 - originMutex sync.Mutex -) - -func GetUniqueOrigin() int64 { - originMutex.Lock() - defer originMutex.Unlock() - now := time.Now().UnixNano() - if now <= previousOrigin { - now = previousOrigin + 1 - } - previousOrigin = now - return now -} - func UpdateLastConnected(name string, lc logger.LoggingClient, dc interfaces.DeviceClient) { t := time.Now().UnixNano() / int64(time.Millisecond) device := dtos.UpdateDevice{ diff --git a/internal/common/utils_test.go b/internal/common/utils_test.go deleted file mode 100644 index 102ebe719..000000000 --- a/internal/common/utils_test.go +++ /dev/null @@ -1,21 +0,0 @@ -// -*- Mode: Go; indent-tabs-mode: t -*- -// -// Copyright (C) 2017-2018 Canonical Ltd -// Copyright (C) 2018-2021 IOTech Ltd -// -// SPDX-License-Identifier: Apache-2.0 - -package common - -import ( - "testing" -) - -func TestGetUniqueOrigin(t *testing.T) { - origin1 := GetUniqueOrigin() - origin2 := GetUniqueOrigin() - - if origin1 >= origin2 { - t.Errorf("origin1: %d should <= origin2: %d", origin1, origin2) - } -} diff --git a/pkg/models/event.go b/pkg/models/event.go deleted file mode 100644 index ad8a545b6..000000000 --- a/pkg/models/event.go +++ /dev/null @@ -1,30 +0,0 @@ -// -- Mode: Go; indent-tabs-mode: t -- -// -// Copyright (C) 2019 Intel Ltd -// -// SPDX-License-Identifier: Apache-2.0 - -package models - -import ( - contract "github.com/edgexfoundry/go-mod-core-contracts/v2/models" -) - -// Event is a wrapper of contract.Event to provide more Binary related operation in Device Service. -type Event struct { - contract.Event - EncodedEvent []byte -} - -// HasBinaryValue confirms whether an event contains one or more -// readings populated with a BinaryValue payload. -func (e Event) HasBinaryValue() bool { - if len(e.Readings) > 0 { - for r := range e.Readings { - if len(e.Readings[r].BinaryValue) > 0 { - return true - } - } - } - return false -}