diff options
author | serena.spinoso <serena.spinoso@polito.it> | 2018-04-26 14:19:16 +0200 |
---|---|---|
committer | serena.spinoso <serena.spinoso@polito.it> | 2018-04-26 14:39:01 +0200 |
commit | fcda9807cfa6a89d691877126b406c5d3909d9b9 (patch) | |
tree | 46fcec15887a0e0722217c26606e1859c8c10ff6 /verigraph/src/it/polito/verigraph/grpc/server/GrpcUtils.java | |
parent | 320ca9e335797f2081f253df60a860e72b6cc9fb (diff) |
Support TOSCA in verigraph (gRPC service)
JIRA: PARSER-179
Add TOSCA service description in gRPC server.
Add a TOSCA-based client to use the new functionality.
Add a JUnit class for testing gRPC service with TOSCA descriptor
Change-Id: Id3217a674f076714cd48e3b7e4236e7445d89cd2
Signed-off-by: serena.spinoso <serena.spinoso@polito.it>
Diffstat (limited to 'verigraph/src/it/polito/verigraph/grpc/server/GrpcUtils.java')
-rw-r--r-- | verigraph/src/it/polito/verigraph/grpc/server/GrpcUtils.java | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/verigraph/src/it/polito/verigraph/grpc/server/GrpcUtils.java b/verigraph/src/it/polito/verigraph/grpc/server/GrpcUtils.java index 43859db..96c52a5 100644 --- a/verigraph/src/it/polito/verigraph/grpc/server/GrpcUtils.java +++ b/verigraph/src/it/polito/verigraph/grpc/server/GrpcUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 Politecnico di Torino and others. + * Copyright (c) 2017/18 Politecnico di Torino and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Apache License, Version 2.0 @@ -12,16 +12,18 @@ import java.io.IOException; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Splitter; + import it.polito.verigraph.grpc.ConfigurationGrpc; import it.polito.verigraph.grpc.GraphGrpc; import it.polito.verigraph.grpc.NeighbourGrpc; import it.polito.verigraph.grpc.NodeGrpc; +import it.polito.verigraph.grpc.NodeGrpc.FunctionalType; import it.polito.verigraph.grpc.TestGrpc; import it.polito.verigraph.grpc.VerificationGrpc; -import it.polito.verigraph.grpc.NodeGrpc.FunctionalType; import it.polito.verigraph.model.Configuration; import it.polito.verigraph.model.Graph; import it.polito.verigraph.model.Neighbour; @@ -29,6 +31,7 @@ import it.polito.verigraph.model.Node; import it.polito.verigraph.model.Test; import it.polito.verigraph.model.Verification; + public class GrpcUtils { private static final Logger logger = Logger.getLogger(GrpcUtils.class.getName()); @@ -43,6 +46,7 @@ public class GrpcUtils { //id is not present Neighbour ne = new Neighbour(); ne.setName(request.getName()); + ne.setId(request.getId()); return ne; } @@ -86,13 +90,17 @@ public class GrpcUtils { } public static Node deriveNode(NodeGrpc request) { - //id is not present + //id is not present Node node = new Node(); node.setName(request.getName()); node.setFunctional_type(request.getFunctionalType().toString()); Configuration conf = deriveConfiguration(request.getConfiguration()); node.setConfiguration(conf); + //Modification for Tosca CLI + Long id = request.getId(); + if( id != null) node.setId(request.getId()); + Map<Long,Neighbour> neighours = node.getNeighbours(); long i = 1; for(NeighbourGrpc neighbour:request.getNeighbourList()){ @@ -106,7 +114,7 @@ public class GrpcUtils { public static GraphGrpc obtainGraph(Graph graph){ GraphGrpc.Builder gr = GraphGrpc.newBuilder(); gr.setId(graph.getId()); - for(Node node:graph.getNodes().values()){ + for(Node node : graph.getNodes().values()){ NodeGrpc ng = obtainNode(node); gr.addNode(ng); } @@ -116,14 +124,16 @@ public class GrpcUtils { public static Graph deriveGraph(GraphGrpc request) { //id is not present Graph graph = new Graph(); - + //Modification for Tosca CLI + Long id = request.getId(); + if( id != null) graph.setId(request.getId()); + long i=1; Map<Long, Node> nodes= graph.getNodes(); for(NodeGrpc node:request.getNodeList()){ Node ng = deriveNode(node); - nodes.put(i++, ng); + nodes.put(i++, ng); } - return graph; } @@ -142,12 +152,13 @@ public class GrpcUtils { return ver.build(); } - /**Intended for string that begins with "?" - * */ + + /** Intended for string that begins with "?" */ public static Map<String,String> getParamGivenString(String str){ String string = str.substring(1); final Map<String, String> map = Splitter.on('&').trimResults().withKeyValueSeparator("="). split(string); return map; } + } |