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.impl; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.config.Config; |
| 22 | import org.onosproject.workflow.api.DefaultRpcDescription; |
| 23 | import org.onosproject.workflow.api.RpcDescription; |
| 24 | import org.onosproject.workflow.api.WorkflowException; |
| 25 | import org.slf4j.Logger; |
| 26 | import org.slf4j.LoggerFactory; |
| 27 | |
| 28 | import java.util.ArrayList; |
| 29 | import java.util.Collection; |
| 30 | import java.util.List; |
| 31 | |
| 32 | |
| 33 | public class WorkflowNetConfig extends Config<ApplicationId> { |
| 34 | |
| 35 | private static final Logger log = LoggerFactory.getLogger(WorkflowNetConfig.class); |
| 36 | |
| 37 | /** |
| 38 | * Workflow RPC pointer. |
| 39 | */ |
| 40 | private static final String RPC_PTR = "/rpc"; |
| 41 | |
| 42 | public Collection<RpcDescription> getRpcDescriptions() throws WorkflowException { |
| 43 | |
| 44 | JsonNode node = object.at(RPC_PTR); |
| 45 | if (!(node instanceof ArrayNode)) { |
| 46 | throw new WorkflowException("invalid rpc for " + object); |
| 47 | } |
| 48 | ArrayNode rpcArrayNode = (ArrayNode) node; |
| 49 | |
| 50 | List<RpcDescription> rpcDescriptions = new ArrayList<>(); |
| 51 | for (JsonNode rpcNode : rpcArrayNode) { |
| 52 | rpcDescriptions.add(DefaultRpcDescription.valueOf(rpcNode)); |
| 53 | } |
| 54 | |
| 55 | return rpcDescriptions; |
| 56 | } |
| 57 | } |