Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / services / execution-service / src / main / kotlin / org / onap / ccsdk / apps / 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.apps.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.*
27
28 @Configuration
29 @ComponentScan
30 @EnableConfigurationProperties
31 open class PythonExecutorConfiguration
32
33 @Configuration
34 open class PythonExecutorProperty {
35     @Value("\${blueprints.processor.functions.python.executor.executionPath}")
36     lateinit var executionPath: String
37     @Value("#{'\${blueprints.processor.functions.python.executor.modulePaths}'.split(',')}")
38     lateinit var modulePaths: List<String>
39 }
40
41 class PythonExecutorConstants {
42     companion object {
43         const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies"
44     }
45 }
46
47 open class BluePrintPython(executablePath: String, blueprintPythonPlatform: MutableList<String>,
48                            val argv: MutableList<String>){
49     lateinit var moduleName: String
50     lateinit var pythonClassName: String
51     lateinit var content: String
52     var props: Properties = Properties()
53
54     init {
55         // Build up the python.path
56         val sb = StringBuilder()
57         sb.append(System.getProperty("java.class.path"))
58
59         for (p in blueprintPythonPlatform) {
60             sb.append(File.pathSeparator).append(p)
61         }
62
63         props["python.import.site"] = "true"
64         props.setProperty("python.path", sb.toString())
65         props.setProperty("python.verbose", "error")
66         props.setProperty("python.executable", executablePath)
67     }
68 }