Refactor ResourceConfig class
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / blueprint / ResourceConfig.java
1 /*============LICENSE_START=======================================================
2  org.onap.dcae
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
10
11       http://www.apache.org/licenses/LICENSE-2.0
12
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=========================================================
19
20  */
21
22 package org.onap.blueprintgenerator.models.blueprint;
23
24 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createStringInput;
25
26 import java.util.LinkedHashMap;
27 import java.util.TreeMap;
28
29 import lombok.AllArgsConstructor;
30 import lombok.Builder;
31 import lombok.Getter;
32 import lombok.NoArgsConstructor;
33 import lombok.Setter;
34
35 //TODO: Auto-generated Javadoc
36 /* (non-Javadoc)
37  * @see java.lang.Object#toString()
38  */
39 @Getter
40 @Setter
41
42 /* (non-Javadoc)
43  * @see java.lang.Object#toString()
44  */
45 @Builder
46
47 /**
48  * Instantiates a new resource config obj.
49  */
50 @NoArgsConstructor
51
52 /**
53  * Instantiates a new resource config obj.
54  *
55  * @param limits the limits
56  * @param requests the requests
57  */
58 @AllArgsConstructor
59
60 public class ResourceConfig {
61
62     /**
63      * The limits.
64      */
65     private TreeMap<String, GetInput> limits;
66
67     /**
68      * The requests.
69      */
70     private TreeMap<String, GetInput> requests;
71
72
73     /**
74      * Creates the resource config.
75      *
76      * @param inps the inps
77      * @param name the name
78      * @return the tree map
79      */
80     public TreeMap<String, LinkedHashMap<String, Object>> createResourceConfig(
81         TreeMap<String, LinkedHashMap<String, Object>> inps, String name) {
82
83         LinkedHashMap<String, Object> memoryLimit = createStringInput("128Mi");
84         LinkedHashMap<String, Object> cpuLimit = createStringInput("250m");
85
86         String namePrefix = getNamePrefix(name);
87
88         //set the limits
89         TreeMap<String, GetInput> limits = new TreeMap<>();
90
91         GetInput cpu = new GetInput();
92         cpu.setBpInputName(namePrefix + "cpu_limit");
93         limits.put("cpu", cpu);
94
95         GetInput memL = new GetInput();
96         memL.setBpInputName(namePrefix + "memory_limit");
97         limits.put("memory", memL);
98
99         inps.put(namePrefix + "cpu_limit", cpuLimit);
100         inps.put(namePrefix + "memory_limit", memoryLimit);
101
102         this.setLimits(limits);
103
104         //set the requests
105         TreeMap<String, GetInput> requests = new TreeMap<>();
106
107         GetInput cpuR = new GetInput();
108         cpuR.setBpInputName(namePrefix + "cpu_request");
109         requests.put("cpu", cpuR);
110
111         GetInput memR = new GetInput();
112         memR.setBpInputName(namePrefix + "memory_request");
113         requests.put("memory", memR);
114
115         inps.put(namePrefix + "cpu_request", cpuLimit);
116         inps.put(namePrefix + "memory_request", memoryLimit);
117
118         this.setRequests(requests);
119
120         return inps;
121     }
122
123     private String getNamePrefix(String name) {
124         return name.isEmpty() ? "" : name + "_";
125     }
126 }
127