summaryrefslogtreecommitdiffstats
path: root/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java')
-rw-r--r--mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java66
1 files changed, 9 insertions, 57 deletions
diff --git a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java
index f1329c1..94d4b40 100644
--- a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java
+++ b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/GraphServiceImpl.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,15 +17,15 @@
*/
package org.onap.dcae.runtime.web.service;
-import org.onap.dcae.runtime.core.*;
+import org.onap.dcae.runtime.core.Edge;
+import org.onap.dcae.runtime.core.FlowGraph;
+import org.onap.dcae.runtime.core.FlowGraphParser;
import org.onap.dcae.runtime.core.FlowGraphParser.BlueprintVessel;
-import org.onap.dcae.runtime.web.exception.ActionsNotDefinedException;
+import org.onap.dcae.runtime.core.Node;
import org.onap.dcae.runtime.web.exception.MainGraphAlreadyExistException;
import org.onap.dcae.runtime.web.exception.MainGraphNotFoundException;
-import org.onap.dcae.runtime.web.models.Action;
import org.onap.dcae.runtime.web.models.DistributeGraphRequest;
import org.onap.dcae.runtime.web.models.GraphRequest;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,6 +46,9 @@ public class GraphServiceImpl implements GraphService{
@Autowired
private FlowGraphParser flowGraphParser;
+ @Autowired
+ private GraphActionsParser actionsParser;
+
@Override
public FlowGraph<Node, Edge> getMainGraph() {
if(mainFlowGraph == null){
@@ -74,7 +77,7 @@ public class GraphServiceImpl implements GraphService{
public List<BlueprintVessel> distribute(DistributeGraphRequest distributeGraphRequest) {
//1.Iterate through list of actions
logger.info("applying actions to graph");
- applyActionsToGraph(distributeGraphRequest);
+ actionsParser.applyActionsToGraph(mainFlowGraph, distributeGraphRequest);
//2. generate blueprint from compspec of the node
logger.info("generating blueprints for the affected nodes");
@@ -99,56 +102,5 @@ public class GraphServiceImpl implements GraphService{
return flowGraphParser.createAndProcessBlueprints();
}
- private void applyActionsToGraph(DistributeGraphRequest distributeGraphRequest) {
- if(distributeGraphRequest.getActions() == null){
- throw new ActionsNotDefinedException("Action(s) must be defined in the request");
- }
- for(Action action : distributeGraphRequest.getActions()){
- if(action.getCommand().equals("addnode")){
- Node node = prepareNodeFromAddNAddNodeAction(action);
- mainFlowGraph.addNode(node);
- }
- else if(action.getCommand().equals("addedge")) {
- Edge edge = prepareEdgeFromAddEdgeAction(action);
- Node srcNode = flowGraphParser.getNodeFromId(edge.getSrc().getNode());
- Node tgtNode = flowGraphParser.getNodeFromId(edge.getTgt().getNode());
- srcNode = fillPlaceholderIfNodeIsEmpty(srcNode);
- tgtNode =fillPlaceholderIfNodeIsEmpty(tgtNode);
- mainFlowGraph.addEdge(srcNode,tgtNode,edge);
- }
- }
- }
-
- private Node fillPlaceholderIfNodeIsEmpty(Node node) {
- if (node == null) {
- node = flowGraphParser.getNodeFromId("dummy_id");
- }
- return node;
- }
-
-
- private Edge prepareEdgeFromAddEdgeAction(Action action) {
- ObjectMapper objectMapper = new ObjectMapper();
- Edge edge = objectMapper.convertValue(action.getPayload(),Edge.class);
- return edge;
- }
-
- private void fillPlaceholderIfLocaionsAreEmpty(Edge edge) {
- if(edge.getSrc().getNode() == null && edge.getSrc().getPort() == null){
- EdgeLocation src = new EdgeLocation("node-id-placeholder", "node-port-placeholder");
- edge.setSrc(src);
- }
- if(edge.getTgt().getNode() == null && edge.getTgt().getPort() == null){
- EdgeLocation tgt = new EdgeLocation("node-id-placeholder", "node-port-placeholder");
- edge.setTgt(tgt);
- }
- }
-
- private Node prepareNodeFromAddNAddNodeAction(Action action) {
- String componentId = (String) action.getPayload().get("component_id");
- String componentName = (String) action.getPayload().get("name");
- String componentSpec = (String) action.getPayload().get("component_spec");
- return new Node(componentId,componentName,componentSpec);
- }
}