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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LockableResource.DescriptorImpl
-
Field Summary
Fields Modifier and Type Field Description static String
GROOVY_LABEL_MARKER
static int
NOT_QUEUED
-
Constructor Summary
Constructors Constructor Description LockableResource(String name)
LockableResource(String name, String description, String labels, String reservedBy, String note)
Deprecated.Use single-argument constructor instead (since 1.8)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
copyUnconfigurableProperties(LockableResource sourceResource)
Copy unconfigurable properties from another instance.boolean
equals(Object obj)
Run<?,?>
getBuild()
String
getBuildName()
String
getDescription()
String
getLabels()
Deprecated.List<String>
getLabelsAsList()
Get labels of this resourceString
getLockCause()
Resolve the lock cause for this resource.String
getLockCauseDetail()
Resolve the lock detailed cause for this resource.String
getName()
String
getNote()
List<LockableResourceProperty>
getProperties()
List<org.jenkinsci.plugins.workflow.steps.StepContext>
getQueuedContexts()
Deprecated.Replaced with LockableResourcesManager.queuedContexts (since 1.11)long
getQueueItemId()
String
getQueueItemProject()
String
getReservedBy()
String
getReservedByEmail()
Date
getReservedTimestamp()
Queue.Task
getTask()
static String
getUserName()
int
hashCode()
boolean
hasLabel(String labelToFind)
Checks if the resource has label *labelToFind*boolean
isEphemeral()
boolean
isFree()
Return true when resource is free.boolean
isLocked()
boolean
isNodeResource()
boolean
isQueued()
boolean
isQueued(long taskId)
boolean
isQueuedByTask(long taskId)
boolean
isReserved()
boolean
isReservedByCurrentUser()
Function check if the resources is reserved by currently logged userboolean
isStolen()
boolean
isValidLabel(String candidate)
Check if the given *candidate* label is valid or not.boolean
isValidLabel(String candidate, Map<String,Object> params)
Deprecated.Use isValidLabel(String candidate)protected Object
readResolve()
void
recycle()
Tell LRM to recycle this resource, including notifications for whoever may be waiting in the queue so they can proceed immediately.void
reserve(String userName)
void
reset()
boolean
scriptMatches(org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript script, Map<String,Object> params)
Checks if the script matches the requirement.void
setBuild(Run<?,?> lockedBy)
void
setDescription(String description)
void
setEphemeral(boolean ephemeral)
void
setLabels(String labels)
Deprecated.no equivalent at the time.void
setNodeResource(boolean b)
void
setNote(String note)
void
setProperties(List<LockableResourceProperty> properties)
void
setQueued(long queueItemId)
void
setQueued(long queueItemId, String queueProjectName)
void
setReservedBy(String userName)
void
setReservedTimestamp(Date reservedTimestamp)
void
setStolen()
String
toString()
void
unqueue()
void
unReserve()
-
Methods inherited from class hudson.model.AbstractDescribableImpl
getDescriptor
-
-
-
-
Field Detail
-
NOT_QUEUED
public static final int NOT_QUEUED
- See Also:
- Constant Field Values
-
GROOVY_LABEL_MARKER
public static final String GROOVY_LABEL_MARKER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LockableResource
@Deprecated public LockableResource(String name, String description, String labels, String reservedBy, String note)
Deprecated.Use single-argument constructor instead (since 1.8)
-
LockableResource
@DataBoundConstructor public LockableResource(@CheckForNull String name)
-
-
Method Detail
-
readResolve
protected Object readResolve()
-
getQueuedContexts
@Deprecated public List<org.jenkinsci.plugins.workflow.steps.StepContext> getQueuedContexts()
Deprecated.Replaced with LockableResourcesManager.queuedContexts (since 1.11)
-
isNodeResource
public boolean isNodeResource()
-
setNodeResource
public void setNodeResource(boolean b)
-
getName
@Exported public String getName()
-
getDescription
@Exported public String getDescription()
-
setDescription
@DataBoundSetter public void setDescription(@Nullable String description)
-
getNote
@Exported public String getNote()
-
setNote
@DataBoundSetter public void setNote(@Nullable String note)
-
setEphemeral
@DataBoundSetter public void setEphemeral(boolean ephemeral)
-
isEphemeral
@Exported public boolean isEphemeral()
-
getLabels
@Deprecated @Exported public String getLabels()
Deprecated.Use getLabelsAsList instead todo This function is marked as deprecated but it is still used in tests ans jelly (config) files.
-
setLabels
@DataBoundSetter public void setLabels(@Nullable String labels)
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
-
getLabelsAsList
@Exported public List<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:
true
if this resource contains the label.
-
isValidLabel
@Deprecated public boolean isValidLabel(String candidate, Map<String,Object> params)
Deprecated.Use isValidLabel(String candidate)
-
isValidLabel
public boolean isValidLabel(@Nullable String candidate)
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
@Exported public List<LockableResourceProperty> getProperties()
-
setProperties
@DataBoundSetter public void setProperties(@Nullable List<LockableResourceProperty> properties)
-
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 ExecutionException
Checks if the script matches the requirement.- Parameters:
script
- Script to be executedparams
- Extra script parameters- Returns:
true
if the script returns true (resource matches).- Throws:
ExecutionException
- Script execution failed (e.g. due to the missing permissions). Carries info in the cause
-
getReservedTimestamp
@Exported public Date getReservedTimestamp()
-
setReservedTimestamp
@DataBoundSetter public void setReservedTimestamp(@Nullable Date reservedTimestamp)
-
getReservedBy
@Exported public String 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
@Exported public String 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()
-
getLockCause
@CheckForNull @Exported public String getLockCause()
Resolve the lock cause for this resource. It can be reserved or locked.- Returns:
- the lock cause or null if not locked
-
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. Therefor moving text into localization files does not make really sense.- Returns:
- the lock cause or null if not locked
-
getBuild
@WithBridgeMethods(value=hudson.model.AbstractBuild.class, adapterMethod="getAbstractBuild") public Run<?,?> getBuild()
-
getBuildName
@Exported public String getBuildName()
-
setBuild
public void setBuild(@Nullable Run<?,?> lockedBy)
-
getTask
public Queue.Task getTask()
-
getQueueItemId
public long getQueueItemId()
-
getQueueItemProject
public String getQueueItemProject()
-
setQueued
public void setQueued(long queueItemId)
-
setQueued
public void setQueued(long queueItemId, String queueProjectName)
-
setReservedBy
@DataBoundSetter public void setReservedBy(String userName)
-
setStolen
public void setStolen()
-
isStolen
@Exported public boolean isStolen()
-
reserve
public void reserve(String userName)
-
unReserve
public void unReserve()
-
reset
public void reset()
-
copyUnconfigurableProperties
public void copyUnconfigurableProperties(LockableResource sourceResource)
Copy unconfigurable properties from another instance. Normally, called after "lockable resource" configuration change.- Parameters:
sourceResource
- resource with properties to copy from
-
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.
-
-