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.ActiveInventoryAdapter;
30 import org.onap.aai.sparky.logging.AaiUiMsgs;
31 import org.onap.aai.sparky.viewandinspect.entity.SelfLinkDeterminationTransaction;
34 public class PerformSelfLinkDeterminationTask implements Supplier<SelfLinkDeterminationTransaction> {
36 private static final Logger logger =
37 LoggerFactory.getInstance().getLogger(PerformSelfLinkDeterminationTask.class);
39 private SelfLinkDeterminationTransaction txn;
40 private ActiveInventoryAdapter aaiAdapter;
41 private Map<String, String> contextMap;
45 * Instantiates a new perform node self link processing task.
48 * @param requestParameters the request parameters
49 * @param aaiProvider the aai provider
51 public PerformSelfLinkDeterminationTask(SelfLinkDeterminationTransaction txn, String requestParameters,
52 ActiveInventoryAdapter aaiAdapter) {
54 this.aaiAdapter = aaiAdapter;
56 this.contextMap = MDC.getCopyOfContextMap();
60 * @see java.util.function.Supplier#get()
63 public SelfLinkDeterminationTransaction get() {
64 MDC.setContextMap(contextMap);
65 if (txn.getQueryString() == null) {
66 OperationResult opResult = new OperationResult();
67 opResult.setResult(500, "Aborting self-link determination because self link query is null.");
68 txn.setOpResult(opResult);
72 OperationResult opResult = null;
74 opResult = aaiAdapter.queryActiveInventoryWithRetries(txn.getQueryString(), "application/json",
75 aaiAdapter.getEndpointConfig().getNumRequestRetries(),"req");
76 } catch (Exception exc) {
77 opResult = new OperationResult();
78 opResult.setResult(500, "Querying AAI with retry failed due to an exception.");
79 logger.error(AaiUiMsgs.ERROR_AAI_QUERY_WITH_RETRY, exc.getMessage());
82 if (logger.isDebugEnabled()) {
83 logger.debug("Operation result = " + opResult.toString());
86 txn.setOpResult(opResult);