2 * Copyright © 2021 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.services.execution.scripts
19 import com.fasterxml.jackson.databind.node.ObjectNode
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService
21 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.K8sPluginInstanceApi
24 import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.K8sRbInstanceStatus
25 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
26 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
27 import org.slf4j.LoggerFactory
29 open class SimpleStatusCheck : AbstractScriptComponentFunction() {
31 private val log = LoggerFactory.getLogger(SimpleStatusCheck::class.java)!!
33 override fun getName(): String {
34 return "SimpleStatusCheck"
37 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
38 log.info("STEP ${executionRequest.stepData?.name} - START")
40 val configValueSetup: ObjectNode = getDynamicProperties("config-deploy-setup") as ObjectNode
41 var checkCount: Int = getDynamicProperties("status-check-max-count").asInt()
43 val bluePrintPropertiesService: BluePrintPropertiesService =
44 this.functionDependencyInstanceAsType("bluePrintPropertiesService")
46 val k8sConfiguration = K8sConnectionPluginConfiguration(bluePrintPropertiesService)
48 val instanceApi = K8sPluginInstanceApi(k8sConfiguration)
50 while (checkCount > 0) {
51 var continueCheck = false
52 configValueSetup.fields().forEach { it ->
53 val vfModuleName = it.key
54 val instanceName = it.value.get("k8s-instance-id").asText()
56 val instanceStatus: K8sRbInstanceStatus? = instanceApi.getInstanceStatus(instanceName)
57 log.debug("Get status for $vfModuleName ($instanceName)")
58 if (!instanceStatus?.ready!!) {
60 log.info("VfModule $vfModuleName ($instanceName) is not ready. Please wait...")
62 log.info("VfModule $vfModuleName ($instanceName) is ready.")
68 throw BluePrintException("Instance State verification failed")
74 log.info("STEP ${executionRequest.stepData?.name} - STOP")
77 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
78 this.addError("${runtimeException.message}")