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=========================================================
20 package org.openecomp.mso.adapters.sdnc.sdncrest;
22 import org.openecomp.mso.adapters.sdnc.impl.Constants;
23 import org.openecomp.mso.logger.MessageEnum;
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;
31 * Typed Request Tunables. Each entry is identified by a TYPE in the property name.
32 * Different types can have different keys.
36 * org.openecomp.mso.adapters.sdnc.TYPE.KEY1[.KEY2...]=METHOD|TIMEOUT|URL|HEADER|NAMESPACE
38 * Currently supported type(s): service
40 * org.openecomp.mso.adapters.sdnc.service.SERVICE.OPERATION=METHOD|TIMEOUT|URL|HEADER|NAMESPACE
43 public class TypedRequestTunables {
45 private static final String MSO_PROPERTIES_ID = "MSO_PROP_SDNC_ADAPTER";
47 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
48 private static final MsoAlarmLogger ALARMLOGGER = new MsoAlarmLogger();
50 private final MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
52 private final String reqId;
53 private final String myUrlSuffix;
54 private String key = null;
55 private String error = null;
57 // tunables (all are required)
58 private String reqMethod = null;
59 private String timeout = null;
60 private String sdncUrl = null;
61 private String headerName = null;
62 private String namespace = null;
63 private String myUrl = null;
65 public TypedRequestTunables(String reqId, String myUrlSuffix) {
67 this.myUrlSuffix = myUrlSuffix;
71 * Sets the key for a service request:
73 * org.openecomp.mso.adapters.sdnc.service.SERVICE.OPERATION
75 * @param service the sdncService
76 * @param operation the sdncOperation
78 public void setServiceKey(String service, String operation) {
79 key = Constants.REQUEST_TUNABLES + ".service." + service + "." + operation;
80 LOGGER.debug("Generated " + getClass().getSimpleName() + " key: " + key);
84 * Gets the SDNC request ID.
86 public String getReqId() {
91 * Gets the generated key.
93 public String getKey() {
98 * Gets the most recent error, or null if there was no error.
100 public String getError() {
104 public String getReqMethod() {
108 public String getTimeout() {
112 public String getSdncUrl() {
116 public String getHeaderName() {
120 public String getNamespace() {
125 * Gets the SDNC adapter notification URL, trimmed of trailing '/' characters.
127 public String getMyUrl() {
132 * Returns true if successful. If there is an error, it is logged and alarmed.
133 * The error description may be retrieved by calling getError().
135 public boolean setTunables() {
137 MsoJavaProperties properties;
140 properties = msoPropertiesFactory.getMsoJavaProperties(MSO_PROPERTIES_ID);
141 } catch (MsoPropertiesException e) {
142 error = "Mso Properties ID not found in cache: " + MSO_PROPERTIES_ID;
143 LOGGER.error(MessageEnum.LOAD_PROPERTIES_FAIL, "Unknown. " + error, "SDNC", "",
144 MsoLogger.ErrorCode.DataError, "Exception - Mso Properties ID not found in cache", e);
145 ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
149 String value = properties.getProperty(key, "");
151 if (value.equals("")) {
152 error = "Missing configuration for: " + key;
153 LOGGER.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, key, "SDNC", "", MsoLogger.ErrorCode.DataError, "Missing config param");
154 ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
158 String[] parts = value.split("\\|");
160 if (parts.length != 5) {
161 error = "Invalid configuration for: " + key;
162 LOGGER.error(MessageEnum.RA_SDNC_INVALID_CONFIG, key, value, "SDNC", "", MsoLogger.ErrorCode.DataError, "Invalid config");
163 ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
167 reqMethod = parts[0];
168 LOGGER.debug("Request Method is set to: " + reqMethod);
171 LOGGER.debug("Timeout is set to: " + timeout);
173 String urlPropKey = Constants.REQUEST_TUNABLES + "." + parts[2];
174 sdncUrl = properties.getProperty(urlPropKey, "");
176 if (sdncUrl.equals("")) {
177 error = "Missing configuration for: " + urlPropKey;
178 LOGGER.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, urlPropKey, "SDNC", "", MsoLogger.ErrorCode.DataError, "Missing config param");
179 ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
183 LOGGER.debug("SDNC Url is set to: " + sdncUrl);
185 headerName = parts[3];
186 LOGGER.debug("Header Name is set to: " + headerName);
188 namespace = parts[4];
189 LOGGER.debug("Namespace is set to: " + namespace);
191 myUrl = properties.getProperty(Constants.MY_URL_PROP, "");
193 if (myUrl.equals("")) {
194 error = "Missing configuration for: " + Constants.MY_URL_PROP;
195 LOGGER.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, Constants.MY_URL_PROP, "SDNC", "",
196 MsoLogger.ErrorCode.DataError, "Missing config param");
197 ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
201 while (myUrl.endsWith("/")) {
202 myUrl = myUrl.substring(0, myUrl.length()-1);
205 myUrl += myUrlSuffix;
207 LOGGER.debug(toString());
212 public String toString() {
213 return getClass().getSimpleName() + "["
215 + (key == null ? "" : ", key=" + key)
216 + (reqMethod == null ? "" : ", reqMethod=" + reqMethod)
217 + (sdncUrl == null ? "" : ", sdncUrl=" + sdncUrl)
218 + (timeout == null ? "" : ", timeout=" + timeout)
219 + (headerName == null ? "" : ", headerName=" + headerName)
220 + (namespace == null ? "" : ", namespace=" + namespace)
221 + (myUrl == null ? "" : ", myUrl=" + myUrl)