Skip to content

Commit

Permalink
feat(sdk): Use v2 Command Client
Browse files Browse the repository at this point in the history
Register v2 client in dic and change interface used throughout.

Signed-off-by: Alex Ullrich <[email protected]>
  • Loading branch information
Alex Ullrich committed May 19, 2021
1 parent d014dc0 commit 22ed9b3
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app-service-template/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go 1.15

require (
github.com/edgexfoundry/app-functions-sdk-go/v2 v2.0.0-dev.52
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.90
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.91
github.com/google/uuid v1.2.0
github.com/stretchr/testify v1.7.0
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/diegoholiveira/jsonlogic v1.0.1-0.20200220175622-ab7989be08b9
github.com/eclipse/paho.mqtt.golang v1.3.4
github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.0-dev.54
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.90
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.91
github.com/edgexfoundry/go-mod-messaging/v2 v2.0.0-dev.13
github.com/edgexfoundry/go-mod-registry/v2 v2.0.0-dev.7
github.com/fxamacker/cbor/v2 v2.2.0
Expand Down
4 changes: 2 additions & 2 deletions internal/app/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
interfaces2 "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/interfaces"
nethttp "net/http"
"os"
"os/signal"
Expand All @@ -29,7 +30,6 @@ import (
"syscall"

"github.com/edgexfoundry/go-mod-core-contracts/v2/clients"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/command"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/coredata"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/notifications"
Expand Down Expand Up @@ -480,7 +480,7 @@ func (svc *Service) EventClient() coredata.EventClient {
}

// CommandClient returns the Command client, which may be nil, from the dependency injection container
func (svc *Service) CommandClient() command.CommandClient {
func (svc *Service) CommandClient() interfaces2.CommandClient {
return container.CommandClientFrom(svc.dic.Get)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/appfunction/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (

bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v2/bootstrap/container"
"github.com/edgexfoundry/go-mod-bootstrap/v2/di"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/command"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/coredata"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/notifications"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/interfaces"

"github.com/edgexfoundry/app-functions-sdk-go/v2/internal/bootstrap/container"
"github.com/edgexfoundry/app-functions-sdk-go/v2/pkg/util"
Expand Down Expand Up @@ -205,7 +205,7 @@ func (appContext *Context) EventClient() coredata.EventClient {
}

// CommandClient returns the Command client, which may be nil, from the dependency injection container
func (appContext *Context) CommandClient() command.CommandClient {
func (appContext *Context) CommandClient() interfaces.CommandClient {
return container.CommandClientFrom(appContext.dic.Get)
}

Expand Down
5 changes: 2 additions & 3 deletions internal/appfunction/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import (
"github.com/edgexfoundry/go-mod-bootstrap/v2/bootstrap/interfaces/mocks"
"github.com/edgexfoundry/go-mod-bootstrap/v2/di"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/command"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/coredata"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/notifications"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/urlclient/local"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2"
v2clients "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/http"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos/common"

Expand All @@ -55,11 +55,10 @@ func TestMain(m *testing.M) {
return notifications.NewNotificationsClient(local.New(clients.ApiNotificationRoute))
},
container.CommandClientName: func(get di.Get) interface{} {
return command.NewCommandClient(local.New(clients.ApiCommandRoute))
return v2clients.NewCommandClient(clients.ApiCommandRoute)
},
bootstrapContainer.LoggingClientInterfaceName: func(get di.Get) interface{} {
return logger.NewMockClient()

},
})
target = NewContext("", dic, "")
Expand Down
8 changes: 4 additions & 4 deletions internal/bootstrap/container/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package container
import (
"github.com/edgexfoundry/go-mod-bootstrap/v2/di"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/command"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/notifications"

"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/coredata"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/notifications"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/interfaces"
)

// ValueDescriptorClientName contains the name of the ValueDescriptorClient's implementation in the DIC.
Expand Down Expand Up @@ -63,10 +63,10 @@ func NotificationsClientFrom(get di.Get) notifications.NotificationsClient {
var CommandClientName = di.TypeInstanceToName((*command.CommandClient)(nil))

// NotificationsClientFrom helper function queries the DIC and returns the NotificationsClientInfo's implementation.
func CommandClientFrom(get di.Get) command.CommandClient {
func CommandClientFrom(get di.Get) interfaces.CommandClient {
if get(CommandClientName) == nil {
return nil
}

return get(CommandClientName).(command.CommandClient)
return get(CommandClientName).(interfaces.CommandClient)
}
9 changes: 5 additions & 4 deletions internal/bootstrap/handlers/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
"github.com/edgexfoundry/go-mod-bootstrap/v2/bootstrap/startup"
"github.com/edgexfoundry/go-mod-bootstrap/v2/di"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/command"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/coredata"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/notifications"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/urlclient/local"

v2clients "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/http"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/interfaces"

"github.com/edgexfoundry/app-functions-sdk-go/v2/internal/bootstrap/container"
)

Expand All @@ -50,7 +52,7 @@ func (_ *Clients) BootstrapHandler(

var eventClient coredata.EventClient
var valueDescriptorClient coredata.ValueDescriptorClient
var commandClient command.CommandClient
var commandClient interfaces.CommandClient
var notificationsClient notifications.NotificationsClient

// Use of these client interfaces is optional, so they are not required to be configured. For instance if not
Expand All @@ -64,8 +66,7 @@ func (_ *Clients) BootstrapHandler(
}

if _, ok := config.Clients[clients.CoreCommandServiceKey]; ok {
commandClient = command.NewCommandClient(
local.New(config.Clients[clients.CoreCommandServiceKey].Url() + clients.ApiDeviceRoute))
commandClient = v2clients.NewCommandClient(config.Clients[clients.CoreCommandServiceKey].Url())
}

if _, ok := config.Clients[clients.SupportNotificationsServiceKey]; ok {
Expand Down
4 changes: 2 additions & 2 deletions pkg/interfaces/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package interfaces

import (
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/interfaces"
"time"

"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/command"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/coredata"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/notifications"
Expand Down Expand Up @@ -68,7 +68,7 @@ type AppFunctionContext interface {
EventClient() coredata.EventClient
// CommandClient returns the Command client. Note if Support Command is not specified in the Clients configuration,
// this will return nil.
CommandClient() command.CommandClient
CommandClient() interfaces.CommandClient
// NotificationsClient returns the Notifications client. Note if Support Notifications is not specified in the
// Clients configuration, this will return nil.
NotificationsClient() notifications.NotificationsClient
Expand Down
10 changes: 5 additions & 5 deletions pkg/interfaces/mocks/ApplicationService.go

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

4 changes: 2 additions & 2 deletions pkg/interfaces/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package interfaces

import (
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/interfaces"
"net/http"

"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/command"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/coredata"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/notifications"
Expand Down Expand Up @@ -103,7 +103,7 @@ type ApplicationService interface {
EventClient() coredata.EventClient
// CommandClient returns the Command client. Note if Support Command is not specified in the Clients configuration,
// this will return nil.
CommandClient() command.CommandClient
CommandClient() interfaces.CommandClient
// NotificationsClient returns the Notifications client. Note if Support Notifications is not specified in the
// Clients configuration, this will return nil.
NotificationsClient() notifications.NotificationsClient
Expand Down

0 comments on commit 22ed9b3

Please sign in to comment.