summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/aai/sparky/synchronizer/SyncHelper.java
blob: 9081d41a939a712441fc2f00bcdf560d3e4c1ea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
/**
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 * Copyright © 2017 Amdocs
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 *
 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 */
package org.onap.aai.sparky.synchronizer;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.lang.Thread.UncaughtExceptionHandler;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
import org.onap.aai.sparky.config.oxm.OxmModelLoader;
import org.onap.aai.sparky.dal.aai.ActiveInventoryAdapter;
import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
import org.onap.aai.sparky.dal.aai.config.ActiveInventoryRestConfig;
import org.onap.aai.sparky.dal.cache.EntityCache;
import org.onap.aai.sparky.dal.cache.InMemoryEntityCache;
import org.onap.aai.sparky.dal.cache.PersistentEntityCache;
import org.onap.aai.sparky.dal.elasticsearch.ElasticSearchAdapter;
import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
import org.onap.aai.sparky.dal.rest.RestClientBuilder;
import org.onap.aai.sparky.dal.rest.RestfulDataAccessor;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.synchronizer.SyncController.SyncActions;
import org.onap.aai.sparky.synchronizer.config.SynchronizerConfiguration;
import org.onap.aai.sparky.synchronizer.config.SynchronizerConstants;
import org.onap.aai.sparky.synchronizer.enumeration.SynchronizerState;
import org.onap.aai.sparky.util.ErrorUtil;
import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.slf4j.MDC;

/**
 * The Class SyncHelper.
 *
 * @author davea.
 */
public class SyncHelper {

  private final Logger LOG = LoggerFactory.getInstance().getLogger(SyncHelper.class);
  private SyncController syncController = null;
  private SyncController entityCounterHistorySummarizer = null;

  private ScheduledExecutorService oneShotExecutor = Executors.newSingleThreadScheduledExecutor();
  private ScheduledExecutorService periodicExecutor = null;
  private ScheduledExecutorService historicalExecutor =
      Executors.newSingleThreadScheduledExecutor();

  private SynchronizerConfiguration syncConfig;
  private ElasticSearchConfig esConfig;
  private OxmModelLoader oxmModelLoader;

  private Boolean initialSyncRunning = false;
  private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
  private AtomicLong timeNextSync = new AtomicLong();
  Map<String, String> contextMap;

  /**
   * The Class SyncTask.
   */
  private class SyncTask implements Runnable {

    private boolean isInitialSync;

    public boolean isInitialSync() {
      return isInitialSync;
    }

    public void setInitialSync(boolean isInitialSync) {
      this.isInitialSync = isInitialSync;
    }

    /**
     * Instantiates a new sync task.
     *
     * @param initialSync the initial sync
     */
    public SyncTask(boolean initialSync) {
      this.isInitialSync = initialSync;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Runnable#run()
     */
    @Override
    public void run() {
      long opStartTime = System.currentTimeMillis();
      MDC.setContextMap(contextMap);

      LOG.info(AaiUiMsgs.SEARCH_ENGINE_SYNC_STARTED, sdf.format(opStartTime)
          .replaceAll(SynchronizerConstants.TIME_STD, SynchronizerConstants.TIME_CONFIG_STD));

      try {

        if (syncController == null) {
          LOG.error(AaiUiMsgs.SYNC_SKIPPED_SYNCCONTROLLER_NOT_INITIALIZED);
          return;
        }

        int taskFrequencyInDays = SynchronizerConfiguration.getConfig().getSyncTaskFrequencyInDay();

        /*
         * Do nothing if the initial start-up sync hasn't finished yet, but the regular sync
         * scheduler fired up a regular sync.
         */
        if (!initialSyncRunning) {
          if (isInitialSync) {
            initialSyncRunning = true;
          } else {
            // update 'timeNextSync' for periodic sync
            timeNextSync.getAndAdd(taskFrequencyInDays * SynchronizerConstants.MILLISEC_IN_A_DAY);

          }

          LOG.info(AaiUiMsgs.INFO_GENERIC, "SyncTask, starting syncrhonization");

          syncController.performAction(SyncActions.SYNCHRONIZE);

          while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
            Thread.sleep(1000);
          }

        } else {
          LOG.info(AaiUiMsgs.SKIP_PERIODIC_SYNC_AS_SYNC_DIDNT_FINISH, sdf.format(opStartTime)
              .replaceAll(SynchronizerConstants.TIME_STD, SynchronizerConstants.TIME_CONFIG_STD));

          return;
        }

        long opEndTime = System.currentTimeMillis();

        if (isInitialSync) {
          /*
           * Handle corner case when start-up sync operation overlapped with a scheduled
           * sync-start-time. Note that the scheduled sync does nothing if 'initialSyncRunning' is
           * TRUE. So the actual next-sync is one more sync-cycle away
           */
          long knownNextSyncTime = timeNextSync.get();
          if (knownNextSyncTime != SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS
              && opEndTime > knownNextSyncTime) {
            timeNextSync.compareAndSet(knownNextSyncTime,
                knownNextSyncTime + taskFrequencyInDays * SynchronizerConstants.MILLISEC_IN_A_DAY);
            initialSyncRunning = false;
          }
        }

        String durationMessage =
            String.format(syncController.getControllerName() + " synchronization took '%d' ms.",
                (opEndTime - opStartTime));

        LOG.info(AaiUiMsgs.SYNC_DURATION, durationMessage);

        // Provide log about the time for next synchronization
        if (syncConfig.isConfigOkForPeriodicSync()
            && timeNextSync.get() != SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS) {
          TimeZone tz = TimeZone.getTimeZone(syncConfig.getSyncTaskStartTimeTimeZone());
          sdf.setTimeZone(tz);
          if (opEndTime - opStartTime > taskFrequencyInDays
              * SynchronizerConstants.MILLISEC_IN_A_DAY) {
            String durationWasLongerMessage = String.format(
                syncController.getControllerName()
                    + " synchronization took '%d' ms which is larger than"
                    + " synchronization interval of '%d' ms.",
                (opEndTime - opStartTime),
                taskFrequencyInDays * SynchronizerConstants.MILLISEC_IN_A_DAY);

            LOG.info(AaiUiMsgs.SYNC_DURATION, durationWasLongerMessage);
          }

          LOG.info(AaiUiMsgs.SYNC_TO_BEGIN, syncController.getControllerName(),
              sdf.format(timeNextSync).replaceAll(SynchronizerConstants.TIME_STD,
                  SynchronizerConstants.TIME_CONFIG_STD));
        }

      } catch (Exception exc) {
        String message = "Caught an exception while attempt to synchronize elastic search "
            + "with an error cause = " + ErrorUtil.extractStackTraceElements(5, exc);
        LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
      }

    }

  }


  /**
   * Gets the first sync time.
   *
   * @param calendar the calendar
   * @param timeNow the time now
   * @param taskFreqInDay the task freq in day
   * @return the first sync time
   */
  public long getFirstSyncTime(Calendar calendar, long timeNow, int taskFreqInDay) {
    if (taskFreqInDay == SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS) {
      return SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS;
    } else if (timeNow > calendar.getTimeInMillis()) {
      calendar.add(Calendar.DAY_OF_MONTH, taskFreqInDay);
    }
    return calendar.getTimeInMillis();
  }

  /**
   * Boot strap and configure the moving pieces of the Sync Controller.
   */

  private void initializeSyncController() {

    try {

      /*
       * TODO: it would be nice to have XML IoC / dependency injection kind of thing for these
       * pieces maybe Spring?
       */

      /*
       * Sync Controller itself
       */

      syncController = new SyncController("entitySyncController");

      /*
       * Create common elements
       */

      ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
      ActiveInventoryRestConfig aaiRestConfig =
          ActiveInventoryConfig.getConfig().getAaiRestConfig();


      EntityCache cache = null;

      if (aaiRestConfig.isCacheEnabled()) {
        cache = new PersistentEntityCache(aaiRestConfig.getStorageFolderOverride(),
            aaiRestConfig.getNumCacheWorkers());
      } else {
        cache = new InMemoryEntityCache();
      }

      RestClientBuilder clientBuilder = new RestClientBuilder();

      aaiAdapter.setCacheEnabled(true);
      aaiAdapter.setEntityCache(cache);

      clientBuilder.setUseHttps(false);

      RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);

      ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
      ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig);

      /*
       * Register Index Validators
       */

      IndexIntegrityValidator entitySearchIndexValidator =
          new IndexIntegrityValidator(nonCachingRestProvider, esConfig.getIndexName(),
              esConfig.getType(), esConfig.getIpAddress(), esConfig.getHttpPort(),
              esConfig.buildElasticSearchTableConfig());

      syncController.registerIndexValidator(entitySearchIndexValidator);

      // TODO: Insert IndexValidator for TopographicalEntityIndex
      // we should have one, but one isn't 100% required as none of the fields are analyzed

      /*
       * Register Synchronizers
       */

      SearchableEntitySynchronizer ses = new SearchableEntitySynchronizer(esConfig.getIndexName());
      ses.setAaiDataProvider(aaiAdapter);
      ses.setEsDataProvider(esAdapter);
      syncController.registerEntitySynchronizer(ses);

      CrossEntityReferenceSynchronizer cers = new CrossEntityReferenceSynchronizer(
          esConfig.getIndexName(), ActiveInventoryConfig.getConfig());
      cers.setAaiDataProvider(aaiAdapter);
      cers.setEsDataProvider(esAdapter);
      syncController.registerEntitySynchronizer(cers);

      if (syncConfig.isAutosuggestSynchronizationEnabled()) {
        initAutoSuggestionSynchronizer(esConfig, aaiAdapter, esAdapter, nonCachingRestProvider);
        initAggregationSynchronizer(esConfig, aaiAdapter, esAdapter, nonCachingRestProvider);
      }

      /*
       * Register Cleaners
       */

      IndexCleaner searchableIndexCleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
          esConfig.getIndexName(), esConfig.getType(), esConfig.getIpAddress(),
          esConfig.getHttpPort(), syncConfig.getScrollContextTimeToLiveInMinutes(),
          syncConfig.getNumScrollContextItemsToRetrievePerRequest());

      syncController.registerIndexCleaner(searchableIndexCleaner);

    } catch (Exception exc) {
      String message = "Error: failed to sync with message = " + exc.getMessage();
      LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
    }

  }

  private List<String> getAutosuggestableEntitiesFromOXM() {
    Map<String, OxmEntityDescriptor> map = oxmModelLoader.getSuggestionSearchEntityDescriptors();
    List<String> suggestableEntities = new ArrayList<String>();

    for (String entity : map.keySet()) {
      suggestableEntities.add(entity);
    }
    return suggestableEntities;
  }

  /**
   * Initialize the AutosuggestionSynchronizer and AggregationSuggestionSynchronizer
   * 
   * @param esConfig
   * @param aaiAdapter
   * @param esAdapter
   * @param nonCachingRestProvider
   */
  private void initAutoSuggestionSynchronizer(ElasticSearchConfig esConfig,
      ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
      RestfulDataAccessor nonCachingRestProvider) {
    LOG.info(AaiUiMsgs.INFO_GENERIC, "initAutoSuggestionSynchronizer");

    // Initialize for entityautosuggestindex
    try {
      IndexIntegrityValidator autoSuggestionIndexValidator =
          new IndexIntegrityValidator(nonCachingRestProvider, esConfig.getAutosuggestIndexname(),
              esConfig.getType(), esConfig.getIpAddress(), esConfig.getHttpPort(),
              esConfig.buildAutosuggestionTableConfig());

      syncController.registerIndexValidator(autoSuggestionIndexValidator);

      AutosuggestionSynchronizer suggestionSynchronizer =
          new AutosuggestionSynchronizer(esConfig.getAutosuggestIndexname());
      suggestionSynchronizer.setAaiDataProvider(aaiAdapter);
      suggestionSynchronizer.setEsDataProvider(esAdapter);
      syncController.registerEntitySynchronizer(suggestionSynchronizer);

      AggregationSuggestionSynchronizer aggregationSuggestionSynchronizer =
          new AggregationSuggestionSynchronizer(esConfig.getAutosuggestIndexname());
      aggregationSuggestionSynchronizer.setEsDataProvider(esAdapter);
      syncController.registerEntitySynchronizer(aggregationSuggestionSynchronizer);

      IndexCleaner autosuggestIndexCleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
          esConfig.getAutosuggestIndexname(), esConfig.getType(), esConfig.getIpAddress(),
          esConfig.getHttpPort(), syncConfig.getScrollContextTimeToLiveInMinutes(),
          syncConfig.getNumScrollContextItemsToRetrievePerRequest());

      syncController.registerIndexCleaner(autosuggestIndexCleaner);
    } catch (Exception exc) {
      String message = "Error: failed to sync with message = " + exc.getMessage();
      LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
    }
  }

  /**
   * Initialize the AggregationSynchronizer
   * 
   * @param esConfig
   * @param aaiAdapter
   * @param esAdapter
   * @param nonCachingRestProvider
   */
  private void initAggregationSynchronizer(ElasticSearchConfig esConfig,
      ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
      RestfulDataAccessor nonCachingRestProvider) {
    LOG.info(AaiUiMsgs.INFO_GENERIC, "initAggregationSynchronizer");

    List<String> aggregationEntities = getAutosuggestableEntitiesFromOXM();

    // For each index: create an IndexValidator, a Synchronizer, and an IndexCleaner
    for (String entity : aggregationEntities) {
      try {
        String indexName = TierSupportUiConstants.getAggregationIndexName(entity);

        IndexIntegrityValidator aggregationIndexValidator = new IndexIntegrityValidator(
            nonCachingRestProvider, indexName, esConfig.getType(), esConfig.getIpAddress(),
            esConfig.getHttpPort(), esConfig.buildAggregationTableConfig());

        syncController.registerIndexValidator(aggregationIndexValidator);

        /*
         * TODO: This per-entity-synchronizer approach will eventually result in AAI / ES overload
         * because of the existing dedicated thread pools for ES + AAI operations within the
         * synchronizer. If we had 50 types to sync then the thread pools within each Synchronizer
         * would cause some heartburn as there would be hundreds of threads trying to talk to AAI.
         * Given that we our running out of time, let's make sure we can get it functional and then
         * we'll re-visit.
         */
        AggregationSynchronizer aggSynchronizer = new AggregationSynchronizer(entity, indexName);
        aggSynchronizer.setAaiDataProvider(aaiAdapter);
        aggSynchronizer.setEsDataProvider(esAdapter);
        syncController.registerEntitySynchronizer(aggSynchronizer);

        IndexCleaner entityDataIndexCleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
            indexName, esConfig.getType(), esConfig.getIpAddress(), esConfig.getHttpPort(),
            syncConfig.getScrollContextTimeToLiveInMinutes(),
            syncConfig.getNumScrollContextItemsToRetrievePerRequest());

        syncController.registerIndexCleaner(entityDataIndexCleaner);

      } catch (Exception exc) {
        String message = "Error: failed to sync with message = " + exc.getMessage();
        LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
      }
    }
  }

  /**
   * Instantiates a new sync helper.
   *
   * @param loader the loader
   */
  public SyncHelper(OxmModelLoader loader) {
    try {
      this.contextMap = MDC.getCopyOfContextMap();
      this.syncConfig = SynchronizerConfiguration.getConfig();
      this.esConfig = ElasticSearchConfig.getConfig();
      this.oxmModelLoader = loader;

      UncaughtExceptionHandler uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread thread, Throwable exc) {
          LOG.error(AaiUiMsgs.ERROR_GENERIC, thread.getName() + ": " + exc);
        }
      };

      ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("SyncHelper-%d")
          .setUncaughtExceptionHandler(uncaughtExceptionHandler).build();

      periodicExecutor = Executors.newScheduledThreadPool(3, namedThreadFactory);

      /*
       * We only want to initialize the synchronizer if sync has been configured to start
       */
      if (syncConfig.isConfigOkForStartupSync() || syncConfig.isConfigOkForPeriodicSync()) {
        initializeSyncController();
      }

      // schedule startup synchronization
      if (syncConfig.isConfigOkForStartupSync()) {

        long taskInitialDelayInMs = syncConfig.getSyncTaskInitialDelayInMs();
        if (taskInitialDelayInMs != SynchronizerConstants.DELAY_NO_STARTUP_SYNC_IN_MS) {
          oneShotExecutor.schedule(new SyncTask(true), taskInitialDelayInMs, TimeUnit.MILLISECONDS);
          LOG.info(AaiUiMsgs.INFO_GENERIC, "Search Engine startup synchronization is enabled.");
        } else {
          LOG.info(AaiUiMsgs.INFO_GENERIC, "Search Engine startup synchronization is disabled.");
        }
      }

      // schedule periodic synchronization
      if (syncConfig.isConfigOkForPeriodicSync()) {

        TimeZone tz = TimeZone.getTimeZone(syncConfig.getSyncTaskStartTimeTimeZone());
        Calendar calendar = Calendar.getInstance(tz);
        sdf.setTimeZone(tz);

        calendar.set(Calendar.HOUR_OF_DAY, syncConfig.getSyncTaskStartTimeHr());
        calendar.set(Calendar.MINUTE, syncConfig.getSyncTaskStartTimeMin());
        calendar.set(Calendar.SECOND, syncConfig.getSyncTaskStartTimeSec());

        long timeCurrent = calendar.getTimeInMillis();
        int taskFrequencyInDay = syncConfig.getSyncTaskFrequencyInDay();
        timeNextSync.getAndSet(getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay));

        long delayUntilFirstRegSyncInMs = 0;
        delayUntilFirstRegSyncInMs = timeNextSync.get() - timeCurrent;

        // Do all calculation in milliseconds
        long taskFreqencyInMs = taskFrequencyInDay * SynchronizerConstants.MILLISEC_IN_A_DAY;

        if (taskFreqencyInMs != SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS) {
          periodicExecutor.scheduleAtFixedRate(new SyncTask(false), delayUntilFirstRegSyncInMs,
              taskFreqencyInMs, TimeUnit.MILLISECONDS);
          LOG.info(AaiUiMsgs.INFO_GENERIC, "Search Engine periodic synchronization is enabled.");
          // case: when - startup sync is misconfigured or is disabled
          // - give a clue to user when is the next periodic sync
          if (!syncConfig.isConfigOkForStartupSync()
              || syncConfig.isConfigDisabledForInitialSync()) {
            LOG.info(AaiUiMsgs.SYNC_TO_BEGIN, syncController.getControllerName(),
                sdf.format(timeNextSync).replaceAll(SynchronizerConstants.TIME_STD,
                    SynchronizerConstants.TIME_CONFIG_STD));
          }
        } else {
          LOG.info(AaiUiMsgs.INFO_GENERIC, "Search Engine periodic synchronization is disabled.");
        }
      }

    } catch (Exception exc) {
      String message = "Caught an exception while starting up the SyncHelper. Error cause = \n"
          + ErrorUtil.extractStackTraceElements(5, exc);
      LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
    }
  }


  /**
   * Shutdown.
   */
  public void shutdown() {

    if (oneShotExecutor != null) {
      oneShotExecutor.shutdown();
    }

    if (periodicExecutor != null) {
      periodicExecutor.shutdown();
    }

    if (historicalExecutor != null) {
      historicalExecutor.shutdown();
    }

    if (syncController != null) {
      syncController.shutdown();
    }

    if (entityCounterHistorySummarizer != null) {
      entityCounterHistorySummarizer.shutdown();
    }

  }

  public OxmModelLoader getOxmModelLoader() {
    return oxmModelLoader;
  }

  public void setOxmModelLoader(OxmModelLoader oxmModelLoader) {
    this.oxmModelLoader = oxmModelLoader;
  }
}