c63952d80fdda63f6d92e172672d1bbd424c9d23
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / health-api-common / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / healthapi / configuration / HealthCheckProperties.kt
1 /*
2  * Copyright © 2019-2020 Orange.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration
18
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
24
25 @Configuration
26 @PropertySource("classpath:application.properties")
27 open class HealthCheckProperties {
28
29     @Value("\${blueprintprocessor.healthcheck.baseUrl}")
30     private val bluePrintProcessorBaseURL: String? = null
31
32     @Value("#{'\${blueprintprocessor.healthcheck.mapping-service-name-with-service-link}'.split(']')}")
33     private val blueprintprocessorServiceMapping: List<String>? = null
34
35     @Value("\${cdslistener.healthcheck.baseUrl}")
36     private val cdsListenerBaseURL: String? = null
37
38     @Value("#{'\${cdslistener.healthcheck.mapping-service-name-with-service-link}'.split(']')}")
39     private val cdsListenerServiceMapping: List<String>? = null
40
41     open fun getBluePrintBaseURL(): String? {
42         return bluePrintProcessorBaseURL
43     }
44
45     open fun getCDSListenerBaseURL(): String? {
46         return cdsListenerBaseURL
47     }
48
49     open fun getBluePrintServiceInformation(): List<ServiceEndpoint> {
50         val serviceName = ServiceName.BLUEPRINT
51         return getListOfServiceEndPoints(blueprintprocessorServiceMapping, serviceName)
52     }
53
54     open fun getCDSListenerServiceInformation(): List<ServiceEndpoint> {
55         val serviceName = ServiceName.BLUEPRINT
56         return getListOfServiceEndPoints(cdsListenerServiceMapping, serviceName)
57
58     }
59
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)
65             }
66         }
67         return serviceEndpoints
68     }
69
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)
78     }
79
80
81     private fun getServiceEndpoint(serviceEndpointInfo: List<String>): ServiceEndpoint {
82         return ServiceEndpoint(removeSpecialCharacter(serviceEndpointInfo.get(0))
83                 , removeSpecialCharacter(serviceEndpointInfo.get(1))
84         )
85     }
86
87     private fun removeSpecialCharacter(value:String):String{
88         return value.replaceFirst(",[","")
89                 .replace("[","")
90                 .replace("]","")
91     }
92 }