Merge "Fix synchronization issues in policy-api"
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / NodeTemplateController.java
index 4496266..944a6f8 100644 (file)
@@ -63,11 +63,17 @@ public class NodeTemplateController extends CommonRestController implements Tosc
                 toJson(body));
         }
         try {
+            mutex.acquire();
             ToscaServiceTemplate nodeTemplates = toscaServiceTemplateService.createToscaNodeTemplates(body);
             return makeOkResponse(requestId, nodeTemplates);
         } catch (PfModelException | PfModelRuntimeException pfme) {
             final var msg = "POST /nodetemplates";
             throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new PolicyApiRuntimeException(e.getMessage(), null, null, requestId);
+        } finally {
+            mutex.release();
         }
     }
 
@@ -86,11 +92,17 @@ public class NodeTemplateController extends CommonRestController implements Tosc
                 toJson(body));
         }
         try {
+            mutex.acquire();
             ToscaServiceTemplate nodeTemplates = toscaServiceTemplateService.updateToscaNodeTemplates(body);
             return makeOkResponse(requestId, nodeTemplates);
         } catch (PfModelException | PfModelRuntimeException pfme) {
             final var msg = "PUT /nodetemplates";
             throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new PolicyApiRuntimeException(e.getMessage(), null, null, requestId);
+        } finally {
+            mutex.release();
         }
     }
 
@@ -104,11 +116,17 @@ public class NodeTemplateController extends CommonRestController implements Tosc
     @Override
     public ResponseEntity<ToscaServiceTemplate> deleteToscaNodeTemplates(String name, String version, UUID requestId) {
         try {
+            mutex.acquire();
             ToscaServiceTemplate nodeTemplates = toscaServiceTemplateService.deleteToscaNodeTemplate(name, version);
             return makeOkResponse(requestId, nodeTemplates);
         } catch (PfModelException | PfModelRuntimeException pfme) {
             final var msg = String.format("DELETE /nodetemplates/%s/versions/%s", name, version);
             throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new PolicyApiRuntimeException(e.getMessage(), null, null, requestId);
+        } finally {
+            mutex.release();
         }
     }