Skip to content

Commit c05146c

Browse files
committed
[JENKINS-63819] Add maxConn default value & value checking
1 parent 224817e commit c05146c

1 file changed

Lines changed: 27 additions & 26 deletions

File tree

src/main/java/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteBuildConfiguration.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public class RemoteBuildConfiguration extends Builder implements SimpleBuildStep
9696
private static final int DEFAULT_HTTP_POST_READ_TIMEOUT = 30000;
9797

9898
/**
99-
* The TTL value of all `queued` items is only 5 minutes.
100-
* That is why we have to ignore user specified poll interval for such items.
99+
* The TTL value of all `queued` items is only 5 minutes. That is why we have to
100+
* ignore user specified poll interval for such items.
101101
*/
102102
private static final int QUEUED_ITEMS_POLLINTERVALL = 30;
103103

@@ -128,7 +128,7 @@ public class RemoteBuildConfiguration extends Builder implements SimpleBuildStep
128128
private boolean enhancedLogging;
129129
private boolean loadParamsFromFile;
130130
private String parameterFile;
131-
private int maxConn;
131+
private int maxConn = 1;
132132
private boolean useCrumbCache;
133133
private boolean useJobInfoCache;
134134
private boolean abortTriggeredJob;
@@ -189,7 +189,7 @@ public void setAbortTriggeredJob(boolean abortTriggeredJob) {
189189

190190
@DataBoundSetter
191191
public void setMaxConn(int maxConn) {
192-
this.maxConn = (maxConn > 5) ? 5 : maxConn;
192+
this.maxConn = (maxConn > 5) ? 5 : (maxConn < 1) ? 1 : maxConn;
193193
}
194194

195195
@DataBoundSetter
@@ -695,8 +695,8 @@ public Handle performTriggerAndGetQueueId(BuildContext context) throws IOExcepti
695695

696696
try {
697697
ConnectionResponse responseRemoteJob = HttpHelper.tryPost(triggerUrlString, context, cleanedParams,
698-
this.getHttpPostReadTimeout(), this.getPollInterval(buildInfo.getStatus()), this.getConnectionRetryLimit(),
699-
this.getAuth2(), getLock(triggerUrlString), isUseCrumbCache());
698+
this.getHttpPostReadTimeout(), this.getPollInterval(buildInfo.getStatus()),
699+
this.getConnectionRetryLimit(), this.getAuth2(), getLock(triggerUrlString), isUseCrumbCache());
700700
QueueItem queueItem = new QueueItem(responseRemoteJob.getHeader());
701701
buildInfo.setQueueId(queueItem.getId());
702702
buildInfo = updateBuildInfo(buildInfo, context);
@@ -733,7 +733,8 @@ public void performWaitForBuild(BuildContext context, Handle handle) throws IOEx
733733
}
734734

735735
while (buildInfo.isQueued()) {
736-
context.logger.println("Waiting for " + this.getPollInterval(buildInfo.getStatus()) + " seconds until next poll.");
736+
context.logger.println(
737+
"Waiting for " + this.getPollInterval(buildInfo.getStatus()) + " seconds until next poll.");
737738
Thread.sleep(this.getPollInterval(buildInfo.getStatus()) * 1000);
738739
buildInfo = updateBuildInfo(buildInfo, context);
739740
handle.setBuildInfo(buildInfo);
@@ -776,7 +777,8 @@ public void performWaitForBuild(BuildContext context, Handle handle) throws IOEx
776777
if (this.getEnhancedLogging()) {
777778
consoleOffset = printOffsetConsoleOutput(context, consoleOffset, buildInfo);
778779
} else {
779-
context.logger.println(" Waiting for " + this.getPollInterval(buildInfo.getStatus()) + " seconds until next poll.");
780+
context.logger.println(" Waiting for " + this.getPollInterval(buildInfo.getStatus())
781+
+ " seconds until next poll.");
780782
}
781783
Thread.sleep(this.getPollInterval(buildInfo.getStatus()) * 1000);
782784
buildInfo = updateBuildInfo(buildInfo, context);
@@ -872,7 +874,8 @@ public RemoteBuildInfo updateBuildInfo(@Nonnull RemoteBuildInfo buildInfo, @Nonn
872874
if (queueItem.isExecuted()) {
873875
URL remoteBuildURL = queueItem.getBuildURL();
874876
String effectiveRemoteServerAddress = context.effectiveRemoteServer.getAddress();
875-
URL effectiveRemoteBuildURL = generateEffectiveRemoteBuildURL(remoteBuildURL, effectiveRemoteServerAddress);
877+
URL effectiveRemoteBuildURL = generateEffectiveRemoteBuildURL(remoteBuildURL,
878+
effectiveRemoteServerAddress);
876879
buildInfo.setBuildData(queueItem.getBuildNumber(), effectiveRemoteBuildURL);
877880
}
878881
return buildInfo;
@@ -899,19 +902,16 @@ public RemoteBuildInfo updateBuildInfo(@Nonnull RemoteBuildInfo buildInfo, @Nonn
899902
return buildInfo;
900903
}
901904

902-
protected static URL generateEffectiveRemoteBuildURL(URL remoteBuildURL, String effectiveRemoteServerAddress) throws AbortException {
905+
protected static URL generateEffectiveRemoteBuildURL(URL remoteBuildURL, String effectiveRemoteServerAddress)
906+
throws AbortException {
903907
if (effectiveRemoteServerAddress == null || remoteBuildURL == null) {
904908
return remoteBuildURL;
905909
}
906910

907911
try {
908912
URI effectiveUri = new URI(effectiveRemoteServerAddress);
909-
return new URL(
910-
effectiveUri.getScheme(),
911-
effectiveUri.getHost(),
912-
effectiveUri.getPort(),
913-
remoteBuildURL.getPath()
914-
);
913+
return new URL(effectiveUri.getScheme(), effectiveUri.getHost(), effectiveUri.getPort(),
914+
remoteBuildURL.getPath());
915915
} catch (URISyntaxException | MalformedURLException ex) {
916916
throw new AbortException(String.format("Unexpected syntax error: %s.", ex.toString()));
917917
}
@@ -942,18 +942,19 @@ private String printOffsetConsoleOutput(BuildContext context, String offset, Rem
942942
* Orchestrates all calls to the remote server. Also takes care of any
943943
* credentials or failed-connection retries.
944944
*
945-
* @param urlString the URL that needs to be called.
946-
* @param context the context of this Builder/BuildStep.
945+
* @param urlString the URL that needs to be called.
946+
* @param context the context of this Builder/BuildStep.
947947
* @param remoteBuildStatus the build status of a remote build.
948948
* @return JSONObject a valid JSON object, or null.
949949
* @throws InterruptedException if any thread has interrupted the current
950950
* thread.
951951
* @throws IOException if any HTTP error occurred.
952952
*/
953-
public ConnectionResponse doGet(String urlString, BuildContext context, RemoteBuildStatus remoteBuildStatus) throws IOException, InterruptedException {
953+
public ConnectionResponse doGet(String urlString, BuildContext context, RemoteBuildStatus remoteBuildStatus)
954+
throws IOException, InterruptedException {
954955
return HttpHelper.tryGet(urlString, context, this.getHttpGetReadTimeout(),
955-
this.getPollInterval(remoteBuildStatus), this.getConnectionRetryLimit(),
956-
this.getAuth2(), getLock(urlString));
956+
this.getPollInterval(remoteBuildStatus), this.getConnectionRetryLimit(), this.getAuth2(),
957+
getLock(urlString));
957958
}
958959

959960
private void logAuthInformation(BuildContext context) throws IOException {
@@ -1074,11 +1075,11 @@ public boolean getPreventRemoteBuildQueue() {
10741075

10751076
public int getPollInterval(RemoteBuildStatus remoteBuildStatus) {
10761077
switch (remoteBuildStatus) {
1077-
case NOT_TRIGGERED:
1078-
case QUEUED:
1079-
return QUEUED_ITEMS_POLLINTERVALL;
1080-
default:
1081-
return pollInterval;
1078+
case NOT_TRIGGERED:
1079+
case QUEUED:
1080+
return QUEUED_ITEMS_POLLINTERVALL;
1081+
default:
1082+
return pollInterval;
10821083
}
10831084
}
10841085

0 commit comments

Comments
 (0)