Committed by
Gerrit Code Review
Generalize the methods in ResourceAdminService
Change-Id: Ib78d2ec441651c3215c422ba4b46d726158de4a9
Showing
4 changed files
with
35 additions
and
52 deletions
... | @@ -16,8 +16,8 @@ | ... | @@ -16,8 +16,8 @@ |
16 | package org.onosproject.net.newresource; | 16 | package org.onosproject.net.newresource; |
17 | 17 | ||
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | +import com.google.common.collect.ImmutableList; | ||
19 | 20 | ||
20 | -import java.util.Arrays; | ||
21 | import java.util.List; | 21 | import java.util.List; |
22 | 22 | ||
23 | /** | 23 | /** |
... | @@ -26,50 +26,42 @@ import java.util.List; | ... | @@ -26,50 +26,42 @@ import java.util.List; |
26 | @Beta | 26 | @Beta |
27 | public interface ResourceAdminService { | 27 | public interface ResourceAdminService { |
28 | /** | 28 | /** |
29 | - * Registers resources as the children of the parent resource path. | 29 | + * Registers the specified resources. |
30 | * | 30 | * |
31 | - * @param parent parent resource path under which the resource are registered | 31 | + * @param resources resources to be registered |
32 | - * @param children resources to be registered as the children of the parent | ||
33 | - * @param <T> type of resources | ||
34 | * @return true if registration is successfully done, false otherwise. Registration | 32 | * @return true if registration is successfully done, false otherwise. Registration |
35 | * succeeds when each resource is not registered or unallocated. | 33 | * succeeds when each resource is not registered or unallocated. |
36 | */ | 34 | */ |
37 | - default <T> boolean registerResources(ResourcePath parent, T... children) { | 35 | + default boolean registerResources(ResourcePath... resources) { |
38 | - return registerResources(parent, Arrays.asList(children)); | 36 | + return registerResources(ImmutableList.copyOf(resources)); |
39 | } | 37 | } |
40 | 38 | ||
41 | /** | 39 | /** |
42 | - * Registers resources as the children of the parent resource path. | 40 | + * Registers the specified resources. |
43 | * | 41 | * |
44 | - * @param parent parent resource path under which the resource are registered | 42 | + * @param resources resources to be registered |
45 | - * @param children resources to be registered as the children of the parent | ||
46 | - * @param <T> type of resources | ||
47 | * @return true if registration is successfully done, false otherwise. Registration | 43 | * @return true if registration is successfully done, false otherwise. Registration |
48 | * succeeds when each resource is not registered or unallocated. | 44 | * succeeds when each resource is not registered or unallocated. |
49 | */ | 45 | */ |
50 | - <T> boolean registerResources(ResourcePath parent, List<T> children); | 46 | + boolean registerResources(List<ResourcePath> resources); |
51 | 47 | ||
52 | /** | 48 | /** |
53 | - * Unregisters resources as the children of the parent resource path. | 49 | + * Unregisters the specified resources. |
54 | * | 50 | * |
55 | - * @param parent parent resource path under which the resource are unregistered | 51 | + * @param resources resources to be unregistered |
56 | - * @param children resources to be unregistered as the children of the parent | ||
57 | - * @param <T> type of resources | ||
58 | * @return true if unregistration is successfully done, false otherwise. Unregistration | 52 | * @return true if unregistration is successfully done, false otherwise. Unregistration |
59 | * succeeds when each resource is not registered or unallocated. | 53 | * succeeds when each resource is not registered or unallocated. |
60 | */ | 54 | */ |
61 | - default <T> boolean unregisterResources(ResourcePath parent, T... children) { | 55 | + default boolean unregisterResources(ResourcePath... resources) { |
62 | - return unregisterResources(parent, Arrays.asList(children)); | 56 | + return unregisterResources(ImmutableList.copyOf(resources)); |
63 | } | 57 | } |
64 | 58 | ||
65 | /** | 59 | /** |
66 | - * Unregisters resources as the children of the parent resource path. | 60 | + * Unregisters the specified resources. |
67 | * | 61 | * |
68 | - * @param parent parent resource path under which the resource are unregistered | 62 | + * @param resources resources to be unregistered |
69 | - * @param children resources to be unregistered as the children of the parent | ||
70 | - * @param <T> type of resources | ||
71 | * @return true if unregistration is successfully done, false otherwise. Unregistration | 63 | * @return true if unregistration is successfully done, false otherwise. Unregistration |
72 | * succeeds when each resource is not registered or unallocated. | 64 | * succeeds when each resource is not registered or unallocated. |
73 | */ | 65 | */ |
74 | - <T> boolean unregisterResources(ResourcePath parent, List<T> children); | 66 | + boolean unregisterResources(List<ResourcePath> resources); |
75 | } | 67 | } | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.newresource.impl; | 16 | package org.onosproject.net.newresource.impl; |
17 | 17 | ||
18 | +import com.google.common.collect.Lists; | ||
18 | import org.onosproject.net.Device; | 19 | import org.onosproject.net.Device; |
19 | import org.onosproject.net.Port; | 20 | import org.onosproject.net.Port; |
20 | import org.onosproject.net.OchPort; | 21 | import org.onosproject.net.OchPort; |
... | @@ -82,21 +83,17 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -82,21 +83,17 @@ final class ResourceDeviceListener implements DeviceListener { |
82 | } | 83 | } |
83 | 84 | ||
84 | private void registerDeviceResource(Device device) { | 85 | private void registerDeviceResource(Device device) { |
85 | - executor.submit(() -> adminService.registerResources(ResourcePath.ROOT, device.id())); | 86 | + executor.submit(() -> adminService.registerResources(ResourcePath.discrete(device.id()))); |
86 | } | 87 | } |
87 | 88 | ||
88 | private void unregisterDeviceResource(Device device) { | 89 | private void unregisterDeviceResource(Device device) { |
89 | - executor.submit(() -> adminService.unregisterResources(ResourcePath.ROOT, device.id())); | 90 | + executor.submit(() -> adminService.unregisterResources(ResourcePath.discrete(device.id()))); |
90 | } | 91 | } |
91 | 92 | ||
92 | private void registerPortResource(Device device, Port port) { | 93 | private void registerPortResource(Device device, Port port) { |
93 | - ResourcePath parent = ResourcePath.discrete(device.id()); | ||
94 | - executor.submit(() -> registerPortResource(device, port, parent)); | ||
95 | - } | ||
96 | - | ||
97 | - private void registerPortResource(Device device, Port port, ResourcePath parent) { | ||
98 | - adminService.registerResources(parent, port.number()); | ||
99 | ResourcePath portPath = ResourcePath.discrete(device.id(), port.number()); | 94 | ResourcePath portPath = ResourcePath.discrete(device.id(), port.number()); |
95 | + executor.submit(() -> { | ||
96 | + adminService.registerResources(portPath); | ||
100 | 97 | ||
101 | switch (port.type()) { | 98 | switch (port.type()) { |
102 | case OCH: | 99 | case OCH: |
... | @@ -106,15 +103,16 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -106,15 +103,16 @@ final class ResourceDeviceListener implements DeviceListener { |
106 | default: | 103 | default: |
107 | break; | 104 | break; |
108 | } | 105 | } |
106 | + }); | ||
109 | } | 107 | } |
110 | 108 | ||
111 | private void registerTributarySlotsResources(OduSignalType oduSignalType, ResourcePath portPath) { | 109 | private void registerTributarySlotsResources(OduSignalType oduSignalType, ResourcePath portPath) { |
112 | switch (oduSignalType) { | 110 | switch (oduSignalType) { |
113 | case ODU2: | 111 | case ODU2: |
114 | - adminService.registerResources(portPath, ENTIRE_ODU2_TRIBUTARY_SLOTS); | 112 | + adminService.registerResources(Lists.transform(ENTIRE_ODU2_TRIBUTARY_SLOTS, portPath::child)); |
115 | break; | 113 | break; |
116 | case ODU4: | 114 | case ODU4: |
117 | - adminService.registerResources(portPath, ENTIRE_ODU4_TRIBUTARY_SLOTS); | 115 | + adminService.registerResources(Lists.transform(ENTIRE_ODU4_TRIBUTARY_SLOTS, portPath::child)); |
118 | break; | 116 | break; |
119 | default: | 117 | default: |
120 | break; | 118 | break; |
... | @@ -122,8 +120,8 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -122,8 +120,8 @@ final class ResourceDeviceListener implements DeviceListener { |
122 | } | 120 | } |
123 | 121 | ||
124 | private void unregisterPortResource(Device device, Port port) { | 122 | private void unregisterPortResource(Device device, Port port) { |
125 | - ResourcePath parent = ResourcePath.discrete(device.id()); | 123 | + ResourcePath resource = ResourcePath.discrete(device.id(), port.number()); |
126 | - executor.submit(() -> adminService.unregisterResources(parent, port.number())); | 124 | + executor.submit(() -> adminService.unregisterResources(resource)); |
127 | } | 125 | } |
128 | 126 | ||
129 | private static List<TributarySlot> getEntireOdu2TributarySlots() { | 127 | private static List<TributarySlot> getEntireOdu2TributarySlots() { | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.newresource.impl; | 16 | package org.onosproject.net.newresource.impl; |
17 | 17 | ||
18 | +import com.google.common.collect.Lists; | ||
18 | import org.onlab.packet.MplsLabel; | 19 | import org.onlab.packet.MplsLabel; |
19 | import org.onlab.packet.VlanId; | 20 | import org.onlab.packet.VlanId; |
20 | import org.onlab.util.ItemNotFoundException; | 21 | import org.onlab.util.ItemNotFoundException; |
... | @@ -85,24 +86,24 @@ final class ResourceLinkListener implements LinkListener { | ... | @@ -85,24 +86,24 @@ final class ResourceLinkListener implements LinkListener { |
85 | executor.submit(() -> { | 86 | executor.submit(() -> { |
86 | // register the link | 87 | // register the link |
87 | LinkKey linkKey = LinkKey.linkKey(link); | 88 | LinkKey linkKey = LinkKey.linkKey(link); |
88 | - adminService.registerResources(ResourcePath.ROOT, linkKey); | 89 | + adminService.registerResources(ResourcePath.discrete(linkKey)); |
89 | 90 | ||
90 | ResourcePath linkPath = ResourcePath.discrete(linkKey); | 91 | ResourcePath linkPath = ResourcePath.discrete(linkKey); |
91 | // register VLAN IDs against the link | 92 | // register VLAN IDs against the link |
92 | if (isEnabled(link, this::isVlanEnabled)) { | 93 | if (isEnabled(link, this::isVlanEnabled)) { |
93 | - adminService.registerResources(linkPath, ENTIRE_VLAN_IDS); | 94 | + adminService.registerResources(Lists.transform(ENTIRE_VLAN_IDS, linkPath::child)); |
94 | } | 95 | } |
95 | 96 | ||
96 | // register MPLS labels against the link | 97 | // register MPLS labels against the link |
97 | if (isEnabled(link, this::isMplsEnabled)) { | 98 | if (isEnabled(link, this::isMplsEnabled)) { |
98 | - adminService.registerResources(linkPath, ENTIRE_MPLS_LABELS); | 99 | + adminService.registerResources(Lists.transform(ENTIRE_MPLS_LABELS, linkPath::child)); |
99 | } | 100 | } |
100 | }); | 101 | }); |
101 | } | 102 | } |
102 | 103 | ||
103 | private void unregisterLinkResource(Link link) { | 104 | private void unregisterLinkResource(Link link) { |
104 | LinkKey linkKey = LinkKey.linkKey(link); | 105 | LinkKey linkKey = LinkKey.linkKey(link); |
105 | - executor.submit(() -> adminService.unregisterResources(ResourcePath.ROOT, linkKey)); | 106 | + executor.submit(() -> adminService.unregisterResources(ResourcePath.discrete(linkKey))); |
106 | } | 107 | } |
107 | 108 | ||
108 | private boolean isEnabled(Link link, Predicate<ConnectPoint> predicate) { | 109 | private boolean isEnabled(Link link, Predicate<ConnectPoint> predicate) { | ... | ... |
... | @@ -17,7 +17,6 @@ package org.onosproject.net.newresource.impl; | ... | @@ -17,7 +17,6 @@ package org.onosproject.net.newresource.impl; |
17 | 17 | ||
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | import com.google.common.collect.ImmutableList; | 19 | import com.google.common.collect.ImmutableList; |
20 | -import com.google.common.collect.Lists; | ||
21 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
22 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
23 | import org.apache.felix.scr.annotations.Deactivate; | 22 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -41,7 +40,6 @@ import java.util.List; | ... | @@ -41,7 +40,6 @@ import java.util.List; |
41 | import java.util.Optional; | 40 | import java.util.Optional; |
42 | import java.util.stream.Collectors; | 41 | import java.util.stream.Collectors; |
43 | 42 | ||
44 | -import static com.google.common.base.Preconditions.checkArgument; | ||
45 | import static com.google.common.base.Preconditions.checkNotNull; | 43 | import static com.google.common.base.Preconditions.checkNotNull; |
46 | 44 | ||
47 | /** | 45 | /** |
... | @@ -164,23 +162,17 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent | ... | @@ -164,23 +162,17 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent |
164 | } | 162 | } |
165 | 163 | ||
166 | @Override | 164 | @Override |
167 | - public <T> boolean registerResources(ResourcePath parent, List<T> children) { | 165 | + public boolean registerResources(List<ResourcePath> resources) { |
168 | - checkNotNull(parent); | 166 | + checkNotNull(resources); |
169 | - checkNotNull(children); | ||
170 | - checkArgument(!children.isEmpty()); | ||
171 | 167 | ||
172 | - List<ResourcePath> resources = Lists.transform(children, parent::child); | ||
173 | return store.register(resources); | 168 | return store.register(resources); |
174 | } | 169 | } |
175 | 170 | ||
176 | @Override | 171 | @Override |
177 | - public <T> boolean unregisterResources(ResourcePath parent, List<T> children) { | 172 | + public boolean unregisterResources(List<ResourcePath> resources) { |
178 | - checkNotNull(parent); | 173 | + checkNotNull(resources); |
179 | - checkNotNull(children); | ||
180 | - checkArgument(!children.isEmpty()); | ||
181 | 174 | ||
182 | - List<ResourcePath> resources = Lists.transform(children, parent::child); | 175 | + return store.register(resources); |
183 | - return store.unregister(resources); | ||
184 | } | 176 | } |
185 | 177 | ||
186 | private class InternalStoreDelegate implements ResourceStoreDelegate { | 178 | private class InternalStoreDelegate implements ResourceStoreDelegate { | ... | ... |
-
Please register or login to post a comment