blob: 934dfead0f6c738994ce0301a31b1fdab7960e4e [file] [log] [blame]
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -07001/*
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -08002 * Copyright 2015-2016 Open Networking Laboratory
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -07003 *
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 */
16package org.onosproject.store.newresource.impl;
17
18import com.google.common.annotations.Beta;
Sho SHIMIZUe7db6142015-11-04 11:24:22 -080019import com.google.common.collect.ImmutableList;
Sho SHIMIZU83258ae2016-01-29 17:39:07 -080020import com.google.common.collect.ImmutableSet;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080021import com.google.common.collect.Maps;
Sho SHIMIZU67c90102016-02-23 10:49:58 -080022import com.google.common.collect.Sets;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070023import org.apache.felix.scr.annotations.Activate;
24import org.apache.felix.scr.annotations.Component;
25import org.apache.felix.scr.annotations.Reference;
26import org.apache.felix.scr.annotations.ReferenceCardinality;
27import org.apache.felix.scr.annotations.Service;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080028import org.onlab.util.GuavaCollectors;
Thomas Vachuska762a2d82016-01-04 10:25:20 -080029import org.onlab.util.Tools;
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080030import org.onosproject.net.newresource.ContinuousResource;
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -080031import org.onosproject.net.newresource.ContinuousResourceId;
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080032import org.onosproject.net.newresource.DiscreteResource;
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -080033import org.onosproject.net.newresource.DiscreteResourceId;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080034import org.onosproject.net.newresource.ResourceAllocation;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070035import org.onosproject.net.newresource.ResourceConsumer;
Sho SHIMIZUfa62b472015-11-02 17:35:46 -080036import org.onosproject.net.newresource.ResourceEvent;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080037import org.onosproject.net.newresource.ResourceId;
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -080038import org.onosproject.net.newresource.Resource;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070039import org.onosproject.net.newresource.ResourceStore;
Sho SHIMIZUfa62b472015-11-02 17:35:46 -080040import org.onosproject.net.newresource.ResourceStoreDelegate;
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -080041import org.onosproject.net.newresource.Resources;
Sho SHIMIZUfa62b472015-11-02 17:35:46 -080042import org.onosproject.store.AbstractStore;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070043import org.onosproject.store.serializers.KryoNamespaces;
44import org.onosproject.store.service.ConsistentMap;
Thomas Vachuska762a2d82016-01-04 10:25:20 -080045import org.onosproject.store.service.ConsistentMapException;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070046import org.onosproject.store.service.Serializer;
47import org.onosproject.store.service.StorageService;
48import org.onosproject.store.service.TransactionContext;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070049import org.onosproject.store.service.TransactionalMap;
50import org.onosproject.store.service.Versioned;
51import org.slf4j.Logger;
52import org.slf4j.LoggerFactory;
53
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070054import java.util.Arrays;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070055import java.util.Collection;
Sho SHIMIZU69420fe2016-02-09 15:01:07 -080056import java.util.LinkedHashMap;
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070057import java.util.LinkedHashSet;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070058import java.util.List;
59import java.util.Map;
60import java.util.Optional;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080061import java.util.Set;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070062import java.util.stream.Collectors;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080063import java.util.stream.Stream;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070064
65import static com.google.common.base.Preconditions.checkArgument;
66import static com.google.common.base.Preconditions.checkNotNull;
Sho SHIMIZUfa62b472015-11-02 17:35:46 -080067import static org.onosproject.net.newresource.ResourceEvent.Type.*;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070068
69/**
70 * Implementation of ResourceStore using TransactionalMap.
71 */
Sho SHIMIZU9a2b8292015-10-28 13:00:16 -070072@Component(immediate = true)
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070073@Service
74@Beta
Sho SHIMIZUfa62b472015-11-02 17:35:46 -080075public class ConsistentResourceStore extends AbstractStore<ResourceEvent, ResourceStoreDelegate>
76 implements ResourceStore {
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070077 private static final Logger log = LoggerFactory.getLogger(ConsistentResourceStore.class);
78
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080079 private static final String DISCRETE_CONSUMER_MAP = "onos-discrete-consumers";
80 private static final String CONTINUOUS_CONSUMER_MAP = "onos-continuous-consumers";
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070081 private static final String CHILD_MAP = "onos-resource-children";
82 private static final Serializer SERIALIZER = Serializer.using(
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080083 Arrays.asList(KryoNamespaces.BASIC, KryoNamespaces.API),
84 ContinuousResourceAllocation.class);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070085
Thomas Vachuska762a2d82016-01-04 10:25:20 -080086 // TODO: We should provide centralized values for this
87 private static final int MAX_RETRIES = 5;
88 private static final int RETRY_DELAY = 1_000; // millis
89
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070090 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
91 protected StorageService service;
92
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -080093 private ConsistentMap<DiscreteResourceId, ResourceConsumer> discreteConsumers;
94 private ConsistentMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumers;
95 private ConsistentMap<DiscreteResourceId, Set<Resource>> childMap;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070096
97 @Activate
98 public void activate() {
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -080099 discreteConsumers = service.<DiscreteResourceId, ResourceConsumer>consistentMapBuilder()
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800100 .withName(DISCRETE_CONSUMER_MAP)
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700101 .withSerializer(SERIALIZER)
102 .build();
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800103 continuousConsumers = service.<ContinuousResourceId, ContinuousResourceAllocation>consistentMapBuilder()
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800104 .withName(CONTINUOUS_CONSUMER_MAP)
105 .withSerializer(SERIALIZER)
106 .build();
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800107 childMap = service.<DiscreteResourceId, Set<Resource>>consistentMapBuilder()
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700108 .withName(CHILD_MAP)
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700109 .withSerializer(SERIALIZER)
110 .build();
Sho SHIMIZUe7db6142015-11-04 11:24:22 -0800111
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800112 Tools.retryable(() -> childMap.put(Resource.ROOT.id(), new LinkedHashSet<>()),
Thomas Vachuska762a2d82016-01-04 10:25:20 -0800113 ConsistentMapException.class, MAX_RETRIES, RETRY_DELAY);
Madan Jampanic7f49f92015-12-10 11:35:06 -0800114 log.info("Started");
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700115 }
116
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800117 // Computational complexity: O(1) if the resource is discrete type.
118 // O(n) if the resource is continuous type where n is the number of the existing allocations for the resource
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700119 @Override
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800120 public List<ResourceAllocation> getResourceAllocations(ResourceId id) {
121 checkNotNull(id);
122 checkArgument(id instanceof DiscreteResourceId || id instanceof ContinuousResourceId);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700123
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800124 if (id instanceof DiscreteResourceId) {
125 return getResourceAllocations((DiscreteResourceId) id);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800126 } else {
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800127 return getResourceAllocations((ContinuousResourceId) id);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800128 }
129 }
130
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800131 // computational complexity: O(1)
132 private List<ResourceAllocation> getResourceAllocations(DiscreteResourceId resource) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800133 Versioned<ResourceConsumer> consumer = discreteConsumers.get(resource);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700134 if (consumer == null) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800135 return ImmutableList.of();
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700136 }
137
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800138 return ImmutableList.of(new ResourceAllocation(Resources.discrete(resource).resource(), consumer.value()));
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800139 }
140
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800141 // computational complexity: O(n) where n is the number of the existing allocations for the resource
142 private List<ResourceAllocation> getResourceAllocations(ContinuousResourceId resource) {
143 Versioned<ContinuousResourceAllocation> allocations = continuousConsumers.get(resource);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800144 if (allocations == null) {
145 return ImmutableList.of();
146 }
147
148 return allocations.value().allocations().stream()
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800149 .filter(x -> x.resource().id().equals(resource))
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800150 .collect(GuavaCollectors.toImmutableList());
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700151 }
152
153 @Override
Jonathan Hart56151262016-02-11 09:48:50 -0800154 public boolean register(List<Resource> resources) {
Sho SHIMIZU83e17a02015-08-20 14:07:05 -0700155 checkNotNull(resources);
HIGUCHI Yuta6f828c32016-01-20 18:11:05 -0800156 if (log.isTraceEnabled()) {
157 resources.forEach(r -> log.trace("registering {}", r));
158 }
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700159
160 TransactionContext tx = service.transactionContextBuilder().build();
161 tx.begin();
162
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800163 TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap =
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800164 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700165
Sho SHIMIZU69420fe2016-02-09 15:01:07 -0800166 // the order is preserved by LinkedHashMap
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800167 Map<DiscreteResource, List<Resource>> resourceMap = resources.stream()
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800168 .filter(x -> x.parent().isPresent())
Sho SHIMIZU69420fe2016-02-09 15:01:07 -0800169 .collect(Collectors.groupingBy(x -> x.parent().get(), LinkedHashMap::new, Collectors.toList()));
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700170
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800171 for (Map.Entry<DiscreteResource, List<Resource>> entry: resourceMap.entrySet()) {
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800172 if (!lookup(childTxMap, entry.getKey().id()).isPresent()) {
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800173 return abortTransaction(tx);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700174 }
175
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800176 if (!appendValues(childTxMap, entry.getKey().id(), entry.getValue())) {
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800177 return abortTransaction(tx);
178 }
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700179 }
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800180
Sho SHIMIZUfa62b472015-11-02 17:35:46 -0800181 boolean success = tx.commit();
182 if (success) {
183 List<ResourceEvent> events = resources.stream()
184 .filter(x -> x.parent().isPresent())
185 .map(x -> new ResourceEvent(RESOURCE_ADDED, x))
186 .collect(Collectors.toList());
187 notifyDelegate(events);
188 }
189 return success;
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700190 }
191
192 @Override
Jonathan Hart56151262016-02-11 09:48:50 -0800193 public boolean unregister(List<ResourceId> ids) {
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800194 checkNotNull(ids);
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700195
196 TransactionContext tx = service.transactionContextBuilder().build();
197 tx.begin();
198
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800199 TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap =
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800200 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800201 TransactionalMap<DiscreteResourceId, ResourceConsumer> discreteConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800202 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800203 TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800204 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700205
Sho SHIMIZU7d54d9c2016-02-17 13:58:46 -0800206 // Look up resources by resource IDs
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800207 List<Resource> resources = ids.stream()
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800208 .filter(x -> x.parent().isPresent())
Sho SHIMIZU7d54d9c2016-02-17 13:58:46 -0800209 .map(x -> {
210 // avoid access to consistent map in the case of discrete resource
211 if (x instanceof DiscreteResourceId) {
212 return Optional.of(Resources.discrete((DiscreteResourceId) x).resource());
213 } else {
214 return lookup(childTxMap, x);
215 }
216 })
HIGUCHI Yuta315179a2016-02-18 14:01:22 -0800217 .filter(Optional::isPresent)
218 .map(Optional::get)
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800219 .collect(Collectors.toList());
Sho SHIMIZU69420fe2016-02-09 15:01:07 -0800220 // the order is preserved by LinkedHashMap
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800221 Map<DiscreteResourceId, List<Resource>> resourceMap = resources.stream()
Sho SHIMIZU69420fe2016-02-09 15:01:07 -0800222 .collect(Collectors.groupingBy(x -> x.parent().get().id(), LinkedHashMap::new, Collectors.toList()));
Sho SHIMIZU83e17a02015-08-20 14:07:05 -0700223
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800224 // even if one of the resources is allocated to a consumer,
225 // all unregistrations are regarded as failure
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800226 for (Map.Entry<DiscreteResourceId, List<Resource>> entry: resourceMap.entrySet()) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800227 boolean allocated = entry.getValue().stream().anyMatch(x -> {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800228 if (x instanceof DiscreteResource) {
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800229 return discreteConsumerTxMap.get(((DiscreteResource) x).id()) != null;
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800230 } else if (x instanceof ContinuousResource) {
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800231 ContinuousResourceAllocation allocations =
232 continuousConsumerTxMap.get(((ContinuousResource) x).id());
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800233 return allocations != null && !allocations.allocations().isEmpty();
234 } else {
235 return false;
236 }
237 });
238 if (allocated) {
HIGUCHI Yuta5b6dfba2016-01-27 14:43:41 -0800239 log.warn("Failed to unregister {}: allocation exists", entry.getKey());
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800240 return abortTransaction(tx);
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700241 }
242
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800243 if (!removeValues(childTxMap, entry.getKey(), entry.getValue())) {
HIGUCHI Yuta6acdfd02016-02-18 10:39:43 -0800244 log.warn("Failed to unregister {}: Failed to remove {} values.",
245 entry.getKey(), entry.getValue().size());
246 log.debug("Failed to unregister {}: Failed to remove values: {}",
HIGUCHI Yuta5b6dfba2016-01-27 14:43:41 -0800247 entry.getKey(), entry.getValue());
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800248 return abortTransaction(tx);
249 }
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700250 }
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800251
Sho SHIMIZUfa62b472015-11-02 17:35:46 -0800252 boolean success = tx.commit();
253 if (success) {
254 List<ResourceEvent> events = resources.stream()
255 .filter(x -> x.parent().isPresent())
256 .map(x -> new ResourceEvent(RESOURCE_REMOVED, x))
257 .collect(Collectors.toList());
258 notifyDelegate(events);
HIGUCHI Yuta5b6dfba2016-01-27 14:43:41 -0800259 } else {
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800260 log.warn("Failed to unregister {}: Commit failed.", ids);
Sho SHIMIZUfa62b472015-11-02 17:35:46 -0800261 }
262 return success;
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700263 }
264
265 @Override
Jonathan Hart56151262016-02-11 09:48:50 -0800266 public boolean allocate(List<Resource> resources, ResourceConsumer consumer) {
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700267 checkNotNull(resources);
268 checkNotNull(consumer);
269
270 TransactionContext tx = service.transactionContextBuilder().build();
271 tx.begin();
272
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800273 TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap =
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800274 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800275 TransactionalMap<DiscreteResourceId, ResourceConsumer> discreteConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800276 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800277 TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800278 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700279
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800280 for (Resource resource: resources) {
Sho SHIMIZU171a9382016-02-15 13:56:34 -0800281 // if the resource is not registered, then abort
282 Optional<Resource> lookedUp = lookup(childTxMap, resource.id());
283 if (!lookedUp.isPresent()) {
284 return abortTransaction(tx);
285 }
Sho SHIMIZUd29847f2015-08-13 09:10:59 -0700286
Sho SHIMIZU171a9382016-02-15 13:56:34 -0800287 if (resource instanceof DiscreteResource) {
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800288 ResourceConsumer oldValue = discreteConsumerTxMap.put(((DiscreteResource) resource).id(), consumer);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800289 if (oldValue != null) {
290 return abortTransaction(tx);
291 }
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800292 } else if (resource instanceof ContinuousResource) {
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800293 // Down cast: this must be safe as ContinuousResource is associated with ContinuousResourceId
294 ContinuousResource continuous = (ContinuousResource) lookedUp.get();
295 ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(continuous.id());
296 if (!hasEnoughResource(continuous, (ContinuousResource) resource, allocations)) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800297 return abortTransaction(tx);
298 }
299
300 boolean success = appendValue(continuousConsumerTxMap,
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800301 continuous, new ResourceAllocation(continuous, consumer));
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800302 if (!success) {
303 return abortTransaction(tx);
304 }
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800305 }
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700306 }
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800307
308 return tx.commit();
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700309 }
310
311 @Override
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -0800312 public boolean release(List<ResourceAllocation> allocations) {
313 checkNotNull(allocations);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700314
315 TransactionContext tx = service.transactionContextBuilder().build();
316 tx.begin();
317
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800318 TransactionalMap<DiscreteResourceId, ResourceConsumer> discreteConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800319 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800320 TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800321 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700322
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -0800323 for (ResourceAllocation allocation : allocations) {
324 Resource resource = allocation.resource();
325 ResourceConsumer consumer = allocation.consumer();
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700326
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800327 if (resource instanceof DiscreteResource) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800328 // if this single release fails (because the resource is allocated to another consumer,
329 // the whole release fails
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800330 if (!discreteConsumerTxMap.remove(((DiscreteResource) resource).id(), consumer)) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800331 return abortTransaction(tx);
332 }
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800333 } else if (resource instanceof ContinuousResource) {
334 ContinuousResource continuous = (ContinuousResource) resource;
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -0800335 ContinuousResourceAllocation continuousAllocation = continuousConsumerTxMap.get(continuous.id());
336 ImmutableList<ResourceAllocation> newAllocations = continuousAllocation.allocations().stream()
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800337 .filter(x -> !(x.consumer().equals(consumer) &&
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800338 ((ContinuousResource) x.resource()).value() == continuous.value()))
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800339 .collect(GuavaCollectors.toImmutableList());
340
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -0800341 if (!continuousConsumerTxMap.replace(continuous.id(), continuousAllocation,
342 new ContinuousResourceAllocation(continuousAllocation.original(), newAllocations))) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800343 return abortTransaction(tx);
344 }
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700345 }
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700346 }
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800347
348 return tx.commit();
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700349 }
350
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800351 // computational complexity: O(1) if the resource is discrete type.
352 // O(n) if the resource is continuous type where n is the number of the children of
353 // the specified resource's parent
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700354 @Override
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800355 public boolean isAvailable(Resource resource) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800356 checkNotNull(resource);
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800357 checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800358
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800359 if (resource instanceof DiscreteResource) {
HIGUCHI Yuta6f828c32016-01-20 18:11:05 -0800360 // check if already consumed
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800361 return getResourceAllocations(resource.id()).isEmpty();
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800362 } else {
Sho SHIMIZUf17ae282016-02-10 23:44:30 -0800363 return isAvailable((ContinuousResource) resource);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800364 }
365 }
366
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800367 // computational complexity: O(n) where n is the number of existing allocations for the resource
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800368 private boolean isAvailable(ContinuousResource resource) {
Sho SHIMIZUf17ae282016-02-10 23:44:30 -0800369 // check if it's registered or not.
370 Versioned<Set<Resource>> children = childMap.get(resource.parent().get().id());
371 if (children == null) {
372 return false;
373 }
374
375 ContinuousResource registered = children.value().stream()
376 .filter(c -> c.id().equals(resource.id()))
377 .findFirst()
378 .map(c -> (ContinuousResource) c)
379 .get();
380 if (registered.value() < resource.value()) {
381 // Capacity < requested, can never satisfy
382 return false;
383 }
384
385 // check if there's enough left
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800386 Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id());
387 if (allocation == null) {
HIGUCHI Yuta6f828c32016-01-20 18:11:05 -0800388 // no allocation (=no consumer) full registered resources available
389 return true;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800390 }
391
392 return hasEnoughResource(allocation.value().original(), resource, allocation.value());
393 }
394
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800395 // computational complexity: O(n + m) where n is the number of entries in discreteConsumers
396 // and m is the number of allocations for all continuous resources
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800397 @Override
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800398 public Collection<Resource> getResources(ResourceConsumer consumer) {
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700399 checkNotNull(consumer);
400
401 // NOTE: getting all entries may become performance bottleneck
402 // TODO: revisit for better backend data structure
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800403 Stream<DiscreteResource> discreteStream = discreteConsumers.entrySet().stream()
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700404 .filter(x -> x.getValue().value().equals(consumer))
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800405 .map(Map.Entry::getKey)
406 .map(x -> Resources.discrete(x).resource());
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800407
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800408 Stream<ContinuousResource> continuousStream = continuousConsumers.values().stream()
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800409 .flatMap(x -> x.value().allocations().stream()
410 .map(y -> Maps.immutableEntry(x.value().original(), y)))
411 .filter(x -> x.getValue().consumer().equals(consumer))
412 .map(x -> x.getKey());
413
414 return Stream.concat(discreteStream, continuousStream).collect(Collectors.toList());
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700415 }
416
Sho SHIMIZU82bfe992016-02-10 09:55:32 -0800417 // computational complexity: O(1)
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700418 @Override
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800419 public Set<Resource> getChildResources(DiscreteResourceId parent) {
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700420 checkNotNull(parent);
421
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800422 Versioned<Set<Resource>> children = childMap.get(parent);
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700423 if (children == null) {
Sho SHIMIZU83258ae2016-01-29 17:39:07 -0800424 return ImmutableSet.of();
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700425 }
426
427 return children.value();
428 }
429
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800430 // computational complexity: O(n) where n is the number of the children of the parent
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700431 @Override
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800432 public <T> Collection<Resource> getAllocatedResources(DiscreteResourceId parent, Class<T> cls) {
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700433 checkNotNull(parent);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700434 checkNotNull(cls);
435
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800436 Versioned<Set<Resource>> children = childMap.get(parent);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700437 if (children == null) {
Sho SHIMIZU2c0ae122016-01-20 13:14:38 -0800438 return ImmutableList.of();
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700439 }
440
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800441 Stream<DiscreteResource> discrete = children.value().stream()
Sho SHIMIZU003ed322016-02-11 12:58:42 -0800442 .filter(x -> x.isTypeOf(cls))
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800443 .filter(x -> x instanceof DiscreteResource)
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800444 .map(x -> ((DiscreteResource) x))
445 .filter(x -> discreteConsumers.containsKey(x.id()));
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800446
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800447 Stream<ContinuousResource> continuous = children.value().stream()
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800448 .filter(x -> x.id().equals(parent.child(cls)))
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800449 .filter(x -> x instanceof ContinuousResource)
450 .map(x -> (ContinuousResource) x)
Sho SHIMIZU90039242016-02-11 09:45:32 -0800451 // we don't use cascading simple predicates like follows to reduce accesses to consistent map
452 // .filter(x -> continuousConsumers.containsKey(x.id()))
453 // .filter(x -> continuousConsumers.get(x.id()) != null)
454 // .filter(x -> !continuousConsumers.get(x.id()).value().allocations().isEmpty());
455 .filter(resource -> {
456 Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id());
457 if (allocation == null) {
458 return false;
459 }
460 return !allocation.value().allocations().isEmpty();
461 });
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800462
463 return Stream.concat(discrete, continuous).collect(Collectors.toList());
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700464 }
Sho SHIMIZUd29847f2015-08-13 09:10:59 -0700465
466 /**
467 * Abort the transaction.
468 *
469 * @param tx transaction context
470 * @return always false
471 */
472 private boolean abortTransaction(TransactionContext tx) {
473 tx.abort();
474 return false;
475 }
476
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800477 // Appends the specified ResourceAllocation to the existing values stored in the map
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800478 // computational complexity: O(n) where n is the number of the elements in the associated allocation
479 private boolean appendValue(TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> map,
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800480 ContinuousResource original, ResourceAllocation value) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800481 ContinuousResourceAllocation oldValue = map.putIfAbsent(original.id(),
482 new ContinuousResourceAllocation(original, ImmutableList.of(value)));
483 if (oldValue == null) {
484 return true;
485 }
486
487 if (oldValue.allocations().contains(value)) {
488 // don't write to map because all values are already stored
489 return true;
490 }
491
492 ContinuousResourceAllocation newValue = new ContinuousResourceAllocation(original,
493 ImmutableList.<ResourceAllocation>builder()
494 .addAll(oldValue.allocations())
495 .add(value)
496 .build());
497 return map.replace(original.id(), oldValue, newValue);
498 }
Sho SHIMIZUd29847f2015-08-13 09:10:59 -0700499 /**
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700500 * Appends the values to the existing values associated with the specified key.
Sho SHIMIZU4568c412015-08-21 16:39:07 -0700501 * If the map already has all the given values, appending will not happen.
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700502 *
503 * @param map map holding multiple values for a key
504 * @param key key specifying values
505 * @param values values to be appended
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700506 * @return true if the operation succeeds, false otherwise.
507 */
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800508 // computational complexity: O(n) where n is the number of the specified value
509 private boolean appendValues(TransactionalMap<DiscreteResourceId, Set<Resource>> map,
510 DiscreteResourceId key, List<Resource> values) {
Sho SHIMIZU67c90102016-02-23 10:49:58 -0800511 Set<Resource> requested = new LinkedHashSet<>(values);
512 Set<Resource> oldValues = map.putIfAbsent(key, requested);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700513 if (oldValues == null) {
Sho SHIMIZU93a74b32015-11-09 11:48:23 -0800514 return true;
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700515 }
516
Sho SHIMIZU67c90102016-02-23 10:49:58 -0800517 Set<Resource> addedValues = Sets.difference(requested, oldValues);
518 // no new value, then no-op
Sho SHIMIZU1992daf2016-02-17 17:38:55 -0800519 if (addedValues.isEmpty()) {
Sho SHIMIZU4568c412015-08-21 16:39:07 -0700520 // don't write to map because all values are already stored
521 return true;
522 }
523
Sho SHIMIZU67c90102016-02-23 10:49:58 -0800524 Set<ResourceId> addedIds = addedValues.stream()
525 .map(Resource::id)
526 .collect(Collectors.toSet());
527 // if the value is not found but the same ID is found
528 // (this happens only when being continuous resource)
529 if (oldValues.stream().anyMatch(x -> addedIds.contains(x.id()))) {
530 // no-op, but indicating failure (reject the request)
531 return false;
532 }
533 Set<Resource> newValues = new LinkedHashSet<>(oldValues);
Sho SHIMIZU1992daf2016-02-17 17:38:55 -0800534 newValues.addAll(addedValues);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800535 return map.replace(key, oldValues, newValues);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700536 }
537
538 /**
Sho SHIMIZUba1f83b2015-10-14 08:11:20 -0700539 * Removes the values from the existing values associated with the specified key.
Sho SHIMIZU5618ee52015-08-21 17:19:44 -0700540 * If the map doesn't contain the given values, removal will not happen.
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700541 *
542 * @param map map holding multiple values for a key
543 * @param key key specifying values
544 * @param values values to be removed
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700545 * @return true if the operation succeeds, false otherwise
546 */
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800547 // computational complexity: O(n) where n is the number of the specified values
548 private boolean removeValues(TransactionalMap<DiscreteResourceId, Set<Resource>> map,
549 DiscreteResourceId key, List<Resource> values) {
Sho SHIMIZU07b7bc92016-01-29 18:27:58 -0800550 Set<Resource> oldValues = map.putIfAbsent(key, new LinkedHashSet<>());
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700551 if (oldValues == null) {
HIGUCHI Yutadc4394c2016-01-29 15:35:10 -0800552 log.trace("No-Op removing values. key {} did not exist", key);
Sho SHIMIZU93a74b32015-11-09 11:48:23 -0800553 return true;
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700554 }
555
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800556 if (values.stream().allMatch(x -> !oldValues.contains(x))) {
Sho SHIMIZU5618ee52015-08-21 17:19:44 -0700557 // don't write map because none of the values are stored
HIGUCHI Yutadc4394c2016-01-29 15:35:10 -0800558 log.trace("No-Op removing values. key {} did not contain {}", key, values);
Sho SHIMIZU5618ee52015-08-21 17:19:44 -0700559 return true;
560 }
561
Sho SHIMIZU07b7bc92016-01-29 18:27:58 -0800562 LinkedHashSet<Resource> newValues = new LinkedHashSet<>(oldValues);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800563 newValues.removeAll(values);
564 return map.replace(key, oldValues, newValues);
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700565 }
566
567 /**
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800568 * Returns the resource which has the same key as the specified resource ID
569 * in the set as a value of the map.
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700570 *
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800571 * @param childTxMap map storing parent - child relationship of resources
572 * @param id ID of resource to be checked
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800573 * @return the resource which is regarded as the same as the specified resource
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700574 */
Sho SHIMIZUa6a6fd32016-02-10 18:36:44 -0800575 // Naive implementation, which traverses all elements in the set when continuous resource
576 // computational complexity: O(1) when discrete resource. O(n) when continuous resource
577 // where n is the number of elements in the associated set
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800578 private Optional<Resource> lookup(TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap, ResourceId id) {
579 if (!id.parent().isPresent()) {
580 return Optional.of(Resource.ROOT);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700581 }
582
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800583 Set<Resource> values = childTxMap.get(id.parent().get());
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800584 if (values == null) {
585 return Optional.empty();
586 }
587
Sho SHIMIZUa6a6fd32016-02-10 18:36:44 -0800588 // short-circuit if discrete resource
589 // check the existence in the set: O(1) operation
590 if (id instanceof DiscreteResourceId) {
591 DiscreteResource discrete = Resources.discrete((DiscreteResourceId) id).resource();
592 if (values.contains(discrete)) {
593 return Optional.of(discrete);
594 } else {
595 return Optional.empty();
596 }
597 }
598
599 // continuous resource case
600 // iterate over the values in the set: O(n) operation
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800601 return values.stream()
602 .filter(x -> x.id().equals(id))
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800603 .findFirst();
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800604 }
605
606 /**
607 * Checks if there is enough resource volume to allocated the requested resource
608 * against the specified resource.
609 *
610 * @param original original resource
611 * @param request requested resource
612 * @param allocation current allocation of the resource
613 * @return true if there is enough resource volume. Otherwise, false.
614 */
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800615 // computational complexity: O(n) where n is the number of allocations
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800616 private boolean hasEnoughResource(ContinuousResource original,
617 ContinuousResource request,
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800618 ContinuousResourceAllocation allocation) {
619 if (allocation == null) {
620 return request.value() <= original.value();
621 }
622
623 double allocated = allocation.allocations().stream()
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800624 .filter(x -> x.resource() instanceof ContinuousResource)
625 .map(x -> (ContinuousResource) x.resource())
626 .mapToDouble(ContinuousResource::value)
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800627 .sum();
628 double left = original.value() - allocated;
629 return request.value() <= left;
630 }
631
632 // internal use only
633 private static final class ContinuousResourceAllocation {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800634 private final ContinuousResource original;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800635 private final ImmutableList<ResourceAllocation> allocations;
636
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800637 private ContinuousResourceAllocation(ContinuousResource original,
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800638 ImmutableList<ResourceAllocation> allocations) {
639 this.original = original;
640 this.allocations = allocations;
641 }
642
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800643 private ContinuousResource original() {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800644 return original;
645 }
646
647 private ImmutableList<ResourceAllocation> allocations() {
648 return allocations;
649 }
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700650 }
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700651}