Skip to content

Commit

Permalink
feat: update as controller board to use EdgeX-3.0 (#140)
Browse files Browse the repository at this point in the history
* feat: update as controller board to use EdgeX-3.0
* fix: remove build tags related to no_zmq for tests
* fix: change automated checkout wording to automated vending for as-controller board
* fix: add the missing support-notification client config in configuration yaml file

Signed-off-by: Jim Wang <yutsung.jim.wang@intel.com>

---------

Signed-off-by: Jim Wang <yutsung.jim.wang@intel.com>
  • Loading branch information
jim-wang-intel authored Sep 19, 2023
1 parent add46cf commit f50f06c
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 359 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/trivyimagescan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@7b7aa264d83dc58691451798b4d117d53d21edfe
with:
image-ref: 'automated-checkout/as-controller-board-status:dev'
image-ref: 'automated-vending/as-controller-board-status:dev'
format: 'template'
template: '@/contrib/sarif.tpl'
output: 'trivy-results-as-controller-board-status.sarif'
Expand Down
16 changes: 8 additions & 8 deletions as-controller-board-status/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Copyright © 2022 Intel Corporation. All rights reserved.
# Copyright © 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause

FROM golang:1.18-alpine3.16 AS builder
FROM golang:1.20-alpine3.17 AS builder

LABEL license='SPDX-License-Identifier: BSD-3-Clause' \
copyright='Copyright (c) 2022: Intel'
copyright='Copyright (c) 2023: Intel'


# add git for go modules
RUN apk update && apk add --no-cache make git gcc libc-dev zeromq-dev linux-headers
# hadolint ignore=DL3018
RUN apk update && apk add --no-cache make git

ENV GO111MODULE=on
WORKDIR /usr/local/bin/
Expand All @@ -28,13 +29,12 @@ COPY . .
RUN make gobuild

# Next image - Copy built Go binary into new workspace
FROM alpine
FROM alpine:3.17

LABEL license='SPDX-License-Identifier: BSD-3-Clause' \
copyright='Copyright (c) 2022: Intel'
copyright='Copyright (c) 2023: Intel'

RUN apk --no-cache add zeromq
COPY --from=builder /usr/local/bin/as-controller-board-status/res/configuration.toml /res/configuration.toml
COPY --from=builder /usr/local/bin/as-controller-board-status/res/configuration.yaml /res/configuration.yaml
COPY --from=builder /usr/local/bin/as-controller-board-status/main /as-controller-board-status

CMD [ "/as-controller-board-status", "-cp=consul.http://edgex-core-consul:8500", "-r"]
2 changes: 1 addition & 1 deletion as-controller-board-status/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright © 2020-2022, Intel Corporation
Copyright © 2020-2023, Intel Corporation
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
10 changes: 5 additions & 5 deletions as-controller-board-status/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright © 2022 Intel Corporation. All rights reserved.
# Copyright © 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause

.PHONY: build gobuild run gorun stop test lint

MICROSERVICE=automated-checkout/as-controller-board-status
MICROSERVICE=automated-vending/as-controller-board-status

ARCH=$(shell uname -m)

Expand All @@ -19,7 +19,7 @@ docker:
.

gobuild: tidy
CGO_ENABLED=1 GOOS=linux go build -ldflags='-s -w' -a -installsuffix cgo main.go
CGO_ENABLED=0 GOOS=linux go build -ldflags='-s -w' -a main.go

run:
docker run \
Expand All @@ -34,10 +34,10 @@ stop:
docker rm -f $(MICROSERVICE):dev

test:
go test -tags no_zmq -test.v -cover ./...
go test -test.v -cover ./...

testHTML:
go test -tags no_zmq -test.v -coverprofile=test_coverage.out ./... && \
go test -test.v -coverprofile=test_coverage.out ./... && \
go tool cover -html=test_coverage.out

lint:
Expand Down
6 changes: 3 additions & 3 deletions as-controller-board-status/functions/common_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

package functions
Expand Down Expand Up @@ -43,12 +43,12 @@ func GetCommonSuccessConfig() *config.ControllerBoardStatusConfig {
DeviceName: "controller-board",
MaxTemperatureThreshold: 83.0,
MinTemperatureThreshold: 10.0,
DoorStatusCommandEndpoint: "http://localhost:48082/api/v2/device/name/Inference-device/vendingDoorStatus",
DoorStatusCommandEndpoint: "http://localhost:48082/api/v3/device/name/Inference-device/vendingDoorStatus",
NotificationCategory: "HW_HEALTH",
NotificationEmailAddresses: "test@site.com,test@site.com",
NotificationLabels: "HW_HEALTH",
NotificationReceiver: "System Administrator",
NotificationSender: "Automated Checkout Maintenance Notification",
NotificationSender: "Automated Vending Maintenance Notification",
NotificationSeverity: "CRITICAL",
NotificationName: "maintenance-notification",
NotificationSubscriptionMaxRESTRetries: 10,
Expand Down
6 changes: 3 additions & 3 deletions as-controller-board-status/functions/models.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

package functions
Expand All @@ -9,7 +9,7 @@ import (
"strings"
"time"

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

// ControllerBoardStatusAppSettings is a data structure that holds the
Expand Down Expand Up @@ -81,7 +81,7 @@ type CheckBoardStatus struct {

// VendingDoorStatus is a string representation of a boolean whose state corresponds
// to the whether the doorClosed state is true or false. This data is sent
// to the MQTT device service for processing by the Automated Checkout inference
// to the MQTT device service for processing by the Automated Vending inference
// algorithm, which will act if the door state flips from open (false) to
// closed (true).
type VendingDoorStatus struct {
Expand Down
6 changes: 3 additions & 3 deletions as-controller-board-status/functions/notify.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

package functions
Expand All @@ -9,8 +9,8 @@ import (

"github.com/google/uuid"

"github.com/edgexfoundry/go-mod-core-contracts/v2/dtos"
"github.com/edgexfoundry/go-mod-core-contracts/v2/dtos/requests"
"github.com/edgexfoundry/go-mod-core-contracts/v3/dtos"
"github.com/edgexfoundry/go-mod-core-contracts/v3/dtos/requests"
)

// SubscribeToNotificationService configures an email notification and submits
Expand Down
6 changes: 3 additions & 3 deletions as-controller-board-status/functions/notify_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

package functions
Expand All @@ -10,8 +10,8 @@ import (
"net/http/httptest"
"testing"

client_mocks "github.com/edgexfoundry/go-mod-core-contracts/v2/clients/interfaces/mocks"
edgex_errors "github.com/edgexfoundry/go-mod-core-contracts/v2/errors"
client_mocks "github.com/edgexfoundry/go-mod-core-contracts/v3/clients/interfaces/mocks"
edgex_errors "github.com/edgexfoundry/go-mod-core-contracts/v3/errors"
assert "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
Expand Down
12 changes: 6 additions & 6 deletions as-controller-board-status/functions/output.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

package functions
Expand All @@ -11,9 +11,9 @@ import (
"strconv"
"time"

"github.com/edgexfoundry/app-functions-sdk-go/v2/pkg/interfaces"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v2/dtos"
"github.com/edgexfoundry/app-functions-sdk-go/v3/pkg/interfaces"
"github.com/edgexfoundry/go-mod-core-contracts/v3/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v3/dtos"
)

const (
Expand All @@ -28,7 +28,7 @@ const (
// It is a decision function that allows for multiple devices to have their events processed
// correctly by this application service. In this case, only one unique type of EdgeX device will come
// through to this function, but in general this is basically a template function that is also followed
// in other services in the Automated Checkout project.
// in other services in the Automated Vending project.
func (boardStatus *CheckBoardStatus) CheckControllerBoardStatus(ctx interfaces.AppFunctionContext, data interface{}) (bool, interface{}) {
if data == nil {
// We didn't receive a result
Expand Down Expand Up @@ -121,7 +121,7 @@ func getTempThresholdExceededMessage(minOrMax string, avgTemp float64, tempThres
if minOrMax != maximum && minOrMax != minimum {
return "", fmt.Errorf("Please specify minOrMax as \"%v\" or \"%v\", the value given was \"%v\"", maximum, minimum, minOrMax)
}
resultMessage := fmt.Sprintf("The internal automated checkout's temperature is currently %.2f, and this temperature exceeds the configured %v temperature threshold of %v degrees. The automated checkout needs maintenance as of: %s", avgTemp, minOrMax, tempThreshold, time.Now().Format("_2 Jan, Mon | 3:04PM MST"))
resultMessage := fmt.Sprintf("The internal automated vending's temperature is currently %.2f, and this temperature exceeds the configured %v temperature threshold of %v degrees. The automated vending needs maintenance as of: %s", avgTemp, minOrMax, tempThreshold, time.Now().Format("_2 Jan, Mon | 3:04PM MST"))
return resultMessage, nil
}

Expand Down
23 changes: 13 additions & 10 deletions as-controller-board-status/functions/output_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

package functions
Expand All @@ -11,11 +11,11 @@ import (
"testing"
"time"

"github.com/edgexfoundry/app-functions-sdk-go/v2/pkg"
"github.com/edgexfoundry/app-functions-sdk-go/v2/pkg/interfaces"
client_mocks "github.com/edgexfoundry/go-mod-core-contracts/v2/clients/interfaces/mocks"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v2/dtos"
"github.com/edgexfoundry/app-functions-sdk-go/v3/pkg"
"github.com/edgexfoundry/app-functions-sdk-go/v3/pkg/interfaces"
client_mocks "github.com/edgexfoundry/go-mod-core-contracts/v3/clients/interfaces/mocks"
"github.com/edgexfoundry/go-mod-core-contracts/v3/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v3/dtos"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -29,12 +29,12 @@ func getCommonApplicationSettingsTyped() *config.ControllerBoardStatusConfig {
DeviceName: "controller-board",
MaxTemperatureThreshold: temp51,
MinTemperatureThreshold: temp49,
DoorStatusCommandEndpoint: "http://localhost:48082/api/v2/device/name/Inference-device/vendingDoorStatus",
DoorStatusCommandEndpoint: "http://localhost:48082/api/v3/device/name/Inference-device/vendingDoorStatus",
NotificationCategory: "HW_HEALTH",
NotificationEmailAddresses: "test@site.com,test@site.com",
NotificationLabels: "HW_HEALTH",
NotificationReceiver: "System Administrator",
NotificationSender: "Automated Checkout Maintenance Notification",
NotificationSender: "Automated Vending Maintenance Notification",
NotificationSeverity: "CRITICAL",
NotificationName: "maintenance-notification",
NotificationSubscriptionMaxRESTRetries: 10,
Expand Down Expand Up @@ -83,9 +83,12 @@ const (
// x failure to run ProcessApplicationSettings due to missing config option
// x failure to unmarshal ControllerBoardStatus from event reading
// x failure to call processTemperature, which can be created by sending a
// status other than "Accepted" via the NotificationHost
//
// status other than "Accepted" via the NotificationHost
//
// x failure to call processVendingDoorState, which can be created by
// sending a status other than status OK to the DoorStatusCommandEndpoint
//
// sending a status other than status OK to the DoorStatusCommandEndpoint
//
// = 6 test cases total, 3 httptest servers
//
Expand Down
88 changes: 46 additions & 42 deletions as-controller-board-status/go.mod
Original file line number Diff line number Diff line change
@@ -1,74 +1,78 @@
// Copyright © 2022 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

module as-controller-board-status

go 1.18
go 1.20

require (
github.com/edgexfoundry/app-functions-sdk-go/v2 v2.2.0
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.2.0
github.com/edgexfoundry/app-functions-sdk-go/v3 v3.0.1
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0
github.com/google/uuid v1.3.0
github.com/intel-iot-devkit/automated-checkout-utilities v1.0.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.4
)

require (
bitbucket.org/bertimus9/systemstat v0.5.0 // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/diegoholiveira/jsonlogic v1.0.1-0.20200220175622-ab7989be08b9 // indirect
github.com/eclipse/paho.mqtt.golang v1.3.5 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v2 v2.2.0 // indirect
github.com/edgexfoundry/go-mod-configuration/v2 v2.2.0 // indirect
github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0 // indirect
github.com/edgexfoundry/go-mod-registry/v2 v2.2.0 // indirect
github.com/edgexfoundry/go-mod-secrets/v2 v2.2.0 // indirect
github.com/diegoholiveira/jsonlogic/v3 v3.2.7 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.2 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.1 // indirect
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0 // indirect
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0 // indirect
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0 // indirect
github.com/edgexfoundry/go-mod-secrets/v3 v3.0.1 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.13.0 // indirect
github.com/go-redis/redis/v7 v7.3.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gomodule/redigo v1.8.8 // indirect
github.com/gomodule/redigo v1.8.9 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/consul/api v1.9.1 // indirect
github.com/hashicorp/consul/api v1.20.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-hclog v0.12.0 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-hclog v0.14.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/hashicorp/serf v0.9.5 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/leodido/go-urn v1.2.3 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/consulstructure v0.0.0-20190329231841-56fdc4d2da54 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/pebbe/zmq4 v1.2.7 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/nats-io/nats.go v1.25.0 // indirect
github.com/nats-io/nkeys v0.4.4 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect
github.com/spiffe/go-spiffe/v2 v2.0.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/spiffe/go-spiffe/v2 v2.1.4 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zeebo/errs v1.2.2 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
github.com/zeebo/errs v1.3.0 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/square/go-jose.v2 v2.4.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit f50f06c

Please sign in to comment.