Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/main/java/jenkins/plugins/jclouds/compute/JCloudsCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -142,7 +143,7 @@
@Deprecated
private final transient String publicKey; // NOPMD - unused private member

private transient int pendingNodes;
private transient AtomicInteger pendingNodes;

public final String endPointUrl;
public final String profile;
Expand Down Expand Up @@ -446,6 +447,12 @@
}
}

private synchronized void initPendingNodes() {
if (null == pendingNodes) {

Check warning on line 451 in src/main/java/jenkins/plugins/jclouds/compute/JCloudsCloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 451 is only partially covered, one branch is missing
pendingNodes = new AtomicInteger(0);
}
}

@DataBoundConstructor
public JCloudsCloud(
final String profile,
Expand Down Expand Up @@ -482,7 +489,7 @@
this.trustAll = trustAll;
this.groupPrefix = groupPrefix;
readResolve();
this.pendingNodes = 0;
initPendingNodes();
}

protected Object readResolve() {
Expand Down Expand Up @@ -651,25 +658,26 @@
&& !Jenkins.get().isQuietingDown()
&& !Jenkins.get().isTerminating()) {

if ((getRunningNodesCount() + plannedNodeList.size() + pendingNodes) >= instanceCap) {
initPendingNodes();
if ((getRunningNodesCount() + plannedNodeList.size() + pendingNodes.intValue()) >= instanceCap) {
LOGGER.info(String.format(
"Instance cap of %s reached while adding capacity for label %s",
getName(), (label != null) ? label.toString() : "null"));
break; // maxed out
}

final ProvisioningActivity.Id provisioningId = new ProvisioningActivity.Id(this.name, tpl.name);

plannedNodeList.add(new TrackedPlannedNode(
provisioningId, tpl.getNumExecutors(), Computer.threadPoolForRemoting.submit(new Callable<Node>() {
public Node call() throws Exception {
// TODO: record the output somewhere

Check warning on line 674 in src/main/java/jenkins/plugins/jclouds/compute/JCloudsCloud.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: record the output somewhere
JCloudsSlave jcloudsSlave;
pendingNodes++;
pendingNodes.incrementAndGet();
try {
jcloudsSlave = tpl.provisionSlave(StreamTaskListener.fromStdout(), provisioningId);
} finally {
pendingNodes--;
pendingNodes.decrementAndGet();
}
Jenkins.get().addNode(jcloudsSlave);

Expand Down Expand Up @@ -875,13 +883,14 @@
return;
}

if (getRunningNodesCount() + pendingNodes < instanceCap) {
initPendingNodes();
if (getRunningNodesCount() + pendingNodes.intValue() < instanceCap) {
try {
pendingNodes++;
pendingNodes.incrementAndGet();
JCloudsSlave node = doProvisionFromTemplate(t);
rsp.sendRedirect2(req.getContextPath() + "/computer/" + node.getNodeName());
} finally {
pendingNodes--;
pendingNodes.decrementAndGet();

Check warning on line 893 in src/main/java/jenkins/plugins/jclouds/compute/JCloudsCloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 661-893 are not covered by tests
}
} else {
sendError(String.format("Instance cap of %s reached", getName()), req, rsp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
<tr>
<td colspan="${monitors.size()+2}">
<l:overflowButton icon="symbol-add"
text="${%Provision via Provision via JClouds} - ${it.name}"
text="${%Provision via JClouds} - ${it.name}"
tooltip="${null}"
clazz="jenkins-!-margin-top-2">
<j:forEach var="t" items="${it.templates}">
Expand Down
Loading