Adding UI extensibility
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / viewinspect / sync / ViewInspectSyncController.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.viewinspect.sync;
24
25 import org.onap.aai.sparky.crossentityreference.sync.CrossEntityReferenceSynchronizer;
26 import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
27 import org.onap.aai.sparky.dal.ElasticSearchAdapter;
28 import org.onap.aai.sparky.sync.ElasticSearchIndexCleaner;
29 import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
30 import org.onap.aai.sparky.sync.IndexCleaner;
31 import org.onap.aai.sparky.sync.IndexIntegrityValidator;
32 import org.onap.aai.sparky.sync.SyncControllerImpl;
33 import org.onap.aai.sparky.sync.SyncControllerRegistrar;
34 import org.onap.aai.sparky.sync.SyncControllerRegistry;
35 import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
36 import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
37 import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
38 import org.onap.aai.sparky.sync.config.SyncControllerConfig;
39
40 public class ViewInspectSyncController extends SyncControllerImpl
41     implements SyncControllerRegistrar {
42
43   private SyncControllerRegistry syncControllerRegistry;
44   private ActiveInventoryAdapter aaiAdapter;
45   private ElasticSearchAdapter esAdapter;
46   private ElasticSearchSchemaConfig schemaConfig;
47   private ElasticSearchEndpointConfig endpointConfig;
48
49   public ViewInspectSyncController(SyncControllerConfig syncControllerConfig,
50       ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
51       ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
52       NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig)
53       throws Exception {
54     super(syncControllerConfig);
55
56
57     // final String controllerName = "View and Inspect Entity Synchronizer";
58
59     this.aaiAdapter = aaiAdapter;
60     this.esAdapter = esAdapter;
61     this.schemaConfig = schemaConfig;
62     this.endpointConfig = endpointConfig;
63     IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(esAdapter, schemaConfig,
64         endpointConfig, ElasticSearchSchemaFactory.getIndexSchema(schemaConfig));
65
66     registerIndexValidator(indexValidator);
67
68
69     ViewInspectEntitySynchronizer ses = new ViewInspectEntitySynchronizer(schemaConfig,
70         syncControllerConfig.getNumInternalSyncWorkers(),
71         syncControllerConfig.getNumSyncActiveInventoryWorkers(),
72         syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig);
73     ses.setAaiAdapter(aaiAdapter);
74     ses.setElasticSearchAdapter(esAdapter);
75
76     registerEntitySynchronizer(ses);
77
78     CrossEntityReferenceSynchronizer cers = new CrossEntityReferenceSynchronizer(schemaConfig,
79         syncControllerConfig.getNumInternalSyncWorkers(),
80         syncControllerConfig.getNumSyncActiveInventoryWorkers(),
81         syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig);
82
83     cers.setAaiAdapter(aaiAdapter);
84     cers.setElasticSearchAdapter(esAdapter);
85
86     registerEntitySynchronizer(cers);
87
88     IndexCleaner indexCleaner =
89         new ElasticSearchIndexCleaner(esAdapter, endpointConfig, schemaConfig);
90
91     registerIndexCleaner(indexCleaner);
92
93   }
94
95   public SyncControllerRegistry getSyncControllerRegistry() {
96     return syncControllerRegistry;
97   }
98
99   public void setSyncControllerRegistry(SyncControllerRegistry syncControllerRegistry) {
100     this.syncControllerRegistry = syncControllerRegistry;
101   }
102
103   public ActiveInventoryAdapter getAaiAdapter() {
104     return this.aaiAdapter;
105   }
106
107   public ElasticSearchAdapter getElasticSearchAdapter() {
108     return this.esAdapter;
109   }
110
111   public ElasticSearchEndpointConfig getendpointConfig() {
112     return this.endpointConfig;
113   }
114
115   public ElasticSearchSchemaConfig getschemaConfig() {
116     return this.schemaConfig;
117   }
118
119
120   @Override
121   public void registerController() {
122     if (syncControllerRegistry != null) {
123       if (syncControllerConfig.isEnabled()) {
124         syncControllerRegistry.registerSyncController(this);
125       }
126     }
127
128   }
129 }