Skip to content

Commit cde5ee8

Browse files
Service Resource
1 parent 9229ae9 commit cde5ee8

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

inttests/service_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ import (
1919
)
2020

2121
func TestDeployeService(t *testing.T) {
22-
templates, err := GC.DeployService("Test-Create", "Test", "8150d563-639d-464e-80c4-a435ed10f132", "8aaaee208c8c467e018cd37813250614")
23-
assert.Nil(t, err)
24-
assert.NotNil(t, templates)
22+
deployments, err := GC.DeployService("Test-Create", "Test", "8150d563-639d-464e-80c4-a435ed10f132", "8aaaee208c8c467e018cd37813250614")
23+
assert.NotNil(t, err)
24+
assert.Nil(t, deployments)
2525
}
2626

2727
func TestGetAllDeployeService(t *testing.T) {
28-
templates, err := GC.GetAllServiceDetails()
28+
deployments, err := GC.GetAllServiceDetails()
2929
assert.Nil(t, err)
30-
assert.NotNil(t, templates)
30+
assert.NotNil(t, deployments)
3131

32-
if len(templates) > 0 {
33-
template, err := GC.GetServiceDetailsByID(templates[0].ID, false)
32+
if len(deployments) > 0 {
33+
template, err := GC.GetServiceDetailsByID(deployments[0].ID, false)
3434
assert.Nil(t, err)
3535
assert.NotNil(t, template)
3636

37-
_, err = GC.UpdateService(templates[0].ID, "Test-Update - Krunal", "Test-Update - Krunal", 1)
37+
_, err = GC.UpdateService(deployments[0].ID, "Test-Update-K", "Test-Update-K", 1)
3838
assert.Nil(t, err)
3939
}
4040

@@ -44,12 +44,12 @@ func TestGetAllDeployeService(t *testing.T) {
4444
}
4545

4646
func TestGetDeployeServiceByName(t *testing.T) {
47-
templates, err := GC.GetAllServiceDetails()
47+
deployments, err := GC.GetAllServiceDetails()
4848
assert.Nil(t, err)
49-
assert.NotNil(t, templates)
49+
assert.NotNil(t, deployments)
5050

51-
if len(templates) > 0 {
52-
template, err := GC.GetServiceDetailsByFilter(templates[0].DeploymentName, "name")
51+
if len(deployments) > 0 {
52+
template, err := GC.GetServiceDetailsByFilter(deployments[0].DeploymentName, "name")
5353
assert.Nil(t, err)
5454
assert.NotNil(t, template)
5555
}

service.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,20 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
164164

165165
if httpResp.StatusCode == 200 {
166166

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+
167176
var deploymentPayloadJson []byte
168177

169-
if nodes > 0 {
178+
nodeDiff := nodes - deployedNodes
179+
180+
if nodeDiff > 0 && nodeDiff == 1 {
170181

171182
var deploymentData map[string]interface{}
172183

@@ -184,14 +195,12 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
184195
// Access the "components" field
185196
serviceTemplate, ok := deploymentData["serviceTemplate"].(map[string]interface{})
186197
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")
189199
}
190200

191201
components, ok := serviceTemplate["components"].([]interface{})
192202
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")
195204
}
196205

197206
// Find the component with type "SERVER"
@@ -225,8 +234,7 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
225234
// Deep copy resources
226235
resources, ok := clonedComponent["resources"].([]interface{})
227236
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")
230238
}
231239

232240
clonedResources := make([]interface{}, len(resources))
@@ -257,8 +265,7 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
257265

258266
parameters, ok := comp["parameters"].([]interface{})
259267
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")
262269
}
263270

264271
clonedParams := make([]interface{}, len(parameters))
@@ -306,7 +313,7 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
306313
// Marshal deploymentData to JSON
307314
deploymentPayloadJson, _ = json.Marshal(deploymentData)
308315

309-
} else {
316+
} else if nodeDiff == 0 {
310317

311318
deploymentResponse, jsonParseError := jsonToMap(responseString)
312319
if jsonParseError != nil {
@@ -318,12 +325,10 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
318325
deploymentResponse["deploymentDescription"] = deploymentDesc
319326

320327
deploymentPayloadJson, _ = json.Marshal(deploymentResponse)
328+
} else if nodeDiff > 1 || nodeDiff < 0 {
329+
return nil, fmt.Errorf("node difference is more than 1")
321330
}
322331

323-
fmt.Println("==================================")
324-
325-
fmt.Println(string(deploymentPayloadJson))
326-
327332
req, httpError := http.NewRequest("PUT", gc.host+"/Api/V1/Deployment/"+deploymentID, bytes.NewBuffer(deploymentPayloadJson))
328333
if httpError != nil {
329334
return nil, httpError
@@ -376,8 +381,6 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
376381
return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", deploymentResponse.Messages[0].DisplayMessage)
377382
}
378383

379-
//return nil, fmt.Errorf("Error While Parsing Response Data For Deployment:")
380-
381384
} else {
382385
var deploymentResponse types.ServiceFailedResponse
383386

0 commit comments

Comments
 (0)