Revert "[WIP] Block ConfigFileBasedClusterMetadataProvider until valid configuration is found."
This reverts commit fd2e126aef3854292f4c6f786109f45f6e843fe7.
Change-Id: I21a8336fea75bb787a75f4bd2ee87ce6370b2086
diff --git a/core/net/src/main/java/org/onosproject/cluster/impl/ConfigFileBasedClusterMetadataProvider.java b/core/net/src/main/java/org/onosproject/cluster/impl/ConfigFileBasedClusterMetadataProvider.java
index ae57576..c75da8a 100644
--- a/core/net/src/main/java/org/onosproject/cluster/impl/ConfigFileBasedClusterMetadataProvider.java
+++ b/core/net/src/main/java/org/onosproject/cluster/impl/ConfigFileBasedClusterMetadataProvider.java
@@ -179,7 +179,7 @@
}
private Versioned<ClusterMetadata> blockForMetadata(String metadataUrl) {
-
+ int iterations = 0;
for (;;) {
Versioned<ClusterMetadata> metadata = fetchMetadata(metadataUrl);
if (metadata != null) {
@@ -187,7 +187,7 @@
}
try {
- Thread.sleep(10);
+ Thread.sleep(Math.min((int) Math.pow(2, ++iterations) * 10, 1000));
} catch (InterruptedException e) {
throw Throwables.propagate(e);
}
@@ -204,12 +204,21 @@
version = file.lastModified();
metadata = mapper.readValue(new FileInputStream(file), ClusterMetadata.class);
} else if ("http".equals(url.getProtocol())) {
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- if (conn.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
+ try {
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ if (conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
+ log.warn("Could not reach metadata URL {}. Retrying...", url);
+ return null;
+ }
+ if (conn.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
+ return null;
+ }
+ version = conn.getLastModified();
+ metadata = mapper.readValue(conn.getInputStream(), ClusterMetadata.class);
+ } catch (IOException e) {
+ log.warn("Could not reach metadata URL {}. Retrying...", url);
return null;
}
- version = conn.getLastModified();
- metadata = mapper.readValue(conn.getInputStream(), ClusterMetadata.class);
}
if (null == metadata) {