summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Blimkie <Steven.Blimkie@amdocs.com>2018-08-24 18:06:52 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-24 18:06:52 +0000
commit31b6fc47e12dd137d3a691b20ed4a34df41ac8a4 (patch)
treef2bac541f66994ba87743db4a778e3e77a7b0019
parentf9d3379dfa2b0d67aef0ba4937018d6c6023a77e (diff)
parent11b1339ca114835bf60356b4061f1ff3f3fd3e8b (diff)
Merge "update sync queries to use searh data service"
-rw-r--r--sparkybe-onap-application/config/application.properties3
-rw-r--r--sparkybe-onap-application/config/spring-beans/sparky-elasticsearch.xml21
-rw-r--r--sparkybe-onap-application/config/spring-beans/sparky-oxm.xml16
-rw-r--r--sparkybe-onap-application/config/spring-beans/sparky-sync.xml103
-rw-r--r--sparkybe-onap-application/config/spring-beans/sparky-view-inspect-with-resources.xml4
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java43
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java30
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizer.java380
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncController.java96
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java19
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java16
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java8
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java20
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java30
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ElasticSearchAdapter.java153
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilder.java139
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/GeoVisualizationProcessor.java176
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/entity/GeoIndexDocument.java285
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/entity/TopographicalEntity.java215
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/EntityCountHistoryProcessor.java403
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java61
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java16
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java18
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleaner.java600
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java36
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfig.java68
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformSearchServicePut.java (renamed from sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchPut.java)22
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformSearchServiceRetrieval.java (renamed from sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchRetrieval.java)16
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformSearchServiceUpdate.java (renamed from sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchUpdate.java)14
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java86
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/topology/sync/GeoSyncController.java97
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java477
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java38
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java28
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java26
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizerTest.java372
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncControllerTest.java16
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java34
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizerTest.java34
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java52
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/dal/ElasticSearchAdapterTest.java50
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilderTest.java34
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/GeoIndexDocumentTest.java121
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/entity/TopographicalEntityTest.java50
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/EntityCountHistoryProcessorTest.java118
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizerTest.java12
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AggregationSynchronizerTest.java58
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleanerTest.java122
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfigTest.java39
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/topology/sync/GeoSynchronizerTest.java347
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationServiceTest.java14
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectEntitySynchronizerTest.java34
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectGizmoEntitySynchronizer.java792
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectGizmoSyncController.java107
54 files changed, 370 insertions, 5799 deletions
diff --git a/sparkybe-onap-application/config/application.properties b/sparkybe-onap-application/config/application.properties
index f3ba9a9..4c6b1c0 100644
--- a/sparkybe-onap-application/config/application.properties
+++ b/sparkybe-onap-application/config/application.properties
@@ -7,9 +7,6 @@ spring.mvc.favicon.enabled=false
#For oxm loading there needs to be a combo of [oxm-default OR oxm-override] AND [oxm-schema-dev OR oxm-schema-prod]
spring.profiles.active=camel,ssl,fe-dev,oxm-schema-dev,resources,sync,oxm-override
-elasticsearch.hostname=127.0.0.1
-elasticsearch.port=9200
-
searchservice.hostname=127.0.0.1
searchservice.port=9502
searchservice.client-cert=client-cert-onap.p12
diff --git a/sparkybe-onap-application/config/spring-beans/sparky-elasticsearch.xml b/sparkybe-onap-application/config/spring-beans/sparky-elasticsearch.xml
index b697fed..8f1207e 100644
--- a/sparkybe-onap-application/config/spring-beans/sparky-elasticsearch.xml
+++ b/sparkybe-onap-application/config/spring-beans/sparky-elasticsearch.xml
@@ -8,25 +8,4 @@
<property name="resourceLoader" ref="sparkyResourceLoader" />
</bean>
- <bean id="elasticSearchRestEndpointConfig" class="org.onap.aai.sparky.dal.rest.config.RestEndpointConfig">
- <property name="endpointIpAddress" value="${elasticsearch.hostname:127.0.0.1}" />
- <property name="endpointServerPort" value="${elasticsearch.port:9200}" />
- <property name="numRequestRetries" value="5" />
- <property name="restAuthenticationMode" value="HTTP_NOAUTH" />
- <property name="connectTimeoutInMs" value="60000" />
- <property name="readTimeoutInMs" value="30000" />
- </bean>
-
- <bean id="elasticSearchAdapter" class="org.onap.aai.sparky.dal.ElasticSearchAdapter">
- <constructor-arg ref="elasticSearchRestEndpointConfig" />
- </bean>
-
- <bean id="elasticSearchEndpointConfig"
- class="org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig">
- <property name="esIpAddress" value="${elasticsearch.hostname:127.0.0.1}" />
- <property name="esServerPort" value="${elasticsearch.port:9200}" />
- <property name="scrollContextTimeToLiveInMinutes" value="5" />
- <property name="scrollContextBatchRequestSize" value="5000" />
- </bean>
-
</beans> \ No newline at end of file
diff --git a/sparkybe-onap-application/config/spring-beans/sparky-oxm.xml b/sparkybe-onap-application/config/spring-beans/sparky-oxm.xml
index ecba6cd..fe1eab0 100644
--- a/sparkybe-onap-application/config/spring-beans/sparky-oxm.xml
+++ b/sparkybe-onap-application/config/spring-beans/sparky-oxm.xml
@@ -60,22 +60,6 @@
<property name="searchProviderRegistry" ref="searchProviderRegistry" />
</bean>
- <bean id="entityCountHistoryProcessor" class="org.onap.aai.sparky.search.EntityCountHistoryProcessor">
- <constructor-arg ref="elasticSearchAdapter" />
- <constructor-arg name="entityTypesToSummarizeDelimitedList"
- value="customer,service-instance,complex,pserver,vserver,vnf" />
- <constructor-arg name="vnfEntityTypesDelimitedList"
- value="vnf,newvce,vce,vpe" />
- <constructor-arg name="entityCountHistoryIndexName"
- value="entitycounthistoryindex" />
- </bean>
-
- <bean id="geoVisualizationProcessor" class="org.onap.aai.sparky.inventory.GeoVisualizationProcessor">
- <constructor-arg ref="elasticSearchAdapter" />
- <constructor-arg name="topographicalSearchIndexName"
- value="topographicalsearchindex" />
- </bean>
-
<bean id="pairingHashMap" class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="targetMapClass">
<value>java.util.HashMap</value>
diff --git a/sparkybe-onap-application/config/spring-beans/sparky-sync.xml b/sparkybe-onap-application/config/spring-beans/sparky-sync.xml
index 34c063b..bb976c8 100644
--- a/sparkybe-onap-application/config/spring-beans/sparky-sync.xml
+++ b/sparkybe-onap-application/config/spring-beans/sparky-sync.xml
@@ -74,14 +74,14 @@
class="org.onap.aai.sparky.aggregation.sync.AggregationSyncControllerFactory"
init-method="registerController">
- <constructor-arg ref="elasticSearchEndpointConfig" />
+ <constructor-arg ref="searchServiceRestEndpointConfi" />
<constructor-arg ref="aggregationSyncControllerConfig" />
<constructor-arg ref="syncControllerRegistry" />
<constructor-arg ref="suggestionEntityLookup" />
<constructor-arg ref="oxmEntityLookup" />
<constructor-arg ref="elasticSearchSchemaFactory" />
- <property name="esAdapter" ref="elasticSearchAdapter" />
+ <property name="searchServiceAdapter" ref="searchServiceAdapter" />
<property name="esStatConfig" ref="elasticSearchNetworkStatConfig" />
<property name="aaiAdapter" ref="activeInventoryAdapter" />
@@ -107,51 +107,6 @@
</bean>
-
- <bean id="historicalEntitySyncControllerConfig" class="org.onap.aai.sparky.sync.config.SyncControllerConfig">
-
- <property name="controllerName" value="Historical-Entity-Sync-Controller" />
- <property name="enabled" value="${historicalEntitySyncEnabled:true}" />
- <property name="syncTaskDelayInMs" value="5000" />
- <property name="syncTaskFrequencyInDays" value="1" />
- <property name="numSyncControllerWorkers" value="2" />
- <property name="runOnceSyncEnabled" value="true" />
- <property name="periodicSyncEnabled" value="false" />
- <property name="numInternalSyncWorkers" value="2" />
- <property name="numSyncElasticWorkers" value="5" />
- <property name="numSyncActiveInventoryWorkers" value="5" />
- <property name="targetSyncStartTimeStamp" value="06:00:00 UTC+00:00" />
- </bean>
-
- <bean id="historicalEntitySchemaConfig"
- class="org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig">
- <property name="indexName" value="entitycounthistoryindex" />
- <property name="indexDocType" value="default" />
- <property name="indexMappingsFileName" value="/schemas/entityCountHistoryMappings.json" />
- <property name="indexSettingsFileName" value="/schemas/es_settings.json" />
- </bean>
-
- <bean id="historicalEntitySyncController"
- class="org.onap.aai.sparky.aggregation.sync.HistoricalEntitySyncController"
- init-method="registerController">
-
- <constructor-arg ref="historicalEntitySyncControllerConfig" />
- <constructor-arg ref="activeInventoryAdapter" />
- <constructor-arg ref="elasticSearchAdapter" />
- <constructor-arg ref="historicalEntitySchemaConfig" />
- <constructor-arg ref="elasticSearchEndpointConfig" />
- <constructor-arg value="60" />
- <constructor-arg ref="aaiNetworkStatConfig" />
- <constructor-arg ref="elasticSearchNetworkStatConfig" />
- <constructor-arg ref="searchableEntityLookup" />
- <constructor-arg ref="elasticSearchSchemaFactory" />
-
- <property name="syncControllerRegistry" ref="syncControllerRegistry" />
-
- </bean>
-
-
-
<bean id="autoSuggestionSyncControllerConfig" class="org.onap.aai.sparky.sync.config.SyncControllerConfig">
<property name="controllerName" value="Auto-Suggestion-Sync-Controller" />
@@ -181,9 +136,9 @@
<constructor-arg ref="autoSuggestionSyncControllerConfig" />
<constructor-arg ref="activeInventoryAdapter" />
- <constructor-arg ref="elasticSearchAdapter" />
+ <constructor-arg ref="searchServiceAdapter" />
<constructor-arg ref="autoSuggestionEntitySchemaConfig" />
- <constructor-arg ref="elasticSearchEndpointConfig" />
+ <constructor-arg ref="searchServiceRestEndpointConfig" />
<constructor-arg ref="aaiNetworkStatConfig" />
<constructor-arg ref="elasticSearchNetworkStatConfig" />
<constructor-arg ref="oxmEntityLookup" />
@@ -228,9 +183,9 @@
<constructor-arg ref="vnfAliasSyncControllerConfig" />
<constructor-arg ref="activeInventoryAdapter" />
- <constructor-arg ref="elasticSearchAdapter" />
+ <constructor-arg ref="searchServiceAdapter" />
<constructor-arg ref="vnfAliasEntitySchemaConfig" />
- <constructor-arg ref="elasticSearchEndpointConfig" />
+ <constructor-arg ref="searchServiceRestEndpointConfig" />
<constructor-arg ref="aaiNetworkStatConfig" />
<constructor-arg ref="elasticSearchNetworkStatConfig" />
<constructor-arg ref="filtersConfig" />
@@ -240,48 +195,6 @@
</bean>
- <bean id="geoSyncControllerConfig" class="org.onap.aai.sparky.sync.config.SyncControllerConfig">
-
- <property name="controllerName" value="Geo-Sync-Controller" />
- <property name="enabled" value="${geoSyncEnabled:true}" />
- <property name="syncTaskDelayInMs" value="5000" />
- <property name="syncTaskFrequencyInDays" value="1" />
- <property name="numSyncControllerWorkers" value="2" />
- <property name="runOnceSyncEnabled" value="true" />
- <property name="periodicSyncEnabled" value="false" />
- <property name="numInternalSyncWorkers" value="2" />
- <property name="numSyncElasticWorkers" value="5" />
- <property name="numSyncActiveInventoryWorkers" value="5" />
- <property name="targetSyncStartTimeStamp" value="06:00:00 UTC+00:00" />
- </bean>
-
- <bean id="geoEntitySchemaConfig"
- class="org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig">
- <property name="indexName" value="topographicalsearchindex" />
- <property name="indexDocType" value="default" />
- <property name="indexMappingsFileName" value="/schemas/dynamicMappings.json" />
- </bean>
-
- <bean id="geoSyncController" class="org.onap.aai.sparky.topology.sync.GeoSyncController"
- init-method="registerController">
-
- <constructor-arg ref="geoSyncControllerConfig" />
- <constructor-arg ref="activeInventoryAdapter" />
- <constructor-arg ref="elasticSearchAdapter" />
- <constructor-arg ref="geoEntitySchemaConfig" />
- <constructor-arg ref="elasticSearchEndpointConfig" />
- <constructor-arg ref="aaiNetworkStatConfig" />
- <constructor-arg ref="elasticSearchNetworkStatConfig" />
- <constructor-arg ref="geoEntityLookup" />
- <constructor-arg ref="oxmEntityLookup" />
- <constructor-arg ref="elasticSearchSchemaFactory" />
-
- <property name="syncControllerRegistry" ref="syncControllerRegistry" />
-
- </bean>
-
-
-
<bean id="viewInspectControllerConfig" class="org.onap.aai.sparky.sync.config.SyncControllerConfig">
<property name="controllerName" value="View-Inspect-Sync-Controller" />
@@ -303,9 +216,9 @@
<constructor-arg ref="viewInspectControllerConfig" />
<constructor-arg ref="activeInventoryAdapter" />
- <constructor-arg ref="elasticSearchAdapter" />
+ <constructor-arg ref="searchServiceAdapter" />
<constructor-arg ref="viewInspectSchemaConfig" />
- <constructor-arg ref="elasticSearchEndpointConfig" />
+ <constructor-arg ref="searchServiceRestEndpointConfig" />
<constructor-arg ref="aaiNetworkStatConfig" />
<constructor-arg ref="elasticSearchNetworkStatConfig" />
<constructor-arg ref="crossEntityReferenceLookup" />
diff --git a/sparkybe-onap-application/config/spring-beans/sparky-view-inspect-with-resources.xml b/sparkybe-onap-application/config/spring-beans/sparky-view-inspect-with-resources.xml
index 7c34697..b0d5471 100644
--- a/sparkybe-onap-application/config/spring-beans/sparky-view-inspect-with-resources.xml
+++ b/sparkybe-onap-application/config/spring-beans/sparky-view-inspect-with-resources.xml
@@ -49,8 +49,8 @@
<constructor-arg name="gizmoAdapter">
<null />
</constructor-arg>
- <constructor-arg ref="elasticSearchAdapter" />
- <constructor-arg ref="elasticSearchEndpointConfig" />
+ <constructor-arg ref="searchServiceAdapter" />
+ <constructor-arg ref="searchServiceRestEndpointConfig" />
<constructor-arg ref="viewInspectSchemaConfig" />
<constructor-arg name="numActiveInventoryWorkers"
value="50" />
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java
index 9c3c1d9..7fd7e9c 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java
@@ -30,17 +30,15 @@ import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
import org.onap.aai.sparky.config.oxm.SuggestionEntityLookup;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.sync.ElasticSearchIndexCleaner;
import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
-import org.onap.aai.sparky.sync.IndexCleaner;
import org.onap.aai.sparky.sync.IndexIntegrityValidator;
import org.onap.aai.sparky.sync.SyncController;
import org.onap.aai.sparky.sync.SyncControllerImpl;
import org.onap.aai.sparky.sync.SyncControllerRegistrar;
import org.onap.aai.sparky.sync.SyncControllerRegistry;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
import org.onap.aai.sparky.sync.config.SyncControllerConfig;
@@ -51,13 +49,13 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
LoggerFactory.getInstance().getLogger(AggregationSyncControllerFactory.class);
private ActiveInventoryAdapter aaiAdapter;
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private SuggestionEntityLookup suggestionEntityLookup;
private Map<String, String> aggregationEntityToIndexMap;
private Map<String, ElasticSearchSchemaConfig> indexNameToSchemaConfigMap;
- private ElasticSearchEndpointConfig elasticSearchEndpointConfig;
+ private RestEndpointConfig endpointConfig;
private SyncControllerConfig syncControllerConfig;
private SyncControllerRegistry syncControllerRegistry;
private NetworkStatisticsConfig aaiStatConfig;
@@ -67,14 +65,14 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
private List<SyncController> syncControllers;
- public AggregationSyncControllerFactory(ElasticSearchEndpointConfig esEndpointConfig,
+ public AggregationSyncControllerFactory(RestEndpointConfig endpointConfig,
SyncControllerConfig syncControllerConfig, SyncControllerRegistry syncControllerRegistry,
SuggestionEntityLookup suggestionEntityLookup,
OxmEntityLookup oxmEntityLookup,
ElasticSearchSchemaFactory elasticSearchSchemaFactory) {
this.elasticSearchSchemaFactory = elasticSearchSchemaFactory;
this.syncControllers = new ArrayList<SyncController>();
- this.elasticSearchEndpointConfig = esEndpointConfig;
+ this.endpointConfig = endpointConfig;
this.syncControllerConfig = syncControllerConfig;
this.syncControllerRegistry = syncControllerRegistry;
this.suggestionEntityLookup = suggestionEntityLookup;
@@ -106,13 +104,13 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
this.indexNameToSchemaConfigMap = indexNameToSchemaConfigMap;
}
- public ElasticSearchEndpointConfig getElasticSearchEndpointConfig() {
- return elasticSearchEndpointConfig;
+ public RestEndpointConfig getEndpointConfig() {
+ return endpointConfig;
}
- public void setElasticSearchEndpointConfig(
- ElasticSearchEndpointConfig elasticSearchEndpointConfig) {
- this.elasticSearchEndpointConfig = elasticSearchEndpointConfig;
+ public void setEndpointConfig(
+ RestEndpointConfig endpointConfig) {
+ this.endpointConfig = endpointConfig;
}
public SyncControllerConfig getSyncControllerConfig() {
@@ -131,12 +129,12 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
this.aaiAdapter = aaiAdapter;
}
- public ElasticSearchAdapter getEsAdapter() {
- return esAdapter;
+ public SearchServiceAdapter getSearchServiceAdapter() {
+ return searchServiceAdapter;
}
- public void setEsAdapter(ElasticSearchAdapter esAdapter) {
- this.esAdapter = esAdapter;
+ public void setSearchServiceAdapter(SearchServiceAdapter searchServiceAdapter) {
+ this.searchServiceAdapter = searchServiceAdapter;
}
public SuggestionEntityLookup getSuggestionEntityLookup() {
@@ -185,8 +183,8 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
continue;
}
- IndexIntegrityValidator aggregationIndexValidator = new IndexIntegrityValidator(esAdapter,
- schemaConfig, elasticSearchEndpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
+ IndexIntegrityValidator aggregationIndexValidator = new IndexIntegrityValidator(searchServiceAdapter,
+ schemaConfig, endpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
aggregationSyncController.registerIndexValidator(aggregationIndexValidator);
@@ -197,15 +195,10 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
oxmEntityLookup);
aggSynchronizer.setAaiAdapter(aaiAdapter);
- aggSynchronizer.setElasticSearchAdapter(esAdapter);
+ aggSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
aggregationSyncController.registerEntitySynchronizer(aggSynchronizer);
- IndexCleaner entityDataIndexCleaner =
- new ElasticSearchIndexCleaner(esAdapter, elasticSearchEndpointConfig, schemaConfig);
-
- aggregationSyncController.registerIndexCleaner(entityDataIndexCleaner);
-
syncControllers.add(aggregationSyncController);
} catch (Exception exc) {
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java
index 67015c5..0b9733f 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java
@@ -56,9 +56,9 @@ import org.onap.aai.sparky.sync.entity.SelfLinkDescriptor;
import org.onap.aai.sparky.sync.enumeration.OperationState;
import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchPut;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchRetrieval;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchUpdate;
+import org.onap.aai.sparky.sync.task.PerformSearchServicePut;
+import org.onap.aai.sparky.sync.task.PerformSearchServiceRetrieval;
+import org.onap.aai.sparky.sync.task.PerformSearchServiceUpdate;
import org.onap.aai.sparky.util.NodeUtils;
import org.slf4j.MDC;
@@ -263,7 +263,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
*/
String link = null;
try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), ae.getId());
+ link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), ae.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
return;
@@ -326,9 +326,9 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
if (wasEntryDiscovered) {
if (versionNumber != null && jsonPayload != null) {
- String requestPayload =
- elasticSearchAdapter.buildBulkImportOperationRequest(schemaConfig.getIndexName(),
- schemaConfig.getIndexDocType(), ae.getId(), versionNumber, jsonPayload);
+ String requestPayload =
+ searchServiceAdapter.buildBulkImportOperationRequest(schemaConfig.getIndexName(),
+ ae.getId(),jsonPayload);
NetworkTransaction transactionTracker = new NetworkTransaction();
transactionTracker.setEntityType(esGetTxn.getEntityType());
@@ -336,9 +336,9 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
transactionTracker.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchUpdate(elasticSearchAdapter.getBulkUrl(),
- requestPayload, elasticSearchAdapter, transactionTracker), esPutExecutor)
- .whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServiceUpdate(searchServiceAdapter.buildSearchServiceBulkUrl(),
+ requestPayload, searchServiceAdapter, transactionTracker), esPutExecutor)
+ .whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -363,8 +363,8 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
updateElasticTxn.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
- esPutExecutor).whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServicePut(jsonPayload, updateElasticTxn, searchServiceAdapter),
+ esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -525,7 +525,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
String link = null;
try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), ae.getId());
+ link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), ae.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY, exc.getLocalizedMessage());
}
@@ -539,8 +539,8 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchRetrieval(n2, elasticSearchAdapter), esExecutor)
- .whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServiceRetrieval(n2, searchServiceAdapter), esExecutor)
+ .whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizer.java
deleted file mode 100644
index c6cd3b1..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizer.java
+++ /dev/null
@@ -1,380 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.aggregation.sync;
-
-import static java.util.concurrent.CompletableFuture.supplyAsync;
-
-import java.io.IOException;
-import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.EnumSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Supplier;
-
-import javax.json.Json;
-import javax.ws.rs.core.MediaType;
-
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.cl.mdc.MdcContext;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
-import org.onap.aai.sparky.config.oxm.SearchableOxmEntityDescriptor;
-import org.onap.aai.sparky.dal.rest.HttpMethod;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
-import org.onap.aai.sparky.sync.IndexSynchronizer;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.sync.enumeration.OperationState;
-import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
-import org.onap.aai.sparky.util.NodeUtils;
-import org.slf4j.MDC;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-
-/**
- * The Class HistoricalEntitySummarizer.
- */
-public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
- implements IndexSynchronizer {
-
- private static final Logger LOG = LoggerFactory.getInstance().getLogger(HistoricalEntitySummarizer.class);
- private static final String INSERTION_DATE_TIME_FORMAT = "yyyyMMdd'T'HHmmssZ";
-
- private boolean allWorkEnumerated;
- private ConcurrentHashMap<String, AtomicInteger> entityCounters;
- private boolean syncInProgress;
- private Map<String, String> contextMap;
- private ElasticSearchSchemaConfig schemaConfig;
- private SearchableEntityLookup searchableEntityLookup;
-
- /**
- * Instantiates a new historical entity summarizer.
- *
- * @throws Exception the exception
- */
- public HistoricalEntitySummarizer(ElasticSearchSchemaConfig schemaConfig, int internalSyncWorkers,
- int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig, SearchableEntityLookup searchableEntityLookup)
- throws Exception {
- super(LOG, "HES", internalSyncWorkers, aaiWorkers, esWorkers, schemaConfig.getIndexName(), aaiStatConfig, esStatConfig);
-
- this.schemaConfig = schemaConfig;
- this.allWorkEnumerated = false;
- this.entityCounters = new ConcurrentHashMap<String, AtomicInteger>();
- this.synchronizerName = "Historical Entity Summarizer";
- this.enabledStatFlags = EnumSet.of(StatFlag.AAI_REST_STATS, StatFlag.ES_REST_STATS);
- this.syncInProgress = false;
- this.contextMap = MDC.getCopyOfContextMap();
- this.syncDurationInMs = -1;
- this.searchableEntityLookup = searchableEntityLookup;
- }
-
- /**
- * Collect all the work.
- *
- * @return the operation state
- */
- private OperationState collectAllTheWork() {
-
- Map<String, SearchableOxmEntityDescriptor> descriptorMap =
- searchableEntityLookup.getSearchableEntityDescriptors();
-
- if (descriptorMap.isEmpty()) {
- LOG.error(AaiUiMsgs.OXM_FAILED_RETRIEVAL, "historical entities");
-
- return OperationState.ERROR;
- }
-
- Collection<String> entityTypes = descriptorMap.keySet();
-
- AtomicInteger asyncWoH = new AtomicInteger(0);
-
- asyncWoH.set(entityTypes.size());
-
- try {
- for (String entityType : entityTypes) {
-
- supplyAsync(new Supplier<Void>() {
-
- @Override
- public Void get() {
- MDC.setContextMap(contextMap);
- try {
- OperationResult typeLinksResult =
- aaiAdapter.getSelfLinksByEntityType(entityType);
- updateActiveInventoryCounters(HttpMethod.GET, entityType, typeLinksResult);
- processEntityTypeSelfLinks(entityType, typeLinksResult);
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ERROR_GETTING_DATA_FROM_AAI, exc.getMessage());
-
- }
-
- return null;
- }
-
- }, aaiExecutor).whenComplete((result, error) -> {
-
- asyncWoH.decrementAndGet();
-
- if (error != null) {
- LOG.error(AaiUiMsgs.HISTORICAL_COLLECT_ERROR, error.getMessage());
- }
-
- });
-
- }
-
-
- while (asyncWoH.get() > 0) {
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, indexName + " summarizer waiting for all the links to be processed.");
- }
-
- Thread.sleep(250);
- }
-
- esWorkOnHand.set(entityCounters.size());
-
- // start doing the real work
- allWorkEnumerated = true;
-
- insertEntityTypeCounters();
-
- if (LOG.isDebugEnabled()) {
-
- StringBuilder sb = new StringBuilder(128);
-
- sb.append("\n\nHistorical Entity Counters:");
-
- for (Entry<String, AtomicInteger> entry : entityCounters.entrySet()) {
- sb.append("\n").append(entry.getKey()).append(" = ").append(entry.getValue().get());
- }
-
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, sb.toString());
-
- }
-
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.HISTORICAL_COLLECT_ERROR, exc.getMessage());
-
-
- esWorkOnHand.set(0);
- allWorkEnumerated = true;
-
- return OperationState.ERROR;
- }
-
- return OperationState.OK;
-
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#doSync()
- */
- @Override
- public OperationState doSync() {
- this.syncDurationInMs = -1;
- String txnID = NodeUtils.getRandomTxnId();
- MdcContext.initialize(txnID, "HistoricalEntitySynchronizer", "", "Sync", "");
-
- if (syncInProgress) {
- LOG.info(AaiUiMsgs.HISTORICAL_SYNC_PENDING);
- return OperationState.PENDING;
- }
-
- clearCache();
-
- syncInProgress = true;
- this.syncStartedTimeStampInMs = System.currentTimeMillis();
- allWorkEnumerated = false;
-
- return collectAllTheWork();
- }
-
- /**
- * Process entity type self links.
- *
- * @param entityType the entity type
- * @param operationResult the operation result
- */
- private void processEntityTypeSelfLinks(String entityType, OperationResult operationResult) {
-
- JsonNode rootNode = null;
-
- final String jsonResult = operationResult.getResult();
-
- if (jsonResult != null && jsonResult.length() > 0 && operationResult.wasSuccessful()) {
-
- try {
- rootNode = mapper.readTree(jsonResult);
- } catch (IOException exc) {
- LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, exc.getMessage());
- return;
- }
-
- JsonNode resultData = rootNode.get("result-data");
- ArrayNode resultDataArrayNode = null;
-
- if (resultData != null && resultData.isArray()) {
- resultDataArrayNode = (ArrayNode) resultData;
- entityCounters.put(entityType, new AtomicInteger(resultDataArrayNode.size()));
- }
- }
-
- }
-
- /**
- * Insert entity type counters.
- */
- private void insertEntityTypeCounters() {
-
- if (esWorkOnHand.get() <= 0) {
- return;
- }
-
- SimpleDateFormat dateFormat = new SimpleDateFormat(INSERTION_DATE_TIME_FORMAT);
- Timestamp timestamp = new Timestamp(System.currentTimeMillis());
- String currentFormattedTimeStamp = dateFormat.format(timestamp);
-
- Set<Entry<String, AtomicInteger>> entityCounterEntries = entityCounters.entrySet();
-
- for (Entry<String, AtomicInteger> entityCounterEntry : entityCounterEntries) {
-
- supplyAsync(new Supplier<Void>() {
-
- @Override
- public Void get() {
- MDC.setContextMap(contextMap);
- String jsonString = Json.createObjectBuilder().add(
- "count", entityCounterEntry.getValue().get())
- .add("entityType", entityCounterEntry.getKey())
- .add("timestamp", currentFormattedTimeStamp).build().toString();
-
- String link = null;
- try {
- link = elasticSearchAdapter.buildElasticSearchPostUrl(indexName);
- OperationResult or = elasticSearchAdapter.doPost(link, jsonString, MediaType.APPLICATION_JSON_TYPE);
- updateElasticSearchCounters(HttpMethod.POST, entityCounterEntry.getKey(), or);
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_STORE_FAILURE, exc.getMessage() );
- }
-
- return null;
- }
-
- }, esExecutor).whenComplete((result, error) -> {
-
- esWorkOnHand.decrementAndGet();
-
- });
-
- }
-
- while (esWorkOnHand.get() > 0) {
-
- try {
- Thread.sleep(500);
- } catch (InterruptedException exc) {
- LOG.error(AaiUiMsgs.INTERRUPTED, "historical Entities", exc.getMessage());
- Thread.currentThread().interrupt();
- }
- }
-
- }
-
- @Override
- public SynchronizerState getState() {
-
- if (!isSyncDone()) {
- return SynchronizerState.PERFORMING_SYNCHRONIZATION;
- }
-
- return SynchronizerState.IDLE;
-
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
- */
- @Override
- public String getStatReport(boolean showFinalReport) {
- syncDurationInMs = System.currentTimeMillis() - syncStartedTimeStampInMs;
- return this.getStatReport(syncDurationInMs, showFinalReport);
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#shutdown()
- */
- @Override
- public void shutdown() {
- this.shutdownExecutors();
- }
-
- @Override
- protected boolean isSyncDone() {
-
- int totalWorkOnHand = aaiWorkOnHand.get() + esWorkOnHand.get();
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,indexName + ", isSyncDone(), totalWorkOnHand = " + totalWorkOnHand
- + " all work enumerated = " + allWorkEnumerated);
- }
-
- if (totalWorkOnHand > 0 || !allWorkEnumerated) {
- return false;
- }
-
- this.syncInProgress = false;
-
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.AbstractEntitySynchronizer#clearCache()
- */
- @Override
- public void clearCache() {
-
- if (syncInProgress) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "Historical Entity Summarizer in progress, request to clear cache ignored");
- return;
- }
-
- super.clearCache();
- this.resetCounters();
- if (entityCounters != null) {
- entityCounters.clear();
- }
-
- allWorkEnumerated = false;
-
- }
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncController.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncController.java
deleted file mode 100644
index da1f290..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncController.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.aggregation.sync;
-
-import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
-import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
-import org.onap.aai.sparky.sync.IndexIntegrityValidator;
-import org.onap.aai.sparky.sync.SyncControllerImpl;
-import org.onap.aai.sparky.sync.SyncControllerRegistrar;
-import org.onap.aai.sparky.sync.SyncControllerRegistry;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.sync.config.SyncControllerConfig;
-
-import java.util.concurrent.TimeUnit;
-
-public class HistoricalEntitySyncController extends SyncControllerImpl
- implements SyncControllerRegistrar {
-
- private SyncControllerRegistry syncControllerRegistry;
-
- public HistoricalEntitySyncController(SyncControllerConfig syncControllerConfig,
- ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
- ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
- int syncFrequencyInMinutes, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig, SearchableEntityLookup searchableEntityLookup,
- ElasticSearchSchemaFactory elasticSearchSchemaFactory) throws Exception {
- super(syncControllerConfig);
-
- // final String controllerName = "Historical Entity Count Synchronizer";
-
- long taskFrequencyInMs = getTaskFrequencyInMs(syncFrequencyInMinutes);
-
- setDelayInMs(taskFrequencyInMs);
- setSyncFrequencyInMs(taskFrequencyInMs);
-
- IndexIntegrityValidator entityCounterHistoryValidator = new IndexIntegrityValidator(esAdapter,
- schemaConfig, endpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
-
- registerIndexValidator(entityCounterHistoryValidator);
-
- HistoricalEntitySummarizer historicalSummarizer = new HistoricalEntitySummarizer(schemaConfig,
- syncControllerConfig.getNumInternalSyncWorkers(),
- syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(),aaiStatConfig, esStatConfig,searchableEntityLookup);
-
- historicalSummarizer.setAaiAdapter(aaiAdapter);
- historicalSummarizer.setElasticSearchAdapter(esAdapter);
-
- registerEntitySynchronizer(historicalSummarizer);
-
- }
-
- static long getTaskFrequencyInMs(int syncFrequencyInMinutes) {
- return TimeUnit.MINUTES.toMillis(Integer.toUnsignedLong(syncFrequencyInMinutes));
- }
-
- public SyncControllerRegistry getSyncControllerRegistry() {
- return syncControllerRegistry;
- }
-
- public void setSyncControllerRegistry(SyncControllerRegistry syncControllerRegistry) {
- this.syncControllerRegistry = syncControllerRegistry;
- }
-
- @Override
- public void registerController() {
- if ( syncControllerRegistry != null ) {
- if ( syncControllerConfig.isEnabled()) {
- syncControllerRegistry.registerSyncController(this);
- }
- }
-
- }
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java
index 54b82fb..6596a9d 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java
@@ -23,16 +23,14 @@ package org.onap.aai.sparky.autosuggestion.sync;
import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
import org.onap.aai.sparky.config.oxm.SuggestionEntityLookup;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.search.filters.config.FiltersConfig;
-import org.onap.aai.sparky.sync.ElasticSearchIndexCleaner;
import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
-import org.onap.aai.sparky.sync.IndexCleaner;
import org.onap.aai.sparky.sync.IndexIntegrityValidator;
import org.onap.aai.sparky.sync.SyncControllerImpl;
import org.onap.aai.sparky.sync.SyncControllerRegistrar;
import org.onap.aai.sparky.sync.SyncControllerRegistry;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
import org.onap.aai.sparky.sync.config.SyncControllerConfig;
@@ -43,8 +41,8 @@ public class AutoSuggestionSyncController extends SyncControllerImpl implements
private SyncControllerRegistry syncControllerRegistry;
public AutoSuggestionSyncController(SyncControllerConfig syncControllerConfig,
- ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
- ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
+ ActiveInventoryAdapter aaiAdapter, SearchServiceAdapter searchServiceAdapter,
+ ElasticSearchSchemaConfig schemaConfig, RestEndpointConfig endpointConfig,
NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
OxmEntityLookup oxmEntityLookup, SuggestionEntityLookup suggestionEntityLookup,
FiltersConfig filtersConfig,
@@ -53,7 +51,7 @@ public class AutoSuggestionSyncController extends SyncControllerImpl implements
// final String controllerName = "Auto Suggestion Synchronizer";
- IndexIntegrityValidator autoSuggestionIndexValidator = new IndexIntegrityValidator(esAdapter,
+ IndexIntegrityValidator autoSuggestionIndexValidator = new IndexIntegrityValidator(searchServiceAdapter,
schemaConfig, endpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
registerIndexValidator(autoSuggestionIndexValidator);
@@ -65,15 +63,10 @@ public class AutoSuggestionSyncController extends SyncControllerImpl implements
oxmEntityLookup, suggestionEntityLookup, filtersConfig);
suggestionSynchronizer.setAaiAdapter(aaiAdapter);
- suggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+ suggestionSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
registerEntitySynchronizer(suggestionSynchronizer);
- IndexCleaner autosuggestIndexCleaner =
- new ElasticSearchIndexCleaner(esAdapter, endpointConfig, schemaConfig);
-
- registerIndexCleaner(autosuggestIndexCleaner);
-
}
public SyncControllerRegistry getSyncControllerRegistry() {
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java
index 74ee4ea..583f260 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java
@@ -62,8 +62,8 @@ import org.onap.aai.sparky.sync.entity.SuggestionSearchEntity;
import org.onap.aai.sparky.sync.enumeration.OperationState;
import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchPut;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchRetrieval;
+import org.onap.aai.sparky.sync.task.PerformSearchServicePut;
+import org.onap.aai.sparky.sync.task.PerformSearchServiceRetrieval;
import org.onap.aai.sparky.util.NodeUtils;
import org.onap.aai.sparky.util.SuggestionsPermutation;
import org.slf4j.MDC;
@@ -434,7 +434,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
if (sse.isSuggestableDoc()) {
String link = null;
try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), sse.getId());
+ link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), sse.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY, exc.getLocalizedMessage());
}
@@ -448,8 +448,8 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchRetrieval(n2, elasticSearchAdapter), esExecutor)
- .whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServiceRetrieval(n2, searchServiceAdapter), esExecutor)
+ .whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -515,7 +515,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
*/
String link = null;
try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), sse.getId());
+ link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), sse.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
return;
@@ -552,8 +552,8 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
updateElasticTxn.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
- esPutExecutor).whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServicePut(jsonPayload, updateElasticTxn, searchServiceAdapter),
+ esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java
index fe3ecd0..7501e5d 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java
@@ -40,7 +40,7 @@ import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
import org.onap.aai.sparky.sync.entity.AggregationSuggestionEntity;
import org.onap.aai.sparky.sync.enumeration.OperationState;
import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchPut;
+import org.onap.aai.sparky.sync.task.PerformSearchServicePut;
import org.onap.aai.sparky.util.NodeUtils;
import org.slf4j.MDC;
@@ -119,7 +119,7 @@ public class VnfAliasSuggestionSynchronizer extends AbstractEntitySynchronizer
String link = null;
try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), syncEntity.getId());
+ link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), syncEntity.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
}
@@ -135,8 +135,8 @@ public class VnfAliasSuggestionSynchronizer extends AbstractEntitySynchronizer
esWorkOnHand.incrementAndGet();
final Map<String, String> contextMap = MDC.getCopyOfContextMap();
- supplyAsync(new PerformElasticSearchPut(jsonPayload, elasticPutTxn,
- elasticSearchAdapter, contextMap), esPutExecutor).whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServicePut(jsonPayload, elasticPutTxn,
+ searchServiceAdapter, contextMap), esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java
index c48ee5a..62183fc 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java
@@ -21,16 +21,14 @@
package org.onap.aai.sparky.autosuggestion.sync;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.search.filters.config.FiltersConfig;
-import org.onap.aai.sparky.sync.ElasticSearchIndexCleaner;
import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
-import org.onap.aai.sparky.sync.IndexCleaner;
import org.onap.aai.sparky.sync.IndexIntegrityValidator;
import org.onap.aai.sparky.sync.SyncControllerImpl;
import org.onap.aai.sparky.sync.SyncControllerRegistrar;
import org.onap.aai.sparky.sync.SyncControllerRegistry;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
import org.onap.aai.sparky.sync.config.SyncControllerConfig;
@@ -40,8 +38,8 @@ public class VnfAliasSyncController extends SyncControllerImpl implements SyncCo
private SyncControllerRegistry syncControllerRegistry;
public VnfAliasSyncController(SyncControllerConfig syncControllerConfig,
- ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
- ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
+ ActiveInventoryAdapter aaiAdapter, SearchServiceAdapter searchServiceAdapter,
+ ElasticSearchSchemaConfig schemaConfig, RestEndpointConfig endpointConfig,
NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
FiltersConfig filtersConfig,
ElasticSearchSchemaFactory elasticSearchSchemaFactory) throws Exception {
@@ -49,7 +47,7 @@ public class VnfAliasSyncController extends SyncControllerImpl implements SyncCo
// final String controllerName = "VNFs Alias Suggestion Synchronizer";
- IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(esAdapter, schemaConfig,
+ IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(searchServiceAdapter, schemaConfig,
endpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
registerIndexValidator(indexValidator);
@@ -60,16 +58,10 @@ public class VnfAliasSyncController extends SyncControllerImpl implements SyncCo
syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig, filtersConfig);
synchronizer.setAaiAdapter(aaiAdapter);
- synchronizer.setElasticSearchAdapter(esAdapter);
+ synchronizer.setSearchServiceAdapter(searchServiceAdapter);
registerEntitySynchronizer(synchronizer);
-
- IndexCleaner indexCleaner =
- new ElasticSearchIndexCleaner(esAdapter, endpointConfig, schemaConfig);
-
- registerIndexCleaner(indexCleaner);
-
}
public SyncControllerRegistry getSyncControllerRegistry() {
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java
index 2087fa3..cf7908b 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java
@@ -60,9 +60,9 @@ import org.onap.aai.sparky.sync.entity.SelfLinkDescriptor;
import org.onap.aai.sparky.sync.enumeration.OperationState;
import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchPut;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchRetrieval;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchUpdate;
+import org.onap.aai.sparky.sync.task.PerformSearchServicePut;
+import org.onap.aai.sparky.sync.task.PerformSearchServiceRetrieval;
+import org.onap.aai.sparky.sync.task.PerformSearchServiceUpdate;
import org.onap.aai.sparky.util.NodeUtils;
import org.slf4j.MDC;
@@ -575,8 +575,8 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
String link = null;
try {
- link = elasticSearchAdapter
- .buildElasticSearchGetDocUrl(getIndexName(), icer.getId());
+ link = searchServiceAdapter
+ .buildSearchServiceDocUrl(getIndexName(), icer.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY,
exc.getLocalizedMessage());
@@ -592,8 +592,8 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
esWorkOnHand.incrementAndGet();
supplyAsync(
- new PerformElasticSearchRetrieval(n2, elasticSearchAdapter),
- esExecutor).whenComplete((result, error) -> {
+ new PerformSearchServiceRetrieval(n2, searchServiceAdapter),
+ esExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -669,7 +669,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
*/
String link = null;
try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), icer.getId());
+ link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), icer.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
return;
@@ -728,8 +728,8 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
if (wasEntryDiscovered) {
if (versionNumber != null && jsonPayload != null) {
- String requestPayload = elasticSearchAdapter.buildBulkImportOperationRequest(getIndexName(),
- "default", icer.getId(), versionNumber, jsonPayload);
+ String requestPayload = searchServiceAdapter.buildBulkImportOperationRequest(getIndexName(),
+ icer.getId(), jsonPayload);
NetworkTransaction transactionTracker = new NetworkTransaction();
transactionTracker.setEntityType(esGetResult.getEntityType());
@@ -737,9 +737,9 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
transactionTracker.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchUpdate(elasticSearchAdapter.getBulkUrl(),
- requestPayload, elasticSearchAdapter, transactionTracker), esPutExecutor)
- .whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServiceUpdate(searchServiceAdapter.buildSearchServiceBulkUrl(),
+ requestPayload, searchServiceAdapter, transactionTracker), esPutExecutor)
+ .whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -762,8 +762,8 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
updateElasticTxn.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
- esPutExecutor).whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServicePut(jsonPayload, updateElasticTxn, searchServiceAdapter),
+ esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ElasticSearchAdapter.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ElasticSearchAdapter.java
deleted file mode 100644
index 3072b91..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ElasticSearchAdapter.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.dal;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.core.MediaType;
-
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.restclient.client.RestClient;
-import org.onap.aai.sparky.dal.rest.RestClientConstructionException;
-import org.onap.aai.sparky.dal.rest.RestClientFactory;
-import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
-
-/**
- * The Class ElasticSearchAdapter.
-
- */
-public class ElasticSearchAdapter {
-
- private static final String BULK_IMPORT_INDEX_TEMPLATE =
- "{\"index\":{\"_index\":\"%s\",\"_type\":\"%s\",\"_id\":\"%s\", \"_version\":\"%s\"}}\n";
-
- private static final String BULK_API = "_bulk";
-
- private static final String DEFAULT_TYPE = "default";
-
- private RestClient restClient;
- private RestEndpointConfig endpointConfig;
-
- /**
- * Instantiates a new elastic search adapter.
- * @throws RestClientConstructionException
- */
- public ElasticSearchAdapter(RestEndpointConfig endpointConfig) throws RestClientConstructionException {
-
- this.restClient = RestClientFactory.buildClient(endpointConfig);
- this.endpointConfig = endpointConfig;
-
- }
-
- protected Map<String, List<String>> getMessageHeaders() {
- Map<String, List<String>> headers = new HashMap<String, List<String>>();
- // insert mandatory headers if there are any
- return headers;
- }
-
- public OperationResult doGet(String url, MediaType acceptContentType) {
- return restClient.get(url, getMessageHeaders(), acceptContentType);
- }
-
- public OperationResult doDelete(String url, MediaType acceptContentType) {
- return restClient.delete(url, getMessageHeaders(), acceptContentType);
- }
-
- public OperationResult doPost(String url, String jsonPayload, MediaType acceptContentType) {
- return restClient.post(url, jsonPayload, getMessageHeaders(), MediaType.APPLICATION_JSON_TYPE,
- acceptContentType);
- }
-
- public OperationResult doPut(String url, String jsonPayload, MediaType acceptContentType) {
- return restClient.put(url, jsonPayload, getMessageHeaders(), MediaType.APPLICATION_JSON_TYPE,
- acceptContentType);
- }
-
- public OperationResult doPatch(String url, String jsonPayload, MediaType acceptContentType) {
-
- Map<String,List<String>> headers = getMessageHeaders();
- headers.putIfAbsent("X-HTTP-Method-Override", new ArrayList<String>());
- headers.get("X-HTTP-Method-Override").add("PATCH");
-
- return restClient.post(url, jsonPayload, headers, MediaType.APPLICATION_JSON_TYPE, acceptContentType);
- }
-
- public OperationResult doHead(String url, MediaType acceptContentType) {
- return restClient.head(url, getMessageHeaders(), acceptContentType);
- }
-
- public OperationResult doBulkOperation(String url, String payload) {
- return restClient.put(url, payload, getMessageHeaders(),
- MediaType.APPLICATION_FORM_URLENCODED_TYPE, MediaType.APPLICATION_JSON_TYPE);
- }
-
- public String buildBulkImportOperationRequest(String index, String type, String id,
- String version, String payload) {
-
- StringBuilder requestPayload = new StringBuilder(128);
-
- requestPayload.append(String.format(BULK_IMPORT_INDEX_TEMPLATE, index, type, id, version));
- requestPayload.append(payload).append("\n");
-
- return requestPayload.toString();
-
- }
-
- public OperationResult retrieveEntityById(String host, String port, String indexName,
- String docType, String resourceUrl) {
- String esUrl =
- String.format("http://%s:%s/%s/%s/%s", host, port, indexName, docType, resourceUrl);
- return doGet(esUrl, MediaType.APPLICATION_JSON_TYPE);
- }
-
- public String buildElasticSearchUrlForApi(String indexName, String api) {
- return String.format("http://%s:%s/%s/%s", endpointConfig.getEndpointIpAddress(),
- endpointConfig.getEndpointServerPort(), indexName, api);
- }
-
- public String buildElasticSearchUrl(String indexName, String docType) {
- return String.format("http://%s:%s/%s/%s", endpointConfig.getEndpointIpAddress(),
- endpointConfig.getEndpointServerPort(), indexName, docType);
- }
-
- public String buildElasticSearchGetDocUrl(String indexName, String docType, String docId) {
- return String.format("http://%s:%s/%s/%s/%s", endpointConfig.getEndpointIpAddress(),
- endpointConfig.getEndpointServerPort(), indexName, docType, docId);
- }
-
- public String buildElasticSearchGetDocUrl(String indexName, String docId) {
- return buildElasticSearchGetDocUrl(indexName, DEFAULT_TYPE, docId);
- }
-
- public String buildElasticSearchPostUrl(String indexName) {
- return String.format("http://%s:%s/%s/%s", endpointConfig.getEndpointIpAddress(),
- endpointConfig.getEndpointServerPort(), indexName, DEFAULT_TYPE);
- }
-
- public String getBulkUrl() {
- return String.format("http://%s:%s/%s", endpointConfig.getEndpointIpAddress(),
- endpointConfig.getEndpointServerPort(), BULK_API);
- }
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilder.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilder.java
deleted file mode 100644
index a7f372a..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilder.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.inventory;
-
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonArrayBuilder;
-import javax.json.JsonObject;
-import javax.json.JsonObjectBuilder;
-
-/**
- * The Class EntityHistoryQueryBuilder.
- */
-public class EntityHistoryQueryBuilder {
-
- private static final String TABLE = "table";
- private static final String GRAPH = "graph";
-
- /**
- * Gets the query.
- *
- * @param type the type
- * @return the query
- */
- public static JsonObject getQuery(String type) {
- if (type.equalsIgnoreCase(TABLE)) {
- return createTableQuery();
- } else if (type.equalsIgnoreCase(GRAPH)) {
- return createGraphQuery();
- } else {
- return null;
- }
- }
-
- /**
- * Creates the graph query.
- *
- * @return the json object
- */
- public static JsonObject createGraphQuery() {
- JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
-
- jsonBuilder.add("aggs",
- Json.createObjectBuilder().add("group_by_entityType",
- Json.createObjectBuilder()
- .add("terms", Json.createObjectBuilder().add("field", "entityType").add("size", 0))
- .add("aggs", Json.createObjectBuilder().add("group_by_date",
- Json.createObjectBuilder().add("date_histogram", createDateHistogram())
- .add("aggs", Json.createObjectBuilder().add("sort_by_date",
- Json.createObjectBuilder().add("top_hits", createTopHitsBlob())))))));
- jsonBuilder.add("size", 0);
-
- return jsonBuilder.build();
- }
-
- /**
- * Creates the table query.
- *
- * @return the json object
- */
- public static JsonObject createTableQuery() {
- JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
-
- jsonBuilder.add("aggs",
- Json.createObjectBuilder().add("group_by_entityType",
- Json.createObjectBuilder()
- .add("terms", Json.createObjectBuilder().add("field", "entityType").add("size", 0))
- .add("aggs", Json.createObjectBuilder().add("sort_by_date",
- Json.createObjectBuilder().add("top_hits", createTopHitsBlob())))));
- jsonBuilder.add("size", 0);
-
- return jsonBuilder.build();
- }
-
- /**
- * Creates the date histogram.
- *
- * @return the json object
- */
- private static JsonObject createDateHistogram() {
- JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
-
- jsonBuilder.add("field", "timestamp");
- jsonBuilder.add("min_doc_count", 1);
- jsonBuilder.add("interval", "day");
- jsonBuilder.add("format", "epoch_millis");
-
- return jsonBuilder.build();
- }
-
- /**
- * Creates the top hits blob.
- *
- * @return the json object
- */
- private static JsonObject createTopHitsBlob() {
- JsonObjectBuilder builder = Json.createObjectBuilder();
- builder.add("size", 1);
- builder.add("sort", getSortCriteria());
- return builder.build();
- }
-
- public static JsonArray getSortCriteria() {
- JsonArrayBuilder jsonBuilder = Json.createArrayBuilder();
- jsonBuilder.add(Json.createObjectBuilder().add("timestamp",
- Json.createObjectBuilder().add("order", "desc")));
-
- return jsonBuilder.build();
- }
-
- /**
- * The main method.
- *
- * @param args the arguments
- */
- public static void main(String[] args) {
- System.out.println("TABLE-QUERY: " + createTableQuery().toString());
- System.out.println("GRAPH_QUERY: " + createGraphQuery().toString());
- }
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/GeoVisualizationProcessor.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/GeoVisualizationProcessor.java
deleted file mode 100644
index 9c1f226..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/GeoVisualizationProcessor.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.inventory;
-
-import java.io.IOException;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.component.restlet.RestletConstants;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.cl.mdc.MdcContext;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.util.NodeUtils;
-import org.restlet.Request;
-import org.restlet.Response;
-import org.restlet.data.ClientInfo;
-import org.restlet.data.Form;
-import org.restlet.data.MediaType;
-import org.restlet.data.Parameter;
-import org.restlet.data.Status;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * The Class GeoVisualizationServlet.
- */
-public class GeoVisualizationProcessor {
-
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(GeoVisualizationProcessor.class);
-
- private ObjectMapper mapper;
- private ElasticSearchAdapter elasticSearchAdapter = null;
- private String topographicalSearchIndexName;
-
- private static final String SEARCH_STRING = "_search";
- private static final String SEARCH_PARAMETER = "?filter_path=hits.hits._source&_source=location&size=5000&q=entityType:";
- private static final String PARAMETER_KEY = "entity";
-
- /**
- * Instantiates a new geo visualization processor
- */
- public GeoVisualizationProcessor(ElasticSearchAdapter elasticSearchAdapter, String topographicalSearchIndexName) {
- this.mapper = new ObjectMapper();
- this.elasticSearchAdapter = elasticSearchAdapter;
- this.topographicalSearchIndexName = topographicalSearchIndexName;
- }
-
- /**
- * Gets the geo visualization results.
- *
- * @param response the response
- * @param entityType the entity type
- * @return the geo visualization results
- * @throws Exception the exception
- */
- protected OperationResult getGeoVisualizationResults(Exchange exchange) throws Exception {
- OperationResult operationResult = new OperationResult();
-
-
- Object xTransactionId = exchange.getIn().getHeader("X-TransactionId");
- if (xTransactionId == null) {
- xTransactionId = NodeUtils.getRandomTxnId();
- }
-
- Object partnerName = exchange.getIn().getHeader("X-FromAppId");
- if (partnerName == null) {
- partnerName = "Browser";
- }
-
- Request request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, Request.class);
-
- /* Disables automatic Apache Camel Restlet component logging which prints out an undesirable log entry
- which includes client (e.g. browser) information */
- request.setLoggable(false);
-
- ClientInfo clientInfo = request.getClientInfo();
- MdcContext.initialize((String) xTransactionId, "AAI-UI", "", (String) partnerName, clientInfo.getAddress() + ":" + clientInfo.getPort());
-
- String entityType = "";
-
- Form form = request.getResourceRef().getQueryAsForm();
- for (Parameter parameter : form) {
- if(PARAMETER_KEY.equals(parameter.getName())) {
- entityType = parameter.getName();
- }
- }
-
- String api = SEARCH_STRING + SEARCH_PARAMETER + entityType;
-
- final String requestUrl = elasticSearchAdapter.buildElasticSearchUrlForApi(topographicalSearchIndexName, api);
-
- try {
-
- OperationResult opResult =
- elasticSearchAdapter.doGet(requestUrl, javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE);
-
- JSONObject finalOutputJson = formatOutput(opResult.getResult());
-
- Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
- response.setStatus(Status.SUCCESS_OK);
- response.setEntity(String.valueOf(finalOutputJson), MediaType.APPLICATION_JSON);
- exchange.getOut().setBody(response);
-
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC, "Error processing Geo Visualization request");
- }
-
- return operationResult;
- }
-
- /**
- * Format output.
- *
- * @param results the results
- * @return the JSON object
- */
- private JSONObject formatOutput(String results) {
- JsonNode resultNode = null;
- JSONObject finalResult = new JSONObject();
- JSONArray entitiesArr = new JSONArray();
-
- try {
- resultNode = mapper.readTree(results);
-
- final JsonNode hitsNode = resultNode.get("hits").get("hits");
- if (hitsNode.isArray()) {
-
- for (final JsonNode arrayNode : hitsNode) {
- JsonNode sourceNode = arrayNode.get("_source");
- if (sourceNode.get("location") != null) {
- JsonNode locationNode = sourceNode.get("location");
- if (NodeUtils.isNumeric(locationNode.get("lon").asText())
- && NodeUtils.isNumeric(locationNode.get("lat").asText())) {
- JSONObject location = new JSONObject();
- location.put("longitude", locationNode.get("lon").asText());
- location.put("latitude", locationNode.get("lat").asText());
-
- entitiesArr.put(location);
- }
-
- }
- }
- }
- finalResult.put("plotPoints", entitiesArr);
-
- } catch (IOException exc) {
- LOG.warn(AaiUiMsgs.ERROR_BUILDING_SEARCH_RESPONSE, exc.getLocalizedMessage());
- }
-
- return finalResult;
- }
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/entity/GeoIndexDocument.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/entity/GeoIndexDocument.java
deleted file mode 100644
index 9f775e5..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/entity/GeoIndexDocument.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.inventory.entity;
-
-import java.io.Serializable;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.List;
-
-import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
-import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
-import org.onap.aai.sparky.sync.entity.IndexDocument;
-import org.onap.aai.sparky.util.NodeUtils;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * The Class GeoIndexDocument.
- */
-public class GeoIndexDocument implements Serializable, IndexDocument {
-
- @JsonIgnore
- private static final long serialVersionUID = -5188479658230319058L;
-
- protected String entityType;
- protected String entityPrimaryKeyValue;
- protected String entityPrimaryKeyName;
- protected String latitude;
- protected String longitude;
- protected String selfLink;
-
- @JsonIgnore
- protected OxmEntityLookup oxmEntityLookup;
-
- @JsonIgnore
- protected ObjectMapper mapper = new ObjectMapper();
- // generated, SHA-256 digest
- @JsonIgnore
- protected String id;
-
- /**
- * Convert bytes to hex string.
- *
- * @param bytesToConvert the bytes to convert
- * @return the string
- */
- private static String convertBytesToHexString(byte[] bytesToConvert) {
- StringBuffer hexString = new StringBuffer();
- for (int i = 0; i < bytesToConvert.length; i++) {
- hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
- }
- return hexString.toString();
- }
-
-
- @JsonIgnore
- public boolean isValidGeoDocument() {
-
- boolean isValid = true;
-
- isValid &= (this.getEntityType() != null);
- isValid &= (this.getLatitude() != null);
- isValid &= (this.getLongitude() != null);
- isValid &= (this.getId() != null);
- isValid &= (this.getSelfLink() != null);
-
- isValid &= NodeUtils.isNumeric(this.getLatitude());
- isValid &= NodeUtils.isNumeric(this.getLongitude());
-
- return isValid;
- }
-
- /**
- * Concat array.
- *
- * @param list the list
- * @param delimiter the delimiter
- * @return the string
- */
- private static String concatArray(List<String> list, char delimiter) {
-
- if (list == null || list.size() == 0) {
- return "";
- }
-
- StringBuilder result = new StringBuilder(64);
-
- int listSize = list.size();
- boolean firstValue = true;
-
- for (String item : list) {
-
- if (firstValue) {
- result.append(item);
- firstValue = false;
- } else {
- result.append(delimiter).append(item);
- }
-
- }
-
- return result.toString();
-
- }
-
- /*
- * We'll try and create a unique identity key that we can use for differencing the previously
- * imported record sets as we won't have granular control of what is created/removed and when. The
- * best we can hope for is identification of resources by generated Id until the Identity-Service
- * UUID is tagged against all resources, then we can use that instead.
- */
-
- /**
- * Generate unique sha digest.
- *
- * @param entityType the entity type
- * @param fieldName the field name
- * @param fieldValue the field value
- * @return the string
- * @throws NoSuchAlgorithmException the no such algorithm exception
- */
- public static String generateUniqueShaDigest(String entityType, String fieldName,
- String fieldValue) throws NoSuchAlgorithmException {
-
- /*
- * Basically SHA-256 will result in an identity with a guaranteed uniqueness compared to just a
- * java hashcode value.
- */
- MessageDigest digest = MessageDigest.getInstance("SHA-256");
- digest.update(String.format("%s.%s.%s", entityType, fieldName, fieldValue).getBytes());
- return convertBytesToHexString(digest.digest());
- }
-
- /**
- * Instantiates a new geo index document.
- */
- public GeoIndexDocument() {}
-
- /*
- * (non-Javadoc)
- *
- */
-
- @Override
- @JsonIgnore
- public String getAsJson() throws JsonProcessingException {
-
- if (latitude != null && longitude != null) {
-
- /**
- * A valid entry from this class is one that has both lat and long. If one or both is missing
- * we shouldn't be indexing anything.
- */
-
- return NodeUtils.convertObjectToJson(this, true);
-
- }
-
- return null;
-
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
- */
- @Override
- public void deriveFields() {
-
- /*
- * We'll try and create a unique identity key that we can use for differencing the previously
- * imported record sets as we won't have granular control of what is created/removed and when.
- * The best we can hope for is identification of resources by generated Id until the
- * Identity-Service UUID is tagged against all resources, then we can use that instead.
- */
-
- OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(entityType);
- String entityPrimaryKeyName = NodeUtils.concatArray(
- descriptor.getPrimaryKeyAttributeNames(), "/");
-
- this.id =
- NodeUtils.generateUniqueShaDigest(entityType, entityPrimaryKeyName, entityPrimaryKeyValue);
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "TopographicalEntity [" + ("entityType=" + entityType + ", ")
- + ("entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", ")
- + ("latitude=" + latitude + ", ") + ("longitude=" + longitude + ", ") + ("ID=" + id + ", ")
- + ("selfLink=" + selfLink) + "]";
- }
-
- @Override
- @JsonIgnore
- public String getId() {
- return this.id;
- }
-
- @JsonProperty("entityType")
- public String getEntityType() {
- return entityType;
- }
-
- public void setEntityType(String entityType) {
- this.entityType = entityType;
- }
-
- @JsonProperty("entityPrimaryKeyValue")
- public String getEntityPrimaryKeyValue() {
- return entityPrimaryKeyValue;
- }
-
- public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
- this.entityPrimaryKeyValue = entityPrimaryKeyValue;
- }
-
- @JsonProperty("entityPrimaryKeyName")
- public String getEntityPrimaryKeyName() {
- return entityPrimaryKeyName;
- }
-
- public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
- this.entityPrimaryKeyName = entityPrimaryKeyName;
- }
-
- @JsonProperty("lat")
- public String getLatitude() {
- return latitude;
- }
-
- public void setLatitude(String latitude) {
- this.latitude = latitude;
- }
-
- @JsonProperty("long")
- public String getLongitude() {
- return longitude;
- }
-
- public void setLongitude(String longitude) {
- this.longitude = longitude;
- }
-
- @JsonProperty("link")
- public String getSelfLink() {
- return selfLink;
- }
-
- public void setSelfLink(String selfLink) {
- this.selfLink = selfLink;
- }
-
- @JsonIgnore
- public static long getSerialversionuid() {
- return serialVersionUID;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/entity/TopographicalEntity.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/entity/TopographicalEntity.java
deleted file mode 100644
index 88d47ba..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/inventory/entity/TopographicalEntity.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.inventory.entity;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.List;
-
-import javax.json.Json;
-import javax.json.JsonObject;
-
-/**
- * The Class TopographicalEntity.
- */
-public class TopographicalEntity implements Serializable {
-
- private static final long serialVersionUID = -5188479658230319058L;
-
- protected String entityType;
- protected String entityPrimaryKeyValue;
- protected String entityPrimaryKeyName;
- protected String latitude;
- protected String longitude;
- protected String selfLink;
-
- // generated, SHA-256 digest
- protected String id;
-
- /**
- * Convert bytes to hex string.
- *
- * @param bytesToConvert the bytes to convert
- * @return the string
- */
- private static String convertBytesToHexString(byte[] bytesToConvert) {
- StringBuffer hexString = new StringBuffer();
- for (int i = 0; i < bytesToConvert.length; i++) {
- hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
- }
- return hexString.toString();
- }
-
- /**
- * Concat array.
- *
- * @param list the list
- * @param delimiter the delimiter
- * @return the string
- */
- private static String concatArray(List<String> list, char delimiter) {
-
- if (list == null || list.size() == 0) {
- return "";
- }
-
- StringBuilder result = new StringBuilder(64);
-
- int listSize = list.size();
- boolean firstValue = true;
-
- for (String item : list) {
-
- if (firstValue) {
- result.append(item);
- firstValue = false;
- } else {
- result.append(delimiter).append(item);
- }
-
- }
-
- return result.toString();
-
- }
-
- /*
- * We'll try and create a unique identity key that we can use for differencing the previously
- * imported record sets as we won't have granular control of what is created/removed and when. The
- * best we can hope for is identification of resources by generated Id until the Identity-Service
- * UUID is tagged against all resources, then we can use that instead.
- */
-
- /**
- * Generate unique sha digest.
- *
- * @param entityType the entity type
- * @param fieldName the field name
- * @param fieldValue the field value
- * @return the string
- * @throws NoSuchAlgorithmException the no such algorithm exception
- */
- public static String generateUniqueShaDigest(String entityType, String fieldName,
- String fieldValue) throws NoSuchAlgorithmException {
-
- /*
- * Basically SHA-256 will result in an identity with a guaranteed uniqueness compared to just a
- * java hashcode value.
- */
- MessageDigest digest = MessageDigest.getInstance("SHA-256");
- digest.update(String.format("%s.%s.%s", entityType, fieldName, fieldValue).getBytes());
- return convertBytesToHexString(digest.digest());
- }
-
- /**
- * Instantiates a new topographical entity.
- */
- public TopographicalEntity() {}
-
- /*
- * (non-Javadoc)
- *
- */
- public String getAsJson() throws IOException {
-
- JsonObject obj =
- Json.createObjectBuilder().add("entityType", entityType).add("pkey", entityPrimaryKeyValue)
- .add("location", Json.createObjectBuilder().add("lat", latitude).add("lon", longitude))
- .add("selfLink", selfLink).build();
-
- return obj.toString();
- }
-
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "TopographicalEntity [" + ("entityType=" + entityType + ", ")
- + ("entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", ")
- + ("latitude=" + latitude + ", ") + ("longitude=" + longitude + ", ") + ("ID=" + id + ", ")
- + ("selfLink=" + selfLink) + "]";
- }
-
- public String getId() {
- return this.id;
- }
-
- public String getEntityType() {
- return entityType;
- }
-
- public void setEntityType(String entityType) {
- this.entityType = entityType;
- }
-
- public String getEntityPrimaryKeyValue() {
- return entityPrimaryKeyValue;
- }
-
- public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
- this.entityPrimaryKeyValue = entityPrimaryKeyValue;
- }
-
- public String getEntityPrimaryKeyName() {
- return entityPrimaryKeyName;
- }
-
- public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
- this.entityPrimaryKeyName = entityPrimaryKeyName;
- }
-
- public String getLatitude() {
- return latitude;
- }
-
- public void setLatitude(String latitude) {
- this.latitude = latitude;
- }
-
- public String getLongitude() {
- return longitude;
- }
-
- public void setLongitude(String longitude) {
- this.longitude = longitude;
- }
-
- public String getSelfLink() {
- return selfLink;
- }
-
- public void setSelfLink(String selfLink) {
- this.selfLink = selfLink;
- }
-
- public static long getSerialversionuid() {
- return serialVersionUID;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/EntityCountHistoryProcessor.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/EntityCountHistoryProcessor.java
deleted file mode 100644
index ad651c7..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/EntityCountHistoryProcessor.java
+++ /dev/null
@@ -1,403 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.search;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TreeMap;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.component.restlet.RestletConstants;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.cl.mdc.MdcContext;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.inventory.EntityHistoryQueryBuilder;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.util.NodeUtils;
-import org.onap.aai.sparky.util.RestletUtils;
-import org.restlet.Request;
-import org.restlet.Response;
-import org.restlet.data.ClientInfo;
-import org.restlet.data.MediaType;
-import org.restlet.data.Status;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-
-/**
- * Receives and processes Entity Count History requests
- */
-public class EntityCountHistoryProcessor implements Processor {
-
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(EntityCountHistoryProcessor.class);
-
- private static final long serialVersionUID = 1L;
-
- private ElasticSearchAdapter elasticSearchAdapter = null;
- private ObjectMapper mapper;
-
- private static final String SEARCH_PRETTY_STRING = "_search?pretty";
- private static final String TYPE = "type";
- private static final String TABLE = "table";
- private static final String GRAPH = "graph";
-
- private List<String> entityTypesToSummarize;
- private List<String> vnfEntityTypes;
-
- private String entityCountHistoryIndexName;
-
- private boolean summarizeVnfs = false;
-
- private RestletUtils restletUtils = new RestletUtils();
-
- /**
- * Instantiates a new Entity Count History
- */
-
- public EntityCountHistoryProcessor(ElasticSearchAdapter elasticSearchAdapter,
- String entityTypesToSummarizeDelimitedList, String vnfEntityTypesDelimitedList, String entityCountHistoryIndexName) {
-
- this.elasticSearchAdapter = elasticSearchAdapter;
- this.entityCountHistoryIndexName = entityCountHistoryIndexName;
-
- entityTypesToSummarize =
- Arrays.asList(entityTypesToSummarizeDelimitedList.toLowerCase().split("[\\s,]+"));
-
- vnfEntityTypes =
- Arrays.asList(vnfEntityTypesDelimitedList.toLowerCase().split("[\\s,]+"));
-
- summarizeVnfs = vnfEntityTypesDelimitedList.toLowerCase().contains("vnf");
-
- this.mapper = new ObjectMapper();
- this.mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
- }
-
- /**
- * Processes a entity count history search request
- *
- * @param exchange The Exchange object generated by Apache Camel for the incoming request
- */
-
- @Override
- public void process(Exchange exchange) throws Exception {
-
- Request request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, Request.class);
- Response restletResponse =
- exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
-
- Object xTransactionId = exchange.getIn().getHeader("X-TransactionId");
- if (xTransactionId == null) {
- xTransactionId = NodeUtils.getRandomTxnId();
- }
-
- Object partnerName = exchange.getIn().getHeader("X-FromAppId");
- if (partnerName == null) {
- partnerName = "Browser";
- }
-
- /*
- * Disables automatic Apache Camel Restlet component logging which prints out an undesirable log
- * entry which includes client (e.g. browser) information
- */
- request.setLoggable(false);
-
- ClientInfo clientInfo = request.getClientInfo();
- MdcContext.initialize((String) xTransactionId, "AAI-UI", "", (String) partnerName,
- clientInfo.getAddress() + ":" + clientInfo.getPort());
-
- String typeParameter = getTypeParameter(exchange);
-
- if (null != typeParameter && !typeParameter.isEmpty()) {
- OperationResult operationResult = null;
-
- try {
- operationResult = getResults(restletResponse, typeParameter);
- restletResponse.setEntity(operationResult.getResult(), MediaType.APPLICATION_JSON);
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.CONFIGURATION_ERROR, exc.getLocalizedMessage());
- }
- } else {
- LOG.error(AaiUiMsgs.RESOURCE_NOT_FOUND, request.getOriginalRef().toString());
- String errorMessage =
- restletUtils.generateJsonErrorResponse("Unsupported request. Resource not found.");
- restletResponse.setEntity(errorMessage, MediaType.APPLICATION_JSON);
- restletResponse.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
- }
-
- exchange.getOut().setBody(restletResponse);
- }
-
-
- /**
- * Format line graph output
- *
- * @param results The results
- * @return The JSON object
- * @throws JsonProcessingException The JSON processing exception
- */
- public JSONObject formatLineGraphOutput(String results) throws JsonProcessingException {
- Map<Long, Long> countByDateMap = new HashMap<Long, Long>();
-
- JsonNode resultNode = null;
-
- JSONObject finalResult = new JSONObject();
- JSONArray finalResultArr = new JSONArray();
-
- try {
- resultNode = mapper.readTree(results);
-
- final JsonNode bucketsNode = getBucketsNode(resultNode);
-
- if (bucketsNode.isArray()) {
-
- for (final JsonNode entityNode : bucketsNode) {
- final JsonNode dateBucketNode = entityNode.get("group_by_date").get("buckets");
- if (dateBucketNode.isArray()) {
- for (final JsonNode dateBucket : dateBucketNode) {
- Long date = dateBucket.get("key").asLong();
- final JsonNode countBucketNode =
- dateBucket.get("sort_by_date").get("hits").get("hits");
-
- if (countBucketNode.isArray()) {
- final JsonNode latestEntityNode = countBucketNode.get(0);
-
- long currentCount = latestEntityNode.get("_source").get("count").asLong();
- if (countByDateMap.containsKey(date)) {
- // add to the value if map already contains this date
- currentCount += countByDateMap.get(date);
- }
-
- countByDateMap.put(date, currentCount);
- }
- }
-
- }
- }
- }
-
- /*
- * Sort the map by epoch timestamp
- */
- Map<Long, Long> sortedMap = new TreeMap<Long, Long>(countByDateMap);
- for (Entry<Long, Long> entry : sortedMap.entrySet()) {
- JSONObject dateEntry = new JSONObject();
- dateEntry.put("date", entry.getKey());
- dateEntry.put("count", entry.getValue());
- finalResultArr.put(dateEntry);
- }
-
- } catch (Exception exc) {
- LOG.warn(AaiUiMsgs.ERROR_BUILDING_SEARCH_RESPONSE, exc.getLocalizedMessage());
- }
-
- return finalResult.put("result", finalResultArr);
- }
-
- /**
- * Format table output
- *
- * @param results The results
- * @return The JSON object
- * @throws JsonProcessingException The JSON processing exception
- */
- public JSONObject formatTableOutput(String results) throws JsonProcessingException {
- JsonNode resultNode = null;
-
- JSONObject finalResult = new JSONObject();
- JSONArray entitiesArr = new JSONArray();
-
- Map<String, Long> entityCountInTable = initializeEntityMap();
-
- long vnfCount = 0;
-
- try {
- resultNode = mapper.readTree(results);
-
- final JsonNode bucketsNode = getBucketsNode(resultNode);
- if (bucketsNode.isArray()) {
-
- for (final JsonNode entityNode : bucketsNode) {
- String entityType = entityNode.get("key").asText();
- boolean isAVnf = vnfEntityTypes.contains(entityType);
- long countValue = 0;
-
- if (isAVnf || entityCountInTable.get(entityType) != null) {
- final JsonNode hitsBucketNode = entityNode.get("sort_by_date").get("hits").get("hits");
- if (hitsBucketNode.isArray()) {
- // the first bucket will be the latest
- final JsonNode hitNode = hitsBucketNode.get(0);
-
- countValue = hitNode.get("_source").get("count").asLong();
-
- /*
- * Special case: Add all the VNF types together to get aggregate count
- */
- if (summarizeVnfs && isAVnf) {
- vnfCount += countValue;
- countValue = vnfCount;
- entityType = "vnf";
- }
-
- entityCountInTable.replace(entityType, countValue);
- }
- }
-
- }
- }
- for (Entry<String, Long> entry : entityCountInTable.entrySet()) {
- JSONObject entityType = new JSONObject();
- entityType.put("key", entry.getKey());
- entityType.put("doc_count", entry.getValue());
- entitiesArr.put(entityType);
- }
-
- finalResult.put("result", entitiesArr);
-
- } catch (Exception exc) {
- LOG.warn(AaiUiMsgs.ERROR_BUILDING_RESPONSE_FOR_TABLE_QUERY, exc.getLocalizedMessage());
- }
-
- return finalResult;
- }
-
- /**
- * Gets the results
- *
- * @param response The response
- * @param type The type
- * @return The results
- */
- public OperationResult getResults(Response response, String type) {
- OperationResult operationResult = new OperationResult();
-
- String reqPayload = EntityHistoryQueryBuilder.getQuery(type).toString();
-
- try {
- final String fullUrlStr = elasticSearchAdapter
- .buildElasticSearchUrlForApi(entityCountHistoryIndexName, SEARCH_PRETTY_STRING);
-
- OperationResult opResult = elasticSearchAdapter.doPost(fullUrlStr, reqPayload,
- javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE);
-
- JSONObject finalOutput = null;
- if (type.equalsIgnoreCase(TABLE)) {
- finalOutput = formatTableOutput(opResult.getResult());
- } else if (type.equalsIgnoreCase(GRAPH)) {
- finalOutput = formatLineGraphOutput(opResult.getResult());
- }
-
- if (finalOutput != null) {
- response.setEntity(finalOutput.toString(), MediaType.APPLICATION_JSON);
- operationResult.setResult(finalOutput.toString());
- }
- } catch (JsonProcessingException exc) {
- restletUtils.handleRestletErrors(LOG, "Unable to map JSONpayload", exc, response);
- }
-
- return operationResult;
- }
-
- /**
- * Gets the buckets node
- *
- * @param node The node
- * @return The buckets node
- * @throws Exception The exception
- */
- public JsonNode getBucketsNode(JsonNode node) throws Exception {
- if (node.get("aggregations").get("group_by_entityType").get("buckets") != null) {
- return node.get("aggregations").get("group_by_entityType").get("buckets");
- } else {
- throw new Exception("Failed to map JSON response");
- }
- }
-
- /**
- * Initialize entity map
- *
- * @return the map
- */
- private Map<String, Long> initializeEntityMap() {
- Map<String, Long> entityMap = new HashMap<String, Long>();
- for (String entity : entityTypesToSummarize) {
- entityMap.put(entity, (long) 0);
- }
-
- return entityMap;
- }
-
- /**
- * Extracts the "type" query parameter from the request URI
- *
- * @param exchange
- * @return String containing the value of the "type" query parameter of the request. Returns null
- * if no "type" parameter found
- */
- public String getTypeParameter(Exchange exchange) {
- String typeParameter = null;
-
- String requestUriParameterString = exchange.getIn().getHeader("CamelHttpQuery", String.class);
-
- if (null != requestUriParameterString) {
- String[] requestParameterParts = requestUriParameterString.split("&");
-
- String[] parameter = requestParameterParts[0].split("=");
- String currentParameterKey = parameter[0];
-
- if (null != currentParameterKey && !currentParameterKey.isEmpty()) {
- // Check if we're looking at the "type" parameter key
- if (currentParameterKey.equals(TYPE)) {
- boolean uriIncludesTypeParameterValue =
- (parameter.length >= 2) && !parameter[1].isEmpty();
-
- if (uriIncludesTypeParameterValue) {
- String typeParameterValue = parameter[1];
-
- // Is the parameter value one that we return data for?
- if (typeParameterValue.equalsIgnoreCase(TABLE)
- || typeParameterValue.equalsIgnoreCase(GRAPH)) {
- typeParameter = typeParameterValue;
- }
- }
- }
- }
- }
-
- return typeParameter;
- }
-
-
- public void setRestletUtils(RestletUtils restletUtils) {
- this.restletUtils = restletUtils;
- }
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java
index cb3e5e4..a22170a 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java
@@ -43,6 +43,13 @@ public class SearchServiceAdapter {
private static final String VALUE_QUERY = "query";
private static final String SUGGEST_QUERY = "suggest";
+ private static final String BULK_API = "bulk";
+ private static final String DOCUMENT_EDNPOINT = "documents";
+ private static final String SEARH_SERVICE_BULK_TEMPLATE =
+ "{\"create\":{\"metaData\":{\"url\":\"%s\"},\"document\":\"%s\"}}\n";
+
+ private static final String SEARH_SERVICE_SINGLE_ENTITY_TEMPLATE =
+ "{\"queries\":[{\"must\":{\"match\":{\"field\":\"_id\",\"value\":\"%s\"}}}]}\n";
private RestClient client;
private RestEndpointConfig endpointConfig;
@@ -113,6 +120,13 @@ public class SearchServiceAdapter {
OperationResult or = client.delete(url, getTxnHeader(), MediaType.APPLICATION_JSON_TYPE);
return new OperationResult(or.getResultCode(), or.getResult());
}
+
+ public OperationResult doBulkOperation(String url, String jsonPayload) {
+
+ OperationResult or = client.post(url, jsonPayload, getTxnHeader(),
+ MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON_TYPE);
+ return new OperationResult(or.getResultCode(), or.getResult());
+ }
public Map<String, List<String>> getTxnHeader() {
HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
@@ -121,6 +135,15 @@ public class SearchServiceAdapter {
headers.put("X-FromAppId", Arrays.asList(MDC.get(MdcContext.MDC_PARTNER_NAME)));
return headers;
}
+
+public String buildBulkImportOperationRequest(String indexName, String id, String payload){
+
+ StringBuilder requestPayload = new StringBuilder(128);
+ String SearchTarget = buildSearchServiceDocUrl(indexName,id);
+
+ requestPayload.append(String.format(SEARH_SERVICE_BULK_TEMPLATE,SearchTarget,payload));
+ return requestPayload.toString();
+ }
/**
* Get Full URL for search
@@ -143,12 +166,50 @@ public class SearchServiceAdapter {
public String buildSuggestServiceQueryUrl(String indexName) {
return buildSearchServiceUrlForApi(indexName, SUGGEST_QUERY);
}
+
+ public String buildSearchServiceDocUrl(String indexName,String api) {
+
+ return String.format("https://%s:%s/services/search-data-service/%s/search/indexes/%s/%s/%s",
+ endpointConfig.getEndpointIpAddress(), endpointConfig.getEndpointServerPort(),
+ serviceApiVersion, indexName,DOCUMENT_EDNPOINT, api);
+ }
+
+
+ public String buildSearchServiceCreateDocApi(String indexName){
+
+ return String.format("https://%s:%s/services/search-data-service/%s/search/indexes/%s/%s",
+ endpointConfig.getEndpointIpAddress(), endpointConfig.getEndpointServerPort(),
+ serviceApiVersion, indexName,DOCUMENT_EDNPOINT );
+ }
public String buildSearchServiceUrlForApi(String indexName, String api) {
+
return String.format("https://%s:%s/services/search-data-service/%s/search/indexes/%s/%s",
endpointConfig.getEndpointIpAddress(), endpointConfig.getEndpointServerPort(),
serviceApiVersion, indexName, api);
}
+
+ public String buildSearchServiceBulkUrl() {
+
+ return String.format("https://%s:%s/services/search-data-service/%s/search/%s", endpointConfig.getEndpointIpAddress(),
+ endpointConfig.getEndpointServerPort(),serviceApiVersion,BULK_API);
+ }
+
+ public OperationResult retrieveEntityById(String entityId,String indexName) {
+
+ StringBuilder requestPayload = new StringBuilder(128);
+ requestPayload.append(String.format(SEARH_SERVICE_SINGLE_ENTITY_TEMPLATE,entityId));
+ String payload = requestPayload.toString();
+ String searchServiceUrl = buildSearchServiceQueryUrl(indexName);
+
+ return this.doPost(searchServiceUrl,payload);
+ }
+
+public String buildSearchServiceCreateIndexUrl(String indexName) {
+
+ return String.format("https://%s:%s/services/search-data-service/%s/search/indexes/dynamic/%s", endpointConfig.getEndpointIpAddress(),
+ endpointConfig.getEndpointServerPort(),serviceApiVersion,indexName);
+ }
}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java
index 707f907..1eb1823 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java
@@ -31,11 +31,10 @@ import org.json.JSONObject;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.search.filters.config.UiFilterDataSourceConfig;
import org.onap.aai.sparky.search.filters.entity.UiFilterEntity;
-import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
/**
@@ -51,10 +50,10 @@ public class FilterElasticSearchAdapter {
private static final String CONTAINER = "default";
private static final String BUCKETS = "buckets";
private static final String FILTER_VALUE_KEY = "key";
- private ElasticSearchAdapter elasticSearchAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
- public FilterElasticSearchAdapter(ElasticSearchAdapter elasticSearchAdapter) {
- this.elasticSearchAdapter = elasticSearchAdapter;
+ public FilterElasticSearchAdapter(SearchServiceAdapter searchServiceAdapter) {
+ this.searchServiceAdapter = searchServiceAdapter;
}
/**
@@ -76,10 +75,9 @@ public class FilterElasticSearchAdapter {
filterValueQuery = FilterQueryBuilder.createFilterValueQueryObject(dataSourceConfig.getFieldName());
}
- OperationResult opResult = elasticSearchAdapter.doPost(
- elasticSearchAdapter.buildElasticSearchUrlForApi(dataSourceConfig.getIndexName(),
- SparkyConstants.ES_SEARCH_API),
- filterValueQuery.toString(), MediaType.APPLICATION_JSON_TYPE);
+ OperationResult opResult = searchServiceAdapter.doPost(
+ searchServiceAdapter.buildSearchServiceQueryUrl(dataSourceConfig.getIndexName()),
+ filterValueQuery.toString(), "application/json");
String result = opResult.getResult();
if(opResult.wasSuccessful() && result != null) {
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java
index 444eafb..a85e9f2 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java
@@ -30,7 +30,7 @@ import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.cl.mdc.MdcContext;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.dal.NetworkTransaction;
import org.onap.aai.sparky.dal.aai.ActiveInventoryEntityStatistics;
import org.onap.aai.sparky.dal.aai.ActiveInventoryProcessingExceptionStatistics;
@@ -39,7 +39,7 @@ import org.onap.aai.sparky.dal.rest.HttpMethod;
import org.onap.aai.sparky.dal.rest.RestOperationalStatistics;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchRetrieval;
+import org.onap.aai.sparky.sync.task.PerformSearchServiceRetrieval;
import org.onap.aai.sparky.util.NodeUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -72,7 +72,7 @@ public abstract class AbstractEntitySynchronizer {
protected EnumSet<StatFlag> enabledStatFlags;
- protected ElasticSearchAdapter elasticSearchAdapter;
+ protected SearchServiceAdapter searchServiceAdapter;
protected ActiveInventoryAdapter aaiAdapter;
protected ExecutorService synchronizerExecutor;
@@ -362,12 +362,12 @@ public abstract class AbstractEntitySynchronizer {
*/
public void clearCache() {}
- public ElasticSearchAdapter getElasticSearchAdapter() {
- return elasticSearchAdapter;
+ public SearchServiceAdapter getSearchServiceAdapter() {
+ return searchServiceAdapter;
}
- public void setElasticSearchAdapter(ElasticSearchAdapter elasticSearchAdapter) {
- this.elasticSearchAdapter = elasticSearchAdapter;
+ public void setSearchServiceAdapter(SearchServiceAdapter searchServiceAdapter) {
+ this.searchServiceAdapter = searchServiceAdapter;
}
public ActiveInventoryAdapter getAaiAdapter() {
@@ -531,7 +531,7 @@ public abstract class AbstractEntitySynchronizer {
/*
* In this retry flow the se object has already derived its fields
*/
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), id);
+ link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), id);
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_URI, exc.getLocalizedMessage());
}
@@ -548,7 +548,7 @@ public abstract class AbstractEntitySynchronizer {
* called incrementAndGet when queuing the failed PUT!
*/
- supplyAsync(new PerformElasticSearchRetrieval(retryTransaction, elasticSearchAdapter),
+ supplyAsync(new PerformSearchServiceRetrieval(retryTransaction, searchServiceAdapter),
esExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleaner.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleaner.java
deleted file mode 100644
index a397d91..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleaner.java
+++ /dev/null
@@ -1,600 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.sync;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.ws.rs.core.MediaType;
-
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.entity.ObjectIdCollection;
-import org.onap.aai.sparky.sync.entity.SearchableEntity;
-import org.onap.aai.sparky.sync.enumeration.OperationState;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * The Class ElasticSearchIndexCleaner.
- */
-public class ElasticSearchIndexCleaner implements IndexCleaner {
-
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(ElasticSearchIndexCleaner.class);
-
- private static final String BULK_OP_LINE_TEMPLATE = "%s\n";
- private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
-
- private ObjectIdCollection before;
- private ObjectIdCollection after;
-
- private ObjectMapper mapper;
- private ElasticSearchAdapter esAdapter;
- private ElasticSearchEndpointConfig endpointConfig;
- private ElasticSearchSchemaConfig schemaConfig;
-
- /**
- * Instantiates a new elastic search index cleaner.
- *
- * @param restDataProvider the rest data provider
- * @param indexName the index name
- * @param indexType the index type
- * @param host the host
- * @param port the port
- * @param scrollContextTimeToLiveInMinutes the scroll context time to live in minutes
- * @param numItemsToGetBulkRequest the num items to get bulk request
- */
- public ElasticSearchIndexCleaner(ElasticSearchAdapter esAdapter, ElasticSearchEndpointConfig endpointConfig, ElasticSearchSchemaConfig schemaConfig) {
- this.esAdapter = esAdapter;
- this.before = null;
- this.after = null;
- this.endpointConfig = endpointConfig;
- this.schemaConfig = schemaConfig;
- this.mapper = new ObjectMapper();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.synchronizer.IndexCleaner#populatePreOperationCollection()
- */
- @Override
- public OperationState populatePreOperationCollection() {
-
- try {
- before = retrieveAllDocumentIdentifiers();
- return OperationState.OK;
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_PRE_SYNC_FAILURE, schemaConfig.getIndexName(), exc.getMessage());
- return OperationState.ERROR;
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.synchronizer.IndexCleaner#populatePostOperationCollection()
- */
- @Override
- public OperationState populatePostOperationCollection() {
- try {
- after = retrieveAllDocumentIdentifiers();
- return OperationState.OK;
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_PRE_SYNC_FAILURE, schemaConfig.getIndexName(), exc.getMessage());
- return OperationState.ERROR;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.synchronizer.IndexCleaner#performCleanup()
- */
- @Override
- public OperationState performCleanup() {
- // TODO Auto-generated method stub
- LOG.info(AaiUiMsgs.ES_SYNC_CLEAN_UP, schemaConfig.getIndexName());
-
- int sizeBefore = before.getSize();
- int sizeAfter = after.getSize();
-
- LOG.info(AaiUiMsgs.ES_SYNC_CLEAN_UP_SIZE, String.valueOf(sizeBefore),
- String.valueOf(sizeAfter));
-
- /*
- * If the processedImportIds size <= 0, then something has failed in the sync operation and we
- * shouldn't do the selective delete right now.
- */
-
- if (sizeAfter > 0) {
-
- Collection<String> presyncIds = before.getImportedObjectIds();
- presyncIds.removeAll(after.getImportedObjectIds());
-
- try {
- LOG.info(AaiUiMsgs.ES_SYNC_SELECTIVE_DELETE, schemaConfig.getIndexName(), schemaConfig.getIndexDocType(),
- String.valueOf(presyncIds.size()));
-
- ObjectIdCollection bulkIds = new ObjectIdCollection();
-
- Iterator<String> it = presyncIds.iterator();
- int numItemsInBulkRequest = 0;
- int numItemsRemainingToBeDeleted = presyncIds.size();
-
- while (it.hasNext()) {
-
- bulkIds.addObjectId(it.next());
- numItemsInBulkRequest++;
-
- if (numItemsInBulkRequest >= endpointConfig.getScrollContextBatchRequestSize()) {
- LOG.info(AaiUiMsgs.ES_BULK_DELETE, schemaConfig.getIndexName(), String.valueOf(bulkIds.getSize()));
- bulkDelete(bulkIds.getImportedObjectIds());
- numItemsRemainingToBeDeleted -= numItemsInBulkRequest;
- numItemsInBulkRequest = 0;
- bulkIds.clear();
- }
- }
-
- if (numItemsRemainingToBeDeleted > 0) {
- LOG.info(AaiUiMsgs.ES_BULK_DELETE, schemaConfig.getIndexName(), String.valueOf(bulkIds.getSize()));
- bulkDelete(bulkIds.getImportedObjectIds());
- }
-
-
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_BULK_DELETE_ERROR, schemaConfig.getIndexName(), exc.getLocalizedMessage());
-
- }
- }
-
- return OperationState.OK;
- }
-
- @Override
- public String getIndexName() {
- return schemaConfig.getIndexName();
- }
-
- /**
- * Builds the initial scroll request payload.
- *
- * @param numItemsToGetPerRequest the num items to get per request
- * @param fieldList the field list
- * @return the string
- * @throws JsonProcessingException the json processing exception
- */
- protected String buildInitialScrollRequestPayload(int numItemsToGetPerRequest,
- List<String> fieldList) throws JsonProcessingException {
-
- ObjectNode rootNode = mapper.createObjectNode();
- rootNode.put("size", numItemsToGetPerRequest);
-
- ArrayNode fields = mapper.createArrayNode();
-
- for (String f : fieldList) {
- fields.add(f);
- }
-
- rootNode.set("fields", fields);
-
- ObjectNode queryNode = mapper.createObjectNode();
- queryNode.set("match_all", mapper.createObjectNode());
-
- rootNode.set("query", queryNode);
-
- return mapper.writeValueAsString(rootNode);
-
- }
-
- /**
- * Builds the subsequent scroll context request payload.
- *
- * @param scrollId the scroll id
- * @param contextTimeToLiveInMinutes the context time to live in minutes
- * @return the string
- * @throws JsonProcessingException the json processing exception
- */
- protected String buildSubsequentScrollContextRequestPayload(String scrollId,
- int contextTimeToLiveInMinutes) throws JsonProcessingException {
-
- ObjectNode rootNode = mapper.createObjectNode();
-
- rootNode.put("scroll", contextTimeToLiveInMinutes + "m");
- rootNode.put("scroll_id", scrollId);
-
- return mapper.writeValueAsString(rootNode);
-
- }
-
- /**
- * Parses the elastic search result.
- *
- * @param jsonResult the json result
- * @return the json node
- * @throws JsonProcessingException the json processing exception
- * @throws IOException Signals that an I/O exception has occurred.
- */
- protected JsonNode parseElasticSearchResult(String jsonResult)
- throws JsonProcessingException, IOException {
- ObjectMapper mapper = new ObjectMapper();
- return mapper.readTree(jsonResult);
- }
-
- /**
- * Lookup index doc.
- *
- * @param ids the ids
- * @param docs the docs
- * @return the array list
- */
- protected ArrayList<SearchableEntity> lookupIndexDoc(ArrayList<String> ids,
- List<SearchableEntity> docs) {
- ArrayList<SearchableEntity> objs = new ArrayList<SearchableEntity>();
-
- if (ids != null && docs != null) {
- for (SearchableEntity d : docs) {
- if (ids.contains(d.getId())) {
- objs.add(d);
- }
- }
- }
-
- return objs;
- }
-
- /**
- * Builds the delete data object.
- *
- * @param index the index
- * @param type the type
- * @param id the id
- * @return the object node
- */
- protected ObjectNode buildDeleteDataObject(String index, String type, String id) {
-
- ObjectNode indexDocProperties = mapper.createObjectNode();
-
- indexDocProperties.put("_index", index);
- indexDocProperties.put("_type", type);
- indexDocProperties.put("_id", id);
-
- ObjectNode rootNode = mapper.createObjectNode();
- rootNode.set("delete", indexDocProperties);
-
- return rootNode;
- }
-
- /**
- * This method might appear to be a little strange, and is simply an optimization to take an
- * elipsed JsonNode key path and retrieve the node at the end of the path, if it exists.
- *
- * @param startNode the start node
- * @param fieldPath the field path
- * @return the node path
- */
- protected JsonNode getNodePath(JsonNode startNode, String... fieldPath) {
-
- JsonNode jsonNode = null;
-
- for (String field : fieldPath) {
- if (jsonNode == null) {
- jsonNode = startNode.get(field);
- } else {
- jsonNode = jsonNode.get(field);
- }
-
- /*
- * This is our safety net in case any intermediate path returns a null
- */
-
- if (jsonNode == null) {
- return null;
- }
-
- }
-
- return jsonNode;
- }
-
- /**
- * Gets the full url.
- *
- * @param resourceUrl the resource url
- * @return the full url
- */
- private String getFullUrl(String resourceUrl) {
- return String.format("http://%s:%s%s", endpointConfig.getEsIpAddress(),
- endpointConfig.getEsServerPort(), resourceUrl);
- }
-
- /**
- * Retrieve all document identifiers.
- *
- * @return the object id collection
- * @throws IOException Signals that an I/O exception has occurred.
- */
- public ObjectIdCollection retrieveAllDocumentIdentifiers() throws IOException {
-
- ObjectIdCollection currentDocumentIds = new ObjectIdCollection();
-
- long opStartTimeInMs = System.currentTimeMillis();
-
- List<String> fields = new ArrayList<String>();
- fields.add("_id");
- // fields.add("entityType");
-
- String scrollRequestPayload =
- buildInitialScrollRequestPayload(endpointConfig.getScrollContextBatchRequestSize(), fields);
-
- final String fullUrlStr = getFullUrl("/" + schemaConfig.getIndexName()+ "/" + schemaConfig.getIndexDocType() + "/_search?scroll="
- + endpointConfig.getScrollContextTimeToLiveInMinutes() + "m");
-
- OperationResult result =
- esAdapter.doPost(fullUrlStr, scrollRequestPayload, MediaType.APPLICATION_JSON_TYPE);
-
- if (result.wasSuccessful()) {
-
- JsonNode rootNode = parseElasticSearchResult(result.getResult());
-
- /*
- * Check the result for success / failure, and enumerate all the index ids that resulted in
- * success, and ignore the ones that failed or log them so we have a record of the failure.
- */
- int totalRecordsAvailable = 0;
- String scrollId = null;
- int numRecordsFetched = 0;
-
- if (rootNode != null) {
-
- scrollId = getFieldValue(rootNode, "_scroll_id");
- final String tookStr = getFieldValue(rootNode, "took");
- int tookInMs = (tookStr == null) ? 0 : Integer.parseInt(tookStr);
- boolean timedOut = Boolean.parseBoolean(getFieldValue(rootNode, "timed_out"));
-
- if (timedOut) {
- LOG.error(AaiUiMsgs.COLLECT_TIME_WITH_ERROR, "all document Identifiers",
- String.valueOf(tookInMs));
- } else {
- LOG.info(AaiUiMsgs.COLLECT_TIME_WITH_SUCCESS, "all document Identifiers",
- String.valueOf(tookInMs));
- }
-
- JsonNode hitsNode = rootNode.get("hits");
- totalRecordsAvailable = Integer.parseInt(hitsNode.get("total").asText());
-
- LOG.info(AaiUiMsgs.COLLECT_TOTAL, "all document Identifiers",
- String.valueOf(totalRecordsAvailable));
-
- /*
- * Collect all object ids
- */
-
- ArrayNode hitsArray = (ArrayNode) hitsNode.get("hits");
-
- Iterator<JsonNode> nodeIterator = hitsArray.iterator();
-
- String key = null;
- String value = null;
- JsonNode jsonNode = null;
-
- while (nodeIterator.hasNext()) {
-
- jsonNode = nodeIterator.next();
-
- key = getFieldValue(jsonNode, "_id");
-
- if (key != null) {
- currentDocumentIds.addObjectId(key);
- }
-
- }
-
- int totalRecordsRemainingToFetch = (totalRecordsAvailable - numRecordsFetched);
-
- int numRequiredAdditionalFetches =
- (totalRecordsRemainingToFetch / endpointConfig.getScrollContextBatchRequestSize());
-
- /*
- * Do an additional fetch for the remaining items (if needed)
- */
-
- if (totalRecordsRemainingToFetch % endpointConfig.getScrollContextBatchRequestSize() != 0) {
- numRequiredAdditionalFetches += 1;
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.SYNC_NUMBER_REQ_FETCHES,
- String.valueOf(numRequiredAdditionalFetches));
- }
-
-
- for (int x = 0; x < numRequiredAdditionalFetches; x++) {
-
- if (collectItemsFromScrollContext(scrollId, currentDocumentIds) != OperationState.OK) {
- // abort the whole thing because now we can't reliably cleanup the orphans.
- throw new IOException(
- "Failed to collect pre-sync doc collection from index. Aborting operation");
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.SYNC_NUMBER_TOTAL_FETCHES,
- String.valueOf(currentDocumentIds.getSize()),
- String.valueOf(totalRecordsAvailable));
- }
-
- }
-
- }
-
- } else {
- // scroll context get failed, nothing else to do
- LOG.error(AaiUiMsgs.ERROR_GENERIC, result.toString());
- }
-
- LOG.info(AaiUiMsgs.COLLECT_TOTAL_TIME, "all document Identifiers",
- String.valueOf((System.currentTimeMillis() - opStartTimeInMs)));
-
- return currentDocumentIds;
-
- }
-
- /**
- * Collect items from scroll context.
- *
- * @param scrollId the scroll id
- * @param objectIds the object ids
- * @return the operation state
- * @throws IOException Signals that an I/O exception has occurred.
- */
- private OperationState collectItemsFromScrollContext(String scrollId,
- ObjectIdCollection objectIds) throws IOException {
-
- String requestPayload = buildSubsequentScrollContextRequestPayload(scrollId,
- endpointConfig.getScrollContextTimeToLiveInMinutes());
-
- final String fullUrlStr = getFullUrl("/_search/scroll");
-
- OperationResult opResult =
- esAdapter.doPost(fullUrlStr, requestPayload, MediaType.APPLICATION_JSON_TYPE);
-
- if (opResult.getResultCode() >= 300) {
- LOG.warn(AaiUiMsgs.ES_SCROLL_CONTEXT_ERROR, opResult.getResult());
- return OperationState.ERROR;
- }
-
- JsonNode rootNode = parseElasticSearchResult(opResult.getResult());
- boolean timedOut = Boolean.parseBoolean(getFieldValue(rootNode, "timed_out"));
- final String tookStr = getFieldValue(rootNode, "took");
- int tookInMs = (tookStr == null) ? 0 : Integer.parseInt(tookStr);
-
- JsonNode hitsNode = rootNode.get("hits");
-
- /*
- * Check the result for success / failure, and enumerate all the index ids that resulted in
- * success, and ignore the ones that failed or log them so we have a record of the failure.
- */
-
- if (rootNode != null) {
-
- if (timedOut) {
- LOG.info(AaiUiMsgs.COLLECT_TIME_WITH_ERROR, "Scroll Context", String.valueOf(tookInMs));
- } else {
- LOG.info(AaiUiMsgs.COLLECT_TIME_WITH_SUCCESS, "Scroll Context", String.valueOf(tookInMs));
- }
-
- /*
- * Collect all object ids
- */
-
- ArrayNode hitsArray = (ArrayNode) hitsNode.get("hits");
- String key = null;
- String value = null;
- JsonNode jsonNode = null;
-
- Iterator<JsonNode> nodeIterator = hitsArray.iterator();
-
- while (nodeIterator.hasNext()) {
-
- jsonNode = nodeIterator.next();
-
- key = getFieldValue(jsonNode, "_id");
-
- if (key != null) {
- objectIds.addObjectId(key);
-
- }
-
- }
- }
-
- return OperationState.OK;
- }
-
- /**
- * Gets the field value.
- *
- * @param node the node
- * @param fieldName the field name
- * @return the field value
- */
- protected String getFieldValue(JsonNode node, String fieldName) {
-
- JsonNode field = node.get(fieldName);
-
- if (field != null) {
- return field.asText();
- }
-
- return null;
-
- }
-
- /**
- * Bulk delete.
- *
- * @param docIds the doc ids
- * @return the operation result
- * @throws IOException Signals that an I/O exception has occurred.
- */
- public OperationResult bulkDelete(Collection<String> docIds) throws IOException {
-
- if (docIds == null || docIds.size() == 0) {
- LOG.info(AaiUiMsgs.ES_BULK_DELETE_SKIP);
- return new OperationResult(500,
- "Skipping bulkDelete(); operation because docs to delete list is empty");
- }
-
- LOG.info(AaiUiMsgs.ES_BULK_DELETE_START, String.valueOf(docIds.size()));
-
- StringBuilder sb = new StringBuilder(128);
-
- for (String id : docIds) {
- sb.append(String.format(BULK_OP_LINE_TEMPLATE,
- buildDeleteDataObject(schemaConfig.getIndexName(), schemaConfig.getIndexDocType(), id)));
- }
-
- sb.append("\n");
-
- final String fullUrlStr = getFullUrl("/_bulk");
-
- return esAdapter.doPost(fullUrlStr, sb.toString(), MediaType.APPLICATION_FORM_URLENCODED_TYPE);
-
- }
-
- /*
-
- */
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java
index c83aa72..c9d8272 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java
@@ -25,9 +25,9 @@ import javax.ws.rs.core.MediaType;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
+import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
/**
@@ -38,11 +38,11 @@ public class IndexIntegrityValidator implements IndexValidator {
private static final Logger LOG =
LoggerFactory.getInstance().getLogger(IndexIntegrityValidator.class);
- private ElasticSearchEndpointConfig endpointConfig;
+ private RestEndpointConfig endpointConfig;
private ElasticSearchSchemaConfig schemaConfig;
private String tableConfigJson;
- private final ElasticSearchAdapter esAdapter;
+ private final SearchServiceAdapter searchServiceAdapter;
/**
* Instantiates a new index integrity validator.
@@ -54,21 +54,21 @@ public class IndexIntegrityValidator implements IndexValidator {
* @param port the port
* @param tableConfigJson the table config json
*/
- public IndexIntegrityValidator(ElasticSearchAdapter esAdapter,
- ElasticSearchSchemaConfig esSchemaConfig, ElasticSearchEndpointConfig esEndpointConfig,
+ public IndexIntegrityValidator(SearchServiceAdapter searchServiceAdapter,
+ ElasticSearchSchemaConfig esSchemaConfig, RestEndpointConfig esEndpointConfig,
String tableConfigJson) {
- this.esAdapter = esAdapter;
+ this.searchServiceAdapter = searchServiceAdapter;
this.schemaConfig = esSchemaConfig;
this.endpointConfig = esEndpointConfig;
this.tableConfigJson = tableConfigJson;
}
- public ElasticSearchEndpointConfig getEndpointConfig() {
+ public RestEndpointConfig getEndpointConfig() {
return endpointConfig;
}
- public void setEndpointConfig(ElasticSearchEndpointConfig endpointConfig) {
+ public void setEndpointConfig(RestEndpointConfig endpointConfig) {
this.endpointConfig = endpointConfig;
}
@@ -80,8 +80,8 @@ public class IndexIntegrityValidator implements IndexValidator {
this.schemaConfig = schemaConfig;
}
- public ElasticSearchAdapter getEsAdapter() {
- return esAdapter;
+ public SearchServiceAdapter getSearchServiceAdapter() {
+ return searchServiceAdapter;
}
@Override
@@ -95,10 +95,14 @@ public class IndexIntegrityValidator implements IndexValidator {
*
* @see org.openecomp.sparky.synchronizer.IndexValidator#exists()
*/
+ /* TODO
+ * currently Search does not support head operations on an index neither does it support get operations
+ * on an index. get is being used so that it does not break any code.
+ * */
@Override
public boolean exists() {
- final String fullUrlStr = getFullUrl("/" + schemaConfig.getIndexName() + "/");
- OperationResult existsResult = esAdapter.doHead(fullUrlStr, MediaType.APPLICATION_JSON_TYPE);
+ final String fullUrlStr = getFullUrl(schemaConfig.getIndexName() + "/");
+ OperationResult existsResult = searchServiceAdapter.doGet(fullUrlStr, "application/json");
int rc = existsResult.getResultCode();
@@ -135,7 +139,7 @@ public class IndexIntegrityValidator implements IndexValidator {
final String fullUrlStr = getFullUrl("/" + schemaConfig.getIndexName() + "/");
OperationResult createResult =
- esAdapter.doPut(fullUrlStr, tableConfigJson, MediaType.APPLICATION_JSON_TYPE);
+ searchServiceAdapter.doPut(fullUrlStr, tableConfigJson,"application/json");
int rc = createResult.getResultCode();
@@ -167,8 +171,8 @@ public class IndexIntegrityValidator implements IndexValidator {
* @return the full url
*/
private String getFullUrl(String resourceUrl) {
- return String.format("http://%s:%s%s", endpointConfig.getEsIpAddress(),
- endpointConfig.getEsServerPort(), resourceUrl);
+ String createIndexUrl = searchServiceAdapter.buildSearchServiceCreateIndexUrl(resourceUrl);
+ return createIndexUrl;
}
}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfig.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfig.java
deleted file mode 100644
index 4ba3405..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfig.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.sync.config;
-
-public class ElasticSearchEndpointConfig {
-
- private String esIpAddress;
- private String esServerPort;
- private int scrollContextTimeToLiveInMinutes;
- private int scrollContextBatchRequestSize;
-
- public ElasticSearchEndpointConfig() {
-
- }
-
- public String getEsIpAddress() {
- return esIpAddress;
- }
-
- public void setEsIpAddress(String esIpAddress) {
- this.esIpAddress = esIpAddress;
- }
-
- public String getEsServerPort() {
- return esServerPort;
- }
-
- public void setEsServerPort(String esServerPort) {
- this.esServerPort = esServerPort;
- }
-
- public int getScrollContextTimeToLiveInMinutes() {
- return scrollContextTimeToLiveInMinutes;
- }
-
- public void setScrollContextTimeToLiveInMinutes(int scrollContextTimeToLiveInMinutes) {
- this.scrollContextTimeToLiveInMinutes = scrollContextTimeToLiveInMinutes;
- }
-
- public int getScrollContextBatchRequestSize() {
- return scrollContextBatchRequestSize;
- }
-
- public void setScrollContextBatchRequestSize(int scrollContextBatchRequestSize) {
- this.scrollContextBatchRequestSize = scrollContextBatchRequestSize;
- }
-
-
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchPut.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformSearchServicePut.java
index d516ba8..c62445c 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchPut.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformSearchServicePut.java
@@ -23,19 +23,17 @@ package org.onap.aai.sparky.sync.task;
import java.util.Map;
import java.util.function.Supplier;
-import javax.ws.rs.core.MediaType;
-
import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.dal.NetworkTransaction;
import org.slf4j.MDC;
/**
* The Class PerformElasticSearchPut.
*/
-public class PerformElasticSearchPut implements Supplier<NetworkTransaction> {
+public class PerformSearchServicePut implements Supplier<NetworkTransaction> {
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private String jsonPayload;
private NetworkTransaction txn;
private Map<String, String> contextMap;
@@ -47,19 +45,19 @@ public class PerformElasticSearchPut implements Supplier<NetworkTransaction> {
* @param txn the txn
* @param restDataProvider the rest data provider
*/
- public PerformElasticSearchPut(String jsonPayload, NetworkTransaction txn,
- ElasticSearchAdapter esAdapter) {
+ public PerformSearchServicePut(String jsonPayload, NetworkTransaction txn,
+ SearchServiceAdapter searchServiceAdapter) {
this.jsonPayload = jsonPayload;
this.txn = txn;
- this.esAdapter = esAdapter;
+ this.searchServiceAdapter = searchServiceAdapter;
this.contextMap = MDC.getCopyOfContextMap();
}
- public PerformElasticSearchPut(String jsonPayload, NetworkTransaction txn,
- ElasticSearchAdapter esAdapter, Map<String, String> contextMap) {
+ public PerformSearchServicePut(String jsonPayload, NetworkTransaction txn,
+ SearchServiceAdapter searchServiceAdapter, Map<String, String> contextMap) {
this.jsonPayload = jsonPayload;
this.txn = txn;
- this.esAdapter = esAdapter;
+ this.searchServiceAdapter = searchServiceAdapter;
this.contextMap = contextMap;
}
@@ -76,7 +74,7 @@ public class PerformElasticSearchPut implements Supplier<NetworkTransaction> {
long startTimeInMs = System.currentTimeMillis();
OperationResult or =
- esAdapter.doPut(txn.getLink(), jsonPayload, MediaType.APPLICATION_JSON_TYPE);
+ searchServiceAdapter.doPut(txn.getLink(), jsonPayload, "application/json");
txn.setOperationResult(or);
txn.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchRetrieval.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformSearchServiceRetrieval.java
index 5191c65..ab7da7a 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchRetrieval.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformSearchServiceRetrieval.java
@@ -23,20 +23,18 @@ package org.onap.aai.sparky.sync.task;
import java.util.Map;
import java.util.function.Supplier;
-import javax.ws.rs.core.MediaType;
-
import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.dal.NetworkTransaction;
import org.slf4j.MDC;
/**
* The Class PerformElasticSearchRetrieval.
*/
-public class PerformElasticSearchRetrieval implements Supplier<NetworkTransaction> {
+public class PerformSearchServiceRetrieval implements Supplier<NetworkTransaction> {
private NetworkTransaction txn;
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private Map<String, String> contextMap;
/**
@@ -45,10 +43,10 @@ public class PerformElasticSearchRetrieval implements Supplier<NetworkTransactio
* @param elasticSearchTxn the elastic search txn
* @param restDataProvider the rest data provider
*/
- public PerformElasticSearchRetrieval(NetworkTransaction elasticSearchTxn,
- ElasticSearchAdapter esAdapter) {
+ public PerformSearchServiceRetrieval(NetworkTransaction elasticSearchTxn,
+ SearchServiceAdapter searchServiceAdapter) {
this.txn = elasticSearchTxn;
- this.esAdapter = esAdapter;
+ this.searchServiceAdapter = searchServiceAdapter;
this.contextMap = MDC.getCopyOfContextMap();
}
@@ -59,7 +57,7 @@ public class PerformElasticSearchRetrieval implements Supplier<NetworkTransactio
public NetworkTransaction get() {
MDC.setContextMap(contextMap);
long startTimeInMs = System.currentTimeMillis();
- OperationResult or = esAdapter.doGet(txn.getLink(), MediaType.APPLICATION_JSON_TYPE);
+ OperationResult or = searchServiceAdapter.doGet(txn.getLink(), "application/json");
txn.setOperationResult(or);
txn.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);
return txn;
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchUpdate.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformSearchServiceUpdate.java
index 9e8a8fc..d52a338 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchUpdate.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformSearchServiceUpdate.java
@@ -24,16 +24,16 @@ import java.util.Map;
import java.util.function.Supplier;
import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.dal.NetworkTransaction;
import org.slf4j.MDC;
/**
* The Class PerformElasticSearchUpdate.
*/
-public class PerformElasticSearchUpdate implements Supplier<NetworkTransaction> {
+public class PerformSearchServiceUpdate implements Supplier<NetworkTransaction> {
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private NetworkTransaction operationTracker;
private String updatePayload;
private String updateUrl;
@@ -47,11 +47,11 @@ public class PerformElasticSearchUpdate implements Supplier<NetworkTransaction>
* @param esDataProvider the es data provider
* @param transactionTracker the transaction tracker
*/
- public PerformElasticSearchUpdate(String updateUrl, String updatePayload,
- ElasticSearchAdapter esAdapter, NetworkTransaction transactionTracker) {
+ public PerformSearchServiceUpdate(String updateUrl, String updatePayload,
+ SearchServiceAdapter searchServiceAdapter, NetworkTransaction transactionTracker) {
this.updateUrl = updateUrl;
this.updatePayload = updatePayload;
- this.esAdapter = esAdapter;
+ this.searchServiceAdapter = searchServiceAdapter;
this.contextMap = MDC.getCopyOfContextMap();
this.operationTracker = new NetworkTransaction();
operationTracker.setEntityType(transactionTracker.getEntityType());
@@ -69,7 +69,7 @@ public class PerformElasticSearchUpdate implements Supplier<NetworkTransaction>
operationTracker.setTaskAgeInMs();
MDC.setContextMap(contextMap);
long startTimeInMs = System.currentTimeMillis();
- OperationResult or = esAdapter.doBulkOperation(updateUrl, updatePayload);
+ OperationResult or = searchServiceAdapter.doBulkOperation(updateUrl, updatePayload);
operationTracker.setOperationResult(or);
operationTracker.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);
return operationTracker;
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java
deleted file mode 100644
index 301e65d..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.sync.task;
-
-import java.util.Map;
-import java.util.function.Supplier;
-
-import javax.ws.rs.core.MediaType;
-
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.dal.NetworkTransaction;
-import org.onap.aai.sparky.sync.entity.IndexDocument;
-import org.slf4j.MDC;
-
-/**
- * The Class StoreDocumentTask.
- */
-public class StoreDocumentTask implements Supplier<NetworkTransaction> {
-
- private IndexDocument doc;
-
- private NetworkTransaction txn;
-
- private ElasticSearchAdapter esAdapter;
- private Map<String, String> contextMap;
-
- /**
- * Instantiates a new store document task.
- *
- * @param doc the doc
- * @param txn the txn
- * @param esAdapter the es adapter
- */
- public StoreDocumentTask(IndexDocument doc, NetworkTransaction txn,
- ElasticSearchAdapter esAdapter) {
- this.doc = doc;
- this.txn = txn;
- this.esAdapter = esAdapter;
- this.contextMap = MDC.getCopyOfContextMap();
- }
-
- /* (non-Javadoc)
- * @see java.util.function.Supplier#get()
- */
- @Override
- public NetworkTransaction get() {
- txn.setTaskAgeInMs();
-
- long startTimeInMs = System.currentTimeMillis();
- MDC.setContextMap(contextMap);
- OperationResult operationResult = new OperationResult();
-
- try {
-
- operationResult =
- esAdapter.doPut(txn.getLink(), doc.getAsJson(), MediaType.APPLICATION_JSON_TYPE);
- txn.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);
- } catch (Exception exception) {
- operationResult.setResult(500, exception.getMessage());
- }
-
- txn.setOperationResult(operationResult);
-
- return txn;
- }
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/topology/sync/GeoSyncController.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/topology/sync/GeoSyncController.java
deleted file mode 100644
index 66c249c..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/topology/sync/GeoSyncController.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.topology.sync;
-
-import org.onap.aai.sparky.config.oxm.GeoEntityLookup;
-import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
-import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.sync.ElasticSearchIndexCleaner;
-import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
-import org.onap.aai.sparky.sync.IndexCleaner;
-import org.onap.aai.sparky.sync.IndexIntegrityValidator;
-import org.onap.aai.sparky.sync.SyncControllerImpl;
-import org.onap.aai.sparky.sync.SyncControllerRegistrar;
-import org.onap.aai.sparky.sync.SyncControllerRegistry;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.sync.config.SyncControllerConfig;
-
-public class GeoSyncController extends SyncControllerImpl implements SyncControllerRegistrar {
-
- private SyncControllerRegistry syncControllerRegistry;
-
- public GeoSyncController(SyncControllerConfig syncControllerConfig,
- ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
- ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
- NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
- GeoEntityLookup geoEntityLookup, OxmEntityLookup oxmEntityLookup,
- ElasticSearchSchemaFactory elasticSearchSchemaFactory) throws Exception {
- super(syncControllerConfig);
-
- // final String controllerName = "Inventory Geo Synchronizer";
-
- IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(esAdapter, schemaConfig,
- endpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
-
- registerIndexValidator(indexValidator);
-
- GeoSynchronizer synchronizer =
- new GeoSynchronizer(schemaConfig, syncControllerConfig.getNumInternalSyncWorkers(),
- syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig,
- geoEntityLookup, oxmEntityLookup);
-
- synchronizer.setAaiAdapter(aaiAdapter);
- synchronizer.setElasticSearchAdapter(esAdapter);
-
- registerEntitySynchronizer(synchronizer);
-
-
- IndexCleaner indexCleaner =
- new ElasticSearchIndexCleaner(esAdapter, endpointConfig, schemaConfig);
-
- registerIndexCleaner(indexCleaner);
-
- }
-
- public SyncControllerRegistry getSyncControllerRegistry() {
- return syncControllerRegistry;
- }
-
- public void setSyncControllerRegistry(SyncControllerRegistry syncControllerRegistry) {
- this.syncControllerRegistry = syncControllerRegistry;
- }
-
- @Override
- public void registerController() {
-
- if ( syncControllerRegistry != null ) {
- if ( syncControllerConfig.isEnabled()) {
- syncControllerRegistry.registerSyncController(this);
- }
- }
- }
-
-
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java
deleted file mode 100644
index 809c21a..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java
+++ /dev/null
@@ -1,477 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.sparky.topology.sync;
-
-import static java.util.concurrent.CompletableFuture.supplyAsync;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentLinkedDeque;
-import java.util.function.Supplier;
-
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.cl.mdc.MdcContext;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.config.oxm.GeoEntityLookup;
-import org.onap.aai.sparky.config.oxm.GeoOxmEntityDescriptor;
-import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
-import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
-import org.onap.aai.sparky.dal.NetworkTransaction;
-import org.onap.aai.sparky.dal.rest.HttpMethod;
-import org.onap.aai.sparky.inventory.entity.GeoIndexDocument;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
-import org.onap.aai.sparky.sync.IndexSynchronizer;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.sync.entity.SelfLinkDescriptor;
-import org.onap.aai.sparky.sync.enumeration.OperationState;
-import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
-import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
-import org.onap.aai.sparky.sync.task.StoreDocumentTask;
-import org.onap.aai.sparky.util.NodeUtils;
-import org.slf4j.MDC;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-
-
-/**
- * The Class GeoSynchronizer.
- */
-public class GeoSynchronizer extends AbstractEntitySynchronizer implements IndexSynchronizer {
-
- private static final Logger LOG = LoggerFactory.getInstance().getLogger(GeoSynchronizer.class);
-
- private boolean allWorkEnumerated;
- private Deque<SelfLinkDescriptor> selflinks;
- private GeoEntityLookup geoEntityLookup;
- private OxmEntityLookup oxmEntityLookup;
-
- private Map<String, GeoOxmEntityDescriptor> geoDescriptorMap = null;
-
- /**
- * Instantiates a new geo synchronizer.
- *
- * @throws Exception the exception
- */
- public GeoSynchronizer(ElasticSearchSchemaConfig schemaConfig, int internalSyncWorkers,
- int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig, GeoEntityLookup geoEntityLookup,
- OxmEntityLookup oxmEntityLookup) throws Exception {
-
- super(LOG, "GEO", internalSyncWorkers, aaiWorkers, esWorkers, schemaConfig.getIndexName(),aaiStatConfig, esStatConfig);
- this.geoEntityLookup = geoEntityLookup;
- this.oxmEntityLookup = oxmEntityLookup;
- this.allWorkEnumerated = false;
- this.selflinks = new ConcurrentLinkedDeque<SelfLinkDescriptor>();
- this.synchronizerName = "Geo Synchronizer";
- this.geoDescriptorMap = geoEntityLookup.getGeoEntityDescriptors();
- this.aaiEntityStats.intializeEntityCounters(geoDescriptorMap.keySet());
- this.esEntityStats.intializeEntityCounters(geoDescriptorMap.keySet());
- this.syncDurationInMs = -1;
- }
-
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#doSync()
- */
- @Override
- public OperationState doSync() {
- this.syncDurationInMs = -1;
- resetCounters();
- setShouldSkipSync(false);
- allWorkEnumerated = false;
- syncStartedTimeStampInMs = System.currentTimeMillis();
- String txnID = NodeUtils.getRandomTxnId();
- MdcContext.initialize(txnID, "GeoSynchronizer", "", "Sync", "");
-
- collectAllTheWork();
- return OperationState.OK;
- }
-
-
- /**
- * Collect all the work.
- *
- * @return the operation state
- */
- public OperationState collectAllTheWork() {
- final Map<String,String> contextMap = MDC.getCopyOfContextMap();
-
- if (geoDescriptorMap.isEmpty()) {
- setShouldSkipSync(true);
- LOG.error(AaiUiMsgs.OXM_FAILED_RETRIEVAL, "geo entities");
- return OperationState.ERROR;
- }
-
- Collection<String> syncTypes = geoDescriptorMap.keySet();
-
- try {
-
- /*
- * launch a parallel async thread to process the documents for each entity-type (to max the of
- * the configured executor anyway)
- */
-
- aaiWorkOnHand.set(syncTypes.size());
-
- for (String key : syncTypes) {
-
- supplyAsync(new Supplier<Void>() {
-
- @Override
- public Void get() {
- MDC.setContextMap(contextMap);
- OperationResult typeLinksResult = null;
- try {
- typeLinksResult = aaiAdapter.getSelfLinksByEntityType(key);
- aaiWorkOnHand.decrementAndGet();
- processEntityTypeSelfLinks(typeLinksResult);
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ERROR_GETTING_DATA_FROM_AAI, exc);
- }
-
- return null;
- }
-
- }, aaiExecutor).whenComplete((result, error) -> {
-
- if (error != null) {
- LOG.error(AaiUiMsgs.ERROR_GETTING_DATA_FROM_AAI, error.getMessage());
- }
- });
-
- }
-
- while (aaiWorkOnHand.get() != 0) {
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.WAIT_FOR_ALL_SELFLINKS_TO_BE_COLLECTED);
- }
-
- Thread.sleep(1000);
- }
-
- aaiWorkOnHand.set(selflinks.size());
- allWorkEnumerated = true;
- syncEntityTypes();
-
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ERROR_GETTING_DATA_FROM_AAI, exc);
- }
- return OperationState.OK;
- }
-
- /**
- * Sync entity types.
- */
- private void syncEntityTypes() {
-
- while (selflinks.peek() != null) {
-
- SelfLinkDescriptor linkDescriptor = selflinks.poll();
- aaiWorkOnHand.decrementAndGet();
-
- OxmEntityDescriptor descriptor = null;
-
- if (linkDescriptor.getSelfLink() != null && linkDescriptor.getEntityType() != null) {
-
- descriptor = oxmEntityLookup.getEntityDescriptors().get(linkDescriptor.getEntityType());
-
- if (descriptor == null) {
- LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, linkDescriptor.getEntityType());
- // go to next element in iterator
- continue;
- }
-
- NetworkTransaction txn = new NetworkTransaction();
- txn.setDescriptor(descriptor);
- txn.setLink(linkDescriptor.getSelfLink());
- txn.setOperationType(HttpMethod.GET);
- txn.setEntityType(linkDescriptor.getEntityType());
-
- aaiWorkOnHand.incrementAndGet();
-
- supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter), aaiExecutor)
- .whenComplete((result, error) -> {
-
- aaiWorkOnHand.decrementAndGet();
-
- if (error != null) {
- LOG.error(AaiUiMsgs.ERROR_GETTING_DATA_FROM_AAI, error.getMessage());
- } else {
- if (result == null) {
- LOG.error(AaiUiMsgs.SELF_LINK_GET_NO_RESPONSE, linkDescriptor.getSelfLink());
- } else {
- processEntityTypeSelfLinkResult(result);
- }
- }
- });
- }
- }
- }
-
- /**
- * Process entity type self links.
- *
- * @param operationResult the operation result
- */
- private void processEntityTypeSelfLinks(OperationResult operationResult) {
-
- final String jsonResult = operationResult.getResult();
-
- if (jsonResult != null && jsonResult.length() > 0 && operationResult.wasSuccessful()) {
-
- try {
- JsonNode rootNode = mapper.readTree(jsonResult);
- JsonNode resultData = rootNode.get("result-data");
-
- if (resultData.isArray()) {
- ArrayNode resultDataArrayNode = (ArrayNode) resultData;
-
- Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
-
- while (elementIterator.hasNext()) {
- JsonNode element = elementIterator.next();
-
- final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
- final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
-
- if (resourceType != null && resourceLink != null) {
-
- if (geoDescriptorMap.containsKey(resourceType)) {
- selflinks.add(new SelfLinkDescriptor(resourceLink + "?nodes-only", resourceType));
- } else {
- LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
- // go to next element in iterator
- continue;
- }
-
- }
- }
- }
- } catch (IOException exc) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC, exc);
- }
- }
-
- }
-
- /**
- * Process entity type self link result.
- *
- * @param txn the txn
- */
- private void processEntityTypeSelfLinkResult(NetworkTransaction txn) {
-
- updateActiveInventoryCounters(txn);
-
- if (!txn.getOperationResult().wasSuccessful()) {
- return;
- }
-
- GeoOxmEntityDescriptor descriptor = geoDescriptorMap.get(txn.getEntityType());
-
- if ( descriptor == null ) {
- return;
- }
-
- try {
- if (descriptor.hasGeoEntity()) {
-
- GeoIndexDocument geoDoc = new GeoIndexDocument();
-
- final String jsonResult = txn.getOperationResult().getResult();
-
- if (jsonResult != null && jsonResult.length() > 0) {
-
- populateGeoDocument(geoDoc, jsonResult, txn.getDescriptor(), txn.getLink());
-
- if (!geoDoc.isValidGeoDocument()) {
-
- LOG.info(AaiUiMsgs.GEO_SYNC_IGNORING_ENTITY, geoDoc.getEntityType(), geoDoc.toString());
-
- } else {
-
- String link = null;
- try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), geoDoc.getId());
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_URI, exc);
- }
-
- if (link != null) {
-
- NetworkTransaction n2 = new NetworkTransaction();
- n2.setLink(link);
- n2.setEntityType(txn.getEntityType());
- n2.setDescriptor(txn.getDescriptor());
- n2.setOperationType(HttpMethod.PUT);
-
- esWorkOnHand.incrementAndGet();
-
- supplyAsync(new StoreDocumentTask(geoDoc, n2, elasticSearchAdapter), esExecutor)
- .whenComplete((result, error) -> {
-
- esWorkOnHand.decrementAndGet();
-
- if (error != null) {
- LOG.error(AaiUiMsgs.ES_STORE_FAILURE, error.getMessage());
- } else {
- updateElasticSearchCounters(result);
- processStoreDocumentResult(result);
- }
- });
- }
- }
- }
- }
- } catch (JsonProcessingException exc) {
- LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, exc);
- } catch (IOException exc) {
- LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, exc);
- }
-
- return;
- }
-
-
- /**
- * Process store document result.
- *
- * @param txn the txn
- */
- private void processStoreDocumentResult(NetworkTransaction txn) {
-
- OperationResult or = txn.getOperationResult();
-
- if (!or.wasSuccessful()) {
- LOG.error(AaiUiMsgs.ES_STORE_FAILURE, or.toString());
- /*
- * if(or.getResultCode() != 404 || (or.getResultCode() == 404 &&
- * !synchronizerConfig.isResourceNotFoundErrorsSupressed())) { logger.error(
- * "Skipping failed resource = " + "link" + " RC=[" + or.getResultCode() + "]. Message: " +
- * or.getResult()); }
- */
-
- }
-
- }
-
-
- @Override
- public SynchronizerState getState() {
-
- if (!isSyncDone()) {
- return SynchronizerState.PERFORMING_SYNCHRONIZATION;
- }
-
- return SynchronizerState.IDLE;
-
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
- */
- @Override
- public String getStatReport(boolean showFinalReport) {
- syncDurationInMs = System.currentTimeMillis() - syncStartedTimeStampInMs;
- return this.getStatReport(syncDurationInMs, showFinalReport);
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#shutdown()
- */
- @Override
- public void shutdown() {
- this.shutdownExecutors();
- }
-
- /**
- * Populate geo document.
- *
- * @param doc the doc
- * @param result the result
- * @param resultDescriptor the result descriptor
- * @param entityLink the entity link
- * @throws JsonProcessingException the json processing exception
- * @throws IOException Signals that an I/O exception has occurred.
- */
- protected void populateGeoDocument(GeoIndexDocument doc, String result,
- OxmEntityDescriptor resultDescriptor, String entityLink)
- throws JsonProcessingException, IOException {
-
- doc.setSelfLink(entityLink);
- doc.setEntityType(resultDescriptor.getEntityName());
-
- JsonNode entityNode = mapper.readTree(result);
-
- List<String> primaryKeyValues = new ArrayList<String>();
- String pkeyValue = null;
-
- for (String keyName : resultDescriptor.getPrimaryKeyAttributeNames()) {
- pkeyValue = NodeUtils.getNodeFieldAsText(entityNode, keyName);
- if (pkeyValue != null) {
- primaryKeyValues.add(pkeyValue);
- } else {
- LOG.warn(AaiUiMsgs.ES_PKEYVALUE_NULL, resultDescriptor.getEntityName());
- }
- }
-
- final String primaryCompositeKeyValue = NodeUtils.concatArray(primaryKeyValues, "/");
- doc.setEntityPrimaryKeyValue(primaryCompositeKeyValue);
-
- GeoOxmEntityDescriptor descriptor = geoDescriptorMap.get(resultDescriptor.getEntityName());
-
- String geoLatKey = descriptor.getGeoLatName();
- String geoLongKey = descriptor.getGeoLongName();
-
- doc.setLatitude(NodeUtils.getNodeFieldAsText(entityNode, geoLatKey));
- doc.setLongitude(NodeUtils.getNodeFieldAsText(entityNode, geoLongKey));
- doc.deriveFields();
-
- }
-
- @Override
- protected boolean isSyncDone() {
- if (shouldSkipSync()) {
- syncDurationInMs = System.currentTimeMillis() - syncStartedTimeStampInMs;
- return true;
- }
-
- int totalWorkOnHand = aaiWorkOnHand.get() + esWorkOnHand.get();
-
- if (totalWorkOnHand > 0 || !allWorkEnumerated) {
- return false;
- }
-
- return true;
- }
-
-}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java
index 69acc42..17c9072 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java
@@ -34,11 +34,11 @@ import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
import org.onap.aai.sparky.config.oxm.OxmModelLoader;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
import org.onap.aai.sparky.dal.GizmoAdapter;
+import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
import org.onap.aai.sparky.logging.AaiUiMsgs;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.subscription.config.SubscriptionConfig;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.sync.entity.SearchableEntity;
import org.onap.aai.sparky.util.NodeUtils;
@@ -64,7 +64,7 @@ public class BaseVisualizationService implements VisualizationService {
private final ActiveInventoryAdapter aaiAdapter;
private final GizmoAdapter gizmoAdapter;
- private final ElasticSearchAdapter esAdapter;
+ private final SearchServiceAdapter searchServiceAdapter;
private final ExecutorService aaiExecutorService;
private ConcurrentHashMap<Long, VisualizationContext> contextMap;
@@ -72,18 +72,18 @@ public class BaseVisualizationService implements VisualizationService {
private VisualizationConfigs visualizationConfigs;
private SubscriptionConfig subConfig;
- private ElasticSearchEndpointConfig endpointEConfig;
+ private RestEndpointConfig endpointConfig;
private ElasticSearchSchemaConfig schemaEConfig;
private OxmEntityLookup oxmEntityLookup;
public BaseVisualizationService(OxmModelLoader loader, VisualizationConfigs visualizationConfigs,
- ActiveInventoryAdapter aaiAdapter, GizmoAdapter gizmoAdapter, ElasticSearchAdapter esAdapter,
- ElasticSearchEndpointConfig endpointConfig, ElasticSearchSchemaConfig schemaConfig,
+ ActiveInventoryAdapter aaiAdapter, GizmoAdapter gizmoAdapter, SearchServiceAdapter searchServiceAdapter,
+ RestEndpointConfig endpointConfig, ElasticSearchSchemaConfig schemaConfig,
int numActiveInventoryWorkers, OxmEntityLookup oxmEntityLookup, SubscriptionConfig subscriptionConfig)
throws Exception {
this.visualizationConfigs = visualizationConfigs;
- this.endpointEConfig = endpointConfig;
+ this.endpointConfig = endpointConfig;
this.schemaEConfig = schemaConfig;
this.oxmEntityLookup = oxmEntityLookup;
this.subConfig = subscriptionConfig;
@@ -97,7 +97,7 @@ public class BaseVisualizationService implements VisualizationService {
this.aaiAdapter = aaiAdapter;
this.gizmoAdapter = gizmoAdapter;
- this.esAdapter = esAdapter;
+ this.searchServiceAdapter = searchServiceAdapter;
this.mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -159,10 +159,10 @@ public class BaseVisualizationService implements VisualizationService {
if (operationResult.wasSuccessful()) {
try {
- JsonNode elasticValue = mapper.readValue(operationResult.getResult(), JsonNode.class);
+ JsonNode searchServiceResults = mapper.readValue(operationResult.getResult(), JsonNode.class);
- if (elasticValue != null) {
- JsonNode sourceField = elasticValue.get("_source");
+ if (searchServiceResults != null) {
+ JsonNode sourceField = extractSearchServiceContent(searchServiceResults);
if (sourceField != null) {
sourceEntity = new SearchableEntity();
@@ -203,9 +203,9 @@ public class BaseVisualizationService implements VisualizationService {
* Here is where we need to make a dip to elastic-search for the self-link by entity-id (link
* hash).
*/
- dataCollectionResult = esAdapter.retrieveEntityById(endpointEConfig.getEsIpAddress(),
- endpointEConfig.getEsServerPort(),schemaEConfig.getIndexName(),
- schemaEConfig.getIndexDocType(), queryRequest.getHashId());
+ dataCollectionResult = searchServiceAdapter.retrieveEntityById(queryRequest.getHashId(),
+ schemaEConfig.getIndexName());
+
sourceEntity = extractSearchableEntityFromElasticEntity(dataCollectionResult);
if (sourceEntity != null) {
@@ -377,6 +377,16 @@ public class BaseVisualizationService implements VisualizationService {
}
return output;
}
+
+ private JsonNode extractSearchServiceContent(JsonNode returnedData){
+
+ JsonNode searchResults = returnedData.get("searchResult");
+ JsonNode searchHits = searchResults.get("hits");
+ JsonNode searchDoc = searchHits.get(0).get("document");
+ JsonNode content = searchDoc.get("content");
+
+ return content;
+ }
public void shutdown() {
aaiExecutorService.shutdown();
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java
index 8365237..79eded1 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java
@@ -58,9 +58,9 @@ import org.onap.aai.sparky.sync.entity.SelfLinkDescriptor;
import org.onap.aai.sparky.sync.enumeration.OperationState;
import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchPut;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchRetrieval;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchUpdate;
+import org.onap.aai.sparky.sync.task.PerformSearchServicePut;
+import org.onap.aai.sparky.sync.task.PerformSearchServiceRetrieval;
+import org.onap.aai.sparky.sync.task.PerformSearchServiceUpdate;
import org.onap.aai.sparky.util.NodeUtils;
import org.slf4j.MDC;
@@ -378,7 +378,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
*/
String link = null;
try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), se.getId());
+ link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), se.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
return;
@@ -441,8 +441,8 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
if (wasEntryDiscovered) {
if (versionNumber != null && jsonPayload != null) {
- String requestPayload = elasticSearchAdapter.buildBulkImportOperationRequest(getIndexName(),
- "default", se.getId(), versionNumber, jsonPayload);
+ String requestPayload = searchServiceAdapter.buildBulkImportOperationRequest(getIndexName(),
+ se.getId(), jsonPayload);
NetworkTransaction transactionTracker = new NetworkTransaction();
transactionTracker.setEntityType(esGetTxn.getEntityType());
@@ -450,9 +450,9 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
transactionTracker.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchUpdate(elasticSearchAdapter.getBulkUrl(),
- requestPayload, elasticSearchAdapter, transactionTracker), esPutExecutor)
- .whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServiceUpdate(searchServiceAdapter.buildSearchServiceBulkUrl(),
+ requestPayload, searchServiceAdapter, transactionTracker), esPutExecutor)
+ .whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -478,8 +478,8 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
updateElasticTxn.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
- esPutExecutor).whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServicePut(jsonPayload, updateElasticTxn, searchServiceAdapter),
+ esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -578,7 +578,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
String link = null;
try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), se.getId());
+ link = searchServiceAdapter.buildSearchServiceDocUrl(getIndexName(), se.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY, exc.getLocalizedMessage());
}
@@ -592,8 +592,8 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchRetrieval(n2, elasticSearchAdapter), esExecutor)
- .whenComplete((result, error) -> {
+ supplyAsync(new PerformSearchServiceRetrieval(n2, searchServiceAdapter), esExecutor)
+ .whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java
index d8b4af6..2cecf25 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java
@@ -25,15 +25,13 @@ import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
import org.onap.aai.sparky.crossentityreference.sync.CrossEntityReferenceSynchronizer;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.sync.ElasticSearchIndexCleaner;
+import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
-import org.onap.aai.sparky.sync.IndexCleaner;
import org.onap.aai.sparky.sync.IndexIntegrityValidator;
import org.onap.aai.sparky.sync.SyncControllerImpl;
import org.onap.aai.sparky.sync.SyncControllerRegistrar;
import org.onap.aai.sparky.sync.SyncControllerRegistry;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
import org.onap.aai.sparky.sync.config.SyncControllerConfig;
@@ -43,13 +41,13 @@ public class ViewInspectSyncController extends SyncControllerImpl
private SyncControllerRegistry syncControllerRegistry;
private ActiveInventoryAdapter aaiAdapter;
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private ElasticSearchSchemaConfig schemaConfig;
- private ElasticSearchEndpointConfig endpointConfig;
+ private RestEndpointConfig endpointConfig;
public ViewInspectSyncController(SyncControllerConfig syncControllerConfig,
- ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
- ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
+ ActiveInventoryAdapter aaiAdapter, SearchServiceAdapter searchServiceAdapter,
+ ElasticSearchSchemaConfig schemaConfig, RestEndpointConfig endpointConfig,
NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
CrossEntityReferenceLookup crossEntityReferenceLookup, OxmEntityLookup oxmEntityLookup,
SearchableEntityLookup searchableEntityLookup,
@@ -60,10 +58,10 @@ public class ViewInspectSyncController extends SyncControllerImpl
// final String controllerName = "View and Inspect Entity Synchronizer";
this.aaiAdapter = aaiAdapter;
- this.esAdapter = esAdapter;
+ this.searchServiceAdapter = searchServiceAdapter;
this.schemaConfig = schemaConfig;
this.endpointConfig = endpointConfig;
- IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(esAdapter, schemaConfig,
+ IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(searchServiceAdapter, schemaConfig,
endpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
registerIndexValidator(indexValidator);
@@ -76,7 +74,7 @@ public class ViewInspectSyncController extends SyncControllerImpl
oxmEntityLookup, searchableEntityLookup);
ses.setAaiAdapter(aaiAdapter);
- ses.setElasticSearchAdapter(esAdapter);
+ ses.setSearchServiceAdapter(searchServiceAdapter);
registerEntitySynchronizer(ses);
@@ -87,14 +85,10 @@ public class ViewInspectSyncController extends SyncControllerImpl
crossEntityReferenceLookup, oxmEntityLookup, searchableEntityLookup);
cers.setAaiAdapter(aaiAdapter);
- cers.setElasticSearchAdapter(esAdapter);
+ cers.setSearchServiceAdapter(searchServiceAdapter);
registerEntitySynchronizer(cers);
- IndexCleaner indexCleaner =
- new ElasticSearchIndexCleaner(esAdapter, endpointConfig, schemaConfig);
-
- registerIndexCleaner(indexCleaner);
}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizerTest.java
deleted file mode 100644
index e9f03ba..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizerTest.java
+++ /dev/null
@@ -1,372 +0,0 @@
-package org.onap.aai.sparky.aggregation.sync;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-import org.onap.aai.nodes.NodeIngestor;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.setup.Version;
-import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
-import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
-import org.onap.aai.sparky.config.oxm.OxmModelLoader;
-import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
-import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
-import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
-import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.sync.enumeration.OperationState;
-import org.onap.aai.sparky.util.TestResourceLoader;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import javax.inject.Inject;
-
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@TestPropertySource(properties = {
-"schemaIngestPropLoc = src/test/resources/oxm-reader/schema-ingest-single-oxm.properties" })
-@ContextConfiguration(locations = { "classpath:oxm-reader/oxm-reader-bean.xml" })
-public class HistoricalEntitySummarizerTest {
-
- private static ObjectMapper mapper = new ObjectMapper();
-
- private HistoricalEntitySummarizer historicalSummarizer;
-
- private ElasticSearchSchemaConfig esSchemaConfig;
- private NetworkStatisticsConfig aaiStatConfig;
- private NetworkStatisticsConfig esStatConfig;
-
- private SearchableEntityLookup searchableEntityLookup;
- private ElasticSearchAdapter esAdapter;
- private ActiveInventoryAdapter aaiAdapter;
-
-
-
- @Inject
- private NodeIngestor nodeInjest;
-
-
- @Inject
- private OxmEntityLookup oxmEntityLookup;
-
-
-
- @Before
- public void init() throws Exception {
-
- esSchemaConfig = new ElasticSearchSchemaConfig();
- esSchemaConfig.setIndexDocType("default");
- esSchemaConfig.setIndexMappingsFileName(null);
- esSchemaConfig.setIndexName("aggregation-index-name");
- esSchemaConfig.setIndexSettingsFileName(null);
-
-
- aaiStatConfig = new NetworkStatisticsConfig();
-
- aaiStatConfig.setNumSamplesPerThreadForRunningAverage(100);
-
- aaiStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
- aaiStatConfig.setBytesHistogramMaxYAxis(1000000L);
- aaiStatConfig.setBytesHistogramNumBins(20);
- aaiStatConfig.setBytesHistogramNumDecimalPoints(2);
-
- aaiStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
- aaiStatConfig.setQueueLengthHistogramMaxYAxis(20000);
- aaiStatConfig.setQueueLengthHistogramNumBins(20);
- aaiStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
-
- aaiStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
- aaiStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
- aaiStatConfig.setTaskAgeHistogramNumBins(20);
- aaiStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
-
- aaiStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
- aaiStatConfig.setResponseTimeHistogramMaxYAxis(1000L);
- aaiStatConfig.setResponseTimeHistogramNumBins(20);
- aaiStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
-
- aaiStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
- aaiStatConfig.setTpsHistogramMaxYAxis(100);
- aaiStatConfig.setTpsHistogramNumBins(20);
- aaiStatConfig.setTpsHistogramNumDecimalPoints(2);
-
- esStatConfig = new NetworkStatisticsConfig();
-
- esStatConfig.setNumSamplesPerThreadForRunningAverage(100);
-
- esStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
- esStatConfig.setBytesHistogramMaxYAxis(1000000L);
- esStatConfig.setBytesHistogramNumBins(20);
- esStatConfig.setBytesHistogramNumDecimalPoints(2);
-
- esStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
- esStatConfig.setQueueLengthHistogramMaxYAxis(20000);
- esStatConfig.setQueueLengthHistogramNumBins(20);
- esStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
-
- esStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
- esStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
- esStatConfig.setTaskAgeHistogramNumBins(20);
- esStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
-
- esStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
- esStatConfig.setResponseTimeHistogramMaxYAxis(10000L);
- esStatConfig.setResponseTimeHistogramNumBins(20);
- esStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
-
- esStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
- esStatConfig.setTpsHistogramMaxYAxis(100);
- esStatConfig.setTpsHistogramNumBins(20);
- esStatConfig.setTpsHistogramNumDecimalPoints(2);
-
- oxmEntityLookup = new OxmEntityLookup();
-
- esAdapter = Mockito.mock(ElasticSearchAdapter.class);
- aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
-
-
- Set<OxmModelProcessor> processors = new HashSet<OxmModelProcessor>();
-
- processors.add(oxmEntityLookup);
-
-
-
- Map<String, OxmEntityDescriptor> oxmEntityDescriptors =
- new HashMap<String, OxmEntityDescriptor>();
-
- OxmEntityDescriptor genericVnfDescriptor = new OxmEntityDescriptor();
- genericVnfDescriptor.setEntityName("generic-vnf");
- List<String> pkeyNames = new ArrayList<String>();
- pkeyNames.add("vnf-name");
-
- genericVnfDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
-
- oxmEntityDescriptors.put("generic-vnf", genericVnfDescriptor);
-
-
- oxmEntityLookup.setEntityDescriptors(oxmEntityDescriptors);
-
- SuggestionEntityDescriptor genericVnfSuggestionDescriptor = new SuggestionEntityDescriptor();
- genericVnfSuggestionDescriptor.setEntityName("generic-vnf");
- genericVnfSuggestionDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
-
-
-
- /*
- * SuggestionSearchEntity sse = new SuggestionSearchEntity(filtersConfig);
- *
- * sse.setEntityType("generic-vnf"); sse.setSuggestionPropertyTypes( Arrays.asList("vnf-name"));
- *
- * genericVnfSuggestionDescriptor.setSuggestionSearchEntity(sse);
- *
- * suggestionEntityDescriptors.put("generic-vnf", genericVnfSuggestionDescriptor);
- */
-
- searchableEntityLookup = new SearchableEntityLookup();
-
- processors.add(searchableEntityLookup);
- Version v = Version.V11;
- OxmModelLoader oxmModelLoader = new OxmModelLoader(v, processors,nodeInjest);
- oxmModelLoader.loadModel();
-
-
- }
-
- @Test
- public void validateBasicConstruction() throws Exception {
-
- historicalSummarizer = new HistoricalEntitySummarizer(esSchemaConfig, 5, 5, 5, aaiStatConfig,
- esStatConfig, searchableEntityLookup);
-
- historicalSummarizer.setAaiAdapter(aaiAdapter);
- historicalSummarizer.setElasticSearchAdapter(esAdapter);
-
- assertNotNull(historicalSummarizer.getAaiAdapter());
- assertNotNull(historicalSummarizer.getElasticSearchAdapter());
-
- }
-
- @Test
- public void validateSmallSync() throws Exception {
-
- historicalSummarizer = new HistoricalEntitySummarizer(esSchemaConfig, 5, 5, 5, aaiStatConfig,
- esStatConfig, searchableEntityLookup);
-
-
- historicalSummarizer.setAaiAdapter(aaiAdapter);
- historicalSummarizer.setElasticSearchAdapter(esAdapter);
-
- String nodesQueryResponse = TestResourceLoader
- .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
-
- OperationResult genericVnfSelfLinks = new OperationResult();
-
- genericVnfSelfLinks.setResultCode(200);
- genericVnfSelfLinks.setResult(nodesQueryResponse);
-
- Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
- .thenReturn(genericVnfSelfLinks);
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
-
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
- .thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
- "http://server.proxy:9200/myindex/mytype/doc2",
- "http://server.proxy:9200/myindex/mytype/doc3");
-
- /*
- * Our initial gets from elastic search should be record-not-found
- */
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
-
-
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
- .thenReturn(new OperationResult(200, null));
-
- OperationState syncState = historicalSummarizer.doSync();
- assertEquals(OperationState.OK, syncState);
-
- assertNotNull(historicalSummarizer.getStatReport(false));
- assertNotNull(historicalSummarizer.getStatReport(true));
-
- historicalSummarizer.clearCache();
- historicalSummarizer.shutdown();
-
-
- }
-
- @Test
- public void validateSmallSyncWithRetries() throws Exception {
-
- historicalSummarizer = new HistoricalEntitySummarizer(esSchemaConfig, 5, 5, 5, aaiStatConfig,
- esStatConfig, searchableEntityLookup);
-
-
- historicalSummarizer.setAaiAdapter(aaiAdapter);
- historicalSummarizer.setElasticSearchAdapter(esAdapter);
-
- String nodesQueryResponse = TestResourceLoader
- .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
-
- OperationResult genericVnfSelfLinks = new OperationResult();
-
- genericVnfSelfLinks.setResultCode(200);
- genericVnfSelfLinks.setResult(nodesQueryResponse);
-
- Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
- .thenReturn(genericVnfSelfLinks);
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
-
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
- .thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
- "http://server.proxy:9200/myindex/mytype/doc2",
- "http://server.proxy:9200/myindex/mytype/doc3");
-
- /*
- * Our initial gets from elastic search should be record-not-found
- */
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
-
-
- /*
- * Elastic Search puts always fail with a version conflict = 409
- */
-
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
- .thenReturn(new OperationResult(409, null));
-
- OperationState syncState = historicalSummarizer.doSync();
- assertEquals(OperationState.OK, syncState);
-
- assertNotNull(historicalSummarizer.getStatReport(false));
- assertNotNull(historicalSummarizer.getStatReport(true));
-
- historicalSummarizer.clearCache();
- historicalSummarizer.shutdown();
-
-
- }
-} \ No newline at end of file
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncControllerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncControllerTest.java
deleted file mode 100644
index 9527520..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncControllerTest.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.onap.aai.sparky.aggregation.sync;
-
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class HistoricalEntitySyncControllerTest {
-
- @Test
- public void shouldConvertMinutesToMs() {
- assertEquals(60000, HistoricalEntitySyncController.getTaskFrequencyInMs(1));
- assertEquals(120000, HistoricalEntitySyncController.getTaskFrequencyInMs(2));
- }
-
-} \ No newline at end of file
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java
index 4471390..8c13ebc 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java
@@ -26,7 +26,7 @@ import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
import org.onap.aai.sparky.config.oxm.SuggestionEntityLookup;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.search.filters.config.FiltersConfig;
import org.onap.aai.sparky.search.filters.config.FiltersDetailsConfig;
import org.onap.aai.sparky.search.filters.config.FiltersForViewsConfig;
@@ -58,7 +58,7 @@ public class AutosuggestionSynchronizerTest {
private NetworkStatisticsConfig esStatConfig;
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private ActiveInventoryAdapter aaiAdapter;
@Inject
@@ -153,7 +153,7 @@ public class AutosuggestionSynchronizerTest {
- esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ searchServiceAdapter = Mockito.mock(SearchServiceAdapter.class);
aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
@@ -221,10 +221,10 @@ public class AutosuggestionSynchronizerTest {
esStatConfig, oxmEntityLookup, suggestionEntityLookup, filtersConfig);
suggestionSynchronizer.setAaiAdapter(aaiAdapter);
- suggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+ suggestionSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
assertNotNull(suggestionSynchronizer.getAaiAdapter());
- assertNotNull(suggestionSynchronizer.getElasticSearchAdapter());
+ assertNotNull(suggestionSynchronizer.getSearchServiceAdapter());
}
@@ -236,7 +236,7 @@ public class AutosuggestionSynchronizerTest {
suggestionSynchronizer.setAaiAdapter(aaiAdapter);
- suggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+ suggestionSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
@@ -287,7 +287,7 @@ public class AutosuggestionSynchronizerTest {
.thenReturn(new OperationResult(200, TestResourceLoader
.getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString()))
.thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
"http://server.proxy:9200/myindex/mytype/doc2",
"http://server.proxy:9200/myindex/mytype/doc3");
@@ -295,15 +295,15 @@ public class AutosuggestionSynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(200, null));
OperationState syncState = suggestionSynchronizer.doSync();
@@ -326,7 +326,7 @@ public class AutosuggestionSynchronizerTest {
suggestionSynchronizer.setAaiAdapter(aaiAdapter);
- suggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+ suggestionSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
@@ -377,7 +377,7 @@ public class AutosuggestionSynchronizerTest {
.thenReturn(new OperationResult(200, TestResourceLoader
.getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString()))
.thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
"http://server.proxy:9200/myindex/mytype/doc2",
"http://server.proxy:9200/myindex/mytype/doc3");
@@ -385,11 +385,11 @@ public class AutosuggestionSynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
@@ -397,7 +397,7 @@ public class AutosuggestionSynchronizerTest {
* Elastic Search puts always fail with a version conflict = 409
*/
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(409, null));
OperationState syncState = suggestionSynchronizer.doSync();
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizerTest.java
index 1a14256..e72b0df 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizerTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizerTest.java
@@ -22,7 +22,7 @@ import org.onap.aai.sparky.config.oxm.OxmModelLoader;
import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.search.filters.config.FiltersConfig;
import org.onap.aai.sparky.search.filters.config.FiltersDetailsConfig;
import org.onap.aai.sparky.search.filters.config.FiltersForViewsConfig;
@@ -44,7 +44,7 @@ public class VnfAliasSuggestionSynchronizerTest {
private NetworkStatisticsConfig esStatConfig;
private OxmEntityLookup oxmEntityLookup;
private GeoEntityLookup geoEntityLookup;
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private ActiveInventoryAdapter aaiAdapter;
private FiltersConfig filtersConfig;
@@ -120,7 +120,7 @@ public class VnfAliasSuggestionSynchronizerTest {
oxmEntityLookup = new OxmEntityLookup();
- esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ searchServiceAdapter = Mockito.mock(SearchServiceAdapter.class);
aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
@@ -186,10 +186,10 @@ public class VnfAliasSuggestionSynchronizerTest {
aaiStatConfig, esStatConfig, filtersConfig);
vnfAliasSuggestionSynchronizer.setAaiAdapter(aaiAdapter);
- vnfAliasSuggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+ vnfAliasSuggestionSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
assertNotNull(vnfAliasSuggestionSynchronizer.getAaiAdapter());
- assertNotNull(vnfAliasSuggestionSynchronizer.getElasticSearchAdapter());
+ assertNotNull(vnfAliasSuggestionSynchronizer.getSearchServiceAdapter());
}
@@ -201,7 +201,7 @@ public class VnfAliasSuggestionSynchronizerTest {
vnfAliasSuggestionSynchronizer.setAaiAdapter(aaiAdapter);
- vnfAliasSuggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+ vnfAliasSuggestionSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
@@ -244,7 +244,7 @@ public class VnfAliasSuggestionSynchronizerTest {
.thenReturn(new OperationResult(200, TestResourceLoader
.getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString()))
.thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
"http://server.proxy:9200/myindex/mytype/doc2",
"http://server.proxy:9200/myindex/mytype/doc3");
@@ -252,15 +252,15 @@ public class VnfAliasSuggestionSynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(200, null));
OperationState syncState = vnfAliasSuggestionSynchronizer.doSync();
@@ -283,7 +283,7 @@ public class VnfAliasSuggestionSynchronizerTest {
vnfAliasSuggestionSynchronizer.setAaiAdapter(aaiAdapter);
- vnfAliasSuggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+ vnfAliasSuggestionSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
@@ -326,7 +326,7 @@ public class VnfAliasSuggestionSynchronizerTest {
.thenReturn(new OperationResult(200, TestResourceLoader
.getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString()))
.thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
"http://server.proxy:9200/myindex/mytype/doc2",
"http://server.proxy:9200/myindex/mytype/doc3");
@@ -334,11 +334,11 @@ public class VnfAliasSuggestionSynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
@@ -346,7 +346,7 @@ public class VnfAliasSuggestionSynchronizerTest {
* Elastic Search puts always fail with a version conflict = 409
*/
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(409, null));
OperationState syncState = vnfAliasSuggestionSynchronizer.doSync();
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java
index c085ca4..b275813 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java
@@ -22,7 +22,7 @@ import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
@@ -43,7 +43,7 @@ public class CrossEntityReferenceSynchronizerTest {
private NetworkStatisticsConfig esStatConfig;
private OxmEntityLookup oxmEntityLookup;
private SearchableEntityLookup searchableEntityLookup;
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private ActiveInventoryAdapter aaiAdapter;
private CrossEntityReferenceLookup cerLookup;
private RestEndpointConfig aaiRestEndPointConfig;
@@ -118,7 +118,7 @@ public class CrossEntityReferenceSynchronizerTest {
oxmEntityLookup = new OxmEntityLookup();
- esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ searchServiceAdapter = Mockito.mock(SearchServiceAdapter.class);
aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
@@ -164,10 +164,10 @@ public class CrossEntityReferenceSynchronizerTest {
esStatConfig, cerLookup, oxmEntityLookup, searchableEntityLookup);
cerSynchronizer.setAaiAdapter(aaiAdapter);
- cerSynchronizer.setElasticSearchAdapter(esAdapter);
+ cerSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
assertNotNull(cerSynchronizer.getAaiAdapter());
- assertNotNull(cerSynchronizer.getElasticSearchAdapter());
+ assertNotNull(cerSynchronizer.getSearchServiceAdapter());
}
@@ -182,7 +182,7 @@ public class CrossEntityReferenceSynchronizerTest {
esStatConfig, cerLookup, oxmEntityLookup, searchableEntityLookup);
cerSynchronizer.setAaiAdapter(aaiAdapter);
- cerSynchronizer.setElasticSearchAdapter(esAdapter);
+ cerSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_service-subscription_nodesQuery_response.json");
@@ -448,7 +448,7 @@ public class CrossEntityReferenceSynchronizerTest {
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString()))
.thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
"http://server.proxy:9200/myindex/mytype/doc2",
"http://server.proxy:9200/myindex/mytype/doc3");
@@ -456,15 +456,15 @@ public class CrossEntityReferenceSynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(200, null));
OperationState syncState = cerSynchronizer.doSync();
@@ -486,7 +486,7 @@ public class CrossEntityReferenceSynchronizerTest {
esStatConfig, cerLookup, oxmEntityLookup, searchableEntityLookup);
cerSynchronizer.setAaiAdapter(aaiAdapter);
- cerSynchronizer.setElasticSearchAdapter(esAdapter);
+ cerSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_service-subscription_nodesQuery_response.json");
@@ -752,7 +752,7 @@ public class CrossEntityReferenceSynchronizerTest {
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString()))
.thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
"http://server.proxy:9200/myindex/mytype/doc2",
"http://server.proxy:9200/myindex/mytype/doc3");
@@ -760,11 +760,11 @@ public class CrossEntityReferenceSynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
@@ -772,7 +772,7 @@ public class CrossEntityReferenceSynchronizerTest {
* Cause version conflict errors on every put to test retry flow
*/
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(409, null));
OperationState syncState = cerSynchronizer.doSync();
@@ -798,7 +798,7 @@ public class CrossEntityReferenceSynchronizerTest {
esStatConfig, cerLookup, oxmEntityLookup, searchableEntityLookup);
cerSynchronizer.setAaiAdapter(aaiAdapter);
- cerSynchronizer.setElasticSearchAdapter(esAdapter);
+ cerSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_service-subscription_nodesQuery_response.json");
@@ -982,7 +982,7 @@ public class CrossEntityReferenceSynchronizerTest {
"/sync/aai/aai-traversal/generic-query/service-instance-56.json")));
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString()))
.thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
"http://server.proxy:9200/myindex/mytype/doc2",
"http://server.proxy:9200/myindex/mytype/doc3");
@@ -990,27 +990,27 @@ public class CrossEntityReferenceSynchronizerTest {
/*
* Our initial gets from elastic search return 200 ok with a found entity document requiring a doc update
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch1.json")));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch2.json")));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch3.json")));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc4"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc4"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch4.json")));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc5"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc5"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch5.json")));
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(200, null));
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(200, null));
OperationState syncState = cerSynchronizer.doSync();
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/dal/ElasticSearchAdapterTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/dal/ElasticSearchAdapterTest.java
deleted file mode 100644
index 33d57ae..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/dal/ElasticSearchAdapterTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.onap.aai.sparky.dal;
-
-import static org.junit.Assert.assertNotNull;
-
-import javax.ws.rs.core.MediaType;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.aai.restclient.enums.RestAuthenticationMode;
-import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-
-public class ElasticSearchAdapterTest {
-
-
- private ElasticSearchAdapter elasticSearchAdapter;
- private RestEndpointConfig endpointConfig;
-
- @Before
- public void init() throws Exception {
-
- endpointConfig = new RestEndpointConfig();
- endpointConfig.setRestAuthenticationMode(RestAuthenticationMode.SSL_BASIC);
- elasticSearchAdapter = new ElasticSearchAdapter(endpointConfig);
- }
-
-
- @Test
- public void updateValues() {
-
- assertNotNull(elasticSearchAdapter.doPost("https://es.onap.server:9200","{maxResults:10, queryStr: f}",MediaType.APPLICATION_JSON_TYPE));
- assertNotNull(elasticSearchAdapter.doGet("https://es.onap.server:9200",MediaType.APPLICATION_JSON_TYPE));
- assertNotNull(elasticSearchAdapter.doHead("https://es.onap.server:9200",MediaType.APPLICATION_JSON_TYPE));
- assertNotNull(elasticSearchAdapter.doPut("https://es.onap.server:9200","{maxResults:10, queryStr: f}",MediaType.APPLICATION_JSON_TYPE));
- assertNotNull(elasticSearchAdapter.doPatch("https://es.onap.server:9200","{maxResults:10, queryStr: f}",MediaType.APPLICATION_JSON_TYPE));
- assertNotNull(elasticSearchAdapter.doDelete("https://es.onap.server:9200",MediaType.APPLICATION_JSON_TYPE));
- assertNotNull(elasticSearchAdapter.doBulkOperation("https://es.onap.server:9200","{maxResults:10, queryStr: f}"));
- assertNotNull(elasticSearchAdapter.buildBulkImportOperationRequest("","","","",""));
- assertNotNull(elasticSearchAdapter.retrieveEntityById("","","","",""));
- assertNotNull(elasticSearchAdapter.buildElasticSearchUrlForApi("",""));
- assertNotNull(elasticSearchAdapter.buildElasticSearchUrl("",""));
- assertNotNull(elasticSearchAdapter.buildElasticSearchGetDocUrl("","",""));
- assertNotNull(elasticSearchAdapter.buildElasticSearchGetDocUrl("",""));
- assertNotNull(elasticSearchAdapter.buildElasticSearchPostUrl(""));
- assertNotNull(elasticSearchAdapter.getBulkUrl());
-
- }
-
-
-}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilderTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilderTest.java
deleted file mode 100644
index 9cd7781..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilderTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.onap.aai.sparky.inventory;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-//import java.security.SecureRandom;
-
-import org.junit.Before;
-import org.junit.Test;
-//import org.openecomp.sparky.analytics.HistoricalCounter;
-import org.onap.aai.sparky.inventory.EntityHistoryQueryBuilder;
-
-public class EntityHistoryQueryBuilderTest {
-
- private EntityHistoryQueryBuilder entityHistoryQueryBuilder;
-
- @Before
- public void init() throws Exception {
- entityHistoryQueryBuilder = new EntityHistoryQueryBuilder();
- }
-
- @SuppressWarnings("static-access")
- @Test
- public void successfullBuild() {
- entityHistoryQueryBuilder.getQuery("table");
- assertNotNull(entityHistoryQueryBuilder.createTableQuery());
- entityHistoryQueryBuilder.getQuery("graph");
- assertNotNull(entityHistoryQueryBuilder.createGraphQuery());
- entityHistoryQueryBuilder.getQuery("tree");
- assertNull(entityHistoryQueryBuilder.getQuery("tree"));
-
- }
-
-} \ No newline at end of file
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/GeoIndexDocumentTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/GeoIndexDocumentTest.java
deleted file mode 100644
index 2e39725..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/GeoIndexDocumentTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- * ============LICENSE_START===================================================
- * SPARKY (AAI UI service)
- * ============================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ============================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=====================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-
-package org.onap.aai.sparky.inventory;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.aai.sparky.inventory.entity.GeoIndexDocument;
-
-/**
- * The Class GeoIndexDocumentTest.
- */
-@RunWith(MockitoJUnitRunner.class)
-public class GeoIndexDocumentTest {
-
- /**
- * Inits the.
- *
- * @throws Exception the exception
- */
- @Before
- public void init() throws Exception {}
-
- /**
- * Checks if is valid geo index document success path.
- */
- @Test
- public void isValidGeoIndexDocument_successPath() {
-
- GeoIndexDocument geoDoc = new GeoIndexDocument();
-
- geoDoc.setEntityPrimaryKeyName("pkeyName");
- geoDoc.setEntityPrimaryKeyValue("pkeyValue");
- geoDoc.setEntityType("type");
- geoDoc.setId("12312");
- geoDoc.setLatitude("-45.123");
- geoDoc.setLongitude("181.321");
- geoDoc.setSelfLink("https://server.somewhere.com:8443/aai/v7/id");
-
- assertTrue(geoDoc.isValidGeoDocument());
-
- }
-
- /**
- * Checks if is valid geo index document fail no geo coordinates.
- */
- @Test
- public void isValidGeoIndexDocument_fail_no_geoCoordinates() {
-
- GeoIndexDocument geoIndexDoc = new GeoIndexDocument();
-
- geoIndexDoc.setEntityPrimaryKeyName("pkeyName");
- geoIndexDoc.setEntityPrimaryKeyValue("pkeyValue");
- geoIndexDoc.setEntityType("type");
- geoIndexDoc.setId("12312");
- geoIndexDoc.setSelfLink("https://server.somewhere.com:8443/aai/v7/id");
-
- assertFalse(geoIndexDoc.isValidGeoDocument());
-
- }
-
- /**
- * Checks if is valid geo index document fail invalid geo coordinates.
- */
- @Test
- public void isValidGeoIndexDocument_fail_invalid_geoCoordinates() {
-
- GeoIndexDocument geoIndexDoc = new GeoIndexDocument();
-
- geoIndexDoc.setEntityPrimaryKeyName("pkeyName");
- geoIndexDoc.setEntityPrimaryKeyValue("pkeyValue");
- geoIndexDoc.setEntityType("type");
- geoIndexDoc.setId("12312");
- geoIndexDoc.setLatitude("not_a_valid");
- geoIndexDoc.setLongitude("geo point");
-
- geoIndexDoc.setSelfLink("https://server.somewhere.com:8443/aai/v7/id");
-
- assertFalse(geoIndexDoc.isValidGeoDocument());
-
- }
-
- /**
- * Checks if is valid geo index document fail nothing set.
- */
- @Test
- public void isValidGeoIndexDocument_fail_nothing_set() {
-
- GeoIndexDocument geoIndexDoc = new GeoIndexDocument();
-
- assertFalse(geoIndexDoc.isValidGeoDocument());
-
- }
-}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/entity/TopographicalEntityTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/entity/TopographicalEntityTest.java
deleted file mode 100644
index c878077..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/inventory/entity/TopographicalEntityTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.onap.aai.sparky.inventory.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
-
-public class TopographicalEntityTest {
-
- private TopographicalEntity topographicalEntity;
-
-
- @Before
- public void init() throws Exception {
- topographicalEntity = new TopographicalEntity();
- }
-
-
- @SuppressWarnings("static-access")
- @Test
- public void updateValues() {
-
- topographicalEntity.setEntityType("");
- assertNotNull(topographicalEntity.getEntityType());
- topographicalEntity.setEntityPrimaryKeyValue("");
- assertNotNull(topographicalEntity.getEntityPrimaryKeyValue());
- topographicalEntity.setEntityPrimaryKeyName("");
- assertNotNull(topographicalEntity.getEntityPrimaryKeyName());
- topographicalEntity.setLatitude("");
- assertNotNull(topographicalEntity.getLatitude());
- topographicalEntity.setLongitude("");
- assertNotNull(topographicalEntity.getLongitude());
- topographicalEntity.setSelfLink("");
- assertNotNull(topographicalEntity.getSelfLink());
- topographicalEntity.setId("");
- assertNotNull(topographicalEntity.getId());
- assertNotNull(topographicalEntity.getSerialversionuid());
- assertNotNull(topographicalEntity.toString());
-
- //assertNotNull(topographicalEntity.getAsJson());
- //assertNotNull(topographicalEntity.generateUniqueShaDigest("","",""));
- }
-
-}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/EntityCountHistoryProcessorTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/EntityCountHistoryProcessorTest.java
deleted file mode 100644
index c74e4e5..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/EntityCountHistoryProcessorTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package org.onap.aai.sparky.search;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.component.restlet.RestletConstants;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.search.EntityCountHistoryProcessor;
-import org.onap.aai.sparky.util.RestletUtils;
-import org.restlet.Request;
-import org.restlet.Response;
-import org.restlet.data.ClientInfo;
-import org.restlet.data.Reference;
-import org.restlet.data.Status;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-public class EntityCountHistoryProcessorTest {
- private EntityCountHistoryProcessor entityCountHistoryProcessor;
- private Exchange mockExchange;
- private Message mockRequestMessage;
- private Message mockResponseMessage;
- private Request mockRestletRequest;
- private Response mockRestletResponse;
- private ClientInfo requestClientInfo;
- private RestletUtils mockRestletUtils;
- private ElasticSearchAdapter mockElasticSearchAdapter;
-
- @Before
- public void init() throws Exception {
- mockExchange = Mockito.mock(Exchange.class);
- mockRequestMessage = Mockito.mock(Message.class);
- mockResponseMessage = Mockito.mock(Message.class);
- mockRestletRequest = Mockito.mock(Request.class);
- mockRestletResponse = Mockito.mock(Response.class);
- mockRestletUtils = Mockito.mock(RestletUtils.class);
- mockElasticSearchAdapter = Mockito.mock(ElasticSearchAdapter.class);
-
- entityCountHistoryProcessor = new EntityCountHistoryProcessor(mockElasticSearchAdapter,
- "pserver", "vnf", "entityCount-index");
- entityCountHistoryProcessor.setRestletUtils(mockRestletUtils);
-
- requestClientInfo = new ClientInfo();
-
- Mockito.when(mockRestletRequest.getClientInfo()).thenReturn(requestClientInfo);
-
- Mockito.when(mockRequestMessage.getHeader(RestletConstants.RESTLET_REQUEST, Request.class))
- .thenReturn(mockRestletRequest);
- Mockito.when(mockRequestMessage.getHeader(RestletConstants.RESTLET_RESPONSE, Response.class))
- .thenReturn(mockRestletResponse);
- Mockito.when(mockExchange.getIn()).thenReturn(mockRequestMessage);
- Mockito.when(mockExchange.getOut()).thenReturn(mockResponseMessage);
- }
-
- public String getStubbedData_getEntityCountHistory_success() {
- ObjectMapper mapper = new ObjectMapper();
- ObjectNode entityCountEntry = mapper.createObjectNode();
-
- entityCountEntry.put("doc_count", 2069);
- entityCountEntry.put("key", "complex");
-
- ArrayNode arrayNode = mapper.createArrayNode();
- arrayNode.add(entityCountEntry);
-
- ObjectNode resultNode = mapper.createObjectNode();
- resultNode.set("result", arrayNode);
-
- return resultNode.toString();
- }
-
- @Test
- public void testGetEntityCountHistory_success() {
- EntityCountHistoryProcessor spyEntityCountHistoryProcessor =
- Mockito.spy(entityCountHistoryProcessor);
- OperationResult operationResult = new OperationResult();
-
- String result = getStubbedData_getEntityCountHistory_success();
-
- operationResult.setResult(Status.SUCCESS_OK.getCode(), result);
-
- Mockito.when(mockExchange.getIn().getHeader("CamelHttpQuery", String.class)).thenReturn("");
-
- Mockito.doReturn("table").when(spyEntityCountHistoryProcessor).getTypeParameter(Mockito.any());
- Mockito.doReturn(operationResult).when(spyEntityCountHistoryProcessor).getResults(Mockito.any(),
- Mockito.any());
-
-
- }
-
- @Test
- public void testGetEntityCountHistory_failure_noTypeParameter() {
- Mockito.when(mockRestletRequest.getOriginalRef()).thenReturn(new Reference());
-
- EntityCountHistoryProcessor spyEntityCountHistoryProcessor =
- Mockito.spy(entityCountHistoryProcessor);
- OperationResult operationResult = new OperationResult();
-
- String result = getStubbedData_getEntityCountHistory_success();
-
- operationResult.setResult(Status.SUCCESS_OK.getCode(), result);
-
- Mockito.when(mockExchange.getIn().getHeader("CamelHttpQuery", String.class)).thenReturn("");
-
- Mockito.doReturn("").when(spyEntityCountHistoryProcessor).getTypeParameter(Mockito.any());
- Mockito.doReturn(operationResult).when(spyEntityCountHistoryProcessor).getResults(Mockito.any(),
- Mockito.any());
-
-
- }
-}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizerTest.java
index 3bd4928..c324991 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizerTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizerTest.java
@@ -20,7 +20,7 @@ import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
import org.onap.aai.sparky.config.oxm.SearchableOxmEntityDescriptor;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.dal.NetworkTransaction;
import org.onap.aai.sparky.dal.rest.HttpMethod;
import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
@@ -75,7 +75,7 @@ public class AbstractEntitySynchronizerTest {
private QuantumSynchronizer quantumSync;
private NetworkStatisticsConfig aaiStatConfig;
private NetworkStatisticsConfig esStatConfig;
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private ActiveInventoryAdapter aaiAdapter;
private SearchableEntityLookup searchableEntityLookup;
@@ -141,7 +141,7 @@ public class AbstractEntitySynchronizerTest {
esStatConfig.setTpsHistogramNumBins(20);
esStatConfig.setTpsHistogramNumDecimalPoints(2);
- esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ searchServiceAdapter = Mockito.mock(SearchServiceAdapter.class);
aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
}
@@ -216,12 +216,12 @@ public class AbstractEntitySynchronizerTest {
esStatConfig);
quantumSync.setAaiAdapter(aaiAdapter);
- quantumSync.setElasticSearchAdapter(esAdapter);
+ quantumSync.setSearchServiceAdapter(searchServiceAdapter);
quantumSync.clearCache();
assertNotNull(quantumSync.getAaiAdapter());
- assertNotNull(quantumSync.getElasticSearchAdapter());
+ assertNotNull(quantumSync.getSearchServiceAdapter());
assertEquals("quantum-search-index", quantumSync.getIndexName());
quantumSync.setIndexName("new-search-index-name");
@@ -285,7 +285,7 @@ public class AbstractEntitySynchronizerTest {
esStatConfig);
quantumSync.setAaiAdapter(aaiAdapter);
- quantumSync.setElasticSearchAdapter(esAdapter);
+ quantumSync.setSearchServiceAdapter(searchServiceAdapter);
searchableEntityLookup = new SearchableEntityLookup();
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AggregationSynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AggregationSynchronizerTest.java
index 65e6e70..8f8beea 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AggregationSynchronizerTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/AggregationSynchronizerTest.java
@@ -20,7 +20,7 @@ import org.onap.aai.sparky.aggregation.sync.AggregationSynchronizer;
import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
import org.onap.aai.sparky.sync.enumeration.OperationState;
@@ -37,7 +37,7 @@ public class AggregationSynchronizerTest {
private NetworkStatisticsConfig aaiStatConfig;
private NetworkStatisticsConfig esStatConfig;
private OxmEntityLookup oxmEntityLookup;
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private ActiveInventoryAdapter aaiAdapter;
@@ -112,7 +112,7 @@ public class AggregationSynchronizerTest {
oxmEntityLookup = new OxmEntityLookup();
- esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ searchServiceAdapter = Mockito.mock(SearchServiceAdapter.class);
aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
Map<String,OxmEntityDescriptor> oxmEntityDescriptors = new HashMap<String,OxmEntityDescriptor>();
@@ -139,10 +139,10 @@ public class AggregationSynchronizerTest {
esStatConfig, oxmEntityLookup);
aggregationSynchronizer.setAaiAdapter(aaiAdapter);
- aggregationSynchronizer.setElasticSearchAdapter(esAdapter);
+ aggregationSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
assertNotNull(aggregationSynchronizer.getAaiAdapter());
- assertNotNull(aggregationSynchronizer.getElasticSearchAdapter());
+ assertNotNull(aggregationSynchronizer.getSearchServiceAdapter());
}
@@ -153,7 +153,7 @@ public class AggregationSynchronizerTest {
esStatConfig, oxmEntityLookup);
aggregationSynchronizer.setAaiAdapter(aaiAdapter);
- aggregationSynchronizer.setElasticSearchAdapter(esAdapter);
+ aggregationSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_complex_nodesQuery_response.json");
@@ -177,7 +177,7 @@ public class AggregationSynchronizerTest {
}
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString())).thenReturn(
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString())).thenReturn(
"http://localhost:9200/myindex/mytype/doc1", "http://localhost:9200/myindex/mytype/doc2",
"http://localhost:9200/myindex/mytype/doc3", "http://localhost:9200/myindex/mytype/doc4",
"http://localhost:9200/myindex/mytype/doc5");
@@ -185,14 +185,14 @@ public class AggregationSynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when( esAdapter.doGet(Matchers.contains("doc1"), Mockito.any())).thenReturn(new OperationResult(404,null));
- Mockito.when( esAdapter.doGet(Matchers.contains("doc2"), Mockito.any())).thenReturn(new OperationResult(404,null));
- Mockito.when( esAdapter.doGet(Matchers.contains("doc3"), Mockito.any())).thenReturn(new OperationResult(404,null));
- Mockito.when( esAdapter.doGet(Matchers.contains("doc4"), Mockito.any())).thenReturn(new OperationResult(404,null));
- Mockito.when( esAdapter.doGet(Matchers.contains("doc5"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc4"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc5"), Mockito.any())).thenReturn(new OperationResult(404,null));
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(200, null));
OperationState syncState = aggregationSynchronizer.doSync();
@@ -215,7 +215,7 @@ public class AggregationSynchronizerTest {
esStatConfig, oxmEntityLookup);
aggregationSynchronizer.setAaiAdapter(aaiAdapter);
- aggregationSynchronizer.setElasticSearchAdapter(esAdapter);
+ aggregationSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_complex_nodesQuery_response.json");
@@ -239,7 +239,7 @@ public class AggregationSynchronizerTest {
}
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString())).thenReturn(
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString())).thenReturn(
"http://localhost:9200/myindex/mytype/doc1", "http://localhost:9200/myindex/mytype/doc2",
"http://localhost:9200/myindex/mytype/doc3", "http://localhost:9200/myindex/mytype/doc4",
"http://localhost:9200/myindex/mytype/doc5");
@@ -247,17 +247,17 @@ public class AggregationSynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when( esAdapter.doGet(Matchers.contains("doc1"), Mockito.any())).thenReturn(new OperationResult(404,null));
- Mockito.when( esAdapter.doGet(Matchers.contains("doc2"), Mockito.any())).thenReturn(new OperationResult(404,null));
- Mockito.when( esAdapter.doGet(Matchers.contains("doc3"), Mockito.any())).thenReturn(new OperationResult(404,null));
- Mockito.when( esAdapter.doGet(Matchers.contains("doc4"), Mockito.any())).thenReturn(new OperationResult(404,null));
- Mockito.when( esAdapter.doGet(Matchers.contains("doc5"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc4"), Mockito.any())).thenReturn(new OperationResult(404,null));
+ Mockito.when( searchServiceAdapter.doGet(Matchers.contains("doc5"), Mockito.any())).thenReturn(new OperationResult(404,null));
// 409 is the elastic search version conflict code, which will result in the entries being added
// to our retry queue and re-attempted a couple times.
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(409, null));
OperationState syncState = aggregationSynchronizer.doSync();
@@ -279,7 +279,7 @@ public class AggregationSynchronizerTest {
esStatConfig, oxmEntityLookup);
aggregationSynchronizer.setAaiAdapter(aaiAdapter);
- aggregationSynchronizer.setElasticSearchAdapter(esAdapter);
+ aggregationSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_complex_nodesQuery_response.json");
@@ -303,7 +303,7 @@ public class AggregationSynchronizerTest {
}
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString())).thenReturn(
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString())).thenReturn(
"http://localhost:9200/myindex/mytype/doc1", "http://localhost:9200/myindex/mytype/doc2",
"http://localhost:9200/myindex/mytype/doc3", "http://localhost:9200/myindex/mytype/doc4",
"http://localhost:9200/myindex/mytype/doc5");
@@ -311,22 +311,22 @@ public class AggregationSynchronizerTest {
/*
* Our initial gets from elastic search return 200 ok with a found entity document requiring a doc update
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch1.json")));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch2.json")));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch3.json")));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc4"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc4"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch4.json")));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc5"), Mockito.any())).thenReturn(new OperationResult(200,
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc5"), Mockito.any())).thenReturn(new OperationResult(200,
TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch5.json")));
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(200, null));
OperationState syncState = aggregationSynchronizer.doSync();
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleanerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleanerTest.java
deleted file mode 100644
index 30394de..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleanerTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package org.onap.aai.sparky.sync;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.enumeration.OperationState;
-import org.onap.aai.sparky.util.TestResourceLoader;
-
-public class ElasticSearchIndexCleanerTest {
-
- private ElasticSearchIndexCleaner esIndexCleaner;
-
- private ElasticSearchAdapter esAdapter;
- private ElasticSearchEndpointConfig esRestEndpointConfig;
- private ElasticSearchSchemaConfig esSchemaConfig;
-
- @Before
- public void init() throws Exception {
-
- esAdapter = Mockito.mock( ElasticSearchAdapter.class);
- esRestEndpointConfig = new ElasticSearchEndpointConfig();
- esSchemaConfig = new ElasticSearchSchemaConfig();
-
- esRestEndpointConfig.setScrollContextBatchRequestSize(5000);
- esRestEndpointConfig.setEsIpAddress("127.0.0.1");
- esRestEndpointConfig.setEsServerPort("9200");
- esRestEndpointConfig.setScrollContextTimeToLiveInMinutes(5);
-
- }
-
- @Test
- public void validateBasicConstruction() throws Exception {
- esIndexCleaner = new ElasticSearchIndexCleaner(esAdapter, esRestEndpointConfig, esSchemaConfig);
- }
-
- @Test
- public void validatePreOperationCollection() throws Exception {
-
- String beforeSyncScrollApiResponse = TestResourceLoader.getTestResourceDataJson(
- "/sync/ElasticSearch/BeforeSync_ElasticSearch_ScrollApi_Successful.json");
-
- OperationResult scrollApiOpResult = new OperationResult();
- scrollApiOpResult.setResultCode(200);
- scrollApiOpResult.setResult(beforeSyncScrollApiResponse);
-
- Mockito.when(esAdapter.doPost(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject()))
- .thenReturn(scrollApiOpResult);
-
- esIndexCleaner = new ElasticSearchIndexCleaner(esAdapter, esRestEndpointConfig, esSchemaConfig);
- OperationState opState = esIndexCleaner.populatePreOperationCollection();
-
- assertEquals(OperationState.OK, opState);
-
- }
-
- @Test
- public void validatePostOperationCollection() throws Exception {
-
- String afterSyncScrollApiResponse = TestResourceLoader.getTestResourceDataJson(
- "/sync/ElasticSearch/AfterSync_ElasticSearch_ScrollApi_Successful.json");
-
- OperationResult scrollApiOpResult = new OperationResult();
- scrollApiOpResult.setResultCode(200);
- scrollApiOpResult.setResult(afterSyncScrollApiResponse);
-
- Mockito.when(esAdapter.doPost(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject()))
- .thenReturn(scrollApiOpResult);
-
- esIndexCleaner = new ElasticSearchIndexCleaner(esAdapter, esRestEndpointConfig, esSchemaConfig);
- OperationState opState = esIndexCleaner.populatePostOperationCollection();
-
- assertEquals(OperationState.OK, opState);
-
- }
-
-
- @Test
- public void validatePerformCleanup() throws Exception {
-
- String beforeSyncScrollApiResponse = TestResourceLoader.getTestResourceDataJson(
- "/sync/ElasticSearch/BeforeSync_ElasticSearch_ScrollApi_Successful.json");
-
- OperationResult beforeScrollApiOpResult = new OperationResult();
- beforeScrollApiOpResult.setResultCode(200);
- beforeScrollApiOpResult.setResult(beforeSyncScrollApiResponse);
-
- String afterSyncScrollApiResponse = TestResourceLoader.getTestResourceDataJson(
- "/sync/ElasticSearch/AfterSync_ElasticSearch_ScrollApi_Successful.json");
-
- OperationResult afterScrollApiOpResult = new OperationResult();
- afterScrollApiOpResult.setResultCode(200);
- afterScrollApiOpResult.setResult(afterSyncScrollApiResponse);
-
- Mockito.when(esAdapter.doPost(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject()))
- .thenReturn(beforeScrollApiOpResult,afterScrollApiOpResult);
-
- esIndexCleaner = new ElasticSearchIndexCleaner(esAdapter, esRestEndpointConfig, esSchemaConfig);
-
- OperationState beforeOpState = esIndexCleaner.populatePreOperationCollection();
- OperationState afterOpState = esIndexCleaner.populatePostOperationCollection();
-
- assertEquals(OperationState.OK, beforeOpState);
- assertEquals(OperationState.OK, afterOpState);
-
- /*
- * Now we can start the test work
- */
-
- OperationState cleanupState = esIndexCleaner.performCleanup();
- assertEquals(OperationState.OK, cleanupState);
-
-
- }
-
-
-}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfigTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfigTest.java
deleted file mode 100644
index a0dc071..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfigTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.onap.aai.sparky.sync.config;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-
-
-
-import org.junit.Before;
-import org.junit.Test;
-
-
-public class ElasticSearchEndpointConfigTest {
-
- private ElasticSearchEndpointConfig elasticSearchEndpointConfig;
-
- @Before
- public void init() throws Exception {
- elasticSearchEndpointConfig = new ElasticSearchEndpointConfig();
-
- }
-
-
- @Test
- public void updateValues() {
-
- elasticSearchEndpointConfig.setEsIpAddress("aai.es.service");
- assertNotNull(elasticSearchEndpointConfig.getEsIpAddress());
- elasticSearchEndpointConfig.setEsServerPort("6585");
- assertNotNull(elasticSearchEndpointConfig.getEsServerPort());
- elasticSearchEndpointConfig.setScrollContextTimeToLiveInMinutes(3);
- assertEquals(3,elasticSearchEndpointConfig.getScrollContextTimeToLiveInMinutes());
- elasticSearchEndpointConfig.setScrollContextBatchRequestSize(3);
- assertEquals(3,elasticSearchEndpointConfig.getScrollContextBatchRequestSize());
-
- }
-
-
-}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/topology/sync/GeoSynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/topology/sync/GeoSynchronizerTest.java
deleted file mode 100644
index 8cc5626..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/topology/sync/GeoSynchronizerTest.java
+++ /dev/null
@@ -1,347 +0,0 @@
-package org.onap.aai.sparky.topology.sync;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.config.oxm.GeoEntityLookup;
-import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
-import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
-import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
-import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
-import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.sync.enumeration.OperationState;
-import org.onap.aai.sparky.util.TestResourceLoader;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class GeoSynchronizerTest {
-
- private static ObjectMapper mapper = new ObjectMapper();
-
- private GeoSynchronizer geoSynchronizer;
-
- private ElasticSearchSchemaConfig esSchemaConfig;
- private NetworkStatisticsConfig aaiStatConfig;
- private NetworkStatisticsConfig esStatConfig;
- private OxmEntityLookup oxmEntityLookup;
- private GeoEntityLookup geoEntityLookup;
- private ElasticSearchAdapter esAdapter;
- private ActiveInventoryAdapter aaiAdapter;
-
-
-
- @Before
- public void init() throws Exception {
-
- esSchemaConfig = new ElasticSearchSchemaConfig();
- esSchemaConfig.setIndexDocType("default");
- esSchemaConfig.setIndexMappingsFileName(null);
- esSchemaConfig.setIndexName("aggregation-index-name");
- esSchemaConfig.setIndexSettingsFileName(null);
-
-
- aaiStatConfig = new NetworkStatisticsConfig();
-
- aaiStatConfig.setNumSamplesPerThreadForRunningAverage(100);
-
- aaiStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
- aaiStatConfig.setBytesHistogramMaxYAxis(1000000L);
- aaiStatConfig.setBytesHistogramNumBins(20);
- aaiStatConfig.setBytesHistogramNumDecimalPoints(2);
-
- aaiStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
- aaiStatConfig.setQueueLengthHistogramMaxYAxis(20000);
- aaiStatConfig.setQueueLengthHistogramNumBins(20);
- aaiStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
-
- aaiStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
- aaiStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
- aaiStatConfig.setTaskAgeHistogramNumBins(20);
- aaiStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
-
- aaiStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
- aaiStatConfig.setResponseTimeHistogramMaxYAxis(1000L);
- aaiStatConfig.setResponseTimeHistogramNumBins(20);
- aaiStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
-
- aaiStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
- aaiStatConfig.setTpsHistogramMaxYAxis(100);
- aaiStatConfig.setTpsHistogramNumBins(20);
- aaiStatConfig.setTpsHistogramNumDecimalPoints(2);
-
- esStatConfig = new NetworkStatisticsConfig();
-
- esStatConfig.setNumSamplesPerThreadForRunningAverage(100);
-
- esStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
- esStatConfig.setBytesHistogramMaxYAxis(1000000L);
- esStatConfig.setBytesHistogramNumBins(20);
- esStatConfig.setBytesHistogramNumDecimalPoints(2);
-
- esStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
- esStatConfig.setQueueLengthHistogramMaxYAxis(20000);
- esStatConfig.setQueueLengthHistogramNumBins(20);
- esStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
-
- esStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
- esStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
- esStatConfig.setTaskAgeHistogramNumBins(20);
- esStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
-
- esStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
- esStatConfig.setResponseTimeHistogramMaxYAxis(10000L);
- esStatConfig.setResponseTimeHistogramNumBins(20);
- esStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
-
- esStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
- esStatConfig.setTpsHistogramMaxYAxis(100);
- esStatConfig.setTpsHistogramNumBins(20);
- esStatConfig.setTpsHistogramNumDecimalPoints(2);
-
- oxmEntityLookup = new OxmEntityLookup();
-
- esAdapter = Mockito.mock(ElasticSearchAdapter.class);
- aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
-
-
- Set<OxmModelProcessor> processors = new HashSet<OxmModelProcessor>();
-
- processors.add(oxmEntityLookup);
-
-
-
- Map<String, OxmEntityDescriptor> oxmEntityDescriptors =
- new HashMap<String, OxmEntityDescriptor>();
-
- OxmEntityDescriptor genericVnfDescriptor = new OxmEntityDescriptor();
- genericVnfDescriptor.setEntityName("generic-vnf");
- List<String> pkeyNames = new ArrayList<String>();
- pkeyNames.add("vnf-name");
-
- genericVnfDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
-
- oxmEntityDescriptors.put("generic-vnf", genericVnfDescriptor);
-
-
- oxmEntityLookup.setEntityDescriptors(oxmEntityDescriptors);
-
- SuggestionEntityDescriptor genericVnfSuggestionDescriptor = new SuggestionEntityDescriptor();
- genericVnfSuggestionDescriptor.setEntityName("generic-vnf");
- genericVnfSuggestionDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
-
-
-
- /*
- * SuggestionSearchEntity sse = new SuggestionSearchEntity(filtersConfig);
- *
- * sse.setEntityType("generic-vnf"); sse.setSuggestionPropertyTypes( Arrays.asList("vnf-name"));
- *
- * genericVnfSuggestionDescriptor.setSuggestionSearchEntity(sse);
- *
- * suggestionEntityDescriptors.put("generic-vnf", genericVnfSuggestionDescriptor);
- */
-
- geoEntityLookup = new GeoEntityLookup();
-
- processors.add(geoEntityLookup);
-
- // suggestionEntityLookup.setSuggestionSearchEntityDescriptors(suggestionEntityDescriptors);
- }
-
- @Test
- public void validateBasicConstruction() throws Exception {
-
- geoSynchronizer = new GeoSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, esStatConfig,
- geoEntityLookup, oxmEntityLookup);
-
- geoSynchronizer.setAaiAdapter(aaiAdapter);
- geoSynchronizer.setElasticSearchAdapter(esAdapter);
-
- assertNotNull(geoSynchronizer.getAaiAdapter());
- assertNotNull(geoSynchronizer.getElasticSearchAdapter());
-
- }
-
- @Test
- public void validateSmallSync() throws Exception {
-
- geoSynchronizer = new GeoSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, esStatConfig,
- geoEntityLookup, oxmEntityLookup);
-
-
- geoSynchronizer.setAaiAdapter(aaiAdapter);
- geoSynchronizer.setElasticSearchAdapter(esAdapter);
-
- String nodesQueryResponse = TestResourceLoader
- .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
-
- OperationResult genericVnfSelfLinks = new OperationResult();
-
- genericVnfSelfLinks.setResultCode(200);
- genericVnfSelfLinks.setResult(nodesQueryResponse);
-
- Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
- .thenReturn(genericVnfSelfLinks);
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
-
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
- .thenReturn("http://localhost:9200/myindex/mytype/doc1",
- "http://server.proxy:9200/myindex/mytype/doc2",
- "http://server.proxy:9200/myindex/mytype/doc3");
-
- /*
- * Our initial gets from elastic search should be record-not-found
- */
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
-
-
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
- .thenReturn(new OperationResult(200, null));
-
- OperationState syncState = geoSynchronizer.doSync();
- assertEquals(OperationState.OK, syncState);
-
- assertNotNull(geoSynchronizer.getStatReport(false));
- assertNotNull(geoSynchronizer.getStatReport(true));
-
- geoSynchronizer.clearCache();
- geoSynchronizer.shutdown();
-
-
- }
-
- @Test
- public void validateSmallSyncWithRetries() throws Exception {
-
- geoSynchronizer = new GeoSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, esStatConfig,
- geoEntityLookup, oxmEntityLookup);
-
-
- geoSynchronizer.setAaiAdapter(aaiAdapter);
- geoSynchronizer.setElasticSearchAdapter(esAdapter);
-
- String nodesQueryResponse = TestResourceLoader
- .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
-
- OperationResult genericVnfSelfLinks = new OperationResult();
-
- genericVnfSelfLinks.setResultCode(200);
- genericVnfSelfLinks.setResult(nodesQueryResponse);
-
- Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
- .thenReturn(genericVnfSelfLinks);
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
-
- Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
- .thenReturn(
- "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
-
- Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
- Mockito.anyString(), Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader
- .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
-
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
- .thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
- "http://server.proxy:9200/myindex/mytype/doc2",
- "http://server.proxy:9200/myindex/mytype/doc3");
-
- /*
- * Our initial gets from elastic search should be record-not-found
- */
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
- .thenReturn(new OperationResult(404, null));
-
-
- /*
- * Elastic Search puts always fail with a version conflict = 409
- */
-
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
- .thenReturn(new OperationResult(409, null));
-
- OperationState syncState = geoSynchronizer.doSync();
- assertEquals(OperationState.OK, syncState);
-
- assertNotNull(geoSynchronizer.getStatReport(false));
- assertNotNull(geoSynchronizer.getStatReport(true));
-
- geoSynchronizer.clearCache();
- geoSynchronizer.shutdown();
-
-
- }
-} \ No newline at end of file
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationServiceTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationServiceTest.java
index e51c629..eeacde1 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationServiceTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationServiceTest.java
@@ -8,10 +8,10 @@ import org.mockito.Mockito;
import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
import org.onap.aai.sparky.config.oxm.OxmModelLoader;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
import org.onap.aai.sparky.dal.GizmoAdapter;
+import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.subscription.config.SubscriptionConfig;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.util.OxmModelAndProcessorHelper;
import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
@@ -21,10 +21,10 @@ import org.onap.aai.sparky.viewandinspect.util.SchemaVisualizationTestDataBuilde
public class BaseVisualizationServiceTest {
private ActiveInventoryAdapter mockAaiAdapter;
- private ElasticSearchAdapter mockEsAdapter;
+ private SearchServiceAdapter mocksearchServiceAdapter;
private VisualizationConfigs visualizationConfigs;
private SubscriptionConfig subConfig;
- private ElasticSearchEndpointConfig endpointEConfig;
+ private RestEndpointConfig endpointEConfig;
private ElasticSearchSchemaConfig schemaEConfig;
private OxmEntityLookup oxmEntityLookup;
private GizmoAdapter mockGizmoAdapter;
@@ -35,18 +35,18 @@ public class BaseVisualizationServiceTest {
public void init() throws Exception {
this.mockAaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
this.mockAaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
- this.mockEsAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ this.mocksearchServiceAdapter = Mockito.mock(SearchServiceAdapter.class);
this.mockGizmoAdapter = Mockito.mock(GizmoAdapter.class);
this.visualizationConfigs = new VisualizationConfigs();
this.subConfig = new SubscriptionConfig();
- this.endpointEConfig = new ElasticSearchEndpointConfig();
+ this.endpointEConfig = new RestEndpointConfig();
this.schemaEConfig = new ElasticSearchSchemaConfig();
this.oxmEntityLookup = OxmModelAndProcessorHelper.getInstance().getOxmEntityLookup();
OxmModelLoader modelLoader = OxmModelAndProcessorHelper.getInstance().getModelLoader();
this.baseVisService = new BaseVisualizationService(modelLoader, visualizationConfigs,
- mockAaiAdapter, mockGizmoAdapter, mockEsAdapter, endpointEConfig, schemaEConfig, 1,
+ mockAaiAdapter, mockGizmoAdapter, mocksearchServiceAdapter, endpointEConfig, schemaEConfig, 1,
oxmEntityLookup, subConfig);
}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectEntitySynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectEntitySynchronizerTest.java
index 2bf7856..0fd3bca 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectEntitySynchronizerTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectEntitySynchronizerTest.java
@@ -22,7 +22,7 @@ import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
import org.onap.aai.sparky.sync.enumeration.OperationState;
@@ -38,7 +38,7 @@ public class ViewInspectEntitySynchronizerTest {
private NetworkStatisticsConfig esStatConfig;
private OxmEntityLookup oxmEntityLookup;
private SearchableEntityLookup searchableEntityLookup;
- private ElasticSearchAdapter esAdapter;
+ private SearchServiceAdapter searchServiceAdapter;
private ActiveInventoryAdapter aaiAdapter;
@@ -113,7 +113,7 @@ public class ViewInspectEntitySynchronizerTest {
oxmEntityLookup = new OxmEntityLookup();
- esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ searchServiceAdapter = Mockito.mock(SearchServiceAdapter.class);
aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
@@ -169,10 +169,10 @@ public class ViewInspectEntitySynchronizerTest {
aaiStatConfig, esStatConfig, oxmEntityLookup, searchableEntityLookup);
viewInspectSynchronizer.setAaiAdapter(aaiAdapter);
- viewInspectSynchronizer.setElasticSearchAdapter(esAdapter);
+ viewInspectSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
assertNotNull(viewInspectSynchronizer.getAaiAdapter());
- assertNotNull(viewInspectSynchronizer.getElasticSearchAdapter());
+ assertNotNull(viewInspectSynchronizer.getSearchServiceAdapter());
}
@@ -184,7 +184,7 @@ public class ViewInspectEntitySynchronizerTest {
viewInspectSynchronizer.setAaiAdapter(aaiAdapter);
- viewInspectSynchronizer.setElasticSearchAdapter(esAdapter);
+ viewInspectSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
@@ -227,7 +227,7 @@ public class ViewInspectEntitySynchronizerTest {
.thenReturn(new OperationResult(200, TestResourceLoader
.getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString()))
.thenReturn("http://server.proxy:9200/myindex/mytype/doc1",
"http://server.proxy:9200/myindex/mytype/doc2",
"http://server.proxy:9200/myindex/mytype/doc3");
@@ -235,15 +235,15 @@ public class ViewInspectEntitySynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(200, null));
OperationState syncState = viewInspectSynchronizer.doSync();
@@ -266,7 +266,7 @@ public class ViewInspectEntitySynchronizerTest {
viewInspectSynchronizer.setAaiAdapter(aaiAdapter);
- viewInspectSynchronizer.setElasticSearchAdapter(esAdapter);
+ viewInspectSynchronizer.setSearchServiceAdapter(searchServiceAdapter);
String nodesQueryResponse = TestResourceLoader
.getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
@@ -309,7 +309,7 @@ public class ViewInspectEntitySynchronizerTest {
.thenReturn(new OperationResult(200, TestResourceLoader
.getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
- Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ Mockito.when(searchServiceAdapter.buildSearchServiceDocUrl(Mockito.anyString(), Mockito.anyString()))
.thenReturn("http://localhost:9200/myindex/mytype/doc1",
"http://localhost:9200/myindex/mytype/doc2",
"http://localhost:9200/myindex/mytype/doc3");
@@ -317,11 +317,11 @@ public class ViewInspectEntitySynchronizerTest {
/*
* Our initial gets from elastic search should be record-not-found
*/
- Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
- Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
.thenReturn(new OperationResult(404, null));
@@ -329,7 +329,7 @@ public class ViewInspectEntitySynchronizerTest {
* Elastic Search puts always fail with a version conflict = 409
*/
- Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ Mockito.when(searchServiceAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
.thenReturn(new OperationResult(409, null));
OperationState syncState = viewInspectSynchronizer.doSync();
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectGizmoEntitySynchronizer.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectGizmoEntitySynchronizer.java
deleted file mode 100644
index 6d63a8a..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectGizmoEntitySynchronizer.java
+++ /dev/null
@@ -1,792 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-package org.onap.aai.sparky.viewandinspect.sync;
-
-import static java.util.concurrent.CompletableFuture.supplyAsync;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedDeque;
-import java.util.concurrent.ExecutorService;
-import java.util.function.Supplier;
-
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.cl.mdc.MdcContext;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.config.oxm.OxmEntityContainerLookup;
-import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
-import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
-import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
-import org.onap.aai.sparky.config.oxm.SearchableOxmEntityDescriptor;
-import org.onap.aai.sparky.dal.GizmoAdapter;
-import org.onap.aai.sparky.dal.NetworkTransaction;
-import org.onap.aai.sparky.dal.rest.HttpMethod;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
-import org.onap.aai.sparky.sync.IndexSynchronizer;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.sync.entity.MergableEntity;
-import org.onap.aai.sparky.sync.entity.SearchableEntity;
-import org.onap.aai.sparky.sync.entity.SelfLinkDescriptor;
-import org.onap.aai.sparky.sync.enumeration.OperationState;
-import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchPut;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchRetrieval;
-import org.onap.aai.sparky.sync.task.PerformElasticSearchUpdate;
-import org.onap.aai.sparky.sync.task.PerformGizmoRetrieval;
-import org.onap.aai.sparky.util.NodeUtils;
-import org.slf4j.MDC;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectReader;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-
-/**
- * The Class SearchableEntitySynchronizer.
- */
-public class ViewInspectGizmoEntitySynchronizer extends AbstractEntitySynchronizer
- implements IndexSynchronizer {
-
- /**
- * The Class RetrySearchableEntitySyncContainer.
- */
- private class RetrySearchableEntitySyncContainer {
- NetworkTransaction txn;
- SearchableEntity se;
-
- /**
- * Instantiates a new retry searchable entity sync container.
- *
- * @param txn the txn
- * @param se the se
- */
- public RetrySearchableEntitySyncContainer(NetworkTransaction txn, SearchableEntity se) {
- this.txn = txn;
- this.se = se;
- }
-
- public NetworkTransaction getNetworkTransaction() {
- return txn;
- }
-
- public SearchableEntity getSearchableEntity() {
- return se;
- }
- }
-
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(ViewInspectGizmoEntitySynchronizer.class);
-
- private boolean allWorkEnumerated;
- private Deque<SelfLinkDescriptor> selflinks;
- private Deque<RetrySearchableEntitySyncContainer> retryQueue;
- private Map<String, Integer> retryLimitTracker;
- protected ExecutorService esPutExecutor;
- private OxmEntityLookup oxmEntityLookup;
- private SearchableEntityLookup searchableEntityLookup;
- private GizmoAdapter gizmoAdapter;
- private OxmEntityContainerLookup entityContainerLookup;
-
- /**
- * Instantiates a new searchable entity synchronizer.
- *
- * @param indexName the index name
- * @throws Exception the exception
- */
- public ViewInspectGizmoEntitySynchronizer(ElasticSearchSchemaConfig schemaConfig,
- int internalSyncWorkers, int gizmoWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig, OxmEntityLookup oxmEntityLookup,
- SearchableEntityLookup searchableEntityLookup, OxmEntityContainerLookup entityContainerLookup) throws Exception {
- super(LOG, "SES", internalSyncWorkers, gizmoWorkers, esWorkers, schemaConfig.getIndexName(),
- aaiStatConfig, esStatConfig);
-
- this.oxmEntityLookup = oxmEntityLookup;
- this.searchableEntityLookup = searchableEntityLookup;
- this.entityContainerLookup = entityContainerLookup;
- this.allWorkEnumerated = false;
- this.selflinks = new ConcurrentLinkedDeque<SelfLinkDescriptor>();
- this.retryQueue = new ConcurrentLinkedDeque<RetrySearchableEntitySyncContainer>();
- this.retryLimitTracker = new ConcurrentHashMap<String, Integer>();
- this.synchronizerName = "Searchable Entity Synchronizer";
- this.esPutExecutor = NodeUtils.createNamedExecutor("SES-ES-PUT", 5, LOG);
- this.aaiEntityStats.intializeEntityCounters(
- searchableEntityLookup.getSearchableEntityDescriptors().keySet());
- this.esEntityStats.intializeEntityCounters(
- searchableEntityLookup.getSearchableEntityDescriptors().keySet());
- this.syncDurationInMs = -1;
- }
-
-
-
- public GizmoAdapter getGizmoAdapter() {
- return gizmoAdapter;
-}
-
-
-
-public void setGizmoAdapter(GizmoAdapter gizmoAdapter) {
- this.gizmoAdapter = gizmoAdapter;
-}
-
-
-
-/**
- * Collect all the work.
- *
- * @return the operation state
- */
- private OperationState collectAllTheWork() {
- final Map<String, String> contextMap = MDC.getCopyOfContextMap();
-
- Collection<String> searchableEntityGroups = entityContainerLookup.getSearchableEntityGroups();
-
- if (searchableEntityGroups.isEmpty()) {
- LOG.error(AaiUiMsgs.ERROR_LOADING_OXM_SEARCHABLE_ENTITIES);
- return OperationState.ERROR;
- }
-
-
- try {
-
- /*
- * launch a parallel async thread to process the documents for each entity-type (to max the
- * of the configured executor anyway)
- */
-
- /*searchableEntityGroups = new ArrayList<String>();
- searchableEntityGroups.add("pservers");*/
-
- aaiWorkOnHand.set(searchableEntityGroups.size());
-
- for (String searchableEntityGroup : searchableEntityGroups) {
-
- supplyAsync(new Supplier<Void>() {
-
- @Override
- public Void get() {
- MDC.setContextMap(contextMap);
- OperationResult typeLinksResult = null;
- try {
- typeLinksResult = gizmoAdapter.getSelfLinksByEntityType(searchableEntityGroup);
- aaiWorkOnHand.decrementAndGet();
- processEntityTypeSelfLinks(typeLinksResult);
- } catch (Exception exc) {
-
- exc.printStackTrace();
- }
-
- return null;
- }
-
- }, aaiExecutor).whenComplete((result, error) -> {
-
- if (error != null) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC,
- "An error occurred getting data from AAI. Error = " + error.getMessage());
- }
- });
-
- }
-
- while (aaiWorkOnHand.get() != 0) {
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.WAIT_FOR_ALL_SELFLINKS_TO_BE_COLLECTED);
- }
-
- Thread.sleep(1000);
- }
-
- aaiWorkOnHand.set(selflinks.size());
- allWorkEnumerated = true;
- syncEntityTypes();
-
- while (!isSyncDone()) {
- performRetrySync();
- Thread.sleep(1000);
- }
-
- /*
- * Make sure we don't hang on to retries that failed which could cause issues during future
- * syncs
- */
- retryLimitTracker.clear();
-
- } catch (Exception exc) {
- // TODO -> LOG, waht should be logged here?
- }
-
- return OperationState.OK;
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#doSync()
- */
- @Override
- public OperationState doSync() {
- this.syncDurationInMs = -1;
- String txnID = NodeUtils.getRandomTxnId();
- MdcContext.initialize(txnID, "SearchableEntitySynchronizer", "", "Sync", "");
-
- resetCounters();
- this.allWorkEnumerated = false;
- syncStartedTimeStampInMs = System.currentTimeMillis();
- collectAllTheWork();
-
- return OperationState.OK;
- }
-
- /**
- * Process entity type self links.
- *
- * @param operationResult the operation result
- */
- private void processEntityTypeSelfLinks(OperationResult operationResult) {
-
- JsonNode rootNode = null;
-
- final String jsonResult = operationResult.getResult();
-
- if (jsonResult != null && jsonResult.length() > 0 && operationResult.wasSuccessful()) {
-
- try {
- rootNode = mapper.readTree(jsonResult);
- } catch (IOException exc) {
- String message = "Could not deserialize JSON (representing operation result) as node tree. "
- + "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
- LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
- }
-
- ArrayNode resultDataArrayNode = null;
-
- if (rootNode.isArray()) {
- resultDataArrayNode = (ArrayNode) rootNode;
-
- Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
- JsonNode element = null;
-
- while (elementIterator.hasNext()) {
- element = elementIterator.next();
-
- final String id = NodeUtils.getNodeFieldAsText(element, "id");
- final String type = NodeUtils.getNodeFieldAsText(element, "type");
- final String url = NodeUtils.getNodeFieldAsText(element, "url");
-
- String resourceLink;
- try {
- resourceLink = gizmoAdapter.getFullInventoryUrl(type + "/" + id);
- selflinks.add(new SelfLinkDescriptor(NodeUtils.extractRawGizmoPathWithoutVersion(resourceLink), null, type));
- } catch (Exception e) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC, "ERROR: Failed to determine resource link caused by " + e.getMessage());
- }
-
- }
- }
- }
-
- }
-
- /**
- * Sync entity types.
- */
- private void syncEntityTypes() {
-
- while (selflinks.peek() != null) {
-
- SelfLinkDescriptor linkDescriptor = selflinks.poll();
- aaiWorkOnHand.decrementAndGet();
-
- OxmEntityDescriptor descriptor = null;
-
- if (linkDescriptor.getSelfLink() != null && linkDescriptor.getEntityType() != null) {
-
- descriptor = oxmEntityLookup.getEntityDescriptors().get(linkDescriptor.getEntityType());
-
- if (descriptor == null) {
- LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, linkDescriptor.getEntityType());
- continue;
- }
-
- NetworkTransaction txn = new NetworkTransaction();
- txn.setDescriptor(descriptor);
- txn.setLink(linkDescriptor.getSelfLink());
- txn.setOperationType(HttpMethod.GET);
- txn.setEntityType(linkDescriptor.getEntityType());
-
- aaiWorkOnHand.incrementAndGet();
-
- supplyAsync(new PerformGizmoRetrieval(txn, gizmoAdapter), aaiExecutor)
- .whenComplete((result, error) -> {
-
- aaiWorkOnHand.decrementAndGet();
-
- if (error != null) {
- LOG.error(AaiUiMsgs.AAI_RETRIEVAL_FAILED_GENERIC, error.getLocalizedMessage());
- } else {
- if (result == null) {
- LOG.error(AaiUiMsgs.AAI_RETRIEVAL_FAILED_FOR_SELF_LINK,
- linkDescriptor.getSelfLink());
- } else {
- updateActiveInventoryCounters(result);
- fetchDocumentForUpsert(result);
- }
- }
- });
- }
-
- }
-
- }
-
- /**
- * Perform document upsert.
- *
- * @param esGetTxn the es get txn
- * @param se the se
- */
- protected void performDocumentUpsert(NetworkTransaction esGetTxn, SearchableEntity se) {
- /**
- * <p>
- * <ul>
- * As part of the response processing we need to do the following:
- * <li>1. Extract the version (if present), it will be the ETAG when we use the
- * Search-Abstraction-Service
- * <li>2. Spawn next task which is to do the PUT operation into elastic with or with the version
- * tag
- * <li>a) if version is null or RC=404, then standard put, no _update with version tag
- * <li>b) if version != null, do PUT with _update?version= versionNumber in the URI to elastic
- * </ul>
- * </p>
- */
- String link = null;
- try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), se.getId());
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
- return;
- }
-
- String versionNumber = null;
- boolean wasEntryDiscovered = false;
- if (esGetTxn.getOperationResult().getResultCode() == 404) {
- LOG.info(AaiUiMsgs.ES_SIMPLE_PUT, se.getEntityPrimaryKeyValue());
- } else if (esGetTxn.getOperationResult().getResultCode() == 200) {
- wasEntryDiscovered = true;
- try {
- versionNumber = NodeUtils.extractFieldValueFromObject(
- NodeUtils.convertJsonStrToJsonNode(esGetTxn.getOperationResult().getResult()),
- "_version");
- } catch (IOException exc) {
- String message =
- "Error extracting version number from response, aborting searchable entity sync of "
- + se.getEntityPrimaryKeyValue() + ". Error - " + exc.getLocalizedMessage();
- LOG.error(AaiUiMsgs.ERROR_EXTRACTING_FROM_RESPONSE, message);
- return;
- }
- } else {
- /*
- * Not being a 200 does not mean a failure. eg 201 is returned for created. TODO -> Should we
- * return.
- */
- LOG.error(AaiUiMsgs.ES_OPERATION_RETURN_CODE,
- String.valueOf(esGetTxn.getOperationResult().getResultCode()));
- return;
- }
-
- try {
- String jsonPayload = null;
- if (wasEntryDiscovered) {
- try {
- ArrayList<JsonNode> sourceObject = new ArrayList<JsonNode>();
- NodeUtils.extractObjectsByKey(
- NodeUtils.convertJsonStrToJsonNode(esGetTxn.getOperationResult().getResult()),
- "_source", sourceObject);
-
- if (!sourceObject.isEmpty()) {
- String responseSource = NodeUtils.convertObjectToJson(sourceObject.get(0), false);
- MergableEntity me = mapper.readValue(responseSource, MergableEntity.class);
- ObjectReader updater = mapper.readerForUpdating(me);
- MergableEntity merged = updater.readValue(NodeUtils.convertObjectToJson(se,false));
- jsonPayload = mapper.writeValueAsString(merged);
- }
- } catch (IOException exc) {
- String message =
- "Error extracting source value from response, aborting searchable entity sync of "
- + se.getEntityPrimaryKeyValue() + ". Error - " + exc.getLocalizedMessage();
- LOG.error(AaiUiMsgs.ERROR_EXTRACTING_FROM_RESPONSE, message);
- return;
- }
- } else {
- jsonPayload = se.getAsJson();
- }
-
- if (wasEntryDiscovered) {
- if (versionNumber != null && jsonPayload != null) {
-
- String requestPayload = elasticSearchAdapter.buildBulkImportOperationRequest(getIndexName(),
- "default", se.getId(), versionNumber, jsonPayload);
-
- NetworkTransaction transactionTracker = new NetworkTransaction();
- transactionTracker.setEntityType(esGetTxn.getEntityType());
- transactionTracker.setDescriptor(esGetTxn.getDescriptor());
- transactionTracker.setOperationType(HttpMethod.PUT);
-
- esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchUpdate(elasticSearchAdapter.getBulkUrl(),
- requestPayload, elasticSearchAdapter, transactionTracker), esPutExecutor)
- .whenComplete((result, error) -> {
-
- esWorkOnHand.decrementAndGet();
-
- if (error != null) {
- String message = "Searchable entity sync UPDATE PUT error - "
- + error.getLocalizedMessage();
- LOG.error(AaiUiMsgs.ES_SEARCHABLE_ENTITY_SYNC_ERROR, message);
- } else {
- updateElasticSearchCounters(result);
- processStoreDocumentResult(result, esGetTxn, se);
- }
- });
- }
-
- } else {
-
- if (link != null && jsonPayload != null) {
-
- NetworkTransaction updateElasticTxn = new NetworkTransaction();
- updateElasticTxn.setLink(link);
- updateElasticTxn.setEntityType(esGetTxn.getEntityType());
- updateElasticTxn.setDescriptor(esGetTxn.getDescriptor());
- updateElasticTxn.setOperationType(HttpMethod.PUT);
-
- esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
- esPutExecutor).whenComplete((result, error) -> {
-
- esWorkOnHand.decrementAndGet();
-
- if (error != null) {
- String message =
- "Searchable entity sync UPDATE PUT error - " + error.getLocalizedMessage();
- LOG.error(AaiUiMsgs.ES_SEARCHABLE_ENTITY_SYNC_ERROR, message);
- } else {
- updateElasticSearchCounters(result);
- processStoreDocumentResult(result, esGetTxn, se);
- }
- });
- }
- }
- } catch (Exception exc) {
- String message = "Exception caught during searchable entity sync PUT operation. Message - "
- + exc.getLocalizedMessage();
- LOG.error(AaiUiMsgs.ES_SEARCHABLE_ENTITY_SYNC_ERROR, message);
- }
- }
-
- /**
- * Populate searchable entity document.
- *
- * @param doc the doc
- * @param result the result
- * @param resultDescriptor the result descriptor
- * @throws JsonProcessingException the json processing exception
- * @throws IOException Signals that an I/O exception has occurred.
- */
- protected void populateSearchableEntityDocument(SearchableEntity doc, String result,
- OxmEntityDescriptor resultDescriptor) throws JsonProcessingException, IOException {
-
- doc.setEntityType(resultDescriptor.getEntityName());
-
- JsonNode entityNode = mapper.readTree(result);
-
- String id = NodeUtils.getNodeFieldAsText(entityNode, "id");
- String type = NodeUtils.getNodeFieldAsText(entityNode, "type");
- String url = NodeUtils.getNodeFieldAsText(entityNode, "url");
-
- JsonNode properties = entityNode.get("properties");
-
- Iterator<String> fieldNames = properties.fieldNames();
-
-
-
- List<String> primaryKeyValues = new ArrayList<String>();
- String pkeyValue = null;
-
- SearchableOxmEntityDescriptor searchableDescriptor = searchableEntityLookup.getSearchableEntityDescriptors().get(resultDescriptor.getEntityName());
-
- for (String keyName : searchableDescriptor.getPrimaryKeyAttributeNames()) {
- pkeyValue = NodeUtils.getNodeFieldAsText(properties, keyName);
- if (pkeyValue != null) {
- primaryKeyValues.add(pkeyValue);
- } else {
- String message = "populateSearchableEntityDocument(), pKeyValue is null for entityType = "
- + resultDescriptor.getEntityName();
- LOG.warn(AaiUiMsgs.WARN_GENERIC, message);
- }
- }
-
- final String primaryCompositeKeyValue = NodeUtils.concatArray(primaryKeyValues, "/");
- doc.setEntityPrimaryKeyValue(primaryCompositeKeyValue);
-
- final List<String> searchTagFields = searchableDescriptor.getSearchableAttributes();
-
- /*
- * Based on configuration, use the configured field names for this entity-Type to build a
- * multi-value collection of search tags for elastic search entity search criteria.
- */
- for (String searchTagField : searchTagFields) {
- String searchTagValue = NodeUtils.getNodeFieldAsText(properties, searchTagField);
- if (searchTagValue != null && !searchTagValue.isEmpty()) {
- doc.addSearchTagWithKey(searchTagValue, searchTagField);
- }
- }
- }
-
- /**
- * Fetch document for upsert.
- *
- * @param txn the txn
- */
- private void fetchDocumentForUpsert(NetworkTransaction txn) {
- if (!txn.getOperationResult().wasSuccessful()) {
- String message = "Self link failure. Result - " + txn.getOperationResult().getResult();
- LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
- return;
- }
-
- SearchableOxmEntityDescriptor searchableDescriptor = searchableEntityLookup
- .getSearchableEntityDescriptors().get(txn.getDescriptor().getEntityName());
-
- try {
- if (searchableDescriptor.hasSearchableAttributes()) {
-
- final String jsonResult = txn.getOperationResult().getResult();
- if (jsonResult != null && jsonResult.length() > 0) {
-
- SearchableEntity se = new SearchableEntity();
- se.setLink( txn.getLink() );
- populateSearchableEntityDocument(se, jsonResult, searchableDescriptor);
- se.deriveFields();
-
-
- String link = null;
- try {
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), se.getId());
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY, exc.getLocalizedMessage());
- }
-
- if (link != null) {
- NetworkTransaction n2 = new NetworkTransaction();
- n2.setLink(link);
- n2.setEntityType(txn.getEntityType());
- n2.setDescriptor(txn.getDescriptor());
- n2.setOperationType(HttpMethod.GET);
-
- esWorkOnHand.incrementAndGet();
-
- supplyAsync(new PerformElasticSearchRetrieval(n2, elasticSearchAdapter), esExecutor)
- .whenComplete((result, error) -> {
-
- esWorkOnHand.decrementAndGet();
-
- if (error != null) {
- LOG.error(AaiUiMsgs.ES_RETRIEVAL_FAILED, error.getLocalizedMessage());
- } else {
- updateElasticSearchCounters(result);
- performDocumentUpsert(result, se);
- }
- });
- }
- }
-
- }
- } catch (JsonProcessingException exc) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC, "Processing error while fetching document for elasticsearch update. Error: " + exc.getMessage() );
- } catch (IOException exc) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC, "Processing error while fetching document for elasticsearch update. Error: " + exc.getMessage() );
- }
- }
-
- /**
- * Process store document result.
- *
- * @param esPutResult the es put result
- * @param esGetResult the es get result
- * @param se the se
- */
- private void processStoreDocumentResult(NetworkTransaction esPutResult,
- NetworkTransaction esGetResult, SearchableEntity se) {
-
- OperationResult or = esPutResult.getOperationResult();
-
- if (!or.wasSuccessful()) {
- if (or.getResultCode() == VERSION_CONFLICT_EXCEPTION_CODE) {
-
- if (shouldAllowRetry(se.getId())) {
- esWorkOnHand.incrementAndGet();
-
- RetrySearchableEntitySyncContainer rsc =
- new RetrySearchableEntitySyncContainer(esGetResult, se);
- retryQueue.push(rsc);
-
- String message = "Store document failed during searchable entity synchronization"
- + " due to version conflict. Entity will be re-synced.";
- LOG.warn(AaiUiMsgs.ES_SEARCHABLE_ENTITY_SYNC_ERROR, message);
- }
- } else {
- String message =
- "Store document failed during searchable entity synchronization with result code "
- + or.getResultCode() + " and result message " + or.getResult();
- LOG.error(AaiUiMsgs.ES_SEARCHABLE_ENTITY_SYNC_ERROR, message);
- }
- }
- }
-
- /**
- * Perform retry sync.
- */
- private void performRetrySync() {
- while (retryQueue.peek() != null) {
-
- RetrySearchableEntitySyncContainer rsc = retryQueue.poll();
- if (rsc != null) {
-
- SearchableEntity se = rsc.getSearchableEntity();
- NetworkTransaction txn = rsc.getNetworkTransaction();
-
- String link = null;
- try {
- /*
- * In this retry flow the se object has already derived its fields
- */
- link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), se.getId());
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_URI, exc.getLocalizedMessage());
- }
-
- if (link != null) {
- NetworkTransaction retryTransaction = new NetworkTransaction();
- retryTransaction.setLink(link);
- retryTransaction.setEntityType(txn.getEntityType());
- retryTransaction.setDescriptor(txn.getDescriptor());
- retryTransaction.setOperationType(HttpMethod.GET);
-
- /*
- * IMPORTANT - DO NOT incrementAndGet the esWorkOnHand as this is a retry flow! We already
- * called incrementAndGet when queuing the failed PUT!
- */
-
- supplyAsync(new PerformElasticSearchRetrieval(retryTransaction, elasticSearchAdapter),
- esExecutor).whenComplete((result, error) -> {
-
- esWorkOnHand.decrementAndGet();
-
- if (error != null) {
- LOG.error(AaiUiMsgs.ES_RETRIEVAL_FAILED_RESYNC, error.getLocalizedMessage());
- } else {
- updateElasticSearchCounters(result);
- performDocumentUpsert(result, se);
- }
- });
- }
-
- }
- }
- }
-
- /**
- * Should allow retry.
- *
- * @param id the id
- * @return true, if successful
- */
- private boolean shouldAllowRetry(String id) {
- boolean isRetryAllowed = true;
- if (retryLimitTracker.get(id) != null) {
- Integer currentCount = retryLimitTracker.get(id);
- if (currentCount.intValue() >= RETRY_COUNT_PER_ENTITY_LIMIT.intValue()) {
- isRetryAllowed = false;
- String message = "Searchable entity re-sync limit reached for " + id
- + ", re-sync will no longer be attempted for this entity";
- LOG.error(AaiUiMsgs.ES_SEARCHABLE_ENTITY_SYNC_ERROR, message);
- } else {
- Integer newCount = new Integer(currentCount.intValue() + 1);
- retryLimitTracker.put(id, newCount);
- }
- } else {
- Integer firstRetryCount = new Integer(1);
- retryLimitTracker.put(id, firstRetryCount);
- }
-
- return isRetryAllowed;
- }
-
- @Override
- public SynchronizerState getState() {
- if (!isSyncDone()) {
- return SynchronizerState.PERFORMING_SYNCHRONIZATION;
- }
-
- return SynchronizerState.IDLE;
-
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
- */
- @Override
- public String getStatReport(boolean showFinalReport) {
- syncDurationInMs = System.currentTimeMillis() - syncStartedTimeStampInMs;
- return this.getStatReport(syncDurationInMs, showFinalReport);
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#shutdown()
- */
- @Override
- public void shutdown() {
- this.shutdownExecutors();
- }
-
- @Override
- protected boolean isSyncDone() {
- int totalWorkOnHand = aaiWorkOnHand.get() + esWorkOnHand.get();
-
- if (totalWorkOnHand > 0 || !allWorkEnumerated) {
- return false;
- }
-
- return true;
- }
-
-}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectGizmoSyncController.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectGizmoSyncController.java
deleted file mode 100644
index c2a1150..0000000
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectGizmoSyncController.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-package org.onap.aai.sparky.viewandinspect.sync;
-
-import org.onap.aai.sparky.config.oxm.OxmEntityContainerLookup;
-import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
-import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.dal.GizmoAdapter;
-import org.onap.aai.sparky.sync.ElasticSearchIndexCleaner;
-import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
-import org.onap.aai.sparky.sync.IndexCleaner;
-import org.onap.aai.sparky.sync.IndexIntegrityValidator;
-import org.onap.aai.sparky.sync.SyncControllerImpl;
-import org.onap.aai.sparky.sync.SyncControllerRegistrar;
-import org.onap.aai.sparky.sync.SyncControllerRegistry;
-import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig;
-import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
-import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.sync.config.SyncControllerConfig;
-
-public class ViewInspectGizmoSyncController extends SyncControllerImpl
- implements SyncControllerRegistrar {
-
- private SyncControllerRegistry syncControllerRegistry;
- //private GizmoAdapter gizmoAdapter;
- //private ElasticSearchAdapter esAdapter;
- //private ElasticSearchSchemaConfig schemaConfig;
- //private ElasticSearchEndpointConfig endpointConfig;
-
- public ViewInspectGizmoSyncController(SyncControllerConfig syncControllerConfig,
- GizmoAdapter gizmoAdapter, ElasticSearchAdapter esAdapter,
- ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
- NetworkStatisticsConfig gizmoStatConfig, NetworkStatisticsConfig esStatConfig,
- OxmEntityLookup oxmEntityLookup,
- SearchableEntityLookup searchableEntityLookup, OxmEntityContainerLookup oxmEntityContainerLookup,
- ElasticSearchSchemaFactory elasticSearchSchemaFactory) throws Exception {
- super(syncControllerConfig);
-
- // final String controllerName = "View and Inspect Entity Synchronizer";
-
- //this.gizmoAdapter = gizmoAdapter;
- //this.esAdapter = esAdapter;
- //this.schemaConfig = schemaConfig;
- //this.endpointConfig = endpointConfig;
-
- IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(esAdapter, schemaConfig,
- endpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
-
- registerIndexValidator(indexValidator);
-
- ViewInspectGizmoEntitySynchronizer ses = new ViewInspectGizmoEntitySynchronizer(schemaConfig,
- syncControllerConfig.getNumInternalSyncWorkers(),
- syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(), gizmoStatConfig, esStatConfig,
- oxmEntityLookup, searchableEntityLookup, oxmEntityContainerLookup);
-
- ses.setGizmoAdapter(gizmoAdapter);
- ses.setElasticSearchAdapter(esAdapter);
-
- registerEntitySynchronizer(ses);
-
- IndexCleaner indexCleaner =
- new ElasticSearchIndexCleaner(esAdapter, endpointConfig, schemaConfig);
-
- registerIndexCleaner(indexCleaner);
-
- }
-
- public SyncControllerRegistry getSyncControllerRegistry() {
- return syncControllerRegistry;
- }
-
- public void setSyncControllerRegistry(SyncControllerRegistry syncControllerRegistry) {
- this.syncControllerRegistry = syncControllerRegistry;
- }
-
- @Override
- public void registerController() {
- if ( syncControllerRegistry != null ) {
- if ( syncControllerConfig.isEnabled()) {
- syncControllerRegistry.registerSyncController(this);
- }
- }
-
- }
-}