2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
18 package org.onap.dcae.runtime.web.service;
20 import org.onap.dcae.runtime.core.Edge;
21 import org.onap.dcae.runtime.core.FlowGraph;
22 import org.onap.dcae.runtime.core.FlowGraphParser;
23 import org.onap.dcae.runtime.core.FlowGraphParser.BlueprintVessel;
24 import org.onap.dcae.runtime.core.Node;
25 import org.onap.dcae.runtime.web.exception.MainGraphAlreadyExistException;
26 import org.onap.dcae.runtime.web.exception.MainGraphNotFoundException;
27 import org.onap.dcae.runtime.web.models.DistributeGraphRequest;
28 import org.onap.dcae.runtime.web.models.GraphRequest;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Service;
34 import java.util.List;
37 public class GraphServiceImpl implements GraphService{
40 BlueprintInventory blueprintInventory;
42 private FlowGraph<Node, Edge> mainFlowGraph;
44 Logger logger = LoggerFactory.getLogger(GraphServiceImpl.class);
47 private FlowGraphParser flowGraphParser;
50 private GraphActionsParser actionsParser;
53 public FlowGraph<Node, Edge> getMainGraph() {
54 if(mainFlowGraph == null){
55 throw new MainGraphNotFoundException();
61 public boolean initializeMainGraph(GraphRequest mainGraphRequest) {
62 if(mainFlowGraph != null){
63 throw new MainGraphAlreadyExistException("Can not initialize the main graph, it already exists");
65 mainFlowGraph = new FlowGraph<Node,Edge>(mainGraphRequest.getId(),mainGraphRequest.getName(),
66 true, mainGraphRequest.getDescription());
67 mainFlowGraph.addNode(getDummyNode());
68 flowGraphParser.parse(mainFlowGraph);
72 private Node getDummyNode() {
73 return new Node("dummy_id","dummy_name","dummy_compspec");
77 public List<BlueprintVessel> distribute(DistributeGraphRequest distributeGraphRequest) {
78 //1.Iterate through list of actions
79 logger.info("applying actions to graph");
80 actionsParser.applyActionsToGraph(mainFlowGraph, distributeGraphRequest);
82 //2. generate blueprint from compspec of the node
83 logger.info("generating blueprints for the affected nodes");
84 List<BlueprintVessel> blueprints = generateBlueprintsForAffectedNodes(distributeGraphRequest);
86 //3a. Push blueprints to the inventory
87 logger.info("pushing bluepirnts to the dashboard inventrory");
88 blueprintInventory.distributeToInventory(blueprints);
89 //3b. return blueprint map
94 public void deleteMainGraph() {
95 if(mainFlowGraph == null){
96 throw new MainGraphNotFoundException();
101 private List<BlueprintVessel> generateBlueprintsForAffectedNodes(DistributeGraphRequest distributeGraphRequest) {
102 return flowGraphParser.createAndProcessBlueprints();