blob: 0a8e492d45b5a98fe327ed0d5ef876e05c1980b8 [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
18import com.fasterxml.jackson.core.JsonProcessingException;
19import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import org.apache.karaf.shell.commands.Argument;
22import org.apache.karaf.shell.commands.Command;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.workflow.api.ContextEventMapStore;
25import org.onosproject.workflow.api.WorkflowException;
26
27import java.util.Arrays;
28import java.util.Objects;
29
30@Command(scope = "onos", name = "workflow-eventmap", description = "workflow event map cli")
31public class WorkFlowEventMapCommand extends AbstractShellCommand {
32
33 @Argument (index = 0, name = "cmd", description = "command(print)", required = true)
34 private String cmd = null;
35
36 @Override
37 protected void execute() {
38 if (Objects.isNull(cmd)) {
39 error("invalid cmd parameter");
40 return;
41 }
42
43 ContextEventMapStore store = get(ContextEventMapStore.class);
44 try {
45 switch (cmd) {
46 case "print":
47 JsonNode tree = store.asJsonTree();
48 ObjectMapper mapper = new ObjectMapper();
49 try {
50 print(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tree));
51 } catch (JsonProcessingException e) {
52 error(e.getMessage() + ", trace: " + Arrays.asList(e.getStackTrace()));
53 }
54 break;
55
56 default:
57 print("Unsupported cmd: " + cmd);
58 }
59 } catch (WorkflowException e) {
60 error(e.getMessage() + ", trace: " + Arrays.asList(e.getStackTrace()));
61 }
62 }
63}