-
Notifications
You must be signed in to change notification settings - Fork 183
/
QueuedContextStruct.java
107 lines (93 loc) · 3.33 KB
/
QueuedContextStruct.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright (c) 2016, Florian Hug. All rights reserved. *
* *
* This file is part of the Jenkins Lockable Resources Plugin and is *
* published under the MIT license. *
* *
* See the "LICENSE.txt" file for more information. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package org.jenkins.plugins.lockableresources.queue;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.model.Run;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
/*
* This class is used to queue pipeline contexts
* which shall be executed once the necessary
* resources are free'd.
*/
public class QueuedContextStruct implements Serializable {
/*
* Reference to the pipeline step context.
*/
private StepContext context;
/*
* Reference to the resources required by the step context.
*/
private List<LockableResourcesStruct> lockableResourcesStruct;
/*
* Description of the required resources used within logging messages.
*/
private String resourceDescription;
/*
* Name of the variable to save the locks taken.
*/
private String variableName;
private static final Logger LOGGER = Logger.getLogger(QueuedContextStruct.class.getName());
/*
* Constructor for the QueuedContextStruct class.
*/
public QueuedContextStruct(
StepContext context,
List<LockableResourcesStruct> lockableResourcesStruct,
String resourceDescription,
String variableName) {
this.context = context;
this.lockableResourcesStruct = lockableResourcesStruct;
this.resourceDescription = resourceDescription;
this.variableName = variableName;
}
/*
* Gets the pipeline step context.
*/
public StepContext getContext() {
return this.context;
}
/** Return build, where is the resource used. */
@CheckForNull
@Restricted(NoExternalUse.class) // used by jelly
public Run<?, ?> getBuild() {
try {
return this.getContext().get(Run.class);
} catch (IOException | InterruptedException e) {
// for some reason there is no Run object for this context
LOGGER.log(Level.FINE, "Cannot get the Run object from the context to proceed with lock", e);
return null;
}
}
/*
* Gets the required resources.
*/
public List<LockableResourcesStruct> getResources() {
return this.lockableResourcesStruct;
}
/*
* Gets the resource description for logging messages.
*/
public String getResourceDescription() {
return this.resourceDescription;
}
/*
* Gets the variable name to save the locks taken.
*/
public String getVariableName() {
return this.variableName;
}
private static final long serialVersionUID = 1L;
}