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

2.46.2.1 wip #133

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion license-upgrade/apply-license.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
111 changes: 98 additions & 13 deletions license-upgrade/upgrade-license-plugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
}
Expand Down Expand Up @@ -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()}'''

Expand Down Expand Up @@ -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?"
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions license-upgrade/verify-system-readiness.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand Down