summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt6
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt2
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt105
-rw-r--r--ms/command-executor/src/main/python/command_executor_handler.py36
4 files changed, 59 insertions, 90 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
index a0fa97b6d..2640b5b85 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
@@ -107,7 +107,7 @@ open class DatabaseResourceAssignmentProcessor(
"DatabaseResource ($dSource) dictionary information: " +
"Query:($sql), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})"
)
- val jdbcTemplate = blueprintDBLibService(sourceProperties)
+ val jdbcTemplate = blueprintDBLibService(sourceProperties, dSource)
val rows = jdbcTemplate.query(sql, populateNamedParameter(inputKeyMapping))
if (rows.isNullOrEmpty()) {
@@ -117,12 +117,12 @@ open class DatabaseResourceAssignmentProcessor(
}
}
- private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): BluePrintDBLibGenericService {
+ private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource, selector: String): BluePrintDBLibGenericService {
return if (isNotEmpty(sourceProperties.endpointSelector)) {
val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!)
bluePrintDBLibPropertyService.JdbcTemplate(dbPropertiesJson)
} else {
- primaryDBLibGenericService
+ bluePrintDBLibPropertyService.JdbcTemplate(selector)
}
}
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
index 0d737f4ca..637031972 100644
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
@@ -66,7 +66,7 @@ class DBLibConstants {
// list of database
const val MARIA_DB: String = "maria-db"
- const val PRIMARY_DB: String = "processor-db"
+ const val PROCESSOR_DB: String = "processor-db"
const val MYSQL_DB: String = "mysql-db"
const val ORACLE_DB: String = "oracle-db"
const val POSTGRES_DB: String = "postgres-db"
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt
index 35baf9314..e686e8396 100644
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt
@@ -20,10 +20,11 @@ import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService
import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService
import org.onap.ccsdk.cds.blueprintsprocessor.db.DBDataSourceProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.MARIA_DB
+import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.MYSQL_DB
+import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.PROCESSOR_DB
import org.onap.ccsdk.cds.blueprintsprocessor.db.MariaDataSourceProperties
import org.onap.ccsdk.cds.blueprintsprocessor.db.MySqlDataSourceProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.springframework.stereotype.Service
@@ -31,79 +32,45 @@ import org.springframework.stereotype.Service
@Service
class BluePrintDBLibPropertyService(private var bluePrintPropertiesService: BluePrintPropertiesService) {
- fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService {
- val dBConnetionProperties = dBDataSourceProperties(jsonNode)
- return blueprintDBDataSourceService(dBConnetionProperties)
- }
+ fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService =
+ blueprintDBDataSourceService(dBDataSourceProperties(jsonNode))
- fun JdbcTemplate(selector: String): BluePrintDBLibGenericService {
- val prefix = "blueprintsprocessor.db.$selector"
- val dBConnetionProperties = dBDataSourceProperties(prefix)
- return blueprintDBDataSourceService(dBConnetionProperties)
- }
+ fun JdbcTemplate(selector: String): BluePrintDBLibGenericService =
+ blueprintDBDataSourceService(dBDataSourceProperties("blueprintsprocessor.db.$selector"))
- private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties {
- val type = jsonNode.get("type").textValue()
- return when (type) {
- DBLibConstants.MYSQL_DB -> {
- JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java)!!
- }
- DBLibConstants.MARIA_DB -> {
- JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java)!!
- }
- else -> {
- throw BluePrintProcessorException("Rest adaptor($type) is not supported")
- }
- }
- }
+ private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties =
+ when (val type = jsonNode.get("type").textValue()) {
+ MYSQL_DB -> JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java)
+ MARIA_DB -> JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java)
+ else -> {
+ throw BluePrintProcessorException(
+ "DB type ($type) is not supported. Valid types: $MARIA_DB, $MYSQL_DB")
+ }
+ }!!
- private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties {
- val type = bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java)
- return when (type) {
- DBLibConstants.MARIA_DB -> {
- mariaDBConnectionProperties(prefix)
- }
- DBLibConstants.MYSQL_DB -> {
- mySqlDBConnectionProperties(prefix)
- }
- DBLibConstants.ORACLE_DB -> {
- TODO("not implemented")
- }
- DBLibConstants.POSTGRES_DB -> {
- TODO("not implemented")
+ private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties =
+ bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java).let {
+ return when (it) {
+ MARIA_DB, PROCESSOR_DB -> mariaDBConnectionProperties(prefix)
+ MYSQL_DB -> mySqlDBConnectionProperties(prefix)
+ else -> {
+ throw BluePrintProcessorException(
+ "DB type ($it) is not supported. Valid types: $MARIA_DB, $MYSQL_DB, $PROCESSOR_DB")
+ }
+ }
}
- DBLibConstants.PRIMARY_DB -> {
- primaryDBConnectionProperties(prefix)
- }
- else -> {
- throw BluePrintProcessorException("Rest adaptor($type) is not supported")
- }
- }
- }
- private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService {
- when (dBConnetionProperties) {
- is MariaDataSourceProperties -> {
- return MariaDatabaseConfiguration(dBConnetionProperties)
- }
- is MySqlDataSourceProperties -> {
- return MySqlDatabaseConfiguration(dBConnetionProperties)
+ private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService =
+ when (dBConnetionProperties) {
+ is MariaDataSourceProperties -> MariaDatabaseConfiguration(dBConnetionProperties)
+ is MySqlDataSourceProperties -> MySqlDatabaseConfiguration(dBConnetionProperties)
+ else -> throw BluePrintProcessorException(
+ "Failed to create db configuration for ${dBConnetionProperties.url}")
}
- else -> {
- throw BluePrintProcessorException("couldn't get rest service for")
- }
- }
- }
-
- private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties {
- return bluePrintPropertiesService.propertyBeanType(prefix, MySqlDataSourceProperties::class.java)
- }
- private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties {
- return bluePrintPropertiesService.propertyBeanType(prefix, MariaDataSourceProperties::class.java)
- }
+ private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties =
+ bluePrintPropertiesService.propertyBeanType(prefix, MySqlDataSourceProperties::class.java)
- private fun primaryDBConnectionProperties(prefix: String): PrimaryDataSourceProperties {
- return bluePrintPropertiesService.propertyBeanType(prefix, PrimaryDataSourceProperties::class.java)
- }
+ private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties =
+ bluePrintPropertiesService.propertyBeanType(prefix, MariaDataSourceProperties::class.java)
}
diff --git a/ms/command-executor/src/main/python/command_executor_handler.py b/ms/command-executor/src/main/python/command_executor_handler.py
index 9d41b2c7b..1e6f03b81 100644
--- a/ms/command-executor/src/main/python/command_executor_handler.py
+++ b/ms/command-executor/src/main/python/command_executor_handler.py
@@ -31,7 +31,7 @@ import json
REQUIREMENTS_TXT = "requirements.txt"
-class CommandExecutorHandler:
+class CommandExecutorHandler():
def __init__(self, request):
self.request = request
@@ -58,12 +58,12 @@ class CommandExecutorHandler:
return utils.build_ret_data(False, err_msg)
try:
with open(self.installed, "w+") as f:
- if not self.install_packages(request, CommandExecutor_pb2.pip, f, results):
- return utils.build_ret_data(False, "ERROR: failed to prepare environment for request {} during pip package install.".format(self.blueprint_id))
- f.write("\r\n") # TODO: is \r needed?
- results.append("\n")
- if not self.install_packages(request, CommandExecutor_pb2.ansible_galaxy, f, results):
- return utils.build_ret_data(False, "ERROR: failed to prepare environment for request {} during Ansible install.".format(self.blueprint_id))
+ if not self.install_packages(request, CommandExecutor_pb2.pip, f, results):
+ return utils.build_ret_data(False, "ERROR: failed to prepare environment for request {} during pip package install.".format(self.blueprint_id))
+ f.write("\r\n") # TODO: is \r needed?
+ results.append("\n")
+ if not self.install_packages(request, CommandExecutor_pb2.ansible_galaxy, f, results):
+ return utils.build_ret_data(False, "ERROR: failed to prepare environment for request {} during Ansible install.".format(self.blueprint_id))
except Exception as ex:
err_msg = "ERROR: failed to prepare environment for request {} during installing packages. Exception: {}".format(self.blueprint_id, ex)
self.logger.error(err_msg)
@@ -71,7 +71,7 @@ class CommandExecutorHandler:
else:
try:
with open(self.installed, "r") as f:
- results.append(f.read())
+ results.append(f.read())
except Exception as ex:
return utils.build_ret_data(False, "ERROR: failed to prepare environment during reading 'installed' file {}. Exception: {}".format(self.installed, ex))
@@ -108,15 +108,14 @@ class CommandExecutorHandler:
payload_section = []
is_payload_section = False
- ### extract the original header request into sys-env variables
- ### RequestID
- request_id = request.requestId
- ### Sub-requestID
- subrequest_id = request.correlationId
- request_id_map = {'CDS_REQUEST_ID':request_id, 'CDS_CORRELATION_ID':subrequest_id}
- updated_env = { **os.environ, **request_id_map }
+ ### extract the original header request into sys-env variables
+ ### RequestID
+ request_id = request.requestId
+ ### Sub-requestID
+ subrequest_id = request.correlationId
+ request_id_map = {'CDS_REQUEST_ID':request_id, 'CDS_CORRELATION_ID':subrequest_id}
+ updated_env = { **os.environ, **request_id_map }
- try:
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
shell=True, bufsize=1, universal_newlines=True, env=updated_env) as newProcess:
while True:
@@ -190,9 +189,11 @@ class CommandExecutorHandler:
try:
results.append(subprocess.run(command, check=True, stdout=PIPE, stderr=PIPE, env=env).stdout.decode())
results.append("\n")
+ self.logger.info("install_python_packages {} succeeded".format(package))
return True
except CalledProcessError as e:
results.append(e.stderr.decode())
+ self.logger.error("install_python_packages {} failed".format(package))
return False
def install_ansible_packages(self, package, results):
@@ -224,6 +225,7 @@ class CommandExecutorHandler:
# venv doesn't populate the activate_this.py script, hence we use from virtualenv
venv.create(self.venv_home, with_pip=True, system_site_packages=True)
virtualenv.writefile(os.path.join(bin_dir, "activate_this.py"), virtualenv.ACTIVATE_THIS)
+ self.logger.info("{} - Creation of Python Virtual Environment finished.".format(self.blueprint_id))
return utils.build_ret_data(True, "")
except Exception as err:
err_msg = "{} - Failed to provision Python Virtual Environment. Error: {}".format(self.blueprint_id, err)
@@ -243,7 +245,7 @@ class CommandExecutorHandler:
path = "%s/bin/activate_this.py" % self.venv_home
try:
with open(path) as activate_this_script:
- exec (activate_this_script.read(), {'__file__': path})
+ exec (activate_this_script.read(), {'__file__': path})
exec (fixpathenvvar)
self.logger.info("Running with PATH : {}".format(os.environ['PATH']))
return utils.build_ret_data(True, "")