summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2019-03-14 16:31:25 +0100
committersebdet <sebastien.determe@intl.att.com>2019-03-14 16:55:14 +0100
commit493298b4191b37df7c752bdcc050c27dd6ea4c52 (patch)
treed26e6f1b9485d5aa8bb3cd3867f8998857a0def4 /src/main/java
parent4549fd92024cdadf3277d7cc364f33109ca22b59 (diff)
SVG microservice uniqueness
Add field to support uniqueness of the microservice in the SVG Issue-ID: CLAMP-284 Change-Id: Idbfe593374eecf6f180725ad5ae5b077020a9f14 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java5
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java75
-rwxr-xr-xsrc/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java16
-rwxr-xr-xsrc/main/java/org/onap/clamp/clds/util/drawing/Painter.java28
-rw-r--r--src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java6
-rw-r--r--src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java40
6 files changed, 90 insertions, 80 deletions
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java
index 542411b0..c8de4c58 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2019 AT&T
* ===================================================================
*
*/
@@ -84,7 +85,7 @@ public class BlueprintParser {
}
}
String msName = theBiggestMicroServiceKey.toLowerCase().contains(HOLMES_PREFIX) ? HOLMES : TCA;
- return Collections.singletonList(new MicroService(msName, ""));
+ return Collections.singletonList(new MicroService(msName, "", ""));
}
String getName(Entry<String, JsonElement> entry) {
@@ -116,7 +117,7 @@ public class BlueprintParser {
MicroService getNodeRepresentation(Entry<String, JsonElement> entry) {
String name = getName(entry);
String getInputFrom = getInput(entry);
- return new MicroService(name, getInputFrom);
+ return new MicroService(name, getInputFrom, "");
}
private String getTarget(JsonObject elementObject) {
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
index 287ac9a9..198bf0ed 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2019 AT&T
* ===================================================================
*
*/
@@ -25,44 +26,52 @@ package org.onap.clamp.clds.sdc.controller.installer;
import java.util.Objects;
public class MicroService {
- private final String name;
- private final String inputFrom;
+ private final String name;
+ private final String inputFrom;
+ private String mappedNameJpa;
- public MicroService(String name, String inputFrom) {
- this.name = name;
- this.inputFrom = inputFrom;
- }
- public String getName() {
- return name;
- }
+ public MicroService(String name, String inputFrom, String mappedNameJpa) {
+ this.name = name;
+ this.inputFrom = inputFrom;
+ this.mappedNameJpa = mappedNameJpa;
+ }
- public String getInputFrom() {
- return inputFrom;
- }
+ public String getName() {
+ return name;
+ }
- @Override
- public String toString() {
- return "MicroService{" +
- "name='" + name + '\'' +
- ", inputFrom='" + inputFrom + '\'' +
- '}';
- }
+ public String getInputFrom() {
+ return inputFrom;
+ }
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
+ @Override
+ public String toString() {
+ return "MicroService{" + "name='" + name + '\'' + ", inputFrom='" + inputFrom + '\'' + ", mappedNameJpa='"
+ + mappedNameJpa + '\'' + '}';
}
- if (o == null || getClass() != o.getClass()) {
- return false;
+
+ public String getMappedNameJpa() {
+ return mappedNameJpa;
}
- MicroService that = (MicroService) o;
- return name.equals(that.name) &&
- inputFrom.equals(that.inputFrom);
- }
- @Override
- public int hashCode() {
- return Objects.hash(name, inputFrom);
- }
+ public void setMappedNameJpa(String mappedNameJpa) {
+ this.mappedNameJpa = mappedNameJpa;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ MicroService that = (MicroService) o;
+ return name.equals(that.name) && inputFrom.equals(that.inputFrom) && mappedNameJpa.equals(that.mappedNameJpa);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, inputFrom, mappedNameJpa);
+ }
}
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
index 243cb4aa..ef4c4e43 100755
--- a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2019 AT&T
* ===================================================================
*
*/
@@ -27,10 +28,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import org.onap.clamp.clds.sdc.controller.installer.MicroService;
+
public class ClampGraphBuilder {
private String policy;
private String collector;
- private List<String> microServices = new ArrayList<>();
+ private List<MicroService> microServices = new ArrayList<>();
private final Painter painter;
public ClampGraphBuilder(Painter painter) {
@@ -47,16 +50,21 @@ public class ClampGraphBuilder {
return this;
}
- public ClampGraphBuilder microService(String ms) {
+ public ClampGraphBuilder addMicroService(MicroService ms) {
microServices.add(ms);
return this;
}
+ public ClampGraphBuilder addAllMicroServices(List<MicroService> msList) {
+ microServices.addAll(msList);
+ return this;
+ }
+
public ClampGraph build() {
- if(microServices.isEmpty()) {
+ if (microServices.isEmpty()) {
throw new InvalidStateException("At least one microservice is required");
}
- if(Objects.isNull(policy) || policy.trim().isEmpty()) {
+ if (Objects.isNull(policy) || policy.trim().isEmpty()) {
throw new InvalidStateException("Policy element must be present");
}
return new ClampGraph(painter.doPaint(collector, microServices, policy));
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
index e41ca8fb..6263f30b 100755
--- a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2019 AT&T
* ===================================================================
*
*/
@@ -28,7 +29,9 @@ import java.awt.Color;
import java.awt.Point;
import java.awt.RenderingHints;
import java.util.List;
+
import org.apache.batik.svggen.SVGGraphics2D;
+import org.onap.clamp.clds.sdc.controller.installer.MicroService;
public class Painter {
private final int canvasSize;
@@ -47,7 +50,7 @@ public class Painter {
this.canvasSize = DEFALUT_CANVAS_SIZE;
}
- DocumentBuilder doPaint(String collector, List<String> microServices, String policy) {
+ DocumentBuilder doPaint(String collector, List<MicroService> microServices, String policy) {
int numOfRectangles = 2 + microServices.size();
int numOfArrows = numOfRectangles + 1;
int baseLength = (canvasSize - 2 * CIRCLE_RADIUS) / (numOfArrows + numOfRectangles);
@@ -63,29 +66,22 @@ public class Painter {
return ib.getDocumentBuilder();
}
- private void doTheActualDrawing(String collector, List<String> microServices, String policy, ImageBuilder ib) {
- ib.circle("start-circle", SLIM_LINE)
- .arrow()
- .rectangle(collector, RectTypes.COLECTOR, collector);
+ private void doTheActualDrawing(String collector, List<MicroService> microServices, String policy,
+ ImageBuilder ib) {
+ ib.circle("start-circle", SLIM_LINE).arrow().rectangle(collector, RectTypes.COLECTOR, collector);
- for(String ms : microServices) {
- ib.arrow().rectangle(ms, RectTypes.MICROSERVICE, ms);
+ for (MicroService ms : microServices) {
+ ib.arrow().rectangle(ms.getMappedNameJpa(), RectTypes.MICROSERVICE, ms.getName());
}
- ib.arrow()
- .rectangle(policy, RectTypes.POLICY, policy)
- .arrow()
- .circle("stop-circle", THICK_LINE);
+ ib.arrow().rectangle(policy, RectTypes.POLICY, policy).arrow().circle("stop-circle", THICK_LINE);
}
private void adjustGraphics2DProperties() {
- g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
- RenderingHints.VALUE_FRACTIONALMETRICS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
+ g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+ g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
g2d.setStroke(new BasicStroke(SLIM_LINE));
g2d.setPaint(Color.BLACK);
}
-
}
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java b/src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java
index 0ba84863..f5bd6e79 100644
--- a/src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2019 AT&T
* ===================================================================
*
*/
@@ -24,6 +25,7 @@
package org.onap.clamp.clds.util.drawing;
import java.util.List;
+
import org.apache.batik.svggen.SVGGraphics2D;
import org.onap.clamp.clds.sdc.controller.installer.MicroService;
import org.onap.clamp.clds.util.XmlTools;
@@ -38,9 +40,7 @@ public class SvgFacade {
DocumentBuilder dp = new DocumentBuilder(document, svgGraphics2D.getDOMFactory());
Painter p = new Painter(svgGraphics2D, dp);
ClampGraphBuilder cgp = new ClampGraphBuilder(p).collector("VES");
- for(MicroService ms : microServicesChain) {
- cgp = cgp.microService(ms.getName());
- }
+ cgp.addAllMicroServices(microServicesChain);
ClampGraph cg = cgp.policy("Policy").build();
return cg.getAsSVG();
}
diff --git a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java
index 07f1b777..65052888 100644
--- a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java
+++ b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java
@@ -118,16 +118,6 @@ 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();
@@ -137,10 +127,18 @@ public class CsarInstallerImpl implements CsarInstaller {
blueprintArtifact.getResourceAttached().getResourceInstanceName(),
blueprintArtifact.getBlueprintArtifactName()));
newLoop.setLastComputedState(LoopState.DESIGN);
- newLoop.setMicroServicePolicies(createMicroServicePolicies(csar, blueprintArtifact, newLoop));
+
+ List<MicroService> microServicesChain = chainGenerator
+ .getChainOfMicroServices(blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint()));
+ if (microServicesChain.isEmpty()) {
+ microServicesChain = blueprintParser.fallbackToOneMicroService(blueprintArtifact.getDcaeBlueprint());
+ }
+
+ newLoop
+ .setMicroServicePolicies(createMicroServicePolicies(microServicesChain, csar, blueprintArtifact, newLoop));
newLoop.setOperationalPolicies(createOperationalPolicies(csar, blueprintArtifact, newLoop));
- newLoop.setSvgRepresentation(getSvgInLoop(blueprintArtifact));
+ newLoop.setSvgRepresentation(svgFacade.getSvgImage(microServicesChain));
newLoop.setGlobalPropertiesJson(createGlobalPropertiesJson(blueprintArtifact));
newLoop.setModelPropertiesJson(createModelPropertiesJson(csar));
DcaeInventoryResponse dcaeResponse = queryDcaeToGetServiceTypeId(blueprintArtifact);
@@ -156,21 +154,20 @@ public class CsarInstallerImpl implements CsarInstaller {
blueprintArtifact.getBlueprintArtifactName()), newLoop, new JsonObject())));
}
- private HashSet<MicroServicePolicy> createMicroServicePolicies(CsarHandler csar,
- BlueprintArtifact blueprintArtifact, Loop newLoop) throws IOException {
+ private HashSet<MicroServicePolicy> createMicroServicePolicies(List<MicroService> microServicesChain,
+ CsarHandler csar, BlueprintArtifact blueprintArtifact, Loop newLoop) throws IOException {
HashSet<MicroServicePolicy> newSet = new HashSet<>();
- 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(
+ MicroServicePolicy microServicePolicy = 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))));
+ csar.getPolicyModelYaml().orElse(""), false, new HashSet<>(Arrays.asList(newLoop)));
+
+ newSet.add(microServicePolicy);
+ microService.setMappedNameJpa(microServicePolicy.getName());
}
return newSet;
}
@@ -179,7 +176,6 @@ public class CsarInstallerImpl implements CsarInstaller {
JsonObject globalProperties = new JsonObject();
globalProperties.add("dcaeDeployParameters", getAllBlueprintParametersInJson(blueprintArtifact));
return globalProperties;
-
}
private JsonObject createModelPropertiesJson(CsarHandler csar) {