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.IndexCleaner;
42 import org.onap.aai.sparky.synchronizer.IndexIntegrityValidator;
43 import org.onap.aai.sparky.synchronizer.SearchableEntitySynchronizer;
44 import org.onap.aai.sparky.synchronizer.SyncController;
45 import org.onap.aai.sparky.synchronizer.SyncController.SyncActions;
46 import org.onap.aai.sparky.synchronizer.enumeration.SynchronizerState;
47 import org.slf4j.LoggerFactory;
49 import ch.qos.logback.classic.Level;
52 * The Class SyncControllerBuilder.
54 public class SyncControllerBuilder {
57 * Do master entity sync.
59 public void doMasterEntitySync() {
64 * Test elastic search update api.
66 public void testElasticSearchUpdateApi() {
69 RestClientBuilder clientBuilder = new RestClientBuilder();
70 clientBuilder.setUseHttps(false);
72 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
74 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
75 ElasticSearchDataProvider elasticSearchDataProvider =
76 new ElasticSearchAdapter(nonCachingRestProvider, esConfig);
79 "{ \"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";
81 String updateRequest = elasticSearchDataProvider.buildBulkImportOperationRequest(
82 "topographysearchindex-localhost", "default",
83 "1e2a6ba9e09d5e1bcb016b3a0b8d50273b42828e47957bd2a2f3ce1854744f5f", "6", payload);
86 elasticSearchDataProvider.doBulkOperation("http://localhost:9200/_bulk", updateRequest);
88 System.out.println(or.toString());
91 * String BULK_IMPORT_INDEX_TEMPLATE =
92 * "{\"index\":{\"_index\":\"%s\",\"_type\":\"%s\",\"_id\":\"%s\", \"_version\":\"%s\"}}\n";
94 * StringBuilder updateRequestPayload = new StringBuilder(128);
95 * updateRequestPayload.append(String.format(BULK_IMPORT_INDEX_TEMPLATE,
96 * "topographysearchindex-localhost", "default",
97 * "1e2a6ba9e09d5e1bcb016b3a0b8d50273b42828e47957bd2a2f3ce1854744f5f", "5"));
100 * updateRequestPayload.append(payload);
102 * OperationResult or = nonCachingRestProvider.doRestfulOperation(HttpMethod.PUT,
103 * "http://localhost:9200/_bulk", updateRequestPayload.toString(),
104 * RestfulDataAccessor.APPLICATION_X_WWW_FORM_URL_ENCODED,
105 * RestfulDataAccessor.APPLICATION_JSON);
110 } catch (Exception exc) {
111 exc.printStackTrace();
112 System.out.println("Error: failed to sync with message = " + exc.getMessage());
117 * Do historical entity sync.
119 public void doHistoricalEntitySync() {
121 SyncController syncController = new SyncController("historicalEntityTestController");
123 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
124 aaiAdapter.setCacheEnabled(false);
126 RestClientBuilder clientBuilder = new RestClientBuilder();
127 clientBuilder.setUseHttps(false);
129 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
131 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
133 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig);
136 IndexIntegrityValidator entityCounterHistoryValidator =
137 new IndexIntegrityValidator(nonCachingRestProvider, esConfig.getEntityCountHistoryIndex(),
138 esConfig.getType(), esConfig.getIpAddress(), esConfig.getHttpPort(),
139 esConfig.buildElasticSearchEntityCountHistoryTableConfig());
141 syncController.registerIndexValidator(entityCounterHistoryValidator);
146 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
147 * RestClientBuilder());
149 * entitySearchIndexValidator.setIndexName("topographysearchindex-localhost");
150 * entitySearchIndexValidator.setIndexType("default");
151 * entitySearchIndexValidator.setIndexSettings("");
152 * entitySearchIndexValidator.setIndexSettings("");
154 * syncController.registerIndexValidator(entitySearchIndexValidator);
160 * IndexCleaner index1Cleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
161 * "topographysearchindex-localhost", "default", "127.0.0.1", "9200", 5, 5000);
164 // syncController.registerIndexCleaner(index1Cleaner);
168 for (int x = 0; x < 10; x++) {
170 syncController.performAction(SyncActions.SYNCHRONIZE);
172 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
174 System.out.println("sync controller state = " + syncController.getState());
180 syncController.shutdown();
182 } catch (Exception exc) {
183 exc.printStackTrace();
184 System.out.println("Error: failed to sync with message = " + exc.getMessage());
191 * Do geo entity sync.
193 public void doGeoEntitySync() {
196 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
198 aaiAdapter.setCacheEnabled(true);
200 InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
201 aaiAdapter.setEntityCache(aaiInMemoryCache);
204 * PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
205 * aaiAdapter.setEntityCache(aaiDiskCache);
208 RestClientBuilder clientBuilder = new RestClientBuilder();
209 clientBuilder.setUseHttps(false);
211 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
212 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
214 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig);
216 IndexIntegrityValidator entitySearchIndexValidator =
217 new IndexIntegrityValidator(nonCachingRestProvider, esConfig.getIndexName(),
218 esConfig.getType(), esConfig.getIpAddress(), esConfig.getHttpPort(),
219 esConfig.buildElasticSearchTableConfig());
221 SyncController syncController = new SyncController("geoEntitySyncTestController");
222 syncController.registerIndexValidator(entitySearchIndexValidator);
228 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
229 * RestClientBuilder());
231 * entitySearchIndexValidator.setIndexName("topographysearchindex-localhost");
232 * entitySearchIndexValidator.setIndexType("default");
233 * entitySearchIndexValidator.setIndexSettings("");
234 * entitySearchIndexValidator.setIndexSettings("");
236 * syncController.registerIndexValidator(entitySearchIndexValidator);
242 * IndexCleaner index1Cleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
243 * "topographysearchindex-localhost", "default", "127.0.0.1", "9200", 5, 5000);
246 // syncController.registerIndexCleaner(index1Cleaner);
250 syncController.performAction(SyncActions.SYNCHRONIZE);
252 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
256 syncController.shutdown();
258 } catch (Exception exc) {
259 exc.printStackTrace();
260 System.out.println("Error: failed to sync with message = " + exc.getMessage());
265 * Do searchable entitysync.
267 public void doSearchableEntitysync() {
271 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
273 aaiAdapter.setCacheEnabled(true);
276 * InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
277 * aaiAdapter.setEntityCache(aaiInMemoryCache);
280 PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
281 aaiAdapter.setEntityCache(aaiDiskCache);
283 RestClientBuilder clientBuilder = new RestClientBuilder();
284 clientBuilder.setUseHttps(false);
286 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
287 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
289 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig);
293 SyncController syncController = new SyncController("searchtableEntityTestController");
295 SearchableEntitySynchronizer ses =
296 new SearchableEntitySynchronizer("entitysearchindex-localhost");
297 ses.setAaiDataProvider(aaiAdapter);
298 ses.setEsDataProvider(esAdapter);
299 syncController.registerEntitySynchronizer(ses);
304 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
305 * RestClientBuilder());
307 * entitySearchIndexValidator.setIndexName("esi-sync2-localhost");
308 * entitySearchIndexValidator.setIndexType("default");
310 * syncController.registerIndexValidator(entitySearchIndexValidator);
316 * IndexCleaner index1Cleaner = new ElasticSearchIndexCleaner(nonCachingRestProvider,
317 * "entitysearchindex-localhost", "default", "127.0.0.1", "9200", 5, 5000);
319 * syncController.registerIndexCleaner(index1Cleaner);
324 syncController.performAction(SyncActions.SYNCHRONIZE);
326 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
330 syncController.shutdown();
332 } catch (Exception exc) {
333 exc.printStackTrace();
334 System.out.println("Error: failed to sync with message = " + exc.getMessage());
339 * Do cross entity reference sync.
341 public void doCrossEntityReferenceSync() {
345 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
347 aaiAdapter.setCacheEnabled(true);
350 * InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
351 * aaiAdapter.setEntityCache(aaiInMemoryCache);
354 PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
355 aaiAdapter.setEntityCache(aaiDiskCache);
357 RestClientBuilder clientBuilder = new RestClientBuilder();
358 clientBuilder.setUseHttps(false);
360 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
361 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
363 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig);
365 SyncController syncController = new SyncController("crossEntityRefSyncController");
367 CrossEntityReferenceSynchronizer cers = new CrossEntityReferenceSynchronizer(
368 "entitysearchindex-localhost", ActiveInventoryConfig.getConfig());
369 cers.setAaiDataProvider(aaiAdapter);
370 cers.setEsDataProvider(esAdapter);
371 syncController.registerEntitySynchronizer(cers);
373 SearchableEntitySynchronizer ses =
374 new SearchableEntitySynchronizer("entitysearchindex-localhost");
375 ses.setAaiDataProvider(aaiAdapter);
376 ses.setEsDataProvider(esAdapter);
377 syncController.registerEntitySynchronizer(ses);
379 ElasticSearchConfig config = ElasticSearchConfig.getConfig();
381 IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(
382 nonCachingRestProvider, config.getIndexName(), config.getType(), config.getIpAddress(),
383 config.getHttpPort(), config.buildElasticSearchTableConfig());
385 syncController.registerIndexValidator(entitySearchIndexValidator);
389 IndexCleaner index1Cleaner =
390 new ElasticSearchIndexCleaner(nonCachingRestProvider, config.getIndexName(),
391 config.getType(), config.getIpAddress(), config.getHttpPort(), 5, 5000);
393 syncController.registerIndexCleaner(index1Cleaner);
397 syncController.performAction(SyncActions.SYNCHRONIZE);
399 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
403 syncController.shutdown();
405 } catch (Exception exc) {
406 exc.printStackTrace();
407 System.out.println("Error: Failed to sync with message = " + exc.getMessage());
412 * Do suggestion entitysync.
414 public void doSuggestionEntitySync() {
418 ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
420 aaiAdapter.setCacheEnabled(true);
423 * InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
424 * aaiAdapter.setEntityCache(aaiInMemoryCache);
427 PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
428 aaiAdapter.setEntityCache(aaiDiskCache);
430 RestClientBuilder clientBuilder = new RestClientBuilder();
431 clientBuilder.setUseHttps(false);
433 RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder);
434 ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig();
436 ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig);
438 SyncController syncController = new SyncController("suggestionEntityTestController");
440 AutosuggestionSynchronizer ses =
441 new AutosuggestionSynchronizer("suggestionentityindex-localhost");
442 ses.setAaiDataProvider(aaiAdapter);
443 ses.setEsDataProvider(esAdapter);
444 syncController.registerEntitySynchronizer(ses);
446 syncController.performAction(SyncActions.SYNCHRONIZE);
448 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
452 syncController.shutdown();
454 } catch (Exception exc) {
455 exc.printStackTrace();
456 System.out.println("Error: failed to sync with message = " + exc.getMessage());
463 public void doNoOpSync() {
465 SyncController syncController = new SyncController("noopSyncTestController");
468 * ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder());
470 * aaiAdapter.setCacheEnabled(true);
472 * /*InMemoryEntityCache aaiInMemoryCache = new InMemoryEntityCache();
473 * aaiAdapter.setEntityCache(aaiInMemoryCache);
477 * PersistentEntityCache aaiDiskCache = new PersistentEntityCache();
478 * aaiAdapter.setEntityCache(aaiDiskCache);
480 * ElasticSearchConfig config = ElasticSearchConfig.getConfig(); OXMModelLoader loader =
481 * OXMModelLoader.getInstance(); SyncAdapter syncAdapter = new SyncAdapter(new
482 * RestClientBuilder(), config, loader);
486 * SearchableEntitySynchronizer ses = new SearchableEntitySynchronizer();
487 * ses.setAaiDataProvider(aaiAdapter); ses.setEsDataProvider(syncAdapter);
488 * syncController.registerEntitySynchronizer(ses);
492 * IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(new
493 * RestClientBuilder());
495 * entitySearchIndexValidator.setIndexName("esi-sync2-localhost");
496 * entitySearchIndexValidator.setIndexType("default");
497 * entitySearchIndexValidator.setIndexSettings("");
498 * entitySearchIndexValidator.setIndexSettings("");
500 * syncController.registerIndexValidator(entitySearchIndexValidator);
504 * ElasticSearchEntityPurger p1 = new ElasticSearchEntityPurger(new RestClientBuilder());
505 * p1.setIndexName("esi-blal-blah");
507 * ElasticSearchEntityPurger p2 = new ElasticSearchEntityPurger(new RestClientBuilder());
508 * p2.setIndexName("esi-topo-blah");
512 syncController.performAction(SyncActions.SYNCHRONIZE);
514 while (syncController.getState() == SynchronizerState.PERFORMING_SYNCHRONIZATION) {
518 syncController.shutdown();
520 } catch (Exception exc) {
521 System.out.println("Error: failed to sync with message = " + exc.getMessage());