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; |
| 21 | import org.apache.karaf.shell.commands.Argument; |
| 22 | import org.apache.karaf.shell.commands.Command; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.workflow.api.ContextEventMapStore; |
| 25 | import org.onosproject.workflow.api.WorkflowException; |
| 26 | |
| 27 | import java.util.Arrays; |
| 28 | import java.util.Objects; |
| 29 | |
| 30 | @Command(scope = "onos", name = "workflow-eventmap", description = "workflow event map cli") |
| 31 | public 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 | } |