[ONOS-7732] Automating switch workflow: workflow cli command completeter

Change-Id: I226fd243279159af58e2803ff70113168a6b9cf4
This commit is contained in:
jaegonkim 2019-03-16 09:37:53 +09:00
parent 0f7897f917
commit fbf6143335
3 changed files with 92 additions and 4 deletions

View File

@ -18,6 +18,7 @@ package org.onosproject.workflow.cli;
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 @@ import java.util.Objects;
@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 @@ public class WorkFlowCommand extends AbstractShellCommand {
String workplace = tokens[1];
switch (cmd) {
case "invoke":
case INVOKE:
invoke(workflowId, workplace);
break;
case "eval":
case EVAL:
eval(name);
break;
default:

View File

@ -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);
}
}

View File

@ -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());
}
}