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.sync.task;
26 import java.util.function.Supplier;
28 import org.onap.aai.cl.api.Logger;
29 import org.onap.aai.cl.eelf.LoggerFactory;
30 import org.onap.aai.restclient.client.OperationResult;
31 import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
32 import org.onap.aai.sparky.dal.NetworkTransaction;
33 import org.onap.aai.sparky.logging.AaiUiMsgs;
37 * Consider abstraction the tasks into common elemnts, because most of them repeat a generic call
42 * The Class PerformActiveInventoryRetrieval.
44 public class PerformActiveInventoryRetrieval implements Supplier<NetworkTransaction> {
46 private static Logger logger =
47 LoggerFactory.getInstance().getLogger(PerformActiveInventoryRetrieval.class);
49 private NetworkTransaction txn;
50 private ActiveInventoryAdapter aaiAdapter;
51 private Map<String, String> contextMap;
54 * Instantiates a new perform active inventory retrieval.
57 * @param aaiProvider the aai provider
59 public PerformActiveInventoryRetrieval(NetworkTransaction txn,
60 ActiveInventoryAdapter aaiAdapter) {
62 this.aaiAdapter = aaiAdapter;
63 this.contextMap = MDC.getCopyOfContextMap();
69 * @see java.util.function.Supplier#get()
72 public NetworkTransaction get() {
76 long startTimeInMs = System.currentTimeMillis();
77 MDC.setContextMap(contextMap);
78 OperationResult result = null;
81 final String absoluteSelfLink =
82 aaiAdapter.repairSelfLink(txn.getLink(), txn.getQueryParameters());
83 result = aaiAdapter.queryActiveInventoryWithRetries(absoluteSelfLink, "application/json", 5);
84 } catch (Exception exc) {
85 logger.error(AaiUiMsgs.ERROR_GENERIC,
86 "Failure to resolve self link from AAI. Error = " + exc.getMessage());
87 result = new OperationResult(500,
88 "Caught an exception while trying to resolve link = " + exc.getMessage());
90 txn.setOperationResult(result);
91 txn.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);
97 protected void setContextMap(Map<String, String> contextMap) {
98 this.contextMap = contextMap;