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)
59 private fun getListOfServiceEndPoints(serviceMapping: List<String>?, serviceName: ServiceName): MutableList<ServiceEndpoint> {
60 val serviceEndpoints = mutableListOf<ServiceEndpoint>()
61 if (serviceMapping != null) {
62 for (element in serviceMapping) {
63 fillListOfService(serviceName, element, serviceEndpoints)
66 return serviceEndpoints
69 private fun fillListOfService(serviceName: ServiceName, element: String, listOfCDSListenerServiceEndpoint: MutableList<ServiceEndpoint>) {
70 val serviceEndpointInfo = element.split(",/")
71 val serviceEndpoint = getServiceEndpoint(serviceEndpointInfo)
72 if (serviceName.equals(ServiceName.CDSLISTENER))
73 serviceEndpoint.serviceLink = cdsListenerBaseURL + serviceEndpoint.serviceLink
74 else if (serviceName.equals(ServiceName.BLUEPRINT))
75 serviceEndpoint.serviceLink = bluePrintProcessorBaseURL + serviceEndpoint.serviceLink
76 listOfCDSListenerServiceEndpoint.add(serviceEndpoint)
79 private fun getServiceEndpoint(serviceEndpointInfo: List<String>): ServiceEndpoint {
80 return ServiceEndpoint(
81 removeSpecialCharacter(serviceEndpointInfo.get(0)), removeSpecialCharacter(serviceEndpointInfo.get(1))
85 private fun removeSpecialCharacter(value: String): String {
86 return value.replaceFirst(",[", "")