aboutsummaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authortragait <rahul.tyagi@est.tech>2020-11-20 13:25:45 +0000
committerRahul Tyagi <rahul.tyagi@est.tech>2020-11-23 13:56:13 +0000
commit8f4524701c1c5d0625a72f273de7d8f7ed06eff4 (patch)
tree6cccc597e8a80c2bf55394276cae64a574d26950 /ms
parent36db9a541fc469cd59649729243471cf7a8aef3e (diff)
Support for generic URL for mount, Put, Get added
Issue-ID: CCSDK-2993 Signed-off-by: tragait <rahul.tyagi@est.tech> Change-Id: I4061d6ba5084806c0a14b137e169f73cdd68a588
Diffstat (limited to 'ms')
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt70
1 files changed, 70 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt
index 7aabb73e6..2d3eb3bab 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt
@@ -21,6 +21,7 @@ import org.hibernate.annotations.common.util.impl.LoggerFactory
import org.onap.ccsdk.cds.blueprintsprocessor.rest.restClientService
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintRetryException
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
@@ -110,3 +111,72 @@ suspend fun AbstractScriptComponentFunction.restconfUnMountDevice(
log.info("sending unMount request, url: $unMountUrl")
webClientService.exchangeResource("DELETE", unMountUrl, "")
}
+
+/**
+ * Generic PUT/PATCH/POST request function
+ */
+suspend fun AbstractScriptComponentFunction.genericPutPatchPostRequest(
+ webClientService: BlueprintWebClientService,
+ requestUrl: String,
+ requestType: String,
+ payload: Any,
+ headers: Map<String, String> = mutableMapOf("Content-Type" to "application/xml")
+): BlueprintWebClientService.WebClientResponse<String> {
+ when (requestType.toUpperCase()) {
+ "PUT" -> log.info("sending PUT request, url: $requestUrl")
+ "PATCH" -> log.info("sending PATCH request, url: $requestUrl")
+ "POST" -> log.info("sending POST request, url: $requestUrl")
+ else -> throw BluePrintProcessorException("Illegal request type, only POST, PUT or PATCH allowed.")
+ }
+ return webClientService.exchangeResource(requestType, requestUrl, payload as String, headers)
+}
+
+/**
+ * Generic GET/DELETE request function
+ */
+
+suspend fun AbstractScriptComponentFunction.genericGetOrDeleteRequest(
+ webClientService: BlueprintWebClientService,
+ requestUrl: String,
+ requestType: String
+): BlueprintWebClientService.WebClientResponse<String> {
+ when (requestType.toUpperCase()) {
+ "GET" -> log.info("sending GET request, url: $requestUrl")
+ "DELETE" -> log.info("sending DELETE request, url: $requestUrl")
+ else -> throw BluePrintProcessorException("Illegal request type, only GET and DELETE allowed.")
+ }
+ return webClientService.exchangeResource(requestType, requestUrl, "")
+}
+
+/**
+ * Generic Mount function
+ * This function mount the given deviceId and verify if device mounted successfully.
+ * This function take mount url and mount verify url as parameters.
+ */
+
+suspend fun AbstractScriptComponentFunction.restconfMountDevice(
+ webClientService: BlueprintWebClientService,
+ payload: Any,
+ mountUrl: String,
+ mountVerifyUrl: String,
+ headers: Map<String, String> = mutableMapOf("Content-Type" to "application/xml"),
+ expectedMountResult: String = """"netconf-node-topology:connection-status":"connected""""
+) {
+
+ log.info("sending mount request, url: $mountUrl")
+ webClientService.exchangeResource("PUT", mountUrl, payload as String, headers)
+
+ /** Check device has mounted */
+ val mountCheckExecutionBlock: suspend (Int) -> String = { tryCount: Int ->
+ val result = webClientService.exchangeResource("GET", mountVerifyUrl, "")
+ if (result.body.contains(expectedMountResult)) {
+ log.info("NF was mounted successfully on ODL")
+ result.body
+ } else {
+ throw BluePrintRetryException("Wait for device with url($mountUrl) to mount")
+ }
+ }
+
+ log.info("url for ODL status check: $mountVerifyUrl")
+ webClientService.retry<String>(10, 0, 1000, mountCheckExecutionBlock)
+}