aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Hautot <eh552t@intl.att.com>2019-03-13 09:07:55 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-13 09:07:55 +0000
commit5f59ddc97cf293bdb765a36326aaf26b47b71d5d (patch)
treec5d1868b30f5db23e4b6e1184443b3b8412c11f0
parent359d4e4f924a9310e940b312b6d0d911eca95b75 (diff)
parentd022281adea3da26beee6457767577a313c5b617 (diff)
Merge "Add svg support"
-rw-r--r--extra/sql/bulkload/create-tables.sql2
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java18
-rw-r--r--src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java42
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java2
-rw-r--r--src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java5
5 files changed, 49 insertions, 20 deletions
diff --git a/extra/sql/bulkload/create-tables.sql b/extra/sql/bulkload/create-tables.sql
index 93c80cb3..b3560635 100644
--- a/extra/sql/bulkload/create-tables.sql
+++ b/extra/sql/bulkload/create-tables.sql
@@ -23,7 +23,7 @@
global_properties_json json,
last_computed_state varchar(255) not null,
model_properties_json json,
- svg_representation varchar(255),
+ svg_representation MEDIUMTEXT,
primary key (name)
) engine=InnoDB;
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 b05b80f0..27c5b9cb 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<MicroService> getChainOfMicroServices(Set<MicroService> input) {
+ public List<MicroService> getChainOfMicroServices(Set<MicroService> input) {
LinkedList<MicroService> returnList = new LinkedList<>();
- if(preValidate(input)) {
+ if (preValidate(input)) {
LinkedList<MicroService> 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<MicroService> input) {
- List<MicroService> noInputs =
- input.stream().filter(ms -> "".equals(ms.getInputFrom())).collect(Collectors.toList());
+ List<MicroService> noInputs = input.stream().filter(ms -> "".equals(ms.getInputFrom()))
+ .collect(Collectors.toList());
return noInputs.size() == 1;
}
private boolean postValidate(LinkedList<MicroService> 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 6e12f294..07f1b777 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<MicroService> 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<MicroServicePolicy> createMicroServicePolicies(CsarHandler csar,
BlueprintArtifact blueprintArtifact, Loop newLoop) throws IOException {
HashSet<MicroServicePolicy> 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<MicroService> 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 a4cd86d0..473364ae 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
diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
index d1a4bdc5..afa07236 100644
--- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
+++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
@@ -170,7 +170,10 @@ public class CsarInstallerItCase {
// set
Loop loop = loopsRepo
.findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml")).get();
-
+ assertThat(loop.getSvgRepresentation()).startsWith("<svg ");
+ assertThat(loop.getGlobalPropertiesJson().get("dcaeDeployParameters")).isNotNull();
+ assertThat(loop.getMicroServicePolicies()).hasSize(1);
+ assertThat(loop.getOperationalPolicies()).hasSize(1);
assertThat(loop.getModelPropertiesJson().get("serviceDetails")).isNotNull();
assertThat(loop.getModelPropertiesJson().get("resourceDetails")).isNotNull();
}