blob: 8456106604c8d9d54cf64366556bfe91e4e78d6c [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuska58de4162015-09-10 16:15:33 -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 */
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080016package org.onosproject.net.resource;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070017
18import com.google.common.annotations.Beta;
Sho SHIMIZUfa62b472015-11-02 17:35:46 -080019import org.onosproject.store.Store;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070020
21import java.util.Collection;
22import java.util.List;
Sho SHIMIZU83258ae2016-01-29 17:39:07 -080023import java.util.Set;
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070024
25/**
26 * Service for storing resource and consumer information.
27 */
28@Beta
Sho SHIMIZUfa62b472015-11-02 17:35:46 -080029public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegate> {
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070030
31 /**
Sho SHIMIZU83e17a02015-08-20 14:07:05 -070032 * Registers the resources in transactional way.
Sho SHIMIZUad619f52015-08-24 10:45:40 -070033 * Resource registration must be done before resource allocation. The state after completion
Sho SHIMIZU4568c412015-08-21 16:39:07 -070034 * of this method is all the resources are registered, or none of the given resources is registered.
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070035 * The whole registration fails when any one of the resource can't be registered.
36 *
Sho SHIMIZU83e17a02015-08-20 14:07:05 -070037 * @param resources resources to be registered
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070038 * @return true if the registration succeeds, false otherwise
39 */
Jonathan Hart56151262016-02-11 09:48:50 -080040 boolean register(List<Resource> resources);
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070041
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070042 /**
Sho SHIMIZU83e17a02015-08-20 14:07:05 -070043 * Unregisters the resources in transactional way.
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -070044 * The state after completion of this method is all the resources are unregistered,
Sho SHIMIZU5618ee52015-08-21 17:19:44 -070045 * or none of the given resources is unregistered. The whole unregistration fails when any one of the
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -070046 * resource can't be unregistered.
47 *
Sho SHIMIZU72f81b12016-02-09 09:26:17 -080048 * @param ids resources to be unregistered
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -070049 * @return true if the registration succeeds, false otherwise
50 */
Jonathan Hart56151262016-02-11 09:48:50 -080051 boolean unregister(List<ResourceId> ids);
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -070052
53 /**
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070054 * 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 Hart56151262016-02-11 09:48:50 -080063 boolean allocate(List<Resource> resources, ResourceConsumer consumer);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070064
65 /**
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -080066 * Releases the specified allocated resources in transactional way.
67 * The state after completion of this method is all the resources
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070068 * 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 SHIMIZUfc64ffe2016-02-10 20:11:09 -080073 * @param allocations allocaitons to be released
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070074 * @return true if succeeds, otherwise false
75 */
Sho SHIMIZUfc64ffe2016-02-10 20:11:09 -080076 boolean release(List<ResourceAllocation> allocations);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070077
78 /**
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080079 * 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 SHIMIZU78ee25c2015-07-16 15:54:14 -070082 *
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -080083 * @param id ID of the resource whose allocated consumer to be returned
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080084 * @return resource consumers who are allocated the resource.
85 * Returns empty list if there is no such consumer.
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070086 */
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -080087 List<ResourceAllocation> getResourceAllocations(ResourceId id);
Sho SHIMIZU6c9e33a2016-01-07 18:45:27 -080088
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 SHIMIZU8fa670a2016-01-14 11:17:18 -080095 boolean isAvailable(Resource resource);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070096
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 SHIMIZU8fa670a2016-01-14 11:17:18 -0800103 Collection<Resource> getResources(ResourceConsumer consumer);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700104
105 /**
Sho SHIMIZU83258ae2016-01-29 17:39:07 -0800106 * Returns a set of the child resources of the specified parent.
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700107 *
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800108 * @param parent ID of the parent of the resource to be returned
Sho SHIMIZU83258ae2016-01-29 17:39:07 -0800109 * @return a set of the child resources of the specified resource
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700110 */
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800111 Set<Resource> getChildResources(DiscreteResourceId parent);
Sho SHIMIZUe7f4f3f2015-10-13 16:27:25 -0700112
113 /**
Sho SHIMIZU9cc4a242016-05-26 12:55:35 -0700114 * Returns a set of the child resources of the specified parent and whose type is
115 * the specified class.
116 *
117 * @param parent ID of the parent of the resources to be returned
118 * @param cls class instance of the children
119 * @param <T> type of the resource
120 * @return a set of the child resources of the specified parent and whose type is
121 * the specified class
122 */
123 <T> Set<Resource> getChildResources(DiscreteResourceId parent, Class<T> cls);
124
125 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700126 * Returns a collection of the resources which are children of the specified parent and
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700127 * whose type is the specified class.
128 *
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800129 * @param parent ID of the parent of the resources to be returned
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700130 * @param cls class instance of the children
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700131 * @param <T> type of the resource
132 * @return a collection of the resources which belongs to the specified subject and
133 * whose type is the specified class.
134 */
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800135 <T> Collection<Resource> getAllocatedResources(DiscreteResourceId parent, Class<T> cls);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -0700136}