993f10eef7bee90fa210c67cdce37eb4a924f29b
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow
18
19 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
20 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput
21 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.utils.SvcGraphUtils
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
23 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
24 import org.slf4j.LoggerFactory
25 import org.springframework.stereotype.Service
26 import java.io.File
27
28
29 interface BlueprintDGExecutionService {
30
31     fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>,
32                              executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput
33
34 }
35
36 @Service
37 class DefaultBlueprintDGExecutionService(val blueprintSvcLogicService: BlueprintSvcLogicService) : BlueprintDGExecutionService {
38
39     private val log = LoggerFactory.getLogger(DefaultBlueprintDGExecutionService::class.java)
40
41     override fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>,
42                                       executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
43
44         val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
45
46         val workflowName = executionServiceInput.actionIdentifiers.actionName
47
48         // Get the DG Node Template
49         val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName)
50
51         log.info("Executing workflow($workflowName) directed graph NodeTemplate($nodeTemplateName)")
52
53         // Get the DG file info
54         val artifactDefinition = bluePrintContext.nodeTemplateArtifactForArtifactType(nodeTemplateName,
55                 WorkflowServiceConstants.ARTIFACT_TYPE_DIRECTED_GRAPH)
56
57         // Populate the DG Path
58         val dgFilePath = bluePrintRuntimeService.getAsString(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
59                 .plus(File.separator).plus(artifactDefinition.file)
60
61         log.info("Executing directed graph ($dgFilePath)")
62
63         // Create DG instance
64         val graph = SvcGraphUtils.getSvcGraphFromFile(dgFilePath)
65
66         // Execute the DG
67         return blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput) as ExecutionServiceOutput
68
69     }
70
71 }