-
Notifications
You must be signed in to change notification settings - Fork 583
/
abapEnvironmentCreateSystem.go
133 lines (115 loc) · 4.69 KB
/
abapEnvironmentCreateSystem.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package cmd
import (
"encoding/json"
"fmt"
"github.com/SAP/jenkins-library/pkg/abaputils"
"github.com/SAP/jenkins-library/pkg/cloudfoundry"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/google/uuid"
)
func abapEnvironmentCreateSystem(config abapEnvironmentCreateSystemOptions, telemetryData *telemetry.CustomData) {
cf := cloudfoundry.CFUtils{Exec: &command.Command{}}
u := &googleUUID{}
// error situations should stop execution through log.Entry().Fatal() call which leads to an os.Exit(1) in the end
err := runAbapEnvironmentCreateSystem(&config, telemetryData, cf, u)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runAbapEnvironmentCreateSystem(config *abapEnvironmentCreateSystemOptions, telemetryData *telemetry.CustomData, cf cloudfoundry.CFUtils, u uuidGenerator) error {
if config.ServiceManifest != "" {
// if the manifest file is provided, it is directly passed through to cloudFoundryCreateService
createServiceConfig := cloudFoundryCreateServiceOptions{
CfAPIEndpoint: config.CfAPIEndpoint,
CfOrg: config.CfOrg,
CfSpace: config.CfSpace,
Username: config.Username,
Password: config.Password,
ServiceManifest: config.ServiceManifest,
}
return runCloudFoundryCreateService(&createServiceConfig, telemetryData, cf)
}
cfConfig, err := generateServiceParameterString(config)
if err != nil {
log.Entry().Fatalf("Could not generate parameter string")
}
// Calling cloudFoundryCreateService with the respective parameters
createServiceConfig := cloudFoundryCreateServiceOptions{
CfAPIEndpoint: config.CfAPIEndpoint,
CfOrg: config.CfOrg,
CfSpace: config.CfSpace,
Username: config.Username,
Password: config.Password,
CfService: config.CfService,
CfServicePlan: config.CfServicePlan,
CfServiceInstanceName: config.CfServiceInstance,
CfCreateServiceConfig: cfConfig,
CfAsync: false,
}
return runCloudFoundryCreateService(&createServiceConfig, telemetryData, cf)
}
func generateServiceParameterString(config *abapEnvironmentCreateSystemOptions) (string, error) {
addonProduct := ""
addonVersion := ""
parentSaaSAppName := ""
if config.AddonDescriptorFileName != "" && config.IncludeAddon {
descriptor, err := abaputils.ReadAddonDescriptor(config.AddonDescriptorFileName)
if err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return "", fmt.Errorf("Cloud not read addonProduct and addonVersion from %s: %w", config.AddonDescriptorFileName, err)
}
addonProduct = descriptor.AddonProduct
addonVersion = descriptor.AddonVersionYAML
parentSaaSAppName = "addon_test"
}
params := abapSystemParameters{
AdminEmail: config.AbapSystemAdminEmail,
Description: config.AbapSystemDescription,
IsDevelopmentAllowed: &config.AbapSystemIsDevelopmentAllowed,
SapSystemName: config.AbapSystemID,
SizeOfPersistence: config.AbapSystemSizeOfPersistence,
SizeOfRuntime: config.AbapSystemSizeOfRuntime,
AddonProductName: addonProduct,
AddonProductVersion: addonVersion,
ParentSaaSAppName: parentSaaSAppName,
}
serviceParameters, err := json.Marshal(params)
serviceParametersString := string(serviceParameters)
log.Entry().Debugf("Service Parameters: %s", serviceParametersString)
if err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return "", fmt.Errorf("Could not generate parameter string for the cloud foundry cli: %w", err)
}
return serviceParametersString, nil
}
type abapSystemParameters struct {
AdminEmail string `json:"admin_email,omitempty"`
Description string `json:"description,omitempty"`
IsDevelopmentAllowed *bool `json:"is_development_allowed,omitempty"`
SapSystemName string `json:"sapsystemname,omitempty"`
SizeOfPersistence int `json:"size_of_persistence,omitempty"`
SizeOfRuntime int `json:"size_of_runtime,omitempty"`
AddonProductName string `json:"addon_product_name,omitempty"`
AddonProductVersion string `json:"addon_product_version,omitempty"`
ParentSaaSAppName string `json:"parent_saas_appname,omitempty"`
}
type serviceManifest struct {
CreateServices []Service `json:"create-services"`
}
// Service struct for creating a cloud foundry service
type Service struct {
Name string `json:"name"`
Broker string `json:"broker"`
Plan string `json:"plan"`
Parameters string `json:"parameters,omitempty"`
}
type uuidGenerator interface {
getUUID() string
}
type googleUUID struct {
}
func (u *googleUUID) getUUID() string {
return uuid.New().String()
}