3 * * ============LICENSE_START=======================================================
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
12 * * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.onap.blueprintgenerator.service.common;
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;
33 import java.util.HashMap;
34 import java.util.LinkedHashMap;
36 import java.util.TreeMap;
39 * @author : Ravi Mantena
41 * Application: ONAP - Blueprint Generator
42 * Common ONAP Service used by ONAP and DMAAP Blueprint to add ResourceConfig
46 @Service("onapResourceConfigService")
47 public class ResourceConfigService {
50 private BlueprintHelperService blueprintHelperService;
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();
57 LinkedHashMap<String, Object> memoryLimit = blueprintHelperService.createStringInput(Constants.MEMORY_LIMIT_128Mi);
59 LinkedHashMap<String, Object> cpuLimit = blueprintHelperService.createStringInput( Constants.CPU_LIMIT_250m);
61 name = blueprintHelperService.getNamePrefix(name);
63 Map<String, GetInput> lim = new TreeMap<>();
65 GetInput cpu = new GetInput();
66 cpu.setBpInputName(name + Constants.CPU_LIMIT);
69 GetInput memL = new GetInput();
70 memL.setBpInputName(name + Constants.MEMORY_LIMIT);
71 lim.put("memory", memL);
73 inputs.put(name + Constants.CPU_LIMIT, cpuLimit);
74 inputs.put(name + Constants.MEMORY_LIMIT, memoryLimit);
76 resourceConfig.setLimits(lim);
78 Map<String, GetInput> req = new TreeMap<>();
80 GetInput cpuR = new GetInput();
81 cpuR.setBpInputName(name + Constants.CPU_REQUEST);
84 GetInput memR = new GetInput();
85 memR.setBpInputName(name + Constants.MEMORY_REQUEST);
86 req.put("memory", memR);
88 inputs.put(name + Constants.CPU_REQUEST, cpuLimit);
89 inputs.put(name + Constants.MEMORY_REQUEST, memoryLimit);
91 resourceConfig.setRequests(req);
93 response.put("resourceConfig", resourceConfig);
94 response.put("inputs", inputs);