You've already forked sap-jenkins-library
							
							
				mirror of
				https://github.com/SAP/jenkins-library.git
				synced 2025-10-30 23:57:50 +02:00 
			
		
		
		
	IntegrationArtifactGetMplStatus Command (#2558)
* IntegrationArtifactGetMplStatus Command Co-authored-by: Marcus Holl <marcus.holl@sap.com>
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							3ebc21b5cb
						
					
				
				
					commit
					426c106765
				
			
							
								
								
									
										111
									
								
								cmd/integrationArtifactGetMplStatus.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								cmd/integrationArtifactGetMplStatus.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,111 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"net/http" | ||||
| 	"net/url" | ||||
|  | ||||
| 	"github.com/Jeffail/gabs/v2" | ||||
| 	"github.com/SAP/jenkins-library/pkg/command" | ||||
| 	"github.com/SAP/jenkins-library/pkg/cpi" | ||||
| 	piperhttp "github.com/SAP/jenkins-library/pkg/http" | ||||
| 	"github.com/SAP/jenkins-library/pkg/log" | ||||
| 	"github.com/SAP/jenkins-library/pkg/telemetry" | ||||
| 	"github.com/pkg/errors" | ||||
| ) | ||||
|  | ||||
| type integrationArtifactGetMplStatusUtils interface { | ||||
| 	command.ExecRunner | ||||
|  | ||||
| 	// Add more methods here, or embed additional interfaces, or remove/replace as required. | ||||
| 	// The integrationArtifactGetMplStatusUtils interface should be descriptive of your runtime dependencies, | ||||
| 	// i.e. include everything you need to be able to mock in tests. | ||||
| 	// Unit tests shall be executable in parallel (not depend on global state), and don't (re-)test dependencies. | ||||
| } | ||||
|  | ||||
| type integrationArtifactGetMplStatusUtilsBundle struct { | ||||
| 	*command.Command | ||||
|  | ||||
| 	// Embed more structs as necessary to implement methods or interfaces you add to integrationArtifactGetMplStatusUtils. | ||||
| 	// Structs embedded in this way must each have a unique set of methods attached. | ||||
| 	// If there is no struct which implements the method you need, attach the method to | ||||
| 	// integrationArtifactGetMplStatusUtilsBundle and forward to the implementation of the dependency. | ||||
| } | ||||
|  | ||||
| func newIntegrationArtifactGetMplStatusUtils() integrationArtifactGetMplStatusUtils { | ||||
| 	utils := integrationArtifactGetMplStatusUtilsBundle{ | ||||
| 		Command: &command.Command{}, | ||||
| 	} | ||||
| 	// Reroute command output to logging framework | ||||
| 	utils.Stdout(log.Writer()) | ||||
| 	utils.Stderr(log.Writer()) | ||||
| 	return &utils | ||||
| } | ||||
|  | ||||
| func integrationArtifactGetMplStatus(config integrationArtifactGetMplStatusOptions, telemetryData *telemetry.CustomData, commonPipelineEnvironment *integrationArtifactGetMplStatusCommonPipelineEnvironment) { | ||||
| 	// Utils can be used wherever the command.ExecRunner interface is expected. | ||||
| 	// It can also be used for example as a mavenExecRunner. | ||||
| 	httpClient := &piperhttp.Client{} | ||||
| 	// For HTTP calls import  piperhttp "github.com/SAP/jenkins-library/pkg/http" | ||||
| 	// and use a  &piperhttp.Client{} in a custom system | ||||
| 	// Example: step checkmarxExecuteScan.go | ||||
|  | ||||
| 	// Error situations should be bubbled up until they reach the line below which will then stop execution | ||||
| 	// through the log.Entry().Fatal() call leading to an os.Exit(1) in the end. | ||||
| 	err := runIntegrationArtifactGetMplStatus(&config, telemetryData, httpClient, commonPipelineEnvironment) | ||||
| 	if err != nil { | ||||
| 		log.Entry().WithError(err).Fatal("step execution failed") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func runIntegrationArtifactGetMplStatus(config *integrationArtifactGetMplStatusOptions, telemetryData *telemetry.CustomData, httpClient piperhttp.Sender, commonPipelineEnvironment *integrationArtifactGetMplStatusCommonPipelineEnvironment) error { | ||||
| 	clientOptions := piperhttp.ClientOptions{} | ||||
| 	httpClient.SetOptions(clientOptions) | ||||
| 	header := make(http.Header) | ||||
| 	header.Add("Accept", "application/json") | ||||
| 	mplStatusEncodedURL := fmt.Sprintf("%s/api/v1/MessageProcessingLogs?$filter=IntegrationArtifact/Id"+url.QueryEscape(" eq ")+"'%s'&$orderby="+ | ||||
| 		url.QueryEscape("LogEnd desc")+"&$top=1", config.Host, config.IntegrationFlowID) | ||||
| 	tokenParameters := cpi.TokenParameters{TokenURL: config.OAuthTokenProviderURL, Username: config.Username, Password: config.Password, Client: httpClient} | ||||
| 	token, err := cpi.CommonUtils.GetBearerToken(tokenParameters) | ||||
| 	if err != nil { | ||||
| 		return errors.Wrap(err, "failed to fetch Bearer Token") | ||||
| 	} | ||||
| 	clientOptions.Token = fmt.Sprintf("Bearer %s", token) | ||||
| 	httpClient.SetOptions(clientOptions) | ||||
| 	httpMethod := "GET" | ||||
| 	mplStatusResp, httpErr := httpClient.SendRequest(httpMethod, mplStatusEncodedURL, nil, header, nil) | ||||
| 	if httpErr != nil { | ||||
| 		return errors.Wrapf(httpErr, "HTTP %v request to %v failed with error", httpMethod, mplStatusEncodedURL) | ||||
| 	} | ||||
|  | ||||
| 	if mplStatusResp != nil && mplStatusResp.Body != nil { | ||||
| 		defer mplStatusResp.Body.Close() | ||||
| 	} | ||||
|  | ||||
| 	if mplStatusResp == nil { | ||||
| 		return errors.Errorf("did not retrieve a HTTP response: %v", httpErr) | ||||
| 	} | ||||
|  | ||||
| 	if mplStatusResp.StatusCode == 200 { | ||||
| 		bodyText, readErr := ioutil.ReadAll(mplStatusResp.Body) | ||||
| 		if readErr != nil { | ||||
| 			return errors.Wrap(readErr, "HTTP response body could not be read") | ||||
| 		} | ||||
| 		jsonResponse, parsingErr := gabs.ParseJSON([]byte(bodyText)) | ||||
| 		if parsingErr != nil { | ||||
| 			return errors.Wrapf(parsingErr, "HTTP response body could not be parsed as JSON: %v", string(bodyText)) | ||||
| 		} | ||||
| 		mplStatus := jsonResponse.Path("d.results.0.Status").Data().(string) | ||||
| 		commonPipelineEnvironment.custom.iFlowMplStatus = mplStatus | ||||
| 		return nil | ||||
| 	} | ||||
| 	responseBody, readErr := ioutil.ReadAll(mplStatusResp.Body) | ||||
|  | ||||
| 	if readErr != nil { | ||||
| 		return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", mplStatusResp.StatusCode) | ||||
| 	} | ||||
|  | ||||
| 	log.Entry().Errorf("a HTTP error occurred! Response body: %v, Response status code: %v", responseBody, mplStatusResp.StatusCode) | ||||
| 	return errors.Errorf("Unable to get integration flow MPL status, Response Status code: %v", mplStatusResp.StatusCode) | ||||
| } | ||||
							
								
								
									
										217
									
								
								cmd/integrationArtifactGetMplStatus_generated.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										217
									
								
								cmd/integrationArtifactGetMplStatus_generated.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,217 @@ | ||||
| // Code generated by piper's step-generator. DO NOT EDIT. | ||||
|  | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/SAP/jenkins-library/pkg/config" | ||||
| 	"github.com/SAP/jenkins-library/pkg/log" | ||||
| 	"github.com/SAP/jenkins-library/pkg/piperenv" | ||||
| 	"github.com/SAP/jenkins-library/pkg/telemetry" | ||||
| 	"github.com/spf13/cobra" | ||||
| ) | ||||
|  | ||||
| type integrationArtifactGetMplStatusOptions struct { | ||||
| 	Username              string `json:"username,omitempty"` | ||||
| 	Password              string `json:"password,omitempty"` | ||||
| 	IntegrationFlowID     string `json:"integrationFlowId,omitempty"` | ||||
| 	Platform              string `json:"platform,omitempty"` | ||||
| 	Host                  string `json:"host,omitempty"` | ||||
| 	OAuthTokenProviderURL string `json:"oAuthTokenProviderUrl,omitempty"` | ||||
| } | ||||
|  | ||||
| type integrationArtifactGetMplStatusCommonPipelineEnvironment struct { | ||||
| 	custom struct { | ||||
| 		iFlowMplStatus string | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p *integrationArtifactGetMplStatusCommonPipelineEnvironment) persist(path, resourceName string) { | ||||
| 	content := []struct { | ||||
| 		category string | ||||
| 		name     string | ||||
| 		value    interface{} | ||||
| 	}{ | ||||
| 		{category: "custom", name: "iFlowMplStatus", value: p.custom.iFlowMplStatus}, | ||||
| 	} | ||||
|  | ||||
| 	errCount := 0 | ||||
| 	for _, param := range content { | ||||
| 		err := piperenv.SetResourceParameter(path, resourceName, filepath.Join(param.category, param.name), param.value) | ||||
| 		if err != nil { | ||||
| 			log.Entry().WithError(err).Error("Error persisting piper environment.") | ||||
| 			errCount++ | ||||
| 		} | ||||
| 	} | ||||
| 	if errCount > 0 { | ||||
| 		log.Entry().Fatal("failed to persist Piper environment") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // IntegrationArtifactGetMplStatusCommand Get the MPL status of an integration flow | ||||
| func IntegrationArtifactGetMplStatusCommand() *cobra.Command { | ||||
| 	const STEP_NAME = "integrationArtifactGetMplStatus" | ||||
|  | ||||
| 	metadata := integrationArtifactGetMplStatusMetadata() | ||||
| 	var stepConfig integrationArtifactGetMplStatusOptions | ||||
| 	var startTime time.Time | ||||
| 	var commonPipelineEnvironment integrationArtifactGetMplStatusCommonPipelineEnvironment | ||||
|  | ||||
| 	var createIntegrationArtifactGetMplStatusCmd = &cobra.Command{ | ||||
| 		Use:   STEP_NAME, | ||||
| 		Short: "Get the MPL status of an integration flow", | ||||
| 		Long:  `With this step you can obtain information about the Message processing log status of integration flow using OData API.Learn more about the SAP Cloud Integration remote API for getting MPL status messages processed of an deployed integration artifact [here](https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/05fa2a8b31d14c11a4e72e833e5e9f7d.html).`, | ||||
| 		PreRunE: func(cmd *cobra.Command, _ []string) error { | ||||
| 			startTime = time.Now() | ||||
| 			log.SetStepName(STEP_NAME) | ||||
| 			log.SetVerbose(GeneralConfig.Verbose) | ||||
|  | ||||
| 			path, _ := os.Getwd() | ||||
| 			fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} | ||||
| 			log.RegisterHook(fatalHook) | ||||
|  | ||||
| 			err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) | ||||
| 			if err != nil { | ||||
| 				log.SetErrorCategory(log.ErrorConfiguration) | ||||
| 				return err | ||||
| 			} | ||||
| 			log.RegisterSecret(stepConfig.Username) | ||||
| 			log.RegisterSecret(stepConfig.Password) | ||||
|  | ||||
| 			if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { | ||||
| 				sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) | ||||
| 				log.RegisterHook(&sentryHook) | ||||
| 			} | ||||
|  | ||||
| 			return nil | ||||
| 		}, | ||||
| 		Run: func(_ *cobra.Command, _ []string) { | ||||
| 			telemetryData := telemetry.CustomData{} | ||||
| 			telemetryData.ErrorCode = "1" | ||||
| 			handler := func() { | ||||
| 				config.RemoveVaultSecretFiles() | ||||
| 				commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") | ||||
| 				telemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) | ||||
| 				telemetryData.ErrorCategory = log.GetErrorCategory().String() | ||||
| 				telemetry.Send(&telemetryData) | ||||
| 			} | ||||
| 			log.DeferExitHandler(handler) | ||||
| 			defer handler() | ||||
| 			telemetry.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) | ||||
| 			integrationArtifactGetMplStatus(stepConfig, &telemetryData, &commonPipelineEnvironment) | ||||
| 			telemetryData.ErrorCode = "0" | ||||
| 			log.Entry().Info("SUCCESS") | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	addIntegrationArtifactGetMplStatusFlags(createIntegrationArtifactGetMplStatusCmd, &stepConfig) | ||||
| 	return createIntegrationArtifactGetMplStatusCmd | ||||
| } | ||||
|  | ||||
| func addIntegrationArtifactGetMplStatusFlags(cmd *cobra.Command, stepConfig *integrationArtifactGetMplStatusOptions) { | ||||
| 	cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User to authenticate to the SAP Cloud Platform Integration Service") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password to authenticate to the SAP Cloud Platform Integration Service") | ||||
| 	cmd.Flags().StringVar(&stepConfig.IntegrationFlowID, "integrationFlowId", os.Getenv("PIPER_integrationFlowId"), "Specifies the ID of the Integration Flow artifact") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Platform, "platform", os.Getenv("PIPER_platform"), "Specifies the running platform of the SAP Cloud platform integraion service") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Specifies the protocol and host address, including the port. Please provide in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`.") | ||||
| 	cmd.Flags().StringVar(&stepConfig.OAuthTokenProviderURL, "oAuthTokenProviderUrl", os.Getenv("PIPER_oAuthTokenProviderUrl"), "Specifies the oAuth Provider protocol and host address, including the port. Please provide in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`.") | ||||
|  | ||||
| 	cmd.MarkFlagRequired("username") | ||||
| 	cmd.MarkFlagRequired("password") | ||||
| 	cmd.MarkFlagRequired("integrationFlowId") | ||||
| 	cmd.MarkFlagRequired("host") | ||||
| 	cmd.MarkFlagRequired("oAuthTokenProviderUrl") | ||||
| } | ||||
|  | ||||
| // retrieve step metadata | ||||
| func integrationArtifactGetMplStatusMetadata() config.StepData { | ||||
| 	var theMetaData = config.StepData{ | ||||
| 		Metadata: config.StepMetadata{ | ||||
| 			Name:        "integrationArtifactGetMplStatus", | ||||
| 			Aliases:     []config.Alias{}, | ||||
| 			Description: "Get the MPL status of an integration flow", | ||||
| 		}, | ||||
| 		Spec: config.StepSpec{ | ||||
| 			Inputs: config.StepInputs{ | ||||
| 				Parameters: []config.StepParameters{ | ||||
| 					{ | ||||
| 						Name: "username", | ||||
| 						ResourceRef: []config.ResourceReference{ | ||||
| 							{ | ||||
| 								Name:  "cpiCredentialsId", | ||||
| 								Param: "username", | ||||
| 								Type:  "secret", | ||||
| 							}, | ||||
| 						}, | ||||
| 						Scope:     []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:      "string", | ||||
| 						Mandatory: true, | ||||
| 						Aliases:   []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name: "password", | ||||
| 						ResourceRef: []config.ResourceReference{ | ||||
| 							{ | ||||
| 								Name:  "cpiCredentialsId", | ||||
| 								Param: "password", | ||||
| 								Type:  "secret", | ||||
| 							}, | ||||
| 						}, | ||||
| 						Scope:     []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:      "string", | ||||
| 						Mandatory: true, | ||||
| 						Aliases:   []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "integrationFlowId", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "platform", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "host", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "oAuthTokenProviderUrl", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Outputs: config.StepOutputs{ | ||||
| 				Resources: []config.StepResources{ | ||||
| 					{ | ||||
| 						Name: "commonPipelineEnvironment", | ||||
| 						Type: "piperEnvironment", | ||||
| 						Parameters: []map[string]interface{}{ | ||||
| 							{"Name": "custom/iFlowMplStatus"}, | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	return theMetaData | ||||
| } | ||||
							
								
								
									
										17
									
								
								cmd/integrationArtifactGetMplStatus_generated_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								cmd/integrationArtifactGetMplStatus_generated_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func TestIntegrationArtifactGetMplStatusCommand(t *testing.T) { | ||||
| 	t.Parallel() | ||||
|  | ||||
| 	testCmd := IntegrationArtifactGetMplStatusCommand() | ||||
|  | ||||
| 	// only high level testing performed - details are tested in step generation procedure | ||||
| 	assert.Equal(t, "integrationArtifactGetMplStatus", testCmd.Use, "command name incorrect") | ||||
|  | ||||
| } | ||||
							
								
								
									
										71
									
								
								cmd/integrationArtifactGetMplStatus_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								cmd/integrationArtifactGetMplStatus_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,71 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/SAP/jenkins-library/pkg/mock" | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| type integrationArtifactGetMplStatusMockUtils struct { | ||||
| 	*mock.ExecMockRunner | ||||
| 	*mock.FilesMock | ||||
| } | ||||
|  | ||||
| func newIntegrationArtifactGetMplStatusTestsUtils() integrationArtifactGetMplStatusMockUtils { | ||||
| 	utils := integrationArtifactGetMplStatusMockUtils{ | ||||
| 		ExecMockRunner: &mock.ExecMockRunner{}, | ||||
| 		FilesMock:      &mock.FilesMock{}, | ||||
| 	} | ||||
| 	return utils | ||||
| } | ||||
|  | ||||
| func TestRunIntegrationArtifactGetMplStatus(t *testing.T) { | ||||
| 	t.Parallel() | ||||
|  | ||||
| 	t.Run("Successfully Test of Get Integration Flow MPL Status", func(t *testing.T) { | ||||
| 		config := integrationArtifactGetMplStatusOptions{ | ||||
| 			Host:                  "https://demo", | ||||
| 			OAuthTokenProviderURL: "https://demo/oauth/token", | ||||
| 			Username:              "demouser", | ||||
| 			Password:              "******", | ||||
| 			IntegrationFlowID:     "flow1", | ||||
| 			Platform:              "cf", | ||||
| 		} | ||||
|  | ||||
| 		httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactGetMplStatus", ResponseBody: ``, TestType: "Positive"} | ||||
| 		seOut := integrationArtifactGetMplStatusCommonPipelineEnvironment{} | ||||
| 		err := runIntegrationArtifactGetMplStatus(&config, nil, &httpClient, &seOut) | ||||
| 		assert.EqualValues(t, seOut.custom.iFlowMplStatus, "COMPLETED") | ||||
|  | ||||
| 		if assert.NoError(t, err) { | ||||
|  | ||||
| 			t.Run("check url", func(t *testing.T) { | ||||
| 				assert.Equal(t, "https://demo/api/v1/MessageProcessingLogs?$filter=IntegrationArtifact/Id+eq+'flow1'&$orderby=LogEnd+desc&$top=1", httpClient.URL) | ||||
| 			}) | ||||
|  | ||||
| 			t.Run("check method", func(t *testing.T) { | ||||
| 				assert.Equal(t, "GET", httpClient.Method) | ||||
| 			}) | ||||
| 		} | ||||
|  | ||||
| 	}) | ||||
|  | ||||
| 	t.Run("Failed Test of Get Integration Flow MPL Status", func(t *testing.T) { | ||||
| 		config := integrationArtifactGetMplStatusOptions{ | ||||
| 			Host:                  "https://demo", | ||||
| 			OAuthTokenProviderURL: "https://demo/oauth/token", | ||||
| 			Username:              "demouser", | ||||
| 			Password:              "******", | ||||
| 			IntegrationFlowID:     "flow1", | ||||
| 			Platform:              "cf", | ||||
| 		} | ||||
|  | ||||
| 		httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactDeploy", ResponseBody: ``, TestType: "Negative"} | ||||
|  | ||||
| 		seOut := integrationArtifactGetMplStatusCommonPipelineEnvironment{} | ||||
| 		err := runIntegrationArtifactGetMplStatus(&config, nil, &httpClient, &seOut) | ||||
| 		assert.EqualValues(t, seOut.custom.iFlowMplStatus, "") | ||||
| 		assert.EqualError(t, err, "HTTP GET request to https://demo/api/v1/MessageProcessingLogs?$filter=IntegrationArtifact/Id+eq+'flow1'&$orderby=LogEnd+desc&$top=1 failed with error: Internal Server Error") | ||||
| 	}) | ||||
| } | ||||
| @@ -44,6 +44,7 @@ func GetAllStepMetadata() map[string]config.StepData { | ||||
| 		"gitopsUpdateDeployment":                  gitopsUpdateDeploymentMetadata(), | ||||
| 		"hadolintExecute":                         hadolintExecuteMetadata(), | ||||
| 		"integrationArtifactDeploy":               integrationArtifactDeployMetadata(), | ||||
| 		"integrationArtifactGetMplStatus":         integrationArtifactGetMplStatusMetadata(), | ||||
| 		"integrationArtifactUpdateConfiguration":  integrationArtifactUpdateConfigurationMetadata(), | ||||
| 		"jsonApplyPatch":                          jsonApplyPatchMetadata(), | ||||
| 		"kanikoExecute":                           kanikoExecuteMetadata(), | ||||
|   | ||||
| @@ -124,6 +124,7 @@ func Execute() { | ||||
| 	rootCmd.AddCommand(TransportRequestUploadCTSCommand()) | ||||
| 	rootCmd.AddCommand(IntegrationArtifactDeployCommand()) | ||||
| 	rootCmd.AddCommand(IntegrationArtifactUpdateConfigurationCommand()) | ||||
| 	rootCmd.AddCommand(IntegrationArtifactGetMplStatusCommand()) | ||||
|  | ||||
| 	addRootFlags(rootCmd) | ||||
| 	if err := rootCmd.Execute(); err != nil { | ||||
|   | ||||
							
								
								
									
										32
									
								
								documentation/docs/steps/integrationArtifactGetMplStatus.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								documentation/docs/steps/integrationArtifactGetMplStatus.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| # ${docGenStepName} | ||||
|  | ||||
| ## ${docGenDescription} | ||||
|  | ||||
| ## Prerequisites | ||||
|  | ||||
| ## ${docGenParameters} | ||||
|  | ||||
| ## ${docGenConfiguration} | ||||
|  | ||||
| ## ${docJenkinsPluginDependencies} | ||||
|  | ||||
| ## Example | ||||
|  | ||||
| Example configuration for the use in a `Jenkinsfile`. | ||||
|  | ||||
| ```groovy | ||||
| integrationArtifactGetMplStatus script: this | ||||
| ``` | ||||
|  | ||||
| Example for the use in a YAML configuration file (such as `.pipeline/config.yaml`). | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   <...> | ||||
|   integrationArtifactGetMplStatus: | ||||
|     cpiCredentialsId: 'MY_CPI_OAUTH_CREDENTIALSID_IN_JENKINS' | ||||
|     integrationFlowId: 'INTEGRATION_FLOW_ID' | ||||
|     platform: cf | ||||
|     host: https://CPI_HOST_ITSPACES_URL | ||||
|     oAuthTokenProviderUrl: https://CPI_HOST_OAUTH_URL | ||||
| ``` | ||||
| @@ -101,6 +101,7 @@ nav: | ||||
|         - healthExecuteCheck: steps/healthExecuteCheck.md | ||||
|         - influxWriteData: steps/influxWriteData.md | ||||
|         - integrationArtifactDeploy: steps/integrationArtifactDeploy.md | ||||
|         - integrationArtifactGetMplStatus: steps/integrationArtifactGetMplStatus.md | ||||
|         - integrationArtifactUpdateConfiguration: steps/integrationArtifactUpdateConfiguration.md | ||||
|         - jenkinsMaterializeLog: steps/jenkinsMaterializeLog.md | ||||
|         - kanikoExecute: steps/kanikoExecute.md | ||||
|   | ||||
| @@ -46,6 +46,8 @@ func GetCPIFunctionMockResponse(functionName, testType string) (*http.Response, | ||||
| 					}`))), | ||||
| 		} | ||||
| 		return &res, errors.New("Not found - either wrong version for the given Id or wrong parameter key") | ||||
| 	case "IntegrationArtifactGetMplStatus": | ||||
| 		return GetIntegrationArtifactGetMplStatusCommandMockResponse(testType) | ||||
| 	default: | ||||
| 		res := http.Response{ | ||||
| 			StatusCode: 404, | ||||
| @@ -78,3 +80,50 @@ func GetNegativeCaseHTTPResponseBodyAndErrorNil() (*http.Response, error) { | ||||
| 	} | ||||
| 	return &res, nil | ||||
| } | ||||
|  | ||||
| //GetIntegrationArtifactGetMplStatusCommandMockResponse -Provide http respose body | ||||
| func GetIntegrationArtifactGetMplStatusCommandMockResponse(testType string) (*http.Response, error) { | ||||
| 	if testType == "Positive" { | ||||
| 		res := http.Response{ | ||||
| 			StatusCode: 200, | ||||
| 			Body: ioutil.NopCloser(bytes.NewReader([]byte(`{ | ||||
| 				"d": { | ||||
| 					"results": [ | ||||
| 						{ | ||||
| 							"__metadata": { | ||||
| 								"id": "https://roverpoc.it-accd002.cfapps.sap.hana.ondemand.com:443/api/v1/MessageProcessingLogs('AGAS1GcWkfBv-ZtpS6j7TKjReO7t')", | ||||
| 								"uri": "https://roverpoc.it-accd002.cfapps.sap.hana.ondemand.com:443/api/v1/MessageProcessingLogs('AGAS1GcWkfBv-ZtpS6j7TKjReO7t')", | ||||
| 								"type": "com.sap.hci.api.MessageProcessingLog" | ||||
| 							}, | ||||
| 							"MessageGuid": "AGAS1GcWkfBv-ZtpS6j7TKjReO7t", | ||||
| 							"CorrelationId": "AGAS1GevYrPodxieoYf4YSY4jd-8", | ||||
| 							"ApplicationMessageId": null, | ||||
| 							"ApplicationMessageType": null, | ||||
| 							"LogStart": "/Date(1611846759005)/", | ||||
| 							"LogEnd": "/Date(1611846759032)/", | ||||
| 							"Sender": null, | ||||
| 							"Receiver": null, | ||||
| 							"IntegrationFlowName": "flow1", | ||||
| 							"Status": "COMPLETED", | ||||
| 							"LogLevel": "INFO", | ||||
| 							"CustomStatus": "COMPLETED", | ||||
| 							"TransactionId": "aa220151116748eeae69db3e88f2bbc8" | ||||
| 						} | ||||
| 					] | ||||
| 				} | ||||
| 			}`))), | ||||
| 		} | ||||
| 		return &res, nil | ||||
| 	} | ||||
| 	res := http.Response{ | ||||
| 		StatusCode: 400, | ||||
| 		Body: ioutil.NopCloser(bytes.NewReader([]byte(`{ | ||||
| 					"code": "Bad Request", | ||||
| 					"message": { | ||||
| 					"@lang": "en", | ||||
| 					"#text": "Invalid order by expression" | ||||
| 					} | ||||
| 				}`))), | ||||
| 	} | ||||
| 	return &res, errors.New("Unable to get integration flow MPL status, Response Status code:400") | ||||
| } | ||||
|   | ||||
							
								
								
									
										77
									
								
								resources/metadata/integrationArtifactGetMplStatus.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								resources/metadata/integrationArtifactGetMplStatus.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,77 @@ | ||||
| metadata: | ||||
|   name: integrationArtifactGetMplStatus | ||||
|   description: Get the MPL status of an integration flow | ||||
|   longDescription: | | ||||
|     With this step you can obtain information about the Message processing log status of integration flow using OData API.Learn more about the SAP Cloud Integration remote API for getting MPL status messages processed of an deployed integration artifact [here](https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/05fa2a8b31d14c11a4e72e833e5e9f7d.html). | ||||
|  | ||||
| spec: | ||||
|   inputs: | ||||
|     secrets: | ||||
|       - name: cpiCredentialsId | ||||
|         description: Jenkins credentials ID containing username and password for authentication to the SAP Cloud Platform Integration API's | ||||
|         type: jenkins | ||||
|     params: | ||||
|       - name: username | ||||
|         type: string | ||||
|         description: User to authenticate to the SAP Cloud Platform Integration Service | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|         secret: true | ||||
|         resourceRef: | ||||
|           - name: cpiCredentialsId | ||||
|             type: secret | ||||
|             param: username | ||||
|       - name: password | ||||
|         type: string | ||||
|         description: Password to authenticate to the SAP Cloud Platform Integration Service | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|         secret: true | ||||
|         resourceRef: | ||||
|           - name: cpiCredentialsId | ||||
|             type: secret | ||||
|             param: password | ||||
|       - name: integrationFlowId | ||||
|         type: string | ||||
|         description: Specifies the ID of the Integration Flow artifact | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|       - name: platform | ||||
|         type: string | ||||
|         description: Specifies the running platform of the SAP Cloud platform integraion service | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: false | ||||
|       - name: host | ||||
|         type: string | ||||
|         description: Specifies the protocol and host address, including the port. Please provide in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|       - name: oAuthTokenProviderUrl | ||||
|         type: string | ||||
|         description: Specifies the oAuth Provider protocol and host address, including the port. Please provide in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|   outputs: | ||||
|     resources: | ||||
|       - name: commonPipelineEnvironment | ||||
|         type: piperEnvironment | ||||
|         params: | ||||
|           - name: custom/iFlowMplStatus | ||||
| @@ -174,6 +174,7 @@ public class CommonStepsTest extends BasePiperTest{ | ||||
|         'uiVeri5ExecuteTests', //implementing new golang pattern without fields | ||||
|         'integrationArtifactDeploy', //implementing new golang pattern without fields | ||||
|         'integrationArtifactUpdateConfiguration', //implementing new golang pattern without fields | ||||
|         'integrationArtifactGetMplStatus', //implementing new golang pattern without fields | ||||
|     ] | ||||
|  | ||||
|     @Test | ||||
|   | ||||
							
								
								
									
										11
									
								
								vars/integrationArtifactGetMplStatus.groovy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								vars/integrationArtifactGetMplStatus.groovy
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| import groovy.transform.Field | ||||
|  | ||||
| @Field String STEP_NAME = getClass().getName() | ||||
| @Field String METADATA_FILE = 'metadata/integrationArtifactGetMplStatus.yaml' | ||||
|  | ||||
| void call(Map parameters = [:]) { | ||||
|     List credentials = [ | ||||
|         [type: 'usernamePassword', id: 'cpiCredentialsId', env: ['PIPER_username', 'PIPER_password']] | ||||
|     ] | ||||
|     piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user