Skip to content

Commit 2fe50ba

Browse files
committed
feat: Complete Schedule Job features and Add Unit Tests
This is the fourth PR of edgexfoundry#4834 - Completed the features of Schedule Job - Created config package for Cron Schedule Job service - Added unit tests - Modified the Dockerfile to add tzdata for supporting timezone in crontab expression Signed-off-by: Jack Chen <[email protected]>
1 parent 4ff1172 commit 2fe50ba

File tree

10 files changed

+677
-15
lines changed

10 files changed

+677
-15
lines changed

cmd/support-cron-scheduler/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN make cmd/support-cron-scheduler/support-cron-scheduler
3232

3333
FROM alpine:3.18
3434

35-
RUN apk add --update --no-cache ca-certificates dumb-init
35+
RUN apk add --update --no-cache ca-certificates dumb-init tzdata
3636
# Ensure using latest versions of all installed packages to avoid any recent CVEs
3737
RUN apk --no-cache upgrade
3838

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/eclipse/paho.mqtt.golang v1.5.0
77
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.50
88
github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.12
9-
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.35
9+
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.36
1010
github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.31
1111
github.com/edgexfoundry/go-mod-secrets/v3 v3.2.0-dev.9
1212
github.com/fxamacker/cbor/v2 v2.7.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.50 h1:i6VyieS5P7olGlhG1Wt
8888
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.50/go.mod h1:oOuvWXdu6YaB2J17pe4X0ey66AZFyTzOmAZDQxPGGmM=
8989
github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.12 h1:JGZ9fsyCZOgbNkg+qdW9JN63NKIEX95v5zJhCVdlp10=
9090
github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.12/go.mod h1:v7CvWGVmTh8dKItDNtfdBnYTeLhfZP5YmFiLsGJL9KU=
91-
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.35 h1:WAOqSa29J+eNXUkS/1nuu61xPfiGgDYb5yXZzGXCj+g=
92-
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.35/go.mod h1:d/FCa9Djq/pb7RYGEEhrR7fnKo+JK5IQ2YGW4LIHAqE=
91+
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.36 h1:/PXz4+arKeW6A6YwhNpxW/LpabAdnyv5kgh8pPs6LkQ=
92+
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.36/go.mod h1:d/FCa9Djq/pb7RYGEEhrR7fnKo+JK5IQ2YGW4LIHAqE=
9393
github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.31 h1:mC0ZguoK8HjVxeD7dIiXRqKswM0y7gnPQJt1fLOh/v4=
9494
github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.31/go.mod h1:gcHtufkjd6oa3ZLqfzp66bCyCPx8MZe8Pwzh+2ITFnw=
9595
github.com/edgexfoundry/go-mod-registry/v3 v3.2.0-dev.13 h1:LkaF2eOpSz4eUiGpah4a9r+cB/A0Pea3Nh7aTU9hlKs=

internal/support/cronscheduler/application/action/devicecontrol.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ package action
77

88
import (
99
"context"
10+
"encoding/json"
1011

1112
bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/container"
12-
bootstrapUtils "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/utils"
1313
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
1414
"github.com/edgexfoundry/go-mod-core-contracts/v3/errors"
1515
"github.com/edgexfoundry/go-mod-core-contracts/v3/models"
@@ -25,7 +25,7 @@ func issueSetCommand(dic *di.Container, action models.DeviceControlAction) (stri
2525
}
2626

2727
var payload map[string]any
28-
if err := bootstrapUtils.ConvertToMap(action.Payload, &payload); err != nil {
28+
if err := json.Unmarshal(action.Payload, &payload); err != nil {
2929
return "", errors.NewCommonEdgeX(errors.KindContractInvalid, "failed to convert payload to map", err)
3030
}
3131

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// Copyright (C) 2024 IOTech Ltd
3+
//
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package config
7+
8+
import (
9+
bootstrapConfig "github.com/edgexfoundry/go-mod-bootstrap/v3/config"
10+
)
11+
12+
// ConfigurationStruct contains the configuration properties for the Support Cron Scheduler Service
13+
type ConfigurationStruct struct {
14+
Writable WritableInfo
15+
Database bootstrapConfig.Database
16+
Registry bootstrapConfig.RegistryInfo
17+
Service bootstrapConfig.ServiceInfo
18+
Clients bootstrapConfig.ClientsCollection
19+
MessageBus bootstrapConfig.MessageBusInfo
20+
}
21+
22+
type WritableInfo struct {
23+
LogLevel string
24+
InsecureSecrets bootstrapConfig.InsecureSecrets
25+
Telemetry bootstrapConfig.TelemetryInfo
26+
}
27+
28+
// UpdateFromRaw converts configuration received from the registry to a service-specific configuration struct which is
29+
// then used to overwrite the service's existing configuration struct.
30+
func (c *ConfigurationStruct) UpdateFromRaw(rawConfig any) bool {
31+
configuration, ok := rawConfig.(*ConfigurationStruct)
32+
if ok {
33+
*c = *configuration
34+
}
35+
return ok
36+
}
37+
38+
// EmptyWritablePtr returns a pointer to a service-specific empty WritableInfo struct. It is used by the bootstrap to
39+
// provide the appropriate structure to registry.Client's WatchForChanges().
40+
func (c *ConfigurationStruct) EmptyWritablePtr() any {
41+
return &WritableInfo{}
42+
}
43+
44+
// GetWritablePtr returns pointer to the writable section
45+
func (c *ConfigurationStruct) GetWritablePtr() any {
46+
return &c.Writable
47+
}
48+
49+
// UpdateWritableFromRaw converts configuration received from the registry to a service-specific WritableInfo struct
50+
// which is then used to overwrite the service's existing configuration's WritableInfo struct.
51+
func (c *ConfigurationStruct) UpdateWritableFromRaw(rawWritable any) bool {
52+
writable, ok := rawWritable.(*WritableInfo)
53+
if ok {
54+
c.Writable = *writable
55+
}
56+
return ok
57+
}
58+
59+
// GetBootstrap returns the configuration elements required by the bootstrap. Currently, a copy of the configuration
60+
// data is returned. This is intended to be temporary -- since ConfigurationStruct drives the configuration.yaml's
61+
// structure -- until we can make backwards-breaking configuration.yaml changes (which would consolidate these fields
62+
// into an bootstrapConfig.BootstrapConfiguration struct contained within ConfigurationStruct).
63+
func (c *ConfigurationStruct) GetBootstrap() bootstrapConfig.BootstrapConfiguration {
64+
// temporary until we can make backwards-breaking configuration.yaml change
65+
return bootstrapConfig.BootstrapConfiguration{
66+
Clients: &c.Clients,
67+
Database: &c.Database,
68+
MessageBus: &c.MessageBus,
69+
Registry: &c.Registry,
70+
Service: &c.Service,
71+
}
72+
}
73+
74+
// GetLogLevel returns the current ConfigurationStruct's log level.
75+
func (c *ConfigurationStruct) GetLogLevel() string {
76+
return c.Writable.LogLevel
77+
}
78+
79+
// GetRegistryInfo returns the RegistryInfo from the ConfigurationStruct.
80+
func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo {
81+
return c.Registry
82+
}
83+
84+
// GetDatabaseInfo returns a database information map.
85+
func (c *ConfigurationStruct) GetDatabaseInfo() bootstrapConfig.Database {
86+
return c.Database
87+
}
88+
89+
// GetInsecureSecrets returns the service's InsecureSecrets.
90+
func (c *ConfigurationStruct) GetInsecureSecrets() bootstrapConfig.InsecureSecrets {
91+
return c.Writable.InsecureSecrets
92+
}
93+
94+
// GetTelemetryInfo returns the service's Telemetry settings.
95+
func (c *ConfigurationStruct) GetTelemetryInfo() *bootstrapConfig.TelemetryInfo {
96+
return &c.Writable.Telemetry
97+
}

internal/support/cronscheduler/container/config.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
package container
77

88
import (
9-
// TODO: Import the config package from the support/cronscheduler directory if available
10-
"github.com/edgexfoundry/edgex-go/internal/support/scheduler/config"
11-
129
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
10+
11+
"github.com/edgexfoundry/edgex-go/internal/support/cronscheduler/config"
1312
)
1413

1514
// ConfigurationName contains the name of scheduler's config.ConfigurationStruct implementation in the DIC.

0 commit comments

Comments
 (0)