2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.sdnc.impl;
23 import org.onap.so.logger.MessageEnum;
24 import org.onap.so.logger.MsoLogger;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.core.env.Environment;
27 import org.springframework.stereotype.Component;
30 public class MapRequestTunables {
32 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA,MapRequestTunables.class);
33 public static final String GENERATED_KEY = "Generated key: ";
36 private Environment env;
38 public RequestTunables setTunables(RequestTunables reqTunableOriginal)
40 RequestTunables reqTunable = new RequestTunables(reqTunableOriginal);
43 if ("query".equals(reqTunable.getAction())) { //due to variable format for reqTunable.getOperation() eg services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9
44 key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + ".." + reqTunable.getAction();
45 msoLogger.debug(GENERATED_KEY + key);
47 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
48 key = Constants.REQUEST_TUNABLES + "..." + reqTunable.getAction();
49 msoLogger.debug(GENERATED_KEY + key);
51 key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + "." + reqTunable.getOperation() +"." + reqTunable.getAction();
52 msoLogger.debug(GENERATED_KEY + key);
56 value = env.getProperty(key, "");
58 if (value != null && value.length() > 0) {
60 String[] parts = value.split("\\|"); //escape pipe
61 if (parts.length < 3) {
62 msoLogger.warn(MessageEnum.RA_SDNC_INVALID_CONFIG, key, value, "SDNC", "", MsoLogger.ErrorCode.DataError, "Invalid config");
65 for (int i = 0; i < parts.length; i++) {
67 reqTunable.setReqMethod(parts[i]) ;
68 msoLogger.debug("Request Method is set to: " + reqTunable.getReqMethod());
70 reqTunable.setTimeout( parts[i]);
71 msoLogger.debug("Timeout is set to: " + reqTunable.getTimeout());
73 reqTunable.setSdncUrl(env.getProperty(Constants.REQUEST_TUNABLES + "." + parts[i],""));
74 if (reqTunable.getOperation() != null && reqTunable.getSdncUrl() != null) {
75 reqTunable.setSdncUrl(reqTunable.getSdncUrl() + reqTunable.getOperation());
77 msoLogger.debug("SDNC Url is set to: " + reqTunable.getSdncUrl());
79 reqTunable.setHeaderName(parts[i]);
80 msoLogger.debug("HeaderName is set to: " + reqTunable.getHeaderName());
82 reqTunable.setNamespace(parts[i]);
83 msoLogger.debug("NameSpace is set to: " + reqTunable.getNamespace());
85 reqTunable.setAsyncInd(parts[i]);
86 msoLogger.debug("AsyncInd is set to: " + reqTunable.getAsyncInd());
90 if (reqTunable.getSdncUrl() == null || reqTunable.getSdncUrl().equals("")) {
91 error = "Invalid configuration, sdncUrl required for:" + key + " value:" + value;
94 error = "Missing configuration for:" + key;
97 msoLogger.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, key, "SDNC", "", MsoLogger.ErrorCode.DataError, "Missing config param");
99 msoLogger.debug ("RequestTunables Key:" + key + " Value:" + value + " Tunables:" + this.toString());