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 javax.ws.rs.core.MediaType;
32 import org.onap.aai.restclient.client.OperationResult;
33 import org.onap.aai.sparky.dal.ElasticSearchAdapter;
34 import org.onap.aai.sparky.dal.NetworkTransaction;
38 * The Class PerformElasticSearchPut.
40 public class PerformElasticSearchPut implements Supplier<NetworkTransaction> {
42 private ElasticSearchAdapter esAdapter;
43 private String jsonPayload;
44 private NetworkTransaction txn;
45 private Map<String, String> contextMap;
48 * Instantiates a new perform elastic search put.
50 * @param jsonPayload the json payload
52 * @param restDataProvider the rest data provider
54 public PerformElasticSearchPut(String jsonPayload, NetworkTransaction txn,
55 ElasticSearchAdapter esAdapter) {
56 this.jsonPayload = jsonPayload;
58 this.esAdapter = esAdapter;
59 this.contextMap = MDC.getCopyOfContextMap();
62 public PerformElasticSearchPut(String jsonPayload, NetworkTransaction txn,
63 ElasticSearchAdapter esAdapter, Map<String, String> contextMap) {
64 this.jsonPayload = jsonPayload;
66 this.esAdapter = esAdapter;
67 this.contextMap = contextMap;
73 * @see java.util.function.Supplier#get()
76 public NetworkTransaction get() {
78 MDC.setContextMap(contextMap);
80 long startTimeInMs = System.currentTimeMillis();
83 esAdapter.doPut(txn.getLink(), jsonPayload, MediaType.APPLICATION_JSON_TYPE);
85 txn.setOperationResult(or);
86 txn.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);