import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.module.kotlin.convertValue
+import org.onap.ccsdk.cds.blueprintsprocessor.uat.utils.RequestType.EXCHANGE_RESOURCE
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.nodes.Tag
data class RequestDefinition(
val method: String,
@JsonDeserialize(using = PathDeserializer::class)
- val path: String,
+ val path: String = "",
val headers: Map<String, String> = emptyMap(),
- val body: JsonNode? = null
+ val body: JsonNode? = null,
+ val requestType: RequestType = EXCHANGE_RESOURCE
)
+enum class RequestType {
+ EXCHANGE_RESOURCE,
+ UPLOAD_BINARY_FILE
+}
+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class ResponseDefinition(
val status: Int = 200,
import org.onap.ccsdk.cds.blueprintsprocessor.uat.logging.LogColor.COLOR_MOCKITO
import org.onap.ccsdk.cds.blueprintsprocessor.uat.logging.LogColor.markerOf
import org.onap.ccsdk.cds.blueprintsprocessor.uat.logging.MockInvocationLogger
+import org.onap.ccsdk.cds.blueprintsprocessor.uat.utils.RequestType.EXCHANGE_RESOURCE
+import org.onap.ccsdk.cds.blueprintsprocessor.uat.utils.RequestType.UPLOAD_BINARY_FILE
import org.skyscreamer.jsonassert.JSONAssert
import org.skyscreamer.jsonassert.JSONCompareMode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.core.env.ConfigurableEnvironment
+import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.stereotype.Component
import org.springframework.util.Base64Utils
+import java.nio.file.Path
import java.util.concurrent.ConcurrentHashMap
/**
for ((mockClient, expectations) in expectationsPerClient) {
expectations.forEach { expectation ->
val request = expectation.request
- verify(mockClient, evalVerificationMode(expectation.times)).exchangeResource(
- eq(request.method),
- eq(request.path),
- any(),
- argThat(RequiredMapEntriesMatcher(request.headers))
- )
+ if (request.requestType == EXCHANGE_RESOURCE) {
+ verify(mockClient, evalVerificationMode(expectation.times)).exchangeResource(
+ eq(request.method),
+ eq(request.path),
+ any(),
+ argThat(RequiredMapEntriesMatcher(request.headers))
+ )
+ } else if (request.requestType == UPLOAD_BINARY_FILE) {
+ verify(mockClient, evalVerificationMode(expectation.times)).uploadBinaryFile(
+ eq(request.path),
+ any()
+ )
+ }
}
// Don't mind the invocations to the overloaded exchangeResource(String, String, String)
verify(mockClient, atLeast(0)).exchangeResource(any(), any(), any())
restClient.exchangeResource(method, path, request, emptyMap())
}
for (expectation in restExpectations) {
- var stubbing = whenever(
- restClient.exchangeResource(
- eq(expectation.request.method),
- eq(expectation.request.path),
- argThat(JsonMatcher(expectation.request.body.toString())),
- any()
+ if (expectation.request.requestType == EXCHANGE_RESOURCE) {
+ var stubbing = whenever(
+ restClient.exchangeResource(
+ eq(expectation.request.method),
+ eq(expectation.request.path),
+ argThat(JsonMatcher(expectation.request.body.toString())),
+ any()
+ )
)
- )
- for (response in expectation.responses) {
- stubbing = stubbing.thenReturn(WebClientResponse(response.status, response.body.toString()))
+ for (response in expectation.responses) {
+ stubbing = stubbing.thenReturn(WebClientResponse(response.status, response.body.toString()))
+ }
+ }
+ }
+
+ for (expectation in restExpectations) {
+ if (expectation.request.requestType == UPLOAD_BINARY_FILE) {
+ var stubbing = whenever(
+ restClient.uploadBinaryFile(
+ eq(expectation.request.path),
+ any()
+ )
+ )
+ for (response in expectation.responses) {
+ stubbing = stubbing.thenReturn(WebClientResponse(response.status, response.body.toString()))
+ }
}
}
return restClient
headers: Map<String, String>
): WebClientResponse<String> {
val requestDefinition =
- RequestDefinition(methodType, path, headers, toJson(request))
+ RequestDefinition(methodType, path, headers, toJson(request), EXCHANGE_RESOURCE)
val realAnswer = realService.exchangeResource(methodType, path, request, headers)
val responseBody = when {
// TODO: confirm if we need to normalize the response here
return realAnswer
}
+ override fun uploadBinaryFile(path: String, filePath: Path):
+ WebClientResponse<String> {
+ val method = HttpMethod.POST.name
+ val headers = DEFAULT_HEADERS
+ val request = ""
+ val requestDefinition =
+ RequestDefinition(method, path, headers, toJson(request), UPLOAD_BINARY_FILE)
+ val realAnswer = realService.uploadBinaryFile(path, filePath)
+ val responseBody = when {
+ // TODO: confirm if we need to normalize the response here
+ realAnswer.status == HttpStatus.SC_OK -> toJson(realAnswer.body)
+ else -> null
+ }
+ val responseDefinition =
+ ResponseDefinition(realAnswer.status, responseBody)
+ expectations.add(
+ ExpectationDefinition(
+ requestDefinition,
+ responseDefinition
+ )
+ )
+ return realAnswer
+ }
+
override suspend fun <T> retry(times: Int, initialDelay: Long, delay: Long, block: suspend (Int) -> T): T {
return super.retry(times, initialDelay, delay, block)
}
import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
abstract class K8sAbstractRestClientService(
}
abstract fun apiUrl(): String
+
+ companion object {
+ fun getInterceptedWebclientService(
+ service: K8sAbstractRestClientService,
+ clientName: String
+ ): BlueprintWebClientService {
+ val restLibPropertyService: BluePrintRestLibPropertyService =
+ BluePrintDependencyService.instance(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+ return restLibPropertyService.interceptExternalBlueprintWebClientService(
+ service, clientName
+ )
+ }
+ }
}
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sAbstractRestClientService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
open class K8sDefinitionRestClient(
k8sConfiguration: K8sConnectionPluginConfiguration,
private val definition: String,
- private val definitionVersion: String
-) : K8sAbstractRestClientService(k8sConfiguration, "k8s-plugin-definition") {
+ private val definitionVersion: String,
+ private val clientName: String = CLIENT_NAME
+) : K8sAbstractRestClientService(k8sConfiguration, CLIENT_NAME) {
+ companion object {
+ public const val CLIENT_NAME = "k8s-plugin-definition"
+
+ fun getK8sDefinitionRestClient(
+ k8sConfiguration: K8sConnectionPluginConfiguration,
+ definition: String,
+ definitionVersion: String
+ ): BlueprintWebClientService {
+ val rbDefinitionService = K8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
+ return getInterceptedWebclientService(rbDefinitionService, CLIENT_NAME)
+ }
+ }
override fun apiUrl(): String {
return "$baseUrl/v1/rb/definition/$definition/$definitionVersion"
}
import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.profile.K8sProfile
import com.fasterxml.jackson.module.kotlin.readValue
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.K8sDefinitionRestClient.Companion.getK8sDefinitionRestClient
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.template.K8sTemplate
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
private val objectMapper = ObjectMapper()
fun hasDefinition(definition: String, definitionVersion: String): Boolean {
- val rbDefinitionService = K8sDefinitionRestClient(
- k8sConfiguration,
- definition,
- definitionVersion
- )
try {
+ val rbDefinitionService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = rbDefinitionService.exchangeResource(
GET.name,
"",
}
fun hasProfile(definition: String, definitionVersion: String, profileName: String): Boolean {
- val rbDefinitionService = K8sDefinitionRestClient(
- k8sConfiguration,
- definition,
- definitionVersion
- )
try {
+ val rbDefinitionService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = rbDefinitionService.exchangeResource(
GET.name,
"/profile/$profileName",
}
fun getProfile(definition: String, definitionVersion: String, profileName: String): K8sProfile? {
- val rbDefinitionService = K8sDefinitionRestClient(
- k8sConfiguration,
- definition,
- definitionVersion
- )
try {
+ val rbDefinitionService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = rbDefinitionService.exchangeResource(
GET.name,
"/profile/$profileName",
}
fun createProfile(definition: String, definitionVersion: String, profile: K8sProfile) {
- val rbDefinitionService = K8sDefinitionRestClient(
- k8sConfiguration,
- definition,
- definitionVersion
- )
val profileJsonString: String = objectMapper.writeValueAsString(profile)
try {
+ val rbDefinitionService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = rbDefinitionService.exchangeResource(
POST.name,
"/profile",
}
fun updateProfile(profile: K8sProfile) {
- val rbDefinitionService = K8sDefinitionRestClient(
- k8sConfiguration,
- profile.rbName!!,
- profile.rbVersion!!
- )
val profileJsonString: String = objectMapper.writeValueAsString(profile)
try {
+ val rbDefinitionService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ profile.rbName!!,
+ profile.rbVersion!!
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = rbDefinitionService.exchangeResource(
PUT.name,
"/profile/${profile.profileName}",
}
fun deleteProfile(definition: String, definitionVersion: String, profileName: String) {
- val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion)
try {
+ val rbDefinitionService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = rbDefinitionService.exchangeResource(
DELETE.name,
"/profile/$profileName",
}
fun uploadProfileContent(definition: String, definitionVersion: String, profile: K8sProfile, filePath: Path) {
- val fileUploadService = K8sUploadFileRestClientService(
- k8sConfiguration,
- definition,
- definitionVersion
- )
try {
+ val fileUploadService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = fileUploadService.uploadBinaryFile(
"/profile/${profile.profileName}/content",
filePath
}
fun createTemplate(definition: String, definitionVersion: String, template: K8sTemplate) {
- val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion)
val templateJsonString: String = objectMapper.writeValueAsString(template)
try {
+ val rbDefinitionService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = rbDefinitionService.exchangeResource(
POST.name,
"/config-template",
}
fun uploadConfigTemplateContent(definition: String, definitionVersion: String, template: K8sTemplate, filePath: Path) {
- val fileUploadService = K8sUploadFileRestClientService(k8sConfiguration, definition, definitionVersion)
try {
+ val fileUploadService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = fileUploadService.uploadBinaryFile(
"/config-template/${template.templateName}/content",
filePath
}
fun deleteTemplate(definition: String, definitionVersion: String, templateName: String) {
- val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion)
try {
+ val rbDefinitionService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = rbDefinitionService.exchangeResource(
DELETE.name,
"/config-template/$templateName",
}
fun getTemplate(definition: String, definitionVersion: String, templateName: String): K8sTemplate {
- val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion)
try {
+ val rbDefinitionService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
val result: BlueprintWebClientService.WebClientResponse<String> = getTemplateRequest(rbDefinitionService, templateName)
log.debug(result.toString())
return objectMapper.readValue(result.body)
}
fun hasTemplate(definition: String, definitionVersion: String, templateName: String): Boolean {
- val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion)
try {
- val result: BlueprintWebClientService.WebClientResponse<String> = getTemplateRequest(rbDefinitionService, templateName)
+ val interceptedService = getK8sDefinitionRestClient(
+ k8sConfiguration,
+ definition,
+ definitionVersion
+ )
+ val result: BlueprintWebClientService.WebClientResponse<String> = getTemplateRequest(interceptedService, templateName)
log.debug(result.toString())
return result.status in 200..299
} catch (e: Exception) {
}
}
- private fun getTemplateRequest(rbDefinitionService: K8sDefinitionRestClient, templateName: String): BlueprintWebClientService.WebClientResponse<String> {
+ private fun getTemplateRequest(rbDefinitionService: BlueprintWebClientService, templateName: String): BlueprintWebClientService.WebClientResponse<String> {
return rbDefinitionService.exchangeResource(
GET.name,
"/config-template/$templateName",
+++ /dev/null
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2019 IBM.
- * Modifications Copyright © 2020 Orange.
- * Modifications Copyright © 2020 Deutsche Telekom AG.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition
-
-import org.apache.commons.io.IOUtils
-import org.apache.http.client.ClientProtocolException
-import org.apache.http.client.entity.EntityBuilder
-import org.apache.http.client.methods.HttpPost
-import org.apache.http.client.methods.HttpUriRequest
-import org.apache.http.message.BasicHeader
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.RestLoggerService
-import java.io.IOException
-import java.nio.charset.Charset
-import java.nio.file.Files
-import java.nio.file.Path
-
-class K8sUploadFileRestClientService(
- k8sConfiguration: K8sConnectionPluginConfiguration,
- definition: String,
- definitionVersion: String
-) : K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion) {
-
- @Throws(IOException::class, ClientProtocolException::class)
- private fun performHttpCall(httpUriRequest: HttpUriRequest): BlueprintWebClientService.WebClientResponse<String> {
- val httpResponse = httpClient().execute(httpUriRequest)
- val statusCode = httpResponse.statusLine.statusCode
- httpResponse.entity.content.use {
- val body = IOUtils.toString(it, Charset.defaultCharset())
- return BlueprintWebClientService.WebClientResponse(statusCode, body)
- }
- }
-
- fun uploadBinaryFile(path: String, filePath: Path): BlueprintWebClientService.WebClientResponse<String> {
- val convertedHeaders: Array<BasicHeader> = convertToBasicHeaders(defaultHeaders())
- val httpPost = HttpPost(host(path))
- val entity = EntityBuilder.create().setBinary(Files.readAllBytes(filePath)).build()
- httpPost.setEntity(entity)
- RestLoggerService.httpInvoking(convertedHeaders)
- httpPost.setHeaders(convertedHeaders)
- return performHttpCall(httpPost)
- }
-}
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.K8sRbInstanceRestClient.Companion.getK8sRbInstanceRestClient
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.healthcheck.K8sRbInstanceHealthCheck
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.healthcheck.K8sRbInstanceHealthCheckList
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.healthcheck.K8sRbInstanceHealthCheckSimple
private val log = LoggerFactory.getLogger(K8sPluginInstanceApi::class.java)!!
fun getInstanceList(): List<K8sRbInstance>? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getInstanceById(instanceId: String): K8sRbInstance? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getFullInstanceById(instanceId: String): K8sRbInstanceFull? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getInstanceStatus(instanceId: String): K8sRbInstanceStatus? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
name: String? = null,
labels: Map<String, String>? = null
): K8sRbInstanceStatus? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
var path: String = "/query?ApiVersion=$apiVersion&Kind=$kind"
if (name != null)
}
fun getInstanceHealthCheckList(instanceId: String): K8sRbInstanceHealthCheckList? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getInstanceHealthCheck(instanceId: String, healthCheckId: String): K8sRbInstanceHealthCheck? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun startInstanceHealthCheck(instanceId: String): K8sRbInstanceHealthCheckSimple? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
POST.name,
}
fun createConfigurationValues(configValues: K8sConfigValueRequest, instanceId: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
POST.name,
}
fun editConfigurationValues(configValues: K8sConfigValueRequest, instanceId: String, configName: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
PUT.name,
}
fun editConfigurationValuesByDelete(instanceId: String, configName: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
POST.name,
}
fun hasConfigurationValues(instanceId: String, configName: String): Boolean {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun hasConfigurationValuesVersion(instanceId: String, configName: String, version: String): Boolean {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getConfigurationValues(instanceId: String, configName: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getConfigurationValuesVersion(instanceId: String, configName: String, version: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getConfigurationValuesVersionByTag(instanceId: String, configName: String, tag: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getConfigurationValuesList(instanceId: String): List<K8sConfigValueResponse>? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getConfigurationValuesVersionList(instanceId: String, configName: String): List<K8sConfigValueResponse>? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun getConfigurationValuesTagList(instanceId: String, configName: String): List<K8sConfigValueTag>? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
}
fun deleteConfigurationValues(instanceId: String, configName: String, deleteConfigOnly: Boolean) {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
var path: String = "/config/$configName"
if (deleteConfigOnly)
}
fun rollbackConfigurationValues(instanceId: String, configName: String, configVersion: String?, configTag: String?) {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val configValues = hashMapOf<String, String>()
if (configVersion != null)
}
fun tagConfigurationValues(instanceId: String, configName: String, tagName: String) {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val configValues = hashMapOf<String, String>()
configValues["tag-name"] = tagName
}
fun deleteInstanceHealthCheck(instanceId: String, healthCheckId: String) {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
DELETE.name,
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sAbstractRestClientService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
open class K8sRbInstanceRestClient(
k8sConfiguration: K8sConnectionPluginConfiguration,
private val instanceId: String = ""
) : K8sAbstractRestClientService(k8sConfiguration, "k8s-plugin-instance") {
+ companion object {
+ public const val CLIENT_NAME = "k8s-plugin-instance"
+
+ fun getK8sRbInstanceRestClient(
+ k8sConfiguration: K8sConnectionPluginConfiguration,
+ instanceId: String = ""
+ ): BlueprintWebClientService {
+ val rbInstanceService = K8sRbInstanceRestClient(
+ k8sConfiguration,
+ instanceId
+ )
+ return getInterceptedWebclientService(rbInstanceService, CLIENT_NAME)
+ }
+ }
+
override fun apiUrl(): String {
return if (instanceId != "")
"$baseUrl/v1/instance/$instanceId"
package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.query
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.query.K8sQueryRestClient.Companion.getK8sQueryRestClient
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
namespace: String? = null,
labels: Map<String, String>? = null
): K8sResourceStatus? {
- val rbQueryService = K8sQueryRestClient(k8sConfiguration)
+ val rbQueryService = getK8sQueryRestClient(k8sConfiguration)
try {
var path: String = "?CloudRegion=$cloudRegion&ApiVersion=$apiVersion&Kind=$kind"
if (name != null)
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sAbstractRestClientService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
open class K8sQueryRestClient(
k8sConfiguration: K8sConnectionPluginConfiguration
-) : K8sAbstractRestClientService(k8sConfiguration, "k8s-plugin-query") {
+) : K8sAbstractRestClientService(k8sConfiguration, CLIENT_NAME) {
+
+ companion object {
+ public const val CLIENT_NAME = "k8s-plugin-query"
+
+ fun getK8sQueryRestClient(
+ k8sConfiguration: K8sConnectionPluginConfiguration
+ ): BlueprintWebClientService {
+ val rbQueryService = K8sQueryRestClient(
+ k8sConfiguration
+ )
+ return getInterceptedWebclientService(rbQueryService, CLIENT_NAME)
+ }
+ }
override fun apiUrl(): String {
return "$baseUrl/v1/query"
import org.apache.http.HttpStatus
import org.apache.http.client.ClientProtocolException
import org.apache.http.client.config.RequestConfig
+import org.apache.http.client.entity.EntityBuilder
import org.apache.http.client.methods.HttpDelete
import org.apache.http.client.methods.HttpGet
import org.apache.http.client.methods.HttpPatch
import org.apache.http.message.BasicHeader
import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties
import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService.WebClientResponse
import org.onap.ccsdk.cds.blueprintsprocessor.rest.utils.WebClientUtils
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import java.io.InputStream
import java.net.URI
import java.nio.charset.Charset
+import java.nio.file.Files
+import java.nio.file.Path
abstract class BaseBlueprintWebClientService<out E : RestClientProperties> : BlueprintWebClientService {
.build()
}
- override fun exchangeResource(methodType: String, path: String, request: String): BlueprintWebClientService.WebClientResponse<String> {
+ override fun exchangeResource(methodType: String, path: String, request: String): WebClientResponse<String> {
return this.exchangeResource(methodType, path, request, defaultHeaders())
}
path: String,
request: String,
headers: Map<String, String>
- ): BlueprintWebClientService.WebClientResponse<String> {
+ ): WebClientResponse<String> {
/**
* TODO: Basic headers in the implementations of this client do not get added
* in blocking version, whereas in NB version defaultHeaders get added.
}
}
+ @Throws(IOException::class, ClientProtocolException::class)
+ protected fun performHttpCall(httpUriRequest: HttpUriRequest): WebClientResponse<String> {
+ val httpResponse = httpClient().execute(httpUriRequest)
+ val statusCode = httpResponse.statusLine.statusCode
+ httpResponse.entity.content.use {
+ val body = IOUtils.toString(it, Charset.defaultCharset())
+ return WebClientResponse(statusCode, body)
+ }
+ }
+
+ open override fun uploadBinaryFile(path: String, filePath: Path): WebClientResponse<String> {
+ val convertedHeaders: Array<BasicHeader> = convertToBasicHeaders(defaultHeaders())
+ val httpPost = HttpPost(host(path))
+ val entity = EntityBuilder.create().setBinary(Files.readAllBytes(filePath)).build()
+ httpPost.setEntity(entity)
+ RestLoggerService.httpInvoking(convertedHeaders)
+ httpPost.setHeaders(convertedHeaders)
+ return performHttpCall(httpPost)
+ }
+
// TODO: convert to multi-map
override fun convertToBasicHeaders(headers: Map<String, String>): Array<BasicHeader> {
return headers.map { BasicHeader(it.key, it.value) }.toTypedArray()
}
- open fun <T> delete(path: String, headers: Array<BasicHeader>, responseType: Class<T>): BlueprintWebClientService.WebClientResponse<T> {
+ open fun <T> delete(path: String, headers: Array<BasicHeader>, responseType: Class<T>): WebClientResponse<T> {
val httpDelete = HttpDelete(host(path))
RestLoggerService.httpInvoking(headers)
httpDelete.setHeaders(headers)
return performCallAndExtractTypedWebClientResponse(httpDelete, responseType)
}
- open fun <T> get(path: String, headers: Array<BasicHeader>, responseType: Class<T>): BlueprintWebClientService.WebClientResponse<T> {
+ open fun <T> get(path: String, headers: Array<BasicHeader>, responseType: Class<T>): WebClientResponse<T> {
val httpGet = HttpGet(host(path))
RestLoggerService.httpInvoking(headers)
httpGet.setHeaders(headers)
return performCallAndExtractTypedWebClientResponse(httpGet, responseType)
}
- open fun <T> post(path: String, request: Any, headers: Array<BasicHeader>, responseType: Class<T>): BlueprintWebClientService.WebClientResponse<T> {
+ open fun <T> post(path: String, request: Any, headers: Array<BasicHeader>, responseType: Class<T>): WebClientResponse<T> {
val httpPost = HttpPost(host(path))
val entity = StringEntity(strRequest(request))
httpPost.entity = entity
return performCallAndExtractTypedWebClientResponse(httpPost, responseType)
}
- open fun <T> put(path: String, request: Any, headers: Array<BasicHeader>, responseType: Class<T>): BlueprintWebClientService.WebClientResponse<T> {
+ open fun <T> put(path: String, request: Any, headers: Array<BasicHeader>, responseType: Class<T>): WebClientResponse<T> {
val httpPut = HttpPut(host(path))
val entity = StringEntity(strRequest(request))
httpPut.entity = entity
return performCallAndExtractTypedWebClientResponse(httpPut, responseType)
}
- open fun <T> patch(path: String, request: Any, headers: Array<BasicHeader>, responseType: Class<T>): BlueprintWebClientService.WebClientResponse<T> {
+ open fun <T> patch(path: String, request: Any, headers: Array<BasicHeader>, responseType: Class<T>): WebClientResponse<T> {
val httpPatch = HttpPatch(host(path))
val entity = StringEntity(strRequest(request))
httpPatch.entity = entity
httpUriRequest: HttpUriRequest,
responseType: Class<T>
):
- BlueprintWebClientService.WebClientResponse<T> {
+ WebClientResponse<T> {
val httpResponse = httpClient().execute(httpUriRequest)
val statusCode = httpResponse.statusLine.statusCode
val entity: HttpEntity? = httpResponse.entity
if (canResponseHaveBody(httpResponse)) {
entity!!.content.use {
val body = getResponse(it, responseType)
- return BlueprintWebClientService.WebClientResponse(statusCode, body)
+ return WebClientResponse(statusCode, body)
}
} else {
val constructor = responseType.getConstructor()
val body = constructor.newInstance()
- return BlueprintWebClientService.WebClientResponse(statusCode, body)
+ return WebClientResponse(statusCode, body)
}
}
fun canResponseHaveBody(response: HttpResponse): Boolean {
status != HttpStatus.SC_RESET_CONTENT
}
- open suspend fun getNB(path: String): BlueprintWebClientService.WebClientResponse<String> {
+ open suspend fun getNB(path: String): WebClientResponse<String> {
return getNB(path, null, String::class.java)
}
- open suspend fun getNB(path: String, additionalHeaders: Array<BasicHeader>?): BlueprintWebClientService.WebClientResponse<String> {
+ open suspend fun getNB(path: String, additionalHeaders: Array<BasicHeader>?): WebClientResponse<String> {
return getNB(path, additionalHeaders, String::class.java)
}
open suspend fun <T> getNB(path: String, additionalHeaders: Array<BasicHeader>?, responseType: Class<T>):
- BlueprintWebClientService.WebClientResponse<T> = withContext(Dispatchers.IO) {
+ WebClientResponse<T> = withContext(Dispatchers.IO) {
get(path, additionalHeaders!!, responseType)
}
- open suspend fun postNB(path: String, request: Any): BlueprintWebClientService.WebClientResponse<String> {
+ open suspend fun postNB(path: String, request: Any): WebClientResponse<String> {
return postNB(path, request, null, String::class.java)
}
- open suspend fun postNB(path: String, request: Any, additionalHeaders: Array<BasicHeader>?): BlueprintWebClientService.WebClientResponse<String> {
+ open suspend fun postNB(path: String, request: Any, additionalHeaders: Array<BasicHeader>?): WebClientResponse<String> {
return postNB(path, request, additionalHeaders, String::class.java)
}
request: Any,
additionalHeaders: Array<BasicHeader>?,
responseType: Class<T>
- ): BlueprintWebClientService.WebClientResponse<T> = withContext(Dispatchers.IO) {
+ ): WebClientResponse<T> = withContext(Dispatchers.IO) {
post(path, request, additionalHeaders!!, responseType)
}
- open suspend fun putNB(path: String, request: Any): BlueprintWebClientService.WebClientResponse<String> {
+ open suspend fun putNB(path: String, request: Any): WebClientResponse<String> {
return putNB(path, request, null, String::class.java)
}
path: String,
request: Any,
additionalHeaders: Array<BasicHeader>?
- ): BlueprintWebClientService.WebClientResponse<String> {
+ ): WebClientResponse<String> {
return putNB(path, request, additionalHeaders, String::class.java)
}
request: Any,
additionalHeaders: Array<BasicHeader>?,
responseType: Class<T>
- ): BlueprintWebClientService.WebClientResponse<T> = withContext(Dispatchers.IO) {
+ ): WebClientResponse<T> = withContext(Dispatchers.IO) {
put(path, request, additionalHeaders!!, responseType)
}
- open suspend fun <T> deleteNB(path: String): BlueprintWebClientService.WebClientResponse<String> {
+ open suspend fun <T> deleteNB(path: String): WebClientResponse<String> {
return deleteNB(path, null, String::class.java)
}
open suspend fun <T> deleteNB(path: String, additionalHeaders: Array<BasicHeader>?):
- BlueprintWebClientService.WebClientResponse<String> {
+ WebClientResponse<String> {
return deleteNB(path, additionalHeaders, String::class.java)
}
open suspend fun <T> deleteNB(path: String, additionalHeaders: Array<BasicHeader>?, responseType: Class<T>):
- BlueprintWebClientService.WebClientResponse<T> = withContext(Dispatchers.IO) {
+ WebClientResponse<T> = withContext(Dispatchers.IO) {
delete(path, additionalHeaders!!, responseType)
}
open suspend fun <T> patchNB(path: String, request: Any, additionalHeaders: Array<BasicHeader>?, responseType: Class<T>):
- BlueprintWebClientService.WebClientResponse<T> = withContext(Dispatchers.IO) {
+ WebClientResponse<T> = withContext(Dispatchers.IO) {
patch(path, request, additionalHeaders!!, responseType)
}
- override suspend fun exchangeNB(methodType: String, path: String, request: Any): BlueprintWebClientService.WebClientResponse<String> {
+ override suspend fun exchangeNB(methodType: String, path: String, request: Any): WebClientResponse<String> {
return exchangeNB(
methodType, path, request, hashMapOf(),
String::class.java
}
override suspend fun exchangeNB(methodType: String, path: String, request: Any, additionalHeaders: Map<String, String>?):
- BlueprintWebClientService.WebClientResponse<String> {
+ WebClientResponse<String> {
return exchangeNB(methodType, path, request, additionalHeaders, String::class.java)
}
request: Any,
additionalHeaders: Map<String, String>?,
responseType: Class<T>
- ): BlueprintWebClientService.WebClientResponse<T> {
+ ): WebClientResponse<T> {
// TODO: possible inconsistency
// NOTE: this basic headers function is different from non-blocking
import org.apache.http.message.BasicHeader
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintRetryException
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintIOUtils
+import java.nio.file.Path
interface BlueprintWebClientService {
fun defaultHeaders(): Map<String, String>
request: String
): WebClientResponse<String>
+ fun uploadBinaryFile(
+ path: String,
+ filePath: Path
+ ): WebClientResponse<String>
+
suspend fun exchangeNB(methodType: String, path: String, request: Any): WebClientResponse<String>
suspend fun exchangeNB(methodType: String, path: String, request: Any, additionalHeaders: Map<String, String>?):