a3a9c97a146b46350f5561d9adfad5052f9145b4
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / main / java / org / onap / blueprintgenerator / service / common / ResourceConfigService.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
5  *  *  ================================================================================
6  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
7  *  *  ================================================================================
8  *  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  *  you may not use this file except in compliance with the License.
10  *  *  You may obtain a copy of the License at
11  *  *
12  *  *       http://www.apache.org/licenses/LICENSE-2.0
13  *  *
14  *  *  Unless required by applicable law or agreed to in writing, software
15  *  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  *  See the License for the specific language governing permissions and
18  *  *  limitations under the License.
19  *  *  ============LICENSE_END=========================================================
20  *
21  *
22  */
23
24 package org.onap.blueprintgenerator.service.common;
25
26 import org.onap.blueprintgenerator.constants.Constants;
27 import org.onap.blueprintgenerator.model.common.GetInput;
28 import org.onap.blueprintgenerator.model.common.ResourceConfig;
29 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32
33 import java.util.HashMap;
34 import java.util.LinkedHashMap;
35 import java.util.Map;
36 import java.util.TreeMap;
37
38 /**
39  * @author : Ravi Mantena
40  * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to add
41  * ResourceConfig
42  */
43 @Service("onapResourceConfigService")
44 public class ResourceConfigService {
45
46     @Autowired
47     private BlueprintHelperService blueprintHelperService;
48
49     /**
50      * Creates Resouce Config for properties
51      *
52      * @param inputs Inputs
53      * @param name Name
54      * @return
55      */
56     public Map<String, Object> createResourceConfig(
57         Map<String, LinkedHashMap<String, Object>> inputs, String name) {
58         Map<String, Object> response = new HashMap<>();
59         ResourceConfig resourceConfig = new ResourceConfig();
60
61         LinkedHashMap<String, Object> memoryLimit =
62             blueprintHelperService.createStringInput(Constants.MEMORY_LIMIT_128Mi);
63
64         LinkedHashMap<String, Object> cpuLimit =
65             blueprintHelperService.createStringInput(Constants.CPU_LIMIT_250m);
66
67         name = blueprintHelperService.getNamePrefix(name);
68
69         Map<String, GetInput> lim = new TreeMap<>();
70
71         GetInput cpu = new GetInput();
72         cpu.setBpInputName(name + Constants.CPU_LIMIT);
73         lim.put("cpu", cpu);
74
75         GetInput memL = new GetInput();
76         memL.setBpInputName(name + Constants.MEMORY_LIMIT);
77         lim.put("memory", memL);
78
79         inputs.put(name + Constants.CPU_LIMIT, cpuLimit);
80         inputs.put(name + Constants.MEMORY_LIMIT, memoryLimit);
81
82         resourceConfig.setLimits(lim);
83
84         Map<String, GetInput> req = new TreeMap<>();
85
86         GetInput cpuR = new GetInput();
87         cpuR.setBpInputName(name + Constants.CPU_REQUEST);
88         req.put("cpu", cpuR);
89
90         GetInput memR = new GetInput();
91         memR.setBpInputName(name + Constants.MEMORY_REQUEST);
92         req.put("memory", memR);
93
94         inputs.put(name + Constants.CPU_REQUEST, cpuLimit);
95         inputs.put(name + Constants.MEMORY_REQUEST, memoryLimit);
96
97         resourceConfig.setRequests(req);
98
99         response.put("resourceConfig", resourceConfig);
100         response.put("inputs", inputs);
101         return response;
102     }
103 }