2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
 
   6  * Copyright © 2017-2018 Amdocs
 
   7  * ================================================================================
 
   8  * Licensed under the Apache License, Version 2.0 (the "License");
 
   9  * you may not use this file except in compliance with the License.
 
  10  * You may obtain a copy of the License at
 
  12  *       http://www.apache.org/licenses/LICENSE-2.0
 
  14  * Unless required by applicable law or agreed to in writing, software
 
  15  * distributed under the License is distributed on an "AS IS" BASIS,
 
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  17  * See the License for the specific language governing permissions and
 
  18  * limitations under the License.
 
  19  * ============LICENSE_END=========================================================
 
  21 package org.onap.aai.sparky.autosuggestion.sync;
 
  23 import static java.util.concurrent.CompletableFuture.supplyAsync;
 
  25 import java.io.IOException;
 
  26 import java.util.ArrayList;
 
  27 import java.util.Arrays;
 
  28 import java.util.Collection;
 
  29 import java.util.Deque;
 
  30 import java.util.EnumSet;
 
  31 import java.util.HashMap;
 
  32 import java.util.Iterator;
 
  33 import java.util.List;
 
  35 import java.util.concurrent.ConcurrentHashMap;
 
  36 import java.util.concurrent.ConcurrentLinkedDeque;
 
  37 import java.util.concurrent.ExecutorService;
 
  38 import java.util.concurrent.atomic.AtomicInteger;
 
  39 import java.util.function.Consumer;
 
  40 import java.util.function.Supplier;
 
  42 import org.onap.aai.cl.api.Logger;
 
  43 import org.onap.aai.cl.eelf.LoggerFactory;
 
  44 import org.onap.aai.cl.mdc.MdcContext;
 
  45 import org.onap.aai.restclient.client.OperationResult;
 
  46 import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
 
  47 import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
 
  48 import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
 
  49 import org.onap.aai.sparky.config.oxm.SuggestionEntityLookup;
 
  50 import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
 
  51 import org.onap.aai.sparky.dal.NetworkTransaction;
 
  52 import org.onap.aai.sparky.dal.rest.HttpMethod;
 
  53 import org.onap.aai.sparky.logging.AaiUiMsgs;
 
  54 import org.onap.aai.sparky.search.filters.config.FiltersConfig;
 
  55 import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
 
  56 import org.onap.aai.sparky.sync.IndexSynchronizer;
 
  57 import org.onap.aai.sparky.sync.SynchronizerConstants;
 
  58 import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
 
  59 import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
 
  60 import org.onap.aai.sparky.sync.entity.SelfLinkDescriptor;
 
  61 import org.onap.aai.sparky.sync.entity.SuggestionSearchEntity;
 
  62 import org.onap.aai.sparky.sync.enumeration.OperationState;
 
  63 import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
 
  64 import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
 
  65 import org.onap.aai.sparky.sync.task.PerformSearchServicePut;
 
  66 import org.onap.aai.sparky.sync.task.PerformSearchServiceRetrieval;
 
  67 import org.onap.aai.sparky.util.NodeUtils;
 
  68 import org.onap.aai.sparky.util.SuggestionsPermutation;
 
  71 import com.fasterxml.jackson.core.JsonProcessingException;
 
  72 import com.fasterxml.jackson.databind.JsonNode;
 
  73 import com.fasterxml.jackson.databind.node.ArrayNode;
 
  76  * The Class AutosuggestionSynchronizer.
 
  78 public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
 
  79     implements IndexSynchronizer {
 
  81   private class RetrySuggestionEntitySyncContainer {
 
  82     NetworkTransaction txn;
 
  83     SuggestionSearchEntity ssec;
 
  86      * Instantiates a new RetrySuggestionEntitySyncContainer.
 
  89      * @param icer the icer
 
  91     public RetrySuggestionEntitySyncContainer(NetworkTransaction txn, SuggestionSearchEntity icer) {
 
  96     public NetworkTransaction getNetworkTransaction() {
 
 100     public SuggestionSearchEntity getSuggestionSearchEntity() {
 
 105   private static final Logger LOG =
 
 106       LoggerFactory.getInstance().getLogger(AutosuggestionSynchronizer.class);
 
 107   private static final String INSERTION_DATE_TIME_FORMAT = "yyyyMMdd'T'HHmmssZ";
 
 109   private boolean allWorkEnumerated;
 
 110   private Deque<SelfLinkDescriptor> selflinks;
 
 111   private ConcurrentHashMap<String, AtomicInteger> entityCounters;
 
 112   private boolean syncInProgress;
 
 113   private Map<String, String> contextMap;
 
 114   protected ExecutorService esPutExecutor;
 
 115   private Deque<RetrySuggestionEntitySyncContainer> retryQueue;
 
 116   private Map<String, Integer> retryLimitTracker;
 
 117   private OxmEntityLookup oxmEntityLookup;
 
 118   private SuggestionEntityLookup suggestionEntityLookup;
 
 119   private FiltersConfig filtersConfig;
 
 122    * Instantiates a new historical entity summarizer.
 
 124    * @throws Exception the exception
 
 126   public AutosuggestionSynchronizer(ElasticSearchSchemaConfig schemaConfig, int internalSyncWorkers,
 
 127       int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
 
 128       NetworkStatisticsConfig esStatConfig, OxmEntityLookup oxmEntityLookup,
 
 129       SuggestionEntityLookup suggestionEntityLookup, FiltersConfig filtersConfig) throws Exception {
 
 131     super(LOG, "ASES-" + schemaConfig.getIndexName().toUpperCase(), internalSyncWorkers, aaiWorkers,
 
 132         esWorkers, schemaConfig.getIndexName(), aaiStatConfig, esStatConfig);
 
 134     this.oxmEntityLookup = oxmEntityLookup;
 
 135     this.suggestionEntityLookup = suggestionEntityLookup;
 
 136     this.allWorkEnumerated = false;
 
 137     this.selflinks = new ConcurrentLinkedDeque<SelfLinkDescriptor>();
 
 138     this.entityCounters = new ConcurrentHashMap<String, AtomicInteger>();
 
 139     this.synchronizerName = "Autosuggestion Entity Synchronizer";
 
 140     this.enabledStatFlags = EnumSet.of(StatFlag.AAI_REST_STATS, StatFlag.ES_REST_STATS);
 
 141     this.syncInProgress = false;
 
 142     this.contextMap = MDC.getCopyOfContextMap();
 
 143     this.esPutExecutor = NodeUtils.createNamedExecutor("SUES-ES-PUT", 5, LOG);
 
 144     this.retryQueue = new ConcurrentLinkedDeque<RetrySuggestionEntitySyncContainer>();
 
 145     this.retryLimitTracker = new ConcurrentHashMap<String, Integer>();
 
 146     this.syncDurationInMs = -1;
 
 147     this.filtersConfig = filtersConfig;
 
 151    * Collect all the work.
 
 153    * @return the operation state
 
 155   private OperationState collectAllTheWork() {
 
 156     final Map<String, String> contextMap = MDC.getCopyOfContextMap();
 
 157     Map<String, SuggestionEntityDescriptor> descriptorMap =
 
 158         suggestionEntityLookup.getSuggestionSearchEntityDescriptors();
 
 160     if (descriptorMap.isEmpty()) {
 
 161       this.allWorkEnumerated = true;
 
 162       LOG.error(AaiUiMsgs.ERROR_LOADING_OXM_SUGGESTIBLE_ENTITIES);
 
 163       LOG.info(AaiUiMsgs.ERROR_LOADING_OXM_SUGGESTIBLE_ENTITIES);
 
 164       return OperationState.ERROR;
 
 167     Collection<String> syncTypes = descriptorMap.keySet();
 
 172        * launch a parallel async thread to process the documents for each entity-type (to max the of
 
 173        * the configured executor anyway)
 
 176       aaiWorkOnHand.set(syncTypes.size());
 
 178       for (String key : syncTypes) {
 
 180         supplyAsync(new Supplier<Void>() {
 
 184             MDC.setContextMap(contextMap);
 
 185             OperationResult typeLinksResult = null;
 
 187               typeLinksResult = aaiAdapter.getSelfLinksByEntityType(key);
 
 188               aaiWorkOnHand.decrementAndGet();
 
 189               processEntityTypeSelfLinks(typeLinksResult);
 
 190             } catch (Exception exc) {
 
 191               LOG.error(AaiUiMsgs.ERROR_GENERIC,
 
 192                   "An error occurred while processing entity self-links. Error: "
 
 199         }, aaiExecutor).whenComplete((result, error) -> {
 
 202             LOG.error(AaiUiMsgs.ERROR_GENERIC,
 
 203                 "An error occurred getting data from AAI. Error = " + error.getMessage());
 
 209       while (aaiWorkOnHand.get() != 0) {
 
 211         if (LOG.isDebugEnabled()) {
 
 212           LOG.debug(AaiUiMsgs.WAIT_FOR_ALL_SELFLINKS_TO_BE_COLLECTED);
 
 218       aaiWorkOnHand.set(selflinks.size());
 
 219       allWorkEnumerated = true;
 
 222       while (!isSyncDone()) {
 
 228        * Make sure we don't hang on to retries that failed which could cause issues during future
 
 231       retryLimitTracker.clear();
 
 233     } catch (Exception exc) {
 
 234       LOG.error(AaiUiMsgs.ERROR_GENERIC,
 
 235           "An error occurred while performing the sync.  Error: " + exc.getMessage());
 
 238     return OperationState.OK;
 
 245    * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#doSync()
 
 248   public OperationState doSync() {
 
 249     this.syncDurationInMs = -1;
 
 250     syncStartedTimeStampInMs = System.currentTimeMillis();
 
 251     String txnID = NodeUtils.getRandomTxnId();
 
 252     MdcContext.initialize(txnID, "AutosuggestionSynchronizer", "", "Sync", "");
 
 254     return collectAllTheWork();
 
 258    * Process entity type self links.
 
 260    * @param operationResult the operation result
 
 262   private void processEntityTypeSelfLinks(OperationResult operationResult) {
 
 264     if (operationResult == null) {
 
 268     final String jsonResult = operationResult.getResult();
 
 270     if (jsonResult != null && jsonResult.length() > 0 && operationResult.wasSuccessful()) {
 
 273         JsonNode rootNode = mapper.readTree(jsonResult);
 
 274         JsonNode resultData = rootNode.get("result-data");
 
 276         if (resultData.isArray()) {
 
 277           ArrayNode resultDataArrayNode = (ArrayNode) resultData;
 
 279           Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
 
 281           while (elementIterator.hasNext()) {
 
 282             JsonNode element = elementIterator.next();
 
 284             final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
 
 285             final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
 
 287             if (resourceType != null && resourceLink != null) {
 
 289               OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(resourceType);
 
 291               if (descriptor == null) {
 
 292                 LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
 
 293                 // go to next element in iterator
 
 296               selflinks.add(new SelfLinkDescriptor(resourceLink,
 
 297                       SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
 
 301       } catch (IOException exc) {
 
 302         String message = "Could not deserialize JSON (representing operation result) as node tree. "
 
 303                 + "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
 
 304         LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
 
 312   private void syncEntityTypes() {
 
 314     while (selflinks.peek() != null) {
 
 316       SelfLinkDescriptor linkDescriptor = selflinks.poll();
 
 317       aaiWorkOnHand.decrementAndGet();
 
 319       OxmEntityDescriptor descriptor = null;
 
 321       if (linkDescriptor.getSelfLink() != null && linkDescriptor.getEntityType() != null) {
 
 323         descriptor = oxmEntityLookup.getEntityDescriptors().get(linkDescriptor.getEntityType());
 
 325         if (descriptor == null) {
 
 326           LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, linkDescriptor.getEntityType());
 
 327           // go to next element in iterator
 
 331         NetworkTransaction txn = new NetworkTransaction();
 
 332         txn.setDescriptor(descriptor);
 
 333         txn.setLink(linkDescriptor.getSelfLink());
 
 334         txn.setOperationType(HttpMethod.GET);
 
 335         txn.setEntityType(linkDescriptor.getEntityType());
 
 337         aaiWorkOnHand.incrementAndGet();
 
 339         supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter,"sync"), aaiExecutor)
 
 340             .whenComplete((result, error) -> {
 
 342               aaiWorkOnHand.decrementAndGet();
 
 345                 LOG.error(AaiUiMsgs.AAI_RETRIEVAL_FAILED_GENERIC, error.getLocalizedMessage());
 
 347                 if (result == null) {
 
 348                   LOG.error(AaiUiMsgs.AAI_RETRIEVAL_FAILED_FOR_SELF_LINK,
 
 349                       linkDescriptor.getSelfLink());
 
 351                   updateActiveInventoryCounters(result);
 
 352                   fetchDocumentForUpsert(result);
 
 363    * Return a set of valid suggestion attributes for the provided entityName that are present in the
 
 366    * @param node JSON node in which the attributes should be found
 
 368    * @param entityName Name of the entity
 
 370    * @return List of all valid suggestion attributes(key's)
 
 372   public List<String> getSuggestableAttrNamesFromReponse(JsonNode node, String entityName) {
 
 373     List<String> suggestableAttr = new ArrayList<String>();
 
 375     HashMap<String, String> desc =
 
 376         suggestionEntityLookup.getSuggestionSearchEntityOxmModel().get(entityName);
 
 380       String attr = desc.get("suggestibleAttributes");
 
 383         suggestableAttr = Arrays.asList(attr.split(","));
 
 384         List<String> suggestableValue = new ArrayList<>();
 
 385         for (String attribute : suggestableAttr) {
 
 386           if (node.get(attribute) != null && node.get(attribute).asText().length() > 0) {
 
 387             suggestableValue.add(attribute);
 
 390         return suggestableValue;
 
 394     return new ArrayList<>();
 
 398    * Fetch all the documents for upsert. Based on the number of permutations that are available the
 
 399    * number of documents will be different
 
 403   private void fetchDocumentForUpsert(NetworkTransaction txn) {
 
 404     if (!txn.getOperationResult().wasSuccessful()) {
 
 405       String message = "Self link failure. Result - " + txn.getOperationResult().getResult();
 
 406       LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
 
 410       final String jsonResult = txn.getOperationResult().getResult();
 
 412       if (jsonResult != null && jsonResult.length() > 0) {
 
 414         // Step 1: Calculate the number of possible permutations of attributes
 
 415         String entityName = txn.getDescriptor().getEntityName();
 
 416         JsonNode entityNode = mapper.readTree(jsonResult);
 
 418         List<String> availableSuggestableAttrName =
 
 419             getSuggestableAttrNamesFromReponse(entityNode, entityName);
 
 421         ArrayList<ArrayList<String>> uniqueLists =
 
 422             SuggestionsPermutation.getNonEmptyUniqueLists(availableSuggestableAttrName);
 
 423         // Now we have a list of all possible permutations for the status that are
 
 424         // defined for this entity type. Try inserting a document for every combination.
 
 425         for (ArrayList<String> uniqueList : uniqueLists) {
 
 427           SuggestionSearchEntity sse = new SuggestionSearchEntity(filtersConfig, suggestionEntityLookup);
 
 428           sse.setSuggestableAttr(uniqueList);
 
 429           sse.setFilterBasedPayloadFromResponse(entityNode, entityName, uniqueList);
 
 430           sse.setLink(ActiveInventoryAdapter.extractResourcePath(txn.getLink()));
 
 431           populateSuggestionSearchEntityDocument(sse, jsonResult, txn);
 
 432           // The unique id for the document will be created at derive fields
 
 434           // Insert the document only if it has valid statuses
 
 435           if (sse.isSuggestableDoc()) {
 
 438               link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), sse.getId());
 
 439             } catch (Exception exc) {
 
 440               LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY, exc.getLocalizedMessage());
 
 444               NetworkTransaction n2 = new NetworkTransaction();
 
 446               n2.setEntityType(txn.getEntityType());
 
 447               n2.setDescriptor(txn.getDescriptor());
 
 448               n2.setOperationType(HttpMethod.GET);
 
 450               esWorkOnHand.incrementAndGet();
 
 452               supplyAsync(new PerformSearchServiceRetrieval(n2, searchServiceAdapter), esExecutor)
 
 453               .whenComplete((result, error) -> {
 
 455                     esWorkOnHand.decrementAndGet();
 
 458                       LOG.error(AaiUiMsgs.ES_RETRIEVAL_FAILED, error.getLocalizedMessage());
 
 460                       updateElasticSearchCounters(result);
 
 461                       performDocumentUpsert(result, sse);
 
 468     } catch (JsonProcessingException exc) {
 
 469         LOG.error(AaiUiMsgs.ERROR_GENERIC, "There was a json processing error while processing the result from elasticsearch. Error: " + exc.getMessage());
 
 470     } catch (IOException exc) {
 
 471         LOG.error(AaiUiMsgs.ERROR_GENERIC, "There was a io processing error while processing the result from elasticsearch. Error: " + exc.getMessage());
 
 475   protected void populateSuggestionSearchEntityDocument(SuggestionSearchEntity sse, String result,
 
 476       NetworkTransaction txn) throws JsonProcessingException, IOException {
 
 478     OxmEntityDescriptor resultDescriptor = txn.getDescriptor();
 
 480     sse.setEntityType(resultDescriptor.getEntityName());
 
 482     JsonNode entityNode = mapper.readTree(result);
 
 484     List<String> primaryKeyValues = new ArrayList<String>();
 
 485     String pkeyValue = null;
 
 487     for (String keyName : resultDescriptor.getPrimaryKeyAttributeNames()) {
 
 488       pkeyValue = NodeUtils.getNodeFieldAsText(entityNode, keyName);
 
 489       if (pkeyValue != null) {
 
 490         primaryKeyValues.add(pkeyValue);
 
 492         String message = "populateSuggestionSearchEntityDocument(),"
 
 493             + " pKeyValue is null for entityType = " + resultDescriptor.getEntityName();
 
 494         LOG.warn(AaiUiMsgs.WARN_GENERIC, message);
 
 498     final String primaryCompositeKeyValue = NodeUtils.concatArray(primaryKeyValues, "/");
 
 499     sse.setEntityPrimaryKeyValue(primaryCompositeKeyValue);
 
 500     sse.generateSuggestionInputPermutations();
 
 503   protected void performDocumentUpsert(NetworkTransaction esGetTxn, SuggestionSearchEntity sse) {
 
 507      * As part of the response processing we need to do the following:
 
 508      * <li>1. Extract the version (if present), it will be the ETAG when we use the
 
 509      * Search-Abstraction-Service
 
 510      * <li>2. Spawn next task which is to do the PUT operation into elastic with or with the version
 
 512      * <li>a) if version is null or RC=404, then standard put, no _update with version tag
 
 513      * <li>b) if version != null, do PUT with _update?version= versionNumber in the URI to elastic
 
 519       link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), sse.getId());
 
 520     } catch (Exception exc) {
 
 521       LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
 
 525     boolean wasEntryDiscovered = false;
 
 526     if (esGetTxn.getOperationResult().getResultCode() == 404) {
 
 527       LOG.info(AaiUiMsgs.ES_SIMPLE_PUT, sse.getEntityPrimaryKeyValue());
 
 528     } else if (esGetTxn.getOperationResult().getResultCode() == 200) {
 
 529       wasEntryDiscovered = true;
 
 532        * Not being a 200 does not mean a failure. eg 201 is returned for created. and 500 for es not
 
 533        * found TODO -> Should we return.
 
 535       LOG.error(AaiUiMsgs.ES_OPERATION_RETURN_CODE,
 
 536           String.valueOf(esGetTxn.getOperationResult().getResultCode()));
 
 539     // Insert a new document only if the paylod is different.
 
 540     // This is determined by hashing the payload and using it as a id for the document
 
 542     if (!wasEntryDiscovered) {
 
 544         String jsonPayload = null;
 
 546         jsonPayload = sse.getAsJson();
 
 547         if (link != null && jsonPayload != null) {
 
 549           NetworkTransaction updateElasticTxn = new NetworkTransaction();
 
 550           updateElasticTxn.setLink(link);
 
 551           updateElasticTxn.setEntityType(esGetTxn.getEntityType());
 
 552           updateElasticTxn.setDescriptor(esGetTxn.getDescriptor());
 
 553           updateElasticTxn.setOperationType(HttpMethod.PUT);
 
 555           esWorkOnHand.incrementAndGet();
 
 556           supplyAsync(new PerformSearchServicePut(jsonPayload, updateElasticTxn, searchServiceAdapter),
 
 557                   esPutExecutor).whenComplete((result, error) -> {
 
 559                 esWorkOnHand.decrementAndGet();
 
 562                   String message = "Suggestion search entity sync UPDATE PUT error - "
 
 563                       + error.getLocalizedMessage();
 
 564                   LOG.error(AaiUiMsgs.ES_SUGGESTION_SEARCH_ENTITY_SYNC_ERROR, message);
 
 566                   updateElasticSearchCounters(result);
 
 567                   processStoreDocumentResult(result, esGetTxn, sse);
 
 571       } catch (Exception exc) {
 
 573             "Exception caught during suggestion search entity sync PUT operation. Message - "
 
 574                 + exc.getLocalizedMessage();
 
 575         LOG.error(AaiUiMsgs.ES_SUGGESTION_SEARCH_ENTITY_SYNC_ERROR, message);
 
 580   private void processStoreDocumentResult(NetworkTransaction esPutResult,
 
 581       NetworkTransaction esGetResult, SuggestionSearchEntity sse) {
 
 583     OperationResult or = esPutResult.getOperationResult();
 
 585     if (!or.wasSuccessful()) {
 
 586       if (or.getResultCode() == VERSION_CONFLICT_EXCEPTION_CODE) {
 
 588         if (shouldAllowRetry(sse.getId())) {
 
 589           esWorkOnHand.incrementAndGet();
 
 591           RetrySuggestionEntitySyncContainer rssec =
 
 592               new RetrySuggestionEntitySyncContainer(esGetResult, sse);
 
 593           retryQueue.push(rssec);
 
 595           String message = "Store document failed during suggestion search entity synchronization"
 
 596               + " due to version conflict. Entity will be re-synced.";
 
 597           LOG.warn(AaiUiMsgs.ES_SUGGESTION_SEARCH_ENTITY_SYNC_ERROR, message);
 
 601             "Store document failed during suggestion search entity synchronization with result code "
 
 602                 + or.getResultCode() + " and result message " + or.getResult();
 
 603         LOG.error(AaiUiMsgs.ES_SUGGESTION_SEARCH_ENTITY_SYNC_ERROR, message);
 
 609    * Perform retry sync.
 
 611   private void performRetrySync() {
 
 612     while (retryQueue.peek() != null) {
 
 614       RetrySuggestionEntitySyncContainer susc = retryQueue.poll();
 
 617         SuggestionSearchEntity sus = susc.getSuggestionSearchEntity();
 
 618         NetworkTransaction txn = susc.getNetworkTransaction();
 
 620         final Consumer<NetworkTransaction> networkTransactionConsumer = (result) ->  performDocumentUpsert(result, sus);
 
 621         performRetrySync(sus.getId(), networkTransactionConsumer, txn);
 
 628    * Should allow retry.
 
 631    * @return true, if successful
 
 633   private boolean shouldAllowRetry(String id) {
 
 634     boolean isRetryAllowed = true;
 
 635     if (retryLimitTracker.get(id) != null) {
 
 636       Integer currentCount = retryLimitTracker.get(id);
 
 637       if (currentCount.intValue() >= RETRY_COUNT_PER_ENTITY_LIMIT.intValue()) {
 
 638         isRetryAllowed = false;
 
 639         String message = "Searchable entity re-sync limit reached for " + id
 
 640             + ", re-sync will no longer be attempted for this entity";
 
 641         LOG.error(AaiUiMsgs.ES_SEARCHABLE_ENTITY_SYNC_ERROR, message);
 
 643         Integer newCount = new Integer(currentCount.intValue() + 1);
 
 644         retryLimitTracker.put(id, newCount);
 
 647       Integer firstRetryCount = new Integer(1);
 
 648       retryLimitTracker.put(id, firstRetryCount);
 
 651     return isRetryAllowed;
 
 657   public SynchronizerState getState() {
 
 660       return SynchronizerState.PERFORMING_SYNCHRONIZATION;
 
 663     return SynchronizerState.IDLE;
 
 670    * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
 
 673   public String getStatReport(boolean showFinalReport) {
 
 674     syncDurationInMs = System.currentTimeMillis() - syncStartedTimeStampInMs;
 
 675     return getStatReport(syncDurationInMs, showFinalReport);
 
 681    * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#shutdown()
 
 684   public void shutdown() {
 
 685     this.shutdownExecutors();
 
 689   protected boolean isSyncDone() {
 
 691     int totalWorkOnHand = aaiWorkOnHand.get() + esWorkOnHand.get();
 
 693     if (LOG.isDebugEnabled()) {
 
 694       LOG.debug(AaiUiMsgs.DEBUG_GENERIC, indexName + ", isSyncDone(), totalWorkOnHand = "
 
 695           + totalWorkOnHand + " all work enumerated = " + allWorkEnumerated);
 
 698     if (totalWorkOnHand > 0 || !allWorkEnumerated) {
 
 702     this.syncInProgress = false;
 
 710    * @see org.openecomp.sparky.synchronizer.AbstractEntitySynchronizer#clearCache()
 
 713   public void clearCache() {
 
 715     if (syncInProgress) {
 
 716       LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
 
 717           "Autosuggestion Entity Summarizer in progress, request to clear cache ignored");
 
 722     this.resetCounters();
 
 723     if (entityCounters != null) {
 
 724       entityCounters.clear();
 
 727     allWorkEnumerated = false;