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.ActuatorCheckResponse
20 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus
21 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.Metrics
22 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.MetricsInfo
23 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.MetricsResponse
24 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint
25 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.utils.ObjectMappingUtils
26 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
27 import org.springframework.stereotype.Service
30 *Service for combined Metrics for CDS Listener and BluePrintProcessor
32 * @author Shaaban Ebrahim
36 open class CombinedMetricsService(
37 private val endPointExecution: EndPointExecution,
38 private val healthCheckProperties: HealthCheckProperties,
39 private val objectMappingUtils: ObjectMappingUtils<Metrics>
42 private fun setupServiceEndpoint(): List<ServiceEndpoint> {
44 ServiceEndpoint("BluePrintProcessor metrics", healthCheckProperties.getBluePrintBaseURL() + "/actuator/metrics"),
45 ServiceEndpoint("CDS Listener metrics", healthCheckProperties.getCDSListenerBaseURL() + "/actuator/metrics")
49 open val metricsInfo: MetricsInfo
51 val containerHealthChecks = mutableListOf<ActuatorCheckResponse>()
52 for (serviceEndpoint in setupServiceEndpoint().parallelStream()) {
53 val webClientResponse = endPointExecution?.retrieveWebClientResponse(serviceEndpoint)
54 var actuatorsHealthResponse: ActuatorCheckResponse? = null
55 actuatorsHealthResponse = if (webClientResponse?.response != null &&
56 webClientResponse.response!!.status?.equals(200)!!
58 var body = gettingCustomizedBody(serviceEndpoint, webClientResponse.response!!)
59 ActuatorCheckResponse(serviceEndpoint.serviceName, body)
61 ActuatorCheckResponse(serviceEndpoint.serviceName, HealthCheckStatus.DOWN)
63 containerHealthChecks.add(actuatorsHealthResponse)
65 return MetricsInfo(containerHealthChecks)
68 private fun gettingCustomizedBody(
69 serviceEndpoint: ServiceEndpoint?,
70 webClientResponse: BlueprintWebClientService.WebClientResponse<String>
73 val metrics: Metrics = objectMappingUtils.getObjectFromBody(webClientResponse.body, Metrics::class.java)
74 val mapOfMetricsInfo = HashMap<String, String>()
75 for (name in metrics.names!!) {
76 mapOfMetricsInfo.put(name.toString(), serviceEndpoint?.serviceLink + "/" + name)
78 body = MetricsResponse(mapOfMetricsInfo)