aboutsummaryrefslogtreecommitdiffstats
path: root/asdc-controller/src/main/java/org
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-24 10:42:15 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-24 16:10:26 -0500
commit20e1b6517b1c64a82cb52be8a2a2882c86b1318b (patch)
tree68acb7b130d6c479eaaa6ba91275b5b2b2897bb6 /asdc-controller/src/main/java/org
parent57af0e334073b329ca9f48b353ab4cc3bd2027a8 (diff)
Prevent race conditions on same distributionId.
- Code to include optimistic lock to prevent race conditions on same distributionId. Change-Id: Ibe110b32f2472d991a4a3e03e3d15d5e4deefd65 Issue-ID: SO-1566 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'asdc-controller/src/main/java/org')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java15
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java15
2 files changed, 24 insertions, 6 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
index 7a02f47d3f..a21deee51a 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
@@ -30,6 +30,7 @@ import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
+import org.hibernate.StaleObjectStateException;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.consumer.IDistributionStatusMessage;
import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
@@ -58,6 +59,7 @@ import org.onap.so.db.request.data.repository.WatchdogDistributionStatusReposito
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.orm.ObjectOptimisticLockingFailureException;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@@ -592,6 +594,7 @@ public class ASDCController {
try {
LOGGER.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, iNotif.getServiceUUID(), "ASDC", "treatNotification");
+
this.changeControllerStatus(ASDCControllerStatus.BUSY);
Optional<String> notificationMessage = getNotificationJson(iNotif);
toscaInstaller.processWatchdog(iNotif.getDistributionID(), iNotif.getServiceUUID(), notificationMessage,
@@ -619,7 +622,7 @@ public class ASDCController {
distributionStatus = wd.getOverallDistributionStatus(iNotif.getDistributionID());
Thread.sleep(watchDogTimeout / 10);
}catch(Exception e){
- LOGGER.debug ("Exception in Watchdog Loop " + e);
+ LOGGER.debug ("Exception in Watchdog Loop " + e.getMessage());
Thread.sleep(watchDogTimeout / 10);
}
@@ -651,7 +654,7 @@ public class ASDCController {
LOGGER.debug ("A&AI Updated succefully with Distribution Status!");
}
catch(Exception e) {
- LOGGER.debug ("Exception in Watchdog executePatchAAI(): " + e);
+ LOGGER.debug ("Exception in Watchdog executePatchAAI(): " + e.getMessage());
watchdogError = "Error calling A&AI " + e.getMessage();
if(e.getCause() != null) {
LOGGER.debug ("Exception caused by: " + e.getCause().getMessage());
@@ -671,8 +674,14 @@ public class ASDCController {
wdsRepo.save(wds);
}
-
+ } catch(ObjectOptimisticLockingFailureException e) {
+
+ LOGGER.debug ("OptimisticLockingFailure for DistributionId: " + iNotif.getDistributionID() + " Another process has already altered this distribution, so not going to process it on this site.");
+ LOGGER.error (MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
+ "Database concurrency exception: ", "ASDC", "treatNotification", MsoLogger.ErrorCode.BusinessProcesssError, "RuntimeException in treatNotification",
+ e);
+
} catch (Exception e) {
LOGGER.error (MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
"Unexpected exception caught during the notification processing", "ASDC", "treatNotification", MsoLogger.ErrorCode.SchemaError, "RuntimeException in treatNotification",
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
index 10b8ba7c16..60d5d7e061 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
@@ -34,6 +34,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
+import org.hibernate.StaleObjectStateException;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.exception.LockAcquisitionException;
import org.onap.sdc.api.notification.IArtifactInfo;
@@ -124,6 +125,7 @@ import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepos
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.orm.ObjectOptimisticLockingFailureException;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -701,10 +703,17 @@ public class ToscaResourceInstaller {
distributionNotification, consumerId);
watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
- WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
- watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
+ try{
+
+ WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
+ watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
+
+ } catch(ObjectOptimisticLockingFailureException e){
+ logger.debug("ObjectOptimisticLockingFailureException in processWatchdog : " + e.toString());
+ throw e;
+ }
}
-
+
protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
VfResourceStructure vfResourceStructure) {
for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {