blob: d1e37c835ba701efbb1cc0d6180ae58fb7e55ecf [file] [log] [blame]
jaegonkim6a7b5242018-09-12 23:09:42 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16package org.onosproject.workflow.cli;
17
Ray Milkeydf521292018-10-04 15:13:33 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
jaegonkim6a7b5242018-09-12 23:09:42 +090021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.workflow.api.Workflow;
23import org.onosproject.workflow.api.WorkflowStore;
24
25import java.util.Objects;
26import java.net.URI;
27
Ray Milkeydf521292018-10-04 15:13:33 -070028@Service
jaegonkim6a7b5242018-09-12 23:09:42 +090029@Command(scope = "onos", name = "workflowstore", description = "workflow store cli")
30public class WorkFlowStoreCommand extends AbstractShellCommand {
31
Ray Milkeydf521292018-10-04 15:13:33 -070032 @Argument(index = 0, name = "cmd", description = "command(rm)", required = false)
jaegonkim6a7b5242018-09-12 23:09:42 +090033 private String cmd = null;
34
jaegonkime0f45b52018-10-09 20:23:26 +090035 @Argument(index = 1, name = "id", description = "workflow id(URI)", required = false)
jaegonkim6a7b5242018-09-12 23:09:42 +090036 private String id = null;
37
38 @Override
Ray Milkeydf521292018-10-04 15:13:33 -070039 protected void doExecute() {
jaegonkim6a7b5242018-09-12 23:09:42 +090040
41 if (Objects.isNull(cmd)) {
42 printAllWorkflow();
43 return;
44 }
45
46 if (Objects.isNull(id)) {
47 print("invalid id");
48 return;
49 }
50
51 switch (cmd) {
52 case "rm":
53 rmWorkflow(id);
54 break;
55 default:
56 print("Unsupported cmd: " + cmd);
57 }
58 }
59
60 private void rmWorkflow(String id) {
61 WorkflowStore workflowStore = get(WorkflowStore.class);
62 workflowStore.unregister(URI.create(id));
63 }
64
65 private void printAllWorkflow() {
66 WorkflowStore workflowStore = get(WorkflowStore.class);
67 for (Workflow workflow : workflowStore.getAll()) {
68 print(getWorkflowString(workflow));
69 }
70 }
71
72 private String getWorkflowString(Workflow workflow) {
73 return workflow.toString();
74 }
75}