diff --git a/cmd/integrationArtifactDeploy.go b/cmd/integrationArtifactDeploy.go index 3fcb31705..2f92d3d53 100644 --- a/cmd/integrationArtifactDeploy.go +++ b/cmd/integrationArtifactDeploy.go @@ -99,7 +99,11 @@ func runIntegrationArtifactDeploy(config *integrationArtifactDeployOptions, tele log.Entry(). WithField("IntegrationFlowID", config.IntegrationFlowID). Info("successfully deployed into CPI runtime") - deploymentError := pollIFlowDeploymentStatus(retryCount, config, httpClient, serviceKey.OAuth.Host) + taskId, readErr := ioutil.ReadAll(deployResp.Body) + if readErr != nil { + return errors.Wrap(readErr, "Task Id not found. HTTP response body could not be read.") + } + deploymentError := pollIFlowDeploymentStatus(string(taskId), retryCount, config, httpClient, serviceKey.OAuth.Host) return deploymentError } responseBody, readErr := ioutil.ReadAll(deployResp.Body) @@ -112,33 +116,33 @@ func runIntegrationArtifactDeploy(config *integrationArtifactDeployOptions, tele } //pollIFlowDeploymentStatus - Poll the integration flow deployment status, return status or error details -func pollIFlowDeploymentStatus(retryCount int, config *integrationArtifactDeployOptions, httpClient piperhttp.Sender, apiHost string) error { +func pollIFlowDeploymentStatus(taskId string, retryCount int, config *integrationArtifactDeployOptions, httpClient piperhttp.Sender, apiHost string) error { if retryCount <= 0 { return errors.New("failed to start integration artifact after retrying several times") } - deployStatus, err := getIntegrationArtifactDeployStatus(config, httpClient, apiHost) + deployStatus, err := getIntegrationArtifactDeployStatus(config, httpClient, apiHost, taskId) if err != nil { return err } //if artifact starting, then retry based on provided retry count //with specific delay between each retry - if deployStatus == "STARTING" { + if deployStatus == "DEPLOYING" { // Calling Sleep method sleepTime := int(retryCount * 3) time.Sleep(time.Duration(sleepTime) * time.Second) retryCount-- - return pollIFlowDeploymentStatus(retryCount, config, httpClient, apiHost) + return pollIFlowDeploymentStatus(taskId, retryCount, config, httpClient, apiHost) } //if artifact started, then just return - if deployStatus == "STARTED" { + if deployStatus == "SUCCESS" { return nil } //if error return immediately with error details - if deployStatus == "ERROR" { + if deployStatus == "FAIL" || deployStatus == "FAIL_ON_LICENSE_ERROR" { resp, err := getIntegrationArtifactDeployError(config, httpClient, apiHost) if err != nil { return err @@ -159,12 +163,12 @@ func getHTTPErrorMessage(httpErr error, response *http.Response, httpMethod, sta } //getIntegrationArtifactDeployStatus - Get integration artifact Deploy Status -func getIntegrationArtifactDeployStatus(config *integrationArtifactDeployOptions, httpClient piperhttp.Sender, apiHost string) (string, error) { +func getIntegrationArtifactDeployStatus(config *integrationArtifactDeployOptions, httpClient piperhttp.Sender, apiHost string, taskId string) (string, error) { httpMethod := "GET" header := make(http.Header) header.Add("content-type", "application/json") header.Add("Accept", "application/json") - deployStatusURL := fmt.Sprintf("%s/api/v1/IntegrationRuntimeArtifacts('%s')", apiHost, config.IntegrationFlowID) + deployStatusURL := fmt.Sprintf("%s/api/v1/BuildAndDeployStatus(TaskId='%s')", apiHost, taskId) deployStatusResp, httpErr := httpClient.SendRequest(httpMethod, deployStatusURL, nil, header, nil) if deployStatusResp != nil && deployStatusResp.Body != nil { diff --git a/cmd/integrationArtifactDeploy_test.go b/cmd/integrationArtifactDeploy_test.go index 0f679335a..81ec17fa0 100644 --- a/cmd/integrationArtifactDeploy_test.go +++ b/cmd/integrationArtifactDeploy_test.go @@ -10,9 +10,21 @@ import ( "github.com/SAP/jenkins-library/pkg/cpi" piperhttp "github.com/SAP/jenkins-library/pkg/http" + "github.com/SAP/jenkins-library/pkg/mock" "github.com/stretchr/testify/assert" ) +type integrationArtifactDeployMockUtils struct { + *mock.ExecMockRunner +} + +func newIntegrationArtifactDeployTestsUtils() integrationArtifactDeployMockUtils { + utils := integrationArtifactDeployMockUtils{ + ExecMockRunner: &mock.ExecMockRunner{}, + } + return utils +} + func TestRunIntegrationArtifactDeploy(t *testing.T) { t.Parallel() @@ -38,7 +50,7 @@ func TestRunIntegrationArtifactDeploy(t *testing.T) { if assert.NoError(t, err) { t.Run("check url", func(t *testing.T) { - assert.Equal(t, "https://demo/api/v1/IntegrationRuntimeArtifacts('flow1')", httpClient.URL) + assert.Equal(t, "https://demo/api/v1/BuildAndDeployStatus(TaskId='')", httpClient.URL) }) t.Run("check method", func(t *testing.T) { @@ -121,7 +133,7 @@ func TestRunIntegrationArtifactDeploy(t *testing.T) { httpClient := httpMockCpis{CPIFunction: "GetIntegrationArtifactDeployStatus", Options: clientOptions, ResponseBody: ``, TestType: "PositiveAndDeployIntegrationDesigntimeArtifactResBody"} - resp, err := getIntegrationArtifactDeployStatus(&config, &httpClient, "https://demo") + resp, err := getIntegrationArtifactDeployStatus(&config, &httpClient, "https://demo", "9094d6cd-3683-4a99-794f-834ed30fcb01") assert.Equal(t, "STARTED", resp) diff --git a/pkg/cpi/mockingUtils.go b/pkg/cpi/mockingUtils.go index 92865c309..9fd248fe8 100644 --- a/pkg/cpi/mockingUtils.go +++ b/pkg/cpi/mockingUtils.go @@ -436,7 +436,7 @@ func GetCPIFunctionNameByURLCheck(url, method, testType string) string { return GetFunctionNameByTestTypeAndMethod(method, testType) case "https://demo/api/v1/DeployIntegrationDesigntimeArtifact?Id='flow1'&Version='Active'": return GetFunctionNameByTestTypeAndMethod(method, testType) - case "https://demo/api/v1/IntegrationRuntimeArtifacts('flow1')": + case "https://demo/api/v1/BuildAndDeployStatus(TaskId='')": return "GetIntegrationArtifactDeployStatus" case "https://demo/api/v1/IntegrationRuntimeArtifacts('flow1')/ErrorInformation/$value": return "GetIntegrationArtifactDeployErrorDetails" @@ -535,7 +535,7 @@ func GetIntegrationArtifactDeployStatusErrorMockResponseBody() (*http.Response, resp := http.Response{ StatusCode: 200, - Body: ioutil.NopCloser(bytes.NewReader([]byte(GetIntegrationArtifactDeployStatusPayload("ERROR")))), + Body: ioutil.NopCloser(bytes.NewReader([]byte(GetIntegrationArtifactDeployStatusPayload("FAIL")))), } return &resp, nil }