2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.viewandinspect.task;
28 import java.util.function.Supplier;
30 import org.onap.aai.cl.api.Logger;
31 import org.onap.aai.cl.eelf.LoggerFactory;
32 import org.onap.aai.restclient.client.OperationResult;
33 import org.onap.aai.sparky.dal.GizmoAdapter;
34 import org.onap.aai.sparky.logging.AaiUiMsgs;
35 import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction;
39 * The Class PerformNodeSelfLinkProcessingTask.
41 public class PerformGizmoNodeSelfLinkProcessingTask implements Supplier<NodeProcessingTransaction> {
43 private static final Logger logger =
44 LoggerFactory.getInstance().getLogger(PerformGizmoNodeSelfLinkProcessingTask.class);
46 private NodeProcessingTransaction txn;
47 private GizmoAdapter gizmoAdapter;
48 private Map<String, String> contextMap;
51 * Instantiates a new perform node self link processing task.
54 * @param aaiProvider the aai provider
55 * @param aaiConfig the aai config
60 * @param requestParameters
64 public PerformGizmoNodeSelfLinkProcessingTask(NodeProcessingTransaction txn, String requestParameters,
65 GizmoAdapter gizmoAdapter) {
66 this.gizmoAdapter = gizmoAdapter;
68 this.contextMap = MDC.getCopyOfContextMap();
74 * @see java.util.function.Supplier#get()
77 public NodeProcessingTransaction get() {
78 MDC.setContextMap(contextMap);
79 OperationResult opResult = new OperationResult();
80 String link = txn.getSelfLink();
83 opResult.setResult(500, "Aborting self-link processing because self link is null");
84 txn.setOpResult(opResult);
89 * Rebuild the self link:
91 * <li>build the base url with the configured scheme + authority (server:port)
92 * <li>recombine baseUrl + originalEncodedLink + queryStringParameters
96 final String urlSchemeAndAuthority = gizmoAdapter.repairInventorySelfLink("", null);
98 String parameters = txn.getRequestParameters();
99 link = urlSchemeAndAuthority + link;
101 if (parameters != null) {
105 if (logger.isDebugEnabled()) {
106 logger.debug(AaiUiMsgs.DEBUG_GENERIC, "Collecting " + link);
111 opResult = gizmoAdapter.queryGizmoWithRetries(link, "application/json",
112 gizmoAdapter.getEndpointConfig().getNumRequestRetries());
113 } catch (Exception exc) {
114 opResult = new OperationResult();
115 opResult.setResult(500, "Querying AAI with retry failed due to an exception.");
116 logger.error(AaiUiMsgs.ERROR_AAI_QUERY_WITH_RETRY, exc.getMessage());
119 if (logger.isDebugEnabled()) {
120 logger.debug(AaiUiMsgs.DEBUG_GENERIC, "Operation result = " + opResult.toString());
123 txn.setOpResult(opResult);