diff --git a/openid-connect-common/src/main/java/org/mitre/data/AbstractPageOperationTemplate.java b/openid-connect-common/src/main/java/org/mitre/data/AbstractPageOperationTemplate.java index 3a8962aac..3494307df 100644 --- a/openid-connect-common/src/main/java/org/mitre/data/AbstractPageOperationTemplate.java +++ b/openid-connect-common/src/main/java/org/mitre/data/AbstractPageOperationTemplate.java @@ -40,6 +40,11 @@ public abstract class AbstractPageOperationTemplate<T> { * swallowed during execution default true. */ private boolean swallowExceptions = true; + + /** + * String that is used for logging in final tallies. + */ + private String operationName = ""; /** @@ -47,11 +52,10 @@ public abstract class AbstractPageOperationTemplate<T> { * maxPages and maxTime to DEFAULT_MAX_PAGES and * DEFAULT_MAX_TIME_MILLIS respectively */ - public AbstractPageOperationTemplate(){ - this(DEFAULT_MAX_PAGES, DEFAULT_MAX_TIME_MILLIS); + public AbstractPageOperationTemplate(String operationName){ + this(DEFAULT_MAX_PAGES, DEFAULT_MAX_TIME_MILLIS, operationName); } - /** * Instantiates a new AbstractPageOperationTemplate with the * given maxPages and maxTime @@ -59,12 +63,12 @@ public abstract class AbstractPageOperationTemplate<T> { * @param maxPages the maximum number of pages to fetch. * @param maxTime the maximum execution time. */ - public AbstractPageOperationTemplate(int maxPages, long maxTime){ + public AbstractPageOperationTemplate(int maxPages, long maxTime, String operationName){ this.maxPages = maxPages; this.maxTime = maxTime; + this.operationName = operationName; } - /** * Execute the operation on each member of a page of results * retrieved through the fetch method. the method will execute @@ -74,8 +78,7 @@ public abstract class AbstractPageOperationTemplate<T> { * swallowException (default true) field is set true. */ public void execute(){ - logger.info("Starting execution of paged operation. maximum time: " + maxTime - + " maximum pages: " + maxPages); + logger.debug("[" + getOperationName() + "] Starting execution of paged operation. maximum time: " + maxTime + ", maximum pages: " + maxPages); long startTime = System.currentTimeMillis(); long executionTime = 0; @@ -112,12 +115,11 @@ public abstract class AbstractPageOperationTemplate<T> { executionTime = System.currentTimeMillis() - startTime; } - logger.info("Paged operation run completed " + operationsCompleted + " swallowed " + exceptionsSwallowedCount + " exceptions"); - for(String className: exceptionsSwallowedClasses) { - logger.warn("Paged operation swallowed at least one exception of type " + className); - } + finalReport(operationsCompleted, exceptionsSwallowedCount, exceptionsSwallowedClasses); } + + /** * method responsible for fetching * a page of items. @@ -133,6 +135,19 @@ public abstract class AbstractPageOperationTemplate<T> { * @param item the item */ protected abstract void doOperation(T item); + + /** + * Method responsible for final report of progress. + * @return + */ + protected void finalReport(int operationsCompleted, int exceptionsSwallowedCount, Set<String> exceptionsSwallowedClasses) { + if (operationsCompleted > 0 || exceptionsSwallowedCount > 0) { + logger.info("[" + getOperationName() + "] Paged operation run: completed " + operationsCompleted + "; swallowed " + exceptionsSwallowedCount + " exceptions"); + } + for(String className: exceptionsSwallowedClasses) { + logger.warn("[" + getOperationName() + "] Paged operation swallowed at least one exception of type " + className); + } + } public int getMaxPages() { return maxPages; @@ -157,4 +172,20 @@ public abstract class AbstractPageOperationTemplate<T> { public void setSwallowExceptions(boolean swallowExceptions) { this.swallowExceptions = swallowExceptions; } + + + /** + * @return the operationName + */ + public String getOperationName() { + return operationName; + } + + + /** + * @param operationName the operationName to set + */ + public void setOperationName(String operationName) { + this.operationName = operationName; + } } diff --git a/openid-connect-common/src/test/java/org/mitre/data/AbstractPageOperationTemplateTest.java b/openid-connect-common/src/test/java/org/mitre/data/AbstractPageOperationTemplateTest.java index 6dcc8a2bf..46d8bf57e 100644 --- a/openid-connect-common/src/test/java/org/mitre/data/AbstractPageOperationTemplateTest.java +++ b/openid-connect-common/src/test/java/org/mitre/data/AbstractPageOperationTemplateTest.java @@ -138,7 +138,7 @@ public class AbstractPageOperationTemplateTest { private long timeToPreviousFetch; private CountingPageOperation(int maxPages, long maxTime) { - super(maxPages, maxTime); + super(maxPages, maxTime, "CountingPageOperation"); startTime = System.currentTimeMillis(); } diff --git a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2AuthorizationCodeService.java b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2AuthorizationCodeService.java index 9c633e9ff..59806caa2 100644 --- a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2AuthorizationCodeService.java +++ b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2AuthorizationCodeService.java @@ -117,7 +117,7 @@ public class DefaultOAuth2AuthorizationCodeService implements AuthorizationCodeS @Transactional(value="defaultTransactionManager") public void clearExpiredAuthorizationCodes() { - new AbstractPageOperationTemplate<AuthorizationCodeEntity>(){ + new AbstractPageOperationTemplate<AuthorizationCodeEntity>("clearExpiredAuthorizationCodes"){ @Override public Collection<AuthorizationCodeEntity> fetchPage() { return repository.getExpiredCodes(); diff --git a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ProviderTokenService.java b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ProviderTokenService.java index b7681752d..ad0a66491 100644 --- a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ProviderTokenService.java +++ b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ProviderTokenService.java @@ -492,7 +492,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi public void clearExpiredTokens() { logger.debug("Cleaning out all expired tokens"); - new AbstractPageOperationTemplate<OAuth2AccessTokenEntity>() { + new AbstractPageOperationTemplate<OAuth2AccessTokenEntity>("clearExpiredAccessTokens") { @Override public Collection<OAuth2AccessTokenEntity> fetchPage() { return tokenRepository.getAllExpiredAccessTokens(new DefaultPageCriteria()); @@ -504,7 +504,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi } }.execute(); - new AbstractPageOperationTemplate<OAuth2RefreshTokenEntity>() { + new AbstractPageOperationTemplate<OAuth2RefreshTokenEntity>("clearExpiredRefreshTokens") { @Override public Collection<OAuth2RefreshTokenEntity> fetchPage() { return tokenRepository.getAllExpiredRefreshTokens(new DefaultPageCriteria()); @@ -516,7 +516,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi } }.execute(); - new AbstractPageOperationTemplate<AuthenticationHolderEntity>() { + new AbstractPageOperationTemplate<AuthenticationHolderEntity>("clearExpiredAuthenticationHolders") { @Override public Collection<AuthenticationHolderEntity> fetchPage() { return authenticationHolderRepository.getOrphanedAuthenticationHolders(new DefaultPageCriteria());