3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * Copyright (c) 2021 Nokia. All rights reserved.
8 * * ================================================================================
9 * * Licensed under the Apache License, Version 2.0 (the "License");
10 * * you may not use this file except in compliance with the License.
11 * * You may obtain a copy of the License at
13 * * http://www.apache.org/licenses/LICENSE-2.0
15 * * Unless required by applicable law or agreed to in writing, software
16 * * distributed under the License is distributed on an "AS IS" BASIS,
17 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * * See the License for the specific language governing permissions and
19 * * limitations under the License.
20 * * ============LICENSE_END=========================================================
25 package org.onap.blueprintgenerator.service.common;
27 import org.onap.blueprintgenerator.constants.Constants;
28 import org.onap.blueprintgenerator.model.common.GetInput;
29 import org.onap.blueprintgenerator.model.common.ResourceConfig;
30 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.stereotype.Service;
35 import java.util.HashMap;
36 import java.util.LinkedHashMap;
38 import java.util.TreeMap;
41 * @author : Ravi Mantena
42 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to add
45 @Service("onapResourceConfigService")
46 public class ResourceConfigService {
49 private BlueprintHelperService blueprintHelperService;
51 @Value("${resources.cpuLimit}")
52 private String defaultCpuLimit;
54 @Value("${resources.memoryLimit}")
55 private String defaultMemoryLimit;
58 * Creates Resouce Config for properties
60 * @param inputs Inputs
64 public Map<String, Object> createResourceConfig(
65 Map<String, LinkedHashMap<String, Object>> inputs, String name) {
66 Map<String, Object> response = new HashMap<>();
67 ResourceConfig resourceConfig = new ResourceConfig();
69 LinkedHashMap<String, Object> memoryLimit =
70 blueprintHelperService.createStringInput(defaultMemoryLimit);
72 LinkedHashMap<String, Object> cpuLimit =
73 blueprintHelperService.createStringInput(defaultCpuLimit);
75 name = blueprintHelperService.getNamePrefix(name);
77 Map<String, GetInput> lim = new TreeMap<>();
79 GetInput cpu = new GetInput();
80 cpu.setBpInputName(name + Constants.CPU_LIMIT);
83 GetInput memL = new GetInput();
84 memL.setBpInputName(name + Constants.MEMORY_LIMIT);
85 lim.put("memory", memL);
87 inputs.put(name + Constants.CPU_LIMIT, cpuLimit);
88 inputs.put(name + Constants.MEMORY_LIMIT, memoryLimit);
90 resourceConfig.setLimits(lim);
92 Map<String, GetInput> req = new TreeMap<>();
94 GetInput cpuR = new GetInput();
95 cpuR.setBpInputName(name + Constants.CPU_REQUEST);
98 GetInput memR = new GetInput();
99 memR.setBpInputName(name + Constants.MEMORY_REQUEST);
100 req.put("memory", memR);
102 inputs.put(name + Constants.CPU_REQUEST, cpuLimit);
103 inputs.put(name + Constants.MEMORY_REQUEST, memoryLimit);
105 resourceConfig.setRequests(req);
107 response.put("resourceConfig", resourceConfig);
108 response.put("inputs", inputs);