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