Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
Sho SHIMIZU | 6c9e33a | 2016-01-07 18:45:27 -0800 | [diff] [blame] | 2 | * Copyright 2015-2016 Open Networking Laboratory |
Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 16 | package org.onosproject.net.resource; |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.annotations.Beta; |
Sho SHIMIZU | fa62b47 | 2015-11-02 17:35:46 -0800 | [diff] [blame] | 19 | import org.onosproject.store.Store; |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 20 | |
| 21 | import java.util.Collection; |
| 22 | import java.util.List; |
Sho SHIMIZU | 83258ae | 2016-01-29 17:39:07 -0800 | [diff] [blame] | 23 | import java.util.Set; |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Service for storing resource and consumer information. |
| 27 | */ |
| 28 | @Beta |
Sho SHIMIZU | fa62b47 | 2015-11-02 17:35:46 -0800 | [diff] [blame] | 29 | public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegate> { |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 32 | * Registers the resources in transactional way. |
Sho SHIMIZU | ad619f5 | 2015-08-24 10:45:40 -0700 | [diff] [blame] | 33 | * Resource registration must be done before resource allocation. The state after completion |
Sho SHIMIZU | 4568c41 | 2015-08-21 16:39:07 -0700 | [diff] [blame] | 34 | * of this method is all the resources are registered, or none of the given resources is registered. |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 35 | * The whole registration fails when any one of the resource can't be registered. |
| 36 | * |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 37 | * @param resources resources to be registered |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 38 | * @return true if the registration succeeds, false otherwise |
| 39 | */ |
Jonathan Hart | 5615126 | 2016-02-11 09:48:50 -0800 | [diff] [blame] | 40 | boolean register(List<Resource> resources); |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 41 | |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 42 | /** |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 43 | * Unregisters the resources in transactional way. |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 44 | * The state after completion of this method is all the resources are unregistered, |
Sho SHIMIZU | 5618ee5 | 2015-08-21 17:19:44 -0700 | [diff] [blame] | 45 | * or none of the given resources is unregistered. The whole unregistration fails when any one of the |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 46 | * resource can't be unregistered. |
| 47 | * |
Sho SHIMIZU | 72f81b1 | 2016-02-09 09:26:17 -0800 | [diff] [blame] | 48 | * @param ids resources to be unregistered |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 49 | * @return true if the registration succeeds, false otherwise |
| 50 | */ |
Jonathan Hart | 5615126 | 2016-02-11 09:48:50 -0800 | [diff] [blame] | 51 | boolean unregister(List<ResourceId> ids); |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 54 | * Allocates the specified resources to the specified consumer in transactional way. |
| 55 | * The state after completion of this method is all the resources are allocated to the consumer, |
| 56 | * or no resource is allocated to the consumer. The whole allocation fails when any one of |
| 57 | * the resource can't be allocated. |
| 58 | * |
| 59 | * @param resources resources to be allocated |
| 60 | * @param consumer resource consumer which the resources are allocated to |
| 61 | * @return true if the allocation succeeds, false otherwise. |
| 62 | */ |
Jonathan Hart | 5615126 | 2016-02-11 09:48:50 -0800 | [diff] [blame] | 63 | boolean allocate(List<Resource> resources, ResourceConsumer consumer); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
Sho SHIMIZU | fc64ffe | 2016-02-10 20:11:09 -0800 | [diff] [blame] | 66 | * Releases the specified allocated resources in transactional way. |
| 67 | * The state after completion of this method is all the resources |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 68 | * are released from the consumer, or no resource is released. The whole release fails |
| 69 | * when any one of the resource can't be released. The size of the list of resources and |
| 70 | * that of consumers must be equal. The resource and consumer with the same position from |
| 71 | * the head of each list correspond to each other. |
| 72 | * |
Sho SHIMIZU | fc64ffe | 2016-02-10 20:11:09 -0800 | [diff] [blame] | 73 | * @param allocations allocaitons to be released |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 74 | * @return true if succeeds, otherwise false |
| 75 | */ |
Sho SHIMIZU | fc64ffe | 2016-02-10 20:11:09 -0800 | [diff] [blame] | 76 | boolean release(List<ResourceAllocation> allocations); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
Sho SHIMIZU | 6c9e33a | 2016-01-07 18:45:27 -0800 | [diff] [blame] | 79 | * Returns the resource consumers to whom the specified resource is allocated. |
| 80 | * The return value is a list having only one element when the given resource is discrete type. |
| 81 | * The return value may have multiple elements when the given resource is continuous type. |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 82 | * |
Sho SHIMIZU | dd3750c | 2016-02-01 11:37:04 -0800 | [diff] [blame] | 83 | * @param id ID of the resource whose allocated consumer to be returned |
Sho SHIMIZU | 6c9e33a | 2016-01-07 18:45:27 -0800 | [diff] [blame] | 84 | * @return resource consumers who are allocated the resource. |
| 85 | * Returns empty list if there is no such consumer. |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 86 | */ |
Sho SHIMIZU | dd3750c | 2016-02-01 11:37:04 -0800 | [diff] [blame] | 87 | List<ResourceAllocation> getResourceAllocations(ResourceId id); |
Sho SHIMIZU | 6c9e33a | 2016-01-07 18:45:27 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Returns the availability of the specified resource. |
| 91 | * |
| 92 | * @param resource resource to check the availability |
| 93 | * @return true if available, otherwise false |
| 94 | */ |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 95 | boolean isAvailable(Resource resource); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Returns a collection of the resources allocated to the specified consumer. |
| 99 | * |
| 100 | * @param consumer resource consumer whose allocated resource are searched for |
| 101 | * @return a collection of the resources allocated to the specified consumer |
| 102 | */ |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 103 | Collection<Resource> getResources(ResourceConsumer consumer); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
Sho SHIMIZU | 83258ae | 2016-01-29 17:39:07 -0800 | [diff] [blame] | 106 | * Returns a set of the child resources of the specified parent. |
Sho SHIMIZU | e7f4f3f | 2015-10-13 16:27:25 -0700 | [diff] [blame] | 107 | * |
Sho SHIMIZU | dd3750c | 2016-02-01 11:37:04 -0800 | [diff] [blame] | 108 | * @param parent ID of the parent of the resource to be returned |
Sho SHIMIZU | 83258ae | 2016-01-29 17:39:07 -0800 | [diff] [blame] | 109 | * @return a set of the child resources of the specified resource |
Sho SHIMIZU | e7f4f3f | 2015-10-13 16:27:25 -0700 | [diff] [blame] | 110 | */ |
Sho SHIMIZU | dd3750c | 2016-02-01 11:37:04 -0800 | [diff] [blame] | 111 | Set<Resource> getChildResources(DiscreteResourceId parent); |
Sho SHIMIZU | e7f4f3f | 2015-10-13 16:27:25 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 114 | * Returns a collection of the resources which are children of the specified parent and |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 115 | * whose type is the specified class. |
| 116 | * |
Sho SHIMIZU | dd3750c | 2016-02-01 11:37:04 -0800 | [diff] [blame] | 117 | * @param parent ID of the parent of the resources to be returned |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 118 | * @param cls class instance of the children |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 119 | * @param <T> type of the resource |
| 120 | * @return a collection of the resources which belongs to the specified subject and |
| 121 | * whose type is the specified class. |
| 122 | */ |
Sho SHIMIZU | dd3750c | 2016-02-01 11:37:04 -0800 | [diff] [blame] | 123 | <T> Collection<Resource> getAllocatedResources(DiscreteResourceId parent, Class<T> cls); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 124 | } |