@@ -164,9 +164,20 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
164
164
165
165
if httpResp .StatusCode == 200 {
166
166
167
+ var deploymentResponse types.ServiceResponse
168
+
169
+ parseError := json .Unmarshal ([]byte (responseString ), & deploymentResponse )
170
+ if parseError != nil {
171
+ return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment: %s" , parseError )
172
+ }
173
+
174
+ deployedNodes := deploymentResponse .ServiceTemplate .ServerCount
175
+
167
176
var deploymentPayloadJson []byte
168
177
169
- if nodes > 0 {
178
+ nodeDiff := nodes - deployedNodes
179
+
180
+ if nodeDiff > 0 && nodeDiff == 1 {
170
181
171
182
var deploymentData map [string ]interface {}
172
183
@@ -184,14 +195,12 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
184
195
// Access the "components" field
185
196
serviceTemplate , ok := deploymentData ["serviceTemplate" ].(map [string ]interface {})
186
197
if ! ok {
187
- fmt .Println ("Error: serviceTemplate field not found or not a map[string]interface{}" )
188
- return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment: %s" , ok )
198
+ return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment" )
189
199
}
190
200
191
201
components , ok := serviceTemplate ["components" ].([]interface {})
192
202
if ! ok {
193
- fmt .Println ("Error: components field not found or not a []interface{}" )
194
- return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment: %s" , ok )
203
+ return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment" )
195
204
}
196
205
197
206
// Find the component with type "SERVER"
@@ -225,8 +234,7 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
225
234
// Deep copy resources
226
235
resources , ok := clonedComponent ["resources" ].([]interface {})
227
236
if ! ok {
228
- fmt .Println ("Error: resources field not found or not a []interface{}" )
229
- return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment: %s" , ok )
237
+ return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment" )
230
238
}
231
239
232
240
clonedResources := make ([]interface {}, len (resources ))
@@ -257,8 +265,7 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
257
265
258
266
parameters , ok := comp ["parameters" ].([]interface {})
259
267
if ! ok {
260
- fmt .Println ("Error: components field not found or not a []interface{}" )
261
- return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment: %s" , ok )
268
+ return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment" )
262
269
}
263
270
264
271
clonedParams := make ([]interface {}, len (parameters ))
@@ -306,7 +313,7 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
306
313
// Marshal deploymentData to JSON
307
314
deploymentPayloadJson , _ = json .Marshal (deploymentData )
308
315
309
- } else {
316
+ } else if nodeDiff == 0 {
310
317
311
318
deploymentResponse , jsonParseError := jsonToMap (responseString )
312
319
if jsonParseError != nil {
@@ -318,12 +325,10 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
318
325
deploymentResponse ["deploymentDescription" ] = deploymentDesc
319
326
320
327
deploymentPayloadJson , _ = json .Marshal (deploymentResponse )
328
+ } else if nodeDiff > 1 || nodeDiff < 0 {
329
+ return nil , fmt .Errorf ("node difference is more than 1" )
321
330
}
322
331
323
- fmt .Println ("==================================" )
324
-
325
- fmt .Println (string (deploymentPayloadJson ))
326
-
327
332
req , httpError := http .NewRequest ("PUT" , gc .host + "/Api/V1/Deployment/" + deploymentID , bytes .NewBuffer (deploymentPayloadJson ))
328
333
if httpError != nil {
329
334
return nil , httpError
@@ -376,8 +381,6 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
376
381
return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment: %s" , deploymentResponse .Messages [0 ].DisplayMessage )
377
382
}
378
383
379
- //return nil, fmt.Errorf("Error While Parsing Response Data For Deployment:")
380
-
381
384
} else {
382
385
var deploymentResponse types.ServiceFailedResponse
383
386
0 commit comments