0a220948d0b7cc378c8999ab926e22af76ca1997
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / services / execution-service / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / services / execution / scripts / PythonExecutorConfiguration.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Modifications Copyright © 2019 IBM, Bell Canada.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts
20
21 import org.springframework.beans.factory.annotation.Value
22 import org.springframework.boot.context.properties.EnableConfigurationProperties
23 import org.springframework.context.annotation.ComponentScan
24 import org.springframework.context.annotation.Configuration
25 import java.io.File
26 import java.util.Properties
27
28 @Configuration
29 @ComponentScan
30 @EnableConfigurationProperties
31 open class PythonExecutorConfiguration
32
33 @Configuration
34 open class PythonExecutorProperty {
35
36     @Value("\${blueprints.processor.functions.python.executor.executionPath}")
37     lateinit var executionPath: String
38     @Value("#{'\${blueprints.processor.functions.python.executor.modulePaths}'.split(',')}")
39     lateinit var modulePaths: List<String>
40 }
41
42 class PythonExecutorConstants {
43     companion object {
44         const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies"
45     }
46 }
47
48 open class BluePrintPython(
49     executablePath: String,
50     blueprintPythonPlatform: MutableList<String>,
51     val argv: MutableList<String>
52 ) {
53
54     lateinit var moduleName: String
55     lateinit var pythonClassName: String
56     lateinit var content: String
57     var props: Properties = Properties()
58
59     init {
60         // Build up the python.path
61         val sb = StringBuilder()
62         sb.append(System.getProperty("java.class.path"))
63
64         for (p in blueprintPythonPlatform) {
65             sb.append(File.pathSeparator).append(p)
66         }
67
68         props["python.import.site"] = "true"
69         props.setProperty("python.path", sb.toString())
70         props.setProperty("python.verbose", "error")
71         props.setProperty("python.executable", executablePath)
72     }
73 }