Skip to content

Commit

Permalink
D-21808 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
nitheshrayuduv authored Jul 1, 2022
1 parent 292a06f commit 6b54094
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
29 changes: 27 additions & 2 deletions src/main/java/com/xebialabs/deployit/ci/DeployitNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public static final class DeployitDescriptor extends BuildStepDescriptor<Publish
private String deployitClientProxyUrl;

private int connectionPoolSize = DeployitServer.DEFAULT_POOL_SIZE;
private int socketTimeout = DeployitServer.DEFAULT_SOCKET_TIMEOUT;

// credentials are actually globally available credentials
private List<Credential> credentials = new ArrayList<Credential>();
Expand All @@ -175,7 +176,7 @@ private DeployitServer newDeployitServer(Credential credential, ItemGroup<?> ite
String proxyUrl = credential.resolveProxyUrl(deployitClientProxyUrl);

int newConnectionPoolSize = connectionPoolSize > 0 ? connectionPoolSize : DeployitServer.DEFAULT_POOL_SIZE;
int socketTimeout = DeployitServer.DEFAULT_SOCKET_TIMEOUT;
int newSocketTimeout = socketTimeout > 0 ? socketTimeout : DeployitServer.DEFAULT_SOCKET_TIMEOUT;

String userName = credential.getUsername();
String password = credential.getPassword().getPlainText();
Expand All @@ -187,7 +188,7 @@ private DeployitServer newDeployitServer(Credential credential, ItemGroup<?> ite
userName = cred.getUsername();
password = cred.getPassword().getPlainText();
}
return DeployitServerFactory.newInstance(serverUrl, proxyUrl, userName, password, newConnectionPoolSize, socketTimeout);
return DeployitServerFactory.newInstance(serverUrl, proxyUrl, userName, password, newConnectionPoolSize, newSocketTimeout);
}

public DeployitServer getDeployitServer(Credential credential, Job<?, ?> project) {
Expand Down Expand Up @@ -216,9 +217,13 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
deployitServerUrl = json.get("deployitServerUrl").toString();
deployitClientProxyUrl = json.get("deployitClientProxyUrl").toString();
String connectionPoolSizeString = json.get("connectionPoolSize").toString();
String socketTimeoutString = json.get("socketTimeout").toString();
if (!Strings.isNullOrEmpty(connectionPoolSizeString)) {
connectionPoolSize = Integer.parseInt(connectionPoolSizeString);
}
if (!Strings.isNullOrEmpty(socketTimeoutString)) {
socketTimeout = Integer.parseInt(socketTimeoutString);
}
credentials = req.bindJSONToList(Credential.class, json.get("credentials"));
save(); //serialize to xml
credentialServerMap.clear(); // each time global config is changed clear server cache
Expand Down Expand Up @@ -256,6 +261,10 @@ public int getConnectionPoolSize() {
return connectionPoolSize;
}

public int getSocketTimeout() {
return socketTimeout;
}

private FormValidation validateOptionalUrl(String url) {
try {
if (!Strings.isNullOrEmpty(url)) {
Expand Down Expand Up @@ -304,6 +313,22 @@ public FormValidation doCheckConnectionPoolSize(@QueryParameter String connectio
return ok();
}

@RequirePOST
public FormValidation doCheckSocketTimeout(@QueryParameter String socketTimeout) {

Jenkins.getInstance().checkPermission(Item.CONFIGURE);
try {
Integer value = Integer.parseInt(socketTimeout);
if (value <= 0) {
return error("Socket Timeout may not be negative or zero.");
}
} catch (NumberFormatException e) {
return error("%s is not a valid integer.", socketTimeout);
}

return ok();
}

public ListBoxModel doFillCredentialItems() {
ListBoxModel m = new ListBoxModel();
for (Credential c : credentials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface DeployitServer {

void setConnectionPoolSize(int poolSize);

void setSocketTimeout(int poolSize);

List<String> search(String type);

List<String> search(String type, String namePattern);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public class DeployitServerImpl implements DeployitServer {
private BooterConfig booterConfig;
private DeployitDescriptorRegistry descriptorRegistry;
private int poolSize;
private int socketTimeout;

DeployitServerImpl(BooterConfig booterConfig) {
this.booterConfig = booterConfig;
BooterConfig newBooterConfig = BooterConfig.builder(booterConfig)
.withConnectionPoolSize(poolSize)
.withHttpRequestInterceptor(new PreemptiveAuthenticationInterceptor())
.withSocketTimeout(booterConfig.getSocketTimeout())
.withSocketTimeout(socketTimeout)
.build();
this.descriptorRegistry = Reflection.newProxy(DeployitDescriptorRegistry.class,
new PluginFirstClassloaderInvocationHandler(new DeployitDescriptorRegistryImpl(newBooterConfig)));
Expand All @@ -51,6 +52,11 @@ public void setConnectionPoolSize(final int poolSize) {
this.poolSize = poolSize;
}

@Override
public void setSocketTimeout(final int socketTimeout) {
this.socketTimeout = socketTimeout;
}

@Override
public List<String> search(String type) {
return search(type, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<f:entry title="${%Connection Pool Size}" field="connectionPoolSize">
<f:number checkMethod="post" />
</f:entry>
<f:entry title="${%Socket Timeout}" field="socketTimeout">
<f:number checkMethod="post" />
</f:entry>
<f:entry title="Credentials" field="credentials">
<f:repeatable field="credentials" minimum="${1}">
<xld:blockWrapper>
Expand Down

0 comments on commit 6b54094

Please sign in to comment.