blob: 30d534d4310f94968e79b2d6e70c7502caa28d1b [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) {
Sho SHIMIZU25938a52016-02-24 11:25:07 -0800183 log.trace("Transaction commit succeeded on registration: resources={}", resources);
Sho SHIMIZUfa62b472015-11-02 17:35:46 -0800184 List<ResourceEvent> events = resources.stream()
185 .filter(x -> x.parent().isPresent())
186 .map(x -> new ResourceEvent(RESOURCE_ADDED, x))
187 .collect(Collectors.toList());
188 notifyDelegate(events);
Sho SHIMIZU25938a52016-02-24 11:25:07 -0800189 } else {
190 log.debug("Transaction commit failed on registration: resources={}", resources);
Sho SHIMIZUfa62b472015-11-02 17:35:46 -0800191 }
192 return success;
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700193 }
194
195 @Override
Jonathan Hart56151262016-02-11 09:48:50 -0800196 public boolean unregister(List<ResourceId> ids) {
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800197 checkNotNull(ids);
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700198
199 TransactionContext tx = service.transactionContextBuilder().build();
200 tx.begin();
201
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800202 TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap =
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800203 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800204 TransactionalMap<DiscreteResourceId, ResourceConsumer> discreteConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800205 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800206 TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800207 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700208
Sho SHIMIZU7d54d9c2016-02-17 13:58:46 -0800209 // Look up resources by resource IDs
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800210 List<Resource> resources = ids.stream()
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800211 .filter(x -> x.parent().isPresent())
Sho SHIMIZU7d54d9c2016-02-17 13:58:46 -0800212 .map(x -> {
213 // avoid access to consistent map in the case of discrete resource
214 if (x instanceof DiscreteResourceId) {
215 return Optional.of(Resources.discrete((DiscreteResourceId) x).resource());
216 } else {
217 return lookup(childTxMap, x);
218 }
219 })
HIGUCHI Yuta315179a2016-02-18 14:01:22 -0800220 .filter(Optional::isPresent)
221 .map(Optional::get)
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800222 .collect(Collectors.toList());
Sho SHIMIZU69420fe2016-02-09 15:01:07 -0800223 // the order is preserved by LinkedHashMap
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800224 Map<DiscreteResourceId, List<Resource>> resourceMap = resources.stream()
Sho SHIMIZU69420fe2016-02-09 15:01:07 -0800225 .collect(Collectors.groupingBy(x -> x.parent().get().id(), LinkedHashMap::new, Collectors.toList()));
Sho SHIMIZU83e17a02015-08-20 14:07:05 -0700226
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800227 // even if one of the resources is allocated to a consumer,
228 // all unregistrations are regarded as failure
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800229 for (Map.Entry<DiscreteResourceId, List<Resource>> entry: resourceMap.entrySet()) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800230 boolean allocated = entry.getValue().stream().anyMatch(x -> {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800231 if (x instanceof DiscreteResource) {
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800232 return discreteConsumerTxMap.get(((DiscreteResource) x).id()) != null;
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800233 } else if (x instanceof ContinuousResource) {
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800234 ContinuousResourceAllocation allocations =
235 continuousConsumerTxMap.get(((ContinuousResource) x).id());
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800236 return allocations != null && !allocations.allocations().isEmpty();
237 } else {
238 return false;
239 }
240 });
241 if (allocated) {
HIGUCHI Yuta5b6dfba2016-01-27 14:43:41 -0800242 log.warn("Failed to unregister {}: allocation exists", entry.getKey());
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800243 return abortTransaction(tx);
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700244 }
245
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800246 if (!removeValues(childTxMap, entry.getKey(), entry.getValue())) {
HIGUCHI Yuta6acdfd02016-02-18 10:39:43 -0800247 log.warn("Failed to unregister {}: Failed to remove {} values.",
248 entry.getKey(), entry.getValue().size());
249 log.debug("Failed to unregister {}: Failed to remove values: {}",
HIGUCHI Yuta5b6dfba2016-01-27 14:43:41 -0800250 entry.getKey(), entry.getValue());
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800251 return abortTransaction(tx);
252 }
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700253 }
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800254
Sho SHIMIZUfa62b472015-11-02 17:35:46 -0800255 boolean success = tx.commit();
256 if (success) {
257 List<ResourceEvent> events = resources.stream()
258 .filter(x -> x.parent().isPresent())
259 .map(x -> new ResourceEvent(RESOURCE_REMOVED, x))
260 .collect(Collectors.toList());
261 notifyDelegate(events);
HIGUCHI Yuta5b6dfba2016-01-27 14:43:41 -0800262 } else {
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800263 log.warn("Failed to unregister {}: Commit failed.", ids);
Sho SHIMIZUfa62b472015-11-02 17:35:46 -0800264 }
265 return success;
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700266 }
267
268 @Override
Jonathan Hart56151262016-02-11 09:48:50 -0800269 public boolean allocate(List<Resource> resources, ResourceConsumer consumer) {
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700270 checkNotNull(resources);
271 checkNotNull(consumer);
272
273 TransactionContext tx = service.transactionContextBuilder().build();
274 tx.begin();
275
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800276 TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap =
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800277 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800278 TransactionalMap<DiscreteResourceId, ResourceConsumer> discreteConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800279 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800280 TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800281 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700282
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800283 for (Resource resource: resources) {
Sho SHIMIZU171a9382016-02-15 13:56:34 -0800284 // if the resource is not registered, then abort
285 Optional<Resource> lookedUp = lookup(childTxMap, resource.id());
286 if (!lookedUp.isPresent()) {
287 return abortTransaction(tx);
288 }
Sho SHIMIZUd29847f2015-08-13 09:10:59 -0700289
Sho SHIMIZU171a9382016-02-15 13:56:34 -0800290 if (resource instanceof DiscreteResource) {
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800291 ResourceConsumer oldValue = discreteConsumerTxMap.put(((DiscreteResource) resource).id(), consumer);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800292 if (oldValue != null) {
293 return abortTransaction(tx);
294 }
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800295 } else if (resource instanceof ContinuousResource) {
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800296 // Down cast: this must be safe as ContinuousResource is associated with ContinuousResourceId
297 ContinuousResource continuous = (ContinuousResource) lookedUp.get();
298 ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(continuous.id());
299 if (!hasEnoughResource(continuous, (ContinuousResource) resource, allocations)) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800300 return abortTransaction(tx);
301 }
302
303 boolean success = appendValue(continuousConsumerTxMap,
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800304 continuous, new ResourceAllocation(continuous, consumer));
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800305 if (!success) {
306 return abortTransaction(tx);
307 }
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800308 }
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700309 }
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800310
311 return tx.commit();
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700312 }
313
314 @Override
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -0800315 public boolean release(List<ResourceAllocation> allocations) {
316 checkNotNull(allocations);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700317
318 TransactionContext tx = service.transactionContextBuilder().build();
319 tx.begin();
320
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800321 TransactionalMap<DiscreteResourceId, ResourceConsumer> discreteConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800322 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800323 TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800324 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700325
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -0800326 for (ResourceAllocation allocation : allocations) {
327 Resource resource = allocation.resource();
328 ResourceConsumer consumer = allocation.consumer();
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700329
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800330 if (resource instanceof DiscreteResource) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800331 // if this single release fails (because the resource is allocated to another consumer,
332 // the whole release fails
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800333 if (!discreteConsumerTxMap.remove(((DiscreteResource) resource).id(), consumer)) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800334 return abortTransaction(tx);
335 }
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800336 } else if (resource instanceof ContinuousResource) {
337 ContinuousResource continuous = (ContinuousResource) resource;
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -0800338 ContinuousResourceAllocation continuousAllocation = continuousConsumerTxMap.get(continuous.id());
339 ImmutableList<ResourceAllocation> newAllocations = continuousAllocation.allocations().stream()
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800340 .filter(x -> !(x.consumer().equals(consumer) &&
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800341 ((ContinuousResource) x.resource()).value() == continuous.value()))
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800342 .collect(GuavaCollectors.toImmutableList());
343
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -0800344 if (!continuousConsumerTxMap.replace(continuous.id(), continuousAllocation,
345 new ContinuousResourceAllocation(continuousAllocation.original(), newAllocations))) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800346 return abortTransaction(tx);
347 }
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700348 }
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700349 }
Sho SHIMIZU1e0a34c2015-11-02 16:52:29 -0800350
351 return tx.commit();
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700352 }
353
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800354 // computational complexity: O(1) if the resource is discrete type.
355 // O(n) if the resource is continuous type where n is the number of the children of
356 // the specified resource's parent
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700357 @Override
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800358 public boolean isAvailable(Resource resource) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800359 checkNotNull(resource);
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800360 checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800361
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800362 if (resource instanceof DiscreteResource) {
HIGUCHI Yuta6f828c32016-01-20 18:11:05 -0800363 // check if already consumed
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800364 return getResourceAllocations(resource.id()).isEmpty();
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800365 } else {
Sho SHIMIZUf17ae282016-02-10 23:44:30 -0800366 return isAvailable((ContinuousResource) resource);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800367 }
368 }
369
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800370 // computational complexity: O(n) where n is the number of existing allocations for the resource
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800371 private boolean isAvailable(ContinuousResource resource) {
Sho SHIMIZUf17ae282016-02-10 23:44:30 -0800372 // check if it's registered or not.
373 Versioned<Set<Resource>> children = childMap.get(resource.parent().get().id());
374 if (children == null) {
375 return false;
376 }
377
378 ContinuousResource registered = children.value().stream()
379 .filter(c -> c.id().equals(resource.id()))
380 .findFirst()
381 .map(c -> (ContinuousResource) c)
382 .get();
383 if (registered.value() < resource.value()) {
384 // Capacity < requested, can never satisfy
385 return false;
386 }
387
388 // check if there's enough left
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800389 Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id());
390 if (allocation == null) {
HIGUCHI Yuta6f828c32016-01-20 18:11:05 -0800391 // no allocation (=no consumer) full registered resources available
392 return true;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800393 }
394
395 return hasEnoughResource(allocation.value().original(), resource, allocation.value());
396 }
397
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800398 // computational complexity: O(n + m) where n is the number of entries in discreteConsumers
399 // and m is the number of allocations for all continuous resources
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800400 @Override
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800401 public Collection<Resource> getResources(ResourceConsumer consumer) {
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700402 checkNotNull(consumer);
403
404 // NOTE: getting all entries may become performance bottleneck
405 // TODO: revisit for better backend data structure
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800406 Stream<DiscreteResource> discreteStream = discreteConsumers.entrySet().stream()
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700407 .filter(x -> x.getValue().value().equals(consumer))
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800408 .map(Map.Entry::getKey)
409 .map(x -> Resources.discrete(x).resource());
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800410
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800411 Stream<ContinuousResource> continuousStream = continuousConsumers.values().stream()
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800412 .flatMap(x -> x.value().allocations().stream()
413 .map(y -> Maps.immutableEntry(x.value().original(), y)))
414 .filter(x -> x.getValue().consumer().equals(consumer))
415 .map(x -> x.getKey());
416
417 return Stream.concat(discreteStream, continuousStream).collect(Collectors.toList());
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700418 }
419
Sho SHIMIZU82bfe992016-02-10 09:55:32 -0800420 // computational complexity: O(1)
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700421 @Override
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800422 public Set<Resource> getChildResources(DiscreteResourceId parent) {
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700423 checkNotNull(parent);
424
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800425 Versioned<Set<Resource>> children = childMap.get(parent);
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700426 if (children == null) {
Sho SHIMIZU83258ae2016-01-29 17:39:07 -0800427 return ImmutableSet.of();
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700428 }
429
430 return children.value();
431 }
432
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800433 // computational complexity: O(n) where n is the number of the children of the parent
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700434 @Override
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800435 public <T> Collection<Resource> getAllocatedResources(DiscreteResourceId parent, Class<T> cls) {
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700436 checkNotNull(parent);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700437 checkNotNull(cls);
438
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800439 Versioned<Set<Resource>> children = childMap.get(parent);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700440 if (children == null) {
Sho SHIMIZU2c0ae122016-01-20 13:14:38 -0800441 return ImmutableList.of();
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700442 }
443
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800444 Stream<DiscreteResource> discrete = children.value().stream()
Sho SHIMIZU003ed322016-02-11 12:58:42 -0800445 .filter(x -> x.isTypeOf(cls))
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800446 .filter(x -> x instanceof DiscreteResource)
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800447 .map(x -> ((DiscreteResource) x))
448 .filter(x -> discreteConsumers.containsKey(x.id()));
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800449
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800450 Stream<ContinuousResource> continuous = children.value().stream()
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800451 .filter(x -> x.id().equals(parent.child(cls)))
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800452 .filter(x -> x instanceof ContinuousResource)
453 .map(x -> (ContinuousResource) x)
Sho SHIMIZU90039242016-02-11 09:45:32 -0800454 // we don't use cascading simple predicates like follows to reduce accesses to consistent map
455 // .filter(x -> continuousConsumers.containsKey(x.id()))
456 // .filter(x -> continuousConsumers.get(x.id()) != null)
457 // .filter(x -> !continuousConsumers.get(x.id()).value().allocations().isEmpty());
458 .filter(resource -> {
459 Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id());
460 if (allocation == null) {
461 return false;
462 }
463 return !allocation.value().allocations().isEmpty();
464 });
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800465
466 return Stream.concat(discrete, continuous).collect(Collectors.toList());
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700467 }
Sho SHIMIZUd29847f2015-08-13 09:10:59 -0700468
469 /**
470 * Abort the transaction.
471 *
472 * @param tx transaction context
473 * @return always false
474 */
475 private boolean abortTransaction(TransactionContext tx) {
476 tx.abort();
477 return false;
478 }
479
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800480 // Appends the specified ResourceAllocation to the existing values stored in the map
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800481 // computational complexity: O(n) where n is the number of the elements in the associated allocation
482 private boolean appendValue(TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> map,
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800483 ContinuousResource original, ResourceAllocation value) {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800484 ContinuousResourceAllocation oldValue = map.putIfAbsent(original.id(),
485 new ContinuousResourceAllocation(original, ImmutableList.of(value)));
486 if (oldValue == null) {
487 return true;
488 }
489
490 if (oldValue.allocations().contains(value)) {
491 // don't write to map because all values are already stored
492 return true;
493 }
494
495 ContinuousResourceAllocation newValue = new ContinuousResourceAllocation(original,
496 ImmutableList.<ResourceAllocation>builder()
497 .addAll(oldValue.allocations())
498 .add(value)
499 .build());
500 return map.replace(original.id(), oldValue, newValue);
501 }
Sho SHIMIZUd29847f2015-08-13 09:10:59 -0700502 /**
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700503 * Appends the values to the existing values associated with the specified key.
Sho SHIMIZU4568c412015-08-21 16:39:07 -0700504 * If the map already has all the given values, appending will not happen.
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700505 *
506 * @param map map holding multiple values for a key
507 * @param key key specifying values
508 * @param values values to be appended
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700509 * @return true if the operation succeeds, false otherwise.
510 */
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800511 // computational complexity: O(n) where n is the number of the specified value
512 private boolean appendValues(TransactionalMap<DiscreteResourceId, Set<Resource>> map,
513 DiscreteResourceId key, List<Resource> values) {
Sho SHIMIZU67c90102016-02-23 10:49:58 -0800514 Set<Resource> requested = new LinkedHashSet<>(values);
515 Set<Resource> oldValues = map.putIfAbsent(key, requested);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700516 if (oldValues == null) {
Sho SHIMIZU93a74b32015-11-09 11:48:23 -0800517 return true;
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700518 }
519
Sho SHIMIZU67c90102016-02-23 10:49:58 -0800520 Set<Resource> addedValues = Sets.difference(requested, oldValues);
521 // no new value, then no-op
Sho SHIMIZU1992daf2016-02-17 17:38:55 -0800522 if (addedValues.isEmpty()) {
Sho SHIMIZU4568c412015-08-21 16:39:07 -0700523 // don't write to map because all values are already stored
524 return true;
525 }
526
Sho SHIMIZU67c90102016-02-23 10:49:58 -0800527 Set<ResourceId> addedIds = addedValues.stream()
528 .map(Resource::id)
529 .collect(Collectors.toSet());
530 // if the value is not found but the same ID is found
531 // (this happens only when being continuous resource)
532 if (oldValues.stream().anyMatch(x -> addedIds.contains(x.id()))) {
533 // no-op, but indicating failure (reject the request)
534 return false;
535 }
536 Set<Resource> newValues = new LinkedHashSet<>(oldValues);
Sho SHIMIZU1992daf2016-02-17 17:38:55 -0800537 newValues.addAll(addedValues);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800538 return map.replace(key, oldValues, newValues);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700539 }
540
541 /**
Sho SHIMIZUba1f83b2015-10-14 08:11:20 -0700542 * Removes the values from the existing values associated with the specified key.
Sho SHIMIZU5618ee52015-08-21 17:19:44 -0700543 * If the map doesn't contain the given values, removal will not happen.
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700544 *
545 * @param map map holding multiple values for a key
546 * @param key key specifying values
547 * @param values values to be removed
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700548 * @return true if the operation succeeds, false otherwise
549 */
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800550 // computational complexity: O(n) where n is the number of the specified values
551 private boolean removeValues(TransactionalMap<DiscreteResourceId, Set<Resource>> map,
552 DiscreteResourceId key, List<Resource> values) {
Sho SHIMIZU07b7bc92016-01-29 18:27:58 -0800553 Set<Resource> oldValues = map.putIfAbsent(key, new LinkedHashSet<>());
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700554 if (oldValues == null) {
HIGUCHI Yutadc4394c2016-01-29 15:35:10 -0800555 log.trace("No-Op removing values. key {} did not exist", key);
Sho SHIMIZU93a74b32015-11-09 11:48:23 -0800556 return true;
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700557 }
558
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800559 if (values.stream().allMatch(x -> !oldValues.contains(x))) {
Sho SHIMIZU5618ee52015-08-21 17:19:44 -0700560 // don't write map because none of the values are stored
HIGUCHI Yutadc4394c2016-01-29 15:35:10 -0800561 log.trace("No-Op removing values. key {} did not contain {}", key, values);
Sho SHIMIZU5618ee52015-08-21 17:19:44 -0700562 return true;
563 }
564
Sho SHIMIZU07b7bc92016-01-29 18:27:58 -0800565 LinkedHashSet<Resource> newValues = new LinkedHashSet<>(oldValues);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800566 newValues.removeAll(values);
567 return map.replace(key, oldValues, newValues);
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -0700568 }
569
570 /**
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800571 * Returns the resource which has the same key as the specified resource ID
572 * in the set as a value of the map.
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700573 *
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800574 * @param childTxMap map storing parent - child relationship of resources
575 * @param id ID of resource to be checked
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800576 * @return the resource which is regarded as the same as the specified resource
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700577 */
Sho SHIMIZUa6a6fd32016-02-10 18:36:44 -0800578 // Naive implementation, which traverses all elements in the set when continuous resource
579 // computational complexity: O(1) when discrete resource. O(n) when continuous resource
580 // where n is the number of elements in the associated set
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800581 private Optional<Resource> lookup(TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap, ResourceId id) {
582 if (!id.parent().isPresent()) {
583 return Optional.of(Resource.ROOT);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700584 }
585
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800586 Set<Resource> values = childTxMap.get(id.parent().get());
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800587 if (values == null) {
588 return Optional.empty();
589 }
590
Sho SHIMIZUa6a6fd32016-02-10 18:36:44 -0800591 // short-circuit if discrete resource
592 // check the existence in the set: O(1) operation
593 if (id instanceof DiscreteResourceId) {
594 DiscreteResource discrete = Resources.discrete((DiscreteResourceId) id).resource();
595 if (values.contains(discrete)) {
596 return Optional.of(discrete);
597 } else {
598 return Optional.empty();
599 }
600 }
601
602 // continuous resource case
603 // iterate over the values in the set: O(n) operation
Sho SHIMIZU72f81b12016-02-09 09:26:17 -0800604 return values.stream()
605 .filter(x -> x.id().equals(id))
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800606 .findFirst();
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800607 }
608
609 /**
610 * Checks if there is enough resource volume to allocated the requested resource
611 * against the specified resource.
612 *
613 * @param original original resource
614 * @param request requested resource
615 * @param allocation current allocation of the resource
616 * @return true if there is enough resource volume. Otherwise, false.
617 */
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800618 // computational complexity: O(n) where n is the number of allocations
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800619 private boolean hasEnoughResource(ContinuousResource original,
620 ContinuousResource request,
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800621 ContinuousResourceAllocation allocation) {
622 if (allocation == null) {
623 return request.value() <= original.value();
624 }
625
626 double allocated = allocation.allocations().stream()
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800627 .filter(x -> x.resource() instanceof ContinuousResource)
628 .map(x -> (ContinuousResource) x.resource())
629 .mapToDouble(ContinuousResource::value)
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800630 .sum();
631 double left = original.value() - allocated;
632 return request.value() <= left;
633 }
634
635 // internal use only
636 private static final class ContinuousResourceAllocation {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800637 private final ContinuousResource original;
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800638 private final ImmutableList<ResourceAllocation> allocations;
639
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800640 private ContinuousResourceAllocation(ContinuousResource original,
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800641 ImmutableList<ResourceAllocation> allocations) {
642 this.original = original;
643 this.allocations = allocations;
644 }
645
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800646 private ContinuousResource original() {
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -0800647 return original;
648 }
649
650 private ImmutableList<ResourceAllocation> allocations() {
651 return allocations;
652 }
Sho SHIMIZUba41fc12015-08-12 15:43:22 -0700653 }
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700654}