From d022281adea3da26beee6457767577a313c5b617 Mon Sep 17 00:00:00 2001 From: sebdet Date: Tue, 12 Mar 2019 16:35:25 +0100 Subject: Add svg support Add SVG support to the CSAR installer so that UI could render the loop Issue-ID: CLAMP-306 Change-Id: Ief963c4ad8e4c142f20c16b2049cad3a8aeedfb0 Signed-off-by: sebdet --- .../sdc/controller/installer/ChainGenerator.java | 18 +++++----- .../org/onap/clamp/loop/CsarInstallerImpl.java | 42 +++++++++++++++++----- src/main/java/org/onap/clamp/loop/Loop.java | 2 +- 3 files changed, 44 insertions(+), 18 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java index b05b80f00..27c5b9cbd 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java @@ -26,21 +26,23 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.stream.Collectors; + import org.springframework.stereotype.Component; @Component public class ChainGenerator { - ChainGenerator() {} + ChainGenerator() { + } - List getChainOfMicroServices(Set input) { + public List getChainOfMicroServices(Set input) { LinkedList returnList = new LinkedList<>(); - if(preValidate(input)) { + if (preValidate(input)) { LinkedList theList = new LinkedList<>(); for (MicroService ms : input) { insertNodeTemplateIntoChain(ms, theList); } - if(postValidate(theList)) { + if (postValidate(theList)) { returnList = theList; } } @@ -48,16 +50,16 @@ public class ChainGenerator { } private boolean preValidate(Set input) { - List noInputs = - input.stream().filter(ms -> "".equals(ms.getInputFrom())).collect(Collectors.toList()); + List noInputs = input.stream().filter(ms -> "".equals(ms.getInputFrom())) + .collect(Collectors.toList()); return noInputs.size() == 1; } private boolean postValidate(LinkedList microServices) { for (int i = 1; i < microServices.size() - 1; i++) { - MicroService prev = microServices.get(i-1); + MicroService prev = microServices.get(i - 1); MicroService current = microServices.get(i); - if(!current.getInputFrom().equals(prev.getName())) { + if (!current.getInputFrom().equals(prev.getName())) { return false; } } diff --git a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java index 6e12f2940..07f1b777f 100644 --- a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java @@ -31,6 +31,7 @@ import com.google.gson.JsonObject; import java.io.IOException; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -46,6 +47,7 @@ import org.onap.clamp.clds.sdc.controller.installer.CsarHandler; import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; import org.onap.clamp.clds.sdc.controller.installer.MicroService; import org.onap.clamp.clds.util.JsonUtils; +import org.onap.clamp.clds.util.drawing.SvgFacade; import org.onap.clamp.policy.Policy; import org.onap.clamp.policy.microservice.MicroServicePolicy; import org.onap.clamp.policy.operational.OperationalPolicy; @@ -82,6 +84,9 @@ public class CsarInstallerImpl implements CsarInstaller { @Autowired DcaeInventoryServices dcaeInventoryService; + @Autowired + private SvgFacade svgFacade; + @Override public boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException { boolean alreadyInstalled = true; @@ -113,6 +118,16 @@ public class CsarInstallerImpl implements CsarInstaller { } } + private String getSvgInLoop(BlueprintArtifact blueprintArtifact) { + List microServicesChain = chainGenerator + .getChainOfMicroServices(blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint())); + if (microServicesChain.isEmpty()) { + microServicesChain = blueprintParser.fallbackToOneMicroService(blueprintArtifact.getDcaeBlueprint()); + } + return svgFacade.getSvgImage(microServicesChain); + + } + private Loop createLoopFromBlueprint(CsarHandler csar, BlueprintArtifact blueprintArtifact) throws IOException, ParseException, InterruptedException { Loop newLoop = new Loop(); @@ -124,10 +139,10 @@ public class CsarInstallerImpl implements CsarInstaller { newLoop.setLastComputedState(LoopState.DESIGN); newLoop.setMicroServicePolicies(createMicroServicePolicies(csar, blueprintArtifact, newLoop)); newLoop.setOperationalPolicies(createOperationalPolicies(csar, blueprintArtifact, newLoop)); - // Set SVG XML computed - // newLoop.setSvgRepresentation(svgRepresentation); - newLoop.setGlobalPropertiesJson(createGlobalPropertiesJson(csar, blueprintArtifact)); - newLoop.setModelPropertiesJson(createModelPropertiesJson(csar, blueprintArtifact)); + + newLoop.setSvgRepresentation(getSvgInLoop(blueprintArtifact)); + newLoop.setGlobalPropertiesJson(createGlobalPropertiesJson(blueprintArtifact)); + newLoop.setModelPropertiesJson(createModelPropertiesJson(csar)); DcaeInventoryResponse dcaeResponse = queryDcaeToGetServiceTypeId(blueprintArtifact); newLoop.setDcaeBlueprintId(dcaeResponse.getTypeId()); return newLoop; @@ -144,21 +159,30 @@ public class CsarInstallerImpl implements CsarInstaller { private HashSet createMicroServicePolicies(CsarHandler csar, BlueprintArtifact blueprintArtifact, Loop newLoop) throws IOException { HashSet newSet = new HashSet<>(); - for (MicroService microService : blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint())) { - newSet.add(new MicroServicePolicy(microService.getName(), csar.getPolicyModelYaml().orElse(""), false, - new HashSet<>(Arrays.asList(newLoop)))); + List microServicesChain = chainGenerator + .getChainOfMicroServices(blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint())); + if (microServicesChain.isEmpty()) { + microServicesChain = blueprintParser.fallbackToOneMicroService(blueprintArtifact.getDcaeBlueprint()); + } + for (MicroService microService : microServicesChain) { + newSet.add(new MicroServicePolicy( + Policy.generatePolicyName(microService.getName(), csar.getSdcNotification().getServiceName(), + csar.getSdcNotification().getServiceVersion(), + blueprintArtifact.getResourceAttached().getResourceInstanceName(), + blueprintArtifact.getBlueprintArtifactName()), + csar.getPolicyModelYaml().orElse(""), false, new HashSet<>(Arrays.asList(newLoop)))); } return newSet; } - private JsonObject createGlobalPropertiesJson(CsarHandler csar, BlueprintArtifact blueprintArtifact) { + private JsonObject createGlobalPropertiesJson(BlueprintArtifact blueprintArtifact) { JsonObject globalProperties = new JsonObject(); globalProperties.add("dcaeDeployParameters", getAllBlueprintParametersInJson(blueprintArtifact)); return globalProperties; } - private JsonObject createModelPropertiesJson(CsarHandler csar, BlueprintArtifact blueprintArtifact) { + private JsonObject createModelPropertiesJson(CsarHandler csar) { JsonObject modelProperties = new JsonObject(); Gson gson = new Gson(); modelProperties.add("serviceDetails", diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java index a4cd86d07..473364ae4 100644 --- a/src/main/java/org/onap/clamp/loop/Loop.java +++ b/src/main/java/org/onap/clamp/loop/Loop.java @@ -78,7 +78,7 @@ public class Loop implements Serializable { @Column(name = "dcae_blueprint_id") private String dcaeBlueprintId; - @Column(name = "svg_representation") + @Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation") private String svgRepresentation; @Expose -- cgit 1.2.3-korg