From 67f3c7652be891072bde899fcd3a4274de01902d Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Wed, 24 Apr 2024 15:17:22 +0200 Subject: [PATCH 1/3] OSGi bundle snapshot install skipping --- examples/docker/src/aem/default/etc/aem.yml | 6 ++ pkg/osgi_bundle_manager.go | 91 ++++++++++++++++--- .../app_classic/aem/default/etc/aem.yml | 6 ++ pkg/project/app_cloud/aem/default/etc/aem.yml | 6 ++ pkg/project/instance/aem/default/etc/aem.yml | 6 ++ 5 files changed, 102 insertions(+), 13 deletions(-) diff --git a/examples/docker/src/aem/default/etc/aem.yml b/examples/docker/src/aem/default/etc/aem.yml index 2f05038a..200a6da0 100755 --- a/examples/docker/src/aem/default/etc/aem.yml +++ b/examples/docker/src/aem/default/etc/aem.yml @@ -191,6 +191,12 @@ instance: start_level: 20 refresh_packages: true + # Force re-installing of snapshot OSGi bundles (just built / unreleased) + snapshot_patterns: [ "**/*-SNAPSHOT.jar" ] + snapshot_ignored: false + # Use checksums to avoid re-installations when snapshot OSGi bundles are unchanged + snapshot_install_skipping: true + # Crypto Support crypto: key_bundle_symbolic_name: com.adobe.granite.crypto.file diff --git a/pkg/osgi_bundle_manager.go b/pkg/osgi_bundle_manager.go index 7102076c..b47b140e 100644 --- a/pkg/osgi_bundle_manager.go +++ b/pkg/osgi_bundle_manager.go @@ -4,16 +4,25 @@ import ( "fmt" "github.com/samber/lo" log "github.com/sirupsen/logrus" + "github.com/wttech/aemc/pkg/common/filex" "github.com/wttech/aemc/pkg/common/fmtx" + "github.com/wttech/aemc/pkg/common/osx" + "github.com/wttech/aemc/pkg/common/pathx" + "github.com/wttech/aemc/pkg/common/stringsx" "github.com/wttech/aemc/pkg/osgi" + "path/filepath" + "time" ) type OSGiBundleManager struct { instance *Instance - InstallStart bool - InstallStartLevel int - InstallRefreshPackages bool + InstallStart bool + InstallStartLevel int + InstallRefreshPackages bool + SnapshotInstallSkipping bool + SnapshotIgnored bool + SnapshotPatterns []string } func NewBundleManager(instance *Instance) *OSGiBundleManager { @@ -22,9 +31,12 @@ func NewBundleManager(instance *Instance) *OSGiBundleManager { return &OSGiBundleManager{ instance: instance, - InstallStart: cv.GetBool("instance.osgi.bundle.install.start"), - InstallStartLevel: cv.GetInt("instance.osgi.bundle.install.start_level"), - InstallRefreshPackages: cv.GetBool("instance.osgi.bundle.install.refresh_packages"), + InstallStart: cv.GetBool("instance.osgi.bundle.install.start"), + InstallStartLevel: cv.GetInt("instance.osgi.bundle.install.start_level"), + InstallRefreshPackages: cv.GetBool("instance.osgi.bundle.install.refresh_packages"), + SnapshotInstallSkipping: cv.GetBool("instance.osgi.bundle.snapshot_install_skipping"), + SnapshotIgnored: cv.GetBool("instance.osgi.bundle.snapshot_ignored"), + SnapshotPatterns: cv.GetStringSlice("instance.osgi.bundle.snapshot_patterns"), } } @@ -43,7 +55,7 @@ func (bm *OSGiBundleManager) ByFile(localPath string) (*OSGiBundle, error) { return &OSGiBundle{manager: bm, symbolicName: manifest.SymbolicName}, nil } -func (bm OSGiBundleManager) Find(symbolicName string) (*osgi.BundleListItem, error) { +func (bm *OSGiBundleManager) Find(symbolicName string) (*osgi.BundleListItem, error) { bundles, err := bm.List() if err != nil { return nil, fmt.Errorf("%s > cannot find bundle '%s'", bm.instance.IDColor(), symbolicName) @@ -98,27 +110,80 @@ func (bm *OSGiBundleManager) Stop(id int) error { return nil } +func (bm *OSGiBundleManager) IsSnapshot(localPath string) bool { + return !bm.SnapshotIgnored && stringsx.MatchSome(pathx.Normalize(localPath), bm.SnapshotPatterns) +} + func (bm *OSGiBundleManager) InstallWithChanged(localPath string) (bool, error) { + if bm.IsSnapshot(localPath) { + return bm.installSnapshot(localPath) + } + return bm.installRegular(localPath) +} + +func (bm *OSGiBundleManager) installRegular(localPath string) (bool, error) { + installed, err := bm.IsInstalled(localPath) + if err != nil { + return false, err + } + if !installed { + return true, bm.Install(localPath) + } + return false, nil +} + +func (bm *OSGiBundleManager) IsInstalled(localPath string) (bool, error) { manifest, err := osgi.ReadBundleManifest(localPath) if err != nil { return false, err } bundle := bm.New(manifest.SymbolicName) + state, err := bundle.State() if err != nil { - return false, nil + return false, err } - state, err := bundle.State() + return state.Exists && state.data.Version == manifest.Version, nil +} + +func (bm *OSGiBundleManager) installSnapshot(localPath string) (bool, error) { + checksum, err := filex.ChecksumFile(localPath) + if err != nil { + return false, err + } + installed, err := bm.IsInstalled(localPath) if err != nil { return false, err } - if !state.Exists || state.data.Version != manifest.Version { - err = bm.Install(localPath) + var lock = bm.installLock(localPath, checksum) + if installed && bm.SnapshotInstallSkipping && lock.IsLocked() { + lockData, err := lock.Locked() if err != nil { return false, err } - return true, nil + if checksum == lockData.Checksum { + log.Infof("%s > skipped installing bundle '%s'", bm.instance.IDColor(), localPath) + return false, nil + } } - return false, nil + if err := bm.Install(localPath); err != nil { + return false, err + } + if err := lock.Lock(); err != nil { + return false, err + } + return true, nil +} + +func (bm *OSGiBundleManager) installLock(file string, checksum string) osx.Lock[osgiBundleInstallLock] { + name := filepath.Base(file) + return osx.NewLock(fmt.Sprintf("%s/osgi/bundle/install/%s.yml", bm.instance.LockDir(), name), func() (osgiBundleInstallLock, error) { + return osgiBundleInstallLock{Installed: time.Now(), Checksum: checksum}, nil + }) +} + +type osgiBundleInstallLock struct { + Installed time.Time `yaml:"installed"` + Checksum string `yaml:"checksum"` } func (bm *OSGiBundleManager) Install(localPath string) error { diff --git a/pkg/project/app_classic/aem/default/etc/aem.yml b/pkg/project/app_classic/aem/default/etc/aem.yml index f941a55f..7e3a2699 100755 --- a/pkg/project/app_classic/aem/default/etc/aem.yml +++ b/pkg/project/app_classic/aem/default/etc/aem.yml @@ -192,6 +192,12 @@ instance: start_level: 20 refresh_packages: true + # Force re-uploading/installing of snapshot OSGi bundles (just built / unreleased) + snapshot_patterns: [ "**/*-SNAPSHOT.jar" ] + snapshot_ignored: false + # Use checksums to avoid re-installations when snapshot OSGi bundles are unchanged + snapshot_install_skipping: true + # Crypto Support crypto: key_bundle_symbolic_name: com.adobe.granite.crypto.file diff --git a/pkg/project/app_cloud/aem/default/etc/aem.yml b/pkg/project/app_cloud/aem/default/etc/aem.yml index ae38a0a7..e4a78fed 100755 --- a/pkg/project/app_cloud/aem/default/etc/aem.yml +++ b/pkg/project/app_cloud/aem/default/etc/aem.yml @@ -190,6 +190,12 @@ instance: start_level: 20 refresh_packages: true + # Force re-installing of snapshot OSGi bundles (just built / unreleased) + snapshot_patterns: [ "**/*-SNAPSHOT.jar" ] + snapshot_ignored: false + # Use checksums to avoid re-installations when snapshot OSGi bundles are unchanged + snapshot_install_skipping: true + # Crypto Support crypto: key_bundle_symbolic_name: com.adobe.granite.crypto.file diff --git a/pkg/project/instance/aem/default/etc/aem.yml b/pkg/project/instance/aem/default/etc/aem.yml index 5a6ffcad..e92f5c04 100755 --- a/pkg/project/instance/aem/default/etc/aem.yml +++ b/pkg/project/instance/aem/default/etc/aem.yml @@ -193,6 +193,12 @@ instance: start_level: 20 refresh_packages: true + # Force re-installing of snapshot OSGi bundles (just built / unreleased) + snapshot_patterns: [ "**/*-SNAPSHOT.jar" ] + snapshot_ignored: false + # Use checksums to avoid re-installations when snapshot OSGi bundles are unchanged + snapshot_install_skipping: true + # Crypto Support crypto: key_bundle_symbolic_name: com.adobe.granite.crypto.file From e3939df1aefbe46cdda4a0df0b835864ac00112a Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Wed, 24 Apr 2024 15:24:47 +0200 Subject: [PATCH 2/3] Defaults missing --- pkg/cfg/defaults.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cfg/defaults.go b/pkg/cfg/defaults.go index 24f1be54..8eee3782 100644 --- a/pkg/cfg/defaults.go +++ b/pkg/cfg/defaults.go @@ -120,6 +120,10 @@ func (c *Config) setDefaults() { v.SetDefault("instance.osgi.bundle.install.start_level", 20) v.SetDefault("instance.osgi.bundle.install.refresh_packages", true) + v.SetDefault("instance.osgi.bundle.snapshot_install_skipping", true) + v.SetDefault("instance.osgi.bundle.snapshot_ignored", false) + v.SetDefault("instance.osgi.bundle.snapshot_patterns", []string{"**/*-SNAPSHOT.jar"}) + v.SetDefault("instance.ssl.setup_timeout", time.Second*30) v.SetDefault("instance.crypto.key_bundle_symbolic_name", "com.adobe.granite.crypto.file") From 0855f9025cb66b6bb48948e3aa902229c5d0b5ef Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Wed, 24 Apr 2024 15:26:16 +0200 Subject: [PATCH 3/3] Release v1.7.5 --- pkg/project/common/aemw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/project/common/aemw b/pkg/project/common/aemw index a2d02f3a..d736b34a 100755 --- a/pkg/project/common/aemw +++ b/pkg/project/common/aemw @@ -1,6 +1,6 @@ #!/usr/bin/env sh -VERSION=${AEM_CLI_VERSION:-"1.7.4"} +VERSION=${AEM_CLI_VERSION:-"1.7.5"} # Define API # ==========