2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T 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.v11.LInterface;
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class SubInterfaceRequest extends AAIRequest {
38 public static final String PNF_LAGINTERFACE_SUBINTERFACE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pnf.lag.interface.subinterface";
39 public static final String PNF_LAGINTERFACE_SUBINTERFACE_QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pnf.lag.interface.subinterface.query";
41 public static final String PNF_P_INTERFACE_SUBINTERFACE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pnf.p.interface.l.interface";
42 public static final String PNF_P_INTERFACE_SUBINTERFACE_QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pnf.p.interface.l.interface.query";
44 private final String pnf_laginterface_subinterface_path;
45 private final String pnf_laginterface_subinterface_query_path;
46 private final String pnf_p_interface_subinterface_path;
47 private final String pnf_p_interface_subinterface_query_path;
49 public static final String SUBINTERFACE_INTERFACE_NAME = "l-interface.interface-name";
50 public static final String LAG_INTERFACE_INTERFACE_NAME = "lag-interface.interface-name";
51 public static final String PNF_PNF_NAME = "pnf.pnf-name";
52 public static enum TYPE { L2_BRIDGE_BGF, L2_BRIDGE_SBG};
54 private final TYPE type;
56 public SubInterfaceRequest(TYPE type) {
59 pnf_laginterface_subinterface_path = configProperties.getProperty(PNF_LAGINTERFACE_SUBINTERFACE_PATH);
60 pnf_laginterface_subinterface_query_path = configProperties.getProperty(PNF_LAGINTERFACE_SUBINTERFACE_QUERY_PATH);
62 pnf_p_interface_subinterface_path = configProperties.getProperty(PNF_P_INTERFACE_SUBINTERFACE_PATH);
63 pnf_p_interface_subinterface_query_path = configProperties.getProperty(PNF_P_INTERFACE_SUBINTERFACE_QUERY_PATH);
68 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
70 String request_url = null;
71 String encoded_vnf = null;
73 String pnfname = null;
74 String interfaceName = null;
76 if(type == TYPE.L2_BRIDGE_SBG) {
77 request_url = target_uri + pnf_laginterface_subinterface_path;
79 if(requestProperties.containsKey(PNF_PNF_NAME)) {
80 pnfname = requestProperties.getProperty(PNF_PNF_NAME);
81 encoded_vnf = encodeQuery(pnfname);
82 request_url = request_url.replace("{pnf-name}", encoded_vnf);
85 encoded_vnf = encodeQuery(requestProperties.getProperty(LAG_INTERFACE_INTERFACE_NAME));
86 request_url = request_url.replace("{lag-interface.interface-name}", encoded_vnf) ;
89 interfaceName = requestProperties.getProperty(SUBINTERFACE_INTERFACE_NAME);
90 encoded_vnf = encodeQuery(interfaceName);
91 request_url = request_url.replace("{interface-name}", encoded_vnf) ;
94 if(type == TYPE.L2_BRIDGE_BGF) {
95 request_url = target_uri + pnf_p_interface_subinterface_path;
97 if(requestProperties.containsKey(PNF_PNF_NAME)) {
98 pnfname = requestProperties.getProperty(PNF_PNF_NAME);
99 encoded_vnf = encodeQuery(pnfname);
100 request_url = request_url.replace("{pnf-name}", encoded_vnf);
103 encoded_vnf = encodeQuery(requestProperties.getProperty(PInterfaceRequest.PINTERFACE_INTERFACE_NAME));
104 request_url = request_url.replace("{p-interface.interface-name}", encoded_vnf) ;
107 interfaceName = requestProperties.getProperty(SUBINTERFACE_INTERFACE_NAME);
108 encoded_vnf = encodeQuery(interfaceName);
109 request_url = request_url.replace("{interface-name}", encoded_vnf) ;
113 if(resourceVersion != null) {
114 request_url = request_url +"?resource-version="+resourceVersion;
116 URL http_req_url = new URL(request_url);
118 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
121 aaiService.LOGwriteDateTrace("pnf-name", pnfname);
122 if(requestProperties.containsKey(LAG_INTERFACE_INTERFACE_NAME)) {
123 aaiService.LOGwriteDateTrace("lag-interface.interface-name", requestProperties.getProperty(LAG_INTERFACE_INTERFACE_NAME));
125 if(requestProperties.containsKey(PInterfaceRequest.PINTERFACE_INTERFACE_NAME)) {
126 aaiService.LOGwriteDateTrace("p-interface.interface-name", requestProperties.getProperty(PInterfaceRequest.PINTERFACE_INTERFACE_NAME));
128 aaiService.LOGwriteDateTrace("interface-name", interfaceName);
134 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
135 return this.getRequestUrl(method, null);
140 public String toJSONString() {
141 ObjectMapper mapper = getObjectMapper();
142 LInterface vnfc = (LInterface)requestDatum;
143 String json_text = null;
145 json_text = mapper.writeValueAsString(vnfc);
146 } catch (JsonProcessingException exc) {
147 handleException(this, exc);
155 public String[] getArgsList() {
157 if(type == TYPE.L2_BRIDGE_SBG) {
158 String[] tmpArray = {SUBINTERFACE_INTERFACE_NAME, LAG_INTERFACE_INTERFACE_NAME, PNF_PNF_NAME};
161 if(type == TYPE.L2_BRIDGE_BGF) {
162 String[] tmpArray = {SUBINTERFACE_INTERFACE_NAME, PInterfaceRequest.PINTERFACE_INTERFACE_NAME, PNF_PNF_NAME};
170 public Class<? extends AAIDatum> getModelClass() {
171 return LInterface.class;
175 public String getPrimaryResourceName(String resource) {
176 return "sub-interface";
179 public static final String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
180 String interfaceName = requestProperties.getProperty(SUBINTERFACE_INTERFACE_NAME);
181 request_url = request_url.replace("{interface-name}", encodeQuery(interfaceName)) ;