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