Skip to content

Commit

Permalink
Merge pull request #820 from hahattan/remove-v2
Browse files Browse the repository at this point in the history
refactor: remove v2 subdirectory for SDK
  • Loading branch information
cloudxxx8 authored Mar 17, 2021
2 parents 79c5143 + 3a954db commit e34679e
Show file tree
Hide file tree
Showing 39 changed files with 237 additions and 417 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690
github.com/OneOfOne/xxhash v1.2.8
github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.0-dev.14
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.48
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.49
github.com/edgexfoundry/go-mod-registry/v2 v2.0.0-dev.3
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos/requests"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/models"

"github.com/edgexfoundry/device-sdk-go/v2/internal/cache"
"github.com/edgexfoundry/device-sdk-go/v2/internal/container"
"github.com/edgexfoundry/device-sdk-go/v2/internal/v2/cache"
)

func UpdateProfile(profileRequest requests.DeviceProfileRequest, lc logger.LoggingClient) errors.EdgeX {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/models"

"github.com/edgexfoundry/device-sdk-go/v2/internal/cache"
"github.com/edgexfoundry/device-sdk-go/v2/internal/common"
"github.com/edgexfoundry/device-sdk-go/v2/internal/container"
"github.com/edgexfoundry/device-sdk-go/v2/internal/transformer"
"github.com/edgexfoundry/device-sdk-go/v2/internal/v2/cache"
dsModels "github.com/edgexfoundry/device-sdk-go/v2/pkg/models"
)

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/autoevent/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/models"

"github.com/edgexfoundry/device-sdk-go/v2/internal/application"
"github.com/edgexfoundry/device-sdk-go/v2/internal/common"
"github.com/edgexfoundry/device-sdk-go/v2/internal/container"
"github.com/edgexfoundry/device-sdk-go/v2/internal/v2/application"
)

type Executor struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/autoevent/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/edgexfoundry/go-mod-bootstrap/v2/di"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/models"

"github.com/edgexfoundry/device-sdk-go/v2/internal/cache"
"github.com/edgexfoundry/device-sdk-go/v2/internal/container"
"github.com/edgexfoundry/device-sdk-go/v2/internal/v2/cache"
)

type manager struct {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 0 additions & 49 deletions internal/common/apperror.go

This file was deleted.

28 changes: 3 additions & 25 deletions internal/common/consts.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
17 changes: 0 additions & 17 deletions internal/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package common

import (
"context"
"sync"
"time"

"github.com/edgexfoundry/go-mod-core-contracts/v2/clients"
Expand All @@ -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{
Expand Down
21 changes: 0 additions & 21 deletions internal/common/utils_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos/requests"
"github.com/gorilla/mux"

"github.com/edgexfoundry/device-sdk-go/v2/internal/v2/application"
"github.com/edgexfoundry/device-sdk-go/v2/internal/application"
)

func (c *V2HttpController) DeleteDevice(writer http.ResponseWriter, request *http.Request) {
func (c *RestController) DeleteDevice(writer http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request)
name := vars[v2.Name]

Expand All @@ -32,7 +32,7 @@ func (c *V2HttpController) DeleteDevice(writer http.ResponseWriter, request *htt
}
}

func (c *V2HttpController) AddDevice(writer http.ResponseWriter, request *http.Request) {
func (c *RestController) AddDevice(writer http.ResponseWriter, request *http.Request) {
defer request.Body.Close()

var addDeviceRequest requests.AddDeviceRequest
Expand All @@ -53,7 +53,7 @@ func (c *V2HttpController) AddDevice(writer http.ResponseWriter, request *http.R
}
}

func (c *V2HttpController) UpdateDevice(writer http.ResponseWriter, request *http.Request) {
func (c *RestController) UpdateDevice(writer http.ResponseWriter, request *http.Request) {
defer request.Body.Close()

var updateDeviceRequest requests.UpdateDeviceRequest
Expand All @@ -74,7 +74,7 @@ func (c *V2HttpController) UpdateDevice(writer http.ResponseWriter, request *htt
}
}

func (c *V2HttpController) UpdateProfile(writer http.ResponseWriter, request *http.Request) {
func (c *RestController) UpdateProfile(writer http.ResponseWriter, request *http.Request) {
defer request.Body.Close()

var edgexErr errors.EdgeX
Expand All @@ -96,7 +96,7 @@ func (c *V2HttpController) UpdateProfile(writer http.ResponseWriter, request *ht
}
}

func (c *V2HttpController) DeleteProvisionWatcher(writer http.ResponseWriter, request *http.Request) {
func (c *RestController) DeleteProvisionWatcher(writer http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request)
name := vars[v2.Name]

Expand All @@ -109,7 +109,7 @@ func (c *V2HttpController) DeleteProvisionWatcher(writer http.ResponseWriter, re
}
}

func (c *V2HttpController) AddProvisionWatcher(writer http.ResponseWriter, request *http.Request) {
func (c *RestController) AddProvisionWatcher(writer http.ResponseWriter, request *http.Request) {
defer request.Body.Close()

var addProvisionWatcherRequest requests.AddProvisionWatcherRequest
Expand All @@ -130,7 +130,7 @@ func (c *V2HttpController) AddProvisionWatcher(writer http.ResponseWriter, reque
}
}

func (c *V2HttpController) UpdateProvisionWatcher(writer http.ResponseWriter, request *http.Request) {
func (c *RestController) UpdateProvisionWatcher(writer http.ResponseWriter, request *http.Request) {
defer request.Body.Close()

var updateProvisionWatcherRequest requests.UpdateProvisionWatcherRequest
Expand All @@ -151,7 +151,7 @@ func (c *V2HttpController) UpdateProvisionWatcher(writer http.ResponseWriter, re
}
}

func (c *V2HttpController) UpdateDeviceService(writer http.ResponseWriter, request *http.Request) {
func (c *RestController) UpdateDeviceService(writer http.ResponseWriter, request *http.Request) {
defer request.Body.Close()

var updateDeviceServiceRequest requests.UpdateDeviceServiceRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import (
"net/url"
"strings"

edgexErr "github.com/edgexfoundry/go-mod-core-contracts/v2/errors"
"github.com/edgexfoundry/go-mod-core-contracts/v2/errors"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos/common"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos/responses"
"github.com/gorilla/mux"

"github.com/edgexfoundry/device-sdk-go/v2/internal/application"
sdkCommon "github.com/edgexfoundry/device-sdk-go/v2/internal/common"
"github.com/edgexfoundry/device-sdk-go/v2/internal/v2/application"
)

func (c *V2HttpController) Command(writer http.ResponseWriter, request *http.Request) {
func (c *RestController) Command(writer http.ResponseWriter, request *http.Request) {
defer request.Body.Close()

var requestBody string
var queryParams string
var err edgexErr.EdgeX
var err errors.EdgeX
var reserved url.Values
vars := mux.Vars(request)
correlationID := request.Header.Get(sdkCommon.CorrelationHeader)
Expand Down Expand Up @@ -69,24 +69,24 @@ func (c *V2HttpController) Command(writer http.ResponseWriter, request *http.Req
}
}

func readBodyAsString(req *http.Request) (string, edgexErr.EdgeX) {
func readBodyAsString(req *http.Request) (string, errors.EdgeX) {
defer req.Body.Close()
body, err := ioutil.ReadAll(req.Body)
if err != nil {
return "", edgexErr.NewCommonEdgeX(edgexErr.KindServerError, "failed to read request body", err)
return "", errors.NewCommonEdgeX(errors.KindServerError, "failed to read request body", err)
}

if len(body) == 0 {
return "", edgexErr.NewCommonEdgeX(edgexErr.KindServerError, "no request body provided for SET command", nil)
return "", errors.NewCommonEdgeX(errors.KindServerError, "no request body provided for SET command", nil)
}

return string(body), nil
}

func filterQueryParams(queryParams string) (string, url.Values, edgexErr.EdgeX) {
func filterQueryParams(queryParams string) (string, url.Values, errors.EdgeX) {
m, err := url.ParseQuery(queryParams)
if err != nil {
edgexErr := edgexErr.NewCommonEdgeX(edgexErr.KindServerError, "failed to parse query parameter", err)
edgexErr := errors.NewCommonEdgeX(errors.KindServerError, "failed to parse query parameter", err)
return "", nil, edgexErr
}

Expand Down
Loading

0 comments on commit e34679e

Please sign in to comment.