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