Skip to content

Commit 7efbc90

Browse files
authored
Merge pull request #44 from swaroopar/feature/updateXpanseApi
update xpanse API version
2 parents c901825 + a8942d3 commit 7efbc90

10 files changed

+484
-305
lines changed

clientgen/api.json

+146-118
Large diffs are not rendered by default.

go.mod

+12
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,29 @@ require (
2323
github.com/cloudflare/circl v1.3.7 // indirect
2424
github.com/cyphar/filepath-securejoin v0.3.6 // indirect
2525
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
26+
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
2627
github.com/emirpasic/gods v1.18.1 // indirect
2728
github.com/fsnotify/fsnotify v1.7.0 // indirect
29+
github.com/getkin/kin-openapi v0.127.0 // indirect
2830
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
2931
github.com/go-git/go-billy/v5 v5.6.2 // indirect
32+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
33+
github.com/go-openapi/swag v0.23.0 // indirect
3034
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3135
github.com/hashicorp/hcl v1.0.0 // indirect
3236
github.com/inconshreveable/mousetrap v1.1.0 // indirect
37+
github.com/invopop/yaml v0.3.1 // indirect
3338
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
3439
github.com/jonboulle/clockwork v0.4.0 // indirect
40+
github.com/josharian/intern v1.0.0 // indirect
3541
github.com/kevinburke/ssh_config v1.2.0 // indirect
3642
github.com/magiconair/properties v1.8.7 // indirect
43+
github.com/mailru/easyjson v0.7.7 // indirect
3744
github.com/mitchellh/mapstructure v1.5.0 // indirect
45+
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
46+
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 // indirect
3847
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
48+
github.com/perimeterx/marshmallow v1.1.5 // indirect
3949
github.com/pjbgf/sha1cd v0.3.2 // indirect
4050
github.com/pkg/errors v0.9.1 // indirect
4151
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
@@ -45,11 +55,13 @@ require (
4555
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
4656
github.com/skeema/knownhosts v1.3.0 // indirect
4757
github.com/sourcegraph/conc v0.3.0 // indirect
58+
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
4859
github.com/spf13/afero v1.11.0 // indirect
4960
github.com/spf13/cast v1.6.0 // indirect
5061
github.com/spf13/pflag v1.0.6 // indirect
5162
github.com/stretchr/objx v0.5.2 // indirect
5263
github.com/subosito/gotenv v1.6.0 // indirect
64+
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
5365
github.com/xanzy/ssh-agent v0.3.3 // indirect
5466
go.uber.org/atomic v1.9.0 // indirect
5567
go.uber.org/multierr v1.9.0 // indirect

go.sum

+111
Large diffs are not rendered by default.

pkg/ansible/manage_virtual_env.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
"xpanse-agent/pkg/logger"
1515
)
1616

17-
func createVirtualEnv(virtualEnvDir string, pythonVersion float32, moduleRequirementsFile string) error {
17+
func createVirtualEnv(virtualEnvDir string, pythonVersion string, moduleRequirementsFile string) error {
1818
var cmd *exec.Cmd
1919
var err error
2020
// Check if the virtualenv already exists
2121
if _, err = os.Stat(virtualEnvDir); !os.IsNotExist(err) {
2222
logger.Logger.Info(fmt.Sprintf("Virtual environment '%s' already exists. Installing required modules on the same.", virtualEnvDir))
2323
} else {
24-
cmd = exec.Command(fmt.Sprintf("python%.2f", pythonVersion), "-m", "venv", virtualEnvDir)
24+
cmd = exec.Command(fmt.Sprintf("python%s", pythonVersion), "-m", "venv", virtualEnvDir)
2525
err = cmd.Run()
2626
}
2727
if err != nil {

pkg/ansible/run_playbook.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func RunPlaybook(playbookName string,
2222
extraVars map[string]interface{},
2323
inventory *map[string]interface{},
2424
virtualEnvRootDir string,
25-
pythonVersion float32,
25+
pythonVersion string,
2626
manageVirtualEnv bool,
2727
requirementsFileNameInRepo string,
2828
galaxyFile string) (*results.AnsiblePlaybookJSONResults, error) {

pkg/ansible/run_playbook_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestRunPlaybook(t *testing.T) {
1515
err := config.LoadConfig("test_data/test-xpanse-agent-config.yml")
1616
assert.Nil(t, err)
1717
results, runError := RunPlaybook(
18-
"kafka-container-manage.yml", nil, nil, "/tmp/kafka-test/", 3.10, true, "requirements.txt", "requirements.yml")
18+
"kafka-container-manage.yml", nil, nil, "/tmp/kafka-test/", "3.10", true, "requirements.txt", "requirements.yml")
1919
assert.Nil(t, runError)
2020
assert.NotNil(t, results)
2121
}

pkg/executor/api_poller.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"errors"
1111
"fmt"
12+
"github.com/google/uuid"
1213
"net"
1314
"net/http"
1415
"os"
@@ -24,8 +25,13 @@ func PollXpanseApiAndExecuteChanges() error {
2425
logger.Logger.Error(clientError.Error())
2526
}
2627

28+
serviceIdUuid, err := uuid.Parse(config.LoadedConfig.ServiceId)
29+
if err != nil {
30+
return err
31+
}
32+
2733
if c != nil {
28-
resp, requestError := c.GetPendingConfigurationChangeRequestWithResponse(context.Background(), config.LoadedConfig.ServiceId, config.LoadedConfig.ResourceName)
34+
resp, requestError := c.GetPendingServiceChangeRequestWithResponse(context.Background(), serviceIdUuid, config.LoadedConfig.ResourceName)
2935
if requestError != nil {
3036
var ne net.Error
3137
if errors.As(requestError, &ne) && ne.Timeout() {
@@ -50,14 +56,14 @@ func PollXpanseApiAndExecuteChanges() error {
5056

5157
if resp.JSON400 != nil {
5258
logger.Logger.Error(strings.Join(resp.JSON400.Details, ", "))
53-
if resp.JSON400.ResultType == xpanseclient.ParametersInvalid {
59+
if resp.JSON400.ErrorType == xpanseclient.ParametersInvalid {
5460
logger.Logger.Error("Exiting agent. Agent not started with valid parameters")
5561
os.Exit(1)
5662
}
5763
}
5864
if resp.JSON400 != nil {
5965
logger.Logger.Error(strings.Join(resp.JSON400.Details, ", "))
60-
if resp.JSON400.ResultType == xpanseclient.ParametersInvalid {
66+
if resp.JSON400.ErrorType == xpanseclient.ParametersInvalid {
6167
logger.Logger.Error("Exiting agent. Agent not started with valid parameters")
6268
os.Exit(1)
6369
}

pkg/executor/result_updater.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ package executor
88
import (
99
"context"
1010
results "github.com/apenella/go-ansible/v2/pkg/execute/result/json"
11+
"github.com/google/uuid"
1112
"xpanse-agent/pkg/logger"
1213
"xpanse-agent/pkg/xpanseclient"
1314
)
1415

15-
func updateResultToXpanse(err error, ansibleOutput *results.AnsiblePlaybookJSONResults, changeId string) {
16+
func updateResultToXpanse(err error, ansibleOutput *results.AnsiblePlaybookJSONResults, changeId uuid.UUID) {
1617
var isSuccessful bool
1718
var errorString string
1819
var tasks []xpanseclient.AnsibleTaskResult
@@ -37,9 +38,9 @@ func updateResultToXpanse(err error, ansibleOutput *results.AnsiblePlaybookJSONR
3738
resultMessage = ""
3839
}
3940
tasks = append(tasks, xpanseclient.AnsibleTaskResult{
40-
IsSuccessful: &(taskSuccessful),
41+
IsSuccessful: taskSuccessful,
4142
Message: &resultMessage,
42-
Name: &name,
43+
Name: name,
4344
})
4445
}
4546
}
@@ -52,16 +53,16 @@ func updateResultToXpanse(err error, ansibleOutput *results.AnsiblePlaybookJSONR
5253
}
5354

5455
if c != nil {
55-
resp, requestError := c.UpdateConfigurationChangeResult(context.Background(), changeId, xpanseclient.ServiceConfigurationChangeResult{
56+
resp, requestError := c.UpdateServiceChangeResultWithResponse(context.Background(), changeId, xpanseclient.ServiceChangeResult{
5657
Error: &errorString,
57-
IsSuccessful: &isSuccessful,
58+
IsSuccessful: isSuccessful,
5859
Tasks: &tasks,
5960
})
6061
if requestError != nil {
6162
logger.Logger.Error(requestError.Error())
6263
}
6364
if resp != nil {
64-
logger.Logger.Info(resp.Status)
65+
logger.Logger.Info(resp.Status())
6566
}
6667
}
6768
}

pkg/executor/config_update_executor.go pkg/executor/service_change_executor.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,30 @@ package executor
88
import (
99
"fmt"
1010
results "github.com/apenella/go-ansible/v2/pkg/execute/result/json"
11+
"github.com/google/uuid"
1112
"xpanse-agent/pkg/ansible"
1213
"xpanse-agent/pkg/git"
1314
"xpanse-agent/pkg/logger"
1415
"xpanse-agent/pkg/xpanseclient"
1516
)
1617

17-
func informPanicToXpanse(changeId string) {
18+
func informPanicToXpanse(changeId uuid.UUID) {
1819
if r := recover(); r != nil {
1920
panicError := fmt.Errorf("change request failed with error: %s", r)
2021
logger.Logger.Error(panicError.Error())
2122
updateResultToXpanse(panicError, nil, changeId)
2223
}
2324
}
2425

25-
func ConfigUpdate(request xpanseclient.ServiceConfigurationChangeRequest) error {
26-
defer informPanicToXpanse(request.ChangeId.String())
26+
func ConfigUpdate(request xpanseclient.ServiceChangeRequest) error {
27+
defer informPanicToXpanse(request.ChangeId)
2728
var err error
2829
var result *results.AnsiblePlaybookJSONResults
2930
err = git.CloneRepository(request.AnsibleScriptConfig.RepoUrl,
3031
request.AnsibleScriptConfig.Branch)
3132
if err == nil {
3233
result, err = ansible.RunPlaybook(request.AnsibleScriptConfig.PlaybookName,
33-
*request.ConfigParameters,
34+
request.ServiceChangeParameters,
3435
request.AnsibleInventory,
3536
request.AnsibleScriptConfig.VirtualEnv,
3637
request.AnsibleScriptConfig.PythonVersion,
@@ -39,6 +40,6 @@ func ConfigUpdate(request xpanseclient.ServiceConfigurationChangeRequest) error
3940
request.AnsibleScriptConfig.GalaxyFile,
4041
)
4142
}
42-
updateResultToXpanse(err, result, request.ChangeId.String())
43+
updateResultToXpanse(err, result, request.ChangeId)
4344
return err
4445
}

0 commit comments

Comments
 (0)