From 918a2d78567ec05d2e6aafa9557a51ab8200722c Mon Sep 17 00:00:00 2001 From: tiloKo <70266685+tiloKo@users.noreply.github.com> Date: Fri, 18 Sep 2020 14:27:56 +0200 Subject: [PATCH] AAKaas release package #2 --- cmd/abapAddonAssemblyKitReleasePackages.go | 53 +++++++------------ ...donAssemblyKitReleasePackages_generated.go | 29 +++++----- ...semblyKitReleasePackages_generated_test.go | 2 +- cmd/piper.go | 2 +- documentation/mkdocs.yml | 2 +- pkg/abap/aakaas/package.go | 24 +++++++-- test/groovy/CommonStepsTest.groovy | 2 +- 7 files changed, 61 insertions(+), 53 deletions(-) diff --git a/cmd/abapAddonAssemblyKitReleasePackages.go b/cmd/abapAddonAssemblyKitReleasePackages.go index 59191324be..969ef5988f 100644 --- a/cmd/abapAddonAssemblyKitReleasePackages.go +++ b/cmd/abapAddonAssemblyKitReleasePackages.go @@ -4,6 +4,7 @@ import ( "encoding/json" "time" + "github.com/SAP/jenkins-library/pkg/abap/aakaas" abapbuild "github.com/SAP/jenkins-library/pkg/abap/build" "github.com/SAP/jenkins-library/pkg/abaputils" "github.com/SAP/jenkins-library/pkg/command" @@ -54,14 +55,14 @@ func runAbapAddonAssemblyKitReleasePackages(config *abapAddonAssemblyKitReleaseP return nil } -func sortingBack(packagesWithReposLocked []packageWithRepository, packagesWithReposNotLocked []packageWithRepository) []abaputils.Repository { +func sortingBack(packagesWithReposLocked []aakaas.PackageWithRepository, packagesWithReposNotLocked []aakaas.PackageWithRepository) []abaputils.Repository { var combinedRepos []abaputils.Repository for i := range packagesWithReposLocked { - packagesWithReposLocked[i].p.changeStatus(&packagesWithReposLocked[i].repo) - combinedRepos = append(combinedRepos, packagesWithReposLocked[i].repo) + packagesWithReposLocked[i].Package.ChangeStatus(&packagesWithReposLocked[i].Repo) + combinedRepos = append(combinedRepos, packagesWithReposLocked[i].Repo) } for i := range packagesWithReposNotLocked { - combinedRepos = append(combinedRepos, packagesWithReposNotLocked[i].repo) + combinedRepos = append(combinedRepos, packagesWithReposNotLocked[i].Repo) } return combinedRepos } @@ -75,27 +76,27 @@ func checkInput(repos []abaputils.Repository) error { return nil } -func sortByStatus(repos []abaputils.Repository, conn connector) ([]packageWithRepository, []packageWithRepository) { - var packagesWithReposLocked []packageWithRepository - var packagesWithReposNotLocked []packageWithRepository +func sortByStatus(repos []abaputils.Repository, conn abapbuild.Connector) ([]aakaas.PackageWithRepository, []aakaas.PackageWithRepository) { + var packagesWithReposLocked []aakaas.PackageWithRepository + var packagesWithReposNotLocked []aakaas.PackageWithRepository for i := range repos { - var p pckg - p.init(repos[i], conn) - pWR := packageWithRepository{ - p: p, - repo: repos[i], + var pack aakaas.Package + pack.InitPackage(repos[i], conn) + pWR := aakaas.PackageWithRepository{ + Package: pack, + Repo: repos[i], } - if p.Status == "L" { + if pack.Status == "L" { packagesWithReposLocked = append(packagesWithReposLocked, pWR) } else { - log.Entry().Infof("Package %s has status %s, cannot release this package", p.PackageName, p.Status) + log.Entry().Infof("Package %s has status %s, cannot release this package", pack.PackageName, pack.Status) packagesWithReposNotLocked = append(packagesWithReposNotLocked, pWR) } } return packagesWithReposLocked, packagesWithReposNotLocked } -func releaseAndPoll(pckgWR []packageWithRepository, maxRuntimeInMinutes time.Duration, pollIntervalsInSeconds time.Duration) ([]packageWithRepository, error) { +func releaseAndPoll(pckgWR []aakaas.PackageWithRepository, maxRuntimeInMinutes time.Duration, pollIntervalsInSeconds time.Duration) ([]aakaas.PackageWithRepository, error) { timeout := time.After(maxRuntimeInMinutes) ticker := time.Tick(pollIntervalsInSeconds) @@ -106,11 +107,11 @@ func releaseAndPoll(pckgWR []packageWithRepository, maxRuntimeInMinutes time.Dur case <-ticker: var allFinished bool = true for i := range pckgWR { - if pckgWR[i].p.Status != "R" { - err := pckgWR[i].p.release() + if pckgWR[i].Package.Status != aakaas.PackageStatusReleased { + err := pckgWR[i].Package.Release() // if there is an error, release is not yet finished if err != nil { - log.Entry().Infof("Release of %s is not yet finished, check again in %s", pckgWR[i].p.PackageName, pollIntervalsInSeconds) + log.Entry().Infof("Release of %s is not yet finished, check again in %s", pckgWR[i].Package.PackageName, pollIntervalsInSeconds) allFinished = false } } @@ -122,19 +123,3 @@ func releaseAndPoll(pckgWR []packageWithRepository, maxRuntimeInMinutes time.Dur } } } - -func (p *pckg) release() error { - var body []byte - var err error - log.Entry().Infof("Release package %s", p.PackageName) - p.connector.getToken("/odata/aas_ocs_package") - appendum := "/odata/aas_ocs_package/ReleasePackage?Name='" + p.PackageName + "'" - body, err = p.connector.post(appendum, "") - if err != nil { - return err - } - var jPck jsonPackage - json.Unmarshal(body, &jPck) - p.Status = jPck.Package.Status - return nil -} diff --git a/cmd/abapAddonAssemblyKitReleasePackages_generated.go b/cmd/abapAddonAssemblyKitReleasePackages_generated.go index dead84cb2d..728763e50d 100644 --- a/cmd/abapAddonAssemblyKitReleasePackages_generated.go +++ b/cmd/abapAddonAssemblyKitReleasePackages_generated.go @@ -109,10 +109,10 @@ store. The new status "R"eleased is written back to the addonDescriptor in the c } func addAbapAddonAssemblyKitReleasePackagesFlags(cmd *cobra.Command, stepConfig *abapAddonAssemblyKitReleasePackagesOptions) { - cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitEndpoint, "abapAddonAssemblyKitEndpoint", os.Getenv("PIPER_abapAddonAssemblyKitEndpoint"), "Base URL to the Addon Assembly Kit as a Service System (AAKaaS)") - cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for the Addon Assembly Kit as a Service System (AAKaaS)") - cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password the Addon Assembly Kit as a Service System (AAKaaS)") - cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "File name of the YAML file which describes the Product Version and corresponding Software Component Versions") + 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") @@ -141,7 +141,7 @@ func abapAddonAssemblyKitReleasePackagesMetadata() config.StepData { { Name: "username", ResourceRef: []config.ResourceReference{}, - Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, + Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, Type: "string", Mandatory: true, Aliases: []config.Alias{}, @@ -149,18 +149,23 @@ func abapAddonAssemblyKitReleasePackagesMetadata() config.StepData { { Name: "password", ResourceRef: []config.ResourceReference{}, - Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, + 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{}, + Name: "addonDescriptor", + ResourceRef: []config.ResourceReference{ + { + Name: "commonPipelineEnvironment", + Param: "abap/addonDescriptor", + }, + }, + Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, + Type: "string", + Mandatory: true, + Aliases: []config.Alias{}, }, }, }, diff --git a/cmd/abapAddonAssemblyKitReleasePackages_generated_test.go b/cmd/abapAddonAssemblyKitReleasePackages_generated_test.go index d898ebf44c..434c6aac40 100644 --- a/cmd/abapAddonAssemblyKitReleasePackages_generated_test.go +++ b/cmd/abapAddonAssemblyKitReleasePackages_generated_test.go @@ -10,7 +10,7 @@ func TestAbapAddonAssemblyKitReleasePackagesCommand(t *testing.T) { testCmd := AbapAddonAssemblyKitReleasePackagesCommand() - // only high level testing performed - details are tested in step generation procudure + // only high level testing performed - details are tested in step generation procedure assert.Equal(t, "abapAddonAssemblyKitReleasePackages", testCmd.Use, "command name incorrect") } diff --git a/cmd/piper.go b/cmd/piper.go index 121aa2e0dc..b697f12b01 100644 --- a/cmd/piper.go +++ b/cmd/piper.go @@ -110,7 +110,7 @@ func Execute() { rootCmd.AddCommand(AbapAddonAssemblyKitCreateTargetVectorCommand()) rootCmd.AddCommand(AbapAddonAssemblyKitPublishTargetVectorCommand()) rootCmd.AddCommand(AbapAddonAssemblyKitRegisterPackagesCommand()) - // rootCmd.AddCommand(AbapAddonAssemblyKitReleasePackagesCommand()) + rootCmd.AddCommand(AbapAddonAssemblyKitReleasePackagesCommand()) // rootCmd.AddCommand(AbapAddonAssemblyKitReserveNextPackagesCommand()) addRootFlags(rootCmd) diff --git a/documentation/mkdocs.yml b/documentation/mkdocs.yml index 78b69d2355..471556c930 100644 --- a/documentation/mkdocs.yml +++ b/documentation/mkdocs.yml @@ -54,7 +54,7 @@ nav: - abapAddonAssemblyKitCreateTargetVector: steps/abapAddonAssemblyKitCreateTargetVector.md - abapAddonAssemblyKitPublishTargetVector: steps/abapAddonAssemblyKitPublishTargetVector.md - abapAddonAssemblyKitRegisterPackages: steps/abapAddonAssemblyKitRegisterPackages.md -# - abapAddonAssemblyKitReleasePackages: steps/abapAddonAssemblyKitReleasePackages.md + - abapAddonAssemblyKitReleasePackages: steps/abapAddonAssemblyKitReleasePackages.md # - abapAddonAssemblyKitReserveNextPackages: steps/abapAddonAssemblyKitReserveNextPackages.md - abapEnvironmentAssemblePackages: steps/abapEnvironmentAssemblePackages.md - abapEnvironmentCheckoutBranch: steps/abapEnvironmentCheckoutBranch.md diff --git a/pkg/abap/aakaas/package.go b/pkg/abap/aakaas/package.go index 4a189c47bc..f6f4f60398 100644 --- a/pkg/abap/aakaas/package.go +++ b/pkg/abap/aakaas/package.go @@ -45,9 +45,10 @@ type Package struct { Namespace string `json:"Namespace"` } -type packageWithRepository struct { - p Package - repo abaputils.Repository +// PackageWithRepository : pack'n repo +type PackageWithRepository struct { + Package Package + Repo abaputils.Repository } // InitPackage : initialize package attributes from the repository @@ -130,3 +131,20 @@ func (p *Package) Register() error { log.Entry().Infof("Package status %s", p.Status) return nil } + +// Release : release package in AAKaaS +func (p *Package) Release() error { + var body []byte + var err error + log.Entry().Infof("Release package %s", p.PackageName) + p.Connector.GetToken("/odata/aas_ocs_package") + appendum := "/odata/aas_ocs_package/ReleasePackage?Name='" + p.PackageName + "'" + body, err = p.Connector.Post(appendum, "") + if err != nil { + return err + } + var jPck jsonPackage + json.Unmarshal(body, &jPck) + p.Status = jPck.Package.Status + return nil +} diff --git a/test/groovy/CommonStepsTest.groovy b/test/groovy/CommonStepsTest.groovy index 61eef95231..deb1e3b918 100644 --- a/test/groovy/CommonStepsTest.groovy +++ b/test/groovy/CommonStepsTest.groovy @@ -111,7 +111,7 @@ public class CommonStepsTest extends BasePiperTest{ '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 + 'abapAddonAssemblyKitReleasePackages', //implementing new golang pattern without fields //'abapAddonAssemblyKitReserveNextPackages', //implementing new golang pattern without fields 'abapEnvironmentAssemblePackages', //implementing new golang pattern without fields 'abapEnvironmentCheckoutBranch', //implementing new golang pattern without fields