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 
			
		
		
		
	AAKaaS: 4 create Target Vector (#2041)
* adding my steps * messy step * Update abapEnvironmentAssembly.go * clean up * change yaml * corrections * Update cloudFoundryDeploy.go * update * delete simulation step * remove simulate * Update PiperGoUtils.groovy * Update PiperGoUtils.groovy * Update CommonStepsTest.groovy * add docu * Update abapEnvironmentAssembly.md * changes due to PR * Update .gitignore * b * CV list * Update abapEnvironmentAssembly.go * testing with simulation * Update abapEnvironmentAssembly.go * remove simulation * renaming * Update mkdocs.yml * moving service key to yaml and fixing code climate * Update abapEnvironmentAssemblePackages.go * Update abapEnvironmentAssemblePackages.go * Update abapEnvironmentAssemblePackages.go * Update abapEnvironmentAssemblePackages.go * change input * Update abapEnvironmentAssemblePackages.go * change json tag * fixed error handling * documentation * Update abapEnvironmentAssemblePackages.md * Update abapEnvironmentAssemblePackages.md * fixing code climate issues * fixing code climate issues * Update abapEnvironmentAssemblePackages.yaml * fixing code climate issues * Update abapEnvironmentAssemblePackages.yaml * adding unittests * adding unittests and improved logging * yaml -> json * change scope of cfServiceKeyName * correct indentation * Update CommonStepsTest.groovy * maintain correct step order * AAKaaS publishTV * AAKaaS createTV * AAKaaS createTV #2 * AAKaaS createTV #3 Co-authored-by: rosemarieB <45030247+rosemarieB@users.noreply.github.com> Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										125
									
								
								cmd/abapAddonAssemblyKitCreateTargetVector.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								cmd/abapAddonAssemblyKitCreateTargetVector.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,125 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
|  | ||||
| 	abapbuild "github.com/SAP/jenkins-library/pkg/abap/build" | ||||
| 	"github.com/SAP/jenkins-library/pkg/abaputils" | ||||
| 	"github.com/SAP/jenkins-library/pkg/command" | ||||
| 	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" | ||||
| ) | ||||
|  | ||||
| func abapAddonAssemblyKitCreateTargetVector(config abapAddonAssemblyKitCreateTargetVectorOptions, telemetryData *telemetry.CustomData, cpe *abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment) { | ||||
| 	// for command execution use Command | ||||
| 	c := command.Command{} | ||||
| 	// reroute command output to logging framework | ||||
| 	c.Stdout(log.Writer()) | ||||
| 	c.Stderr(log.Writer()) | ||||
|  | ||||
| 	client := piperhttp.Client{} | ||||
|  | ||||
| 	// error situations should stop execution through log.Entry().Fatal() call which leads to an os.Exit(1) in the end | ||||
| 	err := runAbapAddonAssemblyKitCreateTargetVector(&config, telemetryData, &client, cpe) | ||||
| 	if err != nil { | ||||
| 		log.Entry().WithError(err).Fatal("step execution failed") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func runAbapAddonAssemblyKitCreateTargetVector(config *abapAddonAssemblyKitCreateTargetVectorOptions, telemetryData *telemetry.CustomData, client piperhttp.Sender, cpe *abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment) error { | ||||
| 	conn := new(abapbuild.Connector) | ||||
| 	conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client) | ||||
| 	var addonDescriptor abaputils.AddonDescriptor | ||||
| 	json.Unmarshal([]byte(config.AddonDescriptor), &addonDescriptor) | ||||
|  | ||||
| 	var tv targetVector | ||||
| 	err := tv.init(addonDescriptor) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	log.Entry().Infof("Create target vector for product %s version %s", addonDescriptor.AddonProduct, addonDescriptor.AddonVersionYAML) | ||||
| 	err = tv.createTargetVector(*conn) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	log.Entry().Infof("Created target vector %s", tv.ID) | ||||
| 	addonDescriptor.TargetVectorID = tv.ID | ||||
| 	log.Entry().Info("Write target vector to CommonPipelineEnvironment") | ||||
| 	toCPE, _ := json.Marshal(addonDescriptor) | ||||
| 	cpe.abap.addonDescriptor = string(toCPE) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (tv *targetVector) init(addonDescriptor abaputils.AddonDescriptor) error { | ||||
| 	if addonDescriptor.AddonProduct == "" || addonDescriptor.AddonVersion == "" || addonDescriptor.AddonSpsLevel == "" || addonDescriptor.AddonPatchLevel == "" { | ||||
| 		return errors.New("Parameters missing. Please provide product name, version, spslevel and patchlevel") | ||||
| 	} | ||||
|  | ||||
| 	tv.ProductName = addonDescriptor.AddonProduct | ||||
| 	tv.ProductVersion = addonDescriptor.AddonVersion | ||||
| 	tv.SpsLevel = addonDescriptor.AddonSpsLevel | ||||
| 	tv.PatchLevel = addonDescriptor.AddonPatchLevel | ||||
|  | ||||
| 	var tvCVs []targetVectorCV | ||||
| 	var tvCV targetVectorCV | ||||
| 	for i := range addonDescriptor.Repositories { | ||||
| 		if addonDescriptor.Repositories[i].Name == "" || addonDescriptor.Repositories[i].Version == "" || addonDescriptor.Repositories[i].SpLevel == "" || | ||||
| 			addonDescriptor.Repositories[i].PatchLevel == "" || addonDescriptor.Repositories[i].PackageName == "" { | ||||
| 			return errors.New("Parameters missing. Please provide software component name, version, splevel, patchlevel and packagename") | ||||
| 		} | ||||
| 		tvCV.ScName = addonDescriptor.Repositories[i].Name | ||||
| 		tvCV.ScVersion = addonDescriptor.Repositories[i].Version | ||||
| 		tvCV.DeliveryPackage = addonDescriptor.Repositories[i].PackageName | ||||
| 		tvCV.SpLevel = addonDescriptor.Repositories[i].SpLevel | ||||
| 		tvCV.PatchLevel = addonDescriptor.Repositories[i].PatchLevel | ||||
| 		tvCVs = append(tvCVs, tvCV) | ||||
| 	} | ||||
| 	tv.Content.TargetVectorCVs = tvCVs | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (tv *targetVector) createTargetVector(conn abapbuild.Connector) error { | ||||
| 	conn.GetToken("/odata/aas_ocs_package") | ||||
| 	tvJSON, err := json.Marshal(tv) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	appendum := "/odata/aas_ocs_package/TargetVectorSet" | ||||
| 	body, err := conn.Post(appendum, string(tvJSON)) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	var jTV jsonTargetVector | ||||
| 	json.Unmarshal(body, &jTV) | ||||
| 	tv.ID = jTV.Tv.ID | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| type jsonTargetVector struct { | ||||
| 	Tv *targetVector `json:"d"` | ||||
| } | ||||
|  | ||||
| type targetVector struct { | ||||
| 	ID             string          `json:"Id"` | ||||
| 	ProductName    string          `json:"ProductName"` | ||||
| 	ProductVersion string          `json:"ProductVersion"` | ||||
| 	SpsLevel       string          `json:"SpsLevel"` | ||||
| 	PatchLevel     string          `json:"PatchLevel"` | ||||
| 	Content        targetVectorCVs `json:"Content"` | ||||
| } | ||||
|  | ||||
| type targetVectorCV struct { | ||||
| 	ID              string `json:"Id"` | ||||
| 	ScName          string `json:"ScName"` | ||||
| 	ScVersion       string `json:"ScVersion"` | ||||
| 	DeliveryPackage string `json:"DeliveryPackage"` | ||||
| 	SpLevel         string `json:"SpLevel"` | ||||
| 	PatchLevel      string `json:"PatchLevel"` | ||||
| } | ||||
|  | ||||
| type targetVectorCVs struct { | ||||
| 	TargetVectorCVs []targetVectorCV `json:"results"` | ||||
| } | ||||
							
								
								
									
										177
									
								
								cmd/abapAddonAssemblyKitCreateTargetVector_generated.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										177
									
								
								cmd/abapAddonAssemblyKitCreateTargetVector_generated.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,177 @@ | ||||
| // 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 abapAddonAssemblyKitCreateTargetVectorOptions struct { | ||||
| 	AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"` | ||||
| 	Username                     string `json:"username,omitempty"` | ||||
| 	Password                     string `json:"password,omitempty"` | ||||
| 	AddonDescriptor              string `json:"addonDescriptor,omitempty"` | ||||
| } | ||||
|  | ||||
| type abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment struct { | ||||
| 	abap struct { | ||||
| 		addonDescriptor string | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p *abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment) persist(path, resourceName string) { | ||||
| 	content := []struct { | ||||
| 		category string | ||||
| 		name     string | ||||
| 		value    string | ||||
| 	}{ | ||||
| 		{category: "abap", name: "addonDescriptor", value: p.abap.addonDescriptor}, | ||||
| 	} | ||||
|  | ||||
| 	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") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // AbapAddonAssemblyKitCreateTargetVectorCommand This step creates a Target Vector for SPC | ||||
| func AbapAddonAssemblyKitCreateTargetVectorCommand() *cobra.Command { | ||||
| 	const STEP_NAME = "abapAddonAssemblyKitCreateTargetVector" | ||||
|  | ||||
| 	metadata := abapAddonAssemblyKitCreateTargetVectorMetadata() | ||||
| 	var stepConfig abapAddonAssemblyKitCreateTargetVectorOptions | ||||
| 	var startTime time.Time | ||||
| 	var commonPipelineEnvironment abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment | ||||
|  | ||||
| 	var createAbapAddonAssemblyKitCreateTargetVectorCmd = &cobra.Command{ | ||||
| 		Use:   STEP_NAME, | ||||
| 		Short: "This step creates a Target Vector for SPC", | ||||
| 		Long: `This step takes the Product Version and the corresponding list of Software Component Versions from the addonDescriptor in the commonPipelineEnvironment. | ||||
| With these it creates a Target Vector, which is necessary for executing the software change in ABAP Cloud Platform systems with help of the Software Provider Cockpit (SPC). | ||||
| It describes the software state, which shall be reached in the managed ABAP Cloud Platform system.`, | ||||
| 		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() { | ||||
| 				commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") | ||||
| 				telemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) | ||||
| 				telemetry.Send(&telemetryData) | ||||
| 			} | ||||
| 			log.DeferExitHandler(handler) | ||||
| 			defer handler() | ||||
| 			telemetry.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) | ||||
| 			abapAddonAssemblyKitCreateTargetVector(stepConfig, &telemetryData, &commonPipelineEnvironment) | ||||
| 			telemetryData.ErrorCode = "0" | ||||
| 			log.Entry().Info("SUCCESS") | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	addAbapAddonAssemblyKitCreateTargetVectorFlags(createAbapAddonAssemblyKitCreateTargetVectorCmd, &stepConfig) | ||||
| 	return createAbapAddonAssemblyKitCreateTargetVectorCmd | ||||
| } | ||||
|  | ||||
| func addAbapAddonAssemblyKitCreateTargetVectorFlags(cmd *cobra.Command, stepConfig *abapAddonAssemblyKitCreateTargetVectorOptions) { | ||||
| 	cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitEndpoint, "abapAddonAssemblyKitEndpoint", os.Getenv("PIPER_abapAddonAssemblyKitEndpoint"), "Base URL to the Addon Assembly Kit as a Service (AAKaaS) system") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for the Addon Assembly Kit as a Service (AAKaaS) system") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for the Addon Assembly Kit as a Service (AAKaaS) system") | ||||
| 	cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions") | ||||
|  | ||||
| 	cmd.MarkFlagRequired("abapAddonAssemblyKitEndpoint") | ||||
| 	cmd.MarkFlagRequired("username") | ||||
| 	cmd.MarkFlagRequired("password") | ||||
| 	cmd.MarkFlagRequired("addonDescriptor") | ||||
| } | ||||
|  | ||||
| // retrieve step metadata | ||||
| func abapAddonAssemblyKitCreateTargetVectorMetadata() config.StepData { | ||||
| 	var theMetaData = config.StepData{ | ||||
| 		Metadata: config.StepMetadata{ | ||||
| 			Name:    "abapAddonAssemblyKitCreateTargetVector", | ||||
| 			Aliases: []config.Alias{}, | ||||
| 		}, | ||||
| 		Spec: config.StepSpec{ | ||||
| 			Inputs: config.StepInputs{ | ||||
| 				Parameters: []config.StepParameters{ | ||||
| 					{ | ||||
| 						Name:        "abapAddonAssemblyKitEndpoint", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "username", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "password", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name: "addonDescriptor", | ||||
| 						ResourceRef: []config.ResourceReference{ | ||||
| 							{ | ||||
| 								Name:  "commonPipelineEnvironment", | ||||
| 								Param: "abap/addonDescriptor", | ||||
| 							}, | ||||
| 						}, | ||||
| 						Scope:     []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:      "string", | ||||
| 						Mandatory: true, | ||||
| 						Aliases:   []config.Alias{}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	return theMetaData | ||||
| } | ||||
							
								
								
									
										16
									
								
								cmd/abapAddonAssemblyKitCreateTargetVector_generated_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								cmd/abapAddonAssemblyKitCreateTargetVector_generated_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func TestAbapAddonAssemblyKitCreateTargetVectorCommand(t *testing.T) { | ||||
|  | ||||
| 	testCmd := AbapAddonAssemblyKitCreateTargetVectorCommand() | ||||
|  | ||||
| 	// only high level testing performed - details are tested in step generation procedure | ||||
| 	assert.Equal(t, "abapAddonAssemblyKitCreateTargetVector", testCmd.Use, "command name incorrect") | ||||
|  | ||||
| } | ||||
							
								
								
									
										144
									
								
								cmd/abapAddonAssemblyKitCreateTargetVector_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								cmd/abapAddonAssemblyKitCreateTargetVector_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,144 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/SAP/jenkins-library/pkg/abaputils" | ||||
| 	"github.com/pkg/errors" | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func TestCreateTargetVectorStep(t *testing.T) { | ||||
| 	//setup | ||||
| 	config := abapAddonAssemblyKitCreateTargetVectorOptions{} | ||||
| 	addonDescriptor := abaputils.AddonDescriptor{ | ||||
| 		AddonProduct:    "dummy", | ||||
| 		AddonVersion:    "dummy", | ||||
| 		AddonSpsLevel:   "dummy", | ||||
| 		AddonPatchLevel: "dummy", | ||||
| 		TargetVectorID:  "dummy", | ||||
| 		Repositories: []abaputils.Repository{ | ||||
| 			{ | ||||
| 				Name:        "dummy", | ||||
| 				Version:     "dummy", | ||||
| 				SpLevel:     "dummy", | ||||
| 				PatchLevel:  "dummy", | ||||
| 				PackageName: "dummy", | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	adoDesc, _ := json.Marshal(addonDescriptor) | ||||
| 	config.AddonDescriptor = string(adoDesc) | ||||
|  | ||||
| 	client := &abaputils.ClientMock{ | ||||
| 		Body: responseCreateTargetVector, | ||||
| 	} | ||||
|  | ||||
| 	cpe := abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment{} | ||||
|  | ||||
| 	t.Run("step success test", func(t *testing.T) { | ||||
| 		//act | ||||
| 		err := runAbapAddonAssemblyKitCreateTargetVector(&config, nil, client, &cpe) | ||||
| 		//assert | ||||
| 		assert.NoError(t, err, "Did not expect error") | ||||
|  | ||||
| 		resultAddonDescriptor := abaputils.AddonDescriptor{} | ||||
| 		json.Unmarshal([]byte(cpe.abap.addonDescriptor), &resultAddonDescriptor) | ||||
| 		assert.Equal(t, "W7Q00207512600000262", resultAddonDescriptor.TargetVectorID) | ||||
| 	}) | ||||
|  | ||||
| 	t.Run("step success test", func(t *testing.T) { | ||||
| 		//arrange | ||||
| 		client := &abaputils.ClientMock{ | ||||
| 			Body:  responseCreateTargetVector, | ||||
| 			Error: errors.New("dummy"), | ||||
| 		} | ||||
| 		//act | ||||
| 		err := runAbapAddonAssemblyKitCreateTargetVector(&config, nil, client, &cpe) | ||||
| 		//assert | ||||
| 		assert.Error(t, err, "Must end with error") | ||||
| 	}) | ||||
|  | ||||
| 	t.Run("step error init product", func(t *testing.T) { | ||||
| 		//arrange | ||||
| 		addonDescriptor := abaputils.AddonDescriptor{ | ||||
| 			Repositories: []abaputils.Repository{ | ||||
| 				{}, | ||||
| 			}, | ||||
| 		} | ||||
| 		adoDesc, _ := json.Marshal(addonDescriptor) | ||||
| 		config.AddonDescriptor = string(adoDesc) | ||||
| 		//act | ||||
| 		err := runAbapAddonAssemblyKitCreateTargetVector(&config, nil, client, &cpe) | ||||
| 		//assert | ||||
| 		assert.Error(t, err, "Must end with error") | ||||
| 	}) | ||||
|  | ||||
| 	t.Run("step error init component", func(t *testing.T) { | ||||
| 		//arrange | ||||
| 		addonDescriptor := abaputils.AddonDescriptor{ | ||||
| 			AddonProduct:    "dummy", | ||||
| 			AddonVersion:    "dummy", | ||||
| 			AddonSpsLevel:   "dummy", | ||||
| 			AddonPatchLevel: "dummy", | ||||
| 			TargetVectorID:  "dummy", | ||||
| 			Repositories: []abaputils.Repository{ | ||||
| 				{ | ||||
| 					Name:        "dummy", | ||||
| 					Version:     "dummy", | ||||
| 					SpLevel:     "dummy", | ||||
| 					PatchLevel:  "dummy", | ||||
| 					PackageName: "dummy", | ||||
| 				}, | ||||
| 				{}, | ||||
| 			}, | ||||
| 		} | ||||
| 		adoDesc, _ := json.Marshal(addonDescriptor) | ||||
| 		config.AddonDescriptor = string(adoDesc) | ||||
| 		//act | ||||
| 		err := runAbapAddonAssemblyKitCreateTargetVector(&config, nil, client, &cpe) | ||||
| 		//assert | ||||
| 		assert.Error(t, err, "Must end with error") | ||||
| 	}) | ||||
|  | ||||
| } | ||||
|  | ||||
| var responseCreateTargetVector = `{ | ||||
|     "d": { | ||||
|         "__metadata": { | ||||
|             "id": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorSet('W7Q00207512600000262')", | ||||
|             "uri": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorSet('W7Q00207512600000262')", | ||||
|             "type": "SSDA.AAS_ODATA_PACKAGE_SRV.TargetVector" | ||||
|         }, | ||||
|         "Id": "W7Q00207512600000262", | ||||
|         "Vendor": "0000203069", | ||||
|         "ProductName": "/DRNMSPC/PRD01", | ||||
|         "ProductVersion": "0001", | ||||
|         "SpsLevel": "0000", | ||||
|         "PatchLevel": "0000", | ||||
|         "Status": "G", | ||||
|         "Content": { | ||||
|             "results": [ | ||||
|                 { | ||||
|                     "__metadata": { | ||||
|                         "id": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorContentSet(Id='W7Q00207512600000262',ScName='%2FDRNMSPC%2FCOMP01')", | ||||
|                         "uri": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorContentSet(Id='W7Q00207512600000262',ScName='%2FDRNMSPC%2FCOMP01')", | ||||
|                         "type": "SSDA.AAS_ODATA_PACKAGE_SRV.TargetVectorContent" | ||||
|                     }, | ||||
|                     "Id": "W7Q00207512600000262", | ||||
|                     "ScName": "/DRNMSPC/COMP01", | ||||
|                     "ScVersion": "0001", | ||||
|                     "DeliveryPackage": "SAPK-001AAINDRNMSPC", | ||||
|                     "SpLevel": "0000", | ||||
|                     "PatchLevel": "0000", | ||||
|                     "Header": { | ||||
|                         "__deferred": { | ||||
|                             "uri": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorContentSet(Id='W7Q00207512600000262',ScName='%2FDRNMSPC%2FCOMP01')/Header" | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             ] | ||||
|         } | ||||
|     } | ||||
| }` | ||||
| @@ -107,7 +107,7 @@ func Execute() { | ||||
| 	rootCmd.AddCommand(AbapEnvironmentAssemblePackagesCommand()) | ||||
| 	rootCmd.AddCommand(AbapAddonAssemblyKitCheckCVsCommand()) | ||||
| 	rootCmd.AddCommand(AbapAddonAssemblyKitCheckPVCommand()) | ||||
| 	//	rootCmd.AddCommand(AbapAddonAssemblyKitCreateTargetVectorCommand()) | ||||
| 	rootCmd.AddCommand(AbapAddonAssemblyKitCreateTargetVectorCommand()) | ||||
| 	rootCmd.AddCommand(AbapAddonAssemblyKitPublishTargetVectorCommand()) | ||||
| 	//	rootCmd.AddCommand(AbapAddonAssemblyKitRegisterPackagesCommand()) | ||||
| 	//	rootCmd.AddCommand(AbapAddonAssemblyKitReleasePackagesCommand()) | ||||
|   | ||||
| @@ -0,0 +1,82 @@ | ||||
| # ${docGenStepName} | ||||
|  | ||||
| ## ${docGenDescription} | ||||
|  | ||||
| ## Prerequisites | ||||
|  | ||||
| * The credentials to access the AAKaaS (e.g. S-User) must be stored in the Jenkins Credential Store | ||||
| * This step needs the Product Version name and the resolved version(version, spslevel and patchlevel). | ||||
| * It also needs for each Software Component Version which should be part of the Target Vector, the name and the resolved version(version, splevel and patchlevel) as well as the Delivery Package. | ||||
| * The Delivery Packages must exist in the package registry (status "P") or already as physical packages (status "L" or "R"). | ||||
| * This information is taken from the addonDescriptor in the commonPipelineEnvironment. | ||||
| * If you run prior to this step the steps: [abapAddonAssemblyKitCheckCVs](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitCheckCVs), [abapAddonAssemblyKitCheckPV](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitCheckPV) and [abapAddonAssemblyKitReserveNextPackages](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitReserveNextPackages) you will get the needed information. | ||||
|  | ||||
| ## ${docGenParameters} | ||||
|  | ||||
| ## ${docGenConfiguration} | ||||
|  | ||||
| ## ${docJenkinsPluginDependencies} | ||||
|  | ||||
| ## Examples | ||||
|  | ||||
| ### Configuration in the config.yml | ||||
|  | ||||
| The recommended way to configure your pipeline is via the config.yml file. In this case, calling the step in the Jenkinsfile is reduced to one line: | ||||
|  | ||||
| ```groovy | ||||
| abapAddonAssemblyKitCreateTargetVector script: this | ||||
| ``` | ||||
|  | ||||
| The config.yml should look like this: | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   abapAddonAssemblyKitCreateTargetVector: | ||||
|     abapAddonAssemblyKitCredentialsId: 'abapAddonAssemblyKitCredentialsId', | ||||
|     abapAddonAssemblyKitEndpoint: 'https://myabapAddonAssemblyKitEndpoint.com', | ||||
| ``` | ||||
|  | ||||
| ### Input via the CommonPipelineEnvironment | ||||
|  | ||||
| ```json | ||||
| {"addonProduct":"/DMO/myAddonProduct", | ||||
| "addonVersion":"", | ||||
| "addonVersionAAK":"0003", | ||||
| "addonUniqueID":"", | ||||
| "customerID":"", | ||||
| "AddonSpsLevel":"0001", | ||||
| "AddonPatchLevel":"0004", | ||||
| "TargetVectorID":"", | ||||
| "repositories":[ | ||||
|   { | ||||
|     "name":"/DMO/REPO_A", | ||||
|     "tag":"", | ||||
|     "branch":"", | ||||
|     "version":"", | ||||
|     "versionAAK":"0001", | ||||
|     "PackageName":"SAPK001001REPOA", | ||||
|     "PackageType":"", | ||||
|     "SpLevel":"0000", | ||||
|     "PatchLevel":"0001", | ||||
|     "PredecessorCommitID":"", | ||||
|     "Status":"L", | ||||
|     "Namespace":"", | ||||
|     "SarXMLFilePath":"" | ||||
|   }, | ||||
|   { | ||||
|     "name":"/DMO/REPO_B", | ||||
|     "tag":"", | ||||
|     "branch":"", | ||||
|     "version":"", | ||||
|     "versionAAK":"0002", | ||||
|     "PackageName":"SAPK002001REPOB", | ||||
|     "PackageType":"", | ||||
|     "SpLevel":"0001", | ||||
|     "PatchLevel":"0001", | ||||
|     "PredecessorCommitID":"", | ||||
|     "Status":"R", | ||||
|     "Namespace":"", | ||||
|     "SarXMLFilePath":"" | ||||
|   } | ||||
| ]} | ||||
| ``` | ||||
| @@ -51,7 +51,7 @@ nav: | ||||
|     - 'Library steps': | ||||
|         - abapAddonAssemblyKitCheckCVs: steps/abapAddonAssemblyKitCheckCVs.md | ||||
|         - abapAddonAssemblyKitCheckCVs: steps/abapAddonAssemblyKitCheckPV.md | ||||
| #        - abapAddonAssemblyKitCreateTargetVector: steps/abapAddonAssemblyKitCreateTargetVector.md | ||||
|         - abapAddonAssemblyKitCreateTargetVector: steps/abapAddonAssemblyKitCreateTargetVector.md | ||||
|         - abapAddonAssemblyKitPublishTargetVector: steps/abapAddonAssemblyKitPublishTargetVector.md | ||||
| #        - abapAddonAssemblyKitRegisterPackages: steps/abapAddonAssemblyKitRegisterPackages.md | ||||
| #        - abapAddonAssemblyKitReleasePackages: steps/abapAddonAssemblyKitReleasePackages.md | ||||
|   | ||||
| @@ -0,0 +1,56 @@ | ||||
| metadata: | ||||
|     name: abapAddonAssemblyKitCreateTargetVector | ||||
|     description: This step creates a Target Vector for SPC | ||||
|     longDescription: | | ||||
|       This step takes the Product Version and the corresponding list of Software Component Versions from the addonDescriptor in the commonPipelineEnvironment. | ||||
|       With these it creates a Target Vector, which is necessary for executing the software change in ABAP Cloud Platform systems with help of the Software Provider Cockpit (SPC). | ||||
|       It describes the software state, which shall be reached in the managed ABAP Cloud Platform system. | ||||
| spec: | ||||
|   inputs: | ||||
|     secrets: | ||||
|       - name: abapAddonAssemblyKitCredentialsId | ||||
|         description: Credential stored in Jenkins for the Addon Assembly Kit as a Service (AAKaaS) system | ||||
|         type: jenkins | ||||
|     params: | ||||
|       - name: abapAddonAssemblyKitEndpoint | ||||
|         type: string | ||||
|         description: Base URL to the Addon Assembly Kit as a Service (AAKaaS) system | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|           - GENERAL | ||||
|         mandatory: true | ||||
|       - name: username | ||||
|         type: string | ||||
|         description: User for the Addon Assembly Kit as a Service (AAKaaS) system | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|         secret: true | ||||
|       - name: password | ||||
|         type: string | ||||
|         description: Password for the Addon Assembly Kit as a Service (AAKaaS) system | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|         mandatory: true | ||||
|         secret: true | ||||
|       - name: addonDescriptor | ||||
|         type: string | ||||
|         description: Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions | ||||
|         mandatory: true | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         resourceRef: | ||||
|           - name: commonPipelineEnvironment | ||||
|             param: abap/addonDescriptor | ||||
|   outputs: | ||||
|     resources: | ||||
|       - name: commonPipelineEnvironment | ||||
|         type: piperEnvironment | ||||
|         params: | ||||
|           - name: abap/addonDescriptor | ||||
| @@ -108,7 +108,7 @@ public class CommonStepsTest extends BasePiperTest{ | ||||
|     private static fieldRelatedWhitelist = [ | ||||
|         'abapAddonAssemblyKitCheckCVs', //implementing new golang pattern without fields | ||||
|         'abapAddonAssemblyKitCheckPV', //implementing new golang pattern without fields | ||||
|         //'abapAddonAssemblyKitCreateTargetVector', //implementing new golang pattern without fields | ||||
|         'abapAddonAssemblyKitCreateTargetVector', //implementing new golang pattern without fields | ||||
|         'abapAddonAssemblyKitPublishTargetVector', //implementing new golang pattern without fields | ||||
|         //'abapAddonAssemblyKitRegisterPackages', //implementing new golang pattern without fields | ||||
|         //'abapAddonAssemblyKitReleasePackages', //implementing new golang pattern without fields | ||||
|   | ||||
							
								
								
									
										11
									
								
								vars/abapAddonAssemblyKitCreateTargetVector.groovy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								vars/abapAddonAssemblyKitCreateTargetVector.groovy
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| import groovy.transform.Field | ||||
|  | ||||
| @Field String STEP_NAME = getClass().getName() | ||||
| @Field String METADATA_FILE = 'metadata/abapAddonAssemblyKitCreateTargetVector.yaml' | ||||
|  | ||||
| void call(Map parameters = [:]) { | ||||
|     List credentials = [ | ||||
|         [type: 'usernamePassword', id: 'abapAddonAssemblyKitCredentialsId', env: ['PIPER_username', 'PIPER_password']] | ||||
|     ] | ||||
|         piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials, false, false, true) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user