Convert Sparky to Spring-Boot
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / viewandinspect / sync / ViewInspectGizmoSyncController.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.viewandinspect.sync;
24
25 import org.onap.aai.sparky.config.oxm.OxmEntityContainerLookup;
26 import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
27 import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
28 import org.onap.aai.sparky.dal.ElasticSearchAdapter;
29 import org.onap.aai.sparky.dal.GizmoAdapter;
30 import org.onap.aai.sparky.sync.ElasticSearchIndexCleaner;
31 import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
32 import org.onap.aai.sparky.sync.IndexCleaner;
33 import org.onap.aai.sparky.sync.IndexIntegrityValidator;
34 import org.onap.aai.sparky.sync.SyncControllerImpl;
35 import org.onap.aai.sparky.sync.SyncControllerRegistrar;
36 import org.onap.aai.sparky.sync.SyncControllerRegistry;
37 import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
38 import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
39 import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
40 import org.onap.aai.sparky.sync.config.SyncControllerConfig;
41
42 public class ViewInspectGizmoSyncController extends SyncControllerImpl
43     implements SyncControllerRegistrar {
44
45   private SyncControllerRegistry syncControllerRegistry;
46   //private GizmoAdapter gizmoAdapter;
47   //private ElasticSearchAdapter esAdapter;
48   //private ElasticSearchSchemaConfig schemaConfig;
49   //private ElasticSearchEndpointConfig endpointConfig;
50
51   public ViewInspectGizmoSyncController(SyncControllerConfig syncControllerConfig,
52       GizmoAdapter gizmoAdapter, ElasticSearchAdapter esAdapter,
53       ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
54       NetworkStatisticsConfig gizmoStatConfig, NetworkStatisticsConfig esStatConfig,
55       OxmEntityLookup oxmEntityLookup,
56       SearchableEntityLookup searchableEntityLookup, OxmEntityContainerLookup oxmEntityContainerLookup,
57       ElasticSearchSchemaFactory elasticSearchSchemaFactory) throws Exception {
58     super(syncControllerConfig);
59
60     // final String controllerName = "View and Inspect Entity Synchronizer";
61
62      //this.gizmoAdapter = gizmoAdapter; 
63      //this.esAdapter = esAdapter; 
64      //this.schemaConfig = schemaConfig; 
65      //this.endpointConfig = endpointConfig; 
66      
67     IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(esAdapter, schemaConfig,
68         endpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
69
70     registerIndexValidator(indexValidator);
71
72     ViewInspectGizmoEntitySynchronizer ses = new ViewInspectGizmoEntitySynchronizer(schemaConfig,
73         syncControllerConfig.getNumInternalSyncWorkers(),
74         syncControllerConfig.getNumSyncActiveInventoryWorkers(),
75         syncControllerConfig.getNumSyncElasticWorkers(), gizmoStatConfig, esStatConfig,
76         oxmEntityLookup, searchableEntityLookup, oxmEntityContainerLookup);
77     
78     ses.setGizmoAdapter(gizmoAdapter);
79     ses.setElasticSearchAdapter(esAdapter);
80
81     registerEntitySynchronizer(ses);
82
83     IndexCleaner indexCleaner =
84         new ElasticSearchIndexCleaner(esAdapter, endpointConfig, schemaConfig);
85
86     registerIndexCleaner(indexCleaner);
87
88   }
89
90   public SyncControllerRegistry getSyncControllerRegistry() {
91     return syncControllerRegistry;
92   }
93
94   public void setSyncControllerRegistry(SyncControllerRegistry syncControllerRegistry) {
95     this.syncControllerRegistry = syncControllerRegistry;
96   }
97   
98   @Override
99   public void registerController() {
100     if ( syncControllerRegistry != null ) {
101       if ( syncControllerConfig.isEnabled()) { 
102         syncControllerRegistry.registerSyncController(this);
103       }
104     }
105
106   }
107 }