blob: da8796b9b4d8a2b8e94518e0778b68efb288ddc8 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
Ayaka Koshibee114f042015-05-01 11:43:00 -070016package org.onosproject.store.resource.impl;
17
18import java.util.ArrayList;
19import java.util.Collection;
20import java.util.Collections;
21import java.util.HashMap;
22import java.util.HashSet;
23import java.util.List;
24import java.util.Map;
25import java.util.Set;
26import java.util.stream.Collectors;
27
28import org.apache.felix.scr.annotations.Component;
29import org.apache.felix.scr.annotations.Reference;
30import org.apache.felix.scr.annotations.ReferenceCardinality;
31import org.apache.felix.scr.annotations.Service;
32import org.apache.felix.scr.annotations.Activate;
33import org.apache.felix.scr.annotations.Deactivate;
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070034import org.onlab.util.Bandwidth;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070035import org.onosproject.net.OmsPort;
36import org.onosproject.net.device.DeviceService;
Ayaka Koshibee114f042015-05-01 11:43:00 -070037import org.slf4j.Logger;
Ayaka Koshibee114f042015-05-01 11:43:00 -070038import org.onlab.util.PositionalParameterStringFormatter;
39import org.onosproject.net.Link;
40import org.onosproject.net.LinkKey;
Ayaka Koshibe8117f362015-06-02 13:44:01 -070041import org.onosproject.net.Port;
Ayaka Koshibee114f042015-05-01 11:43:00 -070042import org.onosproject.net.intent.IntentId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070043import org.onosproject.net.resource.link.BandwidthResource;
44import org.onosproject.net.resource.link.BandwidthResourceAllocation;
45import org.onosproject.net.resource.link.LambdaResource;
46import org.onosproject.net.resource.link.LambdaResourceAllocation;
47import org.onosproject.net.resource.link.LinkResourceAllocations;
48import org.onosproject.net.resource.link.LinkResourceEvent;
49import org.onosproject.net.resource.link.LinkResourceStore;
50import org.onosproject.net.resource.link.LinkResourceStoreDelegate;
51import org.onosproject.net.resource.link.MplsLabel;
52import org.onosproject.net.resource.link.MplsLabelResourceAllocation;
Ayaka Koshibee114f042015-05-01 11:43:00 -070053import org.onosproject.net.resource.ResourceAllocation;
54import org.onosproject.net.resource.ResourceAllocationException;
55import org.onosproject.net.resource.ResourceType;
56import org.onosproject.store.AbstractStore;
57import org.onosproject.store.serializers.KryoNamespaces;
58import org.onosproject.store.service.ConsistentMap;
59import org.onosproject.store.service.Serializer;
60import org.onosproject.store.service.StorageService;
61import org.onosproject.store.service.TransactionContext;
62import org.onosproject.store.service.TransactionException;
63import org.onosproject.store.service.TransactionalMap;
64import org.onosproject.store.service.Versioned;
65
66import com.google.common.collect.ImmutableList;
67import com.google.common.collect.ImmutableSet;
68import com.google.common.collect.Sets;
69
70import static com.google.common.base.Preconditions.checkNotNull;
71import static com.google.common.base.Preconditions.checkState;
72import static org.slf4j.LoggerFactory.getLogger;
73import static org.onosproject.net.AnnotationKeys.BANDWIDTH;
Ayaka Koshibee114f042015-05-01 11:43:00 -070074
75/**
76 * Store that manages link resources using Copycat-backed TransactionalMaps.
77 */
Ayaka Koshibe474ef5f2015-05-01 15:24:51 -070078@Component(immediate = true, enabled = true)
Ayaka Koshibee114f042015-05-01 11:43:00 -070079@Service
80public class ConsistentLinkResourceStore extends
81 AbstractStore<LinkResourceEvent, LinkResourceStoreDelegate> implements
82 LinkResourceStore {
83
84 private final Logger log = getLogger(getClass());
85
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070086 private static final BandwidthResource DEFAULT_BANDWIDTH = new BandwidthResource(Bandwidth.mbps(1_000));
87 private static final BandwidthResource EMPTY_BW = new BandwidthResource(Bandwidth.bps(0));
Ayaka Koshibee114f042015-05-01 11:43:00 -070088
89 // Smallest non-reserved MPLS label
90 private static final int MIN_UNRESERVED_LABEL = 0x10;
91 // Max non-reserved MPLS label = 239
92 private static final int MAX_UNRESERVED_LABEL = 0xEF;
93
94 // table to store current allocations
95 /** LinkKey -> List<LinkResourceAllocations>. */
Ayaka Koshibebcb02372015-06-01 10:56:42 -070096 private static final String LINK_RESOURCE_ALLOCATIONS = "LinkAllocations";
Ayaka Koshibee114f042015-05-01 11:43:00 -070097
98 /** IntentId -> LinkResourceAllocations. */
Ayaka Koshibebcb02372015-06-01 10:56:42 -070099 private static final String INTENT_ALLOCATIONS = "LinkIntentAllocations";
Ayaka Koshibee114f042015-05-01 11:43:00 -0700100
Sho SHIMIZU200a7392015-07-23 16:28:35 -0700101 private static final Serializer SERIALIZER = Serializer.using(KryoNamespaces.API);
Ayaka Koshibee114f042015-05-01 11:43:00 -0700102
103 // for reading committed values.
104 private ConsistentMap<IntentId, LinkResourceAllocations> intentAllocMap;
105
106 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
107 protected StorageService storageService;
108
109 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700110 protected DeviceService deviceService;
111
Ayaka Koshibee114f042015-05-01 11:43:00 -0700112 @Activate
113 public void activate() {
114 intentAllocMap = storageService.<IntentId, LinkResourceAllocations>consistentMapBuilder()
115 .withName(INTENT_ALLOCATIONS)
116 .withSerializer(SERIALIZER)
117 .build();
118 log.info("Started");
119 }
120
121 @Deactivate
122 public void deactivate() {
123 log.info("Stopped");
124 }
125
126 private TransactionalMap<IntentId, LinkResourceAllocations> getIntentAllocs(TransactionContext tx) {
127 return tx.getTransactionalMap(INTENT_ALLOCATIONS, SERIALIZER);
128 }
129
130 private TransactionalMap<LinkKey, List<LinkResourceAllocations>> getLinkAllocs(TransactionContext tx) {
131 return tx.getTransactionalMap(LINK_RESOURCE_ALLOCATIONS, SERIALIZER);
132 }
133
134 private TransactionContext getTxContext() {
135 return storageService.transactionContextBuilder().build();
136 }
137
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700138 private Set<ResourceAllocation> getResourceCapacity(ResourceType type, Link link) {
Sho SHIMIZU04ae54a2015-10-05 15:46:28 -0700139 switch (type) {
140 case BANDWIDTH:
141 return ImmutableSet.of(getBandwidthResourceCapacity(link));
142 case LAMBDA:
143 return getLambdaResourceCapacity(link);
144 case MPLS_LABEL:
145 return getMplsResourceCapacity();
146 default:
147 return ImmutableSet.of();
Ayaka Koshibee114f042015-05-01 11:43:00 -0700148 }
Ayaka Koshibee114f042015-05-01 11:43:00 -0700149 }
150
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700151 private Set<ResourceAllocation> getLambdaResourceCapacity(Link link) {
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700152 Port port = deviceService.getPort(link.src().deviceId(), link.src().port());
Sho SHIMIZUa005a6e52015-10-02 15:13:27 -0700153 if (!(port instanceof OmsPort)) {
154 return Collections.emptySet();
155 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700156
Sho SHIMIZUa005a6e52015-10-02 15:13:27 -0700157 OmsPort omsPort = (OmsPort) port;
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700158 Set<ResourceAllocation> allocations = new HashSet<>();
Sho SHIMIZUa005a6e52015-10-02 15:13:27 -0700159 // Assume fixed grid for now
160 for (int i = 0; i < omsPort.totalChannels(); i++) {
161 allocations.add(new LambdaResourceAllocation(LambdaResource.valueOf(i)));
Ayaka Koshibee114f042015-05-01 11:43:00 -0700162 }
163 return allocations;
164 }
165
166 private BandwidthResourceAllocation getBandwidthResourceCapacity(Link link) {
167
168 // if Link annotation exist, use them
169 // if all fails, use DEFAULT_BANDWIDTH
Sho SHIMIZUa890e7c2015-10-02 14:48:13 -0700170 BandwidthResource bandwidth = DEFAULT_BANDWIDTH;
Ayaka Koshibee114f042015-05-01 11:43:00 -0700171 String strBw = link.annotations().value(BANDWIDTH);
Sho SHIMIZUa005a6e52015-10-02 15:13:27 -0700172 if (strBw == null) {
173 return new BandwidthResourceAllocation(bandwidth);
Ayaka Koshibee114f042015-05-01 11:43:00 -0700174 }
175
Sho SHIMIZUa005a6e52015-10-02 15:13:27 -0700176 try {
177 bandwidth = new BandwidthResource(Bandwidth.mbps(Double.parseDouble(strBw)));
178 } catch (NumberFormatException e) {
179 // do nothings, use default bandwidth
180 bandwidth = DEFAULT_BANDWIDTH;
181 }
Ayaka Koshibee114f042015-05-01 11:43:00 -0700182 return new BandwidthResourceAllocation(bandwidth);
183 }
184
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700185 private Set<ResourceAllocation> getMplsResourceCapacity() {
186 Set<ResourceAllocation> allocations = new HashSet<>();
Ayaka Koshibee114f042015-05-01 11:43:00 -0700187 //Ignoring reserved labels of 0 through 15
188 for (int i = MIN_UNRESERVED_LABEL; i <= MAX_UNRESERVED_LABEL; i++) {
189 allocations.add(new MplsLabelResourceAllocation(MplsLabel
190 .valueOf(i)));
191
192 }
193 return allocations;
194 }
195
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700196 private Map<ResourceType, Set<ResourceAllocation>> getResourceCapacity(Link link) {
197 Map<ResourceType, Set<ResourceAllocation>> caps = new HashMap<>();
Ayaka Koshibee114f042015-05-01 11:43:00 -0700198 for (ResourceType type : ResourceType.values()) {
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700199 Set<ResourceAllocation> cap = getResourceCapacity(type, link);
Sho SHIMIZUf618cb02015-10-02 14:43:50 -0700200 caps.put(type, cap);
Ayaka Koshibee114f042015-05-01 11:43:00 -0700201 }
202 return caps;
203 }
204
205 @Override
206 public Set<ResourceAllocation> getFreeResources(Link link) {
207 TransactionContext tx = getTxContext();
208
209 tx.begin();
210 try {
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700211 Map<ResourceType, Set<ResourceAllocation>> freeResources = getFreeResourcesEx(tx, link);
Sho SHIMIZUeca9f352015-10-05 15:55:24 -0700212 return freeResources.values().stream()
213 .flatMap(Collection::stream)
214 .collect(Collectors.toSet());
Ayaka Koshibee114f042015-05-01 11:43:00 -0700215 } finally {
216 tx.abort();
217 }
218 }
219
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700220 private Map<ResourceType, Set<ResourceAllocation>> getFreeResourcesEx(TransactionContext tx, Link link) {
Ayaka Koshibee114f042015-05-01 11:43:00 -0700221 checkNotNull(tx);
222 checkNotNull(link);
223
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700224 Map<ResourceType, Set<ResourceAllocation>> free = new HashMap<>();
225 final Map<ResourceType, Set<ResourceAllocation>> caps = getResourceCapacity(link);
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700226 final List<LinkResourceAllocations> allocations = ImmutableList.copyOf(getAllocations(tx, link));
Ayaka Koshibee114f042015-05-01 11:43:00 -0700227
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700228 Set<ResourceAllocation> bw = caps.get(ResourceType.BANDWIDTH);
229 Set<ResourceAllocation> value = getFreeBandwidthResources(link, bw, allocations);
230 free.put(ResourceType.BANDWIDTH, value);
Ayaka Koshibee114f042015-05-01 11:43:00 -0700231
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700232 Set<ResourceAllocation> lmd = caps.get(ResourceType.LAMBDA);
Sho SHIMIZU1bd72c22015-10-06 10:52:12 -0700233 Set<ResourceAllocation> freeL = getFreeResources(link, lmd, allocations,
234 LambdaResourceAllocation.class);
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700235 free.put(ResourceType.LAMBDA, freeL);
Ayaka Koshibee114f042015-05-01 11:43:00 -0700236
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700237 Set<ResourceAllocation> mpls = caps.get(ResourceType.MPLS_LABEL);
Sho SHIMIZU1bd72c22015-10-06 10:52:12 -0700238 Set<ResourceAllocation> freeLabel = getFreeResources(link, mpls, allocations,
239 MplsLabelResourceAllocation.class);
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700240 free.put(ResourceType.MPLS_LABEL, freeLabel);
Ayaka Koshibee114f042015-05-01 11:43:00 -0700241
Ayaka Koshibee114f042015-05-01 11:43:00 -0700242 return free;
243 }
244
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700245 private Set<ResourceAllocation> getFreeBandwidthResources(Link link, Set<ResourceAllocation> bw,
246 List<LinkResourceAllocations> allocations) {
247 if (bw == null || bw.isEmpty()) {
248 bw = Sets.newHashSet(new BandwidthResourceAllocation(EMPTY_BW));
249 }
250
251 BandwidthResourceAllocation cap = (BandwidthResourceAllocation) bw.iterator().next();
252 double freeBw = cap.bandwidth().toDouble();
253
254 // enumerate current allocations, subtracting resources
255 double allocatedBw = allocations.stream()
256 .flatMap(x -> x.getResourceAllocation(link).stream())
257 .filter(x -> x instanceof BandwidthResourceAllocation)
258 .map(x -> (BandwidthResourceAllocation) x)
259 .mapToDouble(x -> x.bandwidth().toDouble())
260 .sum();
261 freeBw -= allocatedBw;
262 return Sets.newHashSet(
263 new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(freeBw))));
264 }
265
Sho SHIMIZU1bd72c22015-10-06 10:52:12 -0700266 private Set<ResourceAllocation> getFreeResources(Link link,
267 Set<ResourceAllocation> resources,
268 List<LinkResourceAllocations> allocations,
269 Class<? extends ResourceAllocation> cls) {
270 if (resources == null || resources.isEmpty()) {
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700271 // nothing left
272 return Collections.emptySet();
273 }
Sho SHIMIZU1bd72c22015-10-06 10:52:12 -0700274 Set<ResourceAllocation> freeL = resources.stream()
275 .filter(cls::isInstance)
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700276 .collect(Collectors.toSet());
277
278 // enumerate current allocations, removing resources
Sho SHIMIZU1bd72c22015-10-06 10:52:12 -0700279 List<ResourceAllocation> allocated = allocations.stream()
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700280 .flatMap(x -> x.getResourceAllocation(link).stream())
Sho SHIMIZU1bd72c22015-10-06 10:52:12 -0700281 .filter(cls::isInstance)
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700282 .collect(Collectors.toList());
Sho SHIMIZU1bd72c22015-10-06 10:52:12 -0700283 freeL.removeAll(allocated);
Sho SHIMIZU48588a72015-10-05 17:00:48 -0700284 return freeL;
285 }
286
Ayaka Koshibee114f042015-05-01 11:43:00 -0700287 @Override
288 public void allocateResources(LinkResourceAllocations allocations) {
289 checkNotNull(allocations);
290 TransactionContext tx = getTxContext();
291
292 tx.begin();
293 try {
294 TransactionalMap<IntentId, LinkResourceAllocations> intentAllocs = getIntentAllocs(tx);
295 intentAllocs.put(allocations.intentId(), allocations);
296 allocations.links().forEach(link -> allocateLinkResource(tx, link, allocations));
297 tx.commit();
298 } catch (Exception e) {
299 log.error("Exception thrown, rolling back", e);
300 tx.abort();
301 throw e;
302 }
303 }
304
305 private void allocateLinkResource(TransactionContext tx, Link link,
306 LinkResourceAllocations allocations) {
307 // requested resources
308 Set<ResourceAllocation> reqs = allocations.getResourceAllocation(link);
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700309 Map<ResourceType, Set<ResourceAllocation>> available = getFreeResourcesEx(tx, link);
Ayaka Koshibee114f042015-05-01 11:43:00 -0700310 for (ResourceAllocation req : reqs) {
Sho SHIMIZUe1b463b2015-10-05 15:39:19 -0700311 Set<ResourceAllocation> avail = available.get(req.type());
Ayaka Koshibee114f042015-05-01 11:43:00 -0700312 if (req instanceof BandwidthResourceAllocation) {
313 // check if allocation should be accepted
314 if (avail.isEmpty()) {
315 checkState(!avail.isEmpty(),
316 "There's no Bandwidth resource on %s?",
317 link);
318 }
319 BandwidthResourceAllocation bw = (BandwidthResourceAllocation) avail.iterator().next();
320 double bwLeft = bw.bandwidth().toDouble();
321 BandwidthResourceAllocation bwReq = ((BandwidthResourceAllocation) req);
322 bwLeft -= bwReq.bandwidth().toDouble();
323 if (bwLeft < 0) {
324 throw new ResourceAllocationException(
325 PositionalParameterStringFormatter.format(
326 "Unable to allocate bandwidth for link {} "
327 + " requested amount is {} current allocation is {}",
328 link,
329 bwReq.bandwidth().toDouble(),
330 bw));
331 }
332 } else if (req instanceof LambdaResourceAllocation) {
333 LambdaResourceAllocation lambdaAllocation = (LambdaResourceAllocation) req;
334 // check if allocation should be accepted
335 if (!avail.contains(req)) {
336 // requested lambda was not available
337 throw new ResourceAllocationException(
338 PositionalParameterStringFormatter.format(
339 "Unable to allocate lambda for link {} lambda is {}",
340 link,
341 lambdaAllocation.lambda().toInt()));
342 }
343 } else if (req instanceof MplsLabelResourceAllocation) {
344 MplsLabelResourceAllocation mplsAllocation = (MplsLabelResourceAllocation) req;
345 if (!avail.contains(req)) {
346 throw new ResourceAllocationException(
347 PositionalParameterStringFormatter
348 .format("Unable to allocate MPLS label for link "
349 + "{} MPLS label is {}",
350 link,
351 mplsAllocation
352 .mplsLabel()
353 .toString()));
354 }
355 }
356 }
357 // all requests allocatable => add allocation
358 final LinkKey linkKey = LinkKey.linkKey(link);
359 TransactionalMap<LinkKey, List<LinkResourceAllocations>> linkAllocs = getLinkAllocs(tx);
360 List<LinkResourceAllocations> before = linkAllocs.get(linkKey);
361 if (before == null) {
362 List<LinkResourceAllocations> after = new ArrayList<>();
363 after.add(allocations);
364 before = linkAllocs.putIfAbsent(linkKey, after);
365 if (before != null) {
366 // concurrent allocation detected, retry transaction : is this needed?
367 log.warn("Concurrent Allocation, retrying");
368 throw new TransactionException();
369 }
370 } else {
371 List<LinkResourceAllocations> after = new ArrayList<>(before.size() + 1);
372 after.addAll(before);
373 after.add(allocations);
374 linkAllocs.replace(linkKey, before, after);
375 }
376 }
377
378 @Override
379 public LinkResourceEvent releaseResources(LinkResourceAllocations allocations) {
380 checkNotNull(allocations);
381
382 final IntentId intentId = allocations.intentId();
383 final Collection<Link> links = allocations.links();
384 boolean success = false;
385 do {
386 TransactionContext tx = getTxContext();
387 tx.begin();
388 try {
389 TransactionalMap<IntentId, LinkResourceAllocations> intentAllocs = getIntentAllocs(tx);
390 intentAllocs.remove(intentId);
391
392 TransactionalMap<LinkKey, List<LinkResourceAllocations>> linkAllocs = getLinkAllocs(tx);
393 links.forEach(link -> {
394 final LinkKey linkId = LinkKey.linkKey(link);
395
396 List<LinkResourceAllocations> before = linkAllocs.get(linkId);
397 if (before == null || before.isEmpty()) {
398 // something is wrong, but it is already freed
399 log.warn("There was no resource left to release on {}", linkId);
400 return;
401 }
402 List<LinkResourceAllocations> after = new ArrayList<>(before);
403 after.remove(allocations);
404 linkAllocs.replace(linkId, before, after);
405 });
406 tx.commit();
407 success = true;
408 } catch (TransactionException e) {
409 log.debug("Transaction failed, retrying", e);
410 tx.abort();
411 } catch (Exception e) {
412 log.error("Exception thrown during releaseResource {}", allocations, e);
413 tx.abort();
414 throw e;
415 }
416 } while (!success);
417
418 // Issue events to force recompilation of intents.
419 final List<LinkResourceAllocations> releasedResources = ImmutableList.of(allocations);
420 return new LinkResourceEvent(
421 LinkResourceEvent.Type.ADDITIONAL_RESOURCES_AVAILABLE,
422 releasedResources);
423
424 }
425
426 @Override
427 public LinkResourceAllocations getAllocations(IntentId intentId) {
428 checkNotNull(intentId);
429 Versioned<LinkResourceAllocations> alloc = null;
430 try {
431 alloc = intentAllocMap.get(intentId);
432 } catch (Exception e) {
433 log.warn("Could not read resource allocation information", e);
434 }
435 return alloc == null ? null : alloc.value();
436 }
437
438 @Override
439 public Iterable<LinkResourceAllocations> getAllocations(Link link) {
440 checkNotNull(link);
441 TransactionContext tx = getTxContext();
442 Iterable<LinkResourceAllocations> res = null;
443 tx.begin();
444 try {
445 res = getAllocations(tx, link);
446 } finally {
447 tx.abort();
448 }
449 return res == null ? Collections.emptyList() : res;
450 }
451
452 @Override
453 public Iterable<LinkResourceAllocations> getAllocations() {
454 try {
455 Set<LinkResourceAllocations> allocs =
456 intentAllocMap.values().stream().map(Versioned::value).collect(Collectors.toSet());
457 return ImmutableSet.copyOf(allocs);
458 } catch (Exception e) {
459 log.warn("Could not read resource allocation information", e);
460 }
461 return ImmutableSet.of();
462 }
463
464 private Iterable<LinkResourceAllocations> getAllocations(TransactionContext tx, Link link) {
465 checkNotNull(tx);
466 checkNotNull(link);
467 final LinkKey key = LinkKey.linkKey(link);
468 TransactionalMap<LinkKey, List<LinkResourceAllocations>> linkAllocs = getLinkAllocs(tx);
Ayaka Koshibee114f042015-05-01 11:43:00 -0700469
Sho SHIMIZU88d36e22015-10-02 14:23:46 -0700470 List<LinkResourceAllocations> res = linkAllocs.get(key);
471 if (res != null) {
472 return res;
Ayaka Koshibee114f042015-05-01 11:43:00 -0700473 }
Sho SHIMIZU88d36e22015-10-02 14:23:46 -0700474
475 res = linkAllocs.putIfAbsent(key, new ArrayList<>());
476 if (res == null) {
477 return Collections.emptyList();
478 } else {
479 return res;
480 }
Ayaka Koshibee114f042015-05-01 11:43:00 -0700481 }
482
483}