summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/config-snapshots/src
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
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')
-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
-rw-r--r--ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutorTest.kt255
-rw-r--r--ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotServiceTest.kt4
6 files changed, 264 insertions, 159 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
+ }
}
diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutorTest.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutorTest.kt
index f013e89a1..c472337ac 100644
--- a/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutorTest.kt
+++ b/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutorTest.kt
@@ -47,9 +47,11 @@ import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
@RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [ResourceConfigSnapshotService::class,
- BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class,
- BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
+@ContextConfiguration(
+ classes = [ResourceConfigSnapshotService::class,
+ BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class,
+ BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]
+)
@TestPropertySource(locations = ["classpath:application-test.properties"])
@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
@EnableAutoConfiguration
@@ -57,10 +59,12 @@ import org.springframework.test.context.junit4.SpringRunner
class ComponentConfigSnapshotsExecutorTest {
@Autowired
- lateinit var cfgSnapshotService : ResourceConfigSnapshotService
- lateinit var cfgSnapshotComponent : ComponentConfigSnapshotsExecutor
- private var bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("123456-1000",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts")
+ lateinit var cfgSnapshotService: ResourceConfigSnapshotService
+ lateinit var cfgSnapshotComponent: ComponentConfigSnapshotsExecutor
+ private var bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
+ "123456-1000",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts"
+ )
private val resourceId = "1"
private val resourceType = "ServiceInstance"
@@ -75,7 +79,6 @@ class ComponentConfigSnapshotsExecutorTest {
props[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_ID] = resourceId.asJsonPrimitive()
props[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_TYPE] = resourceType.asJsonPrimitive()
-
cfgSnapshotComponent.operationInputs = props
cfgSnapshotComponent.bluePrintRuntimeService = bluePrintRuntimeService
cfgSnapshotComponent.nodeTemplateName = nodeTemplateName
@@ -103,17 +106,27 @@ class ComponentConfigSnapshotsExecutorTest {
cfgSnapshotComponent.processNB(executionRequest)
} catch (e: BluePrintProcessorException) {
- kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
- e.message)
+ kotlin.test.assertEquals(
+ "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
+ e.message
+ )
return@runBlocking
}
// then; we should get success and the TEST1 payload in our output properties
- assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_STATUS))
- assertEquals(snapshotConfig.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT))
+ assertEquals(
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS
+ )
+ )
+ assertEquals(
+ snapshotConfig.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT
+ )
+ )
}
}
@@ -127,22 +140,32 @@ class ComponentConfigSnapshotsExecutorTest {
try {
val resId = "121111"
val resType = "PNF"
- cfgSnapshotService.write(snapshotConfig, resId, resType, ResourceConfigSnapshot.Status.CANDIDATE)
+ cfgSnapshotService.write(snapshotConfig, resId, resType, ResourceConfigSnapshot.Status.CANDIDATE)
prepareRequestProperties(OPERATION_FETCH, resId, resType, ResourceConfigSnapshot.Status.CANDIDATE.name)
cfgSnapshotComponent.processNB(executionRequest)
} catch (e: BluePrintProcessorException) {
- kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
- e.message)
+ kotlin.test.assertEquals(
+ "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
+ e.message
+ )
return@runBlocking
}
// then; we should get success and the TEST payload in our output properties
- assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_STATUS))
- assertEquals(snapshotConfig.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT))
+ assertEquals(
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS
+ )
+ )
+ assertEquals(
+ snapshotConfig.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT
+ )
+ )
}
}
@@ -159,20 +182,29 @@ class ComponentConfigSnapshotsExecutorTest {
prepareRequestProperties(OPERATION_STORE, resId, resType, snapshotConfig)
cfgSnapshotComponent.processNB(executionRequest)
-
} catch (e: BluePrintProcessorException) {
- kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
- e.message)
+ kotlin.test.assertEquals(
+ "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
+ e.message
+ )
return@runBlocking
}
// then; we should get success and the PAYLOAD payload in our output properties
- assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_STATUS))
- assertEquals(snapshotConfig.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT))
+ assertEquals(
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS
+ )
+ )
+ assertEquals(
+ snapshotConfig.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT
+ )
+ )
}
}
@@ -182,19 +214,24 @@ class ComponentConfigSnapshotsExecutorTest {
runBlocking {
// when; asking for unknown resource Id/ resource Type combo; should get an error response
try {
- prepareRequestProperties(OPERATION_FETCH, "asdasd", "PNF", ResourceConfigSnapshot.Status.RUNNING.name)
+ prepareRequestProperties(OPERATION_FETCH, "asdasd", "PNF", ResourceConfigSnapshot.Status.RUNNING.name)
cfgSnapshotComponent.processNB(executionRequest)
-
} catch (e: BluePrintProcessorException) {
- kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
- e.message)
+ kotlin.test.assertEquals(
+ "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
+ e.message
+ )
return@runBlocking
}
- assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_STATUS))
+ assertEquals(
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS
+ )
+ )
}
}
@@ -204,25 +241,34 @@ class ComponentConfigSnapshotsExecutorTest {
runBlocking {
// when; asking for unknown operation update; should get an error response
try {
- prepareRequestProperties("update", "asdasd", "PNF", ResourceConfigSnapshot.Status.RUNNING.name)
+ prepareRequestProperties("update", "asdasd", "PNF", ResourceConfigSnapshot.Status.RUNNING.name)
cfgSnapshotComponent.processNB(executionRequest)
-
} catch (e: BluePrintProcessorException) {
- kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
- e.message)
+ kotlin.test.assertEquals(
+ "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
+ e.message
+ )
return@runBlocking
}
// then; we should get error in our output properties
- assertTrue( bluePrintRuntimeService.getBluePrintError().errors.size == 1 )
- assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_ERROR.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_STATUS))
+ assertTrue(bluePrintRuntimeService.getBluePrintError().errors.size == 1)
+ assertEquals(
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_ERROR.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS
+ )
+ )
val msg = "Operation parameter must be fetch, store or diff"
- assertEquals(msg.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_MESSAGE))
+ assertEquals(
+ msg.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_MESSAGE
+ )
+ )
}
}
@@ -234,25 +280,34 @@ class ComponentConfigSnapshotsExecutorTest {
try {
val resId = "121111"
val resType = "PNF"
- cfgSnapshotService.write("snapshotConfig", resId, resType, ResourceConfigSnapshot.Status.CANDIDATE)
- prepareRequestProperties(OPERATION_DIFF, resId, resType, "YANG")
+ cfgSnapshotService.write("snapshotConfig", resId, resType, ResourceConfigSnapshot.Status.CANDIDATE)
+ prepareRequestProperties(OPERATION_DIFF, resId, resType, "YANG")
cfgSnapshotComponent.processNB(executionRequest)
-
} catch (e: BluePrintProcessorException) {
- kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
- e.message)
+ kotlin.test.assertEquals(
+ "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.",
+ e.message
+ )
return@runBlocking
}
// then; we should get error in our output properties
- assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_ERROR.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_STATUS))
+ assertEquals(
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_ERROR.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS
+ )
+ )
val message = "Could not compare config snapshots for type YANG"
- assertEquals(message.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_MESSAGE))
+ assertEquals(
+ message.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_MESSAGE
+ )
+ )
}
}
@@ -270,27 +325,37 @@ class ComponentConfigSnapshotsExecutorTest {
prepareRequestProperties(OPERATION_DIFF, resId, resType, DIFF_JSON)
cfgSnapshotComponent.processNB(executionRequest)
-
} catch (e: BluePrintProcessorException) {
- kotlin.test.assertEquals("Can't proceed with the cfg snapshot diff: provide resource-id and resource-type.",
- e.message)
+ kotlin.test.assertEquals(
+ "Can't proceed with the cfg snapshot diff: provide resource-id and resource-type.",
+ e.message
+ )
return@runBlocking
}
// then; we should get success
- assertTrue( bluePrintRuntimeService.getBluePrintError().errors.size == 0 )
- assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_STATUS))
+ assertTrue(bluePrintRuntimeService.getBluePrintError().errors.size == 0)
+ assertEquals(
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS
+ )
+ )
// then; we should get JSON-patches differences in our response property
- val diffJson = "[{\"op\":\"add\",\"path\":\"/system-uptime-information/last-configured-time/new-child-object\",\"value\":{\"property\":\"value\"}}," +
- "{\"op\":\"replace\",\"path\":\"/system-uptime-information/system-booted-time/time-length\",\"value\":\"14:52:54\"}," +
- "{\"op\":\"replace\",\"path\":\"/system-uptime-information/time-source\",\"value\":\" DNS CLOCK \"}," +
- "{\"op\":\"add\",\"path\":\"/system-uptime-information/uptime-information/load-average-10\",\"value\":\"0.05\"}]"
- assertEquals(diffJson.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT))
+ val diffJson =
+ "[{\"op\":\"add\",\"path\":\"/system-uptime-information/last-configured-time/new-child-object\",\"value\":{\"property\":\"value\"}}," +
+ "{\"op\":\"replace\",\"path\":\"/system-uptime-information/system-booted-time/time-length\",\"value\":\"14:52:54\"}," +
+ "{\"op\":\"replace\",\"path\":\"/system-uptime-information/time-source\",\"value\":\" DNS CLOCK \"}," +
+ "{\"op\":\"add\",\"path\":\"/system-uptime-information/uptime-information/load-average-10\",\"value\":\"0.05\"}]"
+ assertEquals(
+ diffJson.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT
+ )
+ )
}
}
@@ -309,18 +374,23 @@ class ComponentConfigSnapshotsExecutorTest {
prepareRequestProperties(OPERATION_DIFF, resId, resType, DIFF_XML)
cfgSnapshotComponent.processNB(executionRequest)
-
} catch (e: BluePrintProcessorException) {
- kotlin.test.assertEquals("Can't proceed with the cfg snapshot diff: provide resource-id and resource-type.",
- e.message)
+ kotlin.test.assertEquals(
+ "Can't proceed with the cfg snapshot diff: provide resource-id and resource-type.",
+ e.message
+ )
return@runBlocking
}
// then; we should get success
- assertTrue( bluePrintRuntimeService.getBluePrintError().errors.size == 0 )
- assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_STATUS))
+ assertTrue(bluePrintRuntimeService.getBluePrintError().errors.size == 0)
+ assertEquals(
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_STATUS
+ )
+ )
// then; we should get XML-patches differences in our response property
val diffXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
@@ -331,18 +401,23 @@ class ComponentConfigSnapshotsExecutorTest {
"<replace sel=\"/output[1]/interface-information[1]/traffic-statistics[1]/output-packets[1]/text()[1]\">2828828</replace>" +
"<add sel=\"/output[1]/interface-information[1]/physical-interface[1]\"><interface-name>TEGig400-int01</interface-name></add>" +
"</diff>"
- assertEquals(diffXml.asJsonPrimitive(),
- bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName,
- ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT)) }
+ assertEquals(
+ diffXml.asJsonPrimitive(),
+ bluePrintRuntimeService.getNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT
+ )
+ )
+ }
}
- private fun preparePayload(filename : String, resId : String, resType : String, status: ResourceConfigSnapshot.Status) {
+ private fun preparePayload(filename: String, resId: String, resType: String, status: ResourceConfigSnapshot.Status) {
runBlocking {
cfgSnapshotService.write(JacksonUtils.getClassPathFileContent("payload/requests/$filename"), resId, resType, status)
}
}
- private fun prepareRequestProperties (oper : String, resId : String, resType : String, optional: String = "") {
+ private fun prepareRequestProperties(oper: String, resId: String, resType: String, optional: String = "") {
cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_OPERATION] = oper.asJsonPrimitive()
cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_ID] = resId.asJsonPrimitive()
cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_TYPE] = resType.asJsonPrimitive()
@@ -351,7 +426,7 @@ class ComponentConfigSnapshotsExecutorTest {
cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_DIFF_CONTENT_TYPE] = "".asJsonPrimitive()
cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_SNAPSHOT] = "".asJsonPrimitive()
cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_STATUS] =
- ResourceConfigSnapshot.Status.RUNNING.name.asJsonPrimitive()
+ ResourceConfigSnapshot.Status.RUNNING.name.asJsonPrimitive()
when (oper) {
OPERATION_DIFF ->
diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotServiceTest.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotServiceTest.kt
index 18ee8c9dc..f25b6f9c7 100644
--- a/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotServiceTest.kt
+++ b/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotServiceTest.kt
@@ -55,7 +55,7 @@ class ResourceConfigSnapshotServiceTest {
every {
cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
} returns null
- val res = cfgService.write( configSnapshot, resourceId, resourceType, resourceStatus)
+ val res = cfgService.write(configSnapshot, resourceId, resourceType, resourceStatus)
assertEquals(tr, res)
}
}
@@ -71,7 +71,7 @@ class ResourceConfigSnapshotServiceTest {
every {
cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(any(), any(), any())
} returns Unit
- val res = cfgService.write( configSnapshot, resourceId, resourceType)
+ val res = cfgService.write(configSnapshot, resourceId, resourceType)
verify {
cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(eq(resourceId), eq(resourceType), eq(resourceStatus))
}