Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 AT&T
|
| 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 |
|
| 22 | package org.onap.osam.mso.rest;
|
| 23 |
|
| 24 | import com.google.common.collect.ImmutableMap;
|
| 25 | import io.joshworks.restclient.http.HttpResponse;
|
| 26 | import java.util.HashMap;
|
| 27 | import java.util.Map;
|
| 28 | import javax.ws.rs.core.HttpHeaders;
|
| 29 | import javax.ws.rs.core.MediaType;
|
| 30 | import org.apache.commons.codec.binary.Base64;
|
| 31 | import org.eclipse.jetty.util.security.Password;
|
| 32 | import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
|
| 33 | import org.onap.portalsdk.core.util.SystemProperties;
|
| 34 | import org.onap.osam.client.SyncRestClient;
|
| 35 | import org.onap.osam.model.RequestReferencesContainer;
|
| 36 | import org.onap.osam.mso.*;
|
| 37 |
|
| 38 | import java.text.DateFormat;
|
| 39 | import java.text.SimpleDateFormat;
|
| 40 | import java.util.Date;
|
| 41 | import org.onap.osam.utils.Logging;
|
| 42 |
|
| 43 |
|
| 44 | public class MsoRestClientNew implements MsoInterface {
|
| 45 |
|
| 46 | public static final String X_FROM_APP_ID = "X-FromAppId";
|
| 47 | final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
|
| 48 | private static final String START = " start";
|
| 49 | private final SyncRestClient client;
|
| 50 | private final String baseUrl;
|
| 51 | private final Map<String, String> commonHeaders;
|
| 52 | /**
|
| 53 | * The logger.
|
| 54 | */
|
| 55 | EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoRestClientNew.class);
|
| 56 |
|
| 57 | public MsoRestClientNew(SyncRestClient client, String baseUrl) {
|
| 58 | this.client = client;
|
| 59 | this.baseUrl = baseUrl;
|
| 60 | this.commonHeaders = initCommonHeaders();
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public MsoResponseWrapper createSvcInstance(RequestDetails requestDetails, String endpoint) {
|
| 65 | String methodName = "createSvcInstance ";
|
| 66 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 67 | String path = baseUrl + endpoint;
|
| 68 |
|
| 69 | return createInstance(requestDetails, path);
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | public MsoResponseWrapper createE2eSvcInstance(Object requestDetails, String endpoint) {
|
| 74 | String methodName = "createE2eSvcInstance ";
|
| 75 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 76 | String path = baseUrl + endpoint;
|
| 77 |
|
| 78 | return createInstance(requestDetails, path);
|
| 79 | }
|
| 80 |
|
| 81 | @Override
|
| 82 | public MsoResponseWrapper createVnf(RequestDetails requestDetails, String endpoint) {
|
| 83 |
|
| 84 | String methodName = "createVnf";
|
| 85 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 86 | String path = baseUrl + endpoint;
|
| 87 |
|
| 88 | return createInstance(requestDetails, path);
|
| 89 | }
|
| 90 |
|
| 91 | @Override
|
| 92 | public MsoResponseWrapper createNwInstance(RequestDetails requestDetails, String endpoint) {
|
| 93 |
|
| 94 | String methodName = "createNwInstance";
|
| 95 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 96 | String path = baseUrl + endpoint;
|
| 97 |
|
| 98 | return createInstance(requestDetails, path);
|
| 99 | }
|
| 100 |
|
| 101 | @Override
|
| 102 | public MsoResponseWrapper createVolumeGroupInstance(RequestDetails requestDetails, String endpoint) {
|
| 103 | String methodName = "createVolumeGroupInstance";
|
| 104 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 105 | String path = baseUrl + endpoint;
|
| 106 |
|
| 107 | return createInstance(requestDetails, path);
|
| 108 | }
|
| 109 |
|
| 110 | @Override
|
| 111 | public MsoResponseWrapper createVfModuleInstance(RequestDetails requestDetails, String endpoint) {
|
| 112 | String methodName = "createVfModuleInstance";
|
| 113 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 114 | String path = baseUrl + endpoint;
|
| 115 |
|
| 116 | return createInstance(requestDetails, path);
|
| 117 | }
|
| 118 |
|
| 119 | @Override
|
| 120 | public MsoResponseWrapper scaleOutVFModuleInstance(RequestDetailsWrapper requestDetailsWrapper, String endpoint) {
|
| 121 | String methodName = "scaleOutVFModuleInstance";
|
| 122 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 123 | String path = baseUrl + endpoint;
|
| 124 | return createInstance(requestDetailsWrapper, path);
|
| 125 | }
|
| 126 |
|
| 127 | @Override
|
| 128 | public MsoResponseWrapper createConfigurationInstance(org.onap.osam.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String endpoint) {
|
| 129 | String methodName = "createConfigurationInstance";
|
| 130 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 131 | String path = baseUrl + endpoint;
|
| 132 |
|
| 133 | return createInstance(requestDetailsWrapper, path);
|
| 134 | }
|
| 135 |
|
| 136 | @Override
|
| 137 | public MsoResponseWrapper deleteE2eSvcInstance(Object requestDetails, String endpoint) {
|
| 138 | String methodName = "deleteE2eSvcInstance";
|
| 139 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 140 | String path = baseUrl + endpoint;
|
| 141 | return deleteInstance(requestDetails, path);
|
| 142 | }
|
| 143 |
|
| 144 | @Override
|
| 145 | public MsoResponseWrapper deleteSvcInstance(RequestDetails requestDetails, String endpoint) {
|
| 146 | String methodName = "deleteSvcInstance";
|
| 147 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 148 | String path = baseUrl + endpoint;
|
| 149 | return deleteInstance(requestDetails, path);
|
| 150 | }
|
| 151 |
|
| 152 | @Override
|
| 153 | public MsoResponseWrapper unassignSvcInstance(RequestDetails requestDetails, String endpoint) {
|
| 154 | String methodName = "unassignSvcInstance";
|
| 155 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 156 | HttpResponse<String> response = client.post(endpoint, commonHeaders, requestDetails, String.class);
|
| 157 | return MsoUtil.wrapResponse(response);
|
| 158 | }
|
| 159 |
|
| 160 | @Override
|
| 161 | public MsoResponseWrapper deleteVnf(RequestDetails requestDetails, String endpoint) {
|
| 162 | String methodName = "deleteVnf";
|
| 163 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 164 | String path = baseUrl + endpoint;
|
| 165 |
|
| 166 | return deleteInstance(requestDetails, path);
|
| 167 | }
|
| 168 |
|
| 169 | @Override
|
| 170 | public MsoResponseWrapper deleteVfModule(RequestDetails requestDetails, String endpoint) {
|
| 171 | String methodName = "deleteVfModule";
|
| 172 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 173 | String path = baseUrl + endpoint;
|
| 174 |
|
| 175 | return deleteInstance(requestDetails, path);
|
| 176 | }
|
| 177 |
|
| 178 | @Override
|
| 179 | public MsoResponseWrapper deleteVolumeGroupInstance(RequestDetails requestDetails, String endpoint) {
|
| 180 | String methodName = "deleteVolumeGroupInstance";
|
| 181 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 182 | String path = baseUrl + endpoint;
|
| 183 |
|
| 184 | return deleteInstance(requestDetails, path);
|
| 185 | }
|
| 186 |
|
| 187 | @Override
|
| 188 | public MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String endpoint) {
|
| 189 | String methodName = "deleteNwInstance";
|
| 190 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 191 | String path = baseUrl + endpoint;
|
| 192 |
|
| 193 | return deleteInstance(requestDetails, path);
|
| 194 | }
|
| 195 |
|
| 196 | @Override
|
| 197 | public MsoResponseWrapper getOrchestrationRequest(String endpoint) {
|
| 198 | String path = baseUrl + endpoint;
|
| 199 |
|
| 200 | HttpResponse<String> response = client.get(path, commonHeaders, new HashMap<>(), String.class);
|
| 201 | return MsoUtil.wrapResponse(response);
|
| 202 | }
|
| 203 |
|
| 204 | public MsoResponseWrapper getManualTasks(String endpoint) {
|
| 205 | String path = baseUrl + endpoint;
|
| 206 |
|
| 207 | HttpResponse<String> response = client.get(path, commonHeaders, new HashMap<>(), String.class);
|
| 208 | return MsoUtil.wrapResponse(response);
|
| 209 | }
|
| 210 |
|
| 211 | public MsoResponseWrapper getOrchestrationRequestsForDashboard(String t, String sourceId, String path, RestObject restObject) {
|
| 212 | String methodName = "getOrchestrationRequestsForDashboard";
|
| 213 | logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 214 |
|
| 215 | try {
|
| 216 | MsoResponseWrapper w = getOrchestrationRequest(path);
|
| 217 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
|
| 218 |
|
| 219 | return w;
|
| 220 |
|
| 221 | } catch (Exception e) {
|
| 222 | logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 223 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 224 | throw e;
|
| 225 | }
|
| 226 | }
|
| 227 |
|
| 228 | public MsoResponseWrapper getManualTasksByRequestId(String t, String sourceId, String endpoint, RestObject restObject) {
|
| 229 | String methodName = "getManualTasksByRequestId";
|
| 230 | logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 231 |
|
| 232 | try {
|
| 233 | String path = baseUrl + endpoint;
|
| 234 |
|
| 235 | MsoResponseWrapper w =getManualTasks(path);
|
| 236 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
|
| 237 |
|
| 238 | return w;
|
| 239 |
|
| 240 | } catch (Exception e) {
|
| 241 | logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 242 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 243 | throw e;
|
| 244 | }
|
| 245 | }
|
| 246 |
|
| 247 | @Override
|
| 248 | public MsoResponseWrapper completeManualTask(RequestDetails requestDetails, String t, String sourceId, String endpoint, RestObject restObject) {
|
| 249 | String methodName = "completeManualTask";
|
| 250 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Complete ");
|
| 251 | try {
|
| 252 | String path = baseUrl + endpoint;
|
| 253 |
|
| 254 | HttpResponse<String> response = client.post(path, commonHeaders, requestDetails, String.class);
|
| 255 | MsoResponseWrapper w = MsoUtil.wrapResponse(response);
|
| 256 |
|
| 257 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
|
| 258 | return w;
|
| 259 |
|
| 260 | } catch (Exception e) {
|
| 261 | logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 262 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 263 | throw e;
|
| 264 | }
|
| 265 | }
|
| 266 |
|
| 267 | /* @Override
|
| 268 | public MsoResponseWrapper replaceVnf(RequestDetails requestDetails, String endpoint) {
|
| 269 | String methodName = "replaceVnf";
|
| 270 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 271 | String path = baseUrl + endpoint;
|
| 272 | return replaceInstance(requestDetails, path);
|
| 273 | }*/
|
| 274 |
|
| 275 | @Override
|
| 276 | public MsoResponseWrapper deleteConfiguration(org.onap.osam.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String pmc_endpoint) {
|
| 277 | String methodName = "deleteConfiguration";
|
| 278 | logger.debug(EELFLoggerDelegate.debugLogger,
|
| 279 | dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 280 | String path = baseUrl + pmc_endpoint;
|
| 281 |
|
| 282 | return deleteInstance(requestDetailsWrapper, path);
|
| 283 | }
|
| 284 |
|
| 285 | @Override
|
| 286 | public MsoResponseWrapper setConfigurationActiveStatus(RequestDetails request, String endpoint) {
|
| 287 | String methodName = "setConfigurationActiveStatus";
|
| 288 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 289 |
|
| 290 | try {
|
| 291 | String path = baseUrl + endpoint;
|
| 292 |
|
| 293 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== "
|
| 294 | + methodName + " calling change configuration active status, path =[" + path + "]");
|
| 295 | HttpResponse<String> response = client.post(path, commonHeaders, request, String.class);
|
| 296 | return MsoUtil.wrapResponse(response);
|
| 297 | } catch (Exception e) {
|
| 298 | logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 299 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 300 | throw e;
|
| 301 | }
|
| 302 | }
|
| 303 |
|
| 304 | @Override
|
| 305 | public MsoResponseWrapper setPortOnConfigurationStatus(RequestDetails request, String endpoint) {
|
| 306 | String methodName = "setPortOnConfigurationStatus";
|
| 307 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 308 |
|
| 309 | try {
|
| 310 | String path = baseUrl + endpoint;
|
| 311 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== "
|
| 312 | + methodName + " calling change port configuration status, path =[" + path + "]");
|
| 313 | HttpResponse<String> response = client.post(path, commonHeaders, request, String.class);
|
| 314 | return MsoUtil.wrapResponse(response);
|
| 315 | } catch (Exception e) {
|
| 316 | logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 317 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 318 | throw e;
|
| 319 | }
|
| 320 | }
|
| 321 |
|
| 322 | @Override
|
| 323 | public MsoResponseWrapperInterface changeManagementUpdate(RequestDetailsWrapper requestDetails, String endpoint) {
|
| 324 | String path = baseUrl + endpoint;
|
| 325 | HttpResponse<RequestReferencesContainer> response = client.post(path, commonHeaders, requestDetails, RequestReferencesContainer.class);
|
| 326 | return MsoUtil.wrapResponse(response);
|
| 327 | }
|
| 328 |
|
| 329 | public MsoResponseWrapper replaceInstance(RequestDetails request, String path) {
|
| 330 | String methodName = "replaceInstance";
|
| 331 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 332 |
|
| 333 | try {
|
| 334 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Replace VNF, path =[" + path + "]");
|
| 335 |
|
| 336 | HttpResponse<String> response = client.post(path, commonHeaders, request, String.class);
|
| 337 | MsoResponseWrapper msoResponseWrapperObject = MsoUtil.wrapResponse(response);
|
| 338 | int status = msoResponseWrapperObject.getStatus();
|
| 339 | if (status == 202) {
|
| 340 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName +
|
| 341 | ",post succeeded, msoResponseWrapperObject response:" + msoResponseWrapperObject.getResponse());
|
| 342 | } else {
|
| 343 | logger.error(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName +
|
| 344 | ": post failed, msoResponseWrapperObject status" + status + ", response:" + msoResponseWrapperObject.getResponse());
|
| 345 |
|
| 346 | // TODO
|
| 347 | }
|
| 348 | return msoResponseWrapperObject;
|
| 349 |
|
| 350 | } catch (Exception e) {
|
| 351 | logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 352 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 353 | throw e;
|
| 354 | }
|
| 355 |
|
| 356 | }
|
| 357 |
|
| 358 | /*@Override
|
| 359 | public MsoResponseWrapper updateVnf(RequestDetails requestDetails, String endpoint) {
|
| 360 | String methodName = "updateVnf";
|
| 361 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 362 | String path = baseUrl + endpoint;
|
| 363 |
|
| 364 | RequestDetailsWrapper wrapper = new RequestDetailsWrapper();
|
| 365 | wrapper.requestDetails = new MsoRequestDetails(requestDetails);
|
| 366 | return updateInstance(requestDetails, path);
|
| 367 | }*/
|
| 368 |
|
| 369 | public MsoResponseWrapper updateInstance(RequestDetails request, String path) {
|
| 370 | String methodName = "updateInstance";
|
| 371 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 372 |
|
| 373 | try {
|
| 374 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]");
|
| 375 |
|
| 376 | HttpResponse<String> response = client.post(path, commonHeaders, request, String.class);
|
| 377 | MsoResponseWrapper w = MsoUtil.wrapResponse(response);
|
| 378 |
|
| 379 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
|
| 380 | return w;
|
| 381 |
|
| 382 | } catch (Exception e) {
|
| 383 | logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 384 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 385 | throw e;
|
| 386 | }
|
| 387 |
|
| 388 | }
|
| 389 |
|
| 390 | public void setServiceInstanceStatus(RequestDetails requestDetails, String t, String sourceId, String endpoint, RestObject<String> restObject) {
|
| 391 | String methodName = "activateServiceInstance";
|
| 392 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start ");
|
| 393 | try {
|
| 394 | String path = baseUrl + endpoint;
|
| 395 | HttpResponse<String> response = client.post(path, commonHeaders, requestDetails, String.class);
|
| 396 | MsoResponseWrapper w = MsoUtil.wrapResponse(response);
|
| 397 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w =" + w.getResponse());
|
| 398 |
|
| 399 | } catch (Exception e) {
|
| 400 | logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 401 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 402 | throw e;
|
| 403 | }
|
| 404 | }
|
| 405 |
|
| 406 | @Override
|
| 407 | public MsoResponseWrapper removeRelationshipFromServiceInstance(RequestDetails requestDetails, String endpoint) {
|
| 408 | String methodName = "removeRelationshipFromServiceInstance";
|
| 409 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 410 |
|
| 411 | try {
|
| 412 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Remove relationship from service instance, path =[" + endpoint + "]");
|
| 413 | String path = baseUrl + endpoint;
|
| 414 | HttpResponse<String> response = client.post(path, commonHeaders, requestDetails, String.class);
|
| 415 | return MsoUtil.wrapResponse(response);
|
| 416 | } catch (Exception e) {
|
| 417 | logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 418 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 419 | throw e;
|
| 420 | }
|
| 421 | }
|
| 422 |
|
| 423 | @Override
|
| 424 | public MsoResponseWrapper addRelationshipToServiceInstance(RequestDetails requestDetails, String addRelationshipsPath) {
|
| 425 | String methodName = "addRelationshipToServiceInstance";
|
| 426 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 427 |
|
| 428 | try {
|
| 429 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Add relationship to service instance, path =[" + addRelationshipsPath + "]");
|
| 430 | String path = baseUrl + addRelationshipsPath;
|
| 431 |
|
| 432 | HttpResponse<String> response = client.post(path, commonHeaders, requestDetails, String.class);
|
| 433 | return MsoUtil.wrapResponse(response);
|
| 434 | } catch (Exception e) {
|
| 435 | logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 436 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 437 | throw e;
|
| 438 | }
|
| 439 | }
|
| 440 |
|
| 441 | @Override
|
| 442 | public <T> HttpResponse<T> get(String path, Class<T> responseClass) {
|
| 443 | return client.get(path, commonHeaders, new HashMap<>(), responseClass);
|
| 444 | }
|
| 445 |
|
| 446 | @Override
|
| 447 | public <T> HttpResponse<T> post(String path, RequestDetailsWrapper requestDetailsWrapper,
|
| 448 | Class<T> responseClass) {
|
| 449 | return client.post(path, commonHeaders, requestDetailsWrapper, responseClass);
|
| 450 | }
|
| 451 |
|
| 452 |
|
| 453 | private MsoResponseWrapper createInstance(Object request, String endpoint) {
|
| 454 | String methodName = "createInstance";
|
| 455 | logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 456 |
|
| 457 | try {
|
| 458 | HttpResponse<String> response = client.post(endpoint, commonHeaders, request, String.class);
|
| 459 | return MsoUtil.wrapResponse(response);
|
| 460 | } catch (Exception e) {
|
| 461 | logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 462 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 463 | throw e;
|
| 464 | }
|
| 465 | }
|
| 466 |
|
| 467 | /**
|
| 468 | * Delete instance.
|
| 469 | *
|
| 470 | * @param request the request
|
| 471 | * @param path the path
|
| 472 | * @return the mso response wrapper
|
| 473 | * @throws Exception the exception
|
| 474 | */
|
| 475 | private MsoResponseWrapper deleteInstance(Object request, String path) {
|
| 476 | String methodName = "deleteInstance";
|
| 477 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
|
| 478 |
|
| 479 | try {
|
| 480 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]");
|
| 481 |
|
| 482 | HttpResponse<String> response = client.delete(path, commonHeaders, String.class);
|
| 483 | MsoResponseWrapper w = MsoUtil.wrapResponse(response);
|
| 484 |
|
| 485 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
|
| 486 | return w;
|
| 487 |
|
| 488 | } catch (Exception e) {
|
| 489 | logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 490 | logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
|
| 491 | throw e;
|
| 492 | }
|
| 493 |
|
| 494 | }
|
| 495 |
|
| 496 | private Map<String, String> initCommonHeaders() {
|
| 497 | String username = SystemProperties.getProperty(MsoProperties.MSO_USER_NAME);
|
| 498 | String password = SystemProperties.getProperty(MsoProperties.MSO_PASSWORD);
|
| 499 | String decrypted_password = Password.deobfuscate(password);
|
| 500 |
|
| 501 | String authString = username + ":" + decrypted_password;
|
| 502 |
|
| 503 | byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
|
| 504 | String authStringEnc = new String(authEncBytes);
|
| 505 |
|
| 506 | Map<String, String> map = new HashMap<>();
|
| 507 | map.put(HttpHeaders.AUTHORIZATION, "Basic " + authStringEnc);
|
| 508 | map.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
|
| 509 | map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
| 510 | map.put(X_FROM_APP_ID, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME));
|
| 511 | map.put(SystemProperties.ECOMP_REQUEST_ID, Logging.extractOrGenerateRequestId());
|
| 512 | return ImmutableMap.copyOf(map);
|
| 513 | }
|
| 514 |
|
| 515 | }
|