Class LockableResource
java.lang.Object
hudson.model.AbstractDescribableImpl<LockableResource>
org.jenkins.plugins.lockableresources.LockableResource
- All Implemented Interfaces:
Describable<LockableResource>,Serializable
@ExportedBean(defaultVisibility=999)
public class LockableResource
extends AbstractDescribableImpl<LockableResource>
implements Serializable
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLockableResource(String name) Deprecated.Use single-argument constructor instead (since 1.8) -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddShareHolder(String entry) Adds the entry of a lock block joining the current hold.static StringbuildIdOfShareHolderEntry(String entry) Extracts the build externalizable id from a holder entry.voidClears the share id and all holder entries.voidcopyUnconfigurableProperties(LockableResource sourceResource) Copy unconfigurable properties from another instance.static DateFormatCreate a newSimpleDateFormatinstance for timestamp formatting.booleanRun<?, ?> getBuild()Id of the build holding the lock, also when that build no longer exists.Returns why this resource is disabled.getGroup()Deprecated.Get labels of this resourceReturns the labels as a single space-separated string.Resolve the lock cause for this resource.Resolve the lock detailed cause for this resource.Returns the reason why this resource is currently locked.getName()getNote()Builds holding this resource besides the primary holder, as externalizable ids, in acquisition order.List<org.jenkinsci.plugins.workflow.steps.StepContext> Deprecated.Replaced with LockableResourcesManager.queuedContexts (since 1.11)longlongReturns when the pending delayed release frees this resource.Returns the clientId of the remote holder, ornullif the record is not found (e.g.Returns the fullRemoteLockRecordfor the active remote lock, ornullif the resource is not remotely locked or the record is no longer available.Distinct externalizable ids of the builds holding this resource, primary holder first.Snapshot of the holder entries, in acquisition order.Share id of the current hold, ornullwhen it is not shared.getTask()static StringThe builds ofgetOtherShareHolderBuilds()that still exist and that the current user may see, for the resources page.inthashCode()booleanChecks if the resource has label *labelToFind*booleanhasShareHolder(String entry) booleanbooleanReturn true when the resource is disabled and must not be given to new lock requests.booleanbooleanisFree()Return true when resource is free.booleanisLocked()booleanbooleanisQueued()booleanisQueued(long taskId) booleanisQueuedByTask(long taskId) booleanReturn true when the lock is held only until its release delay is over.booleanbooleanFunction check if the resources is reserved by currently logged userbooleanisShareHolderBuild(String buildExternalizableId) True when at least one entry of the given build holds this resource.booleanisStolen()booleanisValidLabel(String candidate) Check if the given *candidate* label is valid or not.booleanisValidLabel(String candidate, Map<String, Object> params) Deprecated.Use isValidLabel(String candidate)static StringnormalizeGroup(String group) protected Objectvoidrecycle()Tell LRM to recycle this resource, including notifications for whoever may be waiting in the queue so they can proceed immediately.booleanremoveShareHolder(String entry) Removes the entry of one lock block.booleanremoveShareHoldersOfBuild(String buildExternalizableId) Removes all entries of a build (hard kill, deletion).voidvoidvoidreset()voidReset unconfigurable properties.booleanscriptMatches(org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript script, Map<String, Object> params) Checks if the script matches the requirement.voidvoidsetDescription(String description) voidsetDisabledCause(String disabledCause) Disables or enables this resource.voidsetEphemeral(boolean ephemeral) voidvoidDeprecated.no equivalent at the time.voidsetLabelsFromString(String labels) Sets labels from a space-separated string.voidsetLockReason(String lockReason) Sets the reason why this resource is being locked.voidsetNodeResource(boolean b) voidvoidsetProperties(List<LockableResourceProperty> properties) voidsetQueued(long queueItemId) voidvoidsetReleaseAt(long releaseAt) voidsetRemoteLockedBy(String lockId) voidsetReservedBy(String userName) voidsetReservedTimestamp(Date reservedTimestamp) voidstatic StringshareHolderEntry(String buildExternalizableId, String blockStartNodeId) Builds a holder entry for one lock block:<buildExternalizableId>@<blockStartNodeId>.voidstartShare(Run<?, ?> build, String shareId, String entry) Starts a hold by its first lock block: sets the primary build, the share id (may benullfor a plain hold that the same build may re-enter) and the first holder entry.toString()voidunqueue()voidMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface hudson.model.Describable
getDescriptor
-
Field Details
-
NOT_QUEUED
public static final int NOT_QUEUED- See Also:
-
GROOVY_LABEL_MARKER
- See Also:
-
-
Constructor Details
-
Method Details
-
getGroup
- Since:
- TODO
-
setGroup
- Since:
- TODO
-
normalizeGroup
- Since:
- TODO
-
readResolve
-
getQueuedContexts
Deprecated.Replaced with LockableResourcesManager.queuedContexts (since 1.11) -
isNodeResource
public boolean isNodeResource() -
setNodeResource
public void setNodeResource(boolean b) -
getName
-
getDescription
-
setDescription
-
getNote
-
setNote
-
getLockReason
Returns the reason why this resource is currently locked.- Returns:
- The lock reason, or empty string if not set.
-
setLockReason
Sets the reason why this resource is being locked. This is typically set via the lock() step's reason parameter and cleared when the resource is unlocked.- Parameters:
lockReason- The reason for locking, or null to clear.
-
getDisabledCause
Returns why this resource is disabled.- Returns:
- The disabled cause, or
nullwhen the resource is enabled.
-
setDisabledCause
Disables or enables this resource. This only changes the field. UseLockableResourcesManager.setDisabledCause(LockableResource, String)to also let waiting builds take the resource once it is enabled again.- Parameters:
disabledCause- Why the resource is disabled, ornull(or blank) to enable it.
-
isDisabled
@Exported public boolean isDisabled()Return true when the resource is disabled and must not be given to new lock requests. -
setEphemeral
@DataBoundSetter public void setEphemeral(boolean ephemeral) -
isEphemeral
@Exported public boolean isEphemeral() -
getLabels
Deprecated.Use getLabelsAsList instead todo This function is marked as deprecated but it is still used in tests and jelly (config) files. -
getLabelsAsString
Returns the labels as a single space-separated string.This is the non-deprecated replacement for
getLabels(). -
setLabels
Deprecated.no equivalent at the time. todo It shall be created new one function selLabelsAsList() and use that one. But it must be checked and changed all config.jelly files and this might takes more time as expected. That the reason why a deprecated function/property is still data-bound-setter -
setLabelsFromString
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void setLabelsFromString(@Nullable String labels) Sets labels from a space-separated string.This is the non-deprecated replacement for
setLabels(String). -
getLabelsAsList
Get labels of this resource- Returns:
- List of assigned labels.
-
hasLabel
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean hasLabel(@CheckForNull String labelToFind) Checks if the resource has label *labelToFind*- Parameters:
labelToFind- Label to find.- Returns:
trueif this resource contains the label.
-
isValidLabel
Deprecated.Use isValidLabel(String candidate) -
isValidLabel
Check if the given *candidate* label is valid or not. candidate may be one label or Label expression (see also https://www.jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#node-allocate-node). Valid means that the resource contains the label or the Label-expression matched. -
getProperties
-
setProperties
-
scriptMatches
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean scriptMatches(@NonNull org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript script, @CheckForNull Map<String, Object> params) throws ExecutionExceptionChecks if the script matches the requirement.- Parameters:
script- Script to be executedparams- Extra script parameters- Returns:
trueif the script returns true (resource matches).- Throws:
ExecutionException- Script execution failed (e.g. due to the missing permissions). Carries info in the cause
-
getReservedTimestamp
-
setReservedTimestamp
-
getReservedBy
-
isFree
@Exported public boolean isFree()Return true when resource is free. False otherwise -
isReserved
@Exported public boolean isReserved() -
getUserName
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @CheckForNull public static String getUserName() -
isReservedByCurrentUser
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean isReservedByCurrentUser()Function check if the resources is reserved by currently logged user- Returns:
- true when reserved by current user, false otherwise.
-
getReservedByEmail
-
isQueued
public boolean isQueued() -
isQueued
public boolean isQueued(long taskId) -
isQueuedByTask
public boolean isQueuedByTask(long taskId) -
unqueue
public void unqueue() -
isLocked
@Exported public boolean isLocked() -
isReleaseDelayed
@Exported public boolean isReleaseDelayed()Return true when the lock is held only until its release delay is over. -
getReleaseDelayedUntil
Returns when the pending delayed release frees this resource.- Returns:
- the release time, or null when no delayed release is pending.
-
getBuildExternalizableId
@CheckForNull @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public String getBuildExternalizableId()Id of the build holding the lock, also when that build no longer exists. -
getReleaseAt
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public long getReleaseAt() -
setReleaseAt
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void setReleaseAt(long releaseAt) -
getRemoteLockedBy
-
getRemoteLockClientId
Returns the clientId of the remote holder, ornullif the record is not found (e.g. after a Jenkins restart) or the caller did not provide one. -
getRemoteLockRecord
Returns the fullRemoteLockRecordfor the active remote lock, ornullif the resource is not remotely locked or the record is no longer available. Used by the Jelly table to display lock details in the heldBy column. -
setRemoteLockedBy
-
getLockCause
Resolve the lock cause for this resource. It can be reserved or locked. The timestamp uses a fixed ISO-like pattern (yyyy-MM-dd'T'HH:mm:ssZ) with the JVM default time zone anden_USlocale, so the output is stable across locales and comparable across controllers.- Returns:
- the lock cause or null if not locked
-
createTimestampFormat
Create a newSimpleDateFormatinstance for timestamp formatting.SimpleDateFormatis not thread-safe, so each caller must create its own instance. The format uses an ISO-like pattern with time zone and a fixeden_USlocale so that log lines from different controllers or agents are comparable. -
getLockCauseDetail
@CheckForNull @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public String getLockCauseDetail()Resolve the lock detailed cause for this resource. Note: this function is used in lock() step and not in the UI. Therefore moving text into localization files does not make really sense.- Returns:
- the lock cause or null if not locked
-
getBuild
-
getBuildName
-
setBuild
-
getTask
-
getQueueItemId
public long getQueueItemId() -
getQueueItemProject
-
setQueued
public void setQueued(long queueItemId) -
setQueued
-
setReservedBy
-
setStolen
public void setStolen() -
isStolen
@Exported public boolean isStolen() -
reserve
-
reserve
-
unReserve
public void unReserve() -
reset
public void reset() -
copyUnconfigurableProperties
Copy unconfigurable properties from another instance. Normally, called after "lockable resource" configuration change.- Parameters:
sourceResource- resource with properties to copy from
-
resetUnconfigurableProperties
public void resetUnconfigurableProperties()Reset unconfigurable properties. Normally, called after "lockable resource" configuration change, to make sure that these fields are ignored if defined in CasC configuration file. -
recycle
public void recycle()Tell LRM to recycle this resource, including notifications for whoever may be waiting in the queue so they can proceed immediately. WARNING: Do not use this from inside the lock step closure which originally locked this resource, to avoid nasty surprises! Just stick with unReserve() and close the closure, if needed. -
toString
-
hashCode
public int hashCode() -
equals
-