diff options
author | liamfallon <liam.fallon@est.tech> | 2020-05-02 01:35:07 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-05-04 21:20:38 +0100 |
commit | 275a3c5707c721d6fb020c9632f7a545cbc33b81 (patch) | |
tree | b4d45d330c51356fc0eb5c494b14e7645a7bc7d7 /models-tosca/src | |
parent | c86d6a6645af95d76a8b2b59f24433c616bf49fe (diff) |
Fix simultaneous write access to policy provider
This change serializes write access to the policy database via the
AUthorative TOSCA provider by making sure that only one request is
executed at a time. His change should be repolaced by proper session
handling in the next release of the Policy Framework project.
Issue-ID: POLICY-2533
Change-Id: I5fe4c0f2846981a66eb2f4e1da936fe3c9490ae5
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src')
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java | 79 |
1 files changed, 47 insertions, 32 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java index a4a6e5942..c595b557e 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java @@ -56,6 +56,9 @@ import org.slf4j.LoggerFactory; public class AuthorativeToscaProvider { private static final Logger LOGGER = LoggerFactory.getLogger(AuthorativeToscaProvider.class); + // TODO: In next release this locking mechanism should be removed and replaced with proper session handling + private static final Object providerLockObject = "providerLockObject"; + /** * Get policy types. * @@ -178,13 +181,15 @@ public class AuthorativeToscaProvider { public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao, @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { - LOGGER.debug("->createPolicyTypes: serviceTemplate={}", serviceTemplate); + synchronized (providerLockObject) { + LOGGER.debug("->createPolicyTypes: serviceTemplate={}", serviceTemplate); - ToscaServiceTemplate createdServiceTempalate = new SimpleToscaProvider() - .createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); + ToscaServiceTemplate createdServiceTempalate = new SimpleToscaProvider() + .createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); - LOGGER.debug("<-createPolicyTypes: createdServiceTempalate={}", createdServiceTempalate); - return createdServiceTempalate; + LOGGER.debug("<-createPolicyTypes: createdServiceTempalate={}", createdServiceTempalate); + return createdServiceTempalate; + } } /** @@ -198,13 +203,15 @@ public class AuthorativeToscaProvider { public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao, @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { - LOGGER.debug("->updatePolicyTypes: serviceTempalate={}", serviceTemplate); + synchronized (providerLockObject) { + LOGGER.debug("->updatePolicyTypes: serviceTempalate={}", serviceTemplate); - ToscaServiceTemplate updatedServiceTempalate = new SimpleToscaProvider() - .updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); + ToscaServiceTemplate updatedServiceTempalate = new SimpleToscaProvider() + .updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); - LOGGER.debug("<-updatePolicyTypes: updatedServiceTempalate={}", updatedServiceTempalate); - return updatedServiceTempalate; + LOGGER.debug("<-updatePolicyTypes: updatedServiceTempalate={}", updatedServiceTempalate); + return updatedServiceTempalate; + } } /** @@ -219,14 +226,16 @@ public class AuthorativeToscaProvider { public ToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao, @NonNull final String name, @NonNull final String version) throws PfModelException { - LOGGER.debug("->deletePolicyType: name={}, version={}", name, version); + synchronized (providerLockObject) { + LOGGER.debug("->deletePolicyType: name={}, version={}", name, version); - ToscaServiceTemplate deletedServiceTempalate = - new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative(); + ToscaServiceTemplate deletedServiceTempalate = + new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative(); - LOGGER.debug("<-deletePolicyType: name={}, version={}, deletedServiceTempalate={}", name, version, - deletedServiceTempalate); - return deletedServiceTempalate; + LOGGER.debug("<-deletePolicyType: name={}, version={}, deletedServiceTempalate={}", name, version, + deletedServiceTempalate); + return deletedServiceTempalate; + } } /** @@ -348,13 +357,15 @@ public class AuthorativeToscaProvider { public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao, @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { - LOGGER.debug("->createPolicies: serviceTempalate={}", serviceTemplate); + synchronized (providerLockObject) { + LOGGER.debug("->createPolicies: serviceTempalate={}", serviceTemplate); - ToscaServiceTemplate createdServiceTempalate = - new SimpleToscaProvider().createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); + ToscaServiceTemplate createdServiceTempalate = new SimpleToscaProvider() + .createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); - LOGGER.debug("<-createPolicies: createdServiceTempalate={}", createdServiceTempalate); - return createdServiceTempalate; + LOGGER.debug("<-createPolicies: createdServiceTempalate={}", createdServiceTempalate); + return createdServiceTempalate; + } } /** @@ -368,13 +379,15 @@ public class AuthorativeToscaProvider { public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao, @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { - LOGGER.debug("->updatePolicies: serviceTempalate={}", serviceTemplate); + synchronized (providerLockObject) { + LOGGER.debug("->updatePolicies: serviceTempalate={}", serviceTemplate); - ToscaServiceTemplate updatedServiceTempalate = - new SimpleToscaProvider().updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); + ToscaServiceTemplate updatedServiceTempalate = new SimpleToscaProvider() + .updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); - LOGGER.debug("<-updatePolicies: updatedServiceTempalate={}", updatedServiceTempalate); - return updatedServiceTempalate; + LOGGER.debug("<-updatePolicies: updatedServiceTempalate={}", updatedServiceTempalate); + return updatedServiceTempalate; + } } /** @@ -389,14 +402,16 @@ public class AuthorativeToscaProvider { public ToscaServiceTemplate deletePolicy(@NonNull final PfDao dao, @NonNull final String name, @NonNull final String version) throws PfModelException { - LOGGER.debug("->deletePolicy: name={}, version={}", name, version); + synchronized (providerLockObject) { + LOGGER.debug("->deletePolicy: name={}, version={}", name, version); - ToscaServiceTemplate deletedServiceTempalate = - new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative(); + ToscaServiceTemplate deletedServiceTempalate = + new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative(); - LOGGER.debug("<-deletePolicy: name={}, version={}, deletedServiceTempalate={}", name, version, - deletedServiceTempalate); - return deletedServiceTempalate; + LOGGER.debug("<-deletePolicy: name={}, version={}, deletedServiceTempalate={}", name, version, + deletedServiceTempalate); + return deletedServiceTempalate; + } } /** |