2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.sli.adaptors.aai;
24 import java.io.UnsupportedEncodingException;
25 import java.net.MalformedURLException;
27 import java.util.Properties;
29 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
30 import org.openecomp.aai.inventory.v10.LInterface;
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class LInterfaceRequest extends AAIRequest {
38 public static final String LAGINTERFACE_LINTERFACE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.lag.interface.l.interface";
39 public static final String LAGINTERFACE_LINTERFACE_QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.lag.interface.l.interface.query";
41 public static final String P_INTERFACE_LINTERFACE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.p.interface.l.interface";
42 public static final String P_INTERFACE_LINTERFACE_QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.p.interface.l.interface.query";
44 public static final String LAGINTERFACE_LINTERFACE_PNF_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.lag.interface.l.interface.pnf";
45 public static final String P_INTERFACE_LINTERFACE_PNF_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.p.interface.l.interface.pnf";
47 private final String laginterface_linterface_path;
48 private final String laginterface_linterface_query_path;
49 private final String p_interface_linterface_path;
50 private final String p_interface_linterface_query_path;
52 private final String laginterface_linterface_pnf_path;
53 private final String p_interface_linterface_pnf_path;
55 public static final String INTERFACE_NAME = "interface-name";
56 public static final String LINTERFACE_INTERFACE_NAME = "l-interface.interface-name";
57 public static final String LAG_INTERFACE_INTERFACE_NAME = "lag-interface.interface-name";
58 public static final String P_INTERFACE_INTERFACE_NAME = "p-interface.interface-name";
59 public static final String PNF_PNF_NAME = "pnf.pnf-name";
61 public static final String ROUTER_NAME = "router-name";
62 public static final String HOSTNAME = "hostname";
65 public static enum TYPE { L2_BRIDGE_BGF, L2_BRIDGE_SBG};
67 private final TYPE type;
69 public LInterfaceRequest(TYPE type) {
72 laginterface_linterface_path = configProperties.getProperty(LAGINTERFACE_LINTERFACE_PATH);
73 laginterface_linterface_query_path = configProperties.getProperty(LAGINTERFACE_LINTERFACE_QUERY_PATH);
75 p_interface_linterface_path = configProperties.getProperty(P_INTERFACE_LINTERFACE_PATH);
76 p_interface_linterface_query_path = configProperties.getProperty(P_INTERFACE_LINTERFACE_QUERY_PATH);
78 laginterface_linterface_pnf_path = configProperties.getProperty(LAGINTERFACE_LINTERFACE_PNF_PATH);
79 p_interface_linterface_pnf_path = configProperties.getProperty(P_INTERFACE_LINTERFACE_PNF_PATH);
84 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
86 String request_url = null;
87 String encoded_vnf = null;
88 String hostname = null;
89 String pnfname = null;
90 String interfaceName = null;
92 if(type == TYPE.L2_BRIDGE_SBG) {
93 if(requestProperties.containsKey(PNF_PNF_NAME)) {
94 request_url = target_uri + laginterface_linterface_pnf_path;
96 request_url = target_uri + laginterface_linterface_path;
99 if(requestProperties.containsKey(ROUTER_NAME)) {
100 hostname = requestProperties.getProperty(ROUTER_NAME);
101 encoded_vnf = encodeQuery(hostname);
102 request_url = request_url.replace("{hostname}", encoded_vnf);
105 if(requestProperties.containsKey(HOSTNAME)) {
106 hostname = requestProperties.getProperty(HOSTNAME);
107 encoded_vnf = encodeQuery(hostname);
108 request_url = request_url.replace("{hostname}", encoded_vnf);
111 if(requestProperties.containsKey(PNF_PNF_NAME)) {
112 pnfname = requestProperties.getProperty(PNF_PNF_NAME);
113 encoded_vnf = encodeQuery(pnfname);
114 request_url = request_url.replace("{pnf-name}", encoded_vnf);
117 encoded_vnf = encodeQuery(requestProperties.getProperty(LAG_INTERFACE_INTERFACE_NAME));
118 request_url = request_url.replace("{lag-interface.interface-name}", encoded_vnf) ;
121 interfaceName = requestProperties.getProperty(INTERFACE_NAME);
122 if(interfaceName == null || interfaceName.isEmpty()) {
123 interfaceName = requestProperties.getProperty(LINTERFACE_INTERFACE_NAME);
125 encoded_vnf = encodeQuery(interfaceName);
126 request_url = request_url.replace("{interface-name}", encoded_vnf) ;
129 if(type == TYPE.L2_BRIDGE_BGF) {
130 if(requestProperties.containsKey(PNF_PNF_NAME)) {
131 request_url = target_uri + p_interface_linterface_pnf_path;
133 request_url = target_uri + p_interface_linterface_path;
137 if(requestProperties.containsKey(ROUTER_NAME)) {
138 hostname = requestProperties.getProperty(ROUTER_NAME);
139 encoded_vnf = encodeQuery(hostname);
140 request_url = request_url.replace("{hostname}", encoded_vnf);
143 if(requestProperties.containsKey(HOSTNAME)) {
144 hostname = requestProperties.getProperty(HOSTNAME);
145 encoded_vnf = encodeQuery(hostname);
146 request_url = request_url.replace("{hostname}", encoded_vnf);
149 if(requestProperties.containsKey(PNF_PNF_NAME)) {
150 pnfname = requestProperties.getProperty(PNF_PNF_NAME);
151 encoded_vnf = encodeQuery(pnfname);
152 request_url = request_url.replace("{pnf-name}", encoded_vnf);
155 encoded_vnf = encodeQuery(requestProperties.getProperty(P_INTERFACE_INTERFACE_NAME));
156 request_url = request_url.replace("{p-interface.interface-name}", encoded_vnf) ;
159 interfaceName = requestProperties.getProperty(INTERFACE_NAME);
160 if(interfaceName == null || interfaceName.isEmpty()) {
161 interfaceName = requestProperties.getProperty(LINTERFACE_INTERFACE_NAME);
163 encoded_vnf = encodeQuery(interfaceName);
164 request_url = request_url.replace("{interface-name}", encoded_vnf) ;
168 if(resourceVersion != null) {
169 request_url = request_url +"?resource-version="+resourceVersion;
171 URL http_req_url = new URL(request_url);
173 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
175 aaiService.LOGwriteDateTrace("hostname", hostname);
177 aaiService.LOGwriteDateTrace("pnf-name", pnfname);
178 if(requestProperties.containsKey(LAG_INTERFACE_INTERFACE_NAME)) {
179 aaiService.LOGwriteDateTrace("lag-interface.interface-name", requestProperties.getProperty(LAG_INTERFACE_INTERFACE_NAME));
181 if(requestProperties.containsKey(P_INTERFACE_INTERFACE_NAME)) {
182 aaiService.LOGwriteDateTrace("p-interface.interface-name", requestProperties.getProperty(P_INTERFACE_INTERFACE_NAME));
184 aaiService.LOGwriteDateTrace("interface-name", interfaceName);
190 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
191 return this.getRequestUrl(method, null);
196 public String toJSONString() {
197 ObjectMapper mapper = getObjectMapper();
198 LInterface vnfc = (LInterface)requestDatum;
199 String json_text = null;
201 json_text = mapper.writeValueAsString(vnfc);
202 } catch (JsonProcessingException exc) {
203 handleException(this, exc);
211 public String[] getArgsList() {
213 if(type == TYPE.L2_BRIDGE_SBG) {
214 String[] tmpArray = {INTERFACE_NAME, LINTERFACE_INTERFACE_NAME, LAG_INTERFACE_INTERFACE_NAME, HOSTNAME, ROUTER_NAME, PNF_PNF_NAME};
217 if(type == TYPE.L2_BRIDGE_BGF) {
218 String[] tmpArray = {INTERFACE_NAME, LINTERFACE_INTERFACE_NAME, P_INTERFACE_INTERFACE_NAME, HOSTNAME, ROUTER_NAME, PNF_PNF_NAME};
226 public Class<? extends AAIDatum> getModelClass() {
227 return LInterface.class;
231 public String getPrimaryResourceName(String resource) {
232 return "l-interface";
235 public static final String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
236 String interfaceName = requestProperties.getProperty(INTERFACE_NAME);
237 if(interfaceName == null || interfaceName.isEmpty()) {
238 interfaceName = requestProperties.getProperty(LINTERFACE_INTERFACE_NAME);
241 request_url = request_url.replace("{interface-name}", encodeQuery(interfaceName)) ;