2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.viewandinspect.task;
26 import java.util.function.Supplier;
28 import org.onap.aai.sparky.dal.aai.ActiveInventoryDataProvider;
29 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
30 import org.onap.aai.sparky.dal.rest.OperationResult;
31 import org.onap.aai.sparky.logging.AaiUiMsgs;
32 import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction;
33 import org.onap.aai.cl.api.Logger;
34 import org.onap.aai.cl.eelf.LoggerFactory;
38 * The Class PerformNodeSelfLinkProcessingTask.
40 public class PerformNodeSelfLinkProcessingTask implements Supplier<NodeProcessingTransaction> {
42 private static final Logger logger =
43 LoggerFactory.getInstance().getLogger(PerformNodeSelfLinkProcessingTask.class);
45 private NodeProcessingTransaction txn;
46 private ActiveInventoryDataProvider aaiProvider;
47 private Map<String, String> contextMap;
48 private ActiveInventoryConfig aaiConfig;
51 * Instantiates a new perform node self link processing task.
54 * @param requestParameters the request parameters
55 * @param aaiProvider the aai provider
57 public PerformNodeSelfLinkProcessingTask(NodeProcessingTransaction txn, String requestParameters,
58 ActiveInventoryDataProvider aaiProvider, ActiveInventoryConfig aaiConfig) {
59 this.aaiProvider = aaiProvider;
61 this.contextMap = MDC.getCopyOfContextMap();
62 this.aaiConfig = aaiConfig;
68 * @see java.util.function.Supplier#get()
71 public NodeProcessingTransaction get() {
72 MDC.setContextMap(contextMap);
73 OperationResult opResult = new OperationResult();
74 String link = txn.getSelfLink();
76 opResult.setResult(500, "Aborting self-link processing because self link is null");
77 txn.setOpResult(opResult);
81 * Rebuild the self link:
83 * <li>build the base url with the configured scheme + authority (server:port)
84 * <li>recombine baseUrl + originalEncodedLink + queryStringParameters
88 final String urlSchemeAndAuthority = aaiConfig.repairSelfLink("");
90 String parameters = txn.getRequestParameters();
91 link = urlSchemeAndAuthority + link;
93 if (parameters != null) {
99 if (logger.isDebugEnabled()) {
100 logger.debug(AaiUiMsgs.DEBUG_GENERIC, "Collecting " + link);
104 opResult = aaiProvider.queryActiveInventoryWithRetries(link, "application/json",
105 ActiveInventoryConfig.getConfig().getAaiRestConfig().getNumRequestRetries());
106 } catch (Exception exc) {
107 opResult = new OperationResult();
108 opResult.setResult(500, "Querying AAI with retry failed due to an exception.");
109 logger.error(AaiUiMsgs.ERROR_AAI_QUERY_WITH_RETRY, exc.getMessage());
112 if (logger.isDebugEnabled()) {
113 logger.debug(AaiUiMsgs.DEBUG_GENERIC, "Operation result = " + opResult.toString());
116 txn.setOpResult(opResult);