6c8c8819edcce8cf02c1e305382d60e9415ff005
[so.git] / adapters / mso-sdnc-adapter / src / main / java / org / openecomp / mso / adapters / sdnc / impl / RequestTunables.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.mso.adapters.sdnc.impl;
22
23
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;
29
30 import org.openecomp.mso.logger.MessageEnum;
31 public class RequestTunables {
32
33         private MsoPropertiesFactory msoPropertiesFactory;
34         
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";
38
39         //criteria
40         private String reqId = "";
41         private String msoAction = "";
42         private String operation = "";
43         private String action = "";
44
45         //tunables
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
52
53         private String sdncaNotificationUrl = null;
54
55         public RequestTunables(String reqId, String msoAction, String operation, String action, MsoPropertiesFactory msoPropFactory) {
56                 super();
57                 msoPropertiesFactory = msoPropFactory;
58                 if (reqId != null) {
59             this.reqId = reqId;
60         }
61                 if (msoAction != null) {
62             this.msoAction = msoAction;
63         }
64                 if (operation != null) {
65             this.operation = operation;
66         }
67                 if (action != null) {
68             this.action = action;
69         }
70         }
71
72         public String getReqId() {
73                 return reqId;
74         }
75         public void setReqId(String reqId) {
76                 this.reqId = reqId;
77         }
78         public String getReqMethod() {
79                 return reqMethod;
80         }
81         public void setReqMethod(String reqMethod) {
82                 this.reqMethod = reqMethod;
83         }
84         public String getMsoAction() {
85                 return msoAction;
86         }
87         public void setMsoAction(String msoAction) {
88                 this.msoAction = msoAction;
89         }
90         public String getAction() {
91                 return action;
92         }
93         public void setAction(String action) {
94                 this.action = action;
95         }
96         public String getOperation() {
97                 return operation;
98         }
99         public void setOperation(String operation) {
100                 this.operation = operation;
101         }
102         public String getSdncUrl() {
103                 return sdncUrl;
104         }
105         public void setSdncUrl(String sdncUrl) {
106                 this.sdncUrl = sdncUrl;
107         }
108         public String getTimeout() {
109                 return timeout;
110         }
111         public void setTimeout(String timeout) {
112                 this.timeout = timeout;
113         }
114         public String getAsyncInd() {
115                 return asyncInd;
116         }
117         public void setAsyncInd(String asyncInd) {
118                 this.asyncInd = asyncInd;
119         }
120         public String getHeaderName() {
121                 return headerName;
122         }
123         public void setHeaderName(String headerName) {
124                 this.headerName = headerName;
125         }
126
127
128         public String getSdncaNotificationUrl() {
129                 return sdncaNotificationUrl;
130         }
131
132         public void setSdncaNotificationUrl(String sdncaNotificationUrl) {
133                 this.sdncaNotificationUrl = sdncaNotificationUrl;
134         }
135
136         public String getNamespace() {
137                 return namespace;
138         }
139
140         public void setNamespace(String namespace) {
141                 this.namespace = namespace;
142         }
143
144         @Override
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 + "]";
152         }
153
154         public void setTunables()
155         {
156                 String error = null;
157                 String key = null;
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);
161                 }
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);
165                 } else {
166                         key = Constants.REQUEST_TUNABLES + "." + msoAction + "." + operation +"."  + action;
167                         msoLogger.debug("Generated key: " + key);
168                 }
169
170                 String value;
171                 try {
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);
175                         value="";
176                 }
177
178                 if (value != null && value.length() > 0) {
179
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");
183                         }
184
185                         for (int i = 0; i < parts.length; i++) {
186                                 if (i == 0) {
187                                         reqMethod = parts[i];
188                                         msoLogger.debug("Request Method is set to: " + reqMethod);
189                                 } else if (i == 1) {
190                                         timeout = parts[i];
191                                         msoLogger.debug("Timeout is set to: " + timeout);
192                                 } else if (i == 2) {
193                                         sdncUrl = SDNCAdapterPortTypeImpl.getProperty(Constants.REQUEST_TUNABLES + "." + parts[i], "",msoPropertiesFactory);
194                                         if (operation != null && sdncUrl != null) {
195                                                 sdncUrl = sdncUrl  + operation;
196                                         }
197                                         msoLogger.debug("SDNC Url is set to: " + sdncUrl);
198                                 } else if  (i == 3) {
199                                         headerName = parts[i];
200                                         msoLogger.debug("HeaderName is set to: " + headerName);
201                                 } else if  (i == 4) {
202                                         namespace = parts[i];
203                                         msoLogger.debug("NameSpace is set to: " + namespace);
204                                 } else if  (i == 5) {
205                                         asyncInd = parts[i];
206                                         msoLogger.debug("AsyncInd is set to: " + asyncInd);
207                                 }
208                         }
209
210                         if (sdncUrl == null) {
211                                 error = "Invalid configuration, sdncUrl required for:" + key + " value:" + value;
212                         }
213                 } else {
214                         error = "Missing configuration for:" + key;
215                 }
216                 if (error != null) {
217                         msoLogger.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, key, "SDNC", "", MsoLogger.ErrorCode.DataError, "Missing config param");
218                         alarmLogger.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
219                 }
220                 msoLogger.debug ("RequestTunables Key:" + key + " Value:" + value + " Tunables:" + this.toString());
221                 return;
222         }
223 }