2 * ============LICENSE_START=======================================================
3 * SPARKY (inventory 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.onap.aai.sparky.synchronizer;
28 import org.onap.aai.sparky.dal.aai.ActiveInventoryAdapter;
29 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
30 import org.onap.aai.sparky.dal.cache.InMemoryEntityCache;
31 import org.onap.aai.sparky.dal.cache.PersistentEntityCache;
32 import org.onap.aai.sparky.dal.elasticsearch.ElasticSearchAdapter;
33 import org.onap.aai.sparky.dal.elasticsearch.ElasticSearchDataProvider;
34 import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
35 import org.onap.aai.sparky.dal.rest.OperationResult;
36 import org.onap.aai.sparky.dal.rest.RestClientBuilder;
37 import org.onap.aai.sparky.dal.rest.RestfulDataAccessor;
38 import org.onap.aai.sparky.synchronizer.AutosuggestionSynchronizer;
39 import org.onap.aai.sparky.synchronizer.CrossEntityReferenceSynchronizer;
40 import org.onap.aai.sparky.synchronizer.ElasticSearchIndexCleaner;
41 import org.onap.aai.sparky.synchronizer.GeoSynchronizer;
42 import org.onap.aai.sparky.synchronizer.HistoricalEntitySummarizer;
43 import org.onap.aai.sparky.synchronizer.IndexCleaner;
44 import org.onap.aai.sparky.synchronizer.IndexIntegrityValidator;
45 import org.onap.aai.sparky.synchronizer.SearchableEntitySynchronizer;
46 import org.onap.aai.sparky.synchronizer.SyncController;
47 import org.onap.aai.sparky.synchronizer.SyncController.SyncActions;
48 import org.onap.aai.sparky.synchronizer.enumeration.SynchronizerState;
49 import org.slf4j.LoggerFactory;
51 import ch.qos.logback.classic.Level;
54 * The Class SyncControllerBuilder.
56 public class SyncControllerBuilder {
59 * Do master entity sync.
61 public void doMasterEntitySync() {
66 * Test elastic search update api.
68 public void testElasticSearchUpdateApi() {
71 RestClientBuilder clientBuilder = new RestClientBuilder();
72 clientBuilder.setUseHttps(false);
74 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
76 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
77 ElasticSearchDataProvider elasticSearchDataProvider =
78 new ElasticSearchAdapter(nonCachingRestProvider, esConfig);
81 "{ \"entityType\": \"complex\", \"pkey\": \"MORRISTOWN0075\", \"location\": { \"lat\": \"40.793414\", \"lon\": \"-74.480432\" }, \"selfLink\": \"https://aai-hostname:8443/aai/v8/cloud-infrastructure/complexes/complex/MORRISTOWN0075?nodes-only\" }\n";
83 String updateRequest = elasticSearchDataProvider.buildBulkImportOperationRequest(
84 "topographysearchindex-localhost", "default",
85 "1e2a6ba9e09d5e1bcb016b3a0b8d50273b42828e47957bd2a2f3ce1854744f5f", "6", payload);
88 elasticSearchDataProvider.doBulkOperation("http://localhost:9200/_bulk", updateRequest);
90 System.out.println(or.toString());
93 * String BULK_IMPORT_INDEX_TEMPLATE =
94 * "{\"index\":{\"_index\":\"%s\",\"_type\":\"%s\",\"_id\":\"%s\", \"_version\":\"%s\"}}\n";
96 * StringBuilder updateRequestPayload = new StringBuilder(128);
97 * updateRequestPayload.append(String.format(BULK_IMPORT_INDEX_TEMPLATE,
98 * "topographysearchindex-localhost", "default",
99 * "1e2a6ba9e09d5e1bcb016b3a0b8d50273b42828e47957bd2a2f3ce1854744f5f", "5"));
102 * updateRequestPayload.append(payload);
104 * OperationResult or = nonCachingRestProvider.doRestfulOperation(HttpMethod.PUT,
105 * "http://localhost:9200/_bulk", updateRequestPayload.toString(),
106 * RestfulDataAccessor.APPLICATION_X_WWW_FORM_URL_ENCODED,
107 * RestfulDataAccessor.APPLICATION_JSON);
112 } catch (Exception exc) {
113 exc.printStackTrace();
114 System.out.println("Error: failed to sync with message = " + exc.getMessage());
119 * Do historical entity sync.
121 public void doHistoricalEntitySync() {
123 SyncController syncController = new SyncController("historicalEntityTestController");
125 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
126 aaiAdapter.setCacheEnabled(false);
128 RestClientBuilder clientBuilder = new RestClientBuilder();
129 clientBuilder.setUseHttps(false);
131 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
133 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
135 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
138 IndexIntegrityValidator entityCounterHistoryValidator =
139 new IndexIntegrityValidator(nonCachingRestProvider, esConfig.getEntityCountHistoryIndex(),
140 esConfig.getType(), esConfig.getIpAddress(), esConfig.getHttpPort(),
141 esConfig.buildElasticSearchEntityCountHistoryTableConfig());
143 syncController.registerIndexValidator(entityCounterHistoryValidator);
150 HistoricalEntitySummarizer historicalSummarizer =
151 new HistoricalEntitySummarizer(esConfig.getEntityCountHistoryIndex());
152 historicalSummarizer.setAaiDataProvider(aaiAdapter);
153 historicalSummarizer.setEsDataProvider(esAdapter);
154 syncController.registerEntitySynchronizer(historicalSummarizer);
159 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
160 * RestClientBuilder());
162 * entitySearchIndexValidator.setIndexName("topographysearchindex-localhost");
163 * entitySearchIndexValidator.setIndexType("default");
164 * entitySearchIndexValidator.setIndexSettings("");
165 * entitySearchIndexValidator.setIndexSettings("");
167 * syncController.registerIndexValidator(entitySearchIndexValidator);
173 * IndexCleaner index1Cleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
174 * "topographysearchindex-localhost", "default", "127.0.0.1", "9200", 5, 5000);
177 // syncController.registerIndexCleaner(index1Cleaner);
181 for (int x = 0; x < 10; x++) {
183 syncController.performAction(SyncActions.SYNCHRONIZE);
185 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
187 System.out.println("sync controller state = " + syncController.getState());
193 syncController.shutdown();
195 } catch (Exception exc) {
196 exc.printStackTrace();
197 System.out.println("Error: failed to sync with message = " + exc.getMessage());
204 * Do geo entity sync.
206 public void doGeoEntitySync() {
209 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
211 aaiAdapter.setCacheEnabled(true);
213 InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
214 aaiAdapter.setEntityCache(aaiInMemoryCache);
217 * PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
218 * aaiAdapter.setEntityCache(aaiDiskCache);
221 RestClientBuilder clientBuilder = new RestClientBuilder();
222 clientBuilder.setUseHttps(false);
224 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
225 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
227 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
229 IndexIntegrityValidator entitySearchIndexValidator =
230 new IndexIntegrityValidator(nonCachingRestProvider, esConfig.getIndexName(),
231 esConfig.getType(), esConfig.getIpAddress(), esConfig.getHttpPort(),
232 esConfig.buildElasticSearchTableConfig());
234 SyncController syncController = new SyncController("geoEntitySyncTestController");
235 syncController.registerIndexValidator(entitySearchIndexValidator);
240 GeoSynchronizer geoSync = new GeoSynchronizer("topographysearchindex-localhost");
241 geoSync.setAaiDataProvider(aaiAdapter);
242 geoSync.setEsDataProvider(esAdapter);
243 syncController.registerEntitySynchronizer(geoSync);
248 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
249 * RestClientBuilder());
251 * entitySearchIndexValidator.setIndexName("topographysearchindex-localhost");
252 * entitySearchIndexValidator.setIndexType("default");
253 * entitySearchIndexValidator.setIndexSettings("");
254 * entitySearchIndexValidator.setIndexSettings("");
256 * syncController.registerIndexValidator(entitySearchIndexValidator);
262 * IndexCleaner index1Cleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
263 * "topographysearchindex-localhost", "default", "127.0.0.1", "9200", 5, 5000);
266 // syncController.registerIndexCleaner(index1Cleaner);
270 syncController.performAction(SyncActions.SYNCHRONIZE);
272 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
276 syncController.shutdown();
278 } catch (Exception exc) {
279 exc.printStackTrace();
280 System.out.println("Error: failed to sync with message = " + exc.getMessage());
285 * Do searchable entitysync.
287 public void doSearchableEntitysync() {
291 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
293 aaiAdapter.setCacheEnabled(true);
296 * InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
297 * aaiAdapter.setEntityCache(aaiInMemoryCache);
300 PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
301 aaiAdapter.setEntityCache(aaiDiskCache);
303 RestClientBuilder clientBuilder = new RestClientBuilder();
304 clientBuilder.setUseHttps(false);
306 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
307 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
309 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
313 SyncController syncController = new SyncController("searchtableEntityTestController");
315 SearchableEntitySynchronizer ses =
316 new SearchableEntitySynchronizer("entitysearchindex-localhost");
317 ses.setAaiDataProvider(aaiAdapter);
318 ses.setEsDataProvider(esAdapter);
319 syncController.registerEntitySynchronizer(ses);
324 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
325 * RestClientBuilder());
327 * entitySearchIndexValidator.setIndexName("esi-sync2-localhost");
328 * entitySearchIndexValidator.setIndexType("default");
330 * syncController.registerIndexValidator(entitySearchIndexValidator);
336 * IndexCleaner index1Cleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
337 * "entitysearchindex-localhost", "default", "127.0.0.1", "9200", 5, 5000);
339 * syncController.registerIndexCleaner(index1Cleaner);
344 syncController.performAction(SyncActions.SYNCHRONIZE);
346 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
350 syncController.shutdown();
352 } catch (Exception exc) {
353 exc.printStackTrace();
354 System.out.println("Error: failed to sync with message = " + exc.getMessage());
359 * Do cross entity reference sync.
361 public void doCrossEntityReferenceSync() {
365 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
367 aaiAdapter.setCacheEnabled(true);
370 * InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
371 * aaiAdapter.setEntityCache(aaiInMemoryCache);
374 PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
375 aaiAdapter.setEntityCache(aaiDiskCache);
377 RestClientBuilder clientBuilder = new RestClientBuilder();
378 clientBuilder.setUseHttps(false);
380 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
381 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
383 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
385 SyncController syncController = new SyncController("crossEntityRefSyncController");
387 CrossEntityReferenceSynchronizer cers =
388 new CrossEntityReferenceSynchronizer("entitysearchindex-localhost", ActiveInventoryConfig.getConfig());
389 cers.setAaiDataProvider(aaiAdapter);
390 cers.setEsDataProvider(esAdapter);
391 syncController.registerEntitySynchronizer(cers);
393 SearchableEntitySynchronizer ses =
394 new SearchableEntitySynchronizer("entitysearchindex-localhost");
395 ses.setAaiDataProvider(aaiAdapter);
396 ses.setEsDataProvider(esAdapter);
397 syncController.registerEntitySynchronizer(ses);
399 ElasticSearchConfig config = ElasticSearchConfig.getConfig();
401 IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(
402 nonCachingRestProvider, config.getIndexName(), config.getType(), config.getIpAddress(),
403 config.getHttpPort(), config.buildElasticSearchTableConfig());
405 syncController.registerIndexValidator(entitySearchIndexValidator);
409 IndexCleaner index1Cleaner =
410 new ElasticSearchIndexCleaner(nonCachingRestProvider, config.getIndexName(),
411 config.getType(), config.getIpAddress(), config.getHttpPort(), 5, 5000);
413 syncController.registerIndexCleaner(index1Cleaner);
417 syncController.performAction(SyncActions.SYNCHRONIZE);
419 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
423 syncController.shutdown();
425 } catch (Exception exc) {
426 exc.printStackTrace();
427 System.out.println("Error: Failed to sync with message = " + exc.getMessage());
432 * Do suggestion entitysync.
434 public void doSuggestionEntitySync() {
438 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
440 aaiAdapter.setCacheEnabled(true);
443 * InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
444 * aaiAdapter.setEntityCache(aaiInMemoryCache);
447 PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
448 aaiAdapter.setEntityCache(aaiDiskCache);
450 RestClientBuilder clientBuilder = new RestClientBuilder();
451 clientBuilder.setUseHttps(false);
453 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
454 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
456 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
458 SyncController syncController = new SyncController("suggestionEntityTestController");
460 AutosuggestionSynchronizer ses =
461 new AutosuggestionSynchronizer("suggestionentityindex-localhost");
462 ses.setAaiDataProvider(aaiAdapter);
463 ses.setEsDataProvider(esAdapter);
464 syncController.registerEntitySynchronizer(ses);
466 syncController.performAction(SyncActions.SYNCHRONIZE);
468 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
472 syncController.shutdown();
474 } catch (Exception exc) {
475 exc.printStackTrace();
476 System.out.println("Error: failed to sync with message = " + exc.getMessage());
483 public void doNoOpSync() {
485 SyncController syncController = new SyncController("noopSyncTestController");
488 * ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
490 * aaiAdapter.setCacheEnabled(true);
492 * /*InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
493 * aaiAdapter.setEntityCache(aaiInMemoryCache);
497 * PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
498 * aaiAdapter.setEntityCache(aaiDiskCache);
500 * ElasticSearchConfig config = ElasticSearchConfig.getConfig(); OXMModelLoader loader =
501 * OXMModelLoader.getInstance(); SyncAdapter syncAdapter = new SyncAdapter(new
502 * RestClientBuilder(), config, loader);
506 * SearchableEntitySynchronizer ses = new SearchableEntitySynchronizer();
507 * ses.setAaiDataProvider(aaiAdapter); ses.setEsDataProvider(syncAdapter);
508 * syncController.registerEntitySynchronizer(ses);
512 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
513 * RestClientBuilder());
515 * entitySearchIndexValidator.setIndexName("esi-sync2-localhost");
516 * entitySearchIndexValidator.setIndexType("default");
517 * entitySearchIndexValidator.setIndexSettings("");
518 * entitySearchIndexValidator.setIndexSettings("");
520 * syncController.registerIndexValidator(entitySearchIndexValidator);
524 * ElasticSearchEntityPurger p1 = new ElasticSearchEntityPurger(new RestClientBuilder());
525 * p1.setIndexName("esi-blal-blah");
527 * ElasticSearchEntityPurger p2 = new ElasticSearchEntityPurger(new RestClientBuilder());
528 * p2.setIndexName("esi-topo-blah");
532 syncController.performAction(SyncActions.SYNCHRONIZE);
534 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
538 syncController.shutdown();
540 } catch (Exception exc) {
541 System.out.println("Error: failed to sync with message = " + exc.getMessage());
549 * @param args the arguments
551 public static void main(String[] args) {
552 boolean runSearchableEntitySync = false;
553 boolean runGeoEntitySync = true;
555 System.setProperty("AJSC_HOME", "e:\\dev");
556 // System.getProperties().setProperty("AJSC_HOME",
557 // "c:\\rpo\\tier-support-ui\\target\\swm\\package\\nix\\"
558 // + "dist_files\\opt\\app\\ajsc-tier-support-ui");
559 System.setProperty("AJSC_HOME", "d:\\AAI\\tier_support_ui\\tier-support-ui\\target\\swm\\package\\nix\\dist_files\\appl\\inventory-ui-service\\1.0-SNAPSHOT");
561 ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
562 .getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
563 // root.detachAndStopAllAppenders();
564 // logger = new CaptureLoggerAppender();
565 root.setLevel(Level.INFO);
566 // root.addAppender(logger);
569 SyncControllerBuilder syncBuilder = new SyncControllerBuilder();
572 * if (runSearchableEntitySync) syncBuilder.doSearchableEntitysync();
575 //syncBuilder.doSearchableEntitysync();
576 // syncBuilder.doCrossEntityReferenceSync();
577 // syncBuilder.doHistoricalEntitySync();
578 // syncBuilder.doGeoEntitySync();
579 syncBuilder.doSuggestionEntitySync();
581 // syncBuilder.testElasticSearchUpdateAPI();
584 * if (runGeoEntitySync) { syncBuilder.doGeoEntitySync(); }