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.onap.aai.sparky.sync.task;
28 import java.util.function.Supplier;
30 import org.onap.aai.cl.api.Logger;
31 import org.onap.aai.cl.eelf.LoggerFactory;
32 import org.onap.aai.restclient.client.OperationResult;
33 import org.onap.aai.sparky.dal.GizmoAdapter;
34 import org.onap.aai.sparky.dal.NetworkTransaction;
35 import org.onap.aai.sparky.logging.AaiUiMsgs;
39 * Consider abstraction the tasks into common elemnts, because most of them repeat a generic call
44 * The Class PerformActiveInventoryRetrieval.
46 public class PerformGizmoRetrieval implements Supplier<NetworkTransaction> {
48 private static Logger logger = LoggerFactory.getInstance().getLogger(PerformGizmoRetrieval.class);
50 private NetworkTransaction txn;
51 private GizmoAdapter gizmoAdapter;
52 private Map<String, String> contextMap;
55 * Instantiates a new perform active inventory retrieval.
58 * @param aaiProvider the aai provider
60 public PerformGizmoRetrieval(NetworkTransaction txn,
61 GizmoAdapter gizmoAdapter) {
63 this.gizmoAdapter = gizmoAdapter;
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 result = gizmoAdapter.queryGizmoWithRetries(txn.getLink(), "application/json", 5);
80 } catch (Exception exc) {
81 logger.error(AaiUiMsgs.ERROR_GENERIC,"Failure to resolve self link from AAI. Error = " + exc.getMessage());
82 result = new OperationResult(500,
83 "Caught an exception while trying to resolve link = " + exc.getMessage());
85 txn.setOperationResult(result);
86 txn.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);
92 protected void setContextMap(Map<String, String> contextMap) {
93 this.contextMap = contextMap;