2020-09-18 10:24:46 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-11-12 15:33:18 +02:00
|
|
|
"time"
|
2020-09-18 10:24:46 +02:00
|
|
|
|
2021-11-12 15:33:18 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/abap/aakaas"
|
2020-09-18 10:24:46 +02:00
|
|
|
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/abaputils"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func abapAddonAssemblyKitPublishTargetVector(config abapAddonAssemblyKitPublishTargetVectorOptions, telemetryData *telemetry.CustomData) {
|
2021-12-09 13:54:18 +02:00
|
|
|
utils := aakaas.NewAakBundleWithTime(time.Duration(config.MaxRuntimeInMinutes), time.Duration(config.PollingIntervalInSeconds))
|
2020-09-18 10:24:46 +02:00
|
|
|
|
|
|
|
// error situations should stop execution through log.Entry().Fatal() call which leads to an os.Exit(1) in the end
|
2021-12-09 13:54:18 +02:00
|
|
|
if err := runAbapAddonAssemblyKitPublishTargetVector(&config, telemetryData, &utils); err != nil {
|
2020-09-18 10:24:46 +02:00
|
|
|
log.Entry().WithError(err).Fatal("step execution failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-09 13:54:18 +02:00
|
|
|
func runAbapAddonAssemblyKitPublishTargetVector(config *abapAddonAssemblyKitPublishTargetVectorOptions, telemetryData *telemetry.CustomData, utils *aakaas.AakUtils) error {
|
2021-11-12 15:33:18 +02:00
|
|
|
|
2020-09-18 10:24:46 +02:00
|
|
|
conn := new(abapbuild.Connector)
|
2021-12-09 13:54:18 +02:00
|
|
|
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils); err != nil {
|
2021-11-12 15:33:18 +02:00
|
|
|
return err
|
|
|
|
}
|
2021-12-09 13:54:18 +02:00
|
|
|
conn.MaxRuntime = (*utils).GetMaxRuntime()
|
|
|
|
conn.PollingInterval = (*utils).GetPollingInterval()
|
2021-11-12 15:33:18 +02:00
|
|
|
|
|
|
|
addonDescriptor := new(abaputils.AddonDescriptor)
|
|
|
|
if err := addonDescriptor.InitFromJSONstring(config.AddonDescriptor); err != nil {
|
|
|
|
return errors.Wrap(err, "Reading AddonDescriptor failed [Make sure abapAddonAssemblyKit...CheckCVs|CheckPV steps have been run before]")
|
|
|
|
}
|
2020-09-18 10:24:46 +02:00
|
|
|
|
|
|
|
if addonDescriptor.TargetVectorID == "" {
|
2021-11-12 15:33:18 +02:00
|
|
|
return errors.New("Parameter missing. Please provide the target vector id (e.g. by running step abapAddonAssemblyKitCreateTargetVector beforehand")
|
2020-09-18 10:24:46 +02:00
|
|
|
}
|
2021-11-12 15:33:18 +02:00
|
|
|
targetVector := new(aakaas.TargetVector)
|
|
|
|
targetVector.InitExisting(addonDescriptor.TargetVectorID)
|
2020-09-18 10:24:46 +02:00
|
|
|
|
2021-11-12 15:33:18 +02:00
|
|
|
switch config.TargetVectorScope {
|
|
|
|
case string(aakaas.TargetVectorStatusTest):
|
|
|
|
log.Entry().Infof("Publish target vector %s for test use", addonDescriptor.TargetVectorID)
|
|
|
|
case string(aakaas.TargetVectorStatusProductive):
|
|
|
|
log.Entry().Infof("Publish target vector %s for productive use", addonDescriptor.TargetVectorID)
|
|
|
|
default:
|
|
|
|
return errors.New("Invalid Value of configuration Parameter TargetVectorScope: " + config.TargetVectorScope)
|
2020-09-18 10:24:46 +02:00
|
|
|
}
|
2021-11-12 15:33:18 +02:00
|
|
|
|
|
|
|
if err := targetVector.PublishTargetVector(conn, aakaas.TargetVectorStatus(config.TargetVectorScope)); err != nil {
|
|
|
|
return err
|
2020-09-18 10:24:46 +02:00
|
|
|
}
|
2021-11-12 15:33:18 +02:00
|
|
|
|
|
|
|
log.Entry().Info("Waiting for target vector publishing to finish")
|
|
|
|
if err := targetVector.PollForStatus(conn, aakaas.TargetVectorStatus(config.TargetVectorScope)); err != nil {
|
2020-09-18 10:24:46 +02:00
|
|
|
return err
|
|
|
|
}
|
2021-11-12 15:33:18 +02:00
|
|
|
|
2021-12-09 11:37:53 +02:00
|
|
|
log.Entry().Info("Success: Publishing finished")
|
2020-09-18 10:24:46 +02:00
|
|
|
return nil
|
|
|
|
}
|