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 31, 2024
1 parent ed786ba commit 8917e48
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -649,32 +649,34 @@ private void freeResources(List<LockableResource> unlockResources, Run<?, ?> bui
removeResources(toBeRemoved);
}

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

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

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

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

// ---------------------------------------------------------------------------
@NonNull
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "not sure which exceptions might be catch.")
public void unlockNames(@Nullable List<String> resourceNamesToUnLock, Run<?, ?> build) {
public List<String> unlockNames(@Nullable List<String> resourceNamesToUnLock, Run<?, ?> build) {

// make sure there is a list of resource names to unlock
if (resourceNamesToUnLock == null || resourceNamesToUnLock.isEmpty()) {
return;
return Collections.emptyList();
}

List<String> unlockedResourceNames;
synchronized (this.syncResources) {
unlockedResourceNames = new ArrayList<>(resourceNamesToUnLock);
unlockResources(this.fromNames(resourceNamesToUnLock), build);
}
return unlockedResourceNames;
}

// ---------------------------------------------------------------------------
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().unlockBuild(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().unlockBuild(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 @@ -259,6 +259,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 8917e48

Please sign in to comment.