Merge "Changes to Regex for Name and version Issue-ID: DCAEGEN2-1867"
[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
41  * Application: ONAP - Blueprint Generator
42  * Common ONAP Service used by ONAP and DMAAP Blueprint to add ResourceConfig
43  */
44
45
46 @Service("onapResourceConfigService")
47 public class ResourceConfigService {
48
49     @Autowired
50     private BlueprintHelperService blueprintHelperService;
51
52     //Method to create Resouce Config for properties
53     public Map<String,Object> createResourceConfig(Map<String, LinkedHashMap<String, Object>> inputs, String name){
54         Map<String,Object> response = new HashMap<>();
55         ResourceConfig resourceConfig = new ResourceConfig();
56
57         LinkedHashMap<String, Object> memoryLimit = blueprintHelperService.createStringInput(Constants.MEMORY_LIMIT_128Mi);
58
59         LinkedHashMap<String, Object> cpuLimit  = blueprintHelperService.createStringInput( Constants.CPU_LIMIT_250m);
60
61         name = blueprintHelperService.getNamePrefix(name);
62
63         Map<String, GetInput> lim = new TreeMap<>();
64
65         GetInput cpu = new GetInput();
66         cpu.setBpInputName(name + Constants.CPU_LIMIT);
67         lim.put("cpu", cpu);
68
69         GetInput memL = new GetInput();
70         memL.setBpInputName(name + Constants.MEMORY_LIMIT);
71         lim.put("memory", memL);
72
73         inputs.put(name + Constants.CPU_LIMIT, cpuLimit);
74         inputs.put(name + Constants.MEMORY_LIMIT, memoryLimit);
75
76         resourceConfig.setLimits(lim);
77
78         Map<String, GetInput> req = new TreeMap<>();
79
80         GetInput cpuR = new GetInput();
81         cpuR.setBpInputName(name + Constants.CPU_REQUEST);
82         req.put("cpu", cpuR);
83
84         GetInput memR = new GetInput();
85         memR.setBpInputName(name + Constants.MEMORY_REQUEST);
86         req.put("memory", memR);
87
88         inputs.put(name + Constants.CPU_REQUEST, cpuLimit);
89         inputs.put(name + Constants.MEMORY_REQUEST, memoryLimit);
90
91         resourceConfig.setRequests(req);
92
93         response.put("resourceConfig", resourceConfig);
94         response.put("inputs", inputs);
95         return response;
96     }
97
98 }