From 843d1f7ec7c45e3aad1d5198b776bb99a235448d Mon Sep 17 00:00:00 2001 From: Shaaban Ebrahim Date: Thu, 24 Oct 2019 12:37:21 +0200 Subject: Update on Health-api -add Combined health check -add combined metrics check Issue-ID: CCSDK-1669 Signed-off-by: Shaaban Ebrahim Change-Id: Idb3c7f67b3f22bd6069f75c193ae458c346fb2ac --- .../BasicAuthRestClientServiceConfiguration.kt | 50 -------- .../healthapi/controller/CombinedHealth.kt | 52 ++++++++ .../healthapi/controller/CombinedMetrics.kt | 52 ++++++++ .../healthapi/controller/HealthCheckController.kt | 48 -------- .../healthapi/domain/HealthApiResponse.kt | 6 - .../healthapi/domain/HealthCheckResponse.kt | 6 - .../healthapi/domain/HealthCheckStatus.kt | 6 - .../healthapi/domain/ServiceEndpoint.kt | 5 - .../healthapi/service/CombinedHealthService.kt | 58 +++++++++ .../healthapi/service/CombinedMetricsService.kt | 72 +++++++++++ .../healthapi/service/HealthCheckService.kt | 91 -------------- .../healthapi/utils/ObjectMappingUtils.kt | 13 ++ .../src/main/resources/application.properties | 5 +- .../healthapi/HealthCheckApplicationTests.kt | 25 +++- .../healthapi/HealthCheckServiceTest.java | 136 --------------------- .../src/test/resources/application-test.properties | 25 ++-- .../health-api/src/test/resources/logback.xml | 30 ++--- 17 files changed, 295 insertions(+), 385 deletions(-) delete mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedHealth.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedMetrics.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/HealthCheckController.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckResponse.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckStatus.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedHealthService.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedMetricsService.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/HealthCheckService.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/utils/ObjectMappingUtils.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.java (limited to 'ms/blueprintsprocessor/modules/inbounds/health-api/src') diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt deleted file mode 100644 index 0a97d37c5..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright © 2019-2020 Orange. - * - * 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.healthapi.configuration - -import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService -import org.springframework.beans.factory.annotation.Value -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.PropertySource - -@Configuration -@PropertySource("classpath:application.properties") -open class BasicAuthRestClientServiceConfiguration { - - @Value("\${endpoints.user.name}") - private val username: String? = null - - @Value("\${endpoints.user.password}") - private val password: String? = null - - @Bean - open fun getBasicAuthRestClientProperties(): BasicAuthRestClientProperties { - val basicAuthRestClientProperties = BasicAuthRestClientProperties() - basicAuthRestClientProperties.username = username.toString() - basicAuthRestClientProperties.password = password.toString() - return basicAuthRestClientProperties - } - - @Bean - open fun getBasicAuthRestClientService(): BasicAuthRestClientService { - return BasicAuthRestClientService(getBasicAuthRestClientProperties()) - } - - -} diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedHealth.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedHealth.kt new file mode 100644 index 000000000..54c85a0fc --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedHealth.kt @@ -0,0 +1,52 @@ +/* + * Copyright © 2019-2020 Orange. + * + * 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.healthapi.controller + +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ApplicationHealth +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.CombinedHealthService +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController + +/** + * Exposes API for checking health for other services . + * + * @author Shaaban Ebrahim + * @version 1.0 + */ +@RestController +@RequestMapping("/api/v1/combinedHealth") +@Api(value = "/api/v1/combinedHealth", + description = "gather all HealthCheckResponses for HealthChecks known to the runtime") +open class CombinedHealth(private val combinedHealthService: CombinedHealthService) { + + @RequestMapping(path = [""], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @ApiOperation(value = "Health Check", hidden = true) + fun getSystemHealthCheckResponse(): ResponseEntity> { + return ResponseEntity.ok().body(combinedHealthService.getCombinedHealthCheck()) + + } +} + diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedMetrics.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedMetrics.kt new file mode 100644 index 000000000..785def524 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedMetrics.kt @@ -0,0 +1,52 @@ +/* + * Copyright © 2019-2020 Orange. + * + * 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.healthapi.controller + +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.MetricsInfo +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.CombinedMetricsService +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController + +/** + * Exposes API for checking Metrics of BluePrint processor and CDSListener. + * + * @author Shaaban Ebrahim + * @version 1.0 + */ +@RestController +@RequestMapping("/api/v1/combinedMetrics") +@Api(value = "/api/v1/combinedMetrics", + description = "gather all Metrics info from BluePrint and CDSListener") +open class CombinedMetrics(private val combinedMetricsService: CombinedMetricsService) { + + @RequestMapping(path = [""], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @ApiOperation(value = " Metrics Check", hidden = true) + fun getMetricsHealthCheckResponse(): ResponseEntity { + return ResponseEntity.ok().body(combinedMetricsService.metricsInfo) + + } + +} diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/HealthCheckController.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/HealthCheckController.kt deleted file mode 100644 index 1283ac5ac..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/HealthCheckController.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © 2019-2020 Orange. - * - * 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.healthapi.controller - -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.HealthCheckService -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.MediaType -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestMethod -import org.springframework.web.bind.annotation.ResponseBody -import org.springframework.web.bind.annotation.RestController - -@RestController -@RequestMapping("/api/v1/health") -@Api(value = "/api/v1/health", - description = "gather all HealthCheckResponses for HealthChecks known to the runtime") -open class HealthCheckController { - - @Autowired - lateinit var healthApiService: HealthCheckService - - @RequestMapping(path = [""], - method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @ApiOperation(value = "Health Check", hidden = true) - fun getSystemHealthCheckResponse(): ResponseEntity { - return ResponseEntity.ok().body(healthApiService.retrieveSystemStatus()) - } -} diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt deleted file mode 100644 index 4dac178e5..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain - - -data class HealthApiResponse(val status: HealthCheckStatus, val checks:List) - - diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckResponse.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckResponse.kt deleted file mode 100644 index acac867cb..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckResponse.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain - - -data class HealthCheckResponse(val name: String, val status: HealthCheckStatus) - - diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckStatus.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckStatus.kt deleted file mode 100644 index a891a40d3..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckStatus.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain - -enum class HealthCheckStatus { - UP, - DOWN -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt deleted file mode 100644 index 8fbc33b47..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain - - - -data class ServiceEndpoint(val serviceName: String, val serviceLink: String) diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedHealthService.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedHealthService.kt new file mode 100644 index 000000000..786048ce4 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedHealthService.kt @@ -0,0 +1,58 @@ +/* + * Copyright © 2019-2020 Orange. + * + * 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.healthapi.service + +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.HealthCheckProperties +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ApplicationHealth +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.WebClientEnpointResponse +import org.springframework.boot.actuate.health.Status +import org.springframework.stereotype.Service + + +/** + *Service for combined health (BluePrintProcessor and CDSListener) + * + * @author Shaaban Ebrahim + * @version 1.0 + */ +@Service +open class CombinedHealthService(private val endPointExecution: EndPointExecution + , private val healthCheckProperties: HealthCheckProperties) { + + private fun setupServiceEndpoint(): List { + return listOf( + ServiceEndpoint("BluePrintProcessor Health Check ", healthCheckProperties.getBluePrintBaseURL() + "actuator/health") + , ServiceEndpoint("CDSListener Health Check", healthCheckProperties.getCDSListenerBaseURL() + "actuator/health") + ) + } + + open fun getCombinedHealthCheck(): List { + val listOfResponse = ArrayList() + for (serviceEndpoint in setupServiceEndpoint().parallelStream()) { + val result: WebClientEnpointResponse? = endPointExecution?.retrieveWebClientResponse(serviceEndpoint) + if (result?.response != null && + result.response!!.status?.equals(200)!!) { + listOfResponse.add(endPointExecution?.getHealthFromWebClientEnpointResponse(result)) + } else { + listOfResponse.add(ApplicationHealth(Status.DOWN, + hashMapOf(serviceEndpoint.serviceLink to serviceEndpoint.serviceLink))) + } + } + return listOfResponse + } + +} diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedMetricsService.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedMetricsService.kt new file mode 100644 index 000000000..a23c9925b --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedMetricsService.kt @@ -0,0 +1,72 @@ +/* + * Copyright © 2019-2020 Orange. + * + * 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.healthapi.service + +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.HealthCheckProperties +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.* +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.utils.ObjectMappingUtils +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService +import org.springframework.stereotype.Service + +/** + *Service for combined Metrics for CDS Listener and BluePrintProcessor + * + * @author Shaaban Ebrahim + * @version 1.0 + */ +@Service +open class CombinedMetricsService(private val endPointExecution: EndPointExecution + , private val healthCheckProperties: HealthCheckProperties + , private val objectMappingUtils: ObjectMappingUtils) { + + private fun setupServiceEndpoint(): List { + return listOf( + ServiceEndpoint("BluePrintProcessor metrics", healthCheckProperties.getBluePrintBaseURL() + "/actuator/metrics") + , ServiceEndpoint("CDS Listener metrics", healthCheckProperties.getCDSListenerBaseURL() + "/actuator/metrics") + ) + } + + open val metricsInfo: MetricsInfo + get() { + val containerHealthChecks = mutableListOf() + for (serviceEndpoint in setupServiceEndpoint().parallelStream()) { + val webClientResponse = endPointExecution?.retrieveWebClientResponse(serviceEndpoint) + var actuatorsHealthResponse: ActuatorCheckResponse? = null + actuatorsHealthResponse = if (webClientResponse?.response != null && + webClientResponse.response!!.status?.equals(200)!!) { + var body = gettingCustomizedBody(serviceEndpoint, webClientResponse.response!!) + ActuatorCheckResponse(serviceEndpoint.serviceName, body) + } else { + ActuatorCheckResponse(serviceEndpoint.serviceName, HealthCheckStatus.DOWN) + } + containerHealthChecks.add(actuatorsHealthResponse) + } + return MetricsInfo(containerHealthChecks) + } + + private fun gettingCustomizedBody(serviceEndpoint: ServiceEndpoint?, webClientResponse: BlueprintWebClientService.WebClientResponse): Any { + var body: Any + val metrics: Metrics = objectMappingUtils.getObjectFromBody(webClientResponse.body, Metrics::class.java) + val mapOfMetricsInfo = HashMap() + for (name in metrics.names!!) { + mapOfMetricsInfo.put(name.toString(), serviceEndpoint?.serviceLink + "/" + name) + } + body = MetricsResponse(mapOfMetricsInfo) + + return body + } +} + diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/HealthCheckService.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/HealthCheckService.kt deleted file mode 100644 index 09fdb67f2..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/HealthCheckService.kt +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright © 2019-2020 Orange. - * - * 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.healthapi.service - -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckResponse -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint -import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.HttpMethod -import org.springframework.stereotype.Service - - -@Service -class HealthCheckService { - - private var logger = LoggerFactory.getLogger(HealthCheckService::class.java) - - @Autowired - lateinit var basicAuthRestClientService: BasicAuthRestClientService - - @Autowired - lateinit var restClientProperties: BasicAuthRestClientProperties - - - open fun setupServiceEndpoint(): List { - return listOf(ServiceEndpoint("Execution service", "http://cds-blueprints-processor-http:8080/api/v1/execution-service/health-check"), - ServiceEndpoint("Template service", "http://cds-blueprints-processor-http:8080/api/v1/template/health-check"), - ServiceEndpoint("Resources service", "http://cds-blueprints-processor-http:8080/api/v1/resources/health-check"), - ServiceEndpoint("SDC Listener service", "http://cds-sdc-listener:8080/api/v1/sdclistener/health-check") - ) - } - - fun retrieveSystemStatus(): HealthApiResponse { - logger.info("Retrieve System Status") - var healthApiResponse: HealthApiResponse - val listOfResponse = mutableListOf() - var systemStatus: HealthCheckStatus = HealthCheckStatus.UP - - for (serviceEndpoint in setupServiceEndpoint().parallelStream()) { - var serviceStatus: HealthCheckStatus = retrieveServiceStatus(serviceEndpoint) - if (serviceStatus.equals(HealthCheckStatus.DOWN)) - systemStatus = HealthCheckStatus.DOWN - - listOfResponse.add(HealthCheckResponse(serviceEndpoint.serviceName, serviceStatus)) - } - healthApiResponse = HealthApiResponse(systemStatus, listOfResponse) - return healthApiResponse - } - - private fun retrieveServiceStatus(serviceEndpoint: ServiceEndpoint): HealthCheckStatus { - var serviceStatus: HealthCheckStatus = HealthCheckStatus.UP - try { - addClientPropertiesConfiguration(serviceEndpoint) - val result: BlueprintWebClientService.WebClientResponse = basicAuthRestClientService.exchangeResource(HttpMethod.GET.name, "", "") - if (result == null || result.status != 200) { - serviceStatus = HealthCheckStatus.DOWN - - } - } catch (e: Exception) { - logger.error("service is down" + e) - serviceStatus = HealthCheckStatus.DOWN - - } - return serviceStatus - } - - private fun addClientPropertiesConfiguration(serviceEndpoint: ServiceEndpoint) { - restClientProperties.url = serviceEndpoint.serviceLink - } - - -} diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/utils/ObjectMappingUtils.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/utils/ObjectMappingUtils.kt new file mode 100644 index 000000000..9964c4518 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/utils/ObjectMappingUtils.kt @@ -0,0 +1,13 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.utils + +import com.fasterxml.jackson.databind.ObjectMapper +import org.springframework.stereotype.Service + +@Service +class ObjectMappingUtils { + + @Throws(java.io.IOException::class) + open fun getObjectFromBody(body: String, mappingClass: Class): T { + return ObjectMapper().readValue(body, mappingClass) as T + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/resources/application.properties b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/resources/application.properties index aca95b481..de4b8f8f9 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/resources/application.properties +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/resources/application.properties @@ -13,6 +13,5 @@ # See the License for the specific language governing permissions and # limitations under the License. # - -endpoints.user.name=ccsdkapps -endpoints.user.password=ccsdkapps +#endpoints.user.name=eHbVUbJAj4AG2522cSbrOQ== +#endpoints.user.password=eHbVUbJAj4AG2522cSbrOQ== diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt index cd02b65dc..b1d629da7 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt @@ -20,7 +20,9 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.security.SecurityProperties import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest @@ -30,25 +32,36 @@ import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner import org.springframework.test.web.reactive.server.WebTestClient - +/** + *Unit tests for making sure that two endpoints is up and running + * + * @author Shaaban Ebrahim + * @version 1.0 + */ @RunWith(SpringRunner::class) @WebFluxTest -@ContextConfiguration(classes = [BluePrintCoreConfiguration::class, - BluePrintCatalogService::class, SecurityProperties::class]) +@ContextConfiguration(classes = [BluePrintRuntimeService::class, BluePrintCoreConfiguration::class, + BluePrintCatalogService::class, SecurityProperties::class, ComponentScriptExecutor::class]) @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class HealthCheckApplicationTests { - @Autowired lateinit var webTestClient: WebTestClient @Test fun testHealthApiUp() { - val result = webTestClient.get().uri("/api/v1/health") + webTestClient.get().uri("/api/v1/combinedHealth") + .exchange() + .expectStatus().is2xxSuccessful + + } + + @Test + fun testMetricsApiUp() { + webTestClient.get().uri("/api/v1/combinedMetrics") .exchange() .expectStatus().is2xxSuccessful - println(result) } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.java b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.java deleted file mode 100644 index 128c80adf..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright © 2019-2020 Orange. - * - * 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.healthapi; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse; -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus; -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.HealthCheckService; -import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties; -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService; -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService.WebClientResponse; -import org.springframework.http.HttpMethod; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.anyString; - -@RunWith(MockitoJUnitRunner.class) -public class HealthCheckServiceTest { - - @Mock - private BasicAuthRestClientService basicAuthRestClientService; - - @Mock - private BasicAuthRestClientProperties restClientProperties; - - @InjectMocks - private HealthCheckService healthCheckService = new HealthCheckService(); - - @Before - public void setup() { - } - - @Test - public void testSystemIsCompletelyDown() { - - Mockito.when(basicAuthRestClientService.exchangeResource(anyString(), anyString(), anyString())). - thenThrow(new RuntimeException()); - HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus(); - assertNotNull(healthApiResponse); - Assert.assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.DOWN); - healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> { - assertNotNull(serviceEndpoint); - assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.DOWN); - - }); - - } - - - @Test - public void testSystemIsUPAndRunning() { - - Mockito.when(basicAuthRestClientService.exchangeResource(eq(HttpMethod.GET.name()), anyString(), anyString())). - thenReturn(new WebClientResponse<>(200, "Success")); - HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus(); - assertNotNull(healthApiResponse); - assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.UP); - healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> { - assertNotNull(serviceEndpoint); - assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.UP); - - }); - - } - - @Test - public void testServiceIsNotFound() { - Mockito.when(basicAuthRestClientService.exchangeResource(eq(HttpMethod.GET.name()), any(), anyString())). - thenReturn(new WebClientResponse<>(404, "failure")); - HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus(); - assertNotNull(healthApiResponse); - assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.DOWN); - healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> { - assertNotNull(serviceEndpoint); - assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.DOWN); - - }); - - } - - - @Test - public void testServiceInternalServerError() { - Mockito.when(basicAuthRestClientService.exchangeResource(eq(HttpMethod.GET.name()), any(), anyString())) - .thenReturn(new WebClientResponse<>(500, "failure")); - HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus(); - assertNotNull(healthApiResponse); - assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.DOWN); - healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> { - assertNotNull(serviceEndpoint); - assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.DOWN); - - }); - - } - - @Test - public void testServiceIsRedirected() { - Mockito.when(basicAuthRestClientService.exchangeResource(eq(HttpMethod.GET.name()), any(), anyString())) - .thenReturn(new WebClientResponse<>(300, "failure")); - HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus(); - assertNotNull(healthApiResponse); - assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.DOWN); - healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> { - assertNotNull(serviceEndpoint); - assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.DOWN); - - }); - - } - -} diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/resources/application-test.properties index c9a5700c1..8eb6db352 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/resources/application-test.properties +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/resources/application-test.properties @@ -1,16 +1,14 @@ -# Copyright © 2019 Bell Canada. # -# 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. +# Copyright © 2019-2020 Orange. +# 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. blueprintsprocessor.db.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 blueprintsprocessor.db.username=sa @@ -24,8 +22,9 @@ blueprintsprocessor.db.hibernateDialect=org.hibernate.dialect.H2Dialect blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy blueprintsprocessor.blueprintWorkingPath=./target/blueprints/work blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive - # Python executor blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints server.socket=localhost:8080 +endpoints.user.name=eHbVUbJAj4AG2522cSbrOQ== +endpoints.user.password=eHbVUbJAj4AG2522cSbrOQ== diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/resources/logback.xml b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/resources/logback.xml index c97e1cd29..11582a301 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/resources/logback.xml +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/resources/logback.xml @@ -1,23 +1,23 @@ - %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n -- cgit 1.2.3-korg