Skip to content

Commit

Permalink
SAK-44410 Unboundid - add options for setHealthCheckIntervalMillis an… (
Browse files Browse the repository at this point in the history
sakaiproject#8677)

* SAK-44410 Unboundid - add options for setHealthCheckIntervalMillis and setHealthCheck

* SAK-44410 Unboundid - add options for setHealthCheckIntervalMillis and setHealthCheck

clean up comments
  • Loading branch information
austin48 authored Oct 22, 2020
1 parent 6a26573 commit 562d84b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
24 changes: 24 additions & 0 deletions providers/component/src/webapp/WEB-INF/unboundid-ldap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@
<value>false</value>
</property -->

<!-- Specifies the length of time in milliseconds between periodic background
health checks against the available connections in this pool.
Requires healthCheckMappings's invokeForBackgroundChecks to be set to true
Defaults to 60000L -->
<!-- property name="healthCheckIntervalMillis">
<value>60000</value>
</property -->

<!-- Provides mapping to create an LDAP connection pool health check implementation
that may be used to check the health of the associated server by verifying that
a specified entry can be retrieved in an acceptable period of time
Defaults to null (invokes the Unboundid defaut implementation, which does not do any checks) -->
<!-- property name="healthCheckMappings">
<map>
<entry key="maxResponseTime"><value>30000</value></entry>
<entry key="invokeOnCreate"><value>false</value></entry>
<entry key="invokeAfterAuthentication"><value>false</value></entry>
<entry key="invokeOnCheckout"><value>false</value></entry>
<entry key="invokeOnRelease"><value>false</value></entry>
<entry key="invokeForBackgroundChecks"><value>true</value></entry>
<entry key="invokeOnException"><value>false</value></entry>
</map>
</property -->

<!-- Optional. Size of batch when loading multiple users at once.
Defaults to DEFAULT_BATCH_SIZE = 200 -->
<!-- property name="batchSize">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.unboundid.ldap.sdk.BindRequest;
import com.unboundid.ldap.sdk.BindResult;
import com.unboundid.ldap.sdk.DereferencePolicy;
import com.unboundid.ldap.sdk.GetEntryLDAPConnectionPoolHealthCheck;
import com.unboundid.ldap.sdk.LDAPConnectionOptions;
import com.unboundid.ldap.sdk.LDAPConnectionPool;
import com.unboundid.ldap.sdk.LDAPSearchException;
Expand Down Expand Up @@ -103,6 +104,8 @@ public class UnboundidDirectoryProvider implements UserDirectoryProvider, LdapCo

public static final boolean DEFAULT_RETRY_FAILED_OPERATIONS_DUE_TO_INVALID_CONNECTIONS = false;

public static final long DEFAULT_HEALTH_CHECK_INTERVAL_MILLIS = 60000L;

/** Default LDAP maximum number of objects in a result */
public static final int DEFAULT_MAX_RESULT_SIZE = 1000;

Expand Down Expand Up @@ -153,6 +156,10 @@ public class UnboundidDirectoryProvider implements UserDirectoryProvider, LdapCo

private boolean retryFailedOperationsDueToInvalidConnections = DEFAULT_RETRY_FAILED_OPERATIONS_DUE_TO_INVALID_CONNECTIONS;

private long healthCheckIntervalMillis = DEFAULT_HEALTH_CHECK_INTERVAL_MILLIS;

private Map<String,String> healthCheckMappings = null;

/** Maximum number of results from one LDAP query */
private int maxResultSize = DEFAULT_MAX_RESULT_SIZE;

Expand Down Expand Up @@ -309,6 +316,19 @@ protected synchronized boolean createConnectionPool() {
log.info("Creating LDAP connection pool of size {}", poolMaxConns);
connectionPool = new LDAPConnectionPool(serverSet, bindRequest, poolMaxConns);
connectionPool.setRetryFailedOperationsDueToInvalidConnections(retryFailedOperationsDueToInvalidConnections);
connectionPool.setHealthCheckIntervalMillis(healthCheckIntervalMillis);
if (healthCheckMappings != null) {
GetEntryLDAPConnectionPoolHealthCheck healthCheck = new GetEntryLDAPConnectionPoolHealthCheck(
ldapUser,
Long.parseLong(healthCheckMappings.get("maxResponseTime")),
Boolean.parseBoolean(healthCheckMappings.get("invokeOnCreate")),
Boolean.parseBoolean(healthCheckMappings.get("invokeAfterAuthentication")),
Boolean.parseBoolean(healthCheckMappings.get("invokeOnCheckout")),
Boolean.parseBoolean(healthCheckMappings.get("invokeOnRelease")),
Boolean.parseBoolean(healthCheckMappings.get("invokeForBackgroundChecks")),
Boolean.parseBoolean(healthCheckMappings.get("invokeOnException")));
connectionPool.setHealthCheck(healthCheck);
}
} catch (com.unboundid.ldap.sdk.LDAPException e) {
log.error("Could not init LDAP pool", e);
return false;
Expand Down Expand Up @@ -1219,6 +1239,24 @@ public void setRetryFailedOperationsDueToInvalidConnections(boolean retryFailedO
this.retryFailedOperationsDueToInvalidConnections = retryFailedOperationsDueToInvalidConnections;
}

public long getHealthCheckIntervalMillis() {
return healthCheckIntervalMillis;
}

public void setHealthCheckIntervalMillis(long healthCheckIntervalMillis) {
this.healthCheckIntervalMillis = healthCheckIntervalMillis;
}

public Map<String, String> getHealthCheckMappings()
{
return healthCheckMappings;
}

public void setHealthCheckMappings(Map<String, String> healthCheckMappings)
{
this.healthCheckMappings = healthCheckMappings;
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 562d84b

Please sign in to comment.