2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2018 IBM.
8 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.so.adapters.sdnc.impl;
26 import org.onap.so.logger.ErrorCode;
27 import org.onap.so.logger.MessageEnum;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.core.env.Environment;
32 import org.springframework.stereotype.Component;
35 public class MapRequestTunables {
37 private static Logger logger = LoggerFactory.getLogger(MapRequestTunables.class);
38 public static final String GENERATED_KEY = "Generated key: ";
41 private Environment env;
43 public RequestTunables setTunables(RequestTunables reqTunableOriginal)
45 RequestTunables reqTunable = new RequestTunables(reqTunableOriginal);
48 if ("query".equals(reqTunable.getAction())) { //due to variable format for reqTunable.getOperation() eg services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9
49 key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + ".." + reqTunable.getAction();
50 logger.debug(GENERATED_KEY + key);
52 else if ("put".equals(reqTunable.getAction()) || "restdelete".equals(reqTunable.getAction())) { //due to variable format for reqTunable.getOperation() eg services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9
53 key = Constants.REQUEST_TUNABLES + "..." + reqTunable.getAction();
54 logger.debug(GENERATED_KEY + key);
56 key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + "." + reqTunable.getOperation() +"." + reqTunable.getAction();
57 logger.debug(GENERATED_KEY + key);
61 value = env.getProperty(key, "");
63 if (value != null && value.length() > 0) {
65 String[] parts = value.split("\\|"); //escape pipe
66 if (parts.length < 3) {
67 logger.warn("{} {} {} {} {} {}", MessageEnum.RA_SDNC_INVALID_CONFIG.toString(), key, value, "SDNC",
68 ErrorCode.DataError.getValue(), "Invalid config");
71 for (int i = 0; i < parts.length; i++) {
73 reqTunable.setReqMethod(parts[i]) ;
74 logger.debug("Request Method is set to: {}", reqTunable.getReqMethod());
76 reqTunable.setTimeout( parts[i]);
77 logger.debug("Timeout is set to: {}", reqTunable.getTimeout());
79 reqTunable.setSdncUrl(env.getProperty(Constants.REQUEST_TUNABLES + "." + parts[i],""));
80 if (reqTunable.getOperation() != null && reqTunable.getSdncUrl() != null) {
81 reqTunable.setSdncUrl(reqTunable.getSdncUrl() + reqTunable.getOperation());
83 logger.debug("SDNC Url is set to: {}", reqTunable.getSdncUrl());
85 reqTunable.setHeaderName(parts[i]);
86 logger.debug("HeaderName is set to: {}", reqTunable.getHeaderName());
88 reqTunable.setNamespace(parts[i]);
89 logger.debug("NameSpace is set to: {}", reqTunable.getNamespace());
91 reqTunable.setAsyncInd(parts[i]);
92 logger.debug("AsyncInd is set to: {}", reqTunable.getAsyncInd());
96 if (reqTunable.getSdncUrl() == null || ("").equals(reqTunable.getSdncUrl())) {
97 error = "Invalid configuration, sdncUrl required for:" + key + " value:" + value;
100 error = "Missing configuration for:" + key;
103 logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), key, "SDNC",
104 ErrorCode.DataError.getValue(), "Missing config param");
106 logger.debug("RequestTunables Key:{} Value:{} Tunables:{}", key, value, this.toString());