a1419d143d5cafd663f6404d1caca87f75548c8a
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / util / RestController.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.aai.util;
22
23 import com.att.eelf.configuration.EELFLogger;
24 import com.att.eelf.configuration.EELFManager;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.fasterxml.jackson.databind.type.TypeFactory;
27 import com.sun.jersey.api.client.Client;
28 import com.sun.jersey.api.client.ClientHandlerException;
29 import com.sun.jersey.api.client.ClientResponse;
30
31 import java.security.KeyManagementException;
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.UUID;
35
36 import org.onap.aai.exceptions.AAIException;
37 import org.onap.aai.logging.LoggingContext;
38
39 public class RestController implements RestControllerInterface {
40
41     private static final String TARGET_NAME = "AAI";
42     private static EELFLogger LOGGER = EELFManager.getInstance().getLogger(RestController.class);
43
44     private static Client client = null;
45
46     private String restSrvrBaseURL;
47
48     private String overrideLocalHost = null;
49
50     // To do - Come up with helper function that will automatically
51     // generate the REST API path based on path parameter(s) and query parameter(s)!
52     public static final String REST_APIPATH_COMPLEXES = "cloud-infrastructure/complexes";
53     public static final String REST_APIPATH_COMPLEX = "cloud-infrastructure/complexes/complex/";
54     public static final String REST_APIPATH_PSERVERS = "cloud-infrastructure/pservers";
55     public static final String REST_APIPATH_PSERVER = "cloud-infrastructure/pservers/pserver/";
56     public static final String REST_APIPATH_PHYSICALLINKS = "network/physical-links/";
57     public static final String REST_APIPATH_PHYSICALLINK = "network/physical-links/physical-link/";
58     public static final String REST_APIPATH_PINTERFACES = "network/p-interfaces/";
59     public static final String REST_APIPATH_PINTERFACE = "network/p-interfaces/p-interface/";
60     public static final String REST_APIPATH_VPLSPES = "network/vpls-pes/";
61     public static final String REST_APIPATH_VPLSPE = "network/vpls-pes/vpls-pe/";
62     public static final String REST_APIPATH_UPDATE = "actions/update/";
63     public static final String REST_APIPATH_SEARCH = "search/nodes-query?search-node-type=";
64
65     public static final String REST_APIPATH_CLOUDREGION = "cloud-infrastructure/cloud-regions/cloud-region/";
66     public static final String REST_APIPATH_TENANT = "cloud-infrastructure/tenants/tenant/";
67     public static final String REST_APIPATH_VIRTUAL_DATA_CENTER =
68             "cloud-infrastructure/virtual-data-centers/virtual-data-center/";
69     public static final String REST_APIPATH_VIRTUAL_DATA_CENTERS = "cloud-infrastructure/virtual-data-centers/";
70     public static final String REST_APIPATH_GENERIC_VNF = "network/generic-vnfs/generic-vnf/";
71     public static final String REST_APIPATH_GENERIC_VNFS = "network/generic-vnfs";
72     public static final String REST_APIPATH_L3_NETWORK = "network/l3-networks/l3-network/";
73     public static final String REST_APIPATH_L3_NETWORKS = "network/l3-networks";
74     public static final String REST_APIPATH_INSTANCE_GROUP = "network/instance-groups/instance-group";
75     public static final String REST_APIPATH_INSTANCE_GROUPS = "network/instance-groups";
76     public static final String REST_APIPATH_VFMODULE = "nodes/vf-modules/vf-module/";
77
78     public static final String REST_APIPATH_VCE = "network/vces/vce/";
79
80     public static final String REST_APIPATH_SERVICE = "service-design-and-creation/services/service/";
81     public static final String REST_APIPATH_LOGICALLINKS = "network/logical-links/";
82     public static final String REST_APIPATH_LOGICALLINK = "network/logical-links/logical-link/";
83
84     public RestController() throws AAIException {
85         this.initRestClient();
86     }
87
88     /**
89      * Inits the rest client.
90      *
91      * @throws AAIException the AAI exception
92      */
93     public void initRestClient() throws AAIException {
94         if (client == null) {
95             try {
96                 client = getHttpsAuthClient();
97             } catch (KeyManagementException e) {
98                 throw new AAIException("AAI_7117", "KeyManagementException in REST call to DB: " + e.toString());
99             } catch (Exception e) {
100                 throw new AAIException("AAI_7117", " Exception in REST call to DB: " + e.toString());
101             }
102         }
103     }
104
105     public Client getHttpsAuthClient() throws KeyManagementException {
106         return HttpsAuthClient.getClient();
107     }
108
109     /**
110      * Sets the rest srvr base URL.
111      *
112      * @param baseURL the base URL
113      * @throws AAIException the AAI exception
114      */
115     public void SetRestSrvrBaseURL(String baseURL) throws AAIException {
116         if (baseURL == null)
117             throw new AAIException("AAI_7117", "REST Server base URL cannot be null.");
118         restSrvrBaseURL = baseURL;
119     }
120
121     /**
122      * Gets the rest srvr base URL.
123      *
124      * @return the rest srvr base URL
125      */
126     public String getRestSrvrBaseURL() {
127         return restSrvrBaseURL;
128     }
129
130     public <T> void Get(T t, String sourceID, String transId, String path, RestObject<T> restObject, boolean oldserver)
131             throws AAIException {
132         Get(t, sourceID, transId, path, restObject, oldserver, AAIConstants.AAI_RESOURCES_PORT);
133     }
134
135     /**
136      * To do - optimization and automation. Also make it as generic as possible.
137      *
138      * @param <T> the generic type
139      * @param t the t
140      * @param sourceID the source ID
141      * @param transId the trans id
142      * @param path the path
143      * @param restObject the rest object
144      * @param oldserver the oldserver
145      * @throws AAIException the AAI exception
146      */
147     @SuppressWarnings("unchecked")
148     public <T> void Get(T t, String sourceID, String transId, String path, RestObject<T> restObject, boolean oldserver,
149             int port) throws AAIException {
150         String methodName = "Get";
151         String url = "";
152         transId += ":" + UUID.randomUUID().toString();
153
154         LoggingContext.save();
155         LoggingContext.partnerName(sourceID);
156         LoggingContext.targetEntity(TARGET_NAME);
157         LoggingContext.requestId(transId);
158         LoggingContext.serviceName(methodName);
159         LoggingContext.targetServiceName(methodName);
160
161         LOGGER.debug(methodName + " start");
162
163         restObject.set(t);
164
165         if (oldserver) {
166             url = AAIConfig.get(AAIConstants.AAI_OLDSERVER_URL) + path;
167         } else {
168             if (overrideLocalHost == null) {
169                 overrideLocalHost =
170                         AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE, AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
171             }
172             if (AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT.equals(overrideLocalHost)) {
173                 url = String.format(AAIConstants.AAI_LOCAL_REST, port,
174                         AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)) + path;
175             } else {
176                 url = String.format(AAIConstants.AAI_LOCAL_REST_OVERRIDE, overrideLocalHost,
177                         AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)) + path;
178             }
179         }
180         initRestClient();
181         LOGGER.debug(url + " for the get REST API");
182         ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
183                 .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json")
184                 .get(ClientResponse.class);
185
186         // System.out.println("cres.EntityInputSream()="+cres.getEntityInputStream().toString());
187         // System.out.println("cres.tostring()="+cres.toString());
188
189         if (cres.getStatus() == 200) {
190             // System.out.println(methodName + ": url=" + url);
191             t = (T) cres.getEntity(t.getClass());
192             restObject.set(t);
193             LOGGER.debug(methodName + "REST api GET was successfull!");
194         } else {
195             LoggingContext.restore();
196             // System.out.println(methodName + ": url=" + url + " failed with status=" + cres.getStatus());
197             throw new AAIException("AAI_7116", methodName + " with status=" + cres.getStatus() + ", url=" + url);
198         }
199
200         LoggingContext.restore();
201     }
202
203     /**
204      * To do - optimization and automation. Also make it as generic as possible.
205      *
206      * @param <T> the generic type
207      * @param t the t
208      * @param sourceID the source ID
209      * @param transId the trans id
210      * @param path the path
211      * @param restObject the rest object
212      * @param oldserver the oldserver
213      * @throws AAIException the AAI exception
214      */
215     @SuppressWarnings("unchecked")
216     public <T> void Get(T t, String sourceID, String transId, String path, RestObject<T> restObject, String apiVersion)
217             throws AAIException {
218         String methodName = "Get";
219         String url = "";
220         transId += ":" + UUID.randomUUID().toString();
221
222         LoggingContext.save();
223         LoggingContext.partnerName(sourceID);
224         LoggingContext.targetEntity(TARGET_NAME);
225         LoggingContext.requestId(transId);
226         LoggingContext.serviceName(methodName);
227         LoggingContext.targetServiceName(methodName);
228
229         LOGGER.debug(methodName + " start");
230
231         restObject.set(t);
232
233         url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + apiVersion + "/" + path;
234
235         initRestClient();
236         LOGGER.debug(url + " for the get REST API");
237         ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
238                 .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json")
239                 .get(ClientResponse.class);
240
241         // System.out.println("cres.EntityInputSream()="+cres.getEntityInputStream().toString());
242         // System.out.println("cres.tostring()="+cres.toString());
243
244         if (cres.getStatus() == 200) {
245             // System.out.println(methodName + ": url=" + url);
246             t = (T) cres.getEntity(t.getClass());
247             restObject.set(t);
248             LOGGER.debug(methodName + "REST api GET was successfull!");
249         } else {
250             LoggingContext.restore();
251             // System.out.println(methodName + ": url=" + url + " failed with status=" + cres.getStatus());
252             throw new AAIException("AAI_7116", methodName + " with status=" + cres.getStatus() + ", url=" + url);
253         }
254
255         LoggingContext.restore();
256     }
257
258     /**
259      * Map json to object list.
260      *
261      * @param <T> the generic type
262      * @param typeDef the type def
263      * @param json the json
264      * @param clazz the clazz
265      * @return the list
266      * @throws Exception the exception
267      */
268     private <T> List<T> mapJsonToObjectList(T typeDef, String json, Class clazz) throws Exception {
269         List<T> list;
270         ObjectMapper mapper = new ObjectMapper();
271         System.out.println(json);
272         TypeFactory t = TypeFactory.defaultInstance();
273         list = mapper.readValue(json, t.constructCollectionType(ArrayList.class, clazz));
274
275         return list;
276     }
277
278     /**
279      * Put.
280      *
281      * @param <T> the generic type
282      * @param t the t
283      * @param sourceID the source ID
284      * @param transId the trans id
285      * @param path the path
286      * @throws AAIException the AAI exception
287      */
288     public <T> void Put(T t, String sourceID, String transId, String path) throws AAIException {
289         Put(t, sourceID, transId, path, false, AAIConstants.AAI_RESOURCES_PORT);
290     }
291
292     /**
293      * Put.
294      *
295      * @param <T> the generic type
296      * @param t the t
297      * @param sourceID the source ID
298      * @param transId the trans id
299      * @param path the path
300      * @throws AAIException the AAI exception
301      */
302     public <T> void Put(T t, String sourceID, String transId, String path, boolean oldserver) throws AAIException {
303         Put(t, sourceID, transId, path, oldserver, AAIConstants.AAI_RESOURCES_PORT);
304     }
305
306     /**
307      * Put.
308      *
309      * @param <T> the generic type
310      * @param t the t
311      * @param sourceID the source ID
312      * @param transId the trans id
313      * @param path the path
314      * @param oldserver the oldserver
315      * @throws AAIException the AAI exception
316      */
317     public <T> void Put(T t, String sourceID, String transId, String path, boolean oldserver, int port)
318             throws AAIException {
319         String methodName = "Put";
320         String url = "";
321         transId += ":" + UUID.randomUUID().toString();
322
323         LoggingContext.save();
324         LoggingContext.partnerName(sourceID);
325         LoggingContext.targetEntity(TARGET_NAME);
326         LoggingContext.requestId(transId);
327         LoggingContext.serviceName(methodName);
328         LoggingContext.targetServiceName(methodName);
329
330         LOGGER.debug(methodName + " start");
331
332         initRestClient();
333
334         if (oldserver) {
335             url = AAIConfig.get(AAIConstants.AAI_OLDSERVER_URL) + path;
336         } else {
337             if (overrideLocalHost == null) {
338                 overrideLocalHost =
339                         AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE, AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
340             }
341             if (AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT.equals(overrideLocalHost)) {
342                 url = String.format(AAIConstants.AAI_LOCAL_REST, port,
343                         AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)) + path;
344             } else {
345                 url = String.format(AAIConstants.AAI_LOCAL_REST_OVERRIDE, overrideLocalHost,
346                         AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)) + path;
347             }
348         }
349
350         ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
351                 .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json").entity(t)
352                 .put(ClientResponse.class);
353
354         // System.out.println("cres.tostring()="+cres.toString());
355
356         int statuscode = cres.getStatus();
357         if (statuscode >= 200 && statuscode <= 299) {
358             LOGGER.debug(methodName + ": url=" + url + ", request=" + path);
359             LoggingContext.restore();
360         } else {
361             LoggingContext.restore();
362             throw new AAIException("AAI_7116", methodName + " with status=" + statuscode + ", url=" + url + ", msg="
363                     + cres.getEntity(String.class));
364         }
365     }
366
367     public void Delete(String sourceID, String transId, String path) throws AAIException {
368         Delete(sourceID, transId, path, AAIConstants.AAI_RESOURCES_PORT);
369     }
370
371     /**
372      * Delete.
373      *
374      * @param sourceID the source ID
375      * @param transId the trans id
376      * @param path the path
377      * @throws AAIException the AAI exception
378      */
379     public void Delete(String sourceID, String transId, String path, int port) throws AAIException {
380         String methodName = "Delete";
381         String url = "";
382         transId += ":" + UUID.randomUUID().toString();
383
384         LoggingContext.save();
385         LoggingContext.partnerName(sourceID);
386         LoggingContext.targetEntity(TARGET_NAME);
387         LoggingContext.requestId(transId);
388         LoggingContext.serviceName(methodName);
389         LoggingContext.targetServiceName(methodName);
390
391         LOGGER.debug(methodName + " start");
392
393         initRestClient();
394         String request = "{}";
395         if (overrideLocalHost == null) {
396             overrideLocalHost = AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE, AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
397         }
398         if (AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT.equals(overrideLocalHost)) {
399             url = String.format(AAIConstants.AAI_LOCAL_REST, port,
400                     AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)) + path;
401         } else {
402             url = String.format(AAIConstants.AAI_LOCAL_REST_OVERRIDE, overrideLocalHost,
403                     AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)) + path;
404         }
405         ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
406                 .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json").entity(request)
407                 .delete(ClientResponse.class);
408
409         if (cres.getStatus() == 404) { // resource not found
410             LOGGER.info("Resource does not exist...: " + cres.getStatus() + ":" + cres.getEntity(String.class));
411             LoggingContext.restore();
412         } else if (cres.getStatus() == 200 || cres.getStatus() == 204) {
413             LOGGER.info("Resource " + url + " deleted");
414             LoggingContext.restore();
415         } else {
416             LOGGER.error("Deleting Resource failed: " + cres.getStatus() + ":" + cres.getEntity(String.class));
417             LoggingContext.restore();
418             throw new AAIException("AAI_7116", "Error during DELETE");
419         }
420     }
421
422     public <T> String Post(T t, String sourceID, String transId, String path) throws Exception {
423         return Post(t, sourceID, transId, path, AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP));
424     }
425
426     /**
427      * Post.
428      *
429      * @param <T> the generic type
430      * @param t the t
431      * @param sourceID the source ID
432      * @param transId the trans id
433      * @param path the path
434      * @param apiVersion the apiVersion
435      * @return the string
436      * @throws Exception the exception
437      */
438     public <T> String Post(T t, String sourceID, String transId, String path, String apiVersion) throws Exception {
439         String methodName = "Post";
440         String url = "";
441         transId += ":" + UUID.randomUUID().toString();
442
443         LoggingContext.save();
444         LoggingContext.partnerName(sourceID);
445         LoggingContext.targetEntity(TARGET_NAME);
446         LoggingContext.requestId(transId);
447         LoggingContext.serviceName(methodName);
448         LoggingContext.targetServiceName(methodName);
449
450         LOGGER.debug(methodName + " start");
451
452         try {
453
454             initRestClient();
455             url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + apiVersion + "/" + path;
456
457             ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
458                     .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json").entity(t)
459                     .post(ClientResponse.class);
460
461             int statuscode = cres.getStatus();
462             if (statuscode >= 200 && statuscode <= 299) {
463                 LOGGER.debug(methodName + "REST api POST was successful!");
464                 return cres.getEntity(String.class);
465             } else {
466                 throw new AAIException("AAI_7116", methodName + " with status=" + statuscode + ", url=" + url + ", msg="
467                         + cres.getEntity(String.class));
468             }
469
470         } catch (AAIException e) {
471             throw new AAIException("AAI_7116", methodName + " with url=" + url + ", Exception: " + e.toString());
472         } catch (Exception e) {
473             throw new AAIException("AAI_7116", methodName + " with url=" + url + ", Exception: " + e.toString());
474
475         } finally {
476             LoggingContext.restore();
477         }
478     }
479
480     /**
481      * Gets the single instance of RestController.
482      *
483      * @param <T> the generic type
484      * @param clazz the clazz
485      * @return single instance of RestController
486      * @throws IllegalAccessException the illegal access exception
487      * @throws InstantiationException the instantiation exception
488      */
489     public <T> T getInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException {
490         return clazz.newInstance();
491     }
492
493     /**
494      * Does resource exist.
495      *
496      * @param <T> the generic type
497      * @param resourcePath the resource path
498      * @param resourceClassName the resource class name
499      * @param fromAppId the from app id
500      * @param transId the trans id
501      * @return the t
502      */
503     /*
504      * DoesResourceExist
505      * 
506      * To check whether a resource exist or get a copy of the existing version of the resource
507      * 
508      * Resourcepath: should contain the qualified resource path (including encoded unique key identifier value),
509      * resourceClassName: is the canonical name of the resource class name,
510      * fromAppId:
511      * transId:
512      * 
513      * Will return null (if the resource doesn’t exist) (or)
514      * Will return the specified resource from the Graph.
515      * 
516      * Example:
517      * LogicalLink llink = new LogicalLink();
518      * String resourceClassName = llink.getClass().getCanonicalName();
519      * llink = RestController.DoesResourceExist("network/logical-links/logical-link/" + <encoded-link-name>,
520      * resourceClassName, fromAppId, transId);
521      */
522     public <T> T DoesResourceExist(String resourcePath, String resourceClassName, String fromAppId, String transId) {
523
524         try {
525
526             RestObject<T> restObj = new RestObject<T>();
527             @SuppressWarnings("unchecked")
528             T resourceObj = (T) getInstance(Class.forName(resourceClassName));
529             restObj.set(resourceObj);
530             Get(resourceObj, fromAppId, transId, resourcePath, restObj, false, AAIConstants.AAI_RESOURCES_PORT);
531
532             resourceObj = restObj.get();
533             if (resourceObj != null)
534                 return resourceObj;
535
536         } catch (AAIException e) {
537
538         } catch (ClientHandlerException che) {
539
540         } catch (Exception e) {
541
542         }
543
544         return null;
545     }
546
547     /**
548      * Patch.
549      *
550      * @param <T> the generic type
551      * @param sourceID the source ID
552      * @param transId the trans id
553      * @param path the path
554      * @throws AAIException the AAI exception
555      */
556     public <T> void Patch(T t, String sourceID, String transId, String path) throws AAIException {
557         String methodName = "Patch";
558         String url = "";
559         transId += ":" + UUID.randomUUID().toString();
560
561         LoggingContext.save();
562         LoggingContext.partnerName(sourceID);
563         LoggingContext.targetEntity(TARGET_NAME);
564         LoggingContext.requestId(transId);
565         LoggingContext.serviceName(methodName);
566         LoggingContext.targetServiceName(methodName);
567
568         int numRetries = 5;
569         ClientResponse cres = null;
570         int statusCode = -1;
571
572         try {
573             if (overrideLocalHost == null) {
574                 overrideLocalHost =
575                         AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE, AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
576             }
577             if (AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT.equals(overrideLocalHost)) {
578                 url = String.format(AAIConstants.AAI_LOCAL_REST, AAIConstants.AAI_RESOURCES_PORT,
579                         AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)) + path;
580             } else {
581                 url = String.format(AAIConstants.AAI_LOCAL_REST_OVERRIDE, overrideLocalHost,
582                         AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)) + path;
583             }
584
585             initRestClient();
586             do {
587
588                 cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
589                         .header("X-FromAppId", sourceID).header("X-HTTP-Method-Override", "PATCH")
590                         .type("application/merge-patch+json").entity(t).post(ClientResponse.class);
591
592                 statusCode = cres.getStatus();
593
594                 if (statusCode >= 200 && statusCode <= 299) {
595                     LOGGER.debug(methodName + "REST api PATCH was successful!");
596                     return;
597                 } else {
598                     LOGGER.debug(methodName + "Unable to make the patch request to url " + url + " so retrying");
599                 }
600
601                 numRetries--;
602
603             } while (numRetries >= 0);
604
605             LOGGER.debug(methodName + "Unable to make the patch request to url " + url + " even after trying = "
606                     + numRetries + " times.");
607             throw new AAIException("AAI_7116", methodName + " with status=" + statusCode + ", url=" + url + ", msg="
608                     + cres.getEntity(String.class));
609
610         } catch (AAIException e) {
611             throw new AAIException("AAI_7116", methodName + " with url=" + url + ", Exception: " + e.toString());
612         } catch (Exception e) {
613             throw new AAIException("AAI_7116", methodName + " with url=" + url + ", Exception: " + e.toString());
614
615         } finally {
616             LoggingContext.restore();
617         }
618
619     }
620 }