[ONOS-7732] Automating switch workflow: workflow cli command completeter
Change-Id: I226fd243279159af58e2803ff70113168a6b9cf4
diff --git a/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCommand.java b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCommand.java
index 5c0f5de..19856b3 100644
--- a/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCommand.java
+++ b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCommand.java
@@ -18,6 +18,7 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.apache.karaf.shell.api.action.Argument;
import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.workflow.api.DefaultWorkflowDescription;
@@ -33,10 +34,21 @@
@Command(scope = "onos", name = "workflow", description = "workflow cli")
public class WorkFlowCommand extends AbstractShellCommand {
- @Argument(index = 0, name = "cmd", description = "command(invoke|eval)", required = true)
+ static final String INVOKE = "invoke";
+ static final String EVAL = "eval";
+
+
+
+ @Argument(index = 0, name = "cmd",
+ description = "command(" + INVOKE + "|" + EVAL + "eval)",
+ required = true)
+ @Completion(WorkFlowCompleter.class)
private String cmd = null;
- @Argument(index = 1, name = "name", description = "workflow context name(workflow@workplace)", required = true)
+ @Argument(index = 1, name = "name",
+ description = "workflow context name(workflow@workplace)",
+ required = true)
+ @Completion(WorkFlowCtxtNameCompleter.class)
private String name = null;
@Override
@@ -61,10 +73,10 @@
String workplace = tokens[1];
switch (cmd) {
- case "invoke":
+ case INVOKE:
invoke(workflowId, workplace);
break;
- case "eval":
+ case EVAL:
eval(name);
break;
default:
diff --git a/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCompleter.java b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCompleter.java
new file mode 100644
index 0000000..1bba836
--- /dev/null
+++ b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCompleter.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.workflow.cli;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractChoicesCompleter;
+
+import java.util.List;
+
+import static org.onosproject.workflow.cli.WorkFlowCommand.EVAL;
+import static org.onosproject.workflow.cli.WorkFlowCommand.INVOKE;
+
+
+/**
+ * Workflow command completer.
+ */
+@Service
+public class WorkFlowCompleter extends AbstractChoicesCompleter {
+ @Override
+ protected List<String> choices() {
+ return ImmutableList.of(INVOKE, EVAL);
+ }
+}
diff --git a/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCtxtNameCompleter.java b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCtxtNameCompleter.java
new file mode 100644
index 0000000..7a972ff
--- /dev/null
+++ b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowCtxtNameCompleter.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.workflow.cli;
+
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractChoicesCompleter;
+import org.onosproject.workflow.api.WorkplaceStore;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.onlab.osgi.DefaultServiceDirectory.getService;
+
+/**
+ * Workflow context name completer.
+ */
+@Service
+public class WorkFlowCtxtNameCompleter extends AbstractChoicesCompleter {
+ @Override
+ protected List<String> choices() {
+ WorkplaceStore workplaceStore = getService(WorkplaceStore.class);
+ return workplaceStore.getContexts().stream()
+ .map(workplace -> workplace.name())
+ .collect(Collectors.toList());
+ }
+}