From b3f268de4a04459a62846ba519a21b6d23f47863 Mon Sep 17 00:00:00 2001 From: tragait Date: Fri, 20 Nov 2020 13:25:45 +0000 Subject: Support for generic URL for mount, Put, Get added Issue-ID: CCSDK-2993 Signed-off-by: tragait Change-Id: I4061d6ba5084806c0a14b137e169f73cdd68a588 --- .../executor/RestconfExecutorExtensions.kt | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'ms/blueprintsprocessor') 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 = mutableMapOf("Content-Type" to "application/xml") +): BlueprintWebClientService.WebClientResponse { + 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 { + 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 = 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(10, 0, 1000, mountCheckExecutionBlock) +} -- cgit 1.2.3-korg