Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.cluster.impl; |
| 17 | |
Madan Jampani | 898fcca | 2016-02-26 12:42:08 -0800 | [diff] [blame] | 18 | import static org.onlab.util.Tools.groupedThreads; |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
| 21 | import java.io.File; |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 22 | import java.io.FileInputStream; |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 23 | import java.io.IOException; |
Jordan Halterman | dbfff06 | 2017-06-19 10:31:32 -0700 | [diff] [blame] | 24 | import java.net.HttpURLConnection; |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 25 | import java.net.URL; |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 26 | import java.util.Set; |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 27 | import java.util.concurrent.ScheduledExecutorService; |
| 28 | import java.util.concurrent.TimeUnit; |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 29 | import java.util.concurrent.atomic.AtomicReference; |
| 30 | |
| 31 | import org.apache.felix.scr.annotations.Activate; |
| 32 | import org.apache.felix.scr.annotations.Component; |
| 33 | import org.apache.felix.scr.annotations.Deactivate; |
| 34 | import org.apache.felix.scr.annotations.Reference; |
| 35 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 36 | import org.onlab.packet.IpAddress; |
| 37 | import org.onosproject.cluster.ClusterMetadata; |
| 38 | import org.onosproject.cluster.ClusterMetadataProvider; |
| 39 | import org.onosproject.cluster.ClusterMetadataProviderRegistry; |
| 40 | import org.onosproject.cluster.ClusterMetadataProviderService; |
| 41 | import org.onosproject.cluster.ControllerNode; |
| 42 | import org.onosproject.cluster.DefaultControllerNode; |
| 43 | import org.onosproject.cluster.DefaultPartition; |
| 44 | import org.onosproject.cluster.NodeId; |
| 45 | import org.onosproject.cluster.Partition; |
| 46 | import org.onosproject.cluster.PartitionId; |
| 47 | import org.onosproject.net.provider.ProviderId; |
| 48 | import org.onosproject.store.service.Versioned; |
| 49 | import org.slf4j.Logger; |
| 50 | |
| 51 | import com.fasterxml.jackson.core.JsonGenerator; |
| 52 | import com.fasterxml.jackson.core.JsonParser; |
| 53 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 54 | import com.fasterxml.jackson.databind.DeserializationContext; |
| 55 | import com.fasterxml.jackson.databind.JsonDeserializer; |
| 56 | import com.fasterxml.jackson.databind.JsonNode; |
| 57 | import com.fasterxml.jackson.databind.JsonSerializer; |
| 58 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 59 | import com.fasterxml.jackson.databind.SerializerProvider; |
| 60 | import com.fasterxml.jackson.databind.module.SimpleModule; |
| 61 | import com.google.common.base.Throwables; |
| 62 | import com.google.common.collect.Sets; |
| 63 | import com.google.common.io.Files; |
| 64 | |
| 65 | import static com.google.common.base.Preconditions.checkState; |
Yuta HIGUCHI | 1624df1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 66 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Provider of {@link ClusterMetadata cluster metadata} sourced from a local config file. |
| 70 | */ |
| 71 | @Component(immediate = true) |
| 72 | public class ConfigFileBasedClusterMetadataProvider implements ClusterMetadataProvider { |
| 73 | |
| 74 | private final Logger log = getLogger(getClass()); |
| 75 | |
| 76 | // constants for filed names (used in serialization) |
| 77 | private static final String ID = "id"; |
| 78 | private static final String PORT = "port"; |
| 79 | private static final String IP = "ip"; |
| 80 | |
Madan Jampani | 898fcca | 2016-02-26 12:42:08 -0800 | [diff] [blame] | 81 | private static final String CONFIG_DIR = "../config"; |
| 82 | private static final String CONFIG_FILE_NAME = "cluster.json"; |
| 83 | private static final File CONFIG_FILE = new File(CONFIG_DIR, CONFIG_FILE_NAME); |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 84 | |
| 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 86 | protected ClusterMetadataProviderRegistry providerRegistry; |
| 87 | |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 88 | private static final ProviderId PROVIDER_ID = new ProviderId("file", "none"); |
Madan Jampani | 898fcca | 2016-02-26 12:42:08 -0800 | [diff] [blame] | 89 | private final AtomicReference<Versioned<ClusterMetadata>> cachedMetadata = new AtomicReference<>(); |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 90 | private final ScheduledExecutorService configFileChangeDetector = |
Yuta HIGUCHI | 1624df1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 91 | newSingleThreadScheduledExecutor(groupedThreads("onos/cluster/metadata/config-watcher", "", log)); |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 92 | |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 93 | private String metadataUrl; |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 94 | private ObjectMapper mapper; |
| 95 | private ClusterMetadataProviderService providerService; |
| 96 | |
| 97 | @Activate |
| 98 | public void activate() { |
| 99 | mapper = new ObjectMapper(); |
| 100 | SimpleModule module = new SimpleModule(); |
| 101 | module.addSerializer(NodeId.class, new NodeIdSerializer()); |
| 102 | module.addDeserializer(NodeId.class, new NodeIdDeserializer()); |
| 103 | module.addSerializer(ControllerNode.class, new ControllerNodeSerializer()); |
| 104 | module.addDeserializer(ControllerNode.class, new ControllerNodeDeserializer()); |
Jordan Halterman | 21a74da | 2017-11-13 21:07:08 -0800 | [diff] [blame] | 105 | module.addSerializer(Partition.class, new PartitionSerializer()); |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 106 | module.addDeserializer(Partition.class, new PartitionDeserializer()); |
| 107 | module.addSerializer(PartitionId.class, new PartitionIdSerializer()); |
| 108 | module.addDeserializer(PartitionId.class, new PartitionIdDeserializer()); |
| 109 | mapper.registerModule(module); |
| 110 | providerService = providerRegistry.register(this); |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 111 | metadataUrl = System.getProperty("onos.cluster.metadata.uri", "file://" + CONFIG_DIR + "/" + CONFIG_FILE); |
| 112 | configFileChangeDetector.scheduleWithFixedDelay(() -> watchUrl(metadataUrl), 100, 500, TimeUnit.MILLISECONDS); |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 113 | log.info("Started"); |
| 114 | } |
| 115 | |
| 116 | @Deactivate |
| 117 | public void deactivate() { |
Madan Jampani | 898fcca | 2016-02-26 12:42:08 -0800 | [diff] [blame] | 118 | configFileChangeDetector.shutdown(); |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 119 | providerRegistry.unregister(this); |
| 120 | log.info("Stopped"); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public ProviderId id() { |
| 125 | return PROVIDER_ID; |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public Versioned<ClusterMetadata> getClusterMetadata() { |
| 130 | checkState(isAvailable()); |
| 131 | synchronized (this) { |
| 132 | if (cachedMetadata.get() == null) { |
Jordan Halterman | dbfff06 | 2017-06-19 10:31:32 -0700 | [diff] [blame] | 133 | cachedMetadata.set(blockForMetadata(metadataUrl)); |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 134 | } |
| 135 | return cachedMetadata.get(); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void setClusterMetadata(ClusterMetadata metadata) { |
| 141 | try { |
Ray Milkey | 8320088 | 2017-11-13 19:18:21 -0800 | [diff] [blame] | 142 | File configFile = new File(metadataUrl.replaceFirst("file://", "")); |
| 143 | Files.createParentDirs(configFile); |
| 144 | mapper.writeValue(configFile, metadata); |
| 145 | cachedMetadata.set(fetchMetadata(metadataUrl)); |
| 146 | providerService.clusterMetadataChanged(new Versioned<>(metadata, configFile.lastModified())); |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 147 | } catch (IOException e) { |
| 148 | Throwables.propagate(e); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void addActivePartitionMember(PartitionId partitionId, NodeId nodeId) { |
| 154 | throw new UnsupportedOperationException(); |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public void removeActivePartitionMember(PartitionId partitionId, NodeId nodeId) { |
| 159 | throw new UnsupportedOperationException(); |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public Set<NodeId> getActivePartitionMembers(PartitionId partitionId) { |
| 164 | throw new UnsupportedOperationException(); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public boolean isAvailable() { |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 169 | try { |
| 170 | URL url = new URL(metadataUrl); |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 171 | if ("file".equals(url.getProtocol())) { |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 172 | File file = new File(metadataUrl.replaceFirst("file://", "")); |
| 173 | return file.exists(); |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 174 | } else { |
Jordan Halterman | 46c7690 | 2017-08-24 14:55:25 -0700 | [diff] [blame] | 175 | // Return true for HTTP URLs since we allow blocking until HTTP servers come up |
| 176 | return "http".equals(url.getProtocol()); |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 177 | } |
| 178 | } catch (Exception e) { |
Jon Hall | db2cf75 | 2016-06-28 16:24:45 -0700 | [diff] [blame] | 179 | log.warn("Exception accessing metadata file at {}:", metadataUrl, e); |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 180 | return false; |
| 181 | } |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Jordan Halterman | dbfff06 | 2017-06-19 10:31:32 -0700 | [diff] [blame] | 184 | private Versioned<ClusterMetadata> blockForMetadata(String metadataUrl) { |
Jordan Halterman | 46c7690 | 2017-08-24 14:55:25 -0700 | [diff] [blame] | 185 | int iterations = 0; |
Jordan Halterman | dbfff06 | 2017-06-19 10:31:32 -0700 | [diff] [blame] | 186 | for (;;) { |
Jordan Halterman | 9ada34a | 2017-10-23 16:31:50 -0700 | [diff] [blame] | 187 | try { |
| 188 | Versioned<ClusterMetadata> metadata = fetchMetadata(metadataUrl); |
| 189 | if (metadata != null) { |
| 190 | return metadata; |
| 191 | } |
| 192 | } catch (Exception e) { |
| 193 | log.warn("Exception attempting to access metadata file at {}: {}", metadataUrl, e); |
Jordan Halterman | dbfff06 | 2017-06-19 10:31:32 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | try { |
Jordan Halterman | 9ada34a | 2017-10-23 16:31:50 -0700 | [diff] [blame] | 197 | Thread.sleep((int) Math.pow(2, iterations < 7 ? ++iterations : iterations) * 10); |
Jordan Halterman | dbfff06 | 2017-06-19 10:31:32 -0700 | [diff] [blame] | 198 | } catch (InterruptedException e) { |
| 199 | throw Throwables.propagate(e); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 204 | private Versioned<ClusterMetadata> fetchMetadata(String metadataUrl) { |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 205 | try { |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 206 | URL url = new URL(metadataUrl); |
| 207 | ClusterMetadata metadata = null; |
| 208 | long version = 0; |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 209 | if ("file".equals(url.getProtocol())) { |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 210 | File file = new File(metadataUrl.replaceFirst("file://", "")); |
| 211 | version = file.lastModified(); |
| 212 | metadata = mapper.readValue(new FileInputStream(file), ClusterMetadata.class); |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 213 | } else if ("http".equals(url.getProtocol())) { |
Jordan Halterman | da26837 | 2017-09-19 11:18:08 -0700 | [diff] [blame] | 214 | try { |
| 215 | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| 216 | if (conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { |
| 217 | log.warn("Could not reach metadata URL {}. Retrying...", url); |
| 218 | return null; |
| 219 | } |
| 220 | if (conn.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) { |
| 221 | return null; |
| 222 | } |
| 223 | version = conn.getLastModified(); |
| 224 | metadata = mapper.readValue(conn.getInputStream(), ClusterMetadata.class); |
| 225 | } catch (IOException e) { |
Jordan Halterman | 46c7690 | 2017-08-24 14:55:25 -0700 | [diff] [blame] | 226 | log.warn("Could not reach metadata URL {}. Retrying...", url); |
| 227 | return null; |
| 228 | } |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 229 | } |
Jordan Halterman | dbfff06 | 2017-06-19 10:31:32 -0700 | [diff] [blame] | 230 | |
zhiyong ke | 60e4000 | 2017-04-13 13:50:47 +0800 | [diff] [blame] | 231 | if (null == metadata) { |
| 232 | log.warn("Metadata is null in the function fetchMetadata"); |
| 233 | throw new NullPointerException(); |
| 234 | } |
Jordan Halterman | dbfff06 | 2017-06-19 10:31:32 -0700 | [diff] [blame] | 235 | |
| 236 | // If the configured partitions are empty then return a null metadata to indicate that the configuration |
| 237 | // needs to be polled until the partitions are populated. |
| 238 | if (metadata.getPartitions().isEmpty() || metadata.getPartitions().stream() |
| 239 | .map(partition -> partition.getMembers().size()) |
| 240 | .reduce(Math::min) |
| 241 | .orElse(0) == 0) { |
| 242 | return null; |
| 243 | } |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 244 | return new Versioned<>(new ClusterMetadata(PROVIDER_ID, |
| 245 | metadata.getName(), |
| 246 | Sets.newHashSet(metadata.getNodes()), |
| 247 | Sets.newHashSet(metadata.getPartitions())), |
| 248 | version); |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 249 | } catch (IOException e) { |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 250 | throw Throwables.propagate(e); |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 251 | } |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Jordan Halterman | 21a74da | 2017-11-13 21:07:08 -0800 | [diff] [blame] | 254 | private static class PartitionSerializer extends JsonSerializer<Partition> { |
| 255 | @Override |
| 256 | public void serialize(Partition partition, JsonGenerator jgen, SerializerProvider serializerProvider) |
| 257 | throws IOException, JsonProcessingException { |
| 258 | jgen.writeStartObject(); |
| 259 | jgen.writeNumberField("id", partition.getId().asInt()); |
| 260 | jgen.writeArrayFieldStart("members"); |
| 261 | for (NodeId nodeId : partition.getMembers()) { |
| 262 | jgen.writeString(nodeId.id()); |
| 263 | } |
| 264 | jgen.writeEndArray(); |
| 265 | jgen.writeEndObject(); |
| 266 | } |
| 267 | } |
| 268 | |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 269 | private static class PartitionDeserializer extends JsonDeserializer<Partition> { |
| 270 | @Override |
| 271 | public Partition deserialize(JsonParser jp, DeserializationContext ctxt) |
| 272 | throws IOException, JsonProcessingException { |
| 273 | return jp.readValueAs(DefaultPartition.class); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | private static class PartitionIdSerializer extends JsonSerializer<PartitionId> { |
| 278 | @Override |
| 279 | public void serialize(PartitionId partitionId, JsonGenerator jgen, SerializerProvider provider) |
| 280 | throws IOException, JsonProcessingException { |
| 281 | jgen.writeNumber(partitionId.asInt()); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | private class PartitionIdDeserializer extends JsonDeserializer<PartitionId> { |
| 286 | @Override |
| 287 | public PartitionId deserialize(JsonParser jp, DeserializationContext ctxt) |
| 288 | throws IOException, JsonProcessingException { |
| 289 | JsonNode node = jp.getCodec().readTree(jp); |
| 290 | return new PartitionId(node.asInt()); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | private static class ControllerNodeSerializer extends JsonSerializer<ControllerNode> { |
| 295 | @Override |
| 296 | public void serialize(ControllerNode node, JsonGenerator jgen, SerializerProvider provider) |
| 297 | throws IOException, JsonProcessingException { |
| 298 | jgen.writeStartObject(); |
| 299 | jgen.writeStringField(ID, node.id().toString()); |
| 300 | jgen.writeStringField(IP, node.ip().toString()); |
| 301 | jgen.writeNumberField(PORT, node.tcpPort()); |
| 302 | jgen.writeEndObject(); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | private static class ControllerNodeDeserializer extends JsonDeserializer<ControllerNode> { |
| 307 | @Override |
| 308 | public ControllerNode deserialize(JsonParser jp, DeserializationContext ctxt) |
| 309 | throws IOException, JsonProcessingException { |
| 310 | JsonNode node = jp.getCodec().readTree(jp); |
| 311 | NodeId nodeId = new NodeId(node.get(ID).textValue()); |
| 312 | IpAddress ip = IpAddress.valueOf(node.get(IP).textValue()); |
| 313 | int port = node.get(PORT).asInt(); |
| 314 | return new DefaultControllerNode(nodeId, ip, port); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | private static class NodeIdSerializer extends JsonSerializer<NodeId> { |
| 319 | @Override |
| 320 | public void serialize(NodeId nodeId, JsonGenerator jgen, SerializerProvider provider) |
| 321 | throws IOException, JsonProcessingException { |
| 322 | jgen.writeString(nodeId.toString()); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | private class NodeIdDeserializer extends JsonDeserializer<NodeId> { |
| 327 | @Override |
| 328 | public NodeId deserialize(JsonParser jp, DeserializationContext ctxt) |
| 329 | throws IOException, JsonProcessingException { |
| 330 | JsonNode node = jp.getCodec().readTree(jp); |
| 331 | return new NodeId(node.asText()); |
| 332 | } |
| 333 | } |
Madan Jampani | 898fcca | 2016-02-26 12:42:08 -0800 | [diff] [blame] | 334 | |
| 335 | /** |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 336 | * Monitors the metadata url for any updates and notifies providerService accordingly. |
Madan Jampani | 898fcca | 2016-02-26 12:42:08 -0800 | [diff] [blame] | 337 | */ |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 338 | private void watchUrl(String metadataUrl) { |
Ray Milkey | e3708c7 | 2017-11-13 13:10:46 -0800 | [diff] [blame] | 339 | if (!isAvailable()) { |
| 340 | return; |
| 341 | } |
Madan Jampani | f172d40 | 2016-03-04 00:56:38 -0800 | [diff] [blame] | 342 | // TODO: We are merely polling the url. |
| 343 | // This can be easily addressed for files. For http urls we need to move to a push style protocol. |
dvaddire | 49add80 | 2017-08-23 09:45:49 +0530 | [diff] [blame] | 344 | try { |
| 345 | Versioned<ClusterMetadata> latestMetadata = fetchMetadata(metadataUrl); |
| 346 | if (cachedMetadata.get() != null && latestMetadata != null |
| 347 | && cachedMetadata.get().version() < latestMetadata.version()) { |
| 348 | cachedMetadata.set(latestMetadata); |
| 349 | providerService.clusterMetadataChanged(latestMetadata); |
| 350 | } |
| 351 | } catch (Exception e) { |
| 352 | log.error("Unable to parse metadata : ", e); |
Madan Jampani | 898fcca | 2016-02-26 12:42:08 -0800 | [diff] [blame] | 353 | } |
| 354 | } |
Madan Jampani | ad3c526 | 2016-01-20 00:50:17 -0800 | [diff] [blame] | 355 | } |