jcc | de3e92e | 2015-03-28 01:40:44 -0700 | [diff] [blame] | 1 | package org.onosproject.cli.net; |
| 2 | |
| 3 | import org.apache.karaf.shell.commands.Argument; |
| 4 | import org.apache.karaf.shell.commands.Command; |
| 5 | import org.onosproject.cli.AbstractShellCommand; |
| 6 | import org.onosproject.net.DeviceId; |
| 7 | import org.onosproject.net.resource.DefaultLabelResource; |
| 8 | import org.onosproject.net.resource.LabelResource; |
| 9 | import org.onosproject.net.resource.LabelResourceId; |
| 10 | import org.onosproject.net.resource.LabelResourceService; |
| 11 | |
| 12 | import com.google.common.collect.ArrayListMultimap; |
| 13 | import com.google.common.collect.Multimap; |
| 14 | |
| 15 | @Command(scope = "onos", name = "release-label-resource-pool", |
| 16 | description = "Releases label ids to label resource pool by a specific device id") |
| 17 | public class ReleaseLabelResourceCommand extends AbstractShellCommand { |
| 18 | @Argument(index = 0, name = "deviceId", |
| 19 | description = "Device identity", |
| 20 | required = true, multiValued = false) |
| 21 | String deviceId = null; |
| 22 | @Argument(index = 1, name = "releaseLabelIds", |
| 23 | description = "Represents for the label ids that are released. They are splited by dot symbol", |
| 24 | required = true, multiValued = false) |
| 25 | String releaseLabelIds = null; |
| 26 | |
| 27 | @Override |
| 28 | protected void execute() { |
| 29 | LabelResourceService lrs = get(LabelResourceService.class); |
| 30 | Multimap<DeviceId, LabelResource> map = ArrayListMultimap |
| 31 | .create(); |
| 32 | String[] labelIds = releaseLabelIds.split(","); |
| 33 | DefaultLabelResource resource = null; |
| 34 | for (int i = 0; i < labelIds.length; i++) { |
| 35 | resource = new DefaultLabelResource( |
| 36 | DeviceId.deviceId(deviceId), |
| 37 | LabelResourceId.labelResourceId(Long |
| 38 | .parseLong(labelIds[i]))); |
| 39 | map.put(DeviceId.deviceId(deviceId), resource); |
| 40 | } |
| 41 | lrs.releaseToDevicePool(map); |
| 42 | } |
| 43 | |
| 44 | } |