ONOS-1058 - Add application Id to intent withdraw command
Change-Id: I6f660f2e115e4acc9d3c7d1ab2e2115caaf1822f
Showing
11 changed files
with
154 additions
and
8 deletions
| ... | @@ -59,6 +59,10 @@ | ... | @@ -59,6 +59,10 @@ |
| 59 | <groupId>org.apache.karaf.shell</groupId> | 59 | <groupId>org.apache.karaf.shell</groupId> |
| 60 | <artifactId>org.apache.karaf.shell.console</artifactId> | 60 | <artifactId>org.apache.karaf.shell.console</artifactId> |
| 61 | </dependency> | 61 | </dependency> |
| 62 | + <dependency> | ||
| 63 | + <groupId>org.apache.felix</groupId> | ||
| 64 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
| 65 | + </dependency> | ||
| 62 | </dependencies> | 66 | </dependencies> |
| 63 | 67 | ||
| 64 | <build> | 68 | <build> |
| ... | @@ -67,6 +71,11 @@ | ... | @@ -67,6 +71,11 @@ |
| 67 | <groupId>org.apache.felix</groupId> | 71 | <groupId>org.apache.felix</groupId> |
| 68 | <artifactId>maven-bundle-plugin</artifactId> | 72 | <artifactId>maven-bundle-plugin</artifactId> |
| 69 | </plugin> | 73 | </plugin> |
| 74 | + | ||
| 75 | + <plugin> | ||
| 76 | + <groupId>org.apache.felix</groupId> | ||
| 77 | + <artifactId>maven-scr-plugin</artifactId> | ||
| 78 | + </plugin> | ||
| 70 | </plugins> | 79 | </plugins> |
| 71 | </build> | 80 | </build> |
| 72 | 81 | ... | ... |
| ... | @@ -52,7 +52,8 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { | ... | @@ -52,7 +52,8 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { |
| 52 | * @return command-line application identifier | 52 | * @return command-line application identifier |
| 53 | */ | 53 | */ |
| 54 | protected ApplicationId appId() { | 54 | protected ApplicationId appId() { |
| 55 | - return get(CoreService.class).registerApplication("org.onosproject.cli"); | 55 | + return get(CoreService.class) |
| 56 | + .registerApplication("org.onosproject.cli"); | ||
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | /** | 59 | /** | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 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.cli; | ||
| 17 | + | ||
| 18 | +import org.apache.felix.scr.annotations.Activate; | ||
| 19 | +import org.apache.felix.scr.annotations.Component; | ||
| 20 | +import org.apache.felix.scr.annotations.Reference; | ||
| 21 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 22 | +import org.onosproject.core.CoreService; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * OSGI Component for the ONOS CLI. | ||
| 26 | + */ | ||
| 27 | + | ||
| 28 | +@Component(immediate = true) | ||
| 29 | +public class CliComponent { | ||
| 30 | + | ||
| 31 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 32 | + protected CoreService coreService; | ||
| 33 | + | ||
| 34 | + @Activate | ||
| 35 | + public void activate() { | ||
| 36 | + coreService | ||
| 37 | + .registerApplication("org.onosproject.cli"); | ||
| 38 | + } | ||
| 39 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 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.cli.app; | ||
| 17 | + | ||
| 18 | +import java.util.List; | ||
| 19 | +import java.util.Set; | ||
| 20 | +import java.util.SortedSet; | ||
| 21 | + | ||
| 22 | +import org.apache.karaf.shell.console.Completer; | ||
| 23 | +import org.apache.karaf.shell.console.completer.StringsCompleter; | ||
| 24 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 25 | +import org.onosproject.core.ApplicationId; | ||
| 26 | +import org.onosproject.core.CoreService; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Application name completer. | ||
| 30 | + */ | ||
| 31 | +public class ApplicationIdNameCompleter implements Completer { | ||
| 32 | + @Override | ||
| 33 | + public int complete(String buffer, int cursor, List<String> candidates) { | ||
| 34 | + // Delegate string completer | ||
| 35 | + StringsCompleter delegate = new StringsCompleter(); | ||
| 36 | + | ||
| 37 | + // Fetch our service and feed it's offerings to the string completer | ||
| 38 | + CoreService service = AbstractShellCommand.get(CoreService.class); | ||
| 39 | + Set<ApplicationId> ids = service.getAppIds(); | ||
| 40 | + SortedSet<String> strings = delegate.getStrings(); | ||
| 41 | + for (ApplicationId id : ids) { | ||
| 42 | + strings.add(id.name()); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + // Now let the completer do the work for figuring out what to offer. | ||
| 46 | + return delegate.complete(buffer, cursor, candidates); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | +} |
| ... | @@ -18,6 +18,8 @@ package org.onosproject.cli.net; | ... | @@ -18,6 +18,8 @@ package org.onosproject.cli.net; |
| 18 | import org.apache.karaf.shell.commands.Argument; | 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; | 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; | 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | +import org.onosproject.core.ApplicationId; | ||
| 22 | +import org.onosproject.core.CoreService; | ||
| 21 | import org.onosproject.net.intent.Intent; | 23 | import org.onosproject.net.intent.Intent; |
| 22 | import org.onosproject.net.intent.IntentService; | 24 | import org.onosproject.net.intent.IntentService; |
| 23 | import org.onosproject.net.intent.Key; | 25 | import org.onosproject.net.intent.Key; |
| ... | @@ -25,28 +27,44 @@ import org.onosproject.net.intent.Key; | ... | @@ -25,28 +27,44 @@ import org.onosproject.net.intent.Key; |
| 25 | import java.math.BigInteger; | 27 | import java.math.BigInteger; |
| 26 | 28 | ||
| 27 | /** | 29 | /** |
| 28 | - * Removes host-to-host connectivity intent. | 30 | + * Removes an intent. |
| 29 | */ | 31 | */ |
| 30 | @Command(scope = "onos", name = "remove-intent", | 32 | @Command(scope = "onos", name = "remove-intent", |
| 31 | description = "Removes the specified intent") | 33 | description = "Removes the specified intent") |
| 32 | public class IntentRemoveCommand extends AbstractShellCommand { | 34 | public class IntentRemoveCommand extends AbstractShellCommand { |
| 33 | 35 | ||
| 34 | - @Argument(index = 0, name = "id", description = "Intent ID", | 36 | + @Argument(index = 0, name = "app", |
| 37 | + description = "Application ID", | ||
| 38 | + required = true, multiValued = false) | ||
| 39 | + String applicationIdString = null; | ||
| 40 | + | ||
| 41 | + @Argument(index = 1, name = "id", | ||
| 42 | + description = "Intent ID", | ||
| 35 | required = true, multiValued = false) | 43 | required = true, multiValued = false) |
| 36 | String id = null; | 44 | String id = null; |
| 37 | 45 | ||
| 38 | @Override | 46 | @Override |
| 39 | protected void execute() { | 47 | protected void execute() { |
| 40 | - IntentService service = get(IntentService.class); | 48 | + IntentService intentService = get(IntentService.class); |
| 49 | + CoreService coreService = get(CoreService.class); | ||
| 50 | + | ||
| 51 | + ApplicationId appId = appId(); | ||
| 52 | + if (applicationIdString != null) { | ||
| 53 | + appId = coreService.getAppId(applicationIdString); | ||
| 54 | + if (appId == null) { | ||
| 55 | + print("Cannot find application Id %s", applicationIdString); | ||
| 56 | + return; | ||
| 57 | + } | ||
| 58 | + } | ||
| 41 | 59 | ||
| 42 | if (id.startsWith("0x")) { | 60 | if (id.startsWith("0x")) { |
| 43 | id = id.replaceFirst("0x", ""); | 61 | id = id.replaceFirst("0x", ""); |
| 44 | } | 62 | } |
| 45 | 63 | ||
| 46 | - Key key = Key.of(new BigInteger(id, 16).longValue(), appId()); | 64 | + Key key = Key.of(new BigInteger(id, 16).longValue(), appId); |
| 47 | - Intent intent = service.getIntent(key); | 65 | + Intent intent = intentService.getIntent(key); |
| 48 | if (intent != null) { | 66 | if (intent != null) { |
| 49 | - service.withdraw(intent); | 67 | + intentService.withdraw(intent); |
| 50 | } | 68 | } |
| 51 | } | 69 | } |
| 52 | } | 70 | } | ... | ... |
| ... | @@ -130,6 +130,7 @@ | ... | @@ -130,6 +130,7 @@ |
| 130 | <command> | 130 | <command> |
| 131 | <action class="org.onosproject.cli.net.IntentRemoveCommand"/> | 131 | <action class="org.onosproject.cli.net.IntentRemoveCommand"/> |
| 132 | <completers> | 132 | <completers> |
| 133 | + <ref component-id="appIdNameCompleter" /> | ||
| 133 | <ref component-id="intentIdCompleter"/> | 134 | <ref component-id="intentIdCompleter"/> |
| 134 | <null/> | 135 | <null/> |
| 135 | </completers> | 136 | </completers> |
| ... | @@ -279,6 +280,7 @@ | ... | @@ -279,6 +280,7 @@ |
| 279 | </command-bundle> | 280 | </command-bundle> |
| 280 | 281 | ||
| 281 | <bean id="appNameCompleter" class="org.onosproject.cli.app.ApplicationNameCompleter"/> | 282 | <bean id="appNameCompleter" class="org.onosproject.cli.app.ApplicationNameCompleter"/> |
| 283 | + <bean id="appIdNameCompleter" class="org.onosproject.cli.app.ApplicationIdNameCompleter"/> | ||
| 282 | <bean id="nodeIdCompleter" class="org.onosproject.cli.NodeIdCompleter"/> | 284 | <bean id="nodeIdCompleter" class="org.onosproject.cli.NodeIdCompleter"/> |
| 283 | <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> | 285 | <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> |
| 284 | <bean id="clusterIdCompleter" class="org.onosproject.cli.net.ClusterIdCompleter"/> | 286 | <bean id="clusterIdCompleter" class="org.onosproject.cli.net.ClusterIdCompleter"/> | ... | ... |
| ... | @@ -49,6 +49,13 @@ public interface CoreService { | ... | @@ -49,6 +49,13 @@ public interface CoreService { |
| 49 | ApplicationId getAppId(Short id); | 49 | ApplicationId getAppId(Short id); |
| 50 | 50 | ||
| 51 | /** | 51 | /** |
| 52 | + * Returns an existing application id from a given id. | ||
| 53 | + * @param name the name portion of the ID to look up | ||
| 54 | + * @return an application id | ||
| 55 | + */ | ||
| 56 | + ApplicationId getAppId(String name); | ||
| 57 | + | ||
| 58 | + /** | ||
| 52 | * Registers a new application by its name, which is expected | 59 | * Registers a new application by its name, which is expected |
| 53 | * to follow the reverse DNS convention, e.g. | 60 | * to follow the reverse DNS convention, e.g. |
| 54 | * {@code org.flying.circus.app} | 61 | * {@code org.flying.circus.app} | ... | ... |
| ... | @@ -38,6 +38,11 @@ public class CoreServiceAdapter implements CoreService { | ... | @@ -38,6 +38,11 @@ public class CoreServiceAdapter implements CoreService { |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | @Override | 40 | @Override |
| 41 | + public ApplicationId getAppId(String name) { | ||
| 42 | + return null; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @Override | ||
| 41 | public ApplicationId registerApplication(String identifier) { | 46 | public ApplicationId registerApplication(String identifier) { |
| 42 | return null; | 47 | return null; |
| 43 | } | 48 | } | ... | ... |
| ... | @@ -74,6 +74,12 @@ public class CoreManager implements CoreService { | ... | @@ -74,6 +74,12 @@ public class CoreManager implements CoreService { |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | @Override | 76 | @Override |
| 77 | + public ApplicationId getAppId(String name) { | ||
| 78 | + return applicationIdStore.getAppId(name); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + | ||
| 82 | + @Override | ||
| 77 | public ApplicationId registerApplication(String name) { | 83 | public ApplicationId registerApplication(String name) { |
| 78 | checkNotNull(name, "Application ID cannot be null"); | 84 | checkNotNull(name, "Application ID cannot be null"); |
| 79 | return applicationIdStore.registerApplication(name); | 85 | return applicationIdStore.registerApplication(name); | ... | ... |
| ... | @@ -34,7 +34,12 @@ public class TestCoreManager implements CoreService { | ... | @@ -34,7 +34,12 @@ public class TestCoreManager implements CoreService { |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | @Override | 36 | @Override |
| 37 | - public ApplicationId getAppId(Short id) { | 37 | + public ApplicationId getAppId(Short id) { |
| 38 | + return null; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public ApplicationId getAppId(String name) { | ||
| 38 | return null; | 43 | return null; |
| 39 | } | 44 | } |
| 40 | 45 | ... | ... |
| ... | @@ -600,6 +600,11 @@ public class FlowRuleManagerTest { | ... | @@ -600,6 +600,11 @@ public class FlowRuleManagerTest { |
| 600 | } | 600 | } |
| 601 | 601 | ||
| 602 | @Override | 602 | @Override |
| 603 | + public ApplicationId getAppId(String name) { | ||
| 604 | + return null; | ||
| 605 | + } | ||
| 606 | + | ||
| 607 | + @Override | ||
| 603 | public ApplicationId registerApplication(String identifier) { | 608 | public ApplicationId registerApplication(String identifier) { |
| 604 | return null; | 609 | return null; |
| 605 | } | 610 | } | ... | ... |
-
Please register or login to post a comment