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.openecomp.sparky.synchronizer.task;
26 import java.util.function.Supplier;
28 import org.openecomp.sparky.dal.NetworkTransaction;
29 import org.openecomp.sparky.dal.aai.ActiveInventoryDataProvider;
30 import org.openecomp.sparky.dal.rest.OperationResult;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
36 * Consider abstraction the tasks into common elemnts, because most of them repeat a generic call
41 * The Class PerformActiveInventoryRetrieval.
43 public class PerformActiveInventoryRetrieval implements Supplier<NetworkTransaction> {
45 private static Logger logger = LoggerFactory.getLogger(PerformActiveInventoryRetrieval.class);
47 private NetworkTransaction txn;
48 private ActiveInventoryDataProvider aaiProvider;
49 private Map<String, String> contextMap;
52 * Instantiates a new perform active inventory retrieval.
55 * @param aaiProvider the aai provider
57 public PerformActiveInventoryRetrieval(NetworkTransaction txn,
58 ActiveInventoryDataProvider aaiProvider) {
60 this.aaiProvider = aaiProvider;
61 this.contextMap = MDC.getCopyOfContextMap();
65 * @see java.util.function.Supplier#get()
68 public NetworkTransaction get() {
72 long startTimeInMs = System.currentTimeMillis();
73 MDC.setContextMap(contextMap);
74 OperationResult result = null;
76 // todo: use proper config instead of hard-coding parameters
77 result = aaiProvider.queryActiveInventoryWithRetries(txn.getLink(), "application/json", 5);
78 } catch (Exception exc) {
79 logger.error("Failure to resolve self link from AAI. Error = ", exc);
80 result = new OperationResult(500,
81 "Caught an exception while trying to resolve link = " + exc.getMessage());
83 result.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs);
84 txn.setOperationResult(result);