Fix for reading remote cluster metadata file
Log exceptions when trying to access metadata file
Close connections opened when checking file availability
Change-Id: Ibe89e66ba52dba1c47b559bb784fd7376a3319f2
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 8f34ec4..2571204 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
@@ -21,6 +21,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Set;
@@ -169,13 +170,15 @@
File file = new File(metadataUrl.replaceFirst("file://", ""));
return file.exists();
} else if (url.getProtocol().equals("http")) {
- url.openStream();
- return true;
+ try (InputStream file = url.openStream()) {
+ return true;
+ }
} else {
// Unsupported protocol
return false;
}
} catch (Exception e) {
+ log.warn("Exception accessing metadata file at {}:", metadataUrl, e);
return false;
}
}