Skip to content

Commit 72bf257

Browse files
committed
introduce hikari db load balancer
1 parent f66c306 commit 72bf257

File tree

59 files changed

+780
-820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+780
-820
lines changed

build/checkstyle-import.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135

136136
<!-- database -->
137137
<subpackage name="svc.db">
138+
<allow pkg="com.zaxxer.hikari"/>
138139
<allow pkg="java.sql"/>
139140
</subpackage>
140141

lib-util/src/main/java/password/pwm/util/java/CollectionUtil.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static <K extends Enum<K>, V> EnumMap<K, V> copiedEnumMap( final Map<K, V
9999
{
100100
if ( CollectionUtil.isEmpty( source ) )
101101
{
102-
return new EnumMap<K, V>( classOfT );
102+
return new EnumMap<>( classOfT );
103103
}
104104

105105
return source.entrySet().stream()
@@ -157,6 +157,27 @@ public static <E extends Enum<E>> Map<String, String> enumMapToStringMap( final
157157
return enumMapToStringMap( inputMap, Enum::name );
158158
}
159159

160+
public static <E extends Enum<E>> List<String> enumSetToStringList( final Set<E> inputSet )
161+
{
162+
return enumSetToStringList( inputSet, Enum::name );
163+
}
164+
165+
public static <E extends Enum<E>> List<String> enumSetToStringList(
166+
final Set<E> inputSet,
167+
final Function<E, String> keyToStringFunction
168+
)
169+
{
170+
if ( CollectionUtil.isEmpty( inputSet ) )
171+
{
172+
return List.of();
173+
}
174+
175+
return inputSet.stream()
176+
.filter( Objects::nonNull )
177+
.map( keyToStringFunction )
178+
.toList();
179+
}
180+
160181
public static <K> boolean isEmpty( final Collection<K> collection )
161182
{
162183
return collection == null || collection.isEmpty();
@@ -183,8 +204,7 @@ public static <E extends Enum<E>> EnumSet<E> copyToEnumSet( final Set<E> source,
183204

184205
public static <E> List<E> iteratorToList( final Iterator<E> iterator )
185206
{
186-
return iteratorToStream( iterator )
187-
.collect( Collectors.toUnmodifiableList() );
207+
return iteratorToStream( iterator ).toList();
188208
}
189209

190210
/**
@@ -217,7 +237,7 @@ public static <T> Set<T> setUnion( final Set<T> set1, final Set<T> set2 )
217237
public static <T, R> List<R> convertListType( final List<T> input, final Function<T, R> convertFunction )
218238

219239
{
220-
return stripNulls( input ).stream().map( convertFunction ).collect( Collectors.toUnmodifiableList() );
240+
return stripNulls( input ).stream().map( convertFunction ).toList();
221241
}
222242

223243
private static <K, V> boolean testMapEntryForNotNull( final Map.Entry<K, V> entry )

server/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@
180180
<artifactId>xmlchai</artifactId>
181181
<version>0.1.3</version>
182182
</dependency>
183+
<dependency>
184+
<groupId>com.zaxxer</groupId>
185+
<artifactId>HikariCP</artifactId>
186+
<version>5.0.1</version>
187+
</dependency>
183188
<dependency>
184189
<groupId>org.apache.directory.api</groupId>
185190
<artifactId>api-all</artifactId>

server/src/main/java/password/pwm/PwmAboutProperty.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ public enum PwmAboutProperty
102102
java_gcName( "Java GC Name", pwmApplication -> readGcName() ),
103103

104104
database_driverName( null,
105-
pwmApplication -> pwmApplication.getDatabaseService().getConnectionDebugProperties().get( DatabaseService.DatabaseAboutProperty.driverName ) ),
105+
pwmApplication -> pwmApplication.getDatabaseService().getConnectionDebugProperties().get( DatabaseService.DatabaseDebugProperty.driverName ) ),
106106
database_driverVersion( null,
107-
pwmApplication -> pwmApplication.getDatabaseService().getConnectionDebugProperties().get( DatabaseService.DatabaseAboutProperty.driverVersion ) ),
107+
pwmApplication -> pwmApplication.getDatabaseService().getConnectionDebugProperties().get( DatabaseService.DatabaseDebugProperty.driverVersion ) ),
108108
database_databaseProductName( null,
109-
pwmApplication -> pwmApplication.getDatabaseService().getConnectionDebugProperties().get( DatabaseService.DatabaseAboutProperty.databaseProductName ) ),
109+
pwmApplication -> pwmApplication.getDatabaseService().getConnectionDebugProperties().get( DatabaseService.DatabaseDebugProperty.databaseProductName ) ),
110110
database_databaseProductVersion( null,
111-
pwmApplication -> pwmApplication.getDatabaseService().getConnectionDebugProperties().get( DatabaseService.DatabaseAboutProperty.databaseProductVersion ) ),;
111+
pwmApplication -> pwmApplication.getDatabaseService().getConnectionDebugProperties().get( DatabaseService.DatabaseDebugProperty.databaseProductVersion ) ),;
112112

113113
private final String label;
114114
private final transient Function<PwmApplication, String> value;

server/src/main/java/password/pwm/PwmConstants.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
package password.pwm;
2222

23-
import com.novell.ldapchai.ChaiConstant;
2423
import org.apache.commons.csv.CSVFormat;
2524
import password.pwm.util.java.StringUtil;
2625

@@ -229,7 +228,7 @@ private static Map<String, String> readBuildManifest( )
229228
final Map<String, String> returnMap = new TreeMap<>();
230229
try
231230
{
232-
final Enumeration<URL> resources = ChaiConstant.class.getClassLoader().getResources( manifestFileName );
231+
final Enumeration<URL> resources = PwmConstants.class.getClassLoader().getResources( manifestFileName );
233232
while ( resources.hasMoreElements() )
234233
{
235234
try ( InputStream inputStream = resources.nextElement().openStream() )

server/src/main/java/password/pwm/health/ConfigurationChecker.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import java.util.List;
7272
import java.util.Locale;
7373
import java.util.NoSuchElementException;
74+
import java.util.Objects;
7475
import java.util.Optional;
7576
import java.util.Set;
7677
import java.util.function.Supplier;
@@ -234,14 +235,14 @@ public List<HealthRecord> healthCheck( final DomainHealthCheckRequest domainHeal
234235
appPropertyKey ) );
235236
}
236237

237-
if ( config.readSettingAsBoolean( PwmSetting.DISPLAY_SHOW_DETAILED_ERRORS ) )
238+
if ( config.getAppConfig().readSettingAsBoolean( PwmSetting.DISPLAY_SHOW_DETAILED_ERRORS ) )
238239
{
239240
records.add( HealthRecord.forMessage(
240241
DomainID.systemId(),
241242
HealthMessage.Config_ShowDetailedErrors,
242243
PwmSetting.DISPLAY_SHOW_DETAILED_ERRORS.toMenuLocationDebug( null, locale ) ) );
243244
}
244-
return Collections.unmodifiableList( records );
245+
return List.copyOf( records );
245246
}
246247
}
247248

@@ -255,9 +256,9 @@ public List<HealthRecord> healthCheck( final DomainHealthCheckRequest domainHeal
255256

256257
final List<HealthRecord> records = new ArrayList<>();
257258
final String siteUrl = config.getAppConfig().readSettingAsString( PwmSetting.PWM_SITE_URL );
259+
final String defaultSiteUrl = ( String) PwmSetting.PWM_SITE_URL.getDefaultValue( config.getTemplate() ).toNativeObject();
258260

259-
if ( siteUrl == null || siteUrl.isEmpty() || siteUrl.equals(
260-
PwmSetting.PWM_SITE_URL.getDefaultValue( config.getTemplate() ).toNativeObject() ) )
261+
if ( StringUtil.isEmpty( siteUrl ) || Objects.equals( siteUrl, defaultSiteUrl ) )
261262
{
262263
records.add( HealthRecord.forMessage(
263264
config.getDomainID(),

server/src/main/java/password/pwm/health/DebugOutputService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import password.pwm.error.PwmUnrecoverableException;
2929
import password.pwm.svc.AbstractPwmService;
3030
import password.pwm.svc.PwmService;
31-
import password.pwm.util.debug.DebugItemGenerator;
31+
import password.pwm.util.debug.DebugGenerator;
3232
import password.pwm.util.java.AtomicLoopIntIncrementer;
3333
import password.pwm.util.java.FileSystemUtility;
3434
import password.pwm.util.java.JavaHelper;
@@ -143,7 +143,7 @@ private void writeSupportZipToAppPath()
143143
}
144144

145145
final int rotationCount = JavaHelper.silentParseInt( pwmApplication.getConfig().readAppProperty( AppProperty.HEALTH_SUPPORT_BUNDLE_FILE_WRITE_COUNT ), 10 );
146-
final DebugItemGenerator debugItemGenerator = new DebugItemGenerator( pwmApplication, getSessionLabel() );
146+
final DebugGenerator debugItemGenerator = new DebugGenerator( pwmApplication, getSessionLabel() );
147147

148148
final Path supportPath = appPath.resolve( "support" );
149149

server/src/main/java/password/pwm/http/servlet/ClientApiServlet.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,13 @@ public ProcessStatus restStatisticsHandler( final PwmRequest pwmRequest )
444444
final RestStatisticsServer.OutputVersion1.JsonOutput jsonOutput = new RestStatisticsServer.OutputVersion1.JsonOutput();
445445
jsonOutput.EPS = RestStatisticsServer.OutputVersion1.addEpsStats( statisticsManager );
446446

447-
if ( statName != null && statName.length() > 0 )
447+
if ( !StringUtil.isEmpty( statName ) )
448448
{
449-
jsonOutput.nameData = RestStatisticsServer.OutputVersion1.doNameStat( statisticsManager, statName, days );
449+
jsonOutput.nameData = RestStatisticsServer.OutputVersion1.doNameStat(
450+
pwmRequest.getPwmRequestContext(),
451+
statisticsManager,
452+
statName,
453+
days );
450454
}
451455
else
452456
{

server/src/main/java/password/pwm/http/servlet/admin/system/ConfigManagerServlet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import password.pwm.i18n.Config;
5656
import password.pwm.i18n.Display;
5757
import password.pwm.ldap.LdapPermissionCalculator;
58-
import password.pwm.util.debug.DebugItemGenerator;
58+
import password.pwm.util.debug.DebugGenerator;
5959
import password.pwm.util.i18n.LocaleHelper;
6060
import password.pwm.util.java.CollectionUtil;
6161
import password.pwm.util.java.EnumUtil;
@@ -360,7 +360,7 @@ private void doDownloadConfig( final PwmRequest pwmRequest )
360360
private void doGenerateSupportZip( final PwmRequest pwmRequest )
361361
throws IOException, PwmUnrecoverableException
362362
{
363-
final DebugItemGenerator debugItemGenerator = new DebugItemGenerator( pwmRequest.getPwmApplication(), pwmRequest.getLabel() );
363+
final DebugGenerator debugItemGenerator = new DebugGenerator( pwmRequest.getPwmApplication(), pwmRequest.getLabel() );
364364
final PwmResponse resp = pwmRequest.getPwmResponse();
365365
resp.markAsDownload( HttpContentType.zip, PwmConstants.PWM_APP_NAME + "-Support.zip" );
366366
try ( ZipOutputStream zipOutput = new ZipOutputStream( resp.getOutputStream(), PwmConstants.DEFAULT_CHARSET ) )

server/src/main/java/password/pwm/http/servlet/resource/ResourceServletService.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import java.util.Objects;
6060
import java.util.Optional;
6161
import java.util.Set;
62+
import java.util.function.Consumer;
6263
import java.util.zip.ZipEntry;
6364
import java.util.zip.ZipFile;
6465

@@ -304,6 +305,19 @@ private static void checksumResourceFilePath( final PwmDomain pwmDomain, final D
304305
return;
305306
}
306307

308+
final Consumer<FileSystemUtility.FileSummaryInformation> consumer = fileSummaryInformation ->
309+
{
310+
try
311+
{
312+
checksumStream.write( fileSummaryInformation.sha512Hash().getBytes( StandardCharsets.UTF_8 ) );
313+
}
314+
catch ( final Exception e )
315+
{
316+
LOGGER.error( () -> "unable to generate resource path nonce: " + e.getMessage() );
317+
}
318+
319+
};
320+
307321
pwmDomain.getPwmApplication().getPwmEnvironment().getContextManager().locateWebInfFilePath().ifPresent( webInfPath ->
308322
{
309323
final Path basePath = webInfPath.getParent();
@@ -312,21 +326,8 @@ private static void checksumResourceFilePath( final PwmDomain pwmDomain, final D
312326
final Path resourcePath = basePath.resolve( "public" ).resolve( "resources" );
313327
if ( Files.exists( resourcePath ) )
314328
{
315-
final List<FileSystemUtility.FileSummaryInformation> fileSummaryInformations =
316-
FileSystemUtility.readFileInformation( Collections.singletonList( resourcePath ) );
317-
{
318-
for ( final FileSystemUtility.FileSummaryInformation fileSummaryInformation : fileSummaryInformations )
319-
{
320-
try
321-
{
322-
checksumStream.write( fileSummaryInformation.getSha512Hash().getBytes( StandardCharsets.UTF_8 ) );
323-
}
324-
catch ( final Exception e )
325-
{
326-
LOGGER.error( () -> "unable to generate resource path nonce: " + e.getMessage() );
327-
}
328-
}
329-
}
329+
FileSystemUtility.readFileInformation( Collections.singletonList( resourcePath ) )
330+
.forEach( consumer::accept );
330331
}
331332
}
332333
} );

0 commit comments

Comments
 (0)