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: refactor services to build monolithic service easily #5010

Merged
merged 2 commits into from
Nov 22, 2024
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
3 changes: 2 additions & 1 deletion cmd/core-command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/core/command"

Expand All @@ -25,5 +26,5 @@ import (

func main() {
ctx, cancel := context.WithCancel(context.Background())
command.Main(ctx, cancel, echo.New())
command.Main(ctx, cancel, echo.New(), os.Args[1:])
}
4 changes: 3 additions & 1 deletion cmd/core-common-config-bootstrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/core/common_config"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
common_config.Main(ctx, cancel)
common_config.Main(ctx, cancel, os.Args[1:])
}
3 changes: 2 additions & 1 deletion cmd/core-data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/core/data"

Expand All @@ -25,5 +26,5 @@ import (

func main() {
ctx, cancel := context.WithCancel(context.Background())
data.Main(ctx, cancel, echo.New())
data.Main(ctx, cancel, echo.New(), os.Args[1:])
}
3 changes: 2 additions & 1 deletion cmd/core-keeper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/core/keeper"

Expand All @@ -15,5 +16,5 @@ import (

func main() {
ctx, cancel := context.WithCancel(context.Background())
keeper.Main(ctx, cancel, echo.New())
keeper.Main(ctx, cancel, echo.New(), os.Args[1:])
}
3 changes: 2 additions & 1 deletion cmd/core-metadata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/core/metadata"

Expand All @@ -24,5 +25,5 @@ import (

func main() {
ctx, cancel := context.WithCancel(context.Background())
metadata.Main(ctx, cancel, echo.New())
metadata.Main(ctx, cancel, echo.New(), os.Args[1:])
}
2 changes: 1 addition & 1 deletion cmd/secrets-config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ import (
func main() {
os.Setenv("LOGLEVEL", "ERROR") // Workaround for https://github.com/edgexfoundry/edgex-go/issues/2922
ctx, cancel := context.WithCancel(context.Background())
exitStatusCode := config.Main(ctx, cancel)
exitStatusCode := config.Main(ctx, cancel, os.Args[1:])
os.Exit(exitStatusCode)
}
2 changes: 1 addition & 1 deletion cmd/security-bootstrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ func main() {
_ = os.Unsetenv("EDGEX_PROFILE")

ctx, cancel := context.WithCancel(context.Background())
bootstrapper.Main(ctx, cancel)
bootstrapper.Main(ctx, cancel, os.Args[1:])
}
3 changes: 2 additions & 1 deletion cmd/security-file-token-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/security/fileprovider"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
fileprovider.Main(ctx, cancel)
fileprovider.Main(ctx, cancel, os.Args[1:])
}
3 changes: 2 additions & 1 deletion cmd/security-proxy-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/security/proxyauth"

Expand All @@ -24,5 +25,5 @@ import (

func main() {
ctx, cancel := context.WithCancel(context.Background())
proxyauth.Main(ctx, cancel, echo.New())
proxyauth.Main(ctx, cancel, echo.New(), os.Args[1:])
}
3 changes: 2 additions & 1 deletion cmd/security-secretstore-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/security/secretstore"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
secretstore.Main(ctx, cancel)
secretstore.Main(ctx, cancel, os.Args[1:])
}
3 changes: 2 additions & 1 deletion cmd/security-spiffe-token-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/security/spiffetokenprovider"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
spiffetokenprovider.Main(ctx, cancel)
spiffetokenprovider.Main(ctx, cancel, os.Args[1:])
}
3 changes: 2 additions & 1 deletion cmd/support-notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/support/notifications"

Expand All @@ -31,5 +32,5 @@ import (

func main() {
ctx, cancel := context.WithCancel(context.Background())
notifications.Main(ctx, cancel, echo.New())
notifications.Main(ctx, cancel, echo.New(), os.Args[1:])
}
3 changes: 2 additions & 1 deletion cmd/support-scheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go/internal/support/scheduler"

Expand All @@ -24,5 +25,5 @@ import (

func main() {
ctx, cancel := context.WithCancel(context.Background())
scheduler.Main(ctx, cancel, echo.New())
scheduler.Main(ctx, cancel, echo.New(), os.Args[1:])
}
7 changes: 3 additions & 4 deletions internal/core/command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package command

import (
"context"
"os"
"sync"
"time"

Expand All @@ -41,18 +40,18 @@ import (
"github.com/labstack/echo/v4"
)

func Main(ctx context.Context, cancel context.CancelFunc, router *echo.Echo) {
func Main(ctx context.Context, cancel context.CancelFunc, router *echo.Echo, args []string) {
startupTimer := startup.NewStartUpTimer(common.CoreCommandServiceKey)

// All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be added here,
// by inserting service specific flag prior to call to commonFlags.Parse().
// Example:
// flags.FlagSet.StringVar(&myvar, "m", "", "Specify a ....")
// ....
// flags.Parse(os.Args[1:])
// flags.Parse(args)
//
f := flags.New()
f.Parse(os.Args[1:])
f.Parse(args)

configuration := &config.ConfigurationStruct{}
dic := di.NewContainer(di.ServiceConstructorMap{
Expand Down
7 changes: 3 additions & 4 deletions internal/core/common_config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ const (
commonConfigDone = "IsCommonConfigReady"
)

func Main(ctx context.Context, cancel context.CancelFunc) {
func Main(ctx context.Context, cancel context.CancelFunc, args []string) {
startupTimer := startup.NewStartUpTimer(common.CoreCommonConfigServiceKey)

// All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be added here,
// by inserting service specific flag prior to call to commonFlags.Parse().
// Example:
// flags.FlagSet.StringVar(&myvar, "m", "", "Specify a ....")
// ....
// flags.Parse(os.Args[1:])
// flags.Parse(args)
//

// TODO: figure out how to eliminate registry and profile flags
f := flags.New()
f.Parse(os.Args[1:])
f.Parse(args)

var wg sync.WaitGroup
translateInterruptToCancel(ctx, &wg, cancel)
Expand Down Expand Up @@ -130,7 +130,6 @@ func Main(ctx context.Context, cancel context.CancelFunc) {
}

lc.Info("Core Common Config exiting")
os.Exit(0)
}

// translateInterruptToCancel spawns a go routine to translate the receipt of a SIGTERM signal to a call to cancel
Expand Down
10 changes: 4 additions & 6 deletions internal/core/data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package data

import (
"context"
"os"

"github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap"
"github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/flags"
"github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/handlers"
Expand All @@ -38,18 +36,18 @@ import (
"github.com/labstack/echo/v4"
)

func Main(ctx context.Context, cancel context.CancelFunc, router *echo.Echo) {
func Main(ctx context.Context, cancel context.CancelFunc, router *echo.Echo, args []string) {
startupTimer := startup.NewStartUpTimer(common.CoreDataServiceKey)

// All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be add here,
// All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be added here,
// by inserting service specific flag prior to call to commonFlags.Parse().
// Example:
// flags.FlagSet.StringVar(&myvar, "m", "", "Specify a ....")
// ....
// flags.Parse(os.Args[1:])
// flags.Parse(args)
//
f := flags.New()
f.Parse(os.Args[1:])
f.Parse(args)

configuration := &config.ConfigurationStruct{}
dic := di.NewContainer(di.ServiceConstructorMap{
Expand Down
10 changes: 4 additions & 6 deletions internal/core/keeper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ package keeper

import (
"context"
"os"

"github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap"
"github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/flags"
"github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/handlers"
Expand All @@ -28,18 +26,18 @@ import (
"github.com/labstack/echo/v4"
)

func Main(ctx context.Context, cancel context.CancelFunc, router *echo.Echo) {
func Main(ctx context.Context, cancel context.CancelFunc, router *echo.Echo, args []string) {
startupTimer := startup.NewStartUpTimer(constants.CoreKeeperServiceKey)

// All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be add here,
// All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be added here,
// by inserting service specific flag prior to call to commonFlags.Parse().
// Example:
// flags.FlagSet.StringVar(&myvar, "m", "", "Specify a ....")
// ....
// flags.Parse(os.Args[1:])
// flags.Parse(args)
//
f := flags.New()
f.Parse(os.Args[1:])
f.Parse(args)

configuration := &config.ConfigurationStruct{}
dic := di.NewContainer(di.ServiceConstructorMap{
Expand Down
10 changes: 4 additions & 6 deletions internal/core/metadata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package metadata

import (
"context"
"os"

"github.com/edgexfoundry/edgex-go"
"github.com/edgexfoundry/edgex-go/internal/core/metadata/config"
"github.com/edgexfoundry/edgex-go/internal/core/metadata/container"
Expand All @@ -39,18 +37,18 @@ import (
"github.com/labstack/echo/v4"
)

func Main(ctx context.Context, cancel context.CancelFunc, router *echo.Echo) {
func Main(ctx context.Context, cancel context.CancelFunc, router *echo.Echo, args []string) {
startupTimer := startup.NewStartUpTimer(common.CoreMetaDataServiceKey)

// All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be add here,
// All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be added here,
// by inserting service specific flag prior to call to commonFlags.Parse().
// Example:
// flags.FlagSet.StringVar(&myvar, "m", "", "Specify a ....")
// ....
// flags.Parse(os.Args[1:])
// flags.Parse(args)
//
f := flags.New()
f.Parse(os.Args[1:])
f.Parse(args)

configuration := &config.ConfigurationStruct{}
dic := di.NewContainer(di.ServiceConstructorMap{
Expand Down
4 changes: 2 additions & 2 deletions internal/security/bootstrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ const (
)

// Main function is the wrapper for the security bootstrapper main
func Main(ctx context.Context, cancel context.CancelFunc) {
func Main(ctx context.Context, cancel context.CancelFunc, args []string) {
// service key for this bootstrapper service
startupTimer := startup.NewStartUpTimer(common.SecurityBootstrapperKey)

// Common Command-line flags have been moved to command.CommonFlags, but this service doesn't use all
// the common flags so we are using our own implementation of the CommonFlags interface
f := bootstrapper.NewCommonFlags()

f.Parse(os.Args[1:])
f.Parse(args)

// find out the subcommand name before assigning the real concrete configuration
// bootstrapRedis has its own configuration settings
Expand Down
6 changes: 2 additions & 4 deletions internal/security/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package config

import (
"context"
"os"

"github.com/edgexfoundry/go-mod-core-contracts/v4/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v4/common"

Expand All @@ -38,14 +36,14 @@ import (
const securitySecretsConfigServiceKey = "secrets-config"

// Main function called from cmd/secrets-config
func Main(ctx context.Context, cancel context.CancelFunc) int {
func Main(ctx context.Context, cancel context.CancelFunc, args []string) int {

startupTimer := startup.NewStartUpTimer(securitySecretsConfigServiceKey)

// Common Command-line flags have been moved to command.CommonFlags, but this service doesn't use all
// the common flags so we are using our own implementation of the CommonFlags interface
f := command.NewCommonFlags()
f.Parse(os.Args[1:])
f.Parse(args)

lc := logger.NewClient(securitySecretsConfigServiceKey, models.ErrorLog)
configuration := &config.ConfigurationStruct{}
Expand Down
Loading
Loading