blob: 3746b5f37a239bfd2588de23be61fddcf6aa9a50 [file] [log] [blame]
m.rahilb2e9cd92019-08-05 23:58:27 +05301/*
2 * Copyright 2019-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
18import com.fasterxml.jackson.databind.JsonNode;
19import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.workflow.api.WorkplaceStore;
24import org.onosproject.workflow.api.WorkflowStore;
25import org.onosproject.workflow.api.WorkflowContext;
26import org.onosproject.workflow.api.Workflow;
27import org.onosproject.workflow.api.JsonDataModelTree;
28import org.onosproject.workflow.api.WorkflowException;
29
30
31import java.util.Objects;
32
33@Service
34@Command(scope = "onos", name = "workflow-nodes", description = "workflow status cli")
35public class WorkflowStatusCommand extends AbstractShellCommand {
36
37 static final String STATUS = "status";
38
39 @Argument(index = 0, name = "cmd",
40 description = "command(" + STATUS + "eval)",
41 required = true)
42 private String cmd = null;
43
44 @Override
45 protected void doExecute() {
46 if (Objects.isNull(cmd)) {
47 error("invalid cmd parameter");
48 return;
49 }
50
51
52 switch (cmd) {
53 case STATUS:
54 invoke();
55 break;
56 default:
57 print("Unsupported cmd: " + cmd);
58 }
59 }
60
61
62 private void invoke() {
63 try {
64 WorkflowStore workflowStore = get(WorkflowStore.class);
65 WorkplaceStore workplaceStore = get(WorkplaceStore.class);
66 System.out.printf("%-25s %-45s %-10s%n", "DEVICEIP", " WORKFLOW NAME", "WORKFLOW STATE");
67 for (WorkflowContext context : workplaceStore.getContexts()) {
68 for (Workflow workflow : workflowStore.getAll()) {
69 if (context.workflowId().equals(workflow.id())) {
70 JsonDataModelTree tree = (JsonDataModelTree) context.data();
71 JsonNode mgmtIp = tree.nodeAt("/mgmtIp");
72 System.out.printf("%-25s %-45s %-10s%n", mgmtIp, context.name(), context.state().toString());
73 }
74
75 }
76 }
77
78 } catch (WorkflowException e) {
79 e.printStackTrace();
80 }
81
82 }
83}
84