jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.workflow.cli; |
| 17 | |
| 18 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
Ray Milkey | df52129 | 2018-10-04 15:13:33 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.Argument; |
| 22 | import org.apache.karaf.shell.api.action.Command; |
| 23 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 24 | import org.onosproject.cli.AbstractShellCommand; |
| 25 | import org.onosproject.workflow.api.ContextEventMapStore; |
| 26 | import org.onosproject.workflow.api.WorkflowException; |
| 27 | |
| 28 | import java.util.Arrays; |
| 29 | import java.util.Objects; |
| 30 | |
Ray Milkey | df52129 | 2018-10-04 15:13:33 -0700 | [diff] [blame] | 31 | @Service |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 32 | @Command(scope = "onos", name = "workflow-eventmap", description = "workflow event map cli") |
| 33 | public class WorkFlowEventMapCommand extends AbstractShellCommand { |
| 34 | |
Ray Milkey | df52129 | 2018-10-04 15:13:33 -0700 | [diff] [blame] | 35 | @Argument(index = 0, name = "cmd", description = "command(print)", required = true) |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 36 | private String cmd = null; |
| 37 | |
| 38 | @Override |
Ray Milkey | df52129 | 2018-10-04 15:13:33 -0700 | [diff] [blame] | 39 | protected void doExecute() { |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 40 | 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) { |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame^] | 54 | error("Exception: " + e.getMessage() + ", trace: " + Arrays.asList(e.getStackTrace())); |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 55 | } |
| 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 | } |