Skip to content

Commit 30dd4da

Browse files
committed
Added platform and backend constants
Signed-off-by: Tobias Stocker <tstocker@student.ethz.ch>
1 parent 8deb397 commit 30dd4da

File tree

15 files changed

+59
-42
lines changed

15 files changed

+59
-42
lines changed

cmd/loader.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"flag"
2929
"fmt"
3030
"os"
31-
"strings"
3231
"time"
3332

3433
"github.com/vhive-serverless/loader/pkg/generator"
@@ -92,17 +91,16 @@ func main() {
9291
}
9392

9493
supportedPlatforms := []string{
95-
"Knative",
96-
"OpenWhisk",
97-
"AWSLambda",
98-
"Dirigent",
94+
common.PlatformKnative,
95+
common.PlatformOpenWhisk,
96+
common.PlatformAWSLambda,
97+
common.PlatformDirigent,
9998
}
100-
10199
if !slices.Contains(supportedPlatforms, cfg.Platform) {
102100
log.Fatal("Unsupported platform!")
103101
}
104102

105-
if cfg.Platform == "Knative" {
103+
if cfg.Platform == common.PlatformKnative {
106104
common.CheckCPULimit(cfg.CPULimit)
107105
}
108106

@@ -151,7 +149,7 @@ func parseYAMLSpecification(cfg *config.LoaderConfiguration) string {
151149
case "firecracker":
152150
return "workloads/firecracker/trace_func_go.yaml"
153151
default:
154-
if strings.ToLower(cfg.Platform) != "dirigent" {
152+
if cfg.Platform == common.PlatformDirigent {
155153
log.Fatal("Invalid 'YAMLSelector' parameter.")
156154
}
157155
}

pkg/common/constants.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,16 @@ const (
105105
)
106106

107107
var ValidCPULimits = []string{CPULimit1vCPU, CPULimitGCP}
108+
109+
// platform
110+
const (
111+
PlatformKnative string = "knative"
112+
PlatformDirigent string = "dirigent"
113+
PlatformOpenWhisk string = "openwhisk"
114+
PlatformAWSLambda string = "awslambda"
115+
)
116+
117+
// dirigent backend
118+
const (
119+
BackendDandelion string = "dandelion"
120+
)

pkg/config/parser.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ package config
2626

2727
import (
2828
"encoding/json"
29+
"github.com/vhive-serverless/loader/pkg/common"
2930
"os"
31+
"strings"
3032

3133
log "github.com/sirupsen/logrus"
3234
)
@@ -127,6 +129,9 @@ func ReadConfigurationFile(path string) LoaderConfiguration {
127129
log.Fatal(err)
128130
}
129131

132+
// set to lower in order to always match constants
133+
config.Platform = strings.ToLower(config.Platform)
134+
130135
return config
131136
}
132137

@@ -164,7 +169,7 @@ func ReadWorkflowConfig(path string) WorkflowConfig {
164169
}
165170

166171
func ReadDirigentConfig(cfg *LoaderConfiguration) *DirigentConfig {
167-
if cfg.Platform != "Dirigent" {
172+
if cfg.Platform != common.PlatformDirigent {
168173
return nil
169174
}
170175

pkg/config/parser_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ package config
2626

2727
import (
2828
"fmt"
29+
"github.com/vhive-serverless/loader/pkg/common"
2930
"os"
3031
"strings"
3132
"testing"
@@ -45,7 +46,7 @@ func TestConfigParser(t *testing.T) {
4546
config := ReadConfigurationFile(pathToConfigFile)
4647

4748
if config.Seed != 42 ||
48-
config.Platform != "Knative" ||
49+
config.Platform != common.PlatformKnative ||
4950
config.YAMLSelector != "container" ||
5051
config.EndpointPort != 80 ||
5152
!strings.HasPrefix(config.TracePath, "data/traces/example") ||

pkg/driver/clients/grpc_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (i *grpcInvoker) Invoke(function *common.Function, runtimeSpec *common.Runt
137137

138138
var dialOptions []grpc.DialOption
139139
dialOptions = append(dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))
140-
if strings.Contains(strings.ToLower(i.cfg.Platform), "dirigent") {
140+
if strings.Contains(i.cfg.Platform, common.PlatformDirigent) {
141141
dialOptions = append(dialOptions, grpc.WithAuthority(function.Name)) // Dirigent specific
142142
}
143143
if i.cfg.EnableZipkinTracing {

pkg/driver/clients/grpc_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242

4343
func createFakeLoaderConfiguration() *config.LoaderConfiguration {
4444
return &config.LoaderConfiguration{
45-
Platform: "Knative",
45+
Platform: common.PlatformKnative,
4646
InvokeProtocol: "grpc",
4747
OutputPathPrefix: "test",
4848
EnableZipkinTracing: true,
@@ -52,7 +52,7 @@ func createFakeLoaderConfiguration() *config.LoaderConfiguration {
5252
}
5353
func createFakeVSwarmLoaderConfiguration() *config.LoaderConfiguration {
5454
return &config.LoaderConfiguration{
55-
Platform: "Knative",
55+
Platform: common.PlatformKnative,
5656
InvokeProtocol: "grpc",
5757
OutputPathPrefix: "test",
5858
EnableZipkinTracing: true,

pkg/driver/clients/http_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func newHTTPInvoker(cfg *config.Configuration) *httpInvoker {
4444
loaderCfg: lcfg,
4545
dirigentCfg: dcfg,
4646

47-
isKnative: strings.Contains(strings.ToLower(lcfg.Platform), "knative"),
48-
isDandelion: strings.Contains(strings.ToLower(dcfg.Backend), "dandelion"),
47+
isKnative: strings.Contains(strings.ToLower(lcfg.Platform), common.PlatformKnative),
48+
isDandelion: strings.Contains(strings.ToLower(dcfg.Backend), common.BackendDandelion),
4949
isWorkflow: dcfg.Workflow,
5050
}
5151
}

pkg/driver/clients/invoker.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ type Invoker interface {
1515
}
1616

1717
func CreateInvoker(cfg *config.Configuration, announceDoneExe *sync.WaitGroup, readOpenWhiskMetadata *sync.Mutex) Invoker {
18-
switch cfg.LoaderConfiguration.Platform {
19-
case "AWSLambda":
18+
switch strings.ToLower(cfg.LoaderConfiguration.Platform) {
19+
case common.PlatformAWSLambda:
2020
return newAWSLambdaInvoker(announceDoneExe)
21-
case "Dirigent":
21+
case common.PlatformDirigent:
2222
if cfg.DirigentConfiguration == nil {
2323
logrus.Fatal("Failed to create invoker: dirigent configuration is required for platform 'dirigent'")
2424
}
25-
if strings.ToLower(cfg.DirigentConfiguration.Backend) == "dandelion" || cfg.LoaderConfiguration.InvokeProtocol != "grpc" {
25+
if strings.ToLower(cfg.DirigentConfiguration.Backend) == common.BackendDandelion || cfg.LoaderConfiguration.InvokeProtocol != "grpc" {
2626
return newHTTPInvoker(cfg)
2727
} else {
2828
return newGRPCInvoker(cfg.LoaderConfiguration, ExecutorRPC{})
2929
}
30-
case "Knative":
30+
case common.PlatformKnative:
3131
if cfg.LoaderConfiguration.InvokeProtocol == "grpc" {
3232
if !cfg.LoaderConfiguration.VSwarm {
3333
return newGRPCInvoker(cfg.LoaderConfiguration, ExecutorRPC{})
@@ -37,7 +37,7 @@ func CreateInvoker(cfg *config.Configuration, announceDoneExe *sync.WaitGroup, r
3737
} else {
3838
return newHTTPInvoker(cfg)
3939
}
40-
case "OpenWhisk":
40+
case common.PlatformOpenWhisk:
4141
return newOpenWhiskInvoker(announceDoneExe, readOpenWhiskMetadata)
4242
default:
4343
logrus.Fatal("Unsupported platform.")

pkg/driver/deployment/deployer.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package deployment
22

33
import (
44
"github.com/sirupsen/logrus"
5+
"github.com/vhive-serverless/loader/pkg/common"
56
"github.com/vhive-serverless/loader/pkg/config"
67
)
78

@@ -12,13 +13,13 @@ type FunctionDeployer interface {
1213

1314
func CreateDeployer(cfg *config.Configuration) FunctionDeployer {
1415
switch cfg.LoaderConfiguration.Platform {
15-
case "AWSLambda":
16+
case common.PlatformAWSLambda:
1617
return newAWSLambdaDeployer()
17-
case "Dirigent":
18-
return newDirigentDeployer(cfg.DirigentConfiguration.Workflow)
19-
case "Knative":
18+
case common.PlatformDirigent:
19+
return newDirigentDeployer()
20+
case common.PlatformKnative:
2021
return newKnativeDeployer()
21-
case "OpenWhisk":
22+
case common.PlatformOpenWhisk:
2223
return newOpenWhiskDeployer()
2324
default:
2425
logrus.Fatal("Unsupported platform.")

pkg/driver/deployment/dirigent.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@ import (
1818
"time"
1919
)
2020

21-
type dirigentDeployer struct {
22-
deployWorkflow bool
23-
}
21+
type dirigentDeployer struct{}
2422

2523
type dirigentDeploymentConfiguration struct {
2624
RegistrationServer string
25+
deployWorkflow bool
2726
}
2827

29-
func newDirigentDeployer(deployWorkflow bool) *dirigentDeployer {
30-
return &dirigentDeployer{
31-
deployWorkflow: deployWorkflow,
32-
}
28+
func newDirigentDeployer() *dirigentDeployer {
29+
return &dirigentDeployer{}
3330
}
3431

3532
func newDirigentDeployerConfiguration(cfg *config.Configuration) dirigentDeploymentConfiguration {
3633
return dirigentDeploymentConfiguration{
3734
RegistrationServer: cfg.DirigentConfiguration.DirigentControlPlaneIP,
35+
deployWorkflow: cfg.DirigentConfiguration.Workflow,
3836
}
3937
}
4038

@@ -43,7 +41,7 @@ func (d *dirigentDeployer) Deploy(cfg *config.Configuration) {
4341

4442
endpoint := ""
4543

46-
if d.deployWorkflow {
44+
if dirigentDeployerConfig.deployWorkflow {
4745
wfConfigPath := cfg.DirigentConfiguration.WorkflowConfigPath
4846
if wfConfigPath == "" {
4947
log.Fatalf("Failed to deploy workflow: no workflow config path specified in config file.")

0 commit comments

Comments
 (0)