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.openecomp.sparky.synchronizer;
28 import org.openecomp.sparky.dal.aai.ActiveInventoryAdapter;
29 import org.openecomp.sparky.dal.aai.config.ActiveInventoryConfig;
30 import org.openecomp.sparky.dal.cache.InMemoryEntityCache;
31 import org.openecomp.sparky.dal.cache.PersistentEntityCache;
32 import org.openecomp.sparky.dal.elasticsearch.ElasticSearchAdapter;
33 import org.openecomp.sparky.dal.elasticsearch.ElasticSearchDataProvider;
34 import org.openecomp.sparky.dal.elasticsearch.config.ElasticSearchConfig;
35 import org.openecomp.sparky.dal.rest.OperationResult;
36 import org.openecomp.sparky.dal.rest.RestClientBuilder;
37 import org.openecomp.sparky.dal.rest.RestfulDataAccessor;
38 import org.openecomp.sparky.synchronizer.SyncController.SyncActions;
39 import org.openecomp.sparky.synchronizer.enumeration.SynchronizerState;
40 import org.slf4j.LoggerFactory;
42 import ch.qos.logback.classic.Level;
45 * The Class SyncControllerBuilder.
47 public class SyncControllerBuilder {
50 * Do master entity sync.
52 public void doMasterEntitySync() {
57 * Test elastic search update api.
59 public void testElasticSearchUpdateApi() {
62 RestClientBuilder clientBuilder = new RestClientBuilder();
63 clientBuilder.setUseHttps(false);
65 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
67 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
68 ElasticSearchDataProvider elasticSearchDataProvider =
69 new ElasticSearchAdapter(nonCachingRestProvider, esConfig);
72 "{ \"entityType\": \"complex\", \"pkey\": \"MORRISTOWN0075\", \"location\": { \"lat\": \"40.793414\", \"lon\": \"-74.480432\" }, \"selfLink\": \"https://aai-int1.test.att.com:8443/aai/v8/cloud-infrastructure/complexes/complex/MORRISTOWN0075?nodes-only\" }\n";
74 String updateRequest = elasticSearchDataProvider.buildBulkImportOperationRequest(
75 "topographysearchindex-localhost", "default",
76 "1e2a6ba9e09d5e1bcb016b3a0b8d50273b42828e47957bd2a2f3ce1854744f5f", "6", payload);
79 elasticSearchDataProvider.doBulkOperation("http://localhost:9200/_bulk", updateRequest);
81 System.out.println(or.toString());
84 * String BULK_IMPORT_INDEX_TEMPLATE =
85 * "{\"index\":{\"_index\":\"%s\",\"_type\":\"%s\",\"_id\":\"%s\", \"_version\":\"%s\"}}\n";
87 * StringBuilder updateRequestPayload = new StringBuilder(128);
88 * updateRequestPayload.append(String.format(BULK_IMPORT_INDEX_TEMPLATE,
89 * "topographysearchindex-localhost", "default",
90 * "1e2a6ba9e09d5e1bcb016b3a0b8d50273b42828e47957bd2a2f3ce1854744f5f", "5"));
93 * updateRequestPayload.append(payload);
95 * OperationResult or = nonCachingRestProvider.doRestfulOperation(HttpMethod.PUT,
96 * "http://localhost:9200/_bulk", updateRequestPayload.toString(),
97 * RestfulDataAccessor.APPLICATION_X_WWW_FORM_URL_ENCODED,
98 * RestfulDataAccessor.APPLICATION_JSON);
103 } catch (Exception exc) {
104 exc.printStackTrace();
105 System.out.println("Error: failed to sync with message = " + exc.getMessage());
110 * Do historical entity sync.
112 public void doHistoricalEntitySync() {
114 SyncController syncController = new SyncController("historicalEntityTestController");
116 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
117 aaiAdapter.setCacheEnabled(false);
119 RestClientBuilder clientBuilder = new RestClientBuilder();
120 clientBuilder.setUseHttps(false);
122 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
124 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
126 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
129 IndexIntegrityValidator entityCounterHistoryValidator =
130 new IndexIntegrityValidator(nonCachingRestProvider, esConfig.getEntityCountHistoryIndex(),
131 esConfig.getType(), esConfig.getIpAddress(), esConfig.getHttpPort(),
132 esConfig.buildElasticSearchEntityCountHistoryTableConfig());
134 syncController.registerIndexValidator(entityCounterHistoryValidator);
141 HistoricalEntitySummarizer historicalSummarizer =
142 new HistoricalEntitySummarizer(esConfig.getEntityCountHistoryIndex());
143 historicalSummarizer.setAaiDataProvider(aaiAdapter);
144 historicalSummarizer.setEsDataProvider(esAdapter);
145 syncController.registerEntitySynchronizer(historicalSummarizer);
150 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
151 * RestClientBuilder());
153 * entitySearchIndexValidator.setIndexName("topographysearchindex-localhost");
154 * entitySearchIndexValidator.setIndexType("default");
155 * entitySearchIndexValidator.setIndexSettings("");
156 * entitySearchIndexValidator.setIndexSettings("");
158 * syncController.registerIndexValidator(entitySearchIndexValidator);
164 * IndexCleaner index1Cleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
165 * "topographysearchindex-localhost", "default", "127.0.0.1", "9200", 5, 5000);
168 // syncController.registerIndexCleaner(index1Cleaner);
172 for (int x = 0; x < 10; x++) {
174 syncController.performAction(SyncActions.SYNCHRONIZE);
176 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
178 System.out.println("sync controller state = " + syncController.getState());
184 syncController.shutdown();
186 } catch (Exception exc) {
187 exc.printStackTrace();
188 System.out.println("Error: failed to sync with message = " + exc.getMessage());
195 * Do geo entity sync.
197 public void doGeoEntitySync() {
200 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
202 aaiAdapter.setCacheEnabled(true);
204 InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
205 aaiAdapter.setEntityCache(aaiInMemoryCache);
208 * PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
209 * aaiAdapter.setEntityCache(aaiDiskCache);
212 RestClientBuilder clientBuilder = new RestClientBuilder();
213 clientBuilder.setUseHttps(false);
215 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
216 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
218 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
220 IndexIntegrityValidator entitySearchIndexValidator =
221 new IndexIntegrityValidator(nonCachingRestProvider, esConfig.getIndexName(),
222 esConfig.getType(), esConfig.getIpAddress(), esConfig.getHttpPort(),
223 esConfig.buildElasticSearchTableConfig());
225 SyncController syncController = new SyncController("geoEntitySyncTestController");
226 syncController.registerIndexValidator(entitySearchIndexValidator);
231 GeoSynchronizer geoSync = new GeoSynchronizer("topographysearchindex-localhost");
232 geoSync.setAaiDataProvider(aaiAdapter);
233 geoSync.setEsDataProvider(esAdapter);
234 syncController.registerEntitySynchronizer(geoSync);
239 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
240 * RestClientBuilder());
242 * entitySearchIndexValidator.setIndexName("topographysearchindex-localhost");
243 * entitySearchIndexValidator.setIndexType("default");
244 * entitySearchIndexValidator.setIndexSettings("");
245 * entitySearchIndexValidator.setIndexSettings("");
247 * syncController.registerIndexValidator(entitySearchIndexValidator);
253 * IndexCleaner index1Cleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
254 * "topographysearchindex-localhost", "default", "127.0.0.1", "9200", 5, 5000);
257 // syncController.registerIndexCleaner(index1Cleaner);
261 syncController.performAction(SyncActions.SYNCHRONIZE);
263 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
267 syncController.shutdown();
269 } catch (Exception exc) {
270 exc.printStackTrace();
271 System.out.println("Error: failed to sync with message = " + exc.getMessage());
276 * Do searchable entitysync.
278 public void doSearchableEntitysync() {
282 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
284 aaiAdapter.setCacheEnabled(true);
287 * InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
288 * aaiAdapter.setEntityCache(aaiInMemoryCache);
291 PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
292 aaiAdapter.setEntityCache(aaiDiskCache);
294 RestClientBuilder clientBuilder = new RestClientBuilder();
295 clientBuilder.setUseHttps(false);
297 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
298 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
300 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
304 SyncController syncController = new SyncController("searchtableEntityTestController");
306 SearchableEntitySynchronizer ses =
307 new SearchableEntitySynchronizer("entitysearchindex-localhost");
308 ses.setAaiDataProvider(aaiAdapter);
309 ses.setEsDataProvider(esAdapter);
310 syncController.registerEntitySynchronizer(ses);
315 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
316 * RestClientBuilder());
318 * entitySearchIndexValidator.setIndexName("esi-sync2-localhost");
319 * entitySearchIndexValidator.setIndexType("default");
321 * syncController.registerIndexValidator(entitySearchIndexValidator);
327 * IndexCleaner index1Cleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
328 * "entitysearchindex-localhost", "default", "127.0.0.1", "9200", 5, 5000);
330 * syncController.registerIndexCleaner(index1Cleaner);
335 syncController.performAction(SyncActions.SYNCHRONIZE);
337 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
341 syncController.shutdown();
343 } catch (Exception exc) {
344 exc.printStackTrace();
345 System.out.println("Error: failed to sync with message = " + exc.getMessage());
350 * Do cross entity reference sync.
352 public void doCrossEntityReferenceSync() {
356 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
358 aaiAdapter.setCacheEnabled(true);
361 * InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
362 * aaiAdapter.setEntityCache(aaiInMemoryCache);
365 PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
366 aaiAdapter.setEntityCache(aaiDiskCache);
368 RestClientBuilder clientBuilder = new RestClientBuilder();
369 clientBuilder.setUseHttps(false);
371 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
372 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
374 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
376 SyncController syncController = new SyncController("crossEntityRefSyncController");
378 CrossEntityReferenceSynchronizer cers =
379 new CrossEntityReferenceSynchronizer("entitysearchindex-localhost", ActiveInventoryConfig.getConfig());
380 cers.setAaiDataProvider(aaiAdapter);
381 cers.setEsDataProvider(esAdapter);
382 syncController.registerEntitySynchronizer(cers);
384 SearchableEntitySynchronizer ses =
385 new SearchableEntitySynchronizer("entitysearchindex-localhost");
386 ses.setAaiDataProvider(aaiAdapter);
387 ses.setEsDataProvider(esAdapter);
388 syncController.registerEntitySynchronizer(ses);
390 ElasticSearchConfig config = ElasticSearchConfig.getConfig();
392 IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(
393 nonCachingRestProvider, config.getIndexName(), config.getType(), config.getIpAddress(),
394 config.getHttpPort(), config.buildElasticSearchTableConfig());
396 syncController.registerIndexValidator(entitySearchIndexValidator);
400 IndexCleaner index1Cleaner =
401 new ElasticSearchIndexCleaner(nonCachingRestProvider, config.getIndexName(),
402 config.getType(), config.getIpAddress(), config.getHttpPort(), 5, 5000);
404 syncController.registerIndexCleaner(index1Cleaner);
408 syncController.performAction(SyncActions.SYNCHRONIZE);
410 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
414 syncController.shutdown();
416 } catch (Exception exc) {
417 exc.printStackTrace();
418 System.out.println("Error: Failed to sync with message = " + exc.getMessage());
423 * Do suggestion entitysync.
425 public void doSuggestionEntitySync() {
429 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
431 aaiAdapter.setCacheEnabled(true);
434 * InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
435 * aaiAdapter.setEntityCache(aaiInMemoryCache);
438 PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
439 aaiAdapter.setEntityCache(aaiDiskCache);
441 RestClientBuilder clientBuilder = new RestClientBuilder();
442 clientBuilder.setUseHttps(false);
444 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
445 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
447 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig);
449 SyncController syncController = new SyncController("suggestionEntityTestController");
451 AutosuggestionSynchronizer ses =
452 new AutosuggestionSynchronizer("suggestionentityindex-localhost");
453 ses.setAaiDataProvider(aaiAdapter);
454 ses.setEsDataProvider(esAdapter);
455 syncController.registerEntitySynchronizer(ses);
457 syncController.performAction(SyncActions.SYNCHRONIZE);
459 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
463 syncController.shutdown();
465 } catch (Exception exc) {
466 exc.printStackTrace();
467 System.out.println("Error: failed to sync with message = " + exc.getMessage());
474 public void doNoOpSync() {
476 SyncController syncController = new SyncController("noopSyncTestController");
479 * ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
481 * aaiAdapter.setCacheEnabled(true);
483 * /*InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
484 * aaiAdapter.setEntityCache(aaiInMemoryCache);
488 * PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
489 * aaiAdapter.setEntityCache(aaiDiskCache);
491 * ElasticSearchConfig config = ElasticSearchConfig.getConfig(); OXMModelLoader loader =
492 * OXMModelLoader.getInstance(); SyncAdapter syncAdapter = new SyncAdapter(new
493 * RestClientBuilder(), config, loader);
497 * SearchableEntitySynchronizer ses = new SearchableEntitySynchronizer();
498 * ses.setAaiDataProvider(aaiAdapter); ses.setEsDataProvider(syncAdapter);
499 * syncController.registerEntitySynchronizer(ses);
503 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
504 * RestClientBuilder());
506 * entitySearchIndexValidator.setIndexName("esi-sync2-localhost");
507 * entitySearchIndexValidator.setIndexType("default");
508 * entitySearchIndexValidator.setIndexSettings("");
509 * entitySearchIndexValidator.setIndexSettings("");
511 * syncController.registerIndexValidator(entitySearchIndexValidator);
515 * ElasticSearchEntityPurger p1 = new ElasticSearchEntityPurger(new RestClientBuilder());
516 * p1.setIndexName("esi-blal-blah");
518 * ElasticSearchEntityPurger p2 = new ElasticSearchEntityPurger(new RestClientBuilder());
519 * p2.setIndexName("esi-topo-blah");
523 syncController.performAction(SyncActions.SYNCHRONIZE);
525 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
529 syncController.shutdown();
531 } catch (Exception exc) {
532 System.out.println("Error: failed to sync with message = " + exc.getMessage());
540 * @param args the arguments
542 public static void main(String[] args) {
543 boolean runSearchableEntitySync = false;
544 boolean runGeoEntitySync = true;
546 System.setProperty("AJSC_HOME", "e:\\dev");
547 // System.getProperties().setProperty("AJSC_HOME",
548 // "c:\\rpo\\tier-support-ui\\target\\swm\\package\\nix\\"
549 // + "dist_files\\opt\\app\\ajsc-tier-support-ui");
550 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");
552 ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
553 .getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
554 // root.detachAndStopAllAppenders();
555 // logger = new CaptureLoggerAppender();
556 root.setLevel(Level.INFO);
557 // root.addAppender(logger);
560 SyncControllerBuilder syncBuilder = new SyncControllerBuilder();
563 * if (runSearchableEntitySync) syncBuilder.doSearchableEntitysync();
566 //syncBuilder.doSearchableEntitysync();
567 // syncBuilder.doCrossEntityReferenceSync();
568 // syncBuilder.doHistoricalEntitySync();
569 // syncBuilder.doGeoEntitySync();
570 syncBuilder.doSuggestionEntitySync();
572 // syncBuilder.testElasticSearchUpdateAPI();
575 * if (runGeoEntitySync) { syncBuilder.doGeoEntitySync(); }