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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration
19 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint
20 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceName
21 import org.springframework.beans.factory.annotation.Value
22 import org.springframework.context.annotation.Configuration
23 import org.springframework.context.annotation.PropertySource
26 @PropertySource("classpath:application.properties")
27 open class HealthCheckProperties {
29 @Value("\${blueprintprocessor.healthcheck.baseUrl}")
30 private val bluePrintProcessorBaseURL: String? = null
32 @Value("#{'\${blueprintprocessor.healthcheck.mapping-service-name-with-service-link}'.split(']')}")
33 private val blueprintprocessorServiceMapping: List<String>? = null
35 @Value("\${cdslistener.healthcheck.baseUrl}")
36 private val cdsListenerBaseURL: String? = null
38 @Value("#{'\${cdslistener.healthcheck.mapping-service-name-with-service-link}'.split(']')}")
39 private val cdsListenerServiceMapping: List<String>? = null
41 open fun getBluePrintBaseURL(): String? {
42 return bluePrintProcessorBaseURL
45 open fun getCDSListenerBaseURL(): String? {
46 return cdsListenerBaseURL
49 open fun getBluePrintServiceInformation(): List<ServiceEndpoint> {
50 val serviceName = ServiceName.BLUEPRINT
51 return getListOfServiceEndPoints(blueprintprocessorServiceMapping, serviceName)
54 open fun getCDSListenerServiceInformation(): List<ServiceEndpoint> {
55 val serviceName = ServiceName.BLUEPRINT
56 return getListOfServiceEndPoints(cdsListenerServiceMapping, serviceName)
60 private fun getListOfServiceEndPoints(serviceMapping: List<String>?, serviceName: ServiceName): MutableList<ServiceEndpoint> {
61 val serviceEndpoints = mutableListOf<ServiceEndpoint>()
62 if (serviceMapping != null) {
63 for (element in serviceMapping) {
64 fillListOfService(serviceName, element, serviceEndpoints)
67 return serviceEndpoints
70 private fun fillListOfService(serviceName: ServiceName , element: String, listOfCDSListenerServiceEndpoint: MutableList<ServiceEndpoint>) {
71 val serviceEndpointInfo = element.split(",/")
72 val serviceEndpoint = getServiceEndpoint(serviceEndpointInfo)
73 if (serviceName.equals(ServiceName.CDSLISTENER))
74 serviceEndpoint.serviceLink = cdsListenerBaseURL + serviceEndpoint.serviceLink
75 else if (serviceName.equals(ServiceName.BLUEPRINT))
76 serviceEndpoint.serviceLink = bluePrintProcessorBaseURL + serviceEndpoint.serviceLink
77 listOfCDSListenerServiceEndpoint.add(serviceEndpoint)
81 private fun getServiceEndpoint(serviceEndpointInfo: List<String>): ServiceEndpoint {
82 return ServiceEndpoint(removeSpecialCharacter(serviceEndpointInfo.get(0))
83 , removeSpecialCharacter(serviceEndpointInfo.get(1))
87 private fun removeSpecialCharacter(value:String):String{
88 return value.replaceFirst(",[","")