summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-11-24 12:49:55 +0000
committerGerrit Code Review <gerrit@onap.org>2020-11-24 12:49:55 +0000
commit517928b32c9b72f8b83a2ff1564d442dacbc554e (patch)
treed1a499268fe69984621aaa12caea40534d08967d
parent404e8af1a9f4de2cad05097a8861560560305d79 (diff)
parent8f4524701c1c5d0625a72f273de7d8f7ed06eff4 (diff)
Merge "Support for generic URL for mount, Put, Get added"
-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)
+}