Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAKaaS:1 check Component Versions #2023

Merged
merged 86 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
54f92e2
adding my steps
rosemarieB Jul 30, 2020
1e8e716
messy step
rosemarieB Jul 30, 2020
bc18dba
Update abapEnvironmentAssembly.go
rosemarieB Jul 30, 2020
d5a705a
clean up
rosemarieB Jul 31, 2020
5c92d0e
Merge https://github.com/SAP/jenkins-library
rosemarieB Jul 31, 2020
43e4fa2
change yaml
rosemarieB Aug 5, 2020
2e8578c
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 5, 2020
49bb4fe
corrections
rosemarieB Aug 5, 2020
4f3d261
Update cloudFoundryDeploy.go
rosemarieB Aug 5, 2020
512346c
update
rosemarieB Aug 5, 2020
cbddd5d
delete simulation step
rosemarieB Aug 5, 2020
26fd7ae
remove simulate
rosemarieB Aug 5, 2020
c2243fa
Update PiperGoUtils.groovy
rosemarieB Aug 5, 2020
4c745ca
Update PiperGoUtils.groovy
rosemarieB Aug 5, 2020
ebce730
Merge branch 'master' into master
rosemarieB Aug 5, 2020
ec058bd
Update CommonStepsTest.groovy
rosemarieB Aug 5, 2020
213e84e
Merge branch 'master' of https://github.com/rosemarieB/jenkins-library
rosemarieB Aug 5, 2020
2538d45
add docu
rosemarieB Aug 5, 2020
1639efe
Update abapEnvironmentAssembly.md
rosemarieB Aug 5, 2020
ab0cfd1
Merge branch 'master' into master
DanielMieg Aug 6, 2020
007464e
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 7, 2020
0f780ea
changes due to PR
rosemarieB Aug 7, 2020
26c4449
Update .gitignore
rosemarieB Aug 7, 2020
6c58d1d
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 12, 2020
ab25fd5
b
rosemarieB Aug 12, 2020
5b2940a
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 13, 2020
0b0dd65
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 14, 2020
67d2a36
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 14, 2020
418bf91
CV list
rosemarieB Aug 14, 2020
e036eca
Update abapEnvironmentAssembly.go
rosemarieB Aug 17, 2020
245c97a
testing with simulation
rosemarieB Aug 17, 2020
38cf92e
Update abapEnvironmentAssembly.go
rosemarieB Aug 17, 2020
36e530a
remove simulation
rosemarieB Aug 17, 2020
088e792
renaming
rosemarieB Aug 17, 2020
7b5dcc7
Update mkdocs.yml
rosemarieB Aug 17, 2020
5597f5a
moving service key to yaml and fixing code climate
rosemarieB Aug 19, 2020
28fe073
Update abapEnvironmentAssemblePackages.go
rosemarieB Aug 20, 2020
3ff90f6
Update abapEnvironmentAssemblePackages.go
rosemarieB Aug 20, 2020
7ba8022
Update abapEnvironmentAssemblePackages.go
rosemarieB Aug 20, 2020
d520ef3
Update abapEnvironmentAssemblePackages.go
rosemarieB Aug 21, 2020
fba6c89
change input
rosemarieB Aug 21, 2020
dfb5b18
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 21, 2020
af8c0c6
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 21, 2020
2a7c3a2
Update abapEnvironmentAssemblePackages.go
rosemarieB Aug 21, 2020
3f45f0a
change json tag
rosemarieB Aug 24, 2020
3b89360
fixed error handling
rosemarieB Aug 24, 2020
c178bcd
documentation
rosemarieB Aug 25, 2020
51982a5
Update abapEnvironmentAssemblePackages.md
rosemarieB Aug 25, 2020
d8127c6
Update abapEnvironmentAssemblePackages.md
rosemarieB Aug 25, 2020
cc1b19e
fixing code climate issues
rosemarieB Aug 25, 2020
6716eeb
fixing code climate issues
rosemarieB Aug 25, 2020
2a14922
Update abapEnvironmentAssemblePackages.yaml
rosemarieB Aug 25, 2020
065f751
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 25, 2020
d738cdd
fixing code climate issues
rosemarieB Aug 25, 2020
72767d8
Update abapEnvironmentAssemblePackages.yaml
rosemarieB Aug 25, 2020
488251d
adding unittests
rosemarieB Aug 25, 2020
1df3690
adding unittests and improved logging
rosemarieB Aug 25, 2020
afb8eb6
yaml -> json
rosemarieB Aug 26, 2020
4afce97
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 26, 2020
f5e75e7
change scope of cfServiceKeyName
rosemarieB Aug 26, 2020
a34056b
Merge branch 'master' into master
CCFenner Aug 26, 2020
26d53fe
correct indentation
CCFenner Aug 26, 2020
86a4488
Update CommonStepsTest.groovy
CCFenner Aug 26, 2020
9c64c2c
maintain correct step order
CCFenner Aug 26, 2020
d64f89e
Merge https://github.com/SAP/jenkins-library
rosemarieB Aug 27, 2020
73f1099
Merge https://github.com/SAP/jenkins-library
rosemarieB Sep 2, 2020
b91c80b
Merge https://github.com/SAP/jenkins-library
rosemarieB Sep 3, 2020
39ec367
Merge remote-tracking branch 'upstream/master'
tiloKo Sep 14, 2020
eecc0d2
AAKaaS CheckCV step
tiloKo Sep 15, 2020
b3147e1
AAKaaS CheckCV step #2
tiloKo Sep 15, 2020
46fa5eb
AAKaaS CheckCV step #3
tiloKo Sep 15, 2020
3a922ba
AAKaaS CheckCV step #4
tiloKo Sep 15, 2020
79e3a5d
Merge branch 'master' into AAKaaS_1_checkCVs
DanielMieg Sep 15, 2020
33186bc
AAKaaS CheckCV step #5
tiloKo Sep 15, 2020
1096962
Merge branch 'master' into AAKaaS_1_checkCVs
tiloKo Sep 15, 2020
f65390c
AAKaaS CheckCV step #6
tiloKo Sep 15, 2020
8e30add
Merge branch 'AAKaaS_1_checkCVs' of github.com:rosemarieB/jenkins-lib…
tiloKo Sep 15, 2020
65d31de
AAKaaS CheckCV step #7
tiloKo Sep 15, 2020
bdda68f
AAKaaS CheckCV step #8
tiloKo Sep 16, 2020
fda0639
Merge branch 'master' into AAKaaS_1_checkCVs
DanielMieg Sep 16, 2020
8421197
AAKaaS CheckCV step #9
tiloKo Sep 16, 2020
4ca1f7d
AAKaaS CheckCV step #10
tiloKo Sep 17, 2020
35fcafa
AAKaaS CheckCV step #11
tiloKo Sep 17, 2020
2e160ef
Merge branch 'master' into AAKaaS_1_checkCVs
tiloKo Sep 17, 2020
411ba10
AAKaaS CheckCV step #12
tiloKo Sep 17, 2020
dd41c3e
AAKaaS CheckCV step #13
tiloKo Sep 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions cmd/abapAddonAssemblyKitCheckCVs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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"
)

func abapAddonAssemblyKitCheckCVs(config abapAddonAssemblyKitCheckCVsOptions, telemetryData *telemetry.CustomData, cpe *abapAddonAssemblyKitCheckCVsCommonPipelineEnvironment) {
// 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 := runAbapAddonAssemblyKitCheckCVs(&config, telemetryData, &client, cpe, abaputils.ReadAddonDescriptor)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}

func runAbapAddonAssemblyKitCheckCVs(config *abapAddonAssemblyKitCheckCVsOptions, telemetryData *telemetry.CustomData, client piperhttp.Sender,
cpe *abapAddonAssemblyKitCheckCVsCommonPipelineEnvironment, readAdoDescriptor abaputils.ReadAddonDescriptorType) error {
var addonDescriptorFromCPE abaputils.AddonDescriptor
json.Unmarshal([]byte(config.AddonDescriptor), &addonDescriptorFromCPE)
addonDescriptor, err := readAdoDescriptor(config.AddonDescriptorFileName)
if err != nil {
return err
}
addonDescriptor = combineYAMLRepositoriesWithCPEProduct(addonDescriptor, addonDescriptorFromCPE)
conn := new(abapbuild.Connector)
conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client)

for i := range addonDescriptor.Repositories {
var c cv
c.initCV(addonDescriptor.Repositories[i], *conn)
err := c.validate()
if err != nil {
return err
}
c.copyFieldsToRepo(&addonDescriptor.Repositories[i])
}
log.Entry().Info("Write the resolved versions to the CommonPipelineEnvironment")
toCPE, _ := json.Marshal(addonDescriptor)
cpe.abap.addonDescriptor = string(toCPE)
return nil
}

//take the product part from CPE and the repositories part from the YAML file
func combineYAMLRepositoriesWithCPEProduct(addonDescriptor abaputils.AddonDescriptor, addonDescriptorFromCPE abaputils.AddonDescriptor) abaputils.AddonDescriptor {
addonDescriptorFromCPE.Repositories = addonDescriptor.Repositories
return addonDescriptorFromCPE
}

func (c *cv) initCV(repo abaputils.Repository, conn abapbuild.Connector) {
c.Connector = conn
c.Name = repo.Name
c.VersionYAML = repo.VersionYAML
}

func (c *cv) copyFieldsToRepo(initialRepo *abaputils.Repository) {
initialRepo.Version = c.Version
initialRepo.SpLevel = c.SpLevel
initialRepo.PatchLevel = c.PatchLevel
}

func (c *cv) validate() error {
log.Entry().Infof("Validate component %s version %s and resolve version", c.Name, c.VersionYAML)
appendum := "/odata/aas_ocs_package/ValidateComponentVersion?Name='" + c.Name + "'&Version='" + c.VersionYAML + "'"
body, err := c.Connector.Get(appendum)
if err != nil {
return err
}
var jCV jsonCV
json.Unmarshal(body, &jCV)
c.Name = jCV.CV.Name
c.Version = jCV.CV.Version
c.SpLevel = jCV.CV.SpLevel
c.PatchLevel = jCV.CV.PatchLevel
log.Entry().Infof("Resolved version %s, splevel %s, patchlevel %s", c.Version, c.SpLevel, c.PatchLevel)
return nil
}

type jsonCV struct {
CV *cv `json:"d"`
}

type cv struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth extracting cv and it's functions also to the abap package?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: what does cv stand for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cv is the acronym for "(software)component version" which are the (more or less) independent deployable units of an ABAP system.
Honestly I'm new to go and do not know where to place the coding best. As far as I got the cv struct is only used in this step without reuse in any of the others - that's why I have not extracted it. Anyway what I read so far about recommended directory structure I was a bit surprised there is no "internal" package. So what's the suggestion in this case? Should it be extracted even if there is only on step using it?

abapbuild.Connector
Name string `json:"Name"`
VersionYAML string
Version string `json:"Version"`
SpLevel string `json:"SpLevel"`
PatchLevel string `json:"PatchLevel"`
}
181 changes: 181 additions & 0 deletions cmd/abapAddonAssemblyKitCheckCVs_generated.go

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

16 changes: 16 additions & 0 deletions cmd/abapAddonAssemblyKitCheckCVs_generated_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cmd

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestAbapAddonAssemblyKitCheckCVsCommand(t *testing.T) {

testCmd := AbapAddonAssemblyKitCheckCVsCommand()

// only high level testing performed - details are tested in step generation procedure
assert.Equal(t, "abapAddonAssemblyKitCheckCVs", testCmd.Use, "command name incorrect")

}
Loading