From 341db21b2ac0a14a1ed2b8bf7930914dda054bfe Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Fri, 22 Nov 2019 18:06:08 -0500 Subject: 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) Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331 --- .../snapshots/ComponentConfigSnapshotsExecutor.kt | 68 +++--- .../config/snapshots/db/ResourceConfigSnapshot.kt | 11 +- .../db/ResourceConfigSnapshotRepository.kt | 6 +- .../snapshots/db/ResourceConfigSnapshotService.kt | 79 ++++--- .../ComponentConfigSnapshotsExecutorTest.kt | 255 +++++++++++++-------- .../db/ResourceConfigSnapshotServiceTest.kt | 4 +- 6 files changed, 264 insertions(+), 159 deletions(-) (limited to 'ms/blueprintsprocessor/functions/config-snapshots') 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("" + - "") + output.append( + "" + + "" + ) 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("") - .append(aDiff.testDetails.value) - .append("") + .append(aDiff.testDetails.value) + .append("") } ComparisonType.TEXT_VALUE -> { output.append("") - .append(aDiff.testDetails.value) - .append("") + .append(aDiff.testDetails.value) + .append("") } ComparisonType.CHILD_LOOKUP -> { output.append("") - .append(formatNode(aDiff.testDetails.target)) - .append("") + .append(formatNode(aDiff.testDetails.target)) + .append("") } 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" + @@ -331,18 +401,23 @@ class ComponentConfigSnapshotsExecutorTest { "2828828" + "TEGig400-int01" + "" - 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)) } -- cgit 1.2.3-korg