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.elasticsearch.ElasticSearchDataProvider;
33 import org.openecomp.sparky.dal.rest.OperationResult;
37 * The Class PerformElasticSearchUpdate.
39 public class PerformElasticSearchUpdate implements Supplier<NetworkTransaction> {
41 private ElasticSearchDataProvider esDataProvider;
42 private NetworkTransaction operationTracker;
43 private String updatePayload;
44 private String updateUrl;
45 private Map<String, String> contextMap;
48 * Instantiates a new perform elastic search update.
50 * @param updateUrl the update url
51 * @param updatePayload the update payload
52 * @param esDataProvider the es data provider
53 * @param transactionTracker the transaction tracker
55 public PerformElasticSearchUpdate(String updateUrl, String updatePayload,
56 ElasticSearchDataProvider esDataProvider, NetworkTransaction transactionTracker) {
57 this.updateUrl = updateUrl;
58 this.updatePayload = updatePayload;
59 this.esDataProvider = esDataProvider;
60 this.contextMap = MDC.getCopyOfContextMap();
61 this.operationTracker = new NetworkTransaction();
62 operationTracker.setEntityType(transactionTracker.getEntityType());
63 operationTracker.setDescriptor(transactionTracker.getDescriptor());
64 operationTracker.setOperationType(transactionTracker.getOperationType());
68 * @see java.util.function.Supplier#get()
71 public NetworkTransaction get() {
72 operationTracker.setTaskAgeInMs();
73 long startTimeInMs = System.currentTimeMillis();
74 MDC.setContextMap(contextMap);
75 OperationResult or = esDataProvider.doBulkOperation(updateUrl, updatePayload);
77 or.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs);
78 operationTracker.setOperationResult(or);
80 return operationTracker;