@@ -97,45 +97,33 @@ func (a *VMCloudAPIClient) GetDeploymentDetails(ctx context.Context, deploymentI
9797
9898// CreateDeployment creates a new deployment in VictoriaMetrics Cloud based on the provided deployment configuration.
9999func (a * VMCloudAPIClient ) CreateDeployment (ctx context.Context , deployment DeploymentCreationRequest ) (DeploymentInfo , error ) {
100- if deployment .Name == "" {
101- return DeploymentInfo {}, fmt .Errorf ("deployment name cannot be empty" )
102- }
103- if deployment .Type != DeploymentTypeSingleNode && deployment .Type != DeploymentTypeCluster {
104- return DeploymentInfo {}, fmt .Errorf ("invalid deployment type: %s" , deployment .Type )
105- }
106- if deployment .Region == "" {
107- return DeploymentInfo {}, fmt .Errorf ("deployment region cannot be empty" )
108- }
109- if deployment .Tier == 0 {
110- return DeploymentInfo {}, fmt .Errorf ("deployment tier cannot be empty" )
111- }
112- if deployment .Provider != DeploymentCloudProviderAWS {
113- return DeploymentInfo {}, fmt .Errorf ("unsupported deployment cloud provider: %s" , deployment .Provider )
114- }
115- if deployment .MaintenanceWindow != MaintenanceWindowWeekendDays && deployment .MaintenanceWindow != MaintenanceWindowBusinessDays {
116- return DeploymentInfo {}, fmt .Errorf ("invalid maintenance window: %s" , deployment .MaintenanceWindow )
117- }
118- if deployment .StorageSize == 0 {
119- return DeploymentInfo {}, fmt .Errorf ("deployment storage size cannot be zero" )
120- }
121- if deployment .StorageSizeUnit != StorageUnitGB && deployment .StorageSizeUnit != StorageUnitTB {
122- return DeploymentInfo {}, fmt .Errorf ("invalid storage size unit: %s" , deployment .StorageSizeUnit )
123- }
124- if deployment .StorageSizeUnit == StorageUnitGB && deployment .StorageSize < 10 {
125- return DeploymentInfo {}, fmt .Errorf ("deployment storage size must be at least 10 GB" )
126- }
127- if deployment .Type == DeploymentTypeSingleNode && deployment .StorageSizeUnit == StorageUnitTB && deployment .StorageSize > 16 {
128- return DeploymentInfo {}, fmt .Errorf ("single-node deployments cannot have more than 16 TB of storage" )
129- }
130- if deployment .Retention == 0 {
131- return DeploymentInfo {}, fmt .Errorf ("deployment retention cannot be zero" )
132- }
133- if deployment .RetentionUnit != DurationUnitDay && deployment .RetentionUnit != DurationUnitMonth {
134- return DeploymentInfo {}, fmt .Errorf ("invalid retention unit: %s, only days and months are supported" , deployment .RetentionUnit )
100+ // Validate common parameters
101+ err := validateCommonDeploymentParams (
102+ deployment .Name ,
103+ deployment .Tier ,
104+ deployment .MaintenanceWindow ,
105+ deployment .StorageSize ,
106+ deployment .StorageSizeUnit ,
107+ deployment .Retention ,
108+ deployment .RetentionUnit ,
109+ deployment .DeduplicationUnit ,
110+ )
111+ if err != nil {
112+ return DeploymentInfo {}, err
135113 }
136- if deployment .DeduplicationUnit != DurationUnitSecond && deployment .DeduplicationUnit != DurationUnitMillisecond {
137- return DeploymentInfo {}, fmt .Errorf ("invalid deduplication unit: %s, only seconds and milliseconds are supported" , deployment .DeduplicationUnit )
114+
115+ // Validate creation-specific parameters
116+ err = validateCreateDeploymentParams (
117+ deployment .Type ,
118+ deployment .Region ,
119+ deployment .Provider ,
120+ deployment .StorageSize ,
121+ deployment .StorageSizeUnit ,
122+ )
123+ if err != nil {
124+ return DeploymentInfo {}, err
138125 }
126+
139127 body , err := json .Marshal (deployment )
140128 if err != nil {
141129 return DeploymentInfo {}, fmt .Errorf ("failed to marshal deployment create request: %w" , err )
@@ -148,33 +136,22 @@ func (a *VMCloudAPIClient) UpdateDeployment(ctx context.Context, deploymentID st
148136 if err := checkDeploymentID (deploymentID ); err != nil {
149137 return DeploymentInfo {}, err
150138 }
151- if deployment .Name == "" {
152- return DeploymentInfo {}, fmt .Errorf ("deployment name cannot be empty" )
153- }
154- if deployment .Tier == 0 {
155- return DeploymentInfo {}, fmt .Errorf ("deployment tier cannot be empty" )
156- }
157- if deployment .MaintenanceWindow != MaintenanceWindowWeekendDays && deployment .MaintenanceWindow != MaintenanceWindowBusinessDays {
158- return DeploymentInfo {}, fmt .Errorf ("invalid maintenance window: %s" , deployment .MaintenanceWindow )
159- }
160- if deployment .StorageSize == 0 {
161- return DeploymentInfo {}, fmt .Errorf ("deployment storage size cannot be zero" )
162- }
163- if deployment .StorageSizeUnit != StorageUnitGB && deployment .StorageSizeUnit != StorageUnitTB {
164- return DeploymentInfo {}, fmt .Errorf ("invalid storage size unit: %s" , deployment .StorageSizeUnit )
165- }
166- if deployment .StorageSizeUnit == StorageUnitGB && deployment .StorageSize < 10 {
167- return DeploymentInfo {}, fmt .Errorf ("deployment storage size must be at least 10 GB" )
168- }
169- if deployment .Retention == 0 {
170- return DeploymentInfo {}, fmt .Errorf ("deployment retention cannot be zero" )
171- }
172- if deployment .RetentionUnit != DurationUnitDay && deployment .RetentionUnit != DurationUnitMonth {
173- return DeploymentInfo {}, fmt .Errorf ("invalid retention unit: %s, only days and months are supported" , deployment .RetentionUnit )
174- }
175- if deployment .DeduplicationUnit != DurationUnitSecond && deployment .DeduplicationUnit != DurationUnitMillisecond {
176- return DeploymentInfo {}, fmt .Errorf ("invalid deduplication unit: %s, only seconds and milliseconds are supported" , deployment .DeduplicationUnit )
139+
140+ // Validate common parameters
141+ err := validateCommonDeploymentParams (
142+ deployment .Name ,
143+ deployment .Tier ,
144+ deployment .MaintenanceWindow ,
145+ deployment .StorageSize ,
146+ deployment .StorageSizeUnit ,
147+ deployment .Retention ,
148+ deployment .RetentionUnit ,
149+ deployment .DeduplicationUnit ,
150+ )
151+ if err != nil {
152+ return DeploymentInfo {}, err
177153 }
154+
178155 body , err := json .Marshal (deployment )
179156 if err != nil {
180157 return DeploymentInfo {}, fmt .Errorf ("failed to marshal deployment update request: %w" , err )
0 commit comments