9bb562b76270aa1c08f317e2a7df960928bdc775
[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.service.BluePrintRuntimeService
23 import org.slf4j.LoggerFactory
24 import org.springframework.stereotype.Service
25 import java.io.File
26
27
28 interface BlueprintDGExecutionService {
29
30     fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>,
31                              executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput
32
33 }
34
35 @Service
36 class DefaultBlueprintDGExecutionService(val blueprintSvcLogicService: BlueprintSvcLogicService) : BlueprintDGExecutionService {
37
38     private val log = LoggerFactory.getLogger(DefaultBlueprintDGExecutionService::class.java)
39
40     override fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>,
41                                       executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
42
43         val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
44
45         val workflowName = executionServiceInput.actionIdentifiers.actionName
46
47         // Get the DG Node Template
48         val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName)
49
50         log.info("Executing workflow($workflowName) directed graph NodeTemplate($nodeTemplateName)")
51
52         // Get the DG file info
53         val artifactDefinition = bluePrintContext.nodeTemplateArtifactForArtifactType(nodeTemplateName,
54                 WorkflowServiceConstants.ARTIFACT_TYPE_DIRECTED_GRAPH)
55
56         // Populate the DG Path
57         val dgFilePath = bluePrintContext.rootPath.plus(File.separator).plus(artifactDefinition.file)
58
59         log.info("Executing directed graph ($dgFilePath)")
60
61         // Create DG instance
62         val graph = SvcGraphUtils.getSvcGraphFromFile(dgFilePath)
63
64         // Assign Workflow inputs
65         val input = executionServiceInput.payload.get("$workflowName-request")
66         bluePrintRuntimeService.assignWorkflowInputs(workflowName, input)
67
68         // Execute the DG
69         return blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput) as ExecutionServiceOutput
70
71     }
72
73 }