Skip to content

Commit

Permalink
Reinstate the released lock messages for freestyle builds (removed by j…
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoote committed Oct 22, 2024
1 parent 1f0dff5 commit 5a88765
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -643,19 +643,27 @@ private void freeResources(List<LockableResource> unlockResources, Run<?, ?> bui
removeResources(toBeRemoved);
}

public void unlockBuild(@Nullable Run<?, ?> build) {
@NonNull
public List<String> unlockBuild2(@Nullable Run<?, ?> build) {

if (build == null) {
return;
return Collections.emptyList();
}

List<String> resourcesInUse =
LockedResourcesBuildAction.findAndInitAction(build).getCurrentUsedResourceNames();
List<String> resourcesInUse = new ArrayList<>(
LockedResourcesBuildAction.findAndInitAction(build).getCurrentUsedResourceNames());

if (resourcesInUse.size() == 0) {
return;
if (!resourcesInUse.isEmpty()) {
unlockNames(resourcesInUse, build);
}
unlockNames(resourcesInUse, build);
return resourcesInUse;
}

/** @deprecated Use unlockBuild2 */
@Deprecated
public void unlockBuild(@Nullable Run<?, ?> build) {

unlockBuild2(build);
}

// ---------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,29 @@ public void onCompleted(Run<?, ?> build, @NonNull TaskListener listener) {
// Skip unlocking for multiple configuration projects,
// only the child jobs will actually unlock resources.
if (build instanceof MatrixBuild) return;
LOGGER.info(build.getFullDisplayName());
LockableResourcesManager.get().unlockBuild(build);

List<String> unlocked = LockableResourcesManager.get().unlockBuild2(build);
if (!unlocked.isEmpty()) {
listener.getLogger().printf("%s released lock on %s%n", LOG_PREFIX, unlocked);
LOGGER.info(build.getFullDisplayName()
+ " released lock on "
+ unlocked
+ ", because the build has finished.");
}
}

@Override
public void onDeleted(Run<?, ?> build) {
// Skip unlocking for multiple configuration projects,
// only the child jobs will actually unlock resources.
if (build instanceof MatrixBuild) return;
LOGGER.info(build.getFullDisplayName());
LockableResourcesManager.get().unlockBuild(build);

List<String> unlocked = LockableResourcesManager.get().unlockBuild2(build);
if (!unlocked.isEmpty()) {
LOGGER.warning(build.getFullDisplayName()
+ " released lock on "
+ unlocked
+ ", because the build has been deleted.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
QueueTaskFuture<FreeStyleBuild> fb2q = f2.scheduleBuild2(0);

semaphore.release();
j.waitForMessage("released lock on [shared]", fb0);
j.waitForCompletion(fb0);
// fb1 or fb2 might run first, it shouldn't matter as long as they both get the resource
FreeStyleBuild fb1 = fb1q.waitForStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class NodesMirrorTest {

private static final Logger LOGGER = Logger.getLogger(NodesMirror.class.getName());
private static final Logger LOGGER = Logger.getLogger(NodesMirrorTest.class.getName());

@Rule
public final JenkinsRule j = new JenkinsRule();
Expand Down

0 comments on commit 5a88765

Please sign in to comment.