[ONOS-3662] Add CLI for control plane manager
- Implement CLI for enumerating control plane metrics stats - Implement ControlResourceTypeCompleter - Implement DiskResourceNameCompleter - Implement NetworkResourceNameCompleter - Implement ControlMessageDeviceIdCompleter - Extract the control resource type and metrics in a separated class for the sake of simplicity. Change-Id: Ic505191a74bd463091b0e5c75e11f1824bafb816
Showing
15 changed files
with
564 additions
and
74 deletions
... | @@ -41,57 +41,57 @@ public enum ControlMetricType { | ... | @@ -41,57 +41,57 @@ public enum ControlMetricType { |
41 | /* Number of CPU cores. */ | 41 | /* Number of CPU cores. */ |
42 | NUM_OF_CORES, | 42 | NUM_OF_CORES, |
43 | 43 | ||
44 | - /* Number of CPUs. **/ | 44 | + /* Number of CPUs. */ |
45 | NUM_OF_CPUS, | 45 | NUM_OF_CPUS, |
46 | 46 | ||
47 | - /* CPU Speed. **/ | 47 | + /* CPU Speed. */ |
48 | CPU_SPEED, | 48 | CPU_SPEED, |
49 | 49 | ||
50 | - /* CPU Load. **/ | 50 | + /* CPU Load. */ |
51 | CPU_LOAD, | 51 | CPU_LOAD, |
52 | 52 | ||
53 | - /* Total Amount of CPU Up Time. **/ | 53 | + /* Total Amount of CPU Up Time. */ |
54 | TOTAL_CPU_TIME, | 54 | TOTAL_CPU_TIME, |
55 | 55 | ||
56 | - /* System CPU Up Time. **/ | 56 | + /* System CPU Up Time. */ |
57 | SYS_CPU_TIME, | 57 | SYS_CPU_TIME, |
58 | 58 | ||
59 | - /* User CPU Up Time. **/ | 59 | + /* User CPU Up Time. */ |
60 | USER_CPU_TIME, | 60 | USER_CPU_TIME, |
61 | 61 | ||
62 | - /* CPU Idle Time. **/ | 62 | + /* CPU Idle Time. */ |
63 | CPU_IDLE_TIME, | 63 | CPU_IDLE_TIME, |
64 | 64 | ||
65 | /* Ratio of Used Memory Amount. */ | 65 | /* Ratio of Used Memory Amount. */ |
66 | MEMORY_USED_RATIO, | 66 | MEMORY_USED_RATIO, |
67 | 67 | ||
68 | - /* Ratio of Free Memory Amount. **/ | 68 | + /* Ratio of Free Memory Amount. */ |
69 | MEMORY_FREE_RATIO, | 69 | MEMORY_FREE_RATIO, |
70 | 70 | ||
71 | - /* Used Memory Amount. **/ | 71 | + /* Used Memory Amount. */ |
72 | MEMORY_USED, | 72 | MEMORY_USED, |
73 | 73 | ||
74 | - /* Free Memory Amount. **/ | 74 | + /* Free Memory Amount. */ |
75 | MEMORY_FREE, | 75 | MEMORY_FREE, |
76 | 76 | ||
77 | - /* Total Amount of Memory. **/ | 77 | + /* Total Amount of Memory. */ |
78 | MEMORY_TOTAL, | 78 | MEMORY_TOTAL, |
79 | 79 | ||
80 | - /* Disk Read Bytes. **/ | 80 | + /* Disk Read Bytes. */ |
81 | DISK_READ_BYTES, | 81 | DISK_READ_BYTES, |
82 | 82 | ||
83 | - /* Disk Write Bytes. **/ | 83 | + /* Disk Write Bytes. */ |
84 | DISK_WRITE_BYTES, | 84 | DISK_WRITE_BYTES, |
85 | 85 | ||
86 | - /* Network Incoming Bytes. **/ | 86 | + /* Network Incoming Bytes. */ |
87 | NW_INCOMING_BYTES, | 87 | NW_INCOMING_BYTES, |
88 | 88 | ||
89 | - /* Network Outgoing Bytes. **/ | 89 | + /* Network Outgoing Bytes. */ |
90 | NW_OUTGOING_BYTES, | 90 | NW_OUTGOING_BYTES, |
91 | 91 | ||
92 | - /* Network Incoming Packets. **/ | 92 | + /* Network Incoming Packets. */ |
93 | NW_INCOMING_PACKETS, | 93 | NW_INCOMING_PACKETS, |
94 | 94 | ||
95 | - /* Network Outgoing Packets. **/ | 95 | + /* Network Outgoing Packets. */ |
96 | NW_OUTGOING_PACKETS | 96 | NW_OUTGOING_PACKETS |
97 | } | 97 | } | ... | ... |
... | @@ -19,6 +19,9 @@ import org.onosproject.cluster.NodeId; | ... | @@ -19,6 +19,9 @@ import org.onosproject.cluster.NodeId; |
19 | import org.onosproject.net.DeviceId; | 19 | import org.onosproject.net.DeviceId; |
20 | 20 | ||
21 | import java.util.Optional; | 21 | import java.util.Optional; |
22 | +import java.util.Set; | ||
23 | + | ||
24 | +import static org.onosproject.cpman.ControlResource.*; | ||
22 | 25 | ||
23 | /** | 26 | /** |
24 | * Control Plane Statistics Service Interface. | 27 | * Control Plane Statistics Service Interface. |
... | @@ -71,4 +74,11 @@ public interface ControlPlaneMonitorService { | ... | @@ -71,4 +74,11 @@ public interface ControlPlaneMonitorService { |
71 | * @return control plane load | 74 | * @return control plane load |
72 | */ | 75 | */ |
73 | ControlLoad getLoad(NodeId nodeId, ControlMetricType type, String resourceName); | 76 | ControlLoad getLoad(NodeId nodeId, ControlMetricType type, String resourceName); |
77 | + | ||
78 | + /** | ||
79 | + * Obtains a list of names of available resources. | ||
80 | + * | ||
81 | + * @return a collection of names of available resources | ||
82 | + */ | ||
83 | + Set<String> availableResources(Type resourceType); | ||
74 | } | 84 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
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; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableSet; | ||
19 | + | ||
20 | +import java.util.Set; | ||
21 | + | ||
22 | +import static org.onosproject.cpman.ControlMetricType.CPU_IDLE_TIME; | ||
23 | +import static org.onosproject.cpman.ControlMetricType.CPU_LOAD; | ||
24 | +import static org.onosproject.cpman.ControlMetricType.DISK_READ_BYTES; | ||
25 | +import static org.onosproject.cpman.ControlMetricType.DISK_WRITE_BYTES; | ||
26 | +import static org.onosproject.cpman.ControlMetricType.FLOW_MOD_PACKET; | ||
27 | +import static org.onosproject.cpman.ControlMetricType.FLOW_REMOVED_PACKET; | ||
28 | +import static org.onosproject.cpman.ControlMetricType.INBOUND_PACKET; | ||
29 | +import static org.onosproject.cpman.ControlMetricType.MEMORY_FREE; | ||
30 | +import static org.onosproject.cpman.ControlMetricType.MEMORY_FREE_RATIO; | ||
31 | +import static org.onosproject.cpman.ControlMetricType.MEMORY_USED; | ||
32 | +import static org.onosproject.cpman.ControlMetricType.MEMORY_USED_RATIO; | ||
33 | +import static org.onosproject.cpman.ControlMetricType.NW_INCOMING_BYTES; | ||
34 | +import static org.onosproject.cpman.ControlMetricType.NW_INCOMING_PACKETS; | ||
35 | +import static org.onosproject.cpman.ControlMetricType.NW_OUTGOING_BYTES; | ||
36 | +import static org.onosproject.cpman.ControlMetricType.NW_OUTGOING_PACKETS; | ||
37 | +import static org.onosproject.cpman.ControlMetricType.OUTBOUND_PACKET; | ||
38 | +import static org.onosproject.cpman.ControlMetricType.REPLY_PACKET; | ||
39 | +import static org.onosproject.cpman.ControlMetricType.REQUEST_PACKET; | ||
40 | +import static org.onosproject.cpman.ControlMetricType.SYS_CPU_TIME; | ||
41 | +import static org.onosproject.cpman.ControlMetricType.TOTAL_CPU_TIME; | ||
42 | +import static org.onosproject.cpman.ControlMetricType.USER_CPU_TIME; | ||
43 | + | ||
44 | +/** | ||
45 | + * A set of resource type used in control plane. | ||
46 | + */ | ||
47 | +public final class ControlResource { | ||
48 | + | ||
49 | + private ControlResource() {} | ||
50 | + | ||
51 | + /** | ||
52 | + * Control resource type. | ||
53 | + */ | ||
54 | + public enum Type { | ||
55 | + /* CPU resource */ | ||
56 | + CPU, | ||
57 | + | ||
58 | + /* Memory resource */ | ||
59 | + MEMORY, | ||
60 | + | ||
61 | + /* Disk resource */ | ||
62 | + DISK, | ||
63 | + | ||
64 | + /* Network resource */ | ||
65 | + NETWORK, | ||
66 | + | ||
67 | + /* Control message resource */ | ||
68 | + CONTROL_MESSAGE | ||
69 | + } | ||
70 | + | ||
71 | + /* A collection of CPU related metric types */ | ||
72 | + public static final Set<ControlMetricType> CPU_METRICS = | ||
73 | + ImmutableSet.of(CPU_IDLE_TIME, CPU_LOAD, SYS_CPU_TIME, | ||
74 | + USER_CPU_TIME, TOTAL_CPU_TIME); | ||
75 | + | ||
76 | + /* A collection of memory related metric types */ | ||
77 | + public static final Set<ControlMetricType> MEMORY_METRICS = | ||
78 | + ImmutableSet.of(MEMORY_FREE, MEMORY_FREE_RATIO, MEMORY_USED, | ||
79 | + MEMORY_USED_RATIO); | ||
80 | + | ||
81 | + /* A collection of disk related metric types */ | ||
82 | + public static final Set<ControlMetricType> DISK_METRICS = | ||
83 | + ImmutableSet.of(DISK_READ_BYTES, DISK_WRITE_BYTES); | ||
84 | + | ||
85 | + /* A collection of network related metric types */ | ||
86 | + public static final Set<ControlMetricType> NETWORK_METRICS = | ||
87 | + ImmutableSet.of(NW_INCOMING_BYTES, NW_OUTGOING_BYTES, | ||
88 | + NW_INCOMING_PACKETS, NW_OUTGOING_PACKETS); | ||
89 | + | ||
90 | + /* A collection of control message related metric types */ | ||
91 | + public static final Set<ControlMetricType> CONTROL_MESSAGE_METRICS = | ||
92 | + ImmutableSet.of(INBOUND_PACKET, OUTBOUND_PACKET, FLOW_MOD_PACKET, | ||
93 | + FLOW_REMOVED_PACKET, REQUEST_PACKET, REPLY_PACKET); | ||
94 | +} |
... | @@ -58,13 +58,14 @@ | ... | @@ -58,13 +58,14 @@ |
58 | <artifactId>onos-cli</artifactId> | 58 | <artifactId>onos-cli</artifactId> |
59 | <version>${project.version}</version> | 59 | <version>${project.version}</version> |
60 | </dependency> | 60 | </dependency> |
61 | - | ||
62 | <dependency> | 61 | <dependency> |
63 | <groupId>org.apache.karaf.shell</groupId> | 62 | <groupId>org.apache.karaf.shell</groupId> |
64 | <artifactId>org.apache.karaf.shell.console</artifactId> | 63 | <artifactId>org.apache.karaf.shell.console</artifactId> |
65 | - <scope>compile</scope> | ||
66 | </dependency> | 64 | </dependency> |
67 | - | 65 | + <dependency> |
66 | + <groupId>org.apache.felix</groupId> | ||
67 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
68 | + </dependency> | ||
68 | <dependency> | 69 | <dependency> |
69 | <groupId>org.onosproject</groupId> | 70 | <groupId>org.onosproject</groupId> |
70 | <artifactId>onlab-junit</artifactId> | 71 | <artifactId>onlab-junit</artifactId> |
... | @@ -180,6 +181,7 @@ | ... | @@ -180,6 +181,7 @@ |
180 | com.fasterxml.jackson.core, | 181 | com.fasterxml.jackson.core, |
181 | org.apache.karaf.shell.commands, | 182 | org.apache.karaf.shell.commands, |
182 | org.apache.karaf.shell.console, | 183 | org.apache.karaf.shell.console, |
184 | + org.apache.karaf.shell.console.completer, | ||
183 | com.google.common.*, | 185 | com.google.common.*, |
184 | org.onlab.packet.*, | 186 | org.onlab.packet.*, |
185 | org.onlab.rest.*, | 187 | org.onlab.rest.*, | ... | ... |
apps/cpman/app/src/main/java/org/onosproject/cpman/cli/ControlMessageDeviceIdCompleter.java
0 → 100644
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 | + * Device identification completer for control plane manager. | ||
32 | + */ | ||
33 | +public class ControlMessageDeviceIdCompleter 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.CONTROL_MESSAGE.toString().toLowerCase().equals(type)) { | ||
44 | + ControlPlaneMonitorService monitorService = | ||
45 | + AbstractShellCommand.get(ControlPlaneMonitorService.class); | ||
46 | + | ||
47 | + Set<String> set = monitorService.availableResources(Type.CONTROL_MESSAGE); | ||
48 | + | ||
49 | + SortedSet<String> strings = delegate.getStrings(); | ||
50 | + if (set != null) { | ||
51 | + set.forEach(s -> strings.add(s)); | ||
52 | + } | ||
53 | + } | ||
54 | + return delegate.complete(buffer, cursor, candidates); | ||
55 | + } | ||
56 | +} |
apps/cpman/app/src/main/java/org/onosproject/cpman/cli/ControlMetricsStatsListCommand.java
0 → 100644
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.commands.Argument; | ||
19 | +import org.apache.karaf.shell.commands.Command; | ||
20 | +import org.onosproject.cli.AbstractShellCommand; | ||
21 | +import org.onosproject.cluster.ClusterService; | ||
22 | +import org.onosproject.cluster.NodeId; | ||
23 | +import org.onosproject.cpman.ControlLoad; | ||
24 | +import org.onosproject.cpman.ControlMetricType; | ||
25 | +import org.onosproject.cpman.ControlPlaneMonitorService; | ||
26 | +import org.onosproject.net.DeviceId; | ||
27 | + | ||
28 | +import java.util.Optional; | ||
29 | +import java.util.Set; | ||
30 | + | ||
31 | +import static org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS; | ||
32 | +import static org.onosproject.cpman.ControlResource.CPU_METRICS; | ||
33 | +import static org.onosproject.cpman.ControlResource.DISK_METRICS; | ||
34 | +import static org.onosproject.cpman.ControlResource.MEMORY_METRICS; | ||
35 | +import static org.onosproject.cpman.ControlResource.NETWORK_METRICS; | ||
36 | + | ||
37 | +/** | ||
38 | + * Lists all stats information of control plane metrics. | ||
39 | + */ | ||
40 | +@Command(scope = "onos", name = "cpman-stats-list", | ||
41 | + description = "Lists control metrics statistics") | ||
42 | +public class ControlMetricsStatsListCommand extends AbstractShellCommand { | ||
43 | + | ||
44 | + private static final String FMT = "metricType=%s, latestValue=%d, " + | ||
45 | + "averageValue=%d, latestTime=%s"; | ||
46 | + private static final String INVALID_TYPE = "Invalid control resource type."; | ||
47 | + | ||
48 | + @Argument(index = 0, name = "type", | ||
49 | + description = "Resource type (cpu|memory|disk|network|control_message)", | ||
50 | + required = true, multiValued = false) | ||
51 | + String type = null; | ||
52 | + | ||
53 | + @Argument(index = 1, name = "name", description = "Resource name (or Device Id)", | ||
54 | + required = false, multiValued = false) | ||
55 | + String name = null; | ||
56 | + | ||
57 | + @Override | ||
58 | + protected void execute() { | ||
59 | + ControlPlaneMonitorService service = get(ControlPlaneMonitorService.class); | ||
60 | + ClusterService clusterService = get(ClusterService.class); | ||
61 | + NodeId nodeId = clusterService.getLocalNode().id(); | ||
62 | + switch (type) { | ||
63 | + case "cpu": | ||
64 | + printMetricsStats(service, nodeId, CPU_METRICS); | ||
65 | + break; | ||
66 | + case "memory": | ||
67 | + printMetricsStats(service, nodeId, MEMORY_METRICS); | ||
68 | + break; | ||
69 | + case "disk": | ||
70 | + printMetricsStats(service, nodeId, DISK_METRICS, name); | ||
71 | + break; | ||
72 | + case "network": | ||
73 | + printMetricsStats(service, nodeId, NETWORK_METRICS, name); | ||
74 | + break; | ||
75 | + case "control_message": | ||
76 | + if (name != null) { | ||
77 | + printMetricsStats(service, nodeId, CONTROL_MESSAGE_METRICS, DeviceId.deviceId(name)); | ||
78 | + } | ||
79 | + break; | ||
80 | + default: | ||
81 | + print(INVALID_TYPE); | ||
82 | + break; | ||
83 | + } | ||
84 | + } | ||
85 | + | ||
86 | + private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId, | ||
87 | + Set<ControlMetricType> typeSet) { | ||
88 | + printMetricsStats(service, nodeId, typeSet, null, null); | ||
89 | + } | ||
90 | + | ||
91 | + private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId, | ||
92 | + Set<ControlMetricType> typeSet, String name) { | ||
93 | + printMetricsStats(service, nodeId, typeSet, name, null); | ||
94 | + } | ||
95 | + | ||
96 | + private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId, | ||
97 | + Set<ControlMetricType> typeSet, DeviceId did) { | ||
98 | + printMetricsStats(service, nodeId, typeSet, null, did); | ||
99 | + } | ||
100 | + | ||
101 | + private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId, | ||
102 | + Set<ControlMetricType> typeSet, String name, DeviceId did) { | ||
103 | + if (name == null && did == null) { | ||
104 | + typeSet.forEach(s -> print(s, service.getLoad(nodeId, s, Optional.ofNullable(null)))); | ||
105 | + } else if (name == null && did != null) { | ||
106 | + typeSet.forEach(s -> print(s, service.getLoad(nodeId, s, Optional.of(did)))); | ||
107 | + } else if (name != null && did == null) { | ||
108 | + typeSet.forEach(s -> print(s, service.getLoad(nodeId, s, name))); | ||
109 | + } | ||
110 | + } | ||
111 | + | ||
112 | + private void print(ControlMetricType type, ControlLoad cl) { | ||
113 | + if (cl != null) { | ||
114 | + print(FMT, type.toString(), cl.latest(), cl.average(), cl.time()); | ||
115 | + } | ||
116 | + } | ||
117 | +} |
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 com.google.common.collect.ImmutableList; | ||
19 | +import org.onosproject.cli.AbstractChoicesCompleter; | ||
20 | + | ||
21 | +import java.util.List; | ||
22 | +import java.util.stream.Collectors; | ||
23 | + | ||
24 | +import static org.onosproject.cpman.ControlResource.Type; | ||
25 | + | ||
26 | +/** | ||
27 | + * Control resource type completer. | ||
28 | + */ | ||
29 | +public class ControlResourceTypeCompleter extends AbstractChoicesCompleter { | ||
30 | + | ||
31 | + private static final List<Type> RESOURCE_TYPES = | ||
32 | + ImmutableList.of(Type.CPU, Type.MEMORY, Type.DISK, Type.NETWORK, | ||
33 | + Type.CONTROL_MESSAGE); | ||
34 | + | ||
35 | + @Override | ||
36 | + protected List<String> choices() { | ||
37 | + return RESOURCE_TYPES.stream().map(type -> | ||
38 | + type.toString().toLowerCase()).collect(Collectors.toList()); | ||
39 | + } | ||
40 | +} |
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 | +} |
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 | +} |
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 | +/** | ||
17 | + * CLI implementation for control plane manager. | ||
18 | + */ | ||
19 | +package org.onosproject.cpman.cli; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
... | @@ -231,7 +231,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -231,7 +231,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
231 | } | 231 | } |
232 | 232 | ||
233 | public static final class Builder implements MetricsDatabase.Builder { | 233 | public static final class Builder implements MetricsDatabase.Builder { |
234 | - private static final int RESOLUTION = 60; // seconds | 234 | + private static final int RESOLUTION_IN_SECOND = 60; |
235 | private static final String STORING_METHOD = "MEMORY"; | 235 | private static final String STORING_METHOD = "MEMORY"; |
236 | private static final DsType SOURCE_TYPE = DsType.GAUGE; | 236 | private static final DsType SOURCE_TYPE = DsType.GAUGE; |
237 | private static final String DB_PATH = "CPMAN"; | 237 | private static final String DB_PATH = "CPMAN"; |
... | @@ -259,7 +259,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -259,7 +259,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
259 | this.metricName = metricName; | 259 | this.metricName = metricName; |
260 | 260 | ||
261 | // define the resolution of monitored metrics | 261 | // define the resolution of monitored metrics |
262 | - rrdDef = new RrdDef(DB_PATH + "_" + metricName, RESOLUTION); | 262 | + rrdDef = new RrdDef(DB_PATH + "_" + metricName, RESOLUTION_IN_SECOND); |
263 | return this; | 263 | return this; |
264 | } | 264 | } |
265 | 265 | ||
... | @@ -279,7 +279,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -279,7 +279,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
279 | IntStream.range(0, dsDefs.size()).forEach(i -> dsDefArray[i] = dsDefs.get(i)); | 279 | IntStream.range(0, dsDefs.size()).forEach(i -> dsDefArray[i] = dsDefs.get(i)); |
280 | 280 | ||
281 | rrdDef.addDatasource(dsDefArray); | 281 | rrdDef.addDatasource(dsDefArray); |
282 | - rrdDef.setStep(RESOLUTION); | 282 | + rrdDef.setStep(RESOLUTION_IN_SECOND); |
283 | 283 | ||
284 | // raw archive, no aggregation is required | 284 | // raw archive, no aggregation is required |
285 | ArcDef rawArchive = new ArcDef(CONSOL_FUNCTION, XFF_VALUE, | 285 | ArcDef rawArchive = new ArcDef(CONSOL_FUNCTION, XFF_VALUE, |
... | @@ -296,7 +296,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -296,7 +296,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
296 | } | 296 | } |
297 | 297 | ||
298 | private DsDef defineSchema(String metricType) { | 298 | private DsDef defineSchema(String metricType) { |
299 | - return new DsDef(metricType, SOURCE_TYPE, RESOLUTION, | 299 | + return new DsDef(metricType, SOURCE_TYPE, RESOLUTION_IN_SECOND, |
300 | MIN_VALUE, MAX_VALUE); | 300 | MIN_VALUE, MAX_VALUE); |
301 | } | 301 | } |
302 | } | 302 | } | ... | ... |
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 | +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> | ||
17 | + | ||
18 | + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> | ||
19 | + <command> | ||
20 | + <action class="org.onosproject.cpman.cli.ControlMetricsStatsListCommand"/> | ||
21 | + <completers> | ||
22 | + <ref component-id="controlResourceTypeCompleter"/> | ||
23 | + <ref component-id="networkResourceNameCompleter"/> | ||
24 | + <ref component-id="diskResourceNameCompleter"/> | ||
25 | + <ref component-id="controlMessageDeviceIdCompleter"/> | ||
26 | + </completers> | ||
27 | + </command> | ||
28 | + </command-bundle> | ||
29 | + | ||
30 | + <bean id="controlResourceTypeCompleter" class="org.onosproject.cpman.cli.ControlResourceTypeCompleter"/> | ||
31 | + <bean id="networkResourceNameCompleter" class="org.onosproject.cpman.cli.NetworkResourceNameCompleter"/> | ||
32 | + <bean id="diskResourceNameCompleter" class="org.onosproject.cpman.cli.DiskResourceNameCompleter"/> | ||
33 | + <bean id="controlMessageDeviceIdCompleter" class="org.onosproject.cpman.cli.ControlMessageDeviceIdCompleter"/> | ||
34 | +</blueprint> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -28,6 +28,7 @@ import org.onosproject.cpman.MetricValue; | ... | @@ -28,6 +28,7 @@ import org.onosproject.cpman.MetricValue; |
28 | import org.onosproject.net.DeviceId; | 28 | import org.onosproject.net.DeviceId; |
29 | 29 | ||
30 | import java.util.Optional; | 30 | import java.util.Optional; |
31 | +import java.util.Set; | ||
31 | 32 | ||
32 | import static org.easymock.EasyMock.anyObject; | 33 | import static org.easymock.EasyMock.anyObject; |
33 | import static org.easymock.EasyMock.createMock; | 34 | import static org.easymock.EasyMock.createMock; |
... | @@ -35,27 +36,8 @@ import static org.easymock.EasyMock.expect; | ... | @@ -35,27 +36,8 @@ import static org.easymock.EasyMock.expect; |
35 | import static org.easymock.EasyMock.replay; | 36 | import static org.easymock.EasyMock.replay; |
36 | import static org.hamcrest.Matchers.is; | 37 | import static org.hamcrest.Matchers.is; |
37 | import static org.junit.Assert.assertThat; | 38 | import static org.junit.Assert.assertThat; |
38 | -import static org.onosproject.cpman.ControlMetricType.CPU_IDLE_TIME; | 39 | + |
39 | -import static org.onosproject.cpman.ControlMetricType.CPU_LOAD; | 40 | +import static org.onosproject.cpman.ControlResource.*; |
40 | -import static org.onosproject.cpman.ControlMetricType.DISK_READ_BYTES; | ||
41 | -import static org.onosproject.cpman.ControlMetricType.DISK_WRITE_BYTES; | ||
42 | -import static org.onosproject.cpman.ControlMetricType.FLOW_MOD_PACKET; | ||
43 | -import static org.onosproject.cpman.ControlMetricType.FLOW_REMOVED_PACKET; | ||
44 | -import static org.onosproject.cpman.ControlMetricType.INBOUND_PACKET; | ||
45 | -import static org.onosproject.cpman.ControlMetricType.MEMORY_FREE; | ||
46 | -import static org.onosproject.cpman.ControlMetricType.MEMORY_FREE_RATIO; | ||
47 | -import static org.onosproject.cpman.ControlMetricType.MEMORY_USED; | ||
48 | -import static org.onosproject.cpman.ControlMetricType.MEMORY_USED_RATIO; | ||
49 | -import static org.onosproject.cpman.ControlMetricType.NW_INCOMING_BYTES; | ||
50 | -import static org.onosproject.cpman.ControlMetricType.NW_INCOMING_PACKETS; | ||
51 | -import static org.onosproject.cpman.ControlMetricType.NW_OUTGOING_BYTES; | ||
52 | -import static org.onosproject.cpman.ControlMetricType.NW_OUTGOING_PACKETS; | ||
53 | -import static org.onosproject.cpman.ControlMetricType.OUTBOUND_PACKET; | ||
54 | -import static org.onosproject.cpman.ControlMetricType.REPLY_PACKET; | ||
55 | -import static org.onosproject.cpman.ControlMetricType.REQUEST_PACKET; | ||
56 | -import static org.onosproject.cpman.ControlMetricType.SYS_CPU_TIME; | ||
57 | -import static org.onosproject.cpman.ControlMetricType.TOTAL_CPU_TIME; | ||
58 | -import static org.onosproject.cpman.ControlMetricType.USER_CPU_TIME; | ||
59 | 41 | ||
60 | /** | 42 | /** |
61 | * Unit test of control plane monitoring service. | 43 | * Unit test of control plane monitoring service. |
... | @@ -67,23 +49,12 @@ public class ControlPlaneMonitorTest { | ... | @@ -67,23 +49,12 @@ public class ControlPlaneMonitorTest { |
67 | private ClusterService mockClusterService; | 49 | private ClusterService mockClusterService; |
68 | private ControllerNode mockControllerNode; | 50 | private ControllerNode mockControllerNode; |
69 | private NodeId nodeId; | 51 | private NodeId nodeId; |
70 | - private static final ImmutableSet<ControlMetricType> CPU_METRICS = | ||
71 | - ImmutableSet.of(CPU_IDLE_TIME, CPU_LOAD, SYS_CPU_TIME, | ||
72 | - USER_CPU_TIME, TOTAL_CPU_TIME); | ||
73 | - private static final ImmutableSet<ControlMetricType> MEMORY_METRICS = | ||
74 | - ImmutableSet.of(MEMORY_FREE, MEMORY_FREE_RATIO, MEMORY_USED, | ||
75 | - MEMORY_USED_RATIO); | ||
76 | - private static final ImmutableSet<ControlMetricType> DISK_METRICS = | ||
77 | - ImmutableSet.of(DISK_READ_BYTES, DISK_WRITE_BYTES); | ||
78 | - private static final ImmutableSet<ControlMetricType> NETWORK_METRICS = | ||
79 | - ImmutableSet.of(NW_INCOMING_BYTES, NW_OUTGOING_BYTES, | ||
80 | - NW_INCOMING_PACKETS, NW_OUTGOING_PACKETS); | ||
81 | - private static final ImmutableSet<ControlMetricType> CTRL_MSGS = | ||
82 | - ImmutableSet.of(INBOUND_PACKET, OUTBOUND_PACKET, FLOW_MOD_PACKET, | ||
83 | - FLOW_REMOVED_PACKET, REQUEST_PACKET, REPLY_PACKET); | ||
84 | 52 | ||
53 | + /** | ||
54 | + * Sets up the services required by control plane monitor. | ||
55 | + */ | ||
85 | @Before | 56 | @Before |
86 | - public void setup() throws Exception { | 57 | + public void setup() { |
87 | monitor = new ControlPlaneMonitor(); | 58 | monitor = new ControlPlaneMonitor(); |
88 | monitor.activate(); | 59 | monitor.activate(); |
89 | 60 | ||
... | @@ -134,13 +105,13 @@ public class ControlPlaneMonitorTest { | ... | @@ -134,13 +105,13 @@ public class ControlPlaneMonitorTest { |
134 | assertThat(monitor.getLoad(nodeId, cmt, Optional.ofNullable(null)).latest(), is(mv.getLoad())); | 105 | assertThat(monitor.getLoad(nodeId, cmt, Optional.ofNullable(null)).latest(), is(mv.getLoad())); |
135 | } | 106 | } |
136 | 107 | ||
137 | - private void testUpdateMetricWithResource(ControlMetricType cmt, MetricValue mv, String resoureName) { | 108 | + private void testUpdateMetricWithResource(ControlMetricType cmt, MetricValue mv, String resourceName) { |
138 | ControlMetric cm = new ControlMetric(cmt, mv); | 109 | ControlMetric cm = new ControlMetric(cmt, mv); |
139 | - monitor.updateMetric(cm, UPDATE_INTERVAL, resoureName); | 110 | + monitor.updateMetric(cm, UPDATE_INTERVAL, resourceName); |
140 | } | 111 | } |
141 | 112 | ||
142 | - private void testLoadMetricWithResource(ControlMetricType cmt, MetricValue mv, String resoureName) { | 113 | + private void testLoadMetricWithResource(ControlMetricType cmt, MetricValue mv, String resourceName) { |
143 | - assertThat(monitor.getLoad(nodeId, cmt, resoureName).latest(), is(mv.getLoad())); | 114 | + assertThat(monitor.getLoad(nodeId, cmt, resourceName).latest(), is(mv.getLoad())); |
144 | } | 115 | } |
145 | 116 | ||
146 | private void testUpdateMetricWithId(ControlMetricType cmt, MetricValue mv, DeviceId did) { | 117 | private void testUpdateMetricWithId(ControlMetricType cmt, MetricValue mv, DeviceId did) { |
... | @@ -152,6 +123,9 @@ public class ControlPlaneMonitorTest { | ... | @@ -152,6 +123,9 @@ public class ControlPlaneMonitorTest { |
152 | assertThat(monitor.getLoad(nodeId, cmt, Optional.of(did)).latest(), is(mv.getLoad())); | 123 | assertThat(monitor.getLoad(nodeId, cmt, Optional.of(did)).latest(), is(mv.getLoad())); |
153 | } | 124 | } |
154 | 125 | ||
126 | + /** | ||
127 | + * Tests cpu metric update and load function. | ||
128 | + */ | ||
155 | @Test | 129 | @Test |
156 | public void testCpuMetric() { | 130 | public void testCpuMetric() { |
157 | MetricValue mv = new MetricValue.Builder().load(30).add(); | 131 | MetricValue mv = new MetricValue.Builder().load(30).add(); |
... | @@ -160,6 +134,9 @@ public class ControlPlaneMonitorTest { | ... | @@ -160,6 +134,9 @@ public class ControlPlaneMonitorTest { |
160 | CPU_METRICS.forEach(cmt -> testLoadMetricWithoutId(cmt, mv)); | 134 | CPU_METRICS.forEach(cmt -> testLoadMetricWithoutId(cmt, mv)); |
161 | } | 135 | } |
162 | 136 | ||
137 | + /** | ||
138 | + * Tests memory metric update and load function. | ||
139 | + */ | ||
163 | @Test | 140 | @Test |
164 | public void testMemoryMetric() { | 141 | public void testMemoryMetric() { |
165 | MetricValue mv = new MetricValue.Builder().load(40).add(); | 142 | MetricValue mv = new MetricValue.Builder().load(40).add(); |
... | @@ -168,11 +145,14 @@ public class ControlPlaneMonitorTest { | ... | @@ -168,11 +145,14 @@ public class ControlPlaneMonitorTest { |
168 | MEMORY_METRICS.forEach(cmt -> testLoadMetricWithoutId(cmt, mv)); | 145 | MEMORY_METRICS.forEach(cmt -> testLoadMetricWithoutId(cmt, mv)); |
169 | } | 146 | } |
170 | 147 | ||
148 | + /** | ||
149 | + * Tests disk metric update and load function. | ||
150 | + */ | ||
171 | @Test | 151 | @Test |
172 | public void testDiskMetric() { | 152 | public void testDiskMetric() { |
173 | MetricValue mv = new MetricValue.Builder().load(50).add(); | 153 | MetricValue mv = new MetricValue.Builder().load(50).add(); |
174 | 154 | ||
175 | - ImmutableSet<String> set = ImmutableSet.of("disk1", "disk2"); | 155 | + Set<String> set = ImmutableSet.of("disk1", "disk2"); |
176 | 156 | ||
177 | set.forEach(disk -> DISK_METRICS.forEach(cmt -> | 157 | set.forEach(disk -> DISK_METRICS.forEach(cmt -> |
178 | testUpdateMetricWithResource(cmt, mv, disk))); | 158 | testUpdateMetricWithResource(cmt, mv, disk))); |
... | @@ -181,11 +161,14 @@ public class ControlPlaneMonitorTest { | ... | @@ -181,11 +161,14 @@ public class ControlPlaneMonitorTest { |
181 | testLoadMetricWithResource(cmt, mv, disk))); | 161 | testLoadMetricWithResource(cmt, mv, disk))); |
182 | } | 162 | } |
183 | 163 | ||
164 | + /** | ||
165 | + * Tests network metric update and load function. | ||
166 | + */ | ||
184 | @Test | 167 | @Test |
185 | public void testNetworkMetric() { | 168 | public void testNetworkMetric() { |
186 | MetricValue mv = new MetricValue.Builder().load(10).add(); | 169 | MetricValue mv = new MetricValue.Builder().load(10).add(); |
187 | 170 | ||
188 | - ImmutableSet<String> set = ImmutableSet.of("eth0", "eth1"); | 171 | + Set<String> set = ImmutableSet.of("eth0", "eth1"); |
189 | 172 | ||
190 | set.forEach(network -> NETWORK_METRICS.forEach(cmt -> | 173 | set.forEach(network -> NETWORK_METRICS.forEach(cmt -> |
191 | testUpdateMetricWithResource(cmt, mv, network))); | 174 | testUpdateMetricWithResource(cmt, mv, network))); |
... | @@ -194,17 +177,40 @@ public class ControlPlaneMonitorTest { | ... | @@ -194,17 +177,40 @@ public class ControlPlaneMonitorTest { |
194 | testLoadMetricWithResource(cmt, mv, network))); | 177 | testLoadMetricWithResource(cmt, mv, network))); |
195 | } | 178 | } |
196 | 179 | ||
180 | + /** | ||
181 | + * Tests control message update and load function. | ||
182 | + */ | ||
197 | @Test | 183 | @Test |
198 | - public void testUpdateControlMessage() { | 184 | + public void testControlMessage() { |
199 | MetricValue mv = new MetricValue.Builder().load(10).add(); | 185 | MetricValue mv = new MetricValue.Builder().load(10).add(); |
186 | + Set<DeviceId> set = ImmutableSet.of(DeviceId.deviceId("of:0000000000000001"), | ||
187 | + DeviceId.deviceId("of:0000000000000002")); | ||
200 | 188 | ||
201 | - ImmutableSet<String> set = ImmutableSet.of("of:0000000000000001", | 189 | + set.forEach(devId -> CONTROL_MESSAGE_METRICS.forEach(cmt -> |
202 | - "of:0000000000000002"); | 190 | + testUpdateMetricWithId(cmt, mv, devId))); |
203 | 191 | ||
204 | - set.forEach(ctrlMsg -> CTRL_MSGS.forEach(cmt -> | 192 | + set.forEach(devId -> CONTROL_MESSAGE_METRICS.forEach(cmt -> |
205 | - testUpdateMetricWithId(cmt, mv, DeviceId.deviceId(ctrlMsg)))); | 193 | + testLoadMetricWithId(cmt, mv, devId))); |
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * Tests available resource update and load function. | ||
198 | + */ | ||
199 | + @Test | ||
200 | + public void testAvailableResources() { | ||
201 | + MetricValue mv = new MetricValue.Builder().load(50).add(); | ||
202 | + | ||
203 | + Set<String> diskSet = ImmutableSet.of("disk1", "disk2"); | ||
204 | + | ||
205 | + diskSet.forEach(disk -> DISK_METRICS.forEach(cmt -> | ||
206 | + testUpdateMetricWithResource(cmt, mv, disk))); | ||
207 | + | ||
208 | + Set<String> networkSet = ImmutableSet.of("eth0", "eth1"); | ||
209 | + | ||
210 | + networkSet.forEach(network -> NETWORK_METRICS.forEach(cmt -> | ||
211 | + testUpdateMetricWithResource(cmt, mv, network))); | ||
206 | 212 | ||
207 | - set.forEach(ctrlMsg -> CTRL_MSGS.forEach(cmt -> | 213 | + assertThat(monitor.availableResources(Type.DISK), is(diskSet)); |
208 | - testLoadMetricWithId(cmt, mv, DeviceId.deviceId(ctrlMsg)))); | 214 | + assertThat(monitor.availableResources(Type.NETWORK), is(networkSet)); |
209 | } | 215 | } |
210 | } | 216 | } | ... | ... |
... | @@ -39,7 +39,7 @@ public class MetricsDatabaseTest { | ... | @@ -39,7 +39,7 @@ public class MetricsDatabaseTest { |
39 | private static final String MEMORY_USED_PERC = "usedPerc"; | 39 | private static final String MEMORY_USED_PERC = "usedPerc"; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | - * Initializes the MetricsDatabase instance. | 42 | + * Initializes metrics database instance. |
43 | */ | 43 | */ |
44 | @Before | 44 | @Before |
45 | public void setUp() { | 45 | public void setUp() { | ... | ... |
-
Please register or login to post a comment