store raw distribution notification in db 25/78025/1
authorBenjamin, Max (mb388a) <mb388a@us.att.com>
Thu, 7 Feb 2019 02:17:24 +0000 (21:17 -0500)
committerBenjamin, Max (mb388a) <mb388a@us.att.com>
Thu, 7 Feb 2019 02:17:37 +0000 (21:17 -0500)
updated the test case to verify ASDC notification sent is the same as
one persisted in the DB and verified it
updated the test case to verify ASDC notification sent is the same as
one persisted in the DB
Added unit test case for WatchdogServiceModVerIdLookup changes
Updated test resources schema.sql and data.sql to include changes to
watchdog_service_mod_ver_id_lookup table
Added length to consumer id column with WatchdogServiceModVerIdLookup
class
ASDC Controller has been enhanced to include the notification message
and consumer id as part of existing table
watchdog_service_mod_ver_id_lookup.

Change-Id: Iee805761ffc16f456d068c44b53804a7febc7933
Issue-ID: SO-1475
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.3__Add_Add_Column_To_WatchDog_Model_Id_Lookup.sql [new file with mode: 0644]
asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ArtifactInfoImpl.java
asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java
asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ResourceInfoImpl.java
asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
asdc-controller/src/test/resources/data.sql
asdc-controller/src/test/resources/schema.sql
mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/WatchdogServiceModVerIdLookup.java

diff --git a/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.3__Add_Add_Column_To_WatchDog_Model_Id_Lookup.sql b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.3__Add_Add_Column_To_WatchDog_Model_Id_Lookup.sql
new file mode 100644 (file)
index 0000000..9a5bef6
--- /dev/null
@@ -0,0 +1,6 @@
+use requestdb;
+
+ALTER TABLE watchdog_service_mod_ver_id_lookup ADD DISTRIBUTION_NOTIFICATION LONGTEXT NULL AFTER SERVICE_MODEL_VERSION_ID;
+ALTER TABLE watchdog_service_mod_ver_id_lookup ADD CONSUMER_ID varchar(200) NULL AFTER DISTRIBUTION_NOTIFICATION;
+
+CREATE INDEX watchdog_service_mod_ver_id_lookup_serv_mod_ver_id_idx ON watchdog_service_mod_ver_id_lookup (SERVICE_MODEL_VERSION_ID ASC);
\ No newline at end of file
index ca1d033..7a02f47 100644 (file)
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.nio.file.Paths;
 import java.util.List;
+import java.util.Optional;
 
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.consumer.IDistributionStatusMessage;
@@ -55,11 +56,16 @@ import org.onap.so.asdc.util.ASDCNotificationLogging;
 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
 import org.onap.so.logger.MessageEnum;
-
 import org.onap.so.logger.MsoLogger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
 @Component
 public class ASDCController {
 
@@ -555,6 +561,22 @@ public class ASDCController {
        LOGGER.recordMetricEvent (subStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully sent Final notification to ASDC", "ASDC", null, null);
     }
 
+       private Optional<String> getNotificationJson(INotificationData iNotif) {
+               ObjectMapper mapper = new ObjectMapper();
+               mapper.setSerializationInclusion(Include.NON_NULL);
+               mapper.setSerializationInclusion(Include.NON_EMPTY);
+               mapper.setSerializationInclusion(Include.NON_ABSENT);
+        mapper.enable(MapperFeature.USE_ANNOTATIONS);
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+               Optional<String> returnValue = Optional.empty();
+               try {
+                       returnValue = Optional.of(mapper.writeValueAsString(iNotif));
+               } catch (JsonProcessingException e) {
+                       LOGGER.error("Error converting incoming ASDC notification to JSON" , e);
+               }
+               return returnValue;
+       }
+       
     public void treatNotification (INotificationData iNotif) {
 
        int noOfArtifacts = 0;
@@ -571,7 +593,9 @@ public class ASDCController {
                LOGGER.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
                        LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, iNotif.getServiceUUID(), "ASDC", "treatNotification");
                        this.changeControllerStatus(ASDCControllerStatus.BUSY);
-                       toscaInstaller.processWatchdog(iNotif.getDistributionID(),iNotif.getServiceUUID());     
+                       Optional<String> notificationMessage = getNotificationJson(iNotif);
+                       toscaInstaller.processWatchdog(iNotif.getDistributionID(), iNotif.getServiceUUID(), notificationMessage,
+                                       asdcConfig.getConsumerID());
                        
                        // Process only the Resource artifacts in MSO                           
                        this.processResourceNotification(iNotif);
index 7dab49f..ed97f5b 100644 (file)
@@ -24,6 +24,8 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.onap.sdc.api.notification.IArtifactInfo;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.EqualsBuilder;
 
 public class ArtifactInfoImpl implements IArtifactInfo {
 
@@ -168,4 +170,23 @@ public class ArtifactInfoImpl implements IArtifactInfo {
        public void setRelatedArtifacts(List<ArtifactInfoImpl> relatedArtifacts) {
                this.relatedArtifactsImpl = relatedArtifacts;
        }
+
+       @Override
+       public boolean equals(final Object other) {
+               if (!(other instanceof ArtifactInfoImpl)) {
+                       return false;
+               }
+               ArtifactInfoImpl castOther = (ArtifactInfoImpl) other;
+               return new EqualsBuilder().append(artifactUUID, castOther.artifactUUID)
+                               .append(artifactVersion, castOther.artifactVersion).isEquals();
+       }
+
+       @Override
+       public int hashCode() {
+               return new HashCodeBuilder().append(artifactName).append(artifactType).append(artifactURL)
+                               .append(artifactChecksum).append(artifactDescription).append(artifactTimeout).append(artifactVersion)
+                               .append(artifactUUID).append(generatedFromUUID).append(generatedArtifact).append(relatedArtifactsInfo)
+                               .append(relatedArtifactsImpl).toHashCode();
+       }
+
 }
index 2942213..a1c660f 100644 (file)
@@ -23,11 +23,15 @@ package org.onap.so.asdc.client.test.emulators;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.onap.sdc.api.notification.IArtifactInfo;
 import org.onap.sdc.api.notification.INotificationData;
 import org.onap.sdc.api.notification.IResourceInstance;
 import org.springframework.stereotype.Component;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 @Component
 public class NotificationDataImpl implements INotificationData {
 
@@ -114,6 +118,7 @@ public class NotificationDataImpl implements INotificationData {
                return ret;
        }
        
+       @JsonIgnore
        public List<ResourceInfoImpl> getResourcesImpl(){
                return resources;
        }
@@ -172,4 +177,22 @@ public class NotificationDataImpl implements INotificationData {
                }
                return ret;
        }
+
+       @Override
+       public boolean equals(final Object other) {
+               if (!(other instanceof NotificationDataImpl)) {
+                       return false;
+               }
+               NotificationDataImpl castOther = (NotificationDataImpl) other;
+               return new EqualsBuilder().append(serviceUUID, castOther.serviceUUID)
+                               .append(serviceVersion, castOther.serviceVersion).isEquals();
+       }
+
+       @Override
+       public int hashCode() {
+               return new HashCodeBuilder().append(distributionID).append(serviceName).append(serviceVersion)
+                               .append(serviceUUID).append(serviceDescription).append(serviceInvariantUUID).append(resources)
+                               .append(serviceArtifacts).append(workloadContext).toHashCode();
+       }
+
 }
index eb4764d..dad7e64 100644 (file)
@@ -23,9 +23,13 @@ package org.onap.so.asdc.client.test.emulators;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.onap.sdc.api.notification.IArtifactInfo;
 import org.onap.sdc.api.notification.IResourceInstance;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 public class ResourceInfoImpl implements IResourceInstance{
        ResourceInfoImpl (){}
        private String resourceInstanceName;
@@ -120,7 +124,8 @@ public class ResourceInfoImpl implements IResourceInstance{
                this.artifacts = artifacts;
        }
        
-       public List<ArtifactInfoImpl> getArtifactsImpl(){
+       @JsonIgnore
+       public List<ArtifactInfoImpl> getArtifactsImpl() {
                return artifacts;
        }
        
@@ -155,4 +160,21 @@ public class ResourceInfoImpl implements IResourceInstance{
        public void setSubcategory(String subcategory) {
                this.subcategory = subcategory;
        }
+
+       @Override
+       public boolean equals(final Object other) {
+               if (!(other instanceof ResourceInfoImpl)) {
+                       return false;
+               }
+               ResourceInfoImpl castOther = (ResourceInfoImpl) other;
+               return new EqualsBuilder().append(resourceUUID, castOther.resourceUUID)
+                               .append(resourceVersion, castOther.resourceVersion).isEquals();
+       }
+
+       @Override
+       public int hashCode() {
+               return new HashCodeBuilder().append(resourceInstanceName).append(resourceCustomizationUUID).append(resourceName)
+                               .append(resourceVersion).append(resourceType).append(resourceUUID).append(resourceInvariantUUID)
+                               .append(category).append(subcategory).append(artifacts).toHashCode();
+       }
 }
index ebc705c..2f4d5ea 100644 (file)
@@ -689,8 +689,10 @@ public class ToscaResourceInstaller {
                }
        }
 
-       public void processWatchdog(String distributionId, String servideUUID) {
-               WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID);
+       public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification,
+                       String consumerId) {
+               WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId, servideUUID,
+                               distributionNotification, consumerId);
                watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
                
                WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
index 681ee3b..70737ab 100644 (file)
@@ -59,6 +59,6 @@ insert into requestdb.watchdog_per_component_distribution_status(DISTRIBUTION_ID
 ('testStatusExceptionTosca', 'AAI', 'COMPONENT_MALFORMED'),
 ('testStatusExceptionTosca', 'SDNC', 'COMPONENT_MALFORMED');
 
-insert into requestdb.watchdog_service_mod_ver_id_lookup(DISTRIBUTION_ID, SERVICE_MODEL_VERSION_ID) values
-('watchdogTestStatusSuccess', '5df8b6de-2083-11e7-93ae-92361f002671'),
-('watchdogTestStatusNull', '00000000-0000-0000-0000-000000000000');
+insert into requestdb.watchdog_service_mod_ver_id_lookup(DISTRIBUTION_ID, SERVICE_MODEL_VERSION_ID, DISTRIBUTION_NOTIFICATION, CONSUMER_ID) values
+('watchdogTestStatusSuccess', '5df8b6de-2083-11e7-93ae-92361f002671', NULL, NULL),
+('watchdogTestStatusNull', '00000000-0000-0000-0000-000000000000', NULL, NULL);
index 17423f8..010b36d 100644 (file)
@@ -1008,6 +1008,8 @@ CREATE TABLE `watchdog_per_component_distribution_status` (
 CREATE TABLE `watchdog_service_mod_ver_id_lookup` (
   `DISTRIBUTION_ID` varchar(45) NOT NULL,
   `SERVICE_MODEL_VERSION_ID` varchar(45) NOT NULL,
+  `DISTRIBUTION_NOTIFICATION` LONGTEXT NULL,
+  `CONSUMER_ID` varchar(200) NULL,  
   `CREATE_TIME` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `MODIFY_TIME` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   PRIMARY KEY (`DISTRIBUTION_ID`,`SERVICE_MODEL_VERSION_ID`)
index 77089cb..25f5802 100644 (file)
@@ -22,6 +22,8 @@ package org.onap.so.db.request.beans;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.Objects;
+import java.util.Optional;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -31,7 +33,7 @@ import javax.persistence.PrePersist;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
-import java.util.Objects;
+
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
 @IdClass(WatchdogServiceModVerIdLookupId.class)
@@ -50,6 +52,10 @@ public class WatchdogServiceModVerIdLookup implements Serializable {
        @Id
        @Column(name = "SERVICE_MODEL_VERSION_ID", length=45)
        private String serviceModelVersionId;
+       @Column(name = "DISTRIBUTION_NOTIFICATION")
+       private String distributionNotification;
+       @Column(name = "CONSUMER_ID", length=200)
+       private String consumerId;      
        @Column(name = "CREATE_TIME", updatable=false)
        @Temporal(TemporalType.TIMESTAMP)
        private Date createTime;
@@ -57,9 +63,19 @@ public class WatchdogServiceModVerIdLookup implements Serializable {
        public WatchdogServiceModVerIdLookup() {
                
        }
-       public WatchdogServiceModVerIdLookup(String distributionId, String serviceModelVersionId) {
+       /**
+        * 
+        * @param distributionId - Distribution ID
+        * @param serviceModelVersionId -- service UUID 
+        * @param distributionNotification -- Notification content from ASDC
+        * @param consumerId -- Consumer ID associated with subscription.
+        */
+       public WatchdogServiceModVerIdLookup(String distributionId, String serviceModelVersionId,
+                       Optional<String> distributionNotification, String consumerId) {
                this.distributionId = distributionId;
                this.serviceModelVersionId = serviceModelVersionId;
+               this.distributionNotification= distributionNotification.orElse(null);
+               this.consumerId = consumerId;           
        }
 
        public String getDistributionId() {
@@ -104,8 +120,24 @@ public class WatchdogServiceModVerIdLookup implements Serializable {
        }
        @Override
        public String toString() {
-               return new ToStringBuilder(this).append("distributionId", getDistributionId())
-                               .append("serviceModelVersionId", getServiceModelVersionId()).append("createTime", getCreateTime())
+               return new ToStringBuilder(this)
+                               .append("distributionId", getDistributionId())
+                               .append("serviceModelVersionId", getServiceModelVersionId())
+                               .append("createTime", getCreateTime())
+                               .append("distributionNotification", getDistributionNotification())
+                               .append("consumerId", getConsumerId())
                                .toString();
        }
+       public String getDistributionNotification() {
+               return distributionNotification;
+       }
+       public void setDistributionNotification(String distributionNotification) {
+               this.distributionNotification = distributionNotification;
+       }
+       public String getConsumerId() {
+               return consumerId;
+       }
+       public void setConsumerId(String consumerId) {
+               this.consumerId = consumerId;
+       }
 }