2 * Copyright © 2017-2018 AT&T Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow
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
28 interface BlueprintDGExecutionService {
30 fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>,
31 executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput
36 class DefaultBlueprintDGExecutionService(val blueprintSvcLogicService: BlueprintSvcLogicService) : BlueprintDGExecutionService {
38 private val log = LoggerFactory.getLogger(DefaultBlueprintDGExecutionService::class.java)
40 override fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>,
41 executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
43 val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
45 val workflowName = executionServiceInput.actionIdentifiers.actionName
47 // Get the DG Node Template
48 val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName)
50 log.info("Executing workflow($workflowName) directed graph NodeTemplate($nodeTemplateName)")
52 // Get the DG file info
53 val artifactDefinition = bluePrintContext.nodeTemplateArtifactForArtifactType(nodeTemplateName,
54 WorkflowServiceConstants.ARTIFACT_TYPE_DIRECTED_GRAPH)
56 // Populate the DG Path
57 val dgFilePath = bluePrintContext.rootPath.plus(File.separator).plus(artifactDefinition.file)
59 log.info("Executing directed graph ($dgFilePath)")
62 val graph = SvcGraphUtils.getSvcGraphFromFile(dgFilePath)
64 // Assign Workflow inputs
65 val input = executionServiceInput.payload.get("$workflowName-request")
66 bluePrintRuntimeService.assignWorkflowInputs(workflowName, input)
69 return blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput) as ExecutionServiceOutput