Skip to content

Commit

Permalink
AAKaas release package SAP#2
Browse files Browse the repository at this point in the history
  • Loading branch information
tiloKo committed Sep 18, 2020
1 parent ac626a4 commit 918a2d7
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 53 deletions.
53 changes: 19 additions & 34 deletions cmd/abapAddonAssemblyKitReleasePackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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)

Expand All @@ -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
}
}
Expand All @@ -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
}
29 changes: 17 additions & 12 deletions cmd/abapAddonAssemblyKitReleasePackages_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/abapAddonAssemblyKitReleasePackages_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

}
2 changes: 1 addition & 1 deletion cmd/piper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion documentation/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions pkg/abap/aakaas/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion test/groovy/CommonStepsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 918a2d7

Please sign in to comment.