- @Override
- public Pserver requestPServerData(String hostname) throws AAIServiceException {
- Pserver response = null;
- InputStream inputStream = null;
-
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("pserver");
- request.addRequestProperty("pserver.hostname", hostname);
-
-
- String rv = executor.get(request);
- if(rv != null) {
- ObjectMapper mapper = getObjectMapper();
- response = mapper.readValue(rv, Pserver.class);
- }
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn("requestPServerData", exc);
- throw new AAIServiceException(exc);
- }
- return response;
- }
-
- @Override
- public boolean postPServerData(String hostname, Pserver data) throws AAIServiceException {
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("pserver");
- request.addRequestProperty("pserver.hostname", hostname);
- request.setRequestObject(data);
- Object response = executor.post(request);
- return true;
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn(Object.class.getClass().getEnclosingMethod().getName(), exc);
- throw new AAIServiceException(exc);
- }
- }
-
- @Override
- public boolean deletePServerData(String hostname, String resourceVersion) throws AAIServiceException {
- boolean response = false;
-
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("pserver");
- request.addRequestProperty("pserver.hostname", hostname);
- response = executor.delete(request, resourceVersion);
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn("deletePServerData", exc);
- throw new AAIServiceException(exc);
- }
-
- return response;
- }
-
-
- @Override
- public L3Network requestL3NetworkData(String networkId) throws AAIServiceException {
- L3Network response = null;
- InputStream inputStream = null;
-
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("l3-network");
- request.addRequestProperty("l3-network.network-id", networkId);
-
- String rv = executor.get(request);
- if(rv != null) {
- ObjectMapper mapper = getObjectMapper();
- response = mapper.readValue(rv, L3Network.class);
- }
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn("requestL3NetworkData", exc);
- throw new AAIServiceException(exc);
- }
- return response;
- }
-
- @Override
- public L3Network requestL3NetworkQueryByName(String networkName) throws AAIServiceException {
- L3Network response = null;
-
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("l3-network");
- request.addRequestProperty("l3-network.network-name", networkName);
-
- String rv = executor.get(request);
- if(rv != null) {
- ObjectMapper mapper = getObjectMapper();
- response = mapper.readValue(rv, L3Network.class);
- }
-
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn("requestL3NetworkQueryByName", exc);
- throw new AAIServiceException(exc);
- }
- return response;
- }
-
- @Override
- public boolean postL3NetworkData(String networkId, L3Network data) throws AAIServiceException {
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("l3-network");
- request.addRequestProperty("l3-network.network-id", networkId);
- request.setRequestObject(data);
- Object response = executor.post(request);
- return true;
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn(Object.class.getClass().getEnclosingMethod().getName(), exc);
- throw new AAIServiceException(exc);
- }
- }
-
- @Override
- public boolean deleteL3NetworkData(String networkId, String resourceVersion) throws AAIServiceException {
- boolean response = false;
-
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("l3-network");
- request.addRequestProperty("l3-network.network-id", networkId);
- response = executor.delete(request, resourceVersion);
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn("deleteL3NetworkData", exc);
- throw new AAIServiceException(exc);
- }
-
- return response;
- }
-
-
- @Override
- public VpnBinding requestVpnBindingData(String vpnId) throws AAIServiceException {
- VpnBinding response = null;
-
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("vpn-binding");
- request.addRequestProperty("vpn-binding.vpn-id", vpnId);
-
- String rv = executor.get(request);
- if(rv != null) {
- ObjectMapper mapper = getObjectMapper();
- response = mapper.readValue(rv, VpnBinding.class);
- }
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn("requestVpnBindingData", exc);
- throw new AAIServiceException(exc);
- }
- return response;
- }
-
- @Override
- public boolean deleteVpnBindingData(String vpnId, String resourceVersion) throws AAIServiceException {
- boolean response = false;
-
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("vpn-binding");
- request.addRequestProperty("vpn-binding.vpn-id", vpnId);
- response = executor.delete(request, resourceVersion);
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn("deleteVpnBindingData", exc);
- throw new AAIServiceException(exc);
- }
- return response;
- }
-
-
- @Override
- public VnfImage requestVnfImageData(String vnf_image_uuid) throws AAIServiceException {
- VnfImage response = null;
-
- try {
- AAIRequest request = AAIRequest.getRequestFromResource("vnf-image");
- request.addRequestProperty("vnf-image.vnf-image-uuid", vnf_image_uuid);
-
- String rv = executor.get(request);
- if(rv != null) {
- ObjectMapper mapper = getObjectMapper();
- response = mapper.readValue(rv, VnfImage.class);
- }
- } catch(AAIServiceException aaiexc) {
- throw aaiexc;
- } catch (Exception exc) {
- LOG.warn("requestVnfImageData", exc);
- throw new AAIServiceException(exc);
- }
- return response;
- }
-
- @Override
- public VnfImage requestVnfImageDataByVendorModel(String vendor, String model) throws AAIServiceException {
- return requestVnfImageDataByVendorModelVersion(vendor, model, null);
- }
-
- @Override
- public VnfImage requestVnfImageDataByVendorModelVersion(String vendor, String model, String version) throws AAIServiceException
- {
- List<VnfImage> responseList = new ArrayList<VnfImage>();
- VnfImage response = null;
- InputStream inputStream = null;
-
- try {
- String request_url = target_uri+vnf_image_query_path + (version==null? "": "&application-version={application_version}");
- request_url = request_url.replace("{application_vendor}", encodeQuery(vendor)) ;
- request_url = request_url.replace("{application_model}", encodeQuery(model)) ;
- if(version != null) {
- request_url = request_url.replace("{application_version}", encodeQuery(version)) ;
- }
- URL http_req_url = new URL(request_url);
+ //==================== DvsSwitch ======================
+ @Override
+ public DvsSwitch requestDvsSwitchData(String vnf_id) throws AAIServiceException {
+ DvsSwitch response = null;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("dvs-switch");
+ request.addRequestProperty("dvs-switch.switch-name", vnf_id);
+
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, DvsSwitch.class);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestDvsSwitchData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public boolean postDvsSwitchData(String switch_name, DvsSwitch data) throws AAIServiceException {
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("dvs-switch");
+ request.addRequestProperty("dvs-switch.switch-name", switch_name);
+ request.setRequestObject(data);
+ Object response = executor.post(request);
+ return true;
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn(Object.class.getClass().getEnclosingMethod().getName(), exc);
+ throw new AAIServiceException(exc);
+ }
+ }
+
+ @Override
+ public boolean deleteDvsSwitchData(String vnf_id, String resourceVersion) throws AAIServiceException {
+ boolean response = false;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("dvs-switch");
+ request.addRequestProperty("dvs-switch.switch-name", vnf_id);
+ response = executor.delete(request, resourceVersion);
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("deleteDvsSwitchData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+ //================== End of DvsSwitch =================
+ //==================== PhysicalLink ======================
+ @Override
+ public PhysicalLink requestPhysicalLinkData(String linkName) throws AAIServiceException {
+ PhysicalLink response = null;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("physical-link");
+ request.addRequestProperty("physical-link.link-name", linkName);
+
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, PhysicalLink.class);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestPhysicalLinkData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public boolean postPhysicalLinkData(String linkName, PhysicalLink data) throws AAIServiceException {
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("physical-link");
+ request.addRequestProperty("physical-link.link-name", linkName);
+ request.setRequestObject(data);
+ Object response = executor.post(request);
+ return true;
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn(Object.class.getClass().getEnclosingMethod().getName(), exc);
+ throw new AAIServiceException(exc);
+ }
+ }
+
+ @Override
+ public boolean deletePhysicalLinkData(String linkName, String resourceVersion) throws AAIServiceException {
+ boolean response = false;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("physical-link");
+ request.addRequestProperty("physical-link.link-name", linkName);
+ response = executor.delete(request, resourceVersion);
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("deletePhysicalLinkData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+ //================== End of PhysicalLink =================
+ //==================== PInterface ======================
+ @Override
+ public PInterface requestPInterfaceData(String hostname, String interfaceName) throws AAIServiceException {
+ PInterface response = null;
+
+ try {
+ AAIRequest request = new PInterfaceRequest();
+ request.addRequestProperty(PInterfaceRequest.PINTERFACE_INTERFACE_NAME, interfaceName);
+ request.addRequestProperty(PInterfaceRequest.PSERVER_HOSTNAME, hostname);
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, PInterface.class);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn(Object.class.getClass().getEnclosingMethod().getName(), exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public boolean postPInterfaceData(String hostname, String interfaceName, PInterface request) throws AAIServiceException {
+ InputStream inputStream = null;
+
+ try {
+
+ ObjectMapper mapper = getObjectMapper();
+ String json_text = mapper.writeValueAsString(request);
+
+ SSLSocketFactory sockFact = CTX.getSocketFactory();
+
+ String request_url = target_uri+p_interface_path;
+ String encoded_vnf = encodeQuery(hostname);
+ request_url = request_url.replace("{hostname}", encoded_vnf) ;
+ encoded_vnf = encodeQuery(interfaceName);
+ request_url = request_url.replace("{interface-name}", encoded_vnf) ;
+ URL http_req_url = new URL(request_url);
+
+ HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.PUT);
+
+ OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
+ osw.write(json_text);
+ osw.flush();
+ osw.close();
+
+
+ LOGwriteFirstTrace("PUT", request_url);
+ LOGwriteDateTrace("hostname", hostname);
+ LOGwriteDateTrace("interface-name", interfaceName);
+ LOGwriteDateTrace("PInterface", json_text);
+
+ // Check for errors
+ int responseCode = con.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ inputStream = con.getInputStream();
+ } else {
+ inputStream = con.getErrorStream();
+ }
+
+ // Process the response
+ BufferedReader reader;
+ String line = null;
+ reader = new BufferedReader( new InputStreamReader( inputStream ) );
+
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ while( ( line = reader.readLine() ) != null ) {
+ stringBuilder.append( line );
+ }
+ LOGwriteEndingTrace(responseCode, "SUCCESS", (stringBuilder.length() > 0) ? stringBuilder.toString() : "{no-data}");
+ return true;
+ } else {
+ ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
+ LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse));
+
+ throw new AAIServiceException(responseCode, errorresponse);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("postPInterfaceData", exc);
+ throw new AAIServiceException(exc);
+ } finally {
+ try {
+ if(inputStream != null)
+ inputStream.close();
+ } catch (Exception exc) {
+
+ }
+ }
+ }
+
+ @Override
+ public boolean deletePInterfaceData(String hostname, String interfaceName, String resourceVersion) throws AAIServiceException {
+ boolean response = false;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("p-interface");
+ request.addRequestProperty("p-interface.interface-name", interfaceName);
+ request.addRequestProperty("pserver.hostname", hostname);
+ response = executor.delete(request, resourceVersion);
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("deletePInterfaceData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+ //================== End of PInterface =================
+ //==================== SitePairSet ======================
+ @Override
+ public SitePairSet requestSitePairSetData(String sitePairSetId) throws AAIServiceException {
+ SitePairSet response = null;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("site-pair-set");
+ request.addRequestProperty("site-pair-set.site-pair-set-id", sitePairSetId);
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, SitePairSet.class);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn(Object.class.getClass().getEnclosingMethod().getName(), exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public boolean postSitePairSetData(String linkName, SitePairSet request) throws AAIServiceException {
+ InputStream inputStream = null;
+
+ try {
+
+ ObjectMapper mapper = getObjectMapper();
+ String json_text = mapper.writeValueAsString(request);
+
+ SSLSocketFactory sockFact = CTX.getSocketFactory();
+
+ String request_url = target_uri+site_pair_set_path;
+ String encoded_vnf = encodeQuery(linkName);
+ request_url = request_url.replace("{site-pair-set-id}", encoded_vnf) ;
+ URL http_req_url = new URL(request_url);
+
+ HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.PUT);
+
+ OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
+ osw.write(json_text);
+ osw.flush();
+ osw.close();
+
+
+ LOGwriteFirstTrace("PUT", request_url);
+ LOGwriteDateTrace("link-name", linkName);
+ LOGwriteDateTrace("SitePairSet", json_text);
+
+ // Check for errors
+ int responseCode = con.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ inputStream = con.getInputStream();
+ } else {
+ inputStream = con.getErrorStream();
+ }
+
+ // Process the response
+ BufferedReader reader;
+ String line = null;
+ reader = new BufferedReader( new InputStreamReader( inputStream ) );
+
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ while( ( line = reader.readLine() ) != null ) {
+ stringBuilder.append( line );
+ }
+ LOGwriteEndingTrace(responseCode, "SUCCESS", (stringBuilder.length() > 0) ? stringBuilder.toString() : "{no-data}");
+ return true;
+ } else {
+ ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
+ LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse));
+
+ throw new AAIServiceException(responseCode, errorresponse);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("postSitePairSetData", exc);
+ throw new AAIServiceException(exc);
+ } finally {
+ try {
+ if(inputStream != null)
+ inputStream.close();
+ } catch (Exception exc) {
+
+ }
+ }
+ }
+
+ @Override
+ public boolean deleteSitePairSetData(String linkName, String resourceVersion) throws AAIServiceException {
+ boolean response = false;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("site-pair-set");
+ request.addRequestProperty("site-pair-set.site-pair-set-id", linkName);
+ response = executor.delete(request, resourceVersion);
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("deleteSitePairSetData", exc);
+ throw new AAIServiceException(exc);
+ }
+
+ return response;
+ }
+ //================== End of SitePairSet =================
+ //==================== Service ======================
+ @Override
+ public Service requestServiceData(String serviceId) throws AAIServiceException {
+ Service response = null;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("service");
+ request.addRequestProperty("service.service-id", serviceId);
+
+
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, Service.class);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestServiceData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public boolean postServiceData(String linkName, Service request) throws AAIServiceException {
+ InputStream inputStream = null;
+
+ try {
+
+ ObjectMapper mapper = getObjectMapper();
+ String json_text = mapper.writeValueAsString(request);
+
+ SSLSocketFactory sockFact = CTX.getSocketFactory();
+
+ String request_url = target_uri+service_path;
+ String encoded_vnf = encodeQuery(linkName);
+ request_url = request_url.replace("{service-id}", encoded_vnf) ;
+ URL http_req_url = new URL(request_url);
+
+ HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.PUT);
+
+ OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
+ osw.write(json_text);
+ osw.flush();
+ osw.close();
+
+
+ LOGwriteFirstTrace("PUT", request_url);
+ LOGwriteDateTrace("service-id", linkName);
+ LOGwriteDateTrace("Service", json_text);
+
+ // Check for errors
+ int responseCode = con.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ inputStream = con.getInputStream();
+ } else {
+ inputStream = con.getErrorStream();
+ }
+
+ // Process the response
+ BufferedReader reader;
+ String line = null;
+ reader = new BufferedReader( new InputStreamReader( inputStream ) );
+
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ while( ( line = reader.readLine() ) != null ) {
+ stringBuilder.append( line );
+ }
+ LOGwriteEndingTrace(responseCode, "SUCCESS", (stringBuilder.length() > 0) ? stringBuilder.toString() : "{no-data}");
+ return true;
+ } else {
+ ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
+ LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse));
+
+ throw new AAIServiceException(responseCode, errorresponse);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("postServiceData", exc);
+ throw new AAIServiceException(exc);
+ } finally {
+ try {
+ if(inputStream != null)
+ inputStream.close();
+ } catch (Exception exc) {
+
+ }
+ }
+ }
+
+ @Override
+ public boolean deleteServiceData(String service_id, String resourceVersion) throws AAIServiceException {
+ boolean response = false;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("service");
+ request.addRequestProperty("service.service-id", service_id);
+ response = executor.delete(request, resourceVersion);
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("deleteServiceData", exc);
+ throw new AAIServiceException(exc);
+ }
+
+ return response;
+ }
+ //================== End of Service =================
+
+
+
+ // 1507 - Request
+ @Override
+ public VServer dataChangeRequestVServerData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return this.getResource(url.toString(), VServer.class);
+ }
+
+ @Override
+ public Pserver dataChangeRequestPServerData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return this.getResource(url.toString(), Pserver.class);
+ }
+
+ @Override
+ public CtagPool dataChangeRequestCtagPoolData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return this.getResource(url.toString(), CtagPool.class);
+ }
+
+ @Override
+ public VplsPe dataChangeRequestVplsPeData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return this.getResource(url.toString(), VplsPe.class);
+ }
+
+ @Override
+ public DvsSwitch dataChangeRequestDvsSwitchData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return this.getResource(url.toString(), DvsSwitch.class);
+ }
+
+ @Override
+ public OamNetwork dataChangeRequestOAMNetworkData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return this.getResource(url.toString(), OamNetwork.class);
+ }
+
+ @Override
+ public AvailabilityZone dataChangeRequestAvailabilityZoneData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return this.getResource(url.toString(), AvailabilityZone.class);
+ }
+
+ @Override
+ public Complex dataChangeRequestComplexData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return this.getResource(url.toString(), Complex.class);
+ }
+
+ /* DELETE */
+ @Override
+ public boolean dataChangeDeleteVServerData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return deleteAAIEntity(url, Object.class.getClass().getEnclosingMethod()
+ .getName());
+ }
+
+ @Override
+ public boolean dataChangeDeleteCtagPoolData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return deleteAAIEntity(url, Object.class.getClass().getEnclosingMethod()
+ .getName());
+ }
+
+ @Override
+ public boolean dataChangeDeleteVplsPeData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return deleteAAIEntity(url, Object.class.getClass().getEnclosingMethod()
+ .getName());
+ }
+
+ @Override
+ public boolean dataChangeDeleteVpeData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return deleteAAIEntity(url, Object.class.getClass().getEnclosingMethod()
+ .getName());
+ }
+
+ @Override
+ public boolean dataChangeDeleteDvsSwitchData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return deleteAAIEntity(url, Object.class.getClass().getEnclosingMethod()
+ .getName());
+ }
+ //OAM-Network:
+ @Override
+ public boolean dataChangeDeleteOAMNetworkData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return deleteAAIEntity(url, Object.class.getClass().getEnclosingMethod()
+ .getName());
+ }
+ //Availability-Zone:
+ @Override
+ public boolean dataChangeDeleteAvailabilityZoneData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return deleteAAIEntity(url, Object.class.getClass().getEnclosingMethod()
+ .getName());
+ }
+ //Complex:
+ @Override
+ public boolean dataChangeDeleteComplexData(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ return deleteAAIEntity(url, Object.class.getClass().getEnclosingMethod()
+ .getName());
+ }
+
+ private boolean deleteAAIEntity(URL url, String caller) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ boolean response = false;
+ InputStream inputStream = null;
+
+ try {
+ URL http_req_url = url;
+
+ HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.DELETE);
+
+ LOGwriteFirstTrace("DELETE", http_req_url.toString());
+
+
+ // Check for errors
+ int responseCode = con.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ inputStream = con.getInputStream();
+ } else {
+ inputStream = con.getErrorStream();
+ }
+
+ // Process the response
+ LOG.debug("HttpURLConnection result:" + responseCode);
+ if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
+ BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
+ String line = null;
+
+ ObjectMapper mapper = getObjectMapper();
+
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ while( ( line = reader.readLine() ) != null ) {
+ stringBuilder.append( line );
+ }
+ LOGwriteEndingTrace(responseCode, "SUCCESS", stringBuilder.toString());
+ response = true;
+ } else if(responseCode == HttpURLConnection.HTTP_NOT_FOUND ) {
+ LOGwriteEndingTrace(responseCode, "HTTP_NOT_FOUND", "Entry does not exist.");
+ response = false;
+ } else {
+ ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
+ LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse));
+ throw new AAIServiceException(responseCode, errorresponse);
+ }
+
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn(caller, exc);
+ throw new AAIServiceException(exc);
+ } finally {
+ if(inputStream != null){
+ try {
+ inputStream.close();
+ } catch(Exception exc) {
+
+ }
+ }
+ }
+ return response;
+ }
+
+ /**
+ * Generic method to GET json data from an A&AI callback URL.
+ * Then convert that json to an Object.
+ * If successful the Object is attempted to be cast to the type parameter.
+ *
+ * @param key
+ * callback url for A&AI
+ * @param type
+ * the class of object that A&AI will return
+ * @return the object created from json or null if the response code is not 200
+ *
+ * @throws AAIServiceException
+ * if empty or null key and or type or there's an error with processing
+ */
+ public <T> T dataChangeRequestAaiData(String key, Class<T> type) throws AAIServiceException {
+ if (StringUtils.isEmpty(key) || type == null) {
+ throw new AAIServiceException("Key is empty or null and or type is null");
+ }
+
+ T response = null;
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ if(!key.contains(" = ") && isValidURL(key)) {
+ key = String.format("selflink = '%s'", key);
+ } else
+ if(!key.contains(" = ") && isValidURI(key)) {
+ key = String.format("resource-path = '%s'", key);
+ }
+
+ HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
+
+ SelfLinkRequest request = new SelfLinkRequest(type);
+ request.processRequestPathValues(nameValues);
+ Object obj = this.getExecutor().query(request, type);
+ response = type.cast(obj);
+
+ return response != null ? type.cast(response) : response;
+ }
+
+ @Override
+ public Pserver requestPServerData(String hostname) throws AAIServiceException {
+ Pserver response = null;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("pserver");
+ request.addRequestProperty("pserver.hostname", hostname);
+
+
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, Pserver.class);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestPServerData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public boolean postPServerData(String hostname, Pserver data) throws AAIServiceException {
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("pserver");
+ request.addRequestProperty("pserver.hostname", hostname);
+ request.setRequestObject(data);
+ Object response = executor.post(request);
+ return true;
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn(Object.class.getClass().getEnclosingMethod().getName(), exc);
+ throw new AAIServiceException(exc);
+ }
+ }
+
+ @Override
+ public boolean deletePServerData(String hostname, String resourceVersion) throws AAIServiceException {
+ boolean response = false;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("pserver");
+ request.addRequestProperty("pserver.hostname", hostname);
+ response = executor.delete(request, resourceVersion);
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("deletePServerData", exc);
+ throw new AAIServiceException(exc);
+ }
+
+ return response;
+ }
+
+
+ @Override
+ public L3Network requestL3NetworkData(String networkId) throws AAIServiceException {
+ L3Network response = null;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("l3-network");
+ request.addRequestProperty("l3-network.network-id", networkId);
+
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, L3Network.class);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestL3NetworkData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public L3Network requestL3NetworkQueryByName(String networkName) throws AAIServiceException {
+ L3Network response = null;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("l3-network");
+ request.addRequestProperty("l3-network.network-name", networkName);
+
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, L3Network.class);
+ }
+
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestL3NetworkQueryByName", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public boolean postL3NetworkData(String networkId, L3Network data) throws AAIServiceException {
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("l3-network");
+ request.addRequestProperty("l3-network.network-id", networkId);
+ request.setRequestObject(data);
+ Object response = executor.post(request);
+ return true;
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn(Object.class.getClass().getEnclosingMethod().getName(), exc);
+ throw new AAIServiceException(exc);
+ }
+ }
+
+ @Override
+ public boolean deleteL3NetworkData(String networkId, String resourceVersion) throws AAIServiceException {
+ boolean response = false;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("l3-network");
+ request.addRequestProperty("l3-network.network-id", networkId);
+ response = executor.delete(request, resourceVersion);
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("deleteL3NetworkData", exc);
+ throw new AAIServiceException(exc);
+ }
+
+ return response;
+ }
+
+
+ @Override
+ public VpnBinding requestVpnBindingData(String vpnId) throws AAIServiceException {
+ VpnBinding response = null;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("vpn-binding");
+ request.addRequestProperty("vpn-binding.vpn-id", vpnId);
+
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, VpnBinding.class);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestVpnBindingData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public boolean deleteVpnBindingData(String vpnId, String resourceVersion) throws AAIServiceException {
+ boolean response = false;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("vpn-binding");
+ request.addRequestProperty("vpn-binding.vpn-id", vpnId);
+ response = executor.delete(request, resourceVersion);
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("deleteVpnBindingData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+
+ @Override
+ public VnfImage requestVnfImageData(String vnf_image_uuid) throws AAIServiceException {
+ VnfImage response = null;
+
+ try {
+ AAIRequest request = AAIRequest.getRequestFromResource("vnf-image");
+ request.addRequestProperty("vnf-image.vnf-image-uuid", vnf_image_uuid);
+
+ String rv = executor.get(request);
+ if(rv != null) {
+ ObjectMapper mapper = getObjectMapper();
+ response = mapper.readValue(rv, VnfImage.class);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestVnfImageData", exc);
+ throw new AAIServiceException(exc);
+ }
+ return response;
+ }
+
+ @Override
+ public VnfImage requestVnfImageDataByVendorModel(String vendor, String model) throws AAIServiceException {
+ return requestVnfImageDataByVendorModelVersion(vendor, model, null);
+ }
+
+ @Override
+ public VnfImage requestVnfImageDataByVendorModelVersion(String vendor, String model, String version) throws AAIServiceException
+ {
+ List<VnfImage> responseList = new ArrayList<VnfImage>();
+ VnfImage response = null;
+ InputStream inputStream = null;
+
+ try {
+ String request_url = target_uri+vnf_image_query_path + (version==null? "": "&application-version={application_version}");
+ request_url = request_url.replace("{application_vendor}", encodeQuery(vendor)) ;
+ request_url = request_url.replace("{application_model}", encodeQuery(model)) ;
+ if(version != null) {
+ request_url = request_url.replace("{application_version}", encodeQuery(version)) ;
+ }
+ URL http_req_url = new URL(request_url);
+
+ HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.GET);
+
+ LOGwriteFirstTrace(HttpMethod.GET, http_req_url.toString());
+ LOGwriteDateTrace("application_vendor", vendor);
+ LOGwriteDateTrace("application_model", model);
+ if(version != null) {
+ LOGwriteDateTrace("application_version", version);
+ }
+
+ // Check for errors
+ int responseCode = con.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ inputStream = con.getInputStream();
+ } else {
+ inputStream = con.getErrorStream();
+ }
+
+ // Process the response
+ LOG.debug("HttpURLConnection result:" + responseCode);
+ if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
+ BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
+
+ ObjectMapper mapper = getObjectMapper();
+
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ response = mapper.readValue(reader, VnfImage.class);
+ String original_buffer = mapper.writeValueAsString(response);
+ LOGwriteEndingTrace(HttpURLConnection.HTTP_OK, "SUCCESS", original_buffer);
+ if(response.getApplicationVendor() == null /*&& response.getAdditionalProperties() != null && !response.getAdditionalProperties().isEmpty()*/){
+ LOG.warn("A List of multiple VNF-IMAGE entries has been returned");
+ VnfImages listOfObjects = mapper.readValue(original_buffer, VnfImages.class);
+ if(!listOfObjects.getVnfImage().isEmpty()) {
+ response = listOfObjects.getVnfImage().get(0);
+ }
+ }
+ } else if(responseCode == HttpURLConnection.HTTP_NOT_FOUND ) {
+ LOGwriteEndingTrace(responseCode, "HTTP_NOT_FOUND", "Entry does not exist.");
+ return response;
+ } else {
+ ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
+ LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse));
+ throw new AAIServiceException(responseCode, errorresponse);
+ }
+
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestVnfImageData", exc);
+ throw new AAIServiceException(exc);
+ } finally {
+ if(inputStream != null){
+ try {
+ inputStream.close();
+ } catch(Exception exc) {
+
+ }
+ }
+ }
+ return response;
+ }
+
+
+ public boolean sendNotify(NotifyEvent event, String serviceInstanceId, String pathCode) throws AAIServiceException {
+ InputStream inputStream = null;
+
+ try {
+
+ String selfLink = selflink_fqdn;
+ if(SELFLINK_AVPN != null && SELFLINK_AVPN.equals(pathCode)) {
+ selfLink = selflink_avpn;
+ }
+ selfLink = selfLink.replace("{service-instance-id}", encodeQuery(serviceInstanceId));
+ event.setSelflink(selfLink);
+
+ ObjectMapper mapper = getObjectMapper();
+ String json_text = mapper.writeValueAsString(event);
+
+ SSLSocketFactory sockFact = CTX.getSocketFactory();
+
+ String request_url = target_uri+ubb_notify_path;
+ URL http_req_url = new URL(request_url);
+
+ HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.PUT);
+
+ OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
+ osw.write(json_text);
+ osw.flush();
+ osw.close();
+
+
+ LOGwriteFirstTrace("PUT", request_url);
+ LOGwriteDateTrace("NotifyEvent", json_text);
+
+ // Check for errors
+ int responseCode = con.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ inputStream = con.getInputStream();
+ } else {
+ inputStream = con.getErrorStream();
+ }
+
+ // Process the response
+ BufferedReader reader;
+ String line = null;
+ reader = new BufferedReader( new InputStreamReader( inputStream ) );
+
+ if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ while( ( line = reader.readLine() ) != null ) {
+ stringBuilder.append( line );
+ }
+ LOGwriteEndingTrace(responseCode, "SUCCESS", (stringBuilder.length() > 0) ? stringBuilder.toString() :
+ "{no-data}");
+ return true;
+ } else {
+ ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
+ LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse));
+
+ throw new AAIServiceException(responseCode, errorresponse);
+ }
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("sendNotify", exc);
+ throw new AAIServiceException(exc);
+ } finally {
+ try {
+ if(inputStream != null)
+ inputStream.close();
+ } catch (Exception exc) {
+
+ }
+ }
+ }
+
+ @Override
+ public SearchResults requestNodeQuery(String node_type, String entityIdentifier, String entityName) throws AAIServiceException {
+ SearchResults response = null;
+ InputStream inputStream = null;
+
+ try {
+ String request_url = target_uri+query_nodes_path;
+ request_url = request_url.replace("{node-type}", encodeQuery(node_type)) ;
+ request_url = request_url.replace("{entity-identifier}", entityIdentifier) ;
+ request_url = request_url.replace("{entity-name}", encodeQuery(entityName)) ;
+ URL http_req_url = new URL(request_url);
+
+ HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.GET);
+
+ LOGwriteFirstTrace(HttpMethod.GET, http_req_url.toString());
+ LOGwriteDateTrace("node_type", node_type);
+ LOGwriteDateTrace("vnf_name", entityName);
+
+ // Check for errors
+ int responseCode = con.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ inputStream = con.getInputStream();
+ } else {
+ inputStream = con.getErrorStream();
+ }
+
+ // Process the response
+ LOG.debug("HttpURLConnection result:" + responseCode);
+ if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
+ BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
+
+ ObjectMapper mapper = getObjectMapper();
+
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ response = mapper.readValue(reader, SearchResults.class);
+ LOGwriteEndingTrace(HttpURLConnection.HTTP_OK, "SUCCESS", mapper.writeValueAsString(response));
+ } else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
+ LOGwriteEndingTrace(responseCode, "HTTP_NOT_FOUND", "Entry does not exist.");
+ return response;
+ } else {
+ ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
+ LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse));
+ throw new AAIServiceException(responseCode, errorresponse);
+ }
+
+ } catch(AAIServiceException aaiexc) {
+ throw aaiexc;
+ } catch (Exception exc) {
+ LOG.warn("requestNodeQuery", exc);
+ throw new AAIServiceException(exc);
+ } finally {
+ if(inputStream != null){
+ try {
+ inputStream.close();
+ } catch(Exception exc) {
+
+ }
+ }
+ }
+ return response;
+
+ }
+
+
+ @Override
+ public String requestDataByURL(URL url) throws AAIServiceException {
+
+ if(url == null) {
+ throw new NullPointerException();
+ }
+
+ String response = null;
+ InputStream inputStream = null;
+
+ try {
+ URL http_req_url = url;