diff options
9 files changed, 144 insertions, 12 deletions
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 index 0000000000..9a5bef6cc8 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.3__Add_Add_Column_To_WatchDog_Model_Id_Lookup.sql @@ -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 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 ca1d0331fd..7a02f47d3f 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 @@ -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); diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ArtifactInfoImpl.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ArtifactInfoImpl.java index 7dab49f82a..ed97f5bdea 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ArtifactInfoImpl.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ArtifactInfoImpl.java @@ -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(); + } + } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java index 294221352c..a1c660f75f 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java @@ -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(); + } + } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ResourceInfoImpl.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ResourceInfoImpl.java index eb4764dec1..dad7e64931 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ResourceInfoImpl.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ResourceInfoImpl.java @@ -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(); + } } 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 ebc705ce30..2f4d5ea6a1 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 @@ -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); diff --git a/asdc-controller/src/test/resources/data.sql b/asdc-controller/src/test/resources/data.sql index 681ee3bda7..70737abf5a 100644 --- a/asdc-controller/src/test/resources/data.sql +++ b/asdc-controller/src/test/resources/data.sql @@ -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); diff --git a/asdc-controller/src/test/resources/schema.sql b/asdc-controller/src/test/resources/schema.sql index 17423f8434..010b36dcf1 100644 --- a/asdc-controller/src/test/resources/schema.sql +++ b/asdc-controller/src/test/resources/schema.sql @@ -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`) diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/WatchdogServiceModVerIdLookup.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/WatchdogServiceModVerIdLookup.java index 77089cbbdc..25f5802413 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/WatchdogServiceModVerIdLookup.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/WatchdogServiceModVerIdLookup.java @@ -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; + } } |