blob: 2bca555f7e6453fcb7214c90af3ef64165dde1e4 [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.impl;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ArrayNode;
20import org.onosproject.core.ApplicationId;
21import org.onosproject.net.config.Config;
22import org.onosproject.workflow.api.DefaultRpcDescription;
23import org.onosproject.workflow.api.RpcDescription;
24import org.onosproject.workflow.api.WorkflowException;
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
28import java.util.ArrayList;
29import java.util.Collection;
30import java.util.List;
31
32
33public 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}