Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): Use v2 Command Client #845

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -29,11 +29,11 @@ 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"
"github.com/edgexfoundry/go-mod-core-contracts/v2/models"
clientInterfaces "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/interfaces"
"github.com/edgexfoundry/go-mod-messaging/v2/pkg/types"
"github.com/edgexfoundry/go-mod-registry/v2/registry"

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() clientInterfaces.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
11 changes: 5 additions & 6 deletions internal/bootstrap/container/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,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 @@ -60,13 +59,13 @@ func NotificationsClientFrom(get di.Get) notifications.NotificationsClient {
}

// CommandClientName contains the name of the CommandClientInfo's implementation in the DIC.
var CommandClientName = di.TypeInstanceToName((*command.CommandClient)(nil))
var CommandClientName = di.TypeInstanceToName((*interfaces.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)
}
8 changes: 4 additions & 4 deletions internal/bootstrap/handlers/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ 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 +51,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 +65,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
5 changes: 3 additions & 2 deletions pkg/interfaces/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package interfaces
import (
"time"

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

"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 +69,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.

5 changes: 3 additions & 2 deletions pkg/interfaces/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package interfaces
import (
"net/http"

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

"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 +104,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