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.restclient.client.OperationResult;
31 import org.onap.aai.sparky.dal.ElasticSearchAdapter;
32 import org.onap.aai.sparky.dal.NetworkTransaction;
36 * The Class PerformElasticSearchUpdate.
38 public class PerformElasticSearchUpdate implements Supplier<NetworkTransaction> {
40 private ElasticSearchAdapter esAdapter;
41 private NetworkTransaction operationTracker;
42 private String updatePayload;
43 private String updateUrl;
44 private Map<String, String> contextMap;
47 * Instantiates a new perform elastic search update.
49 * @param updateUrl the update url
50 * @param updatePayload the update payload
51 * @param esDataProvider the es data provider
52 * @param transactionTracker the transaction tracker
54 public PerformElasticSearchUpdate(String updateUrl, String updatePayload,
55 ElasticSearchAdapter esAdapter, NetworkTransaction transactionTracker) {
56 this.updateUrl = updateUrl;
57 this.updatePayload = updatePayload;
58 this.esAdapter = esAdapter;
59 this.contextMap = MDC.getCopyOfContextMap();
60 this.operationTracker = new NetworkTransaction();
61 operationTracker.setEntityType(transactionTracker.getEntityType());
62 operationTracker.setDescriptor(transactionTracker.getDescriptor());
63 operationTracker.setOperationType(transactionTracker.getOperationType());
69 * @see java.util.function.Supplier#get()
72 public NetworkTransaction get() {
73 operationTracker.setTaskAgeInMs();
74 MDC.setContextMap(contextMap);
75 long startTimeInMs = System.currentTimeMillis();
76 OperationResult or = esAdapter.doBulkOperation(updateUrl, updatePayload);
77 operationTracker.setOperationResult(or);
78 operationTracker.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);
79 return operationTracker;