Skip to content

Commit

Permalink
[JENKINS-23538] Remove support for Legacy Sorter
Browse files Browse the repository at this point in the history
 
 * Upgrading removed, upgrade will remove old config-data
 * Instructions to downgrade to convert and keep data added
  • Loading branch information
emsa23 committed Jun 26, 2014
1 parent a5d32d7 commit 06ff261
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 73 deletions.
34 changes: 0 additions & 34 deletions src/main/java/hudson/queueSorter/PrioritySorterDefaults.java

This file was deleted.

Expand Up @@ -58,7 +58,7 @@ public String getDisplayName() {
}

public int getDefault() {
return PrioritySorterDefaults.getDefault();
return 0;
}

public boolean isUsed() {
Expand Down
Expand Up @@ -62,8 +62,6 @@ public class PrioritySorterConfiguration extends GlobalConfiguration {
MultiBucketStrategy.DEFAULT_PRIORITIES_NUMBER, MultiBucketStrategy.DEFAULT_PRIORITY);

private boolean legacyMode = false;
private Integer legacyMaxPriority = Integer.MAX_VALUE;
private Integer legacyMinPriority = Integer.MIN_VALUE;

/**
* @deprecated used in 2.x - replaces with XXX
Expand Down Expand Up @@ -175,8 +173,6 @@ private void checkLegacy() {
SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
try {
legacyMode = false;
legacyMaxPriority = Integer.MAX_VALUE;
legacyMinPriority = Integer.MIN_VALUE;

// getAllItems() doesn't return MatrixProject even if actually is a Project
// since it also is a group of items (ItemGroup) in the tree being traversed
Expand All @@ -187,8 +183,6 @@ private void checkLegacy() {
PrioritySorterJobProperty priority = project.getProperty(PrioritySorterJobProperty.class);
if (priority != null) {
legacyMode = true;
legacyMaxPriority = Math.max(legacyMaxPriority, priority.priority);
legacyMinPriority = Math.min(legacyMinPriority, priority.priority);
}
}
}
Expand Down Expand Up @@ -241,42 +235,24 @@ private void updatePriorities(int prevNumberOfPriorities) {
}

private void convertFromLegacyToAdvanced() {
// Update legacy range first
checkLegacy();
// Shouldn't really by a permission problem when getting here but
// to be on the safe side
SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
try {
if (getLegacyMode()) {
//
@SuppressWarnings("rawtypes")
List<AbstractProject> allProjects = Jenkins.getInstance().getAllItems(AbstractProject.class);
for (AbstractProject<?, ?> project : allProjects) {
PrioritySorterJobProperty legacyPriorityProperty = project
.getProperty(PrioritySorterJobProperty.class);
if (legacyPriorityProperty != null) {
int advancedPriority = legacyPriorityToAdvancedPriority(legacyMinPriority, legacyMaxPriority,
strategy.getNumberOfPriorities(), legacyPriorityProperty.priority);
PriorityJobProperty advancedQueueSorterJobProperty = new PriorityJobProperty(
true, advancedPriority);
try {
project.addProperty(advancedQueueSorterJobProperty);
project.save();
} catch (IOException e) {
LOGGER.warning("Failed to add Advanced Job Priority To " + project.getName());
}
}
try {
project.removeProperty(legacyPriorityProperty);
project.save();
} catch (IOException e) {
LOGGER.warning("Failed to remove Legacy Job Priority From " + project.getName());
}
@SuppressWarnings("rawtypes")
List<AbstractProject> allProjects = Jenkins.getInstance().getAllItems(AbstractProject.class);
for (AbstractProject<?, ?> project : allProjects) {
PrioritySorterJobProperty legacyPriorityProperty = project
.getProperty(PrioritySorterJobProperty.class);
try {
project.removeProperty(PrioritySorterJobProperty.class);
project.save();
} catch (IOException e) {
LOGGER.warning("Failed to remove Legacy Job Priority From " + project.getName());
}

// Finally, switch Legacy Mode
legacyMode = false;
}
}
// Finally, switch Legacy Mode
legacyMode = false;
} finally {
SecurityContextHolder.setContext(saveCtx);
}
Expand Down
@@ -1,7 +1,8 @@
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
<f:section title="Priority Sorter">
<j:if test="${instance.legacyMode}">
<h3>Priority Sorter found Legacy configuration data, please update the configuration to continue using the Priority Sorter</h3>
<h3>Priority Sorter found Legacy configuration data (version 1.x). This data will be removed when you switch to Advanced mode.</h3>
<h3><i>To keep and convert you priority configurations please downgrade to version 2.x, switch to advanced mode and then to 3.x</i></h3>
<f:optionalBlock title="${%Switch to Advanced Priority Sorter Mode}"
checked="false" inline="true" name="advanced">
<f:dropdownDescriptorSelector field="strategy" title="${%Strategy}"/>
Expand Down

0 comments on commit 06ff261

Please sign in to comment.