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;
37 import java.util.TreeMap;
40 * @author : Ravi Mantena
41 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to add
44 @Service("onapResourceConfigService")
45 public class ResourceConfigService {
48 private BlueprintHelperService blueprintHelperService;
50 @Value("${resources.cpuLimit}")
51 private String defaultCpuLimit;
53 @Value("${resources.memoryLimit}")
54 private String defaultMemoryLimit;
57 * Creates Resouce Config for properties
59 * @param inputs Inputs
63 public Map<String, Object> createResourceConfig(
64 Map<String, Map<String, Object>> inputs, String name) {
65 Map<String, Object> response = new HashMap<>();
66 ResourceConfig resourceConfig = new ResourceConfig();
68 Map<String, Object> memoryLimit =
69 blueprintHelperService.createStringInput(defaultMemoryLimit);
71 Map<String, Object> cpuLimit =
72 blueprintHelperService.createStringInput(defaultCpuLimit);
74 name = blueprintHelperService.getNamePrefix(name);
76 Map<String, GetInput> lim = new TreeMap<>();
78 GetInput cpu = new GetInput();
79 cpu.setBpInputName(name + Constants.CPU_LIMIT);
82 GetInput memL = new GetInput();
83 memL.setBpInputName(name + Constants.MEMORY_LIMIT);
84 lim.put("memory", memL);
86 inputs.put(name + Constants.CPU_LIMIT, cpuLimit);
87 inputs.put(name + Constants.MEMORY_LIMIT, memoryLimit);
89 resourceConfig.setLimits(lim);
91 Map<String, GetInput> req = new TreeMap<>();
93 GetInput cpuR = new GetInput();
94 cpuR.setBpInputName(name + Constants.CPU_REQUEST);
97 GetInput memR = new GetInput();
98 memR.setBpInputName(name + Constants.MEMORY_REQUEST);
99 req.put("memory", memR);
101 inputs.put(name + Constants.CPU_REQUEST, cpuLimit);
102 inputs.put(name + Constants.MEMORY_REQUEST, memoryLimit);
104 resourceConfig.setRequests(req);
106 response.put("resourceConfig", resourceConfig);
107 response.put("inputs", inputs);