aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/health-api/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/health-api/src/main')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt50
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/HealthCheckController.kt48
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt6
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckResponse.kt6
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckStatus.kt6
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt5
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/HealthCheckService.kt91
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/main/resources/application.properties18
8 files changed, 230 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt
new file mode 100644
index 000000000..0a97d37c5
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2019-2020 Orange.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration
+
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService
+import org.springframework.beans.factory.annotation.Value
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import org.springframework.context.annotation.PropertySource
+
+@Configuration
+@PropertySource("classpath:application.properties")
+open class BasicAuthRestClientServiceConfiguration {
+
+ @Value("\${endpoints.user.name}")
+ private val username: String? = null
+
+ @Value("\${endpoints.user.password}")
+ private val password: String? = null
+
+ @Bean
+ open fun getBasicAuthRestClientProperties(): BasicAuthRestClientProperties {
+ val basicAuthRestClientProperties = BasicAuthRestClientProperties()
+ basicAuthRestClientProperties.username = username.toString()
+ basicAuthRestClientProperties.password = password.toString()
+ return basicAuthRestClientProperties
+ }
+
+ @Bean
+ open fun getBasicAuthRestClientService(): BasicAuthRestClientService {
+ return BasicAuthRestClientService(getBasicAuthRestClientProperties())
+ }
+
+
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/HealthCheckController.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/HealthCheckController.kt
new file mode 100644
index 000000000..1283ac5ac
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/HealthCheckController.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright © 2019-2020 Orange.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.controller
+
+import io.swagger.annotations.Api
+import io.swagger.annotations.ApiOperation
+import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse
+import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.HealthCheckService
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.http.MediaType
+import org.springframework.http.ResponseEntity
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RequestMethod
+import org.springframework.web.bind.annotation.ResponseBody
+import org.springframework.web.bind.annotation.RestController
+
+@RestController
+@RequestMapping("/api/v1/health")
+@Api(value = "/api/v1/health",
+ description = "gather all HealthCheckResponses for HealthChecks known to the runtime")
+open class HealthCheckController {
+
+ @Autowired
+ lateinit var healthApiService: HealthCheckService
+
+ @RequestMapping(path = [""],
+ method = [RequestMethod.GET],
+ produces = [MediaType.APPLICATION_JSON_VALUE])
+ @ResponseBody
+ @ApiOperation(value = "Health Check", hidden = true)
+ fun getSystemHealthCheckResponse(): ResponseEntity<HealthApiResponse> {
+ return ResponseEntity.ok().body(healthApiService.retrieveSystemStatus())
+ }
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt
new file mode 100644
index 000000000..4dac178e5
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt
@@ -0,0 +1,6 @@
+package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain
+
+
+data class HealthApiResponse(val status: HealthCheckStatus, val checks:List<HealthCheckResponse>)
+
+
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckResponse.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckResponse.kt
new file mode 100644
index 000000000..acac867cb
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckResponse.kt
@@ -0,0 +1,6 @@
+package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain
+
+
+data class HealthCheckResponse(val name: String, val status: HealthCheckStatus)
+
+
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckStatus.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckStatus.kt
new file mode 100644
index 000000000..a891a40d3
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthCheckStatus.kt
@@ -0,0 +1,6 @@
+package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain
+
+enum class HealthCheckStatus {
+ UP,
+ DOWN
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt
new file mode 100644
index 000000000..8fbc33b47
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt
@@ -0,0 +1,5 @@
+package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain
+
+
+
+data class ServiceEndpoint(val serviceName: String, val serviceLink: String)
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/HealthCheckService.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/HealthCheckService.kt
new file mode 100644
index 000000000..09fdb67f2
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/HealthCheckService.kt
@@ -0,0 +1,91 @@
+/*
+ * Copyright © 2019-2020 Orange.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service
+
+import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse
+import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckResponse
+import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus
+import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.http.HttpMethod
+import org.springframework.stereotype.Service
+
+
+@Service
+class HealthCheckService {
+
+ private var logger = LoggerFactory.getLogger(HealthCheckService::class.java)
+
+ @Autowired
+ lateinit var basicAuthRestClientService: BasicAuthRestClientService
+
+ @Autowired
+ lateinit var restClientProperties: BasicAuthRestClientProperties
+
+
+ open fun setupServiceEndpoint(): List<ServiceEndpoint> {
+ return listOf(ServiceEndpoint("Execution service", "http://cds-blueprints-processor-http:8080/api/v1/execution-service/health-check"),
+ ServiceEndpoint("Template service", "http://cds-blueprints-processor-http:8080/api/v1/template/health-check"),
+ ServiceEndpoint("Resources service", "http://cds-blueprints-processor-http:8080/api/v1/resources/health-check"),
+ ServiceEndpoint("SDC Listener service", "http://cds-sdc-listener:8080/api/v1/sdclistener/health-check")
+ )
+ }
+
+ fun retrieveSystemStatus(): HealthApiResponse {
+ logger.info("Retrieve System Status")
+ var healthApiResponse: HealthApiResponse
+ val listOfResponse = mutableListOf<HealthCheckResponse>()
+ var systemStatus: HealthCheckStatus = HealthCheckStatus.UP
+
+ for (serviceEndpoint in setupServiceEndpoint().parallelStream()) {
+ var serviceStatus: HealthCheckStatus = retrieveServiceStatus(serviceEndpoint)
+ if (serviceStatus.equals(HealthCheckStatus.DOWN))
+ systemStatus = HealthCheckStatus.DOWN
+
+ listOfResponse.add(HealthCheckResponse(serviceEndpoint.serviceName, serviceStatus))
+ }
+ healthApiResponse = HealthApiResponse(systemStatus, listOfResponse)
+ return healthApiResponse
+ }
+
+ private fun retrieveServiceStatus(serviceEndpoint: ServiceEndpoint): HealthCheckStatus {
+ var serviceStatus: HealthCheckStatus = HealthCheckStatus.UP
+ try {
+ addClientPropertiesConfiguration(serviceEndpoint)
+ val result: BlueprintWebClientService.WebClientResponse<String> = basicAuthRestClientService.exchangeResource(HttpMethod.GET.name, "", "")
+ if (result == null || result.status != 200) {
+ serviceStatus = HealthCheckStatus.DOWN
+
+ }
+ } catch (e: Exception) {
+ logger.error("service is down" + e)
+ serviceStatus = HealthCheckStatus.DOWN
+
+ }
+ return serviceStatus
+ }
+
+ private fun addClientPropertiesConfiguration(serviceEndpoint: ServiceEndpoint) {
+ restClientProperties.url = serviceEndpoint.serviceLink
+ }
+
+
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/resources/application.properties b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/resources/application.properties
new file mode 100644
index 000000000..aca95b481
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/resources/application.properties
@@ -0,0 +1,18 @@
+#
+# Copyright � 2019-2020 Orange.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+endpoints.user.name=ccsdkapps
+endpoints.user.password=ccsdkapps