Issue-ID: POLICY-4864
Change-Id: Ieed49019bee3dbd9e5c81dde341d18e6f4bac784
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));\r
}\r
try {\r
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(body);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
final var msg = "POST /policytypes";\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(body);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
final var msg = "POST /policytypes";\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
+ } catch (InterruptedException e) {\r
+ Thread.currentThread().interrupt();\r
+ throw new PolicyApiRuntimeException(e.getMessage(), null, null, requestId);\r
+ } finally {\r
+ mutex.release();\r
String versionId,\r
UUID requestId) {\r
try {\r
String versionId,\r
UUID requestId) {\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("DELETE /policytypes/%s/versions/%s", policyTypeId, versionId);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("DELETE /policytypes/%s/versions/%s", policyTypeId, versionId);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
+ } catch (InterruptedException e) {\r
+ Thread.currentThread().interrupt();\r
+ throw new PolicyApiRuntimeException(e.getMessage(), null, null, requestId);\r
+ } finally {\r
+ mutex.release();\r
"/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));\r
}\r
try {\r
"/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.createPolicy(policyTypeId, policyTypeVersion, body);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("POST /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.createPolicy(policyTypeId, policyTypeVersion, body);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("POST /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
+ } catch (InterruptedException e) {\r
+ Thread.currentThread().interrupt();\r
+ throw new PolicyApiRuntimeException(e.getMessage(), null, null, requestId);\r
+ } finally {\r
+ mutex.release();\r
String policyVersion,\r
UUID requestId) {\r
try {\r
String policyVersion,\r
UUID requestId) {\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);\r
return makeOkResponse(requestId, serviceTemplate);\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);\r
return makeOkResponse(requestId, serviceTemplate);\r
var msg = String.format("DELETE /policytypes/%s/versions/%s/policies/%s/versions/%s",\r
policyTypeId, policyTypeVersion, policyId, policyVersion);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
var msg = String.format("DELETE /policytypes/%s/versions/%s/policies/%s/versions/%s",\r
policyTypeId, policyTypeVersion, policyId, policyVersion);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
+ } catch (InterruptedException e) {\r
+ Thread.currentThread().interrupt();\r
+ throw new PolicyApiRuntimeException(e.getMessage(), null, null, requestId);\r
+ } finally {\r
+ mutex.release();\r
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));\r
}\r
try {\r
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicies(body);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
final var msg = "POST /policies";\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicies(body);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
final var msg = "POST /policies";\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
+ } catch (InterruptedException e) {\r
+ Thread.currentThread().interrupt();\r
+ throw new PolicyApiRuntimeException(e.getMessage(), null, null, requestId);\r
+ } finally {\r
+ mutex.release();\r
String policyVersion,\r
UUID requestId) {\r
try {\r
String policyVersion,\r
UUID requestId) {\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.deletePolicy(null, null, policyId, policyVersion);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("DELETE /policies/%s/versions/%s", policyId, policyVersion);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.deletePolicy(null, null, policyId, policyVersion);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("DELETE /policies/%s/versions/%s", policyId, policyVersion);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
+ } catch (InterruptedException e) {\r
+ Thread.currentThread().interrupt();\r
+ throw new PolicyApiRuntimeException(e.getMessage(), null, null, requestId);\r
+ } finally {\r
+ mutex.release();\r
\r
import java.util.Objects;\r
import java.util.UUID;\r
\r
import java.util.Objects;\r
import java.util.UUID;\r
+import java.util.concurrent.Semaphore;\r
import org.onap.policy.api.main.exception.PolicyApiRuntimeException;\r
import org.onap.policy.common.utils.coder.Coder;\r
import org.onap.policy.common.utils.coder.CoderException;\r
import org.onap.policy.api.main.exception.PolicyApiRuntimeException;\r
import org.onap.policy.common.utils.coder.Coder;\r
import org.onap.policy.common.utils.coder.CoderException;\r
*/\r
public class CommonRestController {\r
\r
*/\r
public class CommonRestController {\r
\r
+ protected static Semaphore mutex = new Semaphore(1);\r
+\r
private static final Logger LOGGER = LoggerFactory.getLogger(CommonRestController.class);\r
\r
protected static final String EXTENSION_NAME = "interface info";\r
private static final Logger LOGGER = LoggerFactory.getLogger(CommonRestController.class);\r
\r
protected static final String EXTENSION_NAME = "interface info";\r
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);
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();
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);
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();
@Override
public ResponseEntity<ToscaServiceTemplate> deleteToscaNodeTemplates(String name, String version, UUID requestId) {
try {
@Override
public ResponseEntity<ToscaServiceTemplate> deleteToscaNodeTemplates(String name, String version, UUID requestId) {
try {
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);
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();