blob: 5240252a6185a0be705b433c4a6e1fae0a186035 [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;
Ray Milkeydf521292018-10-04 15:13:33 -070021import org.apache.karaf.shell.api.action.Argument;
22import org.apache.karaf.shell.api.action.Command;
23import org.apache.karaf.shell.api.action.lifecycle.Service;
jaegonkim6a7b5242018-09-12 23:09:42 +090024import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.workflow.api.ContextEventMapStore;
26import org.onosproject.workflow.api.WorkflowException;
27
28import java.util.Arrays;
29import java.util.Objects;
30
Ray Milkeydf521292018-10-04 15:13:33 -070031@Service
jaegonkim6a7b5242018-09-12 23:09:42 +090032@Command(scope = "onos", name = "workflow-eventmap", description = "workflow event map cli")
33public class WorkFlowEventMapCommand extends AbstractShellCommand {
34
Ray Milkeydf521292018-10-04 15:13:33 -070035 @Argument(index = 0, name = "cmd", description = "command(print)", required = true)
jaegonkim6a7b5242018-09-12 23:09:42 +090036 private String cmd = null;
37
38 @Override
Ray Milkeydf521292018-10-04 15:13:33 -070039 protected void doExecute() {
jaegonkim6a7b5242018-09-12 23:09:42 +090040 if (Objects.isNull(cmd)) {
41 error("invalid cmd parameter");
42 return;
43 }
44
45 ContextEventMapStore store = get(ContextEventMapStore.class);
46 try {
47 switch (cmd) {
48 case "print":
49 JsonNode tree = store.asJsonTree();
50 ObjectMapper mapper = new ObjectMapper();
51 try {
52 print(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tree));
53 } catch (JsonProcessingException e) {
jaegonkime0f45b52018-10-09 20:23:26 +090054 error("Exception: " + e.getMessage() + ", trace: " + Arrays.asList(e.getStackTrace()));
jaegonkim6a7b5242018-09-12 23:09:42 +090055 }
56 break;
57
58 default:
59 print("Unsupported cmd: " + cmd);
60 }
61 } catch (WorkflowException e) {
62 error(e.getMessage() + ", trace: " + Arrays.asList(e.getStackTrace()));
63 }
64 }
65}