blob: 89ac7f771ef0cfb864bc31b6bf032d349d1c0c0d [file] [log] [blame]
Jordan Halterman6359c832017-03-29 16:53:21 -07001/*
2 * Copyright 2017-present 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.store.resource.impl;
17
18import org.onosproject.net.resource.DiscreteResourceId;
19import org.onosproject.net.resource.Resource;
20import org.onosproject.net.resource.ResourceAllocation;
21import org.onosproject.net.resource.ResourceConsumerId;
22import org.onosproject.net.resource.ResourceId;
23import org.onosproject.store.service.TransactionContext;
24
25import java.util.List;
26import java.util.Set;
27import java.util.stream.Stream;
28
29/**
30 * Interface for consistent resource substores.
31 */
32interface ConsistentResourceSubStore
33 <T extends ResourceId, U extends Resource, V extends TransactionalResourceSubStore> {
34
35 /**
36 * Returns a new transactional substore.
37 *
38 * @param tx the transaction context
39 * @return a transactional resource substore
40 */
41 V transactional(TransactionContext tx);
42
43 /**
44 * Returns a list of resource allocations for the given resource ID.
45 *
46 * @param resourceId the resource ID
47 * @return a list of resource allocations for the given ID
48 */
49 List<ResourceAllocation> getResourceAllocations(T resourceId);
50
51 /**
52 * Returns a set of child resources for the given discrete resource.
53 *
54 * @param resourceId the parent resource ID
55 * @return a set of child resources for the given discrete parent
56 */
57 Set<U> getChildResources(DiscreteResourceId resourceId);
58
59 /**
60 * Returns a set of child resources cast to the given type.
61 *
62 * @param resourceId the parent resource ID
63 * @param type the type to which to cast resources
64 * @return a set of child resources for the given discrete parent
65 */
66 Set<U> getChildResources(DiscreteResourceId resourceId, Class<?> type);
67
68 /**
69 * Returns a boolean indicating whether the given resource is available.
70 *
71 * @param resource the resource to check
72 * @return indicates whether the given resource is available
73 */
74 boolean isAvailable(U resource);
75
76 /**
77 * Returns a stream of allocated resources for the given parent.
78 *
79 * @param parent the parent resource ID for which to return allocated resources
80 * @param type the type to which to cast allocated resources
81 * @return a stream of allocated resources for the given parent
82 */
83 Stream<U> getAllocatedResources(DiscreteResourceId parent, Class<?> type);
84
85 /**
86 * Returns a stream of resources for the given consumer.
87 *
88 * @param consumerId the consumer ID for which to return resources
89 * @return a stream of resources for the given consumer
90 */
91 Stream<U> getResources(ResourceConsumerId consumerId);
92
93}