blob: b9b2b521b9de20025e5c2929343df2f6396418eb [file] [log] [blame]
Sho SHIMIZUabd849c2015-07-14 09:14:12 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.newresource;
17
18import com.google.common.annotations.Beta;
19
20import java.util.Collection;
21import java.util.List;
22import java.util.Optional;
23
24/**
25 * Service for allocating/releasing resource(s) and retrieving allocation(s) and availability.
26 */
27@Beta
28public interface ResourceService {
29 /**
30 * Allocates the specified resource to the specified user.
31 *
32 * @param consumer resource user which the resource is allocated to
33 * @param resource resource to be allocated
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070034 * @return allocation information enclosed by Optional. If the allocation fails, the return value is empty
35 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070036 Optional<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath resource);
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070037
38 /**
39 * Transactionally allocates the specified resources to the specified user.
40 * All allocations are made when this method succeeds, or no allocation is made when this method fails.
41 *
42 * @param consumer resource user which the resources are allocated to
43 * @param resources resources to be allocated
44 * @return non-empty list of allocation information if succeeded, otherwise empty list
45 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070046 List<ResourceAllocation> allocate(ResourceConsumer consumer, List<ResourcePath> resources);
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070047
48 /**
49 * Transactionally allocates the specified resources to the specified user.
50 * All allocations are made when this method succeeds, or no allocation is made when this method fails.
51 *
52 * @param consumer resource user which the resources are allocated to
53 * @param resources resources to be allocated
54 * @return non-empty list of allocation information if succeeded, otherwise empty list
55 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070056 List<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath... resources);
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070057
58 /**
59 * Releases the specified resource allocation.
60 *
61 * @param allocation resource allocation to be released
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070062 * @return true if succeeded, otherwise false
63 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070064 boolean release(ResourceAllocation allocation);
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070065
66 /**
67 * Transactionally releases the specified resource allocations.
68 * All allocations are released when this method succeeded, or no allocation is released when this method fails.
69 *
70 * @param allocations resource allocations to be released
71 * @return true if succeeded, otherwise false
72 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070073 boolean release(List<ResourceAllocation> allocations);
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070074
75 /**
76 * Transactionally releases the specified resource allocations.
77 * All allocations are released when this method succeeded, or no allocation is released when this method fails.
78 *
79 * @param allocations resource allocations to be released
80 * @return true if succeeded, otherwise false
81 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070082 boolean release(ResourceAllocation... allocations);
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070083
84 /**
85 * Transactionally releases the resources allocated to the specified consumer.
86 * All allocations are released when this method succeeded, or no allocation is released when this method fails.
87 *
88 * @param consumer consumer whose allocated resources are to be released
89 * @return true if succeeded, otherwise false
90 */
91 boolean release(ResourceConsumer consumer);
92
93 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070094 * Returns allocated resources being as children of the specified parent and being the specified resource type.
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070095 *
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070096 * @param cls class to specify a type of resource
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070097 * @param <T> type of the resource
98 * @return non-empty collection of resource allocations if resources are allocated with the subject and type,
99 * empty collection if no resource is allocated with the subject and type
100 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700101 <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls);
Sho SHIMIZUabd849c2015-07-14 09:14:12 -0700102
103 /**
104 * Returns resources allocated to the specified consumer.
105 *
106 * @param consumer consumer whose allocated resources are to be returned
107 * @return resources allocated to the consumer
108 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700109 Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer);
Sho SHIMIZUabd849c2015-07-14 09:14:12 -0700110
111 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700112 * Returns the availability of the specified resource.
Sho SHIMIZUabd849c2015-07-14 09:14:12 -0700113 *
114 * @param resource resource to check the availability
Sho SHIMIZUabd849c2015-07-14 09:14:12 -0700115 * @return true if available, otherwise false
116 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700117 boolean isAvailable(ResourcePath resource);
Sho SHIMIZUabd849c2015-07-14 09:14:12 -0700118
119 // TODO: listener and event mechanism need to be considered
120}