Sho SHIMIZU
Committed by Gerrit Code Review

Extract interface consisting of read-only operations

Change-Id: I0e43b25ea5feba6af882addb0e734d0662f3808f
...@@ -38,7 +38,7 @@ import org.onosproject.net.resource.ContinuousResource; ...@@ -38,7 +38,7 @@ import org.onosproject.net.resource.ContinuousResource;
38 import org.onosproject.net.resource.DiscreteResource; 38 import org.onosproject.net.resource.DiscreteResource;
39 import org.onosproject.net.resource.Resource; 39 import org.onosproject.net.resource.Resource;
40 import org.onosproject.net.resource.Resources; 40 import org.onosproject.net.resource.Resources;
41 -import org.onosproject.net.resource.ResourceService; 41 +import org.onosproject.net.resource.ResourceQueryService;
42 42
43 import com.google.common.base.Strings; 43 import com.google.common.base.Strings;
44 import com.google.common.collect.ArrayListMultimap; 44 import com.google.common.collect.ArrayListMultimap;
...@@ -75,11 +75,11 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -75,11 +75,11 @@ public class ResourcesCommand extends AbstractShellCommand {
75 String portNumberStr = null; 75 String portNumberStr = null;
76 76
77 77
78 - private ResourceService resourceService; 78 + private ResourceQueryService resourceService;
79 79
80 @Override 80 @Override
81 protected void execute() { 81 protected void execute() {
82 - resourceService = get(ResourceService.class); 82 + resourceService = get(ResourceQueryService.class);
83 83
84 if (typeStrings != null) { 84 if (typeStrings != null) {
85 typesToPrint = new HashSet<>(Arrays.asList(typeStrings)); 85 typesToPrint = new HashSet<>(Arrays.asList(typeStrings));
......
1 +/*
2 + * Copyright 2016 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 + */
16 +package org.onosproject.net.resource;
17 +
18 +import java.util.Collection;
19 +import java.util.List;
20 +import java.util.Set;
21 +
22 +/**
23 + * Service for retrieving resource information.
24 + */
25 +public interface ResourceQueryService {
26 + /**
27 + * Returns resource allocations of the specified resource.
28 + *
29 + * @param id ID of the resource to check the allocation
30 + * @return list of allocation information.
31 + * If the resource is not allocated, the return value is an empty list.
32 + */
33 + List<ResourceAllocation> getResourceAllocations(ResourceId id);
34 +
35 + /**
36 + * Returns allocated resources being as children of the specified parent and being the specified resource type.
37 + *
38 + * @param parent parent resource ID
39 + * @param cls class to specify a type of resource
40 + * @param <T> type of the resource
41 + * @return non-empty collection of resource allocations if resources are allocated with the subject and type,
42 + * empty collection if no resource is allocated with the subject and type
43 + */
44 + <T> Collection<ResourceAllocation> getResourceAllocations(DiscreteResourceId parent, Class<T> cls);
45 +
46 + /**
47 + * Returns resources allocated to the specified consumer.
48 + *
49 + * @param consumer consumer whose allocated resources are to be returned
50 + * @return resources allocated to the consumer
51 + */
52 + Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer);
53 +
54 + /**
55 + * Returns resources that point available child resources under the specified resource.
56 + *
57 + * @param parent parent resource ID
58 + * @return available resources under the specified resource
59 + */
60 + Set<Resource> getAvailableResources(DiscreteResourceId parent);
61 +
62 + /**
63 + * Returns available resources which are child resources of the specified parent and
64 + * whose type is the specified type.
65 + *
66 + * @param parent parent resource ID
67 + * @param cls class to specify a type of resource
68 + * @param <T> type of the resource
69 + * @return available resources of the specified type under the specified parent resource
70 + */
71 + <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls);
72 +
73 + /**
74 + * Returns available resource values which are the values of the child resource of
75 + * the specified parent and whose type is the specified type.
76 + *
77 + * @param parent parent resource ID
78 + * @param cls class to specify a type of resource
79 + * @param <T> type of the resource
80 + * @return available resource value of the specified type under the specified parent resource
81 + */
82 + <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls);
83 +
84 + /**
85 + * Returns resources registered under the specified resource.
86 + *
87 + * @param parent parent resource ID
88 + * @return registered resources under the specified resource
89 + */
90 + Set<Resource> getRegisteredResources(DiscreteResourceId parent);
91 +
92 + /**
93 + * Returns the availability of the specified resource.
94 + *
95 + * @param resource resource to check the availability
96 + * @return true if available, otherwise false
97 + */
98 + boolean isAvailable(Resource resource);
99 +}
...@@ -20,10 +20,8 @@ import com.google.common.collect.ImmutableList; ...@@ -20,10 +20,8 @@ import com.google.common.collect.ImmutableList;
20 import org.onosproject.event.ListenerService; 20 import org.onosproject.event.ListenerService;
21 21
22 import java.util.Arrays; 22 import java.util.Arrays;
23 -import java.util.Collection;
24 import java.util.List; 23 import java.util.List;
25 import java.util.Optional; 24 import java.util.Optional;
26 -import java.util.Set;
27 25
28 import static com.google.common.base.Preconditions.checkNotNull; 26 import static com.google.common.base.Preconditions.checkNotNull;
29 27
...@@ -31,7 +29,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -31,7 +29,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
31 * Service for allocating/releasing resource(s) and retrieving allocation(s) and availability. 29 * Service for allocating/releasing resource(s) and retrieving allocation(s) and availability.
32 */ 30 */
33 @Beta 31 @Beta
34 -public interface ResourceService extends ListenerService<ResourceEvent, ResourceListener> { 32 +public interface ResourceService extends ResourceQueryService, ListenerService<ResourceEvent, ResourceListener> {
35 /** 33 /**
36 * Allocates the specified resource to the specified user. 34 * Allocates the specified resource to the specified user.
37 * 35 *
...@@ -62,7 +60,7 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource ...@@ -62,7 +60,7 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
62 * Transactionally allocates the specified resources to the specified user. 60 * Transactionally allocates the specified resources to the specified user.
63 * All allocations are made when this method succeeds, or no allocation is made when this method fails. 61 * All allocations are made when this method succeeds, or no allocation is made when this method fails.
64 * 62 *
65 - * @param consumer resource user which the resources are allocated to 63 + * @param consumer resource user which the resources are allocated to
66 * @param resources resources to be allocated 64 * @param resources resources to be allocated
67 * @return non-empty list of allocation information if succeeded, otherwise empty list 65 * @return non-empty list of allocation information if succeeded, otherwise empty list
68 */ 66 */
...@@ -72,7 +70,7 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource ...@@ -72,7 +70,7 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
72 * Transactionally allocates the specified resources to the specified user. 70 * Transactionally allocates the specified resources to the specified user.
73 * All allocations are made when this method succeeds, or no allocation is made when this method fails. 71 * All allocations are made when this method succeeds, or no allocation is made when this method fails.
74 * 72 *
75 - * @param consumer resource user which the resources are allocated to 73 + * @param consumer resource user which the resources are allocated to
76 * @param resources resources to be allocated 74 * @param resources resources to be allocated
77 * @return non-empty list of allocation information if succeeded, otherwise empty list 75 * @return non-empty list of allocation information if succeeded, otherwise empty list
78 */ 76 */
...@@ -126,78 +124,5 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource ...@@ -126,78 +124,5 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
126 */ 124 */
127 boolean release(ResourceConsumer consumer); 125 boolean release(ResourceConsumer consumer);
128 126
129 - /**
130 - * Returns resource allocations of the specified resource.
131 - *
132 - * @param id ID of the resource to check the allocation
133 - * @return list of allocation information.
134 - * If the resource is not allocated, the return value is an empty list.
135 - */
136 - List<ResourceAllocation> getResourceAllocations(ResourceId id);
137 -
138 - /**
139 - * Returns allocated resources being as children of the specified parent and being the specified resource type.
140 - *
141 - * @param parent parent resource ID
142 - * @param cls class to specify a type of resource
143 - * @param <T> type of the resource
144 - * @return non-empty collection of resource allocations if resources are allocated with the subject and type,
145 - * empty collection if no resource is allocated with the subject and type
146 - */
147 - <T> Collection<ResourceAllocation> getResourceAllocations(DiscreteResourceId parent, Class<T> cls);
148 -
149 - /**
150 - * Returns resources allocated to the specified consumer.
151 - *
152 - * @param consumer consumer whose allocated resources are to be returned
153 - * @return resources allocated to the consumer
154 - */
155 - Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer);
156 -
157 - /**
158 - * Returns resources that point available child resources under the specified resource.
159 - *
160 - * @param parent parent resource ID
161 - * @return available resources under the specified resource
162 - */
163 - Set<Resource> getAvailableResources(DiscreteResourceId parent);
164 -
165 - /**
166 - * Returns available resources which are child resources of the specified parent and
167 - * whose type is the specified type.
168 - *
169 - * @param parent parent resource ID
170 - * @param cls class to specify a type of resource
171 - * @param <T> type of the resource
172 - * @return available resources of the specified type under the specified parent resource
173 - */
174 - <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls);
175 -
176 - /**
177 - * Returns available resource values which are the values of the child resource of
178 - * the specified parent and whose type is the specified type.
179 - *
180 - * @param parent parent resource ID
181 - * @param cls class to specify a type of resource
182 - * @param <T> type of the resource
183 - * @return available resource value of the specified type under the specified parent resource
184 - */
185 - <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls);
186 - /**
187 - * Returns resources registered under the specified resource.
188 - *
189 - * @param parent parent resource ID
190 - * @return registered resources under the specified resource
191 - */
192 - Set<Resource> getRegisteredResources(DiscreteResourceId parent);
193 -
194 - /**
195 - * Returns the availability of the specified resource.
196 - *
197 - * @param resource resource to check the availability
198 - * @return true if available, otherwise false
199 - */
200 - boolean isAvailable(Resource resource);
201 -
202 // TODO: listener and event mechanism need to be considered 127 // TODO: listener and event mechanism need to be considered
203 } 128 }
......
...@@ -27,7 +27,7 @@ import org.onosproject.net.intent.Constraint; ...@@ -27,7 +27,7 @@ import org.onosproject.net.intent.Constraint;
27 import org.onosproject.net.intent.IntentCompiler; 27 import org.onosproject.net.intent.IntentCompiler;
28 import org.onosproject.net.intent.IntentExtensionService; 28 import org.onosproject.net.intent.IntentExtensionService;
29 import org.onosproject.net.intent.impl.PathNotFoundException; 29 import org.onosproject.net.intent.impl.PathNotFoundException;
30 -import org.onosproject.net.resource.ResourceService; 30 +import org.onosproject.net.resource.ResourceQueryService;
31 import org.onosproject.net.provider.ProviderId; 31 import org.onosproject.net.provider.ProviderId;
32 import org.onosproject.net.topology.LinkWeight; 32 import org.onosproject.net.topology.LinkWeight;
33 import org.onosproject.net.topology.PathService; 33 import org.onosproject.net.topology.PathService;
...@@ -55,7 +55,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> ...@@ -55,7 +55,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent>
55 protected PathService pathService; 55 protected PathService pathService;
56 56
57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 - protected ResourceService resourceService; 58 + protected ResourceQueryService resourceService;
59 59
60 /** 60 /**
61 * Returns an edge-weight capable of evaluating links on the basis of the 61 * Returns an edge-weight capable of evaluating links on the basis of the
......
...@@ -43,8 +43,8 @@ import org.onosproject.net.resource.DiscreteResource; ...@@ -43,8 +43,8 @@ import org.onosproject.net.resource.DiscreteResource;
43 import org.onosproject.net.resource.ResourceAdminService; 43 import org.onosproject.net.resource.ResourceAdminService;
44 import org.onosproject.net.resource.BandwidthCapacity; 44 import org.onosproject.net.resource.BandwidthCapacity;
45 import org.onosproject.net.resource.Resource; 45 import org.onosproject.net.resource.Resource;
46 +import org.onosproject.net.resource.ResourceQueryService;
46 import org.onosproject.net.resource.Resources; 47 import org.onosproject.net.resource.Resources;
47 -import org.onosproject.net.resource.ResourceService;
48 import org.slf4j.Logger; 48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory; 49 import org.slf4j.LoggerFactory;
50 50
...@@ -66,7 +66,7 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -66,7 +66,7 @@ final class ResourceDeviceListener implements DeviceListener {
66 private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class); 66 private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class);
67 67
68 private final ResourceAdminService adminService; 68 private final ResourceAdminService adminService;
69 - private final ResourceService resourceService; 69 + private final ResourceQueryService resourceService;
70 private final DeviceService deviceService; 70 private final DeviceService deviceService;
71 private final MastershipService mastershipService; 71 private final MastershipService mastershipService;
72 private final DriverService driverService; 72 private final DriverService driverService;
...@@ -78,14 +78,14 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -78,14 +78,14 @@ final class ResourceDeviceListener implements DeviceListener {
78 * Creates an instance with the specified ResourceAdminService and ExecutorService. 78 * Creates an instance with the specified ResourceAdminService and ExecutorService.
79 * 79 *
80 * @param adminService instance invoked to register resources 80 * @param adminService instance invoked to register resources
81 - * @param resourceService {@link ResourceService} to be used 81 + * @param resourceService {@link ResourceQueryService} to be used
82 * @param deviceService {@link DeviceService} to be used 82 * @param deviceService {@link DeviceService} to be used
83 * @param mastershipService {@link MastershipService} to be used 83 * @param mastershipService {@link MastershipService} to be used
84 * @param driverService {@link DriverService} to be used 84 * @param driverService {@link DriverService} to be used
85 * @param netcfgService {@link NetworkConfigService} to be used. 85 * @param netcfgService {@link NetworkConfigService} to be used.
86 * @param executor executor used for processing resource registration 86 * @param executor executor used for processing resource registration
87 */ 87 */
88 - ResourceDeviceListener(ResourceAdminService adminService, ResourceService resourceService, 88 + ResourceDeviceListener(ResourceAdminService adminService, ResourceQueryService resourceService,
89 DeviceService deviceService, MastershipService mastershipService, 89 DeviceService deviceService, MastershipService mastershipService,
90 DriverService driverService, NetworkConfigService netcfgService, 90 DriverService driverService, NetworkConfigService netcfgService,
91 ExecutorService executor) { 91 ExecutorService executor) {
......