1 /*============LICENSE_START=======================================================
3 ================================================================================
4 Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5 Copyright (c) 2020 Nokia. All rights reserved.
6 ================================================================================
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ============LICENSE_END=========================================================
22 package org.onap.blueprintgenerator.models.blueprint;
24 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createStringInput;
25 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CPU_LIMIT;
26 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.MEMORY_LIMIT;
28 import java.util.LinkedHashMap;
29 import java.util.TreeMap;
30 import lombok.AllArgsConstructor;
31 import lombok.Builder;
33 import lombok.NoArgsConstructor;
36 //TODO: Auto-generated Javadoc
38 * @see java.lang.Object#toString()
44 * @see java.lang.Object#toString()
49 * Instantiates a new resource config obj.
54 * Instantiates a new resource config obj.
56 * @param limits the limits
57 * @param requests the requests
61 public class ResourceConfig {
63 private TreeMap<String, GetInput> limits;
64 private TreeMap<String, GetInput> requests;
68 * Creates the resource config.
70 * @param inputs the inputs
71 * @param name the name
72 * @return the tree map
74 public TreeMap<String, LinkedHashMap<String, Object>> createResourceConfig(
75 TreeMap<String, LinkedHashMap<String, Object>> inputs, String name) {
77 String namePrefix = getNamePrefix(name);
79 limits = createInputs(inputs, namePrefix, "limit");
80 requests = createInputs(inputs, namePrefix, "request");
85 private TreeMap<String, GetInput> createInputs(TreeMap<String, LinkedHashMap<String, Object>> inputs,
89 LinkedHashMap<String, Object> memoryLimit = createStringInput(MEMORY_LIMIT);
90 LinkedHashMap<String, Object> cpuLimit = createStringInput(CPU_LIMIT);
92 final String cpuKey = namePrefix + "cpu_" + inputType;
93 final String memoryKey = namePrefix + "memory_" + inputType;
94 TreeMap<String, GetInput> inps = new TreeMap<>();
96 insertInput("cpu", cpuKey, inps);
97 insertInput("memory", memoryKey, inps);
99 inputs.put(cpuKey, cpuLimit);
100 inputs.put(memoryKey, memoryLimit);
105 private void insertInput(String type, String name, TreeMap<String, GetInput> inputs) {
106 GetInput input = new GetInput();
107 input.setBpInputName(name);
108 inputs.put(type, input);
111 private String getNamePrefix(String name) {
112 return (name == null || name.isEmpty()) ? "" : name + "_";