Adding interfaces in documentation
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / sync / task / PerformElasticSearchUpdate.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.onap.aai.sparky.sync.task;
26
27 import java.util.Map;
28 import java.util.function.Supplier;
29
30 import org.onap.aai.restclient.client.OperationResult;
31 import org.onap.aai.sparky.dal.ElasticSearchAdapter;
32 import org.onap.aai.sparky.dal.NetworkTransaction;
33 import org.slf4j.MDC;
34
35 /**
36  * The Class PerformElasticSearchUpdate.
37  */
38 public class PerformElasticSearchUpdate implements Supplier<NetworkTransaction> {
39
40   private ElasticSearchAdapter esAdapter;
41   private NetworkTransaction operationTracker;
42   private String updatePayload;
43   private String updateUrl;
44   private Map<String, String> contextMap;
45
46   /**
47    * Instantiates a new perform elastic search update.
48    *
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
53    */
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());
64   }
65
66   /*
67    * (non-Javadoc)
68    * 
69    * @see java.util.function.Supplier#get()
70    */
71   @Override
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;
80   }
81
82 }