2 * Copyright © 2019-2020 Orange.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service
18 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.HealthCheckProperties
19 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.*
20 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.utils.ObjectMappingUtils
21 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
22 import org.springframework.stereotype.Service
25 *Service for combined Metrics for CDS Listener and BluePrintProcessor
27 * @author Shaaban Ebrahim
31 open class CombinedMetricsService(private val endPointExecution: EndPointExecution
32 , private val healthCheckProperties: HealthCheckProperties
33 , private val objectMappingUtils: ObjectMappingUtils<Metrics>) {
35 private fun setupServiceEndpoint(): List<ServiceEndpoint> {
37 ServiceEndpoint("BluePrintProcessor metrics", healthCheckProperties.getBluePrintBaseURL() + "/actuator/metrics")
38 , ServiceEndpoint("CDS Listener metrics", healthCheckProperties.getCDSListenerBaseURL() + "/actuator/metrics")
42 open val metricsInfo: MetricsInfo
44 val containerHealthChecks = mutableListOf<ActuatorCheckResponse>()
45 for (serviceEndpoint in setupServiceEndpoint().parallelStream()) {
46 val webClientResponse = endPointExecution?.retrieveWebClientResponse(serviceEndpoint)
47 var actuatorsHealthResponse: ActuatorCheckResponse? = null
48 actuatorsHealthResponse = if (webClientResponse?.response != null &&
49 webClientResponse.response!!.status?.equals(200)!!) {
50 var body = gettingCustomizedBody(serviceEndpoint, webClientResponse.response!!)
51 ActuatorCheckResponse(serviceEndpoint.serviceName, body)
53 ActuatorCheckResponse(serviceEndpoint.serviceName, HealthCheckStatus.DOWN)
55 containerHealthChecks.add(actuatorsHealthResponse)
57 return MetricsInfo(containerHealthChecks)
60 private fun gettingCustomizedBody(serviceEndpoint: ServiceEndpoint?, webClientResponse: BlueprintWebClientService.WebClientResponse<String>): Any {
62 val metrics: Metrics = objectMappingUtils.getObjectFromBody(webClientResponse.body, Metrics::class.java)
63 val mapOfMetricsInfo = HashMap<String, String>()
64 for (name in metrics.names!!) {
65 mapOfMetricsInfo.put(name.toString(), serviceEndpoint?.serviceLink + "/" + name)
67 body = MetricsResponse(mapOfMetricsInfo)