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..558f94c 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,13 @@ 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()) { + println("found old shitt") + cap = assurance.getReport().getStatus() + } else { + cap = assurance.getBeekeeper().getStatus() + } } else { cap = assurance.getBeekeeperState().getStatus() } @@ -94,33 +99,109 @@ 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() + +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()) { + println "1" + if (assurance.metaClass.respondsTo(assurance, "getBeekeeper", null).isEmpty()) { + println "2" + assurance.getOfferedEnvelope() + } else { + println("refresh1") + assurance.refreshStateSync() + } +} +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()) { + break; + } else { + sleep(waitingFor) + } + } + 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') { + break; + } else { + sleep(waitingFor) + } + } +} +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",void).isEmpty()) { + if (!offered.metaClass.respondsTo(offered, "pick", null).isEmpty()) { offered.pick() } else if (!offered.metaClass.respondsTo(offered, "pick", boolean).isEmpty()) { offered.pick(false) } 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) } } - return incrementalUpgrade ? "RESTART_REQUIRED" : "NO" } catch (Exception fatal) { return "ERROR. Cause: " + fatal.getMessage()}''' @@ -236,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?" @@ -248,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) { @@ -337,12 +419,13 @@ 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 } } +println "not OC" + // After upgrading masters (in case of OC)... def _status = executeScript(script_status) // If plugin requires update @@ -471,7 +554,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..87899c9 100644 --- a/license-upgrade/verify-system-readiness.groovy +++ b/license-upgrade/verify-system-readiness.groovy @@ -18,8 +18,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() } @@ -315,7 +319,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