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.openecomp.mso.adapters.sdnc.impl;
24 import org.openecomp.mso.logger.MsoAlarmLogger;
25 import org.openecomp.mso.logger.MsoLogger;
26 import org.openecomp.mso.properties.MsoJavaProperties;
27 import org.openecomp.mso.properties.MsoPropertiesException;
28 import org.openecomp.mso.properties.MsoPropertiesFactory;
30 import org.openecomp.mso.logger.MessageEnum;
31 public class RequestTunables {
33 private MsoPropertiesFactory msoPropertiesFactory;
35 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
36 private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger();
37 public static final String MSO_PROP_SDNC_ADAPTER="MSO_PROP_SDNC_ADAPTER";
40 private String reqId = "";
41 private String msoAction = "";
42 private String operation = "";
43 private String action = "";
46 private String reqMethod = "POST";
47 private String sdncUrl = null;
48 private String timeout = "60000";
49 private String headerName = "sdnc-request-header";
50 private String namespace = "";
51 private String asyncInd = "N"; //future use
53 private String sdncaNotificationUrl = null;
55 public RequestTunables(String reqId, String msoAction, String operation, String action, MsoPropertiesFactory msoPropFactory) {
57 msoPropertiesFactory = msoPropFactory;
61 if (msoAction != null) {
62 this.msoAction = msoAction;
64 if (operation != null) {
65 this.operation = operation;
72 public String getReqId() {
75 public void setReqId(String reqId) {
78 public String getReqMethod() {
81 public void setReqMethod(String reqMethod) {
82 this.reqMethod = reqMethod;
84 public String getMsoAction() {
87 public void setMsoAction(String msoAction) {
88 this.msoAction = msoAction;
90 public String getAction() {
93 public void setAction(String action) {
96 public String getOperation() {
99 public void setOperation(String operation) {
100 this.operation = operation;
102 public String getSdncUrl() {
105 public void setSdncUrl(String sdncUrl) {
106 this.sdncUrl = sdncUrl;
108 public String getTimeout() {
111 public void setTimeout(String timeout) {
112 this.timeout = timeout;
114 public String getAsyncInd() {
117 public void setAsyncInd(String asyncInd) {
118 this.asyncInd = asyncInd;
120 public String getHeaderName() {
123 public void setHeaderName(String headerName) {
124 this.headerName = headerName;
128 public String getSdncaNotificationUrl() {
129 return sdncaNotificationUrl;
132 public void setSdncaNotificationUrl(String sdncaNotificationUrl) {
133 this.sdncaNotificationUrl = sdncaNotificationUrl;
136 public String getNamespace() {
140 public void setNamespace(String namespace) {
141 this.namespace = namespace;
145 public String toString() {
146 return "RequestTunables [reqId=" + reqId + ", msoAction=" + msoAction
147 + ", operation=" + operation + ", action=" + action
148 + ", reqMethod=" + reqMethod + ", sdncUrl=" + sdncUrl
149 + ", timeout=" + timeout + ", headerName=" + headerName
150 + ", sdncaNotificationUrl=" + sdncaNotificationUrl
151 + ", namespace=" + namespace + "]";
154 public void setTunables()
158 if ("query".equals(action)) { //due to variable format for operation eg services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9
159 key = Constants.REQUEST_TUNABLES + "." + msoAction + ".." + action;
160 msoLogger.debug("Generated key: " + key);
162 else if ("put".equals(action) || "restdelete".equals(action)) { //due to variable format for operation eg services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9
163 key = Constants.REQUEST_TUNABLES + "..." + action;
164 msoLogger.debug("Generated key: " + key);
166 key = Constants.REQUEST_TUNABLES + "." + msoAction + "." + operation +"." + action;
167 msoLogger.debug("Generated key: " + key);
172 value = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_SDNC_ADAPTER).getProperty(key, "");
173 } catch (MsoPropertiesException e) {
174 msoLogger.error (MessageEnum.LOAD_PROPERTIES_FAIL, "Unknown. Mso Properties ID not found in cache: " + MSO_PROP_SDNC_ADAPTER, "SDNC", "", MsoLogger.ErrorCode.DataError, "Exception - Mso Properties ID not found in cache", e);
178 if (value != null && value.length() > 0) {
180 String[] parts = value.split("\\|"); //escape pipe
181 if (parts.length < 3) {
182 msoLogger.warn(MessageEnum.RA_SDNC_INVALID_CONFIG, key, value, "SDNC", "", MsoLogger.ErrorCode.DataError, "Invalid config");
185 for (int i = 0; i < parts.length; i++) {
187 reqMethod = parts[i];
188 msoLogger.debug("Request Method is set to: " + reqMethod);
191 msoLogger.debug("Timeout is set to: " + timeout);
193 sdncUrl = SDNCAdapterPortTypeImpl.getProperty(Constants.REQUEST_TUNABLES + "." + parts[i], "",msoPropertiesFactory);
194 if (operation != null && sdncUrl != null) {
195 sdncUrl = sdncUrl + operation;
197 msoLogger.debug("SDNC Url is set to: " + sdncUrl);
199 headerName = parts[i];
200 msoLogger.debug("HeaderName is set to: " + headerName);
202 namespace = parts[i];
203 msoLogger.debug("NameSpace is set to: " + namespace);
206 msoLogger.debug("AsyncInd is set to: " + asyncInd);
210 if (sdncUrl == null) {
211 error = "Invalid configuration, sdncUrl required for:" + key + " value:" + value;
214 error = "Missing configuration for:" + key;
217 msoLogger.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, key, "SDNC", "", MsoLogger.ErrorCode.DataError, "Missing config param");
218 alarmLogger.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
220 msoLogger.debug ("RequestTunables Key:" + key + " Value:" + value + " Tunables:" + this.toString());