aboutsummaryrefslogtreecommitdiffstats
path: root/kubernetes/policy/resources/config/pe/mysql.conf
diff options
context:
space:
mode:
authorLucjan Bryndza <l.bryndza@samsung.com>2020-04-29 08:52:33 +0000
committerLucjan Bryndza <l.bryndza@samsung.com>2020-04-29 14:16:13 +0000
commit0564965a5c00f45f3d11229d9860d6458e2fb7e9 (patch)
treeab3d7aff04f15788c015e54642230e5688d90b08 /kubernetes/policy/resources/config/pe/mysql.conf
parentf69c491ed06b017fe439ff8ff48ac896e93d0f52 (diff)
Change ingress hosnames for exposed services
Change ingress host to the required hostnames Change-Id: Ic78c8821e2e23e00943d8abdf7b2183b4d940c72 Signed-off-by: Lucjan Bryndza <l.bryndza@samsung.com> Issue-ID: OOM-2391 Signed-off-by: Lucjan Bryndza <l.bryndza@samsung.com>
Diffstat (limited to 'kubernetes/policy/resources/config/pe/mysql.conf')
0 files changed, 0 insertions, 0 deletions
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
/*
 * Copyright © 2017-2018 AT&T Intellectual Property.
 *
 * 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.apps.blueprintsprocessor.functions.resource.resolution.utils

import com.att.eelf.configuration.EELFLogger
import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.NullNode
import com.fasterxml.jackson.databind.node.ObjectNode
import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.*
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
import java.util.*

class ResourceAssignmentUtils {
    companion object {

        private val logger: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentUtils::class.toString())

        @Synchronized
        @Throws(BluePrintProcessorException::class)
        fun setResourceDataValue(resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, value: Any?) {

            val resourceProp = checkNotNull(resourceAssignment.property) { "Failed in setting resource value for resource mapping $resourceAssignment" }
            checkNotEmptyOrThrow(resourceAssignment.name, "Failed in setting resource value for resource mapping $resourceAssignment")

            if (checkNotEmpty(resourceAssignment.dictionaryName)) {
                resourceAssignment.dictionaryName = resourceAssignment.name
                logger.warn("Missing dictionary key, setting with template key (${resourceAssignment.name}) as dictionary key (${resourceAssignment.dictionaryName})")
            }

            try {
                if (checkNotEmpty(resourceProp.type)) {
                    val convertedValue = convertResourceValue(resourceProp.type, value)
                    logger.info("Setting Resource Value ($convertedValue) for Resource Name (${resourceAssignment.dictionaryName}) of type (${resourceProp.type})")
                    setResourceValue(resourceAssignment, raRuntimeService, convertedValue)
                    resourceAssignment.updatedDate = Date()
                    resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM
                    resourceAssignment.status = BluePrintConstants.STATUS_SUCCESS
                }
            } catch (e: Exception) {
                throw BluePrintProcessorException("Failed in setting value for template key (${resourceAssignment.name}) and " +
                        "dictionary key (${resourceAssignment.dictionaryName}) of type (${resourceProp.type}) with error message (${e.message})", e)
            }
        }

        private fun setResourceValue(resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode) {
            raRuntimeService.putResolutionStore(resourceAssignment.name, value)
            raRuntimeService.putDictionaryStore(resourceAssignment.dictionaryName!!, value)
            resourceAssignment.property!!.value = value
        }

        private fun convertResourceValue(type: String, value: Any?): JsonNode {

            return if (value == null || value is NullNode) {
                logger.info("Returning {} value from convertResourceValue", value)
                NullNode.instance
            } else if (BluePrintTypes.validPrimitiveTypes().contains(type) && value is String) {
                JacksonUtils.convertPrimitiveResourceValue(type, value)
            } else if (value is String) {
                JacksonUtils.jsonNode(value)
            } else {
                JacksonUtils.getJsonNode(value)
            }

        }

        @Synchronized
        fun setFailedResourceDataValue(resourceAssignment: ResourceAssignment, message: String?) {
            if (checkNotEmpty(resourceAssignment.name)) {
                resourceAssignment.updatedDate = Date()
                resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM
                resourceAssignment.status = BluePrintConstants.STATUS_FAILURE
                resourceAssignment.message = message
            }
        }

        @Synchronized
        @Throws(BluePrintProcessorException::class)
        fun assertTemplateKeyValueNotNull(resourceAssignment: ResourceAssignment) {
            val resourceProp = checkNotNull(resourceAssignment.property) { "Failed to populate mandatory resource resource mapping $resourceAssignment" }
            if (resourceProp.required != null && resourceProp.required!! && (resourceProp.value == null || resourceProp.value !is NullNode)) {
                logger.error("failed to populate mandatory resource mapping ($resourceAssignment)")
                throw BluePrintProcessorException("failed to populate mandatory resource mapping ($resourceAssignment)")
            }
        }

        @Synchronized
        @Throws(BluePrintProcessorException::class)
        fun generateResourceDataForAssignments(assignments: List<ResourceAssignment>): String {
            var result = "{}"
            try {
                val mapper = ObjectMapper()
                val root = mapper.readTree(result)

                assignments.forEach {
                    if (checkNotEmpty(it.name) && it.property != null) {
                        val rName = it.name
                        val type = nullToEmpty(it.property?.type).toLowerCase()
                        val value = it.property?.value
                        logger.info("Generating Resource name ($rName), type ($type), value ($value)")

                        when (value) {
                            null -> (root as ObjectNode).set(rName, null)
                            is JsonNode -> (root as ObjectNode).set(rName, value)
                            else -> {
                                when (type) {
                                    BluePrintConstants.DATA_TYPE_TIMESTAMP -> (root as ObjectNode).put(rName, value as String)
                                    BluePrintConstants.DATA_TYPE_STRING -> (root as ObjectNode).put(rName, value as String)
                                    BluePrintConstants.DATA_TYPE_BOOLEAN -> (root as ObjectNode).put(rName, value as Boolean)
                                    BluePrintConstants.DATA_TYPE_INTEGER -> (root as ObjectNode).put(rName, value as Int)
                                    BluePrintConstants.DATA_TYPE_FLOAT -> (root as ObjectNode).put(rName, value as Float)
                                    else -> {
                                        (root as ObjectNode).set(rName, JacksonUtils.getJsonNode(value))
                                    }
                                }
                            }
                        }
                    }
                }
                result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root)
                logger.info("Generated Resource Param Data ($result)")
            } catch (e: Exception) {
                throw BluePrintProcessorException("Resource Assignment is failed with $e.message", e)
            }

            return result
        }

        fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>, templateArtifactName: String): ResourceAssignmentRuntimeService {
            val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService(blueprintRuntimeService.id(), blueprintRuntimeService.bluePrintContext())
            resourceAssignmentRuntimeService.createUniqueId(templateArtifactName)
            resourceAssignmentRuntimeService.setExecutionContext(blueprintRuntimeService.getExecutionContext() as MutableMap<String, JsonNode>)

            return resourceAssignmentRuntimeService
        }

        /*
         * Populate the Field property type for the Data type
         */
        @Synchronized
        @Throws(BluePrintProcessorException::class)
        fun getPropertyType(raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String, propertyName: String): String {
            lateinit var type: String
            try {
                val dataTypeProps = checkNotNull(raRuntimeService.bluePrintContext().dataTypeByName(dataTypeName)?.properties)
                val propertyDefinition = checkNotNull(dataTypeProps[propertyName])
                type = returnNotEmptyOrThrow(propertyDefinition.type) { "Couldn't get data type ($dataTypeName)" }
                logger.trace("Data type({})'s property ({}) is ({})", dataTypeName, propertyName, type)
            } catch (e: Exception) {
                logger.error("couldn't get data type($dataTypeName)'s property ($propertyName), error message $e")
                throw BluePrintProcessorException("${e.message}", e)
            }
            return type
        }
    }
}