summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/config-snapshots/src/main
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2019-11-22 18:06:08 -0500
committerKAPIL SINGAL <ks220y@att.com>2019-11-26 21:32:38 +0000
commit341db21b2ac0a14a1ed2b8bf7930914dda054bfe (patch)
tree113bba965b06cfe3a8af3a0a527d1a41c9faf0f9 /ms/blueprintsprocessor/functions/config-snapshots/src/main
parentd274e5fc552cf9ae25500f504f0434981cf3accf (diff)
Formatting Code base with ktlint
No Business logic change, just the code format. Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3 To format run: mvn process-sources -P format Issue-ID: CCSDK-1947 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com> Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331
Diffstat (limited to 'ms/blueprintsprocessor/functions/config-snapshots/src/main')
-rw-r--r--ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutor.kt68
-rw-r--r--ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshot.kt11
-rw-r--r--ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotRepository.kt6
-rw-r--r--ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotService.kt79
4 files changed, 97 insertions, 67 deletions
diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutor.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutor.kt
index 82eaf394d..0bf4e5f32 100644
--- a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutor.kt
+++ b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutor.kt
@@ -38,7 +38,6 @@ import org.xmlunit.builder.Input
import org.xmlunit.diff.ComparisonType
import org.xmlunit.diff.Diff
-
/**
* ComponentConfigSnapshotsExecutor
*
@@ -54,7 +53,7 @@ import org.xmlunit.diff.Diff
@Component("component-config-snapshots-executor")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
open class ComponentConfigSnapshotsExecutor(private val cfgSnapshotService: ResourceConfigSnapshotService) :
- AbstractComponentFunction() {
+ AbstractComponentFunction() {
companion object {
private val log = LoggerFactory.getLogger(ComponentConfigSnapshotsExecutor::class.java)
@@ -100,10 +99,12 @@ open class ComponentConfigSnapshotsExecutor(private val cfgSnapshotService: Reso
when (operation) {
OPERATION_FETCH -> fetchConfigurationSnapshot(resourceId, resourceType, status)
OPERATION_STORE -> storeConfigurationSnapshot(snapshot, resourceId, resourceType, status)
- OPERATION_DIFF -> compareConfigurationSnapshot(resourceId, resourceType, contentType)
+ OPERATION_DIFF -> compareConfigurationSnapshot(resourceId, resourceType, contentType)
- else -> setNodeOutputErrors(OUTPUT_STATUS_ERROR,
- "Operation parameter must be fetch, store or diff")
+ else -> setNodeOutputErrors(
+ OUTPUT_STATUS_ERROR,
+ "Operation parameter must be fetch, store or diff"
+ )
}
}
@@ -117,12 +118,15 @@ open class ComponentConfigSnapshotsExecutor(private val cfgSnapshotService: Reso
/**
* Fetch a configuration snapshot, for resource identified by ID/type, of type status (RUNNING by default)
*/
- private suspend fun fetchConfigurationSnapshot(resourceId: String, resourceType: String,
- status : ResourceConfigSnapshot.Status = RUNNING) {
+ private suspend fun fetchConfigurationSnapshot(
+ resourceId: String,
+ resourceType: String,
+ status: ResourceConfigSnapshot.Status = RUNNING
+ ) {
try {
val cfgSnapshotValue = cfgSnapshotService.findByResourceIdAndResourceTypeAndStatus(resourceId, resourceType, status)
setNodeOutputProperties(OUTPUT_STATUS_SUCCESS, cfgSnapshotValue)
- } catch (er : NoSuchElementException) {
+ } catch (er: NoSuchElementException) {
val message = "No Resource config snapshot identified by resourceId={$resourceId}, " +
"resourceType={$resourceType} does not exists"
setNodeOutputErrors(OUTPUT_STATUS_ERROR, message)
@@ -132,11 +136,15 @@ open class ComponentConfigSnapshotsExecutor(private val cfgSnapshotService: Reso
/**
* Store a configuration snapshot, for resource identified by ID/type, of type status (RUNNING by default)
*/
- private suspend fun storeConfigurationSnapshot(cfgSnapshotValue : String, resourceId: String, resourceType: String,
- status : ResourceConfigSnapshot.Status = RUNNING) {
+ private suspend fun storeConfigurationSnapshot(
+ cfgSnapshotValue: String,
+ resourceId: String,
+ resourceType: String,
+ status: ResourceConfigSnapshot.Status = RUNNING
+ ) {
if (cfgSnapshotValue.isNotEmpty()) {
val cfgSnapshotSaved = cfgSnapshotService.write(cfgSnapshotValue, resourceId, resourceType, status)
- setNodeOutputProperties(OUTPUT_STATUS_SUCCESS, cfgSnapshotSaved.config_snapshot ?: "" )
+ setNodeOutputProperties(OUTPUT_STATUS_SUCCESS, cfgSnapshotSaved.config_snapshot ?: "")
} else {
val message = "Could not store config snapshot identified by resourceId={$resourceId},resourceType={$resourceType} does not exists"
setNodeOutputErrors(OUTPUT_STATUS_ERROR, message)
@@ -146,7 +154,7 @@ open class ComponentConfigSnapshotsExecutor(private val cfgSnapshotService: Reso
/**
* Compare two configs (RUNNING vs CANDIDATE) for resource identified by ID/type, using the specified contentType
*/
- private suspend fun compareConfigurationSnapshot(resourceId: String, resourceType: String, contentType : String) {
+ private suspend fun compareConfigurationSnapshot(resourceId: String, resourceType: String, contentType: String) {
val cfgRunning = cfgSnapshotService.findByResourceIdAndResourceTypeAndStatus(resourceId, resourceType, RUNNING)
val cfgCandidate = cfgSnapshotService.findByResourceIdAndResourceTypeAndStatus(resourceId, resourceType, CANDIDATE)
@@ -163,13 +171,13 @@ open class ComponentConfigSnapshotsExecutor(private val cfgSnapshotService: Reso
}
DIFF_XML -> {
val myDiff = DiffBuilder
- .compare(Input.fromString(cfgRunning))
- .withTest(Input.fromString(cfgCandidate))
- .checkForSimilar()
- .ignoreComments()
- .ignoreWhitespace()
- .normalizeWhitespace()
- .build()
+ .compare(Input.fromString(cfgRunning))
+ .withTest(Input.fromString(cfgCandidate))
+ .checkForSimilar()
+ .ignoreComments()
+ .ignoreWhitespace()
+ .normalizeWhitespace()
+ .build()
setNodeOutputProperties(OUTPUT_STATUS_SUCCESS, formatXmlDifferences(myDiff))
}
@@ -205,10 +213,12 @@ open class ComponentConfigSnapshotsExecutor(private val cfgSnapshotService: Reso
/**
* Formats XmlUnit differences into xml-patch like response (RFC5261)
*/
- private fun formatXmlDifferences(differences : Diff) : String {
+ private fun formatXmlDifferences(differences: Diff): String {
val output = StringBuilder()
- output.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<diff>")
+ output.append(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<diff>"
+ )
val diffIterator = differences.getDifferences().iterator()
while (diffIterator.hasNext()) {
@@ -216,18 +226,18 @@ open class ComponentConfigSnapshotsExecutor(private val cfgSnapshotService: Reso
when (aDiff.type) {
ComparisonType.ATTR_VALUE -> {
output.append("<replace sel=\"").append(aDiff.testDetails.xPath).append("\">")
- .append(aDiff.testDetails.value)
- .append("</replace>")
+ .append(aDiff.testDetails.value)
+ .append("</replace>")
}
ComparisonType.TEXT_VALUE -> {
output.append("<replace sel=\"").append(aDiff.testDetails.xPath).append("\">")
- .append(aDiff.testDetails.value)
- .append("</replace>")
+ .append(aDiff.testDetails.value)
+ .append("</replace>")
}
ComparisonType.CHILD_LOOKUP -> {
output.append("<add sel=\"").append(aDiff.testDetails.parentXPath).append("\">")
- .append(formatNode(aDiff.testDetails.target))
- .append("</add>")
+ .append(formatNode(aDiff.testDetails.target))
+ .append("</add>")
}
ComparisonType.CHILD_NODELIST_LENGTH -> {
// Ignored; will be processed in the CHILD_LOOKUP case
@@ -253,7 +263,7 @@ open class ComponentConfigSnapshotsExecutor(private val cfgSnapshotService: Reso
if (node.hasChildNodes()) {
val nodes = node.childNodes
for (index in 1..nodes.length) {
- val child = nodes.item(index-1)
+ val child = nodes.item(index - 1)
if (child.nodeType == Node.TEXT_NODE || child.nodeType == Node.COMMENT_NODE) {
output.append(child.nodeValue)
} else {
diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshot.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshot.kt
index ef34e6ff9..73c9e22f3 100644
--- a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshot.kt
+++ b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshot.kt
@@ -22,8 +22,15 @@ import org.hibernate.annotations.Proxy
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.io.Serializable
-import java.util.*
-import javax.persistence.*
+import java.util.Date
+import javax.persistence.Column
+import javax.persistence.Entity
+import javax.persistence.EntityListeners
+import javax.persistence.Id
+import javax.persistence.Lob
+import javax.persistence.Table
+import javax.persistence.Temporal
+import javax.persistence.TemporalType
/**
* ResourceConfigSnapshot model
diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotRepository.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotRepository.kt
index 4ab7d7f0e..cb7467b60 100644
--- a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotRepository.kt
+++ b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotRepository.kt
@@ -29,11 +29,13 @@ interface ResourceConfigSnapshotRepository : JpaRepository<ResourceConfigSnapsho
fun findByResourceIdAndResourceTypeAndStatus(
resourceId: String,
resourceType: String,
- status : ResourceConfigSnapshot.Status): ResourceConfigSnapshot?
+ status: ResourceConfigSnapshot.Status
+ ): ResourceConfigSnapshot?
@Transactional
fun deleteByResourceIdAndResourceTypeAndStatus(
resourceId: String,
resourceType: String,
- status : ResourceConfigSnapshot.Status)
+ status: ResourceConfigSnapshot.Status
+ )
}
diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotService.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotService.kt
index 73d517553..fcbc15702 100644
--- a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotService.kt
+++ b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotService.kt
@@ -23,7 +23,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.slf4j.LoggerFactory
import org.springframework.dao.DataIntegrityViolationException
import org.springframework.stereotype.Service
-import java.util.*
+import java.util.UUID
/**
* ResourceConfigSnapshot managing service.
@@ -36,42 +36,53 @@ class ResourceConfigSnapshotService(private val repository: ResourceConfigSnapsh
private val log = LoggerFactory.getLogger(ResourceConfigSnapshotService::class.toString())
- suspend fun findByResourceIdAndResourceTypeAndStatus(resourceId: String, resourceType: String,
- status : ResourceConfigSnapshot.Status = RUNNING): String =
- withContext(Dispatchers.IO) {
- repository.findByResourceIdAndResourceTypeAndStatus(resourceId, resourceType, status)
- ?.config_snapshot ?: Strings.EMPTY
- }
+ suspend fun findByResourceIdAndResourceTypeAndStatus(
+ resourceId: String,
+ resourceType: String,
+ status: ResourceConfigSnapshot.Status = RUNNING
+ ): String =
+ withContext(Dispatchers.IO) {
+ repository.findByResourceIdAndResourceTypeAndStatus(resourceId, resourceType, status)
+ ?.config_snapshot ?: Strings.EMPTY
+ }
- suspend fun write(snapshot: String, resId: String, resType: String,
- status: ResourceConfigSnapshot.Status = RUNNING) : ResourceConfigSnapshot =
- withContext(Dispatchers.IO) {
+ suspend fun write(
+ snapshot: String,
+ resId: String,
+ resType: String,
+ status: ResourceConfigSnapshot.Status = RUNNING
+ ): ResourceConfigSnapshot =
+ withContext(Dispatchers.IO) {
- val resourceConfigSnapshotEntry = ResourceConfigSnapshot()
- resourceConfigSnapshotEntry.id = UUID.randomUUID().toString()
- resourceConfigSnapshotEntry.resourceId = resId
- resourceConfigSnapshotEntry.resourceType = resType
- resourceConfigSnapshotEntry.status = status
- resourceConfigSnapshotEntry.config_snapshot = snapshot
+ val resourceConfigSnapshotEntry = ResourceConfigSnapshot()
+ resourceConfigSnapshotEntry.id = UUID.randomUUID().toString()
+ resourceConfigSnapshotEntry.resourceId = resId
+ resourceConfigSnapshotEntry.resourceType = resType
+ resourceConfigSnapshotEntry.status = status
+ resourceConfigSnapshotEntry.config_snapshot = snapshot
- // Overwrite configuration snapshot entry of resId/resType
- if (resId.isNotEmpty() && resType.isNotEmpty()) {
- repository.findByResourceIdAndResourceTypeAndStatus(resId, resType, status)?.
- let {
- log.info("Overwriting configuration snapshot entry for resourceId=($resId), " +
- "resourceType=($resType), status=($status)")
- repository.deleteByResourceIdAndResourceTypeAndStatus(resId, resType, status)
- }
- }
- var storedSnapshot: ResourceConfigSnapshot
- try {
- storedSnapshot = repository.saveAndFlush(resourceConfigSnapshotEntry)
- log.info("Stored configuration snapshot for resourceId=($resId), " +
+ // Overwrite configuration snapshot entry of resId/resType
+ if (resId.isNotEmpty() && resType.isNotEmpty()) {
+ repository.findByResourceIdAndResourceTypeAndStatus(resId, resType, status)
+ ?.let {
+ log.info(
+ "Overwriting configuration snapshot entry for resourceId=($resId), " +
+ "resourceType=($resType), status=($status)"
+ )
+ repository.deleteByResourceIdAndResourceTypeAndStatus(resId, resType, status)
+ }
+ }
+ var storedSnapshot: ResourceConfigSnapshot
+ try {
+ storedSnapshot = repository.saveAndFlush(resourceConfigSnapshotEntry)
+ log.info(
+ "Stored configuration snapshot for resourceId=($resId), " +
"resourceType=($resType), status=($status), " +
- "dated=(${storedSnapshot.createdDate})")
- } catch (ex: DataIntegrityViolationException) {
- throw BluePrintException("Failed to store configuration snapshot entry.", ex)
- }
- storedSnapshot
+ "dated=(${storedSnapshot.createdDate})"
+ )
+ } catch (ex: DataIntegrityViolationException) {
+ throw BluePrintException("Failed to store configuration snapshot entry.", ex)
}
+ storedSnapshot
+ }
}