Skip to content

Commit

Permalink
Merge branch 'jenkinsci:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mPokornyETM authored Sep 17, 2024
2 parents 861833e + e218743 commit 1757b31
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v4

- name: crowdin action
uses: crowdin/github-action@v2.0.0
uses: crowdin/github-action@v2.1.2
with:
upload_translations: false
download_translations: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/jenkins-security-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
security-scan:
uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2
with:
java-cache: 'maven'
java-version: 11
java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate.
# java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Jenkins Plugin Installs](https://img.shields.io/jenkins/plugin/i/lockable-resources.svg?color=blue)](https://plugins.jenkins.io/lockable-resources)
[![Build Status](https://ci.jenkins.io/buildStatus/icon?job=Plugins%2Flockable-resources-plugin%2Fmaster)](https://ci.jenkins.io/job/Plugins/job/lockable-resources-plugin/job/master/)
[![GitHub license](https://img.shields.io/github/license/jenkinsci/lockable-resources-plugin.svg)](https://github.com/jenkinsci/lockable-resources-plugin/blob/master/LICENSE.txt)
[![Maintenance](https://img.shields.io/maintenance/yes/2023.svg)](https://github.com/jenkinsci/lockable-resources-plugin)
[![Maintenance](https://img.shields.io/maintenance/yes/2024.svg)](https://github.com/jenkinsci/lockable-resources-plugin)
[![Crowdin](https://badges.crowdin.net/e/656dcffac5a09ad0fbdedcb430af1904/localized.svg)](https://jenkins.crowdin.com/lockable-resources-plugin)
[![Join the chat at https://gitter.im/jenkinsci/lockable-resources](https://badges.gitter.im/jenkinsci/lockable-resources.svg)](https://gitter.im/jenkinsci/lockable-resources?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.83</version>
<version>4.87</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.440.x</artifactId>
<version>3120.v4d898e1e9fc4</version>
<version>3358.vea_fa_1f41504d</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,28 @@ public LockStepExecution(LockStep step, StepContext context) {

@Override
public boolean start() throws Exception {
step.validate();

// normally it might raise a exception, but we check it in the function .validate()
// therefore we can skip the try-catch here.
ResourceSelectStrategy resourceSelectStrategy =
ResourceSelectStrategy.valueOf(step.resourceSelectStrategy.toUpperCase(Locale.ENGLISH));

getContext().get(FlowNode.class).addAction(new PauseAction("Lock"));
PrintStream logger = getContext().get(TaskListener.class).getLogger();

Run<?, ?> run = getContext().get(Run.class);
LockableResourcesManager.printLogs("Trying to acquire lock on [" + step + "]", Level.FINE, LOGGER, logger);

List<LockableResourcesStruct> resourceHolderList = new ArrayList<>();

LockableResourcesManager lrm = LockableResourcesManager.get();
List<LockableResource> available = null;
LinkedHashMap<String, List<LockableResourceProperty>> resourceNames = new LinkedHashMap<>();
LinkedHashMap<String, List<LockableResourceProperty>> lockedResources = new LinkedHashMap<>();
LockableResourcesManager lrm = LockableResourcesManager.get();
synchronized (lrm.syncResources) {
step.validate();

LockableResourcesManager.printLogs("Trying to acquire lock on [" + step + "]", Level.FINE, LOGGER, logger);

getContext().get(FlowNode.class).addAction(new PauseAction("Lock"));

List<String> resourceNames = new ArrayList<>();
for (LockStepResource resource : step.getResources()) {
List<String> resources = new ArrayList<>();
if (resource.resource != null) {
Expand All @@ -71,10 +74,15 @@ public boolean start() throws Exception {
logger);
}
resources.add(resource.resource);
resourceNames.addAll(resources);
} else {
resourceNames.add("N/A");
}
resourceHolderList.add(new LockableResourcesStruct(resources, resource.label, resource.quantity));
}

LockedResourcesBuildAction.addLog(run, resourceNames, "try", step.toString());

// determine if there are enough resources available to proceed
available = lrm.getAvailableResources(resourceHolderList, logger, resourceSelectStrategy);
if (available == null || available.isEmpty()) {
Expand All @@ -95,10 +103,10 @@ public boolean start() throws Exception {
// since LockableResource contains transient variables, they cannot be correctly serialized
// hence we use their unique resource names and properties
for (LockableResource resource : available) {
resourceNames.put(resource.getName(), resource.getProperties());
lockedResources.put(resource.getName(), resource.getProperties());
}
LockStepExecution.proceed(lockedResources, getContext(), step.toString(), step.variable);
}
LockStepExecution.proceed(resourceNames, getContext(), step.toString(), step.variable);

return false;
}
Expand Down Expand Up @@ -166,11 +174,12 @@ public static void proceed(
}

try {

LockedResourcesBuildAction.updateAction(build, new ArrayList<>(lockedResources.keySet()));
List<String> resourceNames = new ArrayList<>(lockedResources.keySet());
final String resourceNamesAsString = String.join(",", lockedResources.keySet());
LockedResourcesBuildAction.addLog(build, resourceNames, "acquired", resourceDescription);
PauseAction.endCurrentPause(node);
BodyInvoker bodyInvoker = context.newBodyInvoker()
.withCallback(new Callback(new ArrayList<>(lockedResources.keySet()), resourceDescription));
BodyInvoker bodyInvoker =
context.newBodyInvoker().withCallback(new Callback(resourceNames, resourceDescription));
if (variable != null && !variable.isEmpty()) {
// set the variable for the duration of the block
bodyInvoker.withContext(
Expand All @@ -180,8 +189,7 @@ public static void proceed(
@Override
public void expand(@NonNull EnvVars env) {
final LinkedHashMap<String, String> variables = new LinkedHashMap<>();
final String resourceNames = String.join(",", lockedResources.keySet());
variables.put(variable, resourceNames);
variables.put(variable, resourceNamesAsString);
int index = 0;
for (Entry<String, List<LockableResourceProperty>> lockResourceEntry :
lockedResources.entrySet()) {
Expand Down Expand Up @@ -222,9 +230,11 @@ private static final class Callback extends BodyExecutionCallback.TailCall {

@Override
protected void finished(StepContext context) throws Exception {
LockableResourcesManager.get().unlockNames(this.resourceNames, context.get(Run.class));
Run<?, ?> build = context.get(Run.class);
LockedResourcesBuildAction.addLog(build, this.resourceNames, "released", this.resourceDescription);
LockableResourcesManager.get().unlockNames(this.resourceNames, build);
LockableResourcesManager.printLogs(
"Lock released on resource [" + resourceDescription + "]",
"Lock released on resource [" + this.resourceDescription + "]",
Level.FINE,
LOGGER,
context.get(TaskListener.class).getLogger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,18 @@ public String getLockCauseDetail() {
return build;
}

// ---------------------------------------------------------------------------
@Exported
public String getBuildName() {
if (getBuild() != null) return getBuild().getFullDisplayName();
else return null;
}

// ---------------------------------------------------------------------------
public void setBuild(@Nullable Run<?, ?> lockedBy) {

this.build = lockedBy;

if (lockedBy != null) {
this.buildExternalizableId = lockedBy.getExternalizableId();
setReservedTimestamp(new Date());
Expand Down
Loading

0 comments on commit 1757b31

Please sign in to comment.