aboutsummaryrefslogtreecommitdiffstats
path: root/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/L3InterfaceIpv4AddressListRequest.java
blob: e89c89c2d40c39fd57dacebd120034f543c49d55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*-
 * ============LICENSE_START=======================================================
 * openECOMP : SDN-C
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights
 * 							reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdnc.sli.aai;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;

import org.openecomp.sdnc.sli.aai.data.AAIDatum;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.openecomp.aai.inventory.v11.L3InterfaceIpv4AddressList;

public class L3InterfaceIpv4AddressListRequest extends AAIRequest {

	/*
	 * Note: there are 3 possible paths:
	 * /aai/v7/network/generic-vnfs/generic-vnf/{vnf-id}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * /aai/v7/network/generic-vnfs/generic-vnf/{vnf-id}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * /aai/v7/network/generic-vnfs/generic-vnf/{vnf-id}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * /aai/v7/network/generic-vnfs/generic-vnf/{vnf-id}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/newvces/newvce/{vnf-id2}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/cloud-infrastructure/cloud-regions/pservers/pserver/{hostname}/p-interfaces/p-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/cloud-infrastructure/cloud-regions/pservers/pserver/{hostname}/p-interfaces/p-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/cloud-infrastructure/cloud-regions/pservers/pserver/{hostname}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/cloud-infrastructure/cloud-regions/pservers/pserver/{hostname}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/newvces/newvce/{vnf-id2}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/vpes/vpe/{vnf-id}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/vpes/vpe/{vnf-id}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/vpes/vpe/{vnf-id}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/vpes/vpe/{vnf-id}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/vpls-pes/vpls-pe/{equipment-name}/p-interfaces/p-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/vpls-pes/vpls-pe/{equipment-name}/p-interfaces/p-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/vpls-pes/vpls-pe/{equipment-name}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/vpls-pes/vpls-pe/{equipment-name}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/pnfs/pnf/{pnf-name}/p-interfaces/p-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 * aaiv7:inventory/network/pnfs/pnf/{pnf-name}/p-interfaces/p-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}
	 */

	public static final String L3_INTERFACE_IPV4_ADDRESS_LIST_PATH	=     "org.openecomp.sdnc.sli.aai.path.l3.interface.ipv4.address.list";
	public static final String VLAN_L3_INTERFACE_IPV4_ADDRESS_LIST_PATH	= "org.openecomp.sdnc.sli.aai.path.vlan.l3.interface.ipv4.address.list";

	private final String l3_interface_ipv4_address_list_path;
	private final String vlan_l3_interface_ipv4_address_list_path;

	public static final String L3_INTERFACE_IPV4_ADDRESS	= "l3-interface-ipv4-address";
	public static final String LIST_L3_INTERFACE_IPV4_ADDRESS	= "l3-interface-ipv4-address-list.l3-interface-ipv4-address";
	public static final String VLAN_INTERFACE	= "vlan-interface";
	public static final String VLAN_VLAN_INTERFACE	= "vlan.vlan-interface";

	public L3InterfaceIpv4AddressListRequest() {
		l3_interface_ipv4_address_list_path = configProperties.getProperty(L3_INTERFACE_IPV4_ADDRESS_LIST_PATH);
		vlan_l3_interface_ipv4_address_list_path = configProperties.getProperty(VLAN_L3_INTERFACE_IPV4_ADDRESS_LIST_PATH);
	}

	@Override
	public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
		return this.getRequestUrl(method, null);
	}

	@Override
	public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {

		String request_url = target_uri+l3_interface_ipv4_address_list_path;

		if(requestProperties.containsKey(VLAN_INTERFACE) || requestProperties.containsKey(VLAN_VLAN_INTERFACE)){
			request_url = target_uri+vlan_l3_interface_ipv4_address_list_path;
			request_url = processVLanRequestPathData(request_url, requestProperties);
		}

		request_url = processPathData(request_url, requestProperties);
		request_url = LInterfaceRequest.processPathData(request_url, requestProperties);
//		request_url = GenericVnfRequest.processPathData(request_url, requestProperties);

		if(resourceVersion != null) {
			request_url = request_url +"?resource-version="+resourceVersion;
		}
		URL http_req_url =	new URL(request_url);

		aaiService.LOGwriteFirstTrace(method, http_req_url.toString());

		return http_req_url;
	}

	public static String processVLanRequestPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
		String key = null;

		if(requestProperties.containsKey(VLAN_VLAN_INTERFACE)) {
			key = VLAN_VLAN_INTERFACE;
		} else if(requestProperties.containsKey(VLAN_INTERFACE)) {
			key = VLAN_INTERFACE;
		} else {
			aaiService.logKeyError(String.format("%s,%s", VLAN_INTERFACE, VLAN_VLAN_INTERFACE));
		}

		String encoded_vnf = encodeQuery(requestProperties.getProperty(key));

		request_url = request_url.replace("{vlan-interface}", encoded_vnf) ;
		aaiService.LOGwriteDateTrace("vlan-interface", requestProperties.getProperty(key));
		return request_url;
	}

	@Override
	public String toJSONString() {
		ObjectMapper mapper = getObjectMapper();
		L3InterfaceIpv4AddressList vnfc = (L3InterfaceIpv4AddressList)requestDatum;
		String json_text = null;
		try {
			json_text = mapper.writeValueAsString(vnfc);
		} catch (JsonProcessingException exc) {
			handleException(this, exc);
			return null;
		}
		return json_text;
	}

	@Override
	public String[] getArgsList() {
		String[] args =
			{
				L3_INTERFACE_IPV4_ADDRESS,
				LIST_L3_INTERFACE_IPV4_ADDRESS,
				VLAN_INTERFACE,
				VLAN_VLAN_INTERFACE,
				LInterfaceRequest.INTERFACE_NAME,
				LInterfaceRequest.LINTERFACE_INTERFACE_NAME,
				"generic-vnf.vnf-id"
			};

		return args;
	}

	@Override
	public Class<? extends AAIDatum> getModelClass() {
		return L3InterfaceIpv4AddressList.class;
	}

	public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
		String key = L3_INTERFACE_IPV4_ADDRESS;
		if(requestProperties.containsKey(LIST_L3_INTERFACE_IPV4_ADDRESS)) {
			key = LIST_L3_INTERFACE_IPV4_ADDRESS;
		}

		if(!requestProperties.containsKey(key)) {
			aaiService.logKeyError(String.format("%s,%s", L3_INTERFACE_IPV4_ADDRESS, LIST_L3_INTERFACE_IPV4_ADDRESS));
		}

		String encoded_vnf = encodeQuery(requestProperties.getProperty(key));

		request_url = request_url.replace("{l3-interface-ipv4-address}", encoded_vnf) ;

		aaiService.LOGwriteDateTrace("l3-interface-ipv4-address", requestProperties.getProperty(key));
		return request_url;
	}

	/*
	 * (non-Javadoc)
	 * @see org.openecomp.sdnc.sli.aai.PathConfigurator#configurePath(java.lang.String)
	 */
//	@Override
//	public void processRequestPathValues(Map<String, String> nameValues) {
//		String[] paths =
//		{
//		 "/aai/v7/network/generic-vnfs/generic-vnf/{vnf-id}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}",
//		 "/aai/v7/network/generic-vnfs/generic-vnf/{vnf-id}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}",
//		 "/aai/v7/network/generic-vnfs/generic-vnf/{vnf-id}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}",
//		 "/aai/v7/network/generic-vnfs/generic-vnf/{vnf-id}/lag-interfaces/lag-interface/{interface-name}/l-interfaces/l-interface/{interface-name}/vlans/vlan/{vlan-interface}/l3-interface-ipv4-address-list/{l3-interface-ipv4-address}"
//		};
//
//		List<String>keys = new LinkedList<String>();
//		keys.addAll(nameValues.keySet());
//		for(String key : keys) {
//			if(key.contains(".")) {
//				key = key.replaceAll("_", "-");
//				if(!LIST_L3_INTERFACE_IPV4_ADDRESS.equals(key)) {
//					int index = key.indexOf(".");
//					String resource = key.substring(0, index);
//					AAIRequest rx = createRequest(resource, nameValues);
//					if(rx != null) {
//						pathElements.add(rx);
//					}
//				}
//			}
//		}
//		super.processRequestPathValues(nameValues);
//	}
//	List<AAIRequest> pathElements = new LinkedList<AAIRequest>();

}