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.v11.LagInterface;
31 import org.slf4j.LoggerFactory;
33 import com.fasterxml.jackson.core.JsonProcessingException;
34 import com.fasterxml.jackson.databind.ObjectMapper;
36 public class LagInterfacePnfRequest extends AAIRequest {
39 public static final String LAG_INTERFACE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface";
40 public static final String LAG_INTERFACE_QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface.query";
41 public static final String PNF_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pnf";
43 private final String lag_interface_path;
44 private final String lag_interface_query_path;
46 public static final String INTERFACE_NAME = "interface-name";
47 public static final String LAG_INTERFACE_INTERFACE_NAME = "lag-interface.interface-name";
48 public static final String PNF_NAME = "pnf-name";
49 public static final String PNF_PNF_NAME = "pnf.pnf-name";
52 public LagInterfacePnfRequest() {
53 lag_interface_path = configProperties.getProperty(PNF_PATH) + "/lag-interfaces/lag-interface/{interface-name}";
54 lag_interface_query_path = configProperties.getProperty(LAG_INTERFACE_QUERY_PATH);
55 LoggerFactory.getLogger(LagInterfacePnfRequest.class).debug("org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface=\t" + lag_interface_path);
56 LoggerFactory.getLogger(LagInterfacePnfRequest.class).debug("org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface.query=\t" + lag_interface_query_path);
57 if(lag_interface_path == null) {
58 LoggerFactory.getLogger(LagInterfacePnfRequest.class).warn("org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface PATH not found in aaiclient.properties");
64 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
66 String request_url = target_uri + lag_interface_path;
67 String encoded_vnf = null;
69 String interfaceName = null;
71 if(requestProperties.containsKey(INTERFACE_NAME)) {
72 interfaceName = requestProperties.getProperty(INTERFACE_NAME);
74 if(requestProperties.containsKey(LAG_INTERFACE_INTERFACE_NAME)) {
75 interfaceName = requestProperties.getProperty(LAG_INTERFACE_INTERFACE_NAME);
78 encoded_vnf = encodeQuery(interfaceName);
79 request_url = request_url.replace("{interface-name}", encoded_vnf) ;
81 request_url = processPnfRequestPathData(request_url,requestProperties);
83 if(resourceVersion != null) {
84 request_url = request_url +"?resource-version="+resourceVersion;
86 URL http_req_url = new URL(request_url);
88 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
89 aaiService.LOGwriteDateTrace("interface-name", interfaceName);
94 public static String processPnfRequestPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
96 String key = PNF_NAME;
97 if(requestProperties.containsKey(PNF_PNF_NAME)) {
101 if(!requestProperties.containsKey(key)) {
102 aaiService.logKeyError(String.format("%s,%s", PNF_NAME, PNF_PNF_NAME));
105 String encoded_vnf = encodeQuery(requestProperties.getProperty(key));
106 request_url = request_url.replace("{pnf-name}", encoded_vnf) ;
112 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
113 return this.getRequestUrl(method, null);
118 public String toJSONString() {
119 ObjectMapper mapper = getObjectMapper();
120 LagInterface vnfc = (LagInterface)requestDatum;
121 String json_text = null;
123 json_text = mapper.writeValueAsString(vnfc);
124 } catch (JsonProcessingException exc) {
125 handleException(this, exc);
132 public String[] getArgsList() {
133 String[] args = {INTERFACE_NAME, LAG_INTERFACE_INTERFACE_NAME, PNF_PNF_NAME};
139 public Class<? extends AAIDatum> getModelClass() {
140 return LagInterface.class;