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;
28 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
29 import org.openecomp.aai.inventory.v11.PInterface;
30 import org.slf4j.LoggerFactory;
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class PInterfaceRequest extends AAIRequest {
38 public static final String PINTERFACE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface";
39 public static final String PINTERFACE_QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface.query";
41 private final String pinterface_path;
42 private final String pinterface_query_path;
44 public static final String HOSTNAME = "hostname";
45 public static final String PSERVER_HOSTNAME = "pserver.hostname";
46 public static final String INTERFACE_NAME = "interface-name";
47 public static final String PINTERFACE_INTERFACE_NAME = "p-interface.interface-name";
50 public PInterfaceRequest() {
51 pinterface_path = configProperties.getProperty(PINTERFACE_PATH);
52 pinterface_query_path = configProperties.getProperty(PINTERFACE_QUERY_PATH);
53 LoggerFactory.getLogger(PInterfaceRequest.class).debug("org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface=\t" + pinterface_path);
54 LoggerFactory.getLogger(PInterfaceRequest.class).debug("org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface.query=\t" + pinterface_query_path);
55 if(pinterface_path == null) {
56 LoggerFactory.getLogger(PInterfaceRequest.class).warn("org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface PATH not found in aaiclient.properties");
62 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
64 String request_url = target_uri + pinterface_path;
65 String encoded_vnf = null;
67 String hostname = null;
68 String interfaceName = null;
70 if(requestProperties.containsKey(HOSTNAME)) {
71 hostname = requestProperties.getProperty(HOSTNAME);
73 if(requestProperties.containsKey(PSERVER_HOSTNAME)) {
74 hostname = requestProperties.getProperty(PSERVER_HOSTNAME);
77 if(requestProperties.containsKey(INTERFACE_NAME)) {
78 interfaceName = requestProperties.getProperty(INTERFACE_NAME);
80 if(requestProperties.containsKey(PINTERFACE_INTERFACE_NAME)) {
81 interfaceName = requestProperties.getProperty(PINTERFACE_INTERFACE_NAME);
84 encoded_vnf = encodeQuery(hostname);
85 request_url = request_url.replace("{hostname}", encoded_vnf) ;
87 encoded_vnf = encodeQuery(interfaceName);
88 request_url = request_url.replace("{interface-name}", encoded_vnf) ;
90 if(resourceVersion != null) {
91 request_url = request_url +"?resource-version="+resourceVersion;
93 URL http_req_url = new URL(request_url);
95 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
96 aaiService.LOGwriteDateTrace("hostname", hostname);
97 aaiService.LOGwriteDateTrace("interface-name", hostname);
103 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
104 return this.getRequestUrl(method, null);
109 public String toJSONString() {
110 ObjectMapper mapper = getObjectMapper();
111 PInterface vnfc = (PInterface)requestDatum;
112 String json_text = null;
114 json_text = mapper.writeValueAsString(vnfc);
115 } catch (JsonProcessingException exc) {
116 handleException(this, exc);
123 public String[] getArgsList() {
124 String[] args = {HOSTNAME, PSERVER_HOSTNAME, INTERFACE_NAME, PINTERFACE_INTERFACE_NAME};
129 public Class<? extends AAIDatum> getModelClass() {
130 return PInterface.class;