2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sparky.viewandinspect.task;
24 import java.util.function.Supplier;
26 import org.onap.aai.cl.api.Logger;
27 import org.onap.aai.cl.eelf.LoggerFactory;
28 import org.onap.aai.restclient.client.OperationResult;
29 import org.onap.aai.sparky.dal.GizmoAdapter;
30 import org.onap.aai.sparky.logging.AaiUiMsgs;
31 import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction;
35 * The Class PerformNodeSelfLinkProcessingTask.
37 public class PerformGizmoNodeSelfLinkProcessingTask implements Supplier<NodeProcessingTransaction> {
39 private static final Logger logger =
40 LoggerFactory.getInstance().getLogger(PerformGizmoNodeSelfLinkProcessingTask.class);
42 private NodeProcessingTransaction txn;
43 private GizmoAdapter gizmoAdapter;
44 private Map<String, String> contextMap;
47 * Instantiates a new perform node self link processing task.
50 * @param aaiProvider the aai provider
51 * @param aaiConfig the aai config
56 * @param requestParameters
60 public PerformGizmoNodeSelfLinkProcessingTask(NodeProcessingTransaction txn, String requestParameters,
61 GizmoAdapter gizmoAdapter) {
62 this.gizmoAdapter = gizmoAdapter;
64 this.contextMap = MDC.getCopyOfContextMap();
70 * @see java.util.function.Supplier#get()
73 public NodeProcessingTransaction get() {
74 MDC.setContextMap(contextMap);
75 OperationResult opResult = new OperationResult();
76 String link = txn.getSelfLink();
79 opResult.setResult(500, "Aborting self-link processing because self link is null");
80 txn.setOpResult(opResult);
85 * Rebuild the self link:
87 * <li>build the base url with the configured scheme + authority (server:port)
88 * <li>recombine baseUrl + originalEncodedLink + queryStringParameters
92 final String urlSchemeAndAuthority = gizmoAdapter.repairInventorySelfLink("", null);
94 String parameters = txn.getRequestParameters();
95 link = urlSchemeAndAuthority + link;
97 if (parameters != null) {
101 if (logger.isDebugEnabled()) {
102 logger.debug(AaiUiMsgs.DEBUG_GENERIC, "Collecting " + link);
107 opResult = gizmoAdapter.queryGizmoWithRetries(link, "application/json",
108 gizmoAdapter.getEndpointConfig().getNumRequestRetries());
109 } catch (Exception exc) {
110 opResult = new OperationResult();
111 opResult.setResult(500, "Querying AAI with retry failed due to an exception.");
112 logger.error(AaiUiMsgs.ERROR_AAI_QUERY_WITH_RETRY, exc.getMessage());
115 if (logger.isDebugEnabled()) {
116 logger.debug(AaiUiMsgs.DEBUG_GENERIC, "Operation result = " + opResult.toString());
119 txn.setOpResult(opResult);