Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always provision a new node when exceeded capacity #3

Merged
merged 1 commit into from
Jan 13, 2021
Merged
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
22 changes: 3 additions & 19 deletions src/main/java/dev/lsegal/jenkins/codebuilder/CodeBuilderCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,9 @@ public synchronized Collection<PlannedNode> provision(Label label, int excessWor
return list;
}

long stillProvisioning = numStillProvisioning();
long numToLaunch = Math.max(excessWorkload - stillProvisioning, 0);
LOGGER.info("[CodeBuilder]: Provisioning {} nodes for label '{}' ({} already provisioning)", numToLaunch, labelName,
stillProvisioning);
LOGGER.info("[CodeBuilder]: Provisioning {} nodes for label '{}'", excessWorkload, labelName);

for (int i = 0; i < numToLaunch; i++) {
for (int i = 0; i < excessWorkload; i++) {
final String suffix = RandomStringUtils.randomAlphabetic(4);
final String displayName = String.format("%s.cb-%s", projectName, suffix);
final CodeBuilderCloud cloud = this;
Expand All @@ -368,19 +365,6 @@ public synchronized Collection<PlannedNode> provision(Label label, int excessWor
return list;
}

/**
* Find the number of {@link CodeBuilderAgent} instances still connecting to
* Jenkins host.
*/
private long numStillProvisioning() {
return jenkins().getNodes().stream()
// Get all `CodeBuilderAgent`s as `CodeBuilderAgent`s
.filter(CodeBuilderAgent.class::isInstance).map(CodeBuilderAgent.class::cast)
// Get all those that haven't succesfully launched yet (those for which 'launching' is 'supported')
.filter(a -> a.getLauncher().isLaunchSupported())
.count();
}

/** {@inheritDoc} */
@Override
public boolean canProvision(Label label) {
Expand Down Expand Up @@ -428,7 +412,7 @@ public String getDefaultComputeType() {
}

public boolean getDefaultTerminateAgent() {
return DEFAULT_TERMINATE_AGENT;
return DEFAULT_TERMINATE_AGENT;
}

public ListBoxModel doFillCredentialsIdItems() {
Expand Down