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