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.openecomp.sparky.viewandinspect.task;
28 import java.util.function.Supplier;
30 import org.openecomp.sparky.dal.aai.ActiveInventoryDataProvider;
31 import org.openecomp.sparky.dal.aai.config.ActiveInventoryConfig;
32 import org.openecomp.sparky.dal.rest.OperationResult;
33 import org.openecomp.sparky.logging.AaiUiMsgs;
34 import org.openecomp.sparky.viewandinspect.entity.SelfLinkDeterminationTransaction;
35 import org.openecomp.cl.api.Logger;
36 import org.openecomp.cl.eelf.LoggerFactory;
39 public class PerformSelfLinkDeterminationTask implements Supplier<SelfLinkDeterminationTransaction> {
41 private static final Logger logger =
42 LoggerFactory.getInstance().getLogger(PerformSelfLinkDeterminationTask.class);
44 private SelfLinkDeterminationTransaction txn;
45 private ActiveInventoryDataProvider aaiProvider;
46 private Map<String, String> contextMap;
50 * Instantiates a new perform node self link processing task.
53 * @param requestParameters the request parameters
54 * @param aaiProvider the aai provider
56 public PerformSelfLinkDeterminationTask(SelfLinkDeterminationTransaction txn, String requestParameters,
57 ActiveInventoryDataProvider aaiProvider) {
59 this.aaiProvider = aaiProvider;
61 this.contextMap = MDC.getCopyOfContextMap();
65 * @see java.util.function.Supplier#get()
68 public SelfLinkDeterminationTransaction get() {
69 MDC.setContextMap(contextMap);
70 if (txn.getQueryString() == null) {
71 OperationResult opResult = new OperationResult();
72 opResult.setResult(500, "Aborting self-link determination because self link query is null.");
73 txn.setOpResult(opResult);
77 OperationResult opResult = null;
79 opResult = aaiProvider.queryActiveInventoryWithRetries(txn.getQueryString(), "application/json",
80 ActiveInventoryConfig.getConfig().getAaiRestConfig().getNumRequestRetries());
81 } catch (Exception exc) {
82 opResult = new OperationResult();
83 opResult.setResult(500, "Querying AAI with retry failed due to an exception.");
84 logger.error(AaiUiMsgs.ERROR_AAI_QUERY_WITH_RETRY, exc.getMessage());
87 if (logger.isDebugEnabled()) {
88 logger.debug("Operation result = " + opResult.toString());
91 txn.setOpResult(opResult);