aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-11-24 12:36:35 +0000
committerGerrit Code Review <gerrit@onap.org>2020-11-24 12:36:35 +0000
commit4cd6bf9590c5275307e5aca53450c9e1e22a2f06 (patch)
tree1d27d399c47d41c75d53b240331b206f659b7021
parentf262bed0fc5f91f0111287f6d4637b15855aa3d3 (diff)
parentb3f268de4a04459a62846ba519a21b6d23f47863 (diff)
Merge "Support for generic URL for mount, Put, Get added" into guilin
-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)
+}