From 27605f66cdfceb28aee2f2154968aba140315148 Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Mon, 20 Apr 2020 18:34:49 +0200 Subject: [PATCH 1/8] cjd and beekeeper 2.46 better supported --- license-upgrade/apply-license.groovy | 4 +- license-upgrade/upgrade-license-plugin.groovy | 38 ++++++++++++++++--- .../verify-system-readiness.groovy | 6 ++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/license-upgrade/apply-license.groovy b/license-upgrade/apply-license.groovy index f88d8ac..faa7ac6 100644 --- a/license-upgrade/apply-license.groovy +++ b/license-upgrade/apply-license.groovy @@ -354,7 +354,9 @@ def productType() { } } else { def _plugin_oc_context = jenkins.model.Jenkins.instance.getPlugin('operations-center-context') - if(_plugin_oc_context != null && _plugin_oc_context.getWrapper().isActive()) { + def _plugin_folder_plus = jenkins.model.Jenkins.instance.getPlugin('cloudbees-folder-plus') + if((_plugin_oc_context != null && _plugin_oc_context.getWrapper().isActive()) || + (_plugin_folder_plus != null && _plugin_folder_plus.getWrapper().isActive())) { return Product.STANDALONE_MASTER } else { return Product.CJD diff --git a/license-upgrade/upgrade-license-plugin.groovy b/license-upgrade/upgrade-license-plugin.groovy index ae8741a..c9be8c2 100644 --- a/license-upgrade/upgrade-license-plugin.groovy +++ b/license-upgrade/upgrade-license-plugin.groovy @@ -94,10 +94,37 @@ jenkins.model.Jenkins.instance.doSafeRestart(null) * * ERROR plus the cause if there is a problem with the execution */ script_incremental = '''try { -com.cloudbees.jenkins.plugins.assurance.props.BeekeeperProp.get().NO_FULL_UPGRADES.set() -com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().refreshStateSync() +def tries = 10 +def waitingFor = 2000 def assurance = com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get() + +com.cloudbees.jenkins.plugins.assurance.props.BeekeeperProp.get().NO_FULL_UPGRADES.set() +if (assurance.metaClass.respondsTo(assurance, "refreshOfferedUpgrade").isEmpty()) { + assurance.refreshStateSync() +} +if (!assurance.ucRefresher.metaClass.respondsTo(assurance.ucRefresher, "awaitRefresh").isEmpty()) { + def ucFuture = assurance.refreshUpdateCenters() + for(int i=1; i<=tries; i++) { + if(ucFuture.isDone()) { + break; + } else { + sleep(waitingFor) + } + } + assurance.refreshStateSync() +} else { + assurance.ucRefresher.refresh() + for(int i=1; i<=tries; i++) { + if (com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getOfferedUpgrade().getClass().getName() == 'com.cloudbees.jenkins.plugins.assurance.OfferedUpgrade$Incremental') { + break; + } else { + sleep(waitingFor) + } + } + assurance.refreshOfferedUpgrade() +} + def incrementalUpgrade = false if (assurance.metaClass.respondsTo(assurance, "getUpgradeAction").isEmpty()) { @@ -105,7 +132,7 @@ if (assurance.metaClass.respondsTo(assurance, "getUpgradeAction").isEmpty()) { if (com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getOfferedUpgrade().getClass().getName() == 'com.cloudbees.jenkins.plugins.assurance.OfferedUpgrade$Incremental') { incrementalUpgrade = true def offered = com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getOfferedUpgrade() - if (!offered.metaClass.respondsTo(offered, "pick",void).isEmpty()) { + if (!offered.metaClass.respondsTo(offered, "pick", null).isEmpty()) { offered.pick() } else if (!offered.metaClass.respondsTo(offered, "pick", boolean).isEmpty()) { offered.pick(false) @@ -120,7 +147,6 @@ if (assurance.metaClass.respondsTo(assurance, "getUpgradeAction").isEmpty()) { com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getUpgradeAction().getUpgrade().pick(false, null) } } - return incrementalUpgrade ? "RESTART_REQUIRED" : "NO" } catch (Exception fatal) { return "ERROR. Cause: " + fatal.getMessage()}''' @@ -471,7 +497,9 @@ def productType() { } } else { def _plugin_oc_context = jenkins.model.Jenkins.instance.getPlugin('operations-center-context') - if(_plugin_oc_context != null && _plugin_oc_context.getWrapper().isActive()) { + def _plugin_folder_plus = jenkins.model.Jenkins.instance.getPlugin('cloudbees-folder-plus') + if((_plugin_oc_context != null && _plugin_oc_context.getWrapper().isActive()) || + (_plugin_folder_plus != null && _plugin_folder_plus.getWrapper().isActive())) { return Product.STANDALONE_MASTER } else { return Product.CJD diff --git a/license-upgrade/verify-system-readiness.groovy b/license-upgrade/verify-system-readiness.groovy index 647cadd..346d053 100644 --- a/license-upgrade/verify-system-readiness.groovy +++ b/license-upgrade/verify-system-readiness.groovy @@ -18,7 +18,7 @@ try { try { def assurance = com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get() def cap - if (assurance.metaClass.respondsTo(assurance, "getBeekeeperState",void).isEmpty()) { + if (assurance.metaClass.respondsTo(assurance, "getBeekeeperState",null).isEmpty()) { cap = assurance.getBeekeeper().getStatus() } else { cap = assurance.getBeekeeperState().getStatus() @@ -315,7 +315,9 @@ def productType() { } } else { def _plugin_oc_context = jenkins.model.Jenkins.instance.getPlugin('operations-center-context') - if(_plugin_oc_context != null && _plugin_oc_context.getWrapper().isActive()) { + def _plugin_folder_plus = jenkins.model.Jenkins.instance.getPlugin('cloudbees-folder-plus') + if((_plugin_oc_context != null && _plugin_oc_context.getWrapper().isActive()) || + (_plugin_folder_plus != null && _plugin_folder_plus.getWrapper().isActive())) { return Product.STANDALONE_MASTER } else { return Product.CJD From ce56d6f3d0197277849863070ee3228e49a32c40 Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Mon, 20 Apr 2020 18:56:15 +0200 Subject: [PATCH 2/8] beekeeper 2.46 --- license-upgrade/upgrade-license-plugin.groovy | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/license-upgrade/upgrade-license-plugin.groovy b/license-upgrade/upgrade-license-plugin.groovy index c9be8c2..6986a1b 100644 --- a/license-upgrade/upgrade-license-plugin.groovy +++ b/license-upgrade/upgrade-license-plugin.groovy @@ -8,7 +8,7 @@ Checks for and applies incremental updates for you jenkins instances so that the // automatically using the script. def restart = false // set debug = true for additional debug ouput. The output is supposed to be consumed by a support engineer. -def debug = false +def debug = true // set direct = true to enable directly updating the cloudbees-license-plugin if no incremental update is available (should not be needed). // direct method is useful when BeeKeeper is disabled or the instance cannot reach the public update site. It only replaces the current version // of cloudbees-license plugin by its patched version. @@ -23,8 +23,12 @@ try { try { def assurance = com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get() def cap - if (assurance.metaClass.respondsTo(assurance, "getBeekeeperState",void).isEmpty()) { - cap = assurance.getBeekeeper().getStatus() + if (assurance.metaClass.respondsTo(assurance, "getBeekeeperState",null).isEmpty()) { + if (assurance.metaClass.respondsTo(assurance, "getBeekeeper", null).isEmpty()) { + cap = assurance.getReport().getStatus() + } else { + cap = assurance.getBeekeeper().getStatus() + } } else { cap = assurance.getBeekeeperState().getStatus() } @@ -371,6 +375,7 @@ if (type == Product.OPERATIONS_CENTER) { // After upgrading masters (in case of OC)... def _status = executeScript(script_status) +println _status // If plugin requires update if (_status[0] == '1') { println "Analyzing " + type + "... " From 354a1afbc309b23ed340f1b427039daf15427003 Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Mon, 20 Apr 2020 19:09:05 +0200 Subject: [PATCH 3/8] debug false as default --- license-upgrade/upgrade-license-plugin.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/license-upgrade/upgrade-license-plugin.groovy b/license-upgrade/upgrade-license-plugin.groovy index 6986a1b..2e7a36a 100644 --- a/license-upgrade/upgrade-license-plugin.groovy +++ b/license-upgrade/upgrade-license-plugin.groovy @@ -8,7 +8,7 @@ Checks for and applies incremental updates for you jenkins instances so that the // automatically using the script. def restart = false // set debug = true for additional debug ouput. The output is supposed to be consumed by a support engineer. -def debug = true +def debug = false // set direct = true to enable directly updating the cloudbees-license-plugin if no incremental update is available (should not be needed). // direct method is useful when BeeKeeper is disabled or the instance cannot reach the public update site. It only replaces the current version // of cloudbees-license plugin by its patched version. @@ -375,7 +375,6 @@ if (type == Product.OPERATIONS_CENTER) { // After upgrading masters (in case of OC)... def _status = executeScript(script_status) -println _status // If plugin requires update if (_status[0] == '1') { println "Analyzing " + type + "... " From adcf811d9366f39153b5e4fbdfd1f688a49bead4 Mon Sep 17 00:00:00 2001 From: mike cirioli Date: Mon, 20 Apr 2020 13:54:25 -0400 Subject: [PATCH 4/8] remove confusing user message --- license-upgrade/upgrade-license-plugin.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/license-upgrade/upgrade-license-plugin.groovy b/license-upgrade/upgrade-license-plugin.groovy index 2e7a36a..8512696 100644 --- a/license-upgrade/upgrade-license-plugin.groovy +++ b/license-upgrade/upgrade-license-plugin.groovy @@ -367,7 +367,6 @@ if (type == Product.OPERATIONS_CENTER) { println 'You have one or more connected master instances that need to be upgraded.' } _summary2.append("You have one or more connected master instances that need to be upgraded.\n") - _summary2.append("Operations Center can not be upgraded until all connected master instances have been upgraded.\n") all = false } From 5c1ee2d1c749846e4a88257d882b4ab700772037 Mon Sep 17 00:00:00 2001 From: mike cirioli Date: Mon, 20 Apr 2020 13:54:51 -0400 Subject: [PATCH 5/8] add support for detecting CAP in cje 2.46 --- license-upgrade/verify-system-readiness.groovy | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/license-upgrade/verify-system-readiness.groovy b/license-upgrade/verify-system-readiness.groovy index 346d053..568c82f 100644 --- a/license-upgrade/verify-system-readiness.groovy +++ b/license-upgrade/verify-system-readiness.groovy @@ -19,7 +19,11 @@ try { def assurance = com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get() def cap if (assurance.metaClass.respondsTo(assurance, "getBeekeeperState",null).isEmpty()) { - cap = assurance.getBeekeeper().getStatus() + if (!assurance.metaClass.respondsTo(assurance, "getConfig", null).isEmpty()) { + cap = assurance.getConfig().get().isCap() + } else { + cap = assurance.getBeekeeper().getStatus() + } } else { cap = assurance.getBeekeeperState().getStatus() } From ab31464df1d507836c6c8513266403bd4d202f8e Mon Sep 17 00:00:00 2001 From: mike cirioli Date: Mon, 20 Apr 2020 14:00:22 -0400 Subject: [PATCH 6/8] slightly better way to detect beekeeper in 2.46 --- license-upgrade/verify-system-readiness.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/license-upgrade/verify-system-readiness.groovy b/license-upgrade/verify-system-readiness.groovy index 568c82f..87899c9 100644 --- a/license-upgrade/verify-system-readiness.groovy +++ b/license-upgrade/verify-system-readiness.groovy @@ -19,8 +19,8 @@ try { def assurance = com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get() def cap if (assurance.metaClass.respondsTo(assurance, "getBeekeeperState",null).isEmpty()) { - if (!assurance.metaClass.respondsTo(assurance, "getConfig", null).isEmpty()) { - cap = assurance.getConfig().get().isCap() + if (assurance.metaClass.respondsTo(assurance, "getBeekeeper", null).isEmpty()) { + cap = assurance.getReport().getStatus() } else { cap = assurance.getBeekeeper().getStatus() } From bae9036acb46f7eebb4b8133f30bb0b3c814975a Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Mon, 20 Apr 2020 21:05:35 +0200 Subject: [PATCH 7/8] missing method signature --- license-upgrade/upgrade-license-plugin.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/license-upgrade/upgrade-license-plugin.groovy b/license-upgrade/upgrade-license-plugin.groovy index 2e7a36a..48fb324 100644 --- a/license-upgrade/upgrade-license-plugin.groovy +++ b/license-upgrade/upgrade-license-plugin.groovy @@ -8,7 +8,7 @@ Checks for and applies incremental updates for you jenkins instances so that the // automatically using the script. def restart = false // set debug = true for additional debug ouput. The output is supposed to be consumed by a support engineer. -def debug = false +def debug = true // set direct = true to enable directly updating the cloudbees-license-plugin if no incremental update is available (should not be needed). // direct method is useful when BeeKeeper is disabled or the instance cannot reach the public update site. It only replaces the current version // of cloudbees-license plugin by its patched version. @@ -126,7 +126,6 @@ if (!assurance.ucRefresher.metaClass.respondsTo(assurance.ucRefresher, "awaitRef sleep(waitingFor) } } - assurance.refreshOfferedUpgrade() } def incrementalUpgrade = false From 1019e7147ce4c2a631ed96dee125f267529628be Mon Sep 17 00:00:00 2001 From: mike cirioli Date: Tue, 21 Apr 2020 11:28:58 -0400 Subject: [PATCH 8/8] WIP - this is nonsense --- license-upgrade/upgrade-license-plugin.groovy | 69 +++++++++++++++++-- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/license-upgrade/upgrade-license-plugin.groovy b/license-upgrade/upgrade-license-plugin.groovy index b0b0dbb..558f94c 100644 --- a/license-upgrade/upgrade-license-plugin.groovy +++ b/license-upgrade/upgrade-license-plugin.groovy @@ -25,6 +25,7 @@ try { def cap if (assurance.metaClass.respondsTo(assurance, "getBeekeeperState",null).isEmpty()) { if (assurance.metaClass.respondsTo(assurance, "getBeekeeper", null).isEmpty()) { + println("found old shitt") cap = assurance.getReport().getStatus() } else { cap = assurance.getBeekeeper().getStatus() @@ -103,11 +104,30 @@ def waitingFor = 2000 def assurance = com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get() -com.cloudbees.jenkins.plugins.assurance.props.BeekeeperProp.get().NO_FULL_UPGRADES.set() +println("enabling incrementals...") +try { + com.cloudbees.jenkins.plugins.assurance.props.BeekeeperProp.get().NO_FULL_UPGRADES.set() +} catch (Exception e) { + println "trying alternative method to enable incrementals" + setProperty("cb.BeekeeperProp.noFullUpgrade",true) +} +println("should be enabled") if (assurance.metaClass.respondsTo(assurance, "refreshOfferedUpgrade").isEmpty()) { - assurance.refreshStateSync() + println "1" + if (assurance.metaClass.respondsTo(assurance, "getBeekeeper", null).isEmpty()) { + println "2" + assurance.getOfferedEnvelope() + } else { + println("refresh1") + assurance.refreshStateSync() + } } -if (!assurance.ucRefresher.metaClass.respondsTo(assurance.ucRefresher, "awaitRefresh").isEmpty()) { +println "3" + +if (!assurance.metaClass.respondsTo(assurance,"getOfferedEnvelope").isEmpty()) { + println "nope" +} else if (!assurance.ucRefresher.metaClass.respondsTo(assurance.ucRefresher, "awaitRefresh").isEmpty()) { + println("AA") def ucFuture = assurance.refreshUpdateCenters() for(int i=1; i<=tries; i++) { if(ucFuture.isDone()) { @@ -118,6 +138,7 @@ if (!assurance.ucRefresher.metaClass.respondsTo(assurance.ucRefresher, "awaitRef } assurance.refreshStateSync() } else { + println("BB") assurance.ucRefresher.refresh() for(int i=1; i<=tries; i++) { if (com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getOfferedUpgrade().getClass().getName() == 'com.cloudbees.jenkins.plugins.assurance.OfferedUpgrade$Incremental') { @@ -127,12 +148,42 @@ if (!assurance.ucRefresher.metaClass.respondsTo(assurance.ucRefresher, "awaitRef } } } +println "bbbbbbbb" def incrementalUpgrade = false if (assurance.metaClass.respondsTo(assurance, "getUpgradeAction").isEmpty()) { - // == 2.60.xxx - if (com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getOfferedUpgrade().getClass().getName() == 'com.cloudbees.jenkins.plugins.assurance.OfferedUpgrade$Incremental') { + println "ccc" + if (!assurance.metaClass.respondsTo(assurance,"getOfferedEnvelope").isEmpty()) { + println "aha!" + def cap = com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get() + def installedEnvelope = cap.getConfig().get().getEnvelope().getEnvelope() + def parsedEnvelope = cap.getOfferedEnvelope() + def offeredEnvelope = cap.getOfferedEnvelope().getEnvelope() + if (offeredEnvelope.isIncrementalUpgrade(installedEnvelope).toString()) { + println "indeed!" + incrementalUpgrade = true + def usItem = cap.getReport().getUpdateSiteItem() + println "a1" + if (usItem != null) { + println "a2" + def updateSite = usItem.getOnline() + if (updateSite != null) { + println "a3" + println "offered envelope " + offeredEnvelope + println "updateSite = " + updateSite + try { + cap.stage(parsedEnvelope, updateSite) + } catch (Exception e) { + println "e:" + e + } + println "almost there!" + } + } + } + } else if (com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getOfferedUpgrade().getClass().getName() == 'com.cloudbees.jenkins.plugins.assurance.OfferedUpgrade$Incremental') { + // == 2.60.xxx + println "ddd" incrementalUpgrade = true def offered = com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getOfferedUpgrade() if (!offered.metaClass.respondsTo(offered, "pick", null).isEmpty()) { @@ -142,10 +193,11 @@ if (assurance.metaClass.respondsTo(assurance, "getUpgradeAction").isEmpty()) { } else { incrementalUpgrade = false } - } + } } else { // != 2.60.xxx if (com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getUpgradeAction().getUpgrade().isIncrementalUpgrade()) { + println "eee" incrementalUpgrade = true com.cloudbees.jenkins.plugins.assurance.CloudBeesAssurance.get().getUpgradeAction().getUpgrade().pick(false, null) } @@ -265,7 +317,6 @@ return _restart ? "RESTART_REQUIRED" : "NO" println "upgrade-license-plugin.groovy running..." - def _statusKey = [] _statusKey[0] = "Plugin requires update?" _statusKey[1] = "Is your instance compatible with Incremental Upgrades?" @@ -277,8 +328,10 @@ _statusKey[5] = "Error message" def _summary = new StringBuilder() def _summary2 = new StringBuilder() +println "before prod type" def type = productType() + println "Determine the instance type: " + type boolean all = true if (type == Product.OPERATIONS_CENTER) { @@ -371,6 +424,8 @@ if (type == Product.OPERATIONS_CENTER) { } +println "not OC" + // After upgrading masters (in case of OC)... def _status = executeScript(script_status) // If plugin requires update