Committed by
Gerrit Code Review
Merge various resource type completers as one completer for CPMan
Change-Id: If4a9f6fa6705f49847139cd95b28ec0482d47415
Showing
4 changed files
with
38 additions
and
125 deletions
apps/cpman/app/src/main/java/org/onosproject/cpman/cli/DiskResourceNameCompleter.java
deleted
100644 → 0
| 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.cpman.cli; | ||
| 17 | - | ||
| 18 | -import org.apache.karaf.shell.console.completer.ArgumentCompleter; | ||
| 19 | -import org.apache.karaf.shell.console.completer.StringsCompleter; | ||
| 20 | -import org.onosproject.cli.AbstractCompleter; | ||
| 21 | -import org.onosproject.cli.AbstractShellCommand; | ||
| 22 | -import org.onosproject.cpman.ControlPlaneMonitorService; | ||
| 23 | - | ||
| 24 | -import java.util.List; | ||
| 25 | -import java.util.Set; | ||
| 26 | -import java.util.SortedSet; | ||
| 27 | - | ||
| 28 | -import static org.onosproject.cpman.ControlResource.Type; | ||
| 29 | -/** | ||
| 30 | - * Disk resource name completer. | ||
| 31 | - */ | ||
| 32 | -public class DiskResourceNameCompleter extends AbstractCompleter { | ||
| 33 | - @Override | ||
| 34 | - public int complete(String buffer, int cursor, List<String> candidates) { | ||
| 35 | - // delegate string completer | ||
| 36 | - StringsCompleter delegate = new StringsCompleter(); | ||
| 37 | - | ||
| 38 | - // Resource type is the second argument. | ||
| 39 | - ArgumentCompleter.ArgumentList list = getArgumentList(); | ||
| 40 | - String type = list.getArguments()[1]; | ||
| 41 | - | ||
| 42 | - if (Type.DISK.toString().toLowerCase().equals(type)) { | ||
| 43 | - ControlPlaneMonitorService monitorService = | ||
| 44 | - AbstractShellCommand.get(ControlPlaneMonitorService.class); | ||
| 45 | - | ||
| 46 | - Set<String> set = monitorService.availableResources(Type.DISK); | ||
| 47 | - SortedSet<String> strings = delegate.getStrings(); | ||
| 48 | - | ||
| 49 | - if (set != null) { | ||
| 50 | - set.forEach(s -> strings.add(s)); | ||
| 51 | - } | ||
| 52 | - } | ||
| 53 | - return delegate.complete(buffer, cursor, candidates); | ||
| 54 | - } | ||
| 55 | -} |
apps/cpman/app/src/main/java/org/onosproject/cpman/cli/NetworkResourceNameCompleter.java
deleted
100644 → 0
| 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.cpman.cli; | ||
| 17 | - | ||
| 18 | -import org.apache.karaf.shell.console.completer.ArgumentCompleter; | ||
| 19 | -import org.apache.karaf.shell.console.completer.StringsCompleter; | ||
| 20 | -import org.onosproject.cli.AbstractCompleter; | ||
| 21 | -import org.onosproject.cli.AbstractShellCommand; | ||
| 22 | -import org.onosproject.cpman.ControlPlaneMonitorService; | ||
| 23 | - | ||
| 24 | -import java.util.List; | ||
| 25 | -import java.util.Set; | ||
| 26 | -import java.util.SortedSet; | ||
| 27 | - | ||
| 28 | -import static org.onosproject.cpman.ControlResource.Type; | ||
| 29 | - | ||
| 30 | -/** | ||
| 31 | - * Network resource name completer. | ||
| 32 | - */ | ||
| 33 | -public class NetworkResourceNameCompleter extends AbstractCompleter { | ||
| 34 | - @Override | ||
| 35 | - public int complete(String buffer, int cursor, List<String> candidates) { | ||
| 36 | - // delegate string completer | ||
| 37 | - StringsCompleter delegate = new StringsCompleter(); | ||
| 38 | - | ||
| 39 | - // Resource type is the second argument. | ||
| 40 | - ArgumentCompleter.ArgumentList list = getArgumentList(); | ||
| 41 | - String type = list.getArguments()[1]; | ||
| 42 | - | ||
| 43 | - if (Type.NETWORK.toString().toLowerCase().equals(type)) { | ||
| 44 | - ControlPlaneMonitorService monitorService = | ||
| 45 | - AbstractShellCommand.get(ControlPlaneMonitorService.class); | ||
| 46 | - | ||
| 47 | - Set<String> set = monitorService.availableResources(Type.NETWORK); | ||
| 48 | - SortedSet<String> strings = delegate.getStrings(); | ||
| 49 | - | ||
| 50 | - if (set != null) { | ||
| 51 | - set.forEach(s -> strings.add(s)); | ||
| 52 | - } | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - return delegate.complete(buffer, cursor, candidates); | ||
| 56 | - } | ||
| 57 | -} |
| ... | @@ -15,22 +15,35 @@ | ... | @@ -15,22 +15,35 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.cpman.cli; | 16 | package org.onosproject.cpman.cli; |
| 17 | 17 | ||
| 18 | +import com.google.common.collect.ImmutableSet; | ||
| 19 | +import com.google.common.collect.Sets; | ||
| 18 | import org.apache.karaf.shell.console.completer.ArgumentCompleter; | 20 | import org.apache.karaf.shell.console.completer.ArgumentCompleter; |
| 19 | import org.apache.karaf.shell.console.completer.StringsCompleter; | 21 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
| 20 | import org.onosproject.cli.AbstractCompleter; | 22 | import org.onosproject.cli.AbstractCompleter; |
| 21 | import org.onosproject.cli.AbstractShellCommand; | 23 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.cpman.ControlPlaneMonitorService; | 24 | import org.onosproject.cpman.ControlPlaneMonitorService; |
| 25 | +import org.onosproject.cpman.ControlResource; | ||
| 26 | +import org.slf4j.Logger; | ||
| 27 | +import org.slf4j.LoggerFactory; | ||
| 23 | 28 | ||
| 24 | import java.util.List; | 29 | import java.util.List; |
| 25 | import java.util.Set; | 30 | import java.util.Set; |
| 26 | import java.util.SortedSet; | 31 | import java.util.SortedSet; |
| 27 | 32 | ||
| 28 | -import static org.onosproject.cpman.ControlResource.Type; | ||
| 29 | - | ||
| 30 | /** | 33 | /** |
| 31 | - * Device identification completer for control plane manager. | 34 | + * Resource name completer. |
| 32 | */ | 35 | */ |
| 33 | -public class ControlMessageDeviceIdCompleter extends AbstractCompleter { | 36 | +public class ResourceNameCompleter extends AbstractCompleter { |
| 37 | + | ||
| 38 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 39 | + | ||
| 40 | + private static final String NETWORK = "network"; | ||
| 41 | + private static final String DISK = "disk"; | ||
| 42 | + private static final String CONTROL_MESSAGE = "control_message"; | ||
| 43 | + Set<String> resourceTypes = ImmutableSet.of(NETWORK, DISK, CONTROL_MESSAGE); | ||
| 44 | + private static final String INVALID_MSG = "Invalid type name"; | ||
| 45 | + | ||
| 46 | + | ||
| 34 | @Override | 47 | @Override |
| 35 | public int complete(String buffer, int cursor, List<String> candidates) { | 48 | public int complete(String buffer, int cursor, List<String> candidates) { |
| 36 | // delegate string completer | 49 | // delegate string completer |
| ... | @@ -40,17 +53,33 @@ public class ControlMessageDeviceIdCompleter extends AbstractCompleter { | ... | @@ -40,17 +53,33 @@ public class ControlMessageDeviceIdCompleter extends AbstractCompleter { |
| 40 | ArgumentCompleter.ArgumentList list = getArgumentList(); | 53 | ArgumentCompleter.ArgumentList list = getArgumentList(); |
| 41 | String type = list.getArguments()[1]; | 54 | String type = list.getArguments()[1]; |
| 42 | 55 | ||
| 43 | - if (Type.CONTROL_MESSAGE.toString().toLowerCase().equals(type)) { | 56 | + if (resourceTypes.contains(type)) { |
| 44 | ControlPlaneMonitorService monitorService = | 57 | ControlPlaneMonitorService monitorService = |
| 45 | AbstractShellCommand.get(ControlPlaneMonitorService.class); | 58 | AbstractShellCommand.get(ControlPlaneMonitorService.class); |
| 46 | 59 | ||
| 47 | - Set<String> set = monitorService.availableResources(Type.CONTROL_MESSAGE); | 60 | + Set<String> set = Sets.newHashSet(); |
| 61 | + switch (type) { | ||
| 62 | + case NETWORK: | ||
| 63 | + set = monitorService.availableResources(ControlResource.Type.NETWORK); | ||
| 64 | + break; | ||
| 65 | + case DISK: | ||
| 66 | + set = monitorService.availableResources(ControlResource.Type.DISK); | ||
| 67 | + break; | ||
| 68 | + case CONTROL_MESSAGE: | ||
| 69 | + set = monitorService.availableResources(ControlResource.Type.CONTROL_MESSAGE); | ||
| 70 | + break; | ||
| 71 | + default: | ||
| 72 | + log.warn(INVALID_MSG); | ||
| 73 | + break; | ||
| 74 | + } | ||
| 48 | 75 | ||
| 49 | SortedSet<String> strings = delegate.getStrings(); | 76 | SortedSet<String> strings = delegate.getStrings(); |
| 50 | - if (set != null) { | 77 | + |
| 78 | + if (set.size() != 0) { | ||
| 51 | set.forEach(s -> strings.add(s)); | 79 | set.forEach(s -> strings.add(s)); |
| 52 | } | 80 | } |
| 53 | } | 81 | } |
| 82 | + | ||
| 54 | return delegate.complete(buffer, cursor, candidates); | 83 | return delegate.complete(buffer, cursor, candidates); |
| 55 | } | 84 | } |
| 56 | } | 85 | } | ... | ... |
| ... | @@ -20,15 +20,11 @@ | ... | @@ -20,15 +20,11 @@ |
| 20 | <action class="org.onosproject.cpman.cli.ControlMetricsStatsListCommand"/> | 20 | <action class="org.onosproject.cpman.cli.ControlMetricsStatsListCommand"/> |
| 21 | <completers> | 21 | <completers> |
| 22 | <ref component-id="controlResourceTypeCompleter"/> | 22 | <ref component-id="controlResourceTypeCompleter"/> |
| 23 | - <ref component-id="networkResourceNameCompleter"/> | 23 | + <ref component-id="resourceNameCompleter"/> |
| 24 | - <ref component-id="diskResourceNameCompleter"/> | ||
| 25 | - <ref component-id="controlMessageDeviceIdCompleter"/> | ||
| 26 | </completers> | 24 | </completers> |
| 27 | </command> | 25 | </command> |
| 28 | </command-bundle> | 26 | </command-bundle> |
| 29 | 27 | ||
| 30 | <bean id="controlResourceTypeCompleter" class="org.onosproject.cpman.cli.ControlResourceTypeCompleter"/> | 28 | <bean id="controlResourceTypeCompleter" class="org.onosproject.cpman.cli.ControlResourceTypeCompleter"/> |
| 31 | - <bean id="networkResourceNameCompleter" class="org.onosproject.cpman.cli.NetworkResourceNameCompleter"/> | 29 | + <bean id="resourceNameCompleter" class="org.onosproject.cpman.cli.ResourceNameCompleter"/> |
| 32 | - <bean id="diskResourceNameCompleter" class="org.onosproject.cpman.cli.DiskResourceNameCompleter"/> | ||
| 33 | - <bean id="controlMessageDeviceIdCompleter" class="org.onosproject.cpman.cli.ControlMessageDeviceIdCompleter"/> | ||
| 34 | </blueprint> | 30 | </blueprint> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment