[java-opensaml] 01/04: OSJ-202: Add "last successful refresh attempt" to batch metadata resolvers

Brent Putman putmanb at georgetown.edu
Wed May 10 19:39:45 EDT 2017


This is an automated email from the git hooks/post-receive script.

putmanb pushed a commit to branch master
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=32a8d68372ad7060ced100a629da76258545baf0

commit 32a8d68372ad7060ced100a629da76258545baf0
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Wed May 10 18:28:10 2017 -0400

    OSJ-202: Add "last successful refresh attempt" to batch metadata
    resolvers
    
    Add new public methods getLastSuccessfulRefresh() and
    wasLastRefreshSuccess()
---
 .../resolver/RefreshableMetadataResolver.java      |  2 ++
 .../impl/AbstractReloadingMetadataResolver.java    | 40 ++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/metadata/resolver/RefreshableMetadataResolver.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/metadata/resolver/RefreshableMetadataResolver.java
index 0a43b55..737970f 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/metadata/resolver/RefreshableMetadataResolver.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/metadata/resolver/RefreshableMetadataResolver.java
@@ -56,4 +56,6 @@ public interface RefreshableMetadataResolver extends MetadataResolver {
      */
     @Nullable DateTime getLastUpdate();
     
+    //TODO For 4.0: promote getLastSuccessfulRefresh() and wasLastRefreshSuccess() from AbstractReloadingMetadataResolver
+    
 }
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractReloadingMetadataResolver.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractReloadingMetadataResolver.java
index e5fe4af..16a9a2e 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractReloadingMetadataResolver.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractReloadingMetadataResolver.java
@@ -96,6 +96,15 @@ public abstract class AbstractReloadingMetadataResolver extends AbstractBatchMet
 
     /** Next time a refresh cycle will occur. */
     private DateTime nextRefresh;
+    
+    /** Last time a successful refresh cycle occurred. */
+    private DateTime lastSuccessfulRefresh;
+
+    /** Flag indicating whether last refresh cycle was successful. */
+    private Boolean wasLastRefreshSuccess;
+    
+    /** Internal flag for tracking success during the refresh operation. */
+    private boolean trackRefreshSuccess;
 
     /** Constructor. */
     protected AbstractReloadingMetadataResolver() {
@@ -153,6 +162,24 @@ public abstract class AbstractReloadingMetadataResolver extends AbstractBatchMet
     @Override @Nullable public DateTime getLastRefresh() {
         return lastRefresh;
     }
+    
+    /**
+     * Gets the time the last successful refresh cycle occurred.
+     * 
+     * @return time the last successful refresh cycle occurred
+     */
+    @Nullable DateTime getLastSuccessfulRefresh() {
+        return lastSuccessfulRefresh;
+    }
+
+    /**
+     * Gets whether the last refresh cycle was successful.
+     * 
+     * @return true if last refresh cycle was successful, false if not
+     */
+    @Nullable Boolean wasLastRefreshSuccess() {
+        return wasLastRefreshSuccess;
+    }
 
     /**
      * Gets the time when the next refresh cycle will occur.
@@ -279,6 +306,7 @@ public abstract class AbstractReloadingMetadataResolver extends AbstractBatchMet
     public synchronized void refresh() throws ResolverException {
         final DateTime now = new DateTime(ISOChronology.getInstanceUTC());
         final String mdId = getMetadataIdentifier();
+        trackRefreshSuccess = false;
 
         log.debug("{} Beginning refresh of metadata from '{}'", getLogPrefix(), mdId);
         try {
@@ -291,6 +319,7 @@ public abstract class AbstractReloadingMetadataResolver extends AbstractBatchMet
                 processNewMetadata(mdId, now, mdBytes);
             }
         } catch (final Throwable t) {
+            trackRefreshSuccess = false;
             log.error("{} Error occurred while attempting to refresh metadata from '{}'", getLogPrefix(), mdId, t);
             nextRefresh = new DateTime(ISOChronology.getInstanceUTC()).plus(minRefreshDelay);
             if (t instanceof Exception) {
@@ -305,6 +334,14 @@ public abstract class AbstractReloadingMetadataResolver extends AbstractBatchMet
                 log.warn("{} Metadata root from '{}' currently live (post-refresh) is expired or otherwise invalid", 
                         getLogPrefix(), mdId);
             }
+            
+            if (trackRefreshSuccess) {
+                wasLastRefreshSuccess = true;
+                lastSuccessfulRefresh = now;
+            } else {
+                wasLastRefreshSuccess = false;
+            }
+            
             refreshMetadataTask = new RefreshMetadataTask();
             final long nextRefreshDelay = nextRefresh.getMillis() - System.currentTimeMillis();
             taskTimer.schedule(refreshMetadataTask, nextRefreshDelay);
@@ -365,6 +402,7 @@ public abstract class AbstractReloadingMetadataResolver extends AbstractBatchMet
                 SAML2Support.getEarliestExpiration(getBackingStore().getCachedOriginalMetadata(),
                 refreshStart.plus(getMaxRefreshDelay()), refreshStart);
 
+        trackRefreshSuccess = true;
         expirationTime = metadataExpirationTime;
         final long nextRefreshDelay = computeNextRefreshDelay(expirationTime);
         nextRefresh = new DateTime(ISOChronology.getInstanceUTC()).plus(nextRefreshDelay);
@@ -408,6 +446,7 @@ public abstract class AbstractReloadingMetadataResolver extends AbstractBatchMet
                 getLogPrefix(), metadataIdentifier);
 
         nextRefresh = new DateTime(ISOChronology.getInstanceUTC()).plus(getMinRefreshDelay());
+        trackRefreshSuccess = false;
     }
 
     /**
@@ -456,6 +495,7 @@ public abstract class AbstractReloadingMetadataResolver extends AbstractBatchMet
         setBackingStore(newBackingStore);
         
         lastUpdate = refreshStart;
+        trackRefreshSuccess = true;
         
         long nextRefreshDelay;
         if (metadataExpirationTime.isBeforeNow()) {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list