From de5cdfc6343653056e35c0c528959dda1cc52c4b Mon Sep 17 00:00:00 2001 From: Tomasz Wrobel Date: Wed, 30 Sep 2020 13:23:35 +0200 Subject: Refactor ResourceConfig class Issue-ID: DCAEGEN2-2449 Signed-off-by: Tomasz Wrobel Change-Id: If47d76966937f7aeb90e054974130e8850f37343 --- .../models/blueprint/ResourceConfig.java | 116 +++++++++++---------- 1 file changed, 62 insertions(+), 54 deletions(-) (limited to 'mod/bpgenerator/src') diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java index f750178..030374f 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java @@ -21,7 +21,7 @@ package org.onap.blueprintgenerator.models.blueprint; -import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createInputValue; +import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createStringInput; import java.util.LinkedHashMap; import java.util.TreeMap; @@ -34,86 +34,94 @@ import lombok.Setter; //TODO: Auto-generated Javadoc /* (non-Javadoc) -* @see java.lang.Object#toString() -*/ -@Getter @Setter + * @see java.lang.Object#toString() + */ +@Getter +@Setter /* (non-Javadoc) -* @see java.lang.Object#toString() -*/ + * @see java.lang.Object#toString() + */ @Builder /** -* Instantiates a new resource config obj. -*/ + * Instantiates a new resource config obj. + */ @NoArgsConstructor /** -* Instantiates a new resource config obj. -* -* @param limits the limits -* @param requests the requests -*/ + * Instantiates a new resource config obj. + * + * @param limits the limits + * @param requests the requests + */ @AllArgsConstructor public class ResourceConfig { - /** The limits. */ - private TreeMap limits; + /** + * The limits. + */ + private TreeMap limits; + + /** + * The requests. + */ + private TreeMap requests; - /** The requests. */ - private TreeMap requests; + /** + * Creates the resource config. + * + * @param inps the inps + * @param name the name + * @return the tree map + */ + public TreeMap> createResourceConfig( + TreeMap> inps, String name) { - /** - * Creates the resource config. - * - * @param inps the inps - * @param name the name - * @return the tree map - */ - public TreeMap> createResourceConfig(TreeMap> inps, String name){ + LinkedHashMap memoryLimit = createStringInput("128Mi"); + LinkedHashMap cpuLimit = createStringInput("250m"); - LinkedHashMap memoryLimit = createInputValue("string", "", "128Mi"); - LinkedHashMap cpuLimit = createInputValue("string", "", "250m"); + String namePrefix = getNamePrefix(name); - if(!name.equals("")) { - name = name + "_"; - } + //set the limits + TreeMap limits = new TreeMap<>(); - //set the limits - TreeMap limits = new TreeMap<>(); + GetInput cpu = new GetInput(); + cpu.setBpInputName(namePrefix + "cpu_limit"); + limits.put("cpu", cpu); - GetInput cpu = new GetInput(); - cpu.setBpInputName(name + "cpu_limit"); - limits.put("cpu", cpu); + GetInput memL = new GetInput(); + memL.setBpInputName(namePrefix + "memory_limit"); + limits.put("memory", memL); - GetInput memL = new GetInput(); - memL.setBpInputName(name + "memory_limit"); - limits.put("memory", memL); + inps.put(namePrefix + "cpu_limit", cpuLimit); + inps.put(namePrefix + "memory_limit", memoryLimit); - inps.put(name + "cpu_limit", cpuLimit); - inps.put(name + "memory_limit", memoryLimit); + this.setLimits(limits); - this.setLimits(limits); + //set the requests + TreeMap requests = new TreeMap<>(); - //set the requests - TreeMap requests = new TreeMap<>(); + GetInput cpuR = new GetInput(); + cpuR.setBpInputName(namePrefix + "cpu_request"); + requests.put("cpu", cpuR); - GetInput cpuR = new GetInput(); - cpuR.setBpInputName(name + "cpu_request"); - requests.put("cpu", cpuR); + GetInput memR = new GetInput(); + memR.setBpInputName(namePrefix + "memory_request"); + requests.put("memory", memR); - GetInput memR = new GetInput(); - memR.setBpInputName(name + "memory_request"); - requests.put("memory", memR); + inps.put(namePrefix + "cpu_request", cpuLimit); + inps.put(namePrefix + "memory_request", memoryLimit); - inps.put(name + "cpu_request", cpuLimit); - inps.put(name + "memory_request", memoryLimit); + this.setRequests(requests); - this.setRequests(requests); + return inps; + } - return inps; - } + private String getNamePrefix(String name) { + return name.isEmpty() ? "" : name + "_"; + } } -- cgit 1.2.3-korg