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.synchronizer.task;
26 import java.util.function.Supplier;
28 import org.onap.aai.sparky.dal.NetworkTransaction;
29 import org.onap.aai.sparky.dal.aai.ActiveInventoryDataProvider;
30 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
31 import org.onap.aai.sparky.dal.rest.OperationResult;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
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 = LoggerFactory.getLogger(PerformActiveInventoryRetrieval.class);
48 private NetworkTransaction txn;
49 private ActiveInventoryDataProvider aaiProvider;
50 private Map<String, String> contextMap;
53 * Instantiates a new perform active inventory retrieval.
56 * @param aaiProvider the aai provider
58 public PerformActiveInventoryRetrieval(NetworkTransaction txn,
59 ActiveInventoryDataProvider aaiProvider) {
61 this.aaiProvider = aaiProvider;
62 this.contextMap = MDC.getCopyOfContextMap();
66 * @see java.util.function.Supplier#get()
69 public NetworkTransaction get() {
73 long startTimeInMs = System.currentTimeMillis();
74 MDC.setContextMap(contextMap);
75 OperationResult result = null;
77 // todo: use proper config instead of hard-coding parameters
78 final String absoluteSelfLink = ActiveInventoryConfig.getConfig().repairSelfLink(txn.getLink());
79 result = aaiProvider.queryActiveInventoryWithRetries(absoluteSelfLink, "application/json", 5);
80 } catch (Exception exc) {
81 logger.error("Failure to resolve self link from AAI. Error = ", exc);
82 result = new OperationResult(500,
83 "Caught an exception while trying to resolve link = " + exc.getMessage());
85 result.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs);
86 txn.setOperationResult(result);
95 public static Logger getLogger() {
100 * @param logger the logger to set
102 public static void setLogger(Logger logger) {
103 PerformActiveInventoryRetrieval.logger = logger;
109 public NetworkTransaction getTxn() {
114 * @param txn the txn to set
116 public void setTxn(NetworkTransaction txn) {
121 * @return the aaiProvider
123 public ActiveInventoryDataProvider getAaiProvider() {
128 * @param aaiProvider the aaiProvider to set
130 public void setAaiProvider(ActiveInventoryDataProvider aaiProvider) {
131 this.aaiProvider = aaiProvider;
135 * @return the contextMap
137 public Map<String, String> getContextMap() {
142 * @param contextMap the contextMap to set
144 public void setContextMap(Map<String, String> contextMap) {
145 this.contextMap = contextMap;