summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authordave.adams (da490c) <dave.adams@amdocs.com>2017-12-19 18:02:57 -0500
committerdave.adams (da490c) <dave.adams@amdocs.com>2017-12-19 23:13:38 -0500
commit9eb9e258f0ab06a516f6d88d1aedc36fc22aeeaf (patch)
tree7894072e9da7cc6dc557126df7bf27f2ee08a183 /src/main
parent05e74c6879ab564181e7cf92e4444d17cc7e25d4 (diff)
UI Exensibility config cleanup
Change-Id: I65cd9c92a04bad3ea4858fd70a697373671727b5 Signed-off-by: dave.adams (da490c) <dave.adams@amdocs.com> Issue-ID: AAI-542
Diffstat (limited to 'src/main')
-rw-r--r--src/main/ajsc/inventory-ui-service_v1/inventory-ui-service/v1/routes/README.txt1
-rw-r--r--src/main/java/org/onap/aai/sparky/HelloWorld.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/JaxrsEchoService.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java134
-rw-r--r--src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java77
-rw-r--r--src/main/java/org/onap/aai/sparky/aggregatevnf/search/VnfSearchQueryBuilder.java12
-rw-r--r--src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java36
-rw-r--r--src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java140
-rw-r--r--src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizer.java69
-rw-r--r--src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncController.java10
-rw-r--r--src/main/java/org/onap/aai/sparky/analytics/AbstractStatistics.java27
-rw-r--r--src/main/java/org/onap/aai/sparky/analytics/HistogramSampler.java5
-rw-r--r--src/main/java/org/onap/aai/sparky/analytics/HistoricalCounter.java41
-rw-r--r--src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java22
-rw-r--r--src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java47
-rw-r--r--src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java17
-rw-r--r--src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java23
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReference.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceDescriptor.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceLookup.java32
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/GeoEntityLookup.java24
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/GeoOxmEntityDescriptor.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/OxmEntityLookup.java27
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java41
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/OxmModelProcessor.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/SearchableEntityLookup.java27
-rw-r--r--src/main/java/org/onap/aai/sparky/config/oxm/SuggestionEntityLookup.java37
-rw-r--r--src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java453
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java155
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/ElasticSearchAdapter.java63
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/aai/ActiveInventoryDataProvider.java94
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatistics.java14
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryConfig.java121
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryRestConfig.java173
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventorySslConfig.java215
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/aai/enums/RestAuthenticationMode.java64
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchDataProvider.java69
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatistics.java23
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/elasticsearch/config/ElasticSearchConfig.java305
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/proxy/config/DataRouterConfig.java132
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/proxy/processor/AaiUiProxyProcessor.java72
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/rest/OperationResult.java197
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/rest/RestClientBuilder.java144
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/rest/RestClientConstructionException.java (renamed from src/main/java/org/onap/aai/sparky/viewandinspect/task/CollectNodeSelfLinkTask.java)35
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/rest/RestClientFactory.java94
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/rest/RestDataProvider.java109
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/rest/RestfulDataAccessor.java302
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/rest/config/RestEndpointConfig.java167
-rw-r--r--src/main/java/org/onap/aai/sparky/dal/sas/config/SearchServiceConfig.java25
-rw-r--r--src/main/java/org/onap/aai/sparky/dataintegrity/config/DiUiConstants.java77
-rw-r--r--src/main/java/org/onap/aai/sparky/editattributes/AttributeEditProcessor.java22
-rw-r--r--src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java66
-rw-r--r--src/main/java/org/onap/aai/sparky/editattributes/UserValidator.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilder.java14
-rw-r--r--src/main/java/org/onap/aai/sparky/inventory/GeoVisualizationProcessor.java68
-rw-r--r--src/main/java/org/onap/aai/sparky/inventory/entity/GeoIndexDocument.java28
-rw-r--r--src/main/java/org/onap/aai/sparky/inventory/entity/TopographicalEntity.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/logging/AaiUiMsgs.java37
-rw-r--r--src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java17
-rw-r--r--src/main/java/org/onap/aai/sparky/search/EntityCountHistoryProcessor.java168
-rw-r--r--src/main/java/org/onap/aai/sparky/search/EntityTypeSummary.java10
-rw-r--r--src/main/java/org/onap/aai/sparky/search/EntityTypeSummaryBucket.java8
-rw-r--r--src/main/java/org/onap/aai/sparky/search/SearchEntityProperties.java8
-rw-r--r--src/main/java/org/onap/aai/sparky/search/SearchResponse.java19
-rw-r--r--src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java137
-rw-r--r--src/main/java/org/onap/aai/sparky/search/UnifiedSearchProcessor.java34
-rw-r--r--src/main/java/org/onap/aai/sparky/search/api/SearchProvider.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/search/config/SuggestionConfig.java97
-rw-r--r--src/main/java/org/onap/aai/sparky/search/entity/ExternalSearchRequestEntity.java69
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java99
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java74
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java50
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java58
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/UiFiltersEntityConverter.java98
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java80
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/config/FiltersDetailsConfig.java8
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/config/FiltersForViewsConfig.java8
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterConfig.java32
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterDataSourceConfig.java23
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterListItemConfig.java9
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterOptionsValuesConfig.java7
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/config/UiViewListItemConfig.java9
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/entity/AggregationEntity.java5
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/entity/BoolQueryBuilder.java30
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/entity/SearchFilter.java6
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterEntity.java33
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterValueEntity.java9
-rw-r--r--src/main/java/org/onap/aai/sparky/search/filters/entity/UiFiltersEntity.java10
-rw-r--r--src/main/java/org/onap/aai/sparky/security/EcompSso.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/security/SecurityContextFactoryImpl.java6
-rw-r--r--src/main/java/org/onap/aai/sparky/security/filter/CspCookieFilter.java71
-rw-r--r--src/main/java/org/onap/aai/sparky/security/filter/LoginFilter.java29
-rw-r--r--src/main/java/org/onap/aai/sparky/security/portal/PortalRestAPIServiceImpl.java23
-rw-r--r--src/main/java/org/onap/aai/sparky/security/portal/UserManager.java5
-rw-r--r--src/main/java/org/onap/aai/sparky/security/portal/config/PortalAuthenticationConfig.java9
-rw-r--r--src/main/java/org/onap/aai/sparky/security/portal/config/RolesConfig.java9
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java60
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleaner.java21
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/ElasticSearchSchemaFactory.java15
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/SyncController.java10
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/SyncControllerImpl.java116
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/SyncControllerRegistry.java6
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/SyncControllerService.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/SynchronizerConstants.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfig.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/config/NetworkStatisticsConfig.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/config/SyncControllerConfig.java16
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/entity/AggregationEntity.java29
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/entity/AggregationSuggestionEntity.java23
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/entity/IndexDocument.java8
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/entity/SearchableEntity.java22
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/entity/SelfLinkDescriptor.java6
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/entity/SuggestionSearchEntity.java98
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/task/PerformActiveInventoryRetrieval.java13
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchPut.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchRetrieval.java8
-rw-r--r--src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/topology/sync/GeoSyncController.java15
-rw-r--r--src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java60
-rw-r--r--src/main/java/org/onap/aai/sparky/util/Encryptor.java8
-rw-r--r--src/main/java/org/onap/aai/sparky/util/KeystoreBuilder.java21
-rw-r--r--src/main/java/org/onap/aai/sparky/util/NodeUtils.java68
-rw-r--r--src/main/java/org/onap/aai/sparky/util/RestletUtils.java13
-rw-r--r--src/main/java/org/onap/aai/sparky/util/SuggestionsPermutation.java12
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/EntityTypeAggregation.java1
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessor.java207
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java100
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java42
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java55
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutput.java12
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/EntityEntry.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphMeta.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphRequest.java10
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessage.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeMeta.java8
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeProcessingTransaction.java6
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/QueryParams.java2
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelatedToProperty.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/Relationship.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipData.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipDirectionality.java10
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipList.java4
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/SearchableEntityList.java139
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphLink.java (renamed from src/main/java/org/onap/aai/sparky/dal/elasticsearch/HashQueryResponse.java)51
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphNode.java203
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingAction.java5
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingState.java3
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java106
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContext.java1635
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java366
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContext.java1613
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationService.java353
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java43
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformNodeSelfLinkProcessingTask.java11
-rw-r--r--src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformSelfLinkDeterminationTask.java21
-rw-r--r--src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java92
-rw-r--r--src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java55
158 files changed, 4728 insertions, 6699 deletions
diff --git a/src/main/ajsc/inventory-ui-service_v1/inventory-ui-service/v1/routes/README.txt b/src/main/ajsc/inventory-ui-service_v1/inventory-ui-service/v1/routes/README.txt
new file mode 100644
index 0000000..a3997db
--- /dev/null
+++ b/src/main/ajsc/inventory-ui-service_v1/inventory-ui-service/v1/routes/README.txt
@@ -0,0 +1 @@
+Place any camel routes here that you want to access within the ajsc upon deployment of your service.
diff --git a/src/main/java/org/onap/aai/sparky/HelloWorld.java b/src/main/java/org/onap/aai/sparky/HelloWorld.java
index 2eff767..30d277d 100644
--- a/src/main/java/org/onap/aai/sparky/HelloWorld.java
+++ b/src/main/java/org/onap/aai/sparky/HelloWorld.java
@@ -28,7 +28,7 @@ import org.apache.camel.Exchange;
* The Class HelloWorld.
*/
public class HelloWorld {
-
+
/**
* Instantiates a new hello world.
*/
diff --git a/src/main/java/org/onap/aai/sparky/JaxrsEchoService.java b/src/main/java/org/onap/aai/sparky/JaxrsEchoService.java
index f7ea619..5c408c2 100644
--- a/src/main/java/org/onap/aai/sparky/JaxrsEchoService.java
+++ b/src/main/java/org/onap/aai/sparky/JaxrsEchoService.java
@@ -36,7 +36,7 @@ import com.att.ajsc.filemonitor.AJSCPropertiesMap;
*/
@Path("/jaxrs-services")
public class JaxrsEchoService {
-
+
/**
* Ping.
*
diff --git a/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java b/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java
index 6d2ec6e..12443e4 100644
--- a/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java
+++ b/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java
@@ -35,12 +35,12 @@ 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.elasticsearch.SearchAdapter;
-import org.onap.aai.sparky.dataintegrity.config.DiUiConstants;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.search.filters.FilterQueryBuilder;
+import org.onap.aai.sparky.search.filters.config.FiltersConfig;
import org.onap.aai.sparky.search.filters.entity.SearchFilter;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.MediaType;
@@ -48,51 +48,32 @@ import org.restlet.data.Status;
public class AggregateSummaryProcessor {
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(AggregateSummaryProcessor.class);
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(AggregateSummaryProcessor.class);
private static final String KEY_FILTERS = "filters";
- private SearchAdapter search = null;
-
+ private ElasticSearchAdapter elasticSearchAdapter = null;
+
private String vnfAggregationIndexName;
- private String elasticSearchIp;
- private String elatsticSearchPort;
-
- public AggregateSummaryProcessor() {
- try {
- if (search == null) {
- search = new SearchAdapter();
- }
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC,
- "Failed to get elastic search configuration with error = " + exc.getMessage());
- }
+ private FiltersConfig filtersConfig;
+
+ public AggregateSummaryProcessor(ElasticSearchAdapter elasticSearchAdapter, FiltersConfig filtersConfig) {
+ this.elasticSearchAdapter = elasticSearchAdapter;
+ this.filtersConfig = filtersConfig;
}
-
+
public void setVnfAggregationIndexName(String vnfAggregationIndexName) {
this.vnfAggregationIndexName = vnfAggregationIndexName;
}
-
- public void setElasticSearchIp(String elasticSearchIp) {
- this.elasticSearchIp = elasticSearchIp;
- }
-
- public void setElatsticSearchPort(String elatsticSearchPort) {
- this.elatsticSearchPort = elatsticSearchPort;
- }
-
+
public void getFilteredAggregation(Exchange exchange) {
-
- Response response =
- exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
+
+ Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
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
- */
+ /* Disables automatic Apache Camel Restlet component logging which prints out an undesirable log entry
+ which includes client (e.g. browser) information */
request.setLoggable(false);
try {
@@ -114,29 +95,29 @@ public class AggregateSummaryProcessor {
if (parameters.has(KEY_FILTERS)) {
requestFilters = parameters.getJSONArray(KEY_FILTERS);
} else {
-
+
JSONObject zeroResponsePayload = new JSONObject();
zeroResponsePayload.put("count", 0);
response.setStatus(Status.SUCCESS_OK);
response.setEntity(zeroResponsePayload.toString(), MediaType.APPLICATION_JSON);
exchange.getOut().setBody(response);
-
+
LOG.error(AaiUiMsgs.ERROR_FILTERS_NOT_FOUND);
return;
}
-
+
if (requestFilters != null && requestFilters.length() > 0) {
List<JSONObject> filtersToQuery = new ArrayList<JSONObject>();
- for (int i = 0; i < requestFilters.length(); i++) {
+ for(int i = 0; i < requestFilters.length(); i++) {
JSONObject filterEntry = requestFilters.getJSONObject(i);
filtersToQuery.add(filterEntry);
}
-
+
String jsonResponsePayload = getVnfFilterAggregations(filtersToQuery);
response.setStatus(Status.SUCCESS_OK);
response.setEntity(jsonResponsePayload, MediaType.APPLICATION_JSON);
exchange.getOut().setBody(response);
-
+
} else {
String emptyResponse = getEmptyAggResponse();
response.setStatus(Status.SUCCESS_OK);
@@ -146,11 +127,10 @@ public class AggregateSummaryProcessor {
}
}
} catch (Exception exc) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC,
- "FilterProcessor failed to get filter list due to error = " + exc.getMessage());
+ LOG.error(AaiUiMsgs.ERROR_GENERIC, "FilterProcessor failed to get filter list due to error = " + exc.getMessage());
}
}
-
+
private String getEmptyAggResponse() {
JSONObject aggPayload = new JSONObject();
aggPayload.put("totalChartHits", 0);
@@ -159,78 +139,66 @@ public class AggregateSummaryProcessor {
payload.append("groupby_aggregation", aggPayload);
return payload.toString();
- }
-
+ }
+
private static final String FILTER_ID_KEY = "filterId";
private static final String FILTER_VALUE_KEY = "filterValue";
private static final int DEFAULT_SHOULD_MATCH_SCORE = 1;
private static final String VNF_FILTER_AGGREGATION = "vnfFilterAggregation";
-
+
private String getVnfFilterAggregations(List<JSONObject> filtersToQuery) throws IOException {
-
+
List<SearchFilter> searchFilters = new ArrayList<SearchFilter>();
- for (JSONObject filterEntry : filtersToQuery) {
-
+ for(JSONObject filterEntry : filtersToQuery) {
+
String filterId = filterEntry.getString(FILTER_ID_KEY);
- if (filterId != null) {
+ if(filterId != null) {
SearchFilter filter = new SearchFilter();
filter.setFilterId(filterId);
-
- if (filterEntry.has(FILTER_VALUE_KEY)) {
+
+ if(filterEntry.has(FILTER_VALUE_KEY)) {
String filterValue = filterEntry.getString(FILTER_VALUE_KEY);
filter.addValue(filterValue);
}
-
+
searchFilters.add(filter);
}
}
-
+
// Create query for summary by entity type
- JsonObject vnfSearch =
- FilterQueryBuilder.createCombinedBoolAndAggQuery(searchFilters, DEFAULT_SHOULD_MATCH_SCORE);
+ JsonObject vnfSearch = FilterQueryBuilder.createCombinedBoolAndAggQuery(filtersConfig, searchFilters, DEFAULT_SHOULD_MATCH_SCORE);
// Parse response for summary by entity type query
- OperationResult opResult =
- search.doPost(getFullUrl(vnfAggregationIndexName, TierSupportUiConstants.ES_SEARCH_API),
- vnfSearch.toString(), DiUiConstants.APP_JSON);
-
+ OperationResult opResult = elasticSearchAdapter.doPost(
+ elasticSearchAdapter.buildElasticSearchUrlForApi(vnfAggregationIndexName,
+ SparkyConstants.ES_SEARCH_API),
+ vnfSearch.toString(), javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE);
+
return buildAggregateVnfResponseJson(opResult.getResult());
-
+
}
-
- /**
- * Get Full URL for search using elastic search configuration.
- *
- * @param api the api
- * @return the full url
- */
- private String getFullUrl(String indexName, String api) {
- final String host = elasticSearchIp;
- final String port = elatsticSearchPort;
- return String.format("http://%s:%s/%s/%s", host, port, indexName, api);
- }
-
+
private String buildAggregateVnfResponseJson(String responseJsonStr) {
-
+
JSONObject finalOutputToFe = new JSONObject();
JSONObject responseJson = new JSONObject(responseJsonStr);
-
-
+
+
JSONObject hits = responseJson.getJSONObject("hits");
int totalHits = hits.getInt("total");
finalOutputToFe.put("total", totalHits);
-
+
JSONObject aggregations = responseJson.getJSONObject("aggregations");
String[] aggKeys = JSONObject.getNames(aggregations);
JSONObject aggregationsList = new JSONObject();
-
- for (String aggName : aggKeys) {
+
+ for(String aggName : aggKeys) {
JSONObject aggregation = aggregations.getJSONObject(aggName);
JSONArray buckets = aggregation.getJSONArray("buckets");
aggregationsList.put(aggName, buckets);
}
-
+
finalOutputToFe.put("aggregations", aggregationsList);
return finalOutputToFe.toString();
diff --git a/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java b/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java
index ec3dfaa..6ff779d 100644
--- a/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java
+++ b/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.List;
import javax.json.JsonObject;
+import javax.ws.rs.core.MediaType;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -33,68 +34,38 @@ 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.common.search.CommonSearchSuggestion;
-import org.onap.aai.sparky.dal.elasticsearch.SearchAdapter;
-import org.onap.aai.sparky.dataintegrity.config.DiUiConstants;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.search.api.SearchProvider;
import org.onap.aai.sparky.search.entity.QuerySearchEntity;
import org.onap.aai.sparky.search.entity.SearchSuggestion;
import org.onap.aai.sparky.search.filters.entity.UiFilterValueEntity;
import org.onap.aai.sparky.util.NodeUtils;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AggregateVnfSearchProvider implements SearchProvider {
-
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(AggregateVnfSearchProvider.class);
+
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(AggregateVnfSearchProvider.class);
private ObjectMapper mapper;
- private static SearchAdapter search = null;
-
+ private ElasticSearchAdapter elasticSearchAdapter = null;
private String autoSuggestIndexName;
- private String elasticSearchIp;
- private String elatsticSearchPort;
-
- public AggregateVnfSearchProvider() {
+ private String vnfSearchSuggestionRoute;
+ public AggregateVnfSearchProvider(ElasticSearchAdapter elasticSearchAdapter,
+ String autoSuggestIndexName, String vnfSearchSuggestionRoute) {
mapper = new ObjectMapper();
-
- try {
- if (search == null) {
- search = new SearchAdapter();
- }
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.CONFIGURATION_ERROR,
- "Search Configuration Error. Error = " + exc.getMessage());
- }
+ this.elasticSearchAdapter = elasticSearchAdapter;
+ this.autoSuggestIndexName = autoSuggestIndexName;
+ this.vnfSearchSuggestionRoute = vnfSearchSuggestionRoute;
}
-
+
public void setAutoSuggestIndexName(String autoSuggestIndexName) {
this.autoSuggestIndexName = autoSuggestIndexName;
}
- public void setElasticSearchIp(String elasticSearchIp) {
- this.elasticSearchIp = elasticSearchIp;
- }
-
- public void setElatsticSearchPort(String elatsticSearchPort) {
- this.elatsticSearchPort = elatsticSearchPort;
- }
-
- /**
- * Get Full URL for search using elastic search configuration.
- *
- * @param api the api
- * @return the full url
- */
- private String getFullUrl(String indexName, String api) {
- final String host = elasticSearchIp;
- final String port = elatsticSearchPort;
- return String.format("http://%s:%s/%s/%s", host, port, indexName, api);
- }
-
@Override
public List<SearchSuggestion> search(QuerySearchEntity queryRequest) {
@@ -103,13 +74,13 @@ public class AggregateVnfSearchProvider implements SearchProvider {
try {
/* Create suggestions query */
- JsonObject vnfSearch = VnfSearchQueryBuilder.createSuggestionsQuery(
- String.valueOf(queryRequest.getMaxResults()), queryRequest.getQueryStr());
+ JsonObject vnfSearch = VnfSearchQueryBuilder.createSuggestionsQuery(String.valueOf(queryRequest.getMaxResults()), queryRequest.getQueryStr());
/* Parse suggestions response */
- OperationResult opResult =
- search.doPost(getFullUrl(autoSuggestIndexName, TierSupportUiConstants.ES_SUGGEST_API),
- vnfSearch.toString(), DiUiConstants.APP_JSON);
+ OperationResult opResult = elasticSearchAdapter.doPost(
+ elasticSearchAdapter.buildElasticSearchUrlForApi(autoSuggestIndexName,
+ SparkyConstants.ES_SUGGEST_API),
+ vnfSearch.toString(), MediaType.APPLICATION_JSON_TYPE);
String result = opResult.getResult();
@@ -129,11 +100,8 @@ public class AggregateVnfSearchProvider implements SearchProvider {
if (querySuggestion != null) {
CommonSearchSuggestion responseSuggestion = new CommonSearchSuggestion();
responseSuggestion.setText(querySuggestion.getString("text"));
- responseSuggestion.setRoute("vnfSearch"); // TODO -> Read route from
- // suggestive-search.properties instead of
- // hard coding
- responseSuggestion
- .setHashId(NodeUtils.generateUniqueShaDigest(querySuggestion.getString("text")));
+ responseSuggestion.setRoute(vnfSearchSuggestionRoute);
+ responseSuggestion.setHashId(NodeUtils.generateUniqueShaDigest(querySuggestion.getString("text")));
// Extract filter list from JSON and add to response suggestion
JSONObject payload = querySuggestion.getJSONObject("payload");
@@ -141,8 +109,7 @@ public class AggregateVnfSearchProvider implements SearchProvider {
JSONArray filterList = payload.getJSONArray("filterList");
for (int filter = 0; filter < filterList.length(); filter++) {
String filterValueString = filterList.getJSONObject(filter).toString();
- UiFilterValueEntity filterValue =
- mapper.readValue(filterValueString, UiFilterValueEntity.class);
+ UiFilterValueEntity filterValue = mapper.readValue(filterValueString, UiFilterValueEntity.class);
responseSuggestion.getFilterValues().add(filterValue);
}
}
@@ -156,5 +123,5 @@ public class AggregateVnfSearchProvider implements SearchProvider {
return returnList;
}
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/aggregatevnf/search/VnfSearchQueryBuilder.java b/src/main/java/org/onap/aai/sparky/aggregatevnf/search/VnfSearchQueryBuilder.java
index 96fea3f..a5b14bd 100644
--- a/src/main/java/org/onap/aai/sparky/aggregatevnf/search/VnfSearchQueryBuilder.java
+++ b/src/main/java/org/onap/aai/sparky/aggregatevnf/search/VnfSearchQueryBuilder.java
@@ -30,23 +30,13 @@ import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
-import org.onap.aai.sparky.dataintegrity.config.DiUiConstants;
/**
* Build a JSON payload to send to elastic search to get vnf search data.
*/
public class VnfSearchQueryBuilder {
- static final String SEVERITY = DiUiConstants.SEVERITY;
- static final String TIMESTAMP = DiUiConstants.KEY_TIMESTAMP;
- static final String VIOLATIONS = DiUiConstants.VIOLATIONS;
- static final String CATEGORY = DiUiConstants.CATEGORY;
- static final String ENTITY_TYPE = DiUiConstants.ENTITY_TYPE;
-
- static final String ITEM = DiUiConstants.KEY_ITEM;
- static final String ITEM_AGG = DiUiConstants.KEY_ITEM_AGG;
- static final String BY_ITEM = DiUiConstants.KEY_BY_ITEM;
- static final String BUCKETS = DiUiConstants.KEY_BUCKETS;
+
/**
* Creates the suggestions query.
diff --git a/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java b/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java
index 6d8decf..503de3b 100644
--- a/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java
+++ b/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSyncControllerFactory.java
@@ -28,6 +28,7 @@ import java.util.Map;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
+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;
@@ -61,19 +62,22 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
private ElasticSearchEndpointConfig elasticSearchEndpointConfig;
private SyncControllerConfig syncControllerConfig;
private SyncControllerRegistry syncControllerRegistry;
- private NetworkStatisticsConfig aaiStatConfig;
+ private NetworkStatisticsConfig aaiStatConfig;
private NetworkStatisticsConfig esStatConfig;
-
+ private OxmEntityLookup oxmEntityLookup;
+
private List<SyncController> syncControllers;
public AggregationSyncControllerFactory(ElasticSearchEndpointConfig esEndpointConfig,
SyncControllerConfig syncControllerConfig, SyncControllerRegistry syncControllerRegistry,
- SuggestionEntityLookup suggestionEntityLookup) {
+ SuggestionEntityLookup suggestionEntityLookup,
+ OxmEntityLookup oxmEntityLookup) {
this.syncControllers = new ArrayList<SyncController>();
this.elasticSearchEndpointConfig = esEndpointConfig;
this.syncControllerConfig = syncControllerConfig;
this.syncControllerRegistry = syncControllerRegistry;
this.suggestionEntityLookup = suggestionEntityLookup;
+ this.oxmEntityLookup = oxmEntityLookup;
}
public NetworkStatisticsConfig getAaiStatConfig() {
@@ -153,13 +157,13 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
public void buildControllers() {
if (syncControllerConfig.isEnabled()) {
-
+
Map<String, SuggestionEntityDescriptor> suggestionEntitites =
suggestionEntityLookup.getSuggestionSearchEntityDescriptors();
SyncControllerImpl aggregationSyncController = null;
for (String entityType : suggestionEntitites.keySet()) {
-
+
String indexName = aggregationEntityToIndexMap.get(entityType);
if (indexName == null) {
@@ -180,16 +184,16 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
continue;
}
- IndexIntegrityValidator aggregationIndexValidator =
- new IndexIntegrityValidator(esAdapter, schemaConfig, elasticSearchEndpointConfig,
- ElasticSearchSchemaFactory.getIndexSchema(schemaConfig));
+ IndexIntegrityValidator aggregationIndexValidator = new IndexIntegrityValidator(esAdapter,
+ schemaConfig, elasticSearchEndpointConfig, ElasticSearchSchemaFactory.getIndexSchema(schemaConfig));
aggregationSyncController.registerIndexValidator(aggregationIndexValidator);
AggregationSynchronizer aggSynchronizer = new AggregationSynchronizer(entityType,
schemaConfig, syncControllerConfig.getNumInternalSyncWorkers(),
syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig);
+ syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig,
+ oxmEntityLookup);
aggSynchronizer.setAaiAdapter(aaiAdapter);
aggSynchronizer.setElasticSearchAdapter(esAdapter);
@@ -203,9 +207,9 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
syncControllers.add(aggregationSyncController);
} catch (Exception exc) {
-
+
exc.printStackTrace();
-
+
LOG.error(AaiUiMsgs.ERROR_GENERIC,
"Failed to build aggregation sync controller. Error : " + exc.getMessage());
}
@@ -219,14 +223,14 @@ public class AggregationSyncControllerFactory implements SyncControllerRegistrar
@Override
public void registerController() {
-
+
buildControllers();
-
- if (syncControllerRegistry != null) {
- for (SyncController controller : syncControllers) {
+
+ if ( syncControllerRegistry != null ) {
+ for ( SyncController controller : syncControllers ) {
syncControllerRegistry.registerSyncController(controller);
}
}
-
+
}
}
diff --git a/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java b/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java
index 2a115db..36cd8bc 100644
--- a/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java
+++ b/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java
@@ -42,9 +42,8 @@ import org.onap.aai.cl.mdc.MdcContext;
import org.onap.aai.restclient.client.OperationResult;
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.NetworkTransaction;
-import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
-import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
import org.onap.aai.sparky.dal.rest.HttpMethod;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
@@ -101,7 +100,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
return ae;
}
}
-
+
private static final Logger LOG =
LoggerFactory.getInstance().getLogger(AggregationSynchronizer.class);
private static final String INSERTION_DATE_TIME_FORMAT = "yyyyMMdd'T'HHmmssZ";
@@ -116,7 +115,8 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
private Map<String, String> contextMap;
private String entityType;
private ElasticSearchSchemaConfig schemaConfig;
-
+ private OxmEntityLookup oxmEntityLookup;
+
/**
* Instantiates a new entity aggregation synchronizer.
*
@@ -125,16 +125,14 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
*/
public AggregationSynchronizer(String entityType, ElasticSearchSchemaConfig schemaConfig,
int numSyncWorkers, int numActiveInventoryWorkers, int numElasticWorkers,
- NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig)
- throws Exception {
-
+ NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
+ OxmEntityLookup oxmEntityLookup) throws Exception {
+
super(LOG, "AGGES-" + schemaConfig.getIndexName().toUpperCase(), numSyncWorkers,
- numActiveInventoryWorkers, numElasticWorkers, schemaConfig.getIndexName(), aaiStatConfig,
- esStatConfig); // multiple
- // Autosuggestion
- // Entity Synchronizer will
- // run for different indices
-
+ numActiveInventoryWorkers, numElasticWorkers, schemaConfig.getIndexName(),aaiStatConfig, esStatConfig);
+
+ this.oxmEntityLookup = oxmEntityLookup;
+
this.schemaConfig = schemaConfig;
this.entityType = entityType;
this.allWorkEnumerated = false;
@@ -146,12 +144,12 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
this.selflinks = new ConcurrentLinkedDeque<SelfLinkDescriptor>();
this.retryQueue = new ConcurrentLinkedDeque<RetryAggregationEntitySyncContainer>();
this.retryLimitTracker = new ConcurrentHashMap<String, Integer>();
-
+
this.esPutExecutor = NodeUtils.createNamedExecutor("AGGES-ES-PUT", 1, LOG);
-
+
this.aaiEntityStats.intializeEntityCounters(entityType);
this.esEntityStats.intializeEntityCounters(entityType);
-
+
this.contextMap = MDC.getCopyOfContextMap();
}
@@ -179,7 +177,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
processEntityTypeSelfLinks(typeLinksResult);
} catch (Exception exc) {
// TODO -> LOG, what should be logged here?
-
+
exc.printStackTrace();
}
@@ -224,8 +222,8 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
return OperationState.OK;
}
-
-
+
+
/**
* Perform retry sync.
*/
@@ -243,7 +241,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
/*
* In this retry flow the se object has already derived its fields
*/
- link = getElasticFullUrl("/" + ae.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), ae.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_URI, exc.getLocalizedMessage());
}
@@ -277,7 +275,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
}
}
}
-
+
/**
* Perform document upsert.
*
@@ -300,7 +298,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
*/
String link = null;
try {
- link = getElasticFullUrl("/" + ae.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), ae.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
return;
@@ -373,7 +371,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
transactionTracker.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchUpdate(ElasticSearchConfig.getConfig().getBulkUrl(),
+ supplyAsync(new PerformElasticSearchUpdate(elasticSearchAdapter.getBulkUrl(),
requestPayload, elasticSearchAdapter, transactionTracker), esPutExecutor)
.whenComplete((result, error) -> {
@@ -400,8 +398,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
updateElasticTxn.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(
- new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
+ supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -423,7 +420,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
}
}
-
+
/**
* Should allow retry.
*
@@ -450,7 +447,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
return isRetryAllowed;
}
-
+
/**
* Process store document result.
*
@@ -485,7 +482,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
}
}
}
-
+
/**
* Sync entity types.
*/
@@ -500,8 +497,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
if (linkDescriptor.getSelfLink() != null && linkDescriptor.getEntityType() != null) {
- descriptor = OxmEntityLookup.getInstance().getEntityDescriptors()
- .get(linkDescriptor.getEntityType());
+ descriptor = oxmEntityLookup.getEntityDescriptors().get(linkDescriptor.getEntityType());
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, linkDescriptor.getEntityType());
@@ -539,7 +535,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
}
}
-
+
/**
* Fetch document for upsert.
*
@@ -554,53 +550,53 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
}
try {
- final String jsonResult = txn.getOperationResult().getResult();
- if (jsonResult != null && jsonResult.length() > 0) {
+ final String jsonResult = txn.getOperationResult().getResult();
+ if (jsonResult != null && jsonResult.length() > 0) {
- AggregationEntity ae = new AggregationEntity();
- ae.setLink(ActiveInventoryConfig.extractResourcePath(txn.getLink()));
- populateAggregationEntityDocument(ae, jsonResult, txn.getDescriptor());
- ae.deriveFields();
+ AggregationEntity ae = new AggregationEntity();
+ ae.setLink(ActiveInventoryAdapter.extractResourcePath(txn.getLink()));
+ populateAggregationEntityDocument(ae, jsonResult, txn.getDescriptor());
+ ae.deriveFields();
- String link = null;
- try {
- link = getElasticFullUrl("/" + ae.getId(), getIndexName());
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY, exc.getLocalizedMessage());
- }
+ String link = null;
+ try {
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), ae.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);
+ if (link != null) {
+ NetworkTransaction n2 = new NetworkTransaction();
+ n2.setLink(link);
+ n2.setEntityType(txn.getEntityType());
+ n2.setDescriptor(txn.getDescriptor());
+ n2.setOperationType(HttpMethod.GET);
- esWorkOnHand.incrementAndGet();
+ esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchRetrieval(n2, elasticSearchAdapter), esExecutor)
- .whenComplete((result, error) -> {
+ supplyAsync(new PerformElasticSearchRetrieval(n2, elasticSearchAdapter), esExecutor)
+ .whenComplete((result, error) -> {
- esWorkOnHand.decrementAndGet();
+ esWorkOnHand.decrementAndGet();
- if (error != null) {
- LOG.error(AaiUiMsgs.ES_RETRIEVAL_FAILED, error.getLocalizedMessage());
- } else {
- updateElasticSearchCounters(result);
- performDocumentUpsert(result, ae);
- }
- });
+ if (error != null) {
+ LOG.error(AaiUiMsgs.ES_RETRIEVAL_FAILED, error.getLocalizedMessage());
+ } else {
+ updateElasticSearchCounters(result);
+ performDocumentUpsert(result, ae);
+ }
+ });
+ }
}
- }
- } catch (JsonProcessingException exc) {
+ } catch (JsonProcessingException exc) {
// TODO -> LOG, waht should be logged here?
} catch (IOException exc) {
// TODO -> LOG, waht should be logged here?
}
}
-
-
+
+
/**
* Populate aggregation entity document.
*
@@ -617,7 +613,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
Map<String, Object> map = mapper.convertValue(entityNode, Map.class);
doc.copyAttributeKeyValuePair(map);
}
-
+
/**
* Process entity type self links.
*
@@ -634,8 +630,9 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
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();
+ String message =
+ "Could not deserialize JSON (representing operation result) as node tree. " +
+ "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
}
@@ -658,7 +655,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
if (resourceType != null && resourceLink != null) {
- descriptor = OxmEntityLookup.getInstance().getEntityDescriptors().get(resourceType);
+ descriptor = oxmEntityLookup.getEntityDescriptors().get(resourceType);
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
@@ -666,9 +663,8 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
continue;
}
- selflinks.add(new SelfLinkDescriptor(resourceLink,
- SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
-
+ selflinks.add(new SelfLinkDescriptor(resourceLink, SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
+
}
}
@@ -688,7 +684,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
syncStartedTimeStampInMs = System.currentTimeMillis();
String txnID = NodeUtils.getRandomTxnId();
MdcContext.initialize(txnID, "AggregationSynchronizer", "", "Sync", "");
-
+
return collectAllTheWork();
}
diff --git a/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizer.java b/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizer.java
index 5ee11be..7c9828b 100644
--- a/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizer.java
+++ b/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizer.java
@@ -65,8 +65,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
implements IndexSynchronizer {
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(HistoricalEntitySummarizer.class);
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(HistoricalEntitySummarizer.class);
private static final String INSERTION_DATE_TIME_FORMAT = "yyyyMMdd'T'HHmmssZ";
private boolean allWorkEnumerated;
@@ -74,6 +73,7 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
private boolean syncInProgress;
private Map<String, String> contextMap;
private ElasticSearchSchemaConfig schemaConfig;
+ private SearchableEntityLookup searchableEntityLookup;
/**
* Instantiates a new historical entity summarizer.
@@ -83,9 +83,9 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
*/
public HistoricalEntitySummarizer(ElasticSearchSchemaConfig schemaConfig, int internalSyncWorkers,
int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig) throws Exception {
- super(LOG, "HES", internalSyncWorkers, aaiWorkers, esWorkers, schemaConfig.getIndexName(),
- aaiStatConfig, esStatConfig);
+ NetworkStatisticsConfig esStatConfig, SearchableEntityLookup searchableEntityLookup)
+ throws Exception {
+ super(LOG, "HES", internalSyncWorkers, aaiWorkers, esWorkers, schemaConfig.getIndexName(), aaiStatConfig, esStatConfig);
this.schemaConfig = schemaConfig;
this.allWorkEnumerated = false;
@@ -93,8 +93,9 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
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.contextMap = MDC.getCopyOfContextMap();
this.syncDurationInMs = -1;
+ this.searchableEntityLookup = searchableEntityLookup;
}
/**
@@ -103,9 +104,9 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
* @return the operation state
*/
private OperationState collectAllTheWork() {
-
+
Map<String, SearchableOxmEntityDescriptor> descriptorMap =
- SearchableEntityLookup.getInstance().getSearchableEntityDescriptors();
+ searchableEntityLookup.getSearchableEntityDescriptors();
if (descriptorMap.isEmpty()) {
LOG.error(AaiUiMsgs.OXM_FAILED_RETRIEVAL, "historical entities");
@@ -126,14 +127,15 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
@Override
public Void get() {
- MDC.setContextMap(contextMap);
+ MDC.setContextMap(contextMap);
try {
- OperationResult typeLinksResult = aaiAdapter.getSelfLinksByEntityType(entityType);
+ 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;
@@ -155,8 +157,7 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
while (asyncWoH.get() > 0) {
if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- indexName + " summarizer waiting for all the links to be processed.");
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC, indexName + " summarizer waiting for all the links to be processed.");
}
Thread.sleep(250);
@@ -197,17 +198,15 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#doSync()
*/
@Override
public OperationState doSync() {
this.syncDurationInMs = -1;
- String txnID = NodeUtils.getRandomTxnId();
+ String txnID = NodeUtils.getRandomTxnId();
MdcContext.initialize(txnID, "HistoricalEntitySynchronizer", "", "Sync", "");
-
+
if (syncInProgress) {
LOG.info(AaiUiMsgs.HISTORICAL_SYNC_PENDING);
return OperationState.PENDING;
@@ -276,19 +275,18 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
@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 jsonString = Json.createObjectBuilder().add(
+ "count", entityCounterEntry.getValue().get())
+ .add("entityType", entityCounterEntry.getKey())
+ .add("timestamp", currentFormattedTimeStamp).build().toString();
String link = null;
try {
- link = getElasticFullUrl("", indexName);
- OperationResult or =
- elasticSearchAdapter.doPost(link, jsonString, MediaType.APPLICATION_JSON_TYPE);
+ 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());
+ LOG.error(AaiUiMsgs.ES_STORE_FAILURE, exc.getMessage() );
}
return null;
@@ -324,9 +322,7 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
*/
@Override
@@ -335,9 +331,7 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
return this.getStatReport(syncDurationInMs, showFinalReport);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#shutdown()
*/
@Override
@@ -351,8 +345,8 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
int totalWorkOnHand = aaiWorkOnHand.get() + esWorkOnHand.get();
if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, indexName + ", isSyncDone(), totalWorkOnHand = "
- + totalWorkOnHand + " all work enumerated = " + allWorkEnumerated);
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,indexName + ", isSyncDone(), totalWorkOnHand = " + totalWorkOnHand
+ + " all work enumerated = " + allWorkEnumerated);
}
if (totalWorkOnHand > 0 || !allWorkEnumerated) {
@@ -364,17 +358,14 @@ public class HistoricalEntitySummarizer extends AbstractEntitySynchronizer
return true;
}
- /*
- * (non-Javadoc)
- *
+ /* (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");
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "Historical Entity Summarizer in progress, request to clear cache ignored");
return;
}
diff --git a/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncController.java b/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncController.java
index 1f7db2e..f4dbdf6 100644
--- a/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncController.java
+++ b/src/main/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySyncController.java
@@ -22,6 +22,7 @@
*/
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;
@@ -43,7 +44,8 @@ public class HistoricalEntitySyncController extends SyncControllerImpl
ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
int syncFrequencyInMinutes, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig) throws Exception {
+ NetworkStatisticsConfig esStatConfig, SearchableEntityLookup searchableEntityLookup)
+ throws Exception {
super(syncControllerConfig);
// final String controllerName = "Historical Entity Count Synchronizer";
@@ -61,7 +63,7 @@ public class HistoricalEntitySyncController extends SyncControllerImpl
HistoricalEntitySummarizer historicalSummarizer = new HistoricalEntitySummarizer(schemaConfig,
syncControllerConfig.getNumInternalSyncWorkers(),
syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig);
+ syncControllerConfig.getNumSyncElasticWorkers(),aaiStatConfig, esStatConfig,searchableEntityLookup);
historicalSummarizer.setAaiAdapter(aaiAdapter);
historicalSummarizer.setElasticSearchAdapter(esAdapter);
@@ -80,8 +82,8 @@ public class HistoricalEntitySyncController extends SyncControllerImpl
@Override
public void registerController() {
- if (syncControllerRegistry != null) {
- if (syncControllerConfig.isEnabled()) {
+ if ( syncControllerRegistry != null ) {
+ if ( syncControllerConfig.isEnabled()) {
syncControllerRegistry.registerSyncController(this);
}
}
diff --git a/src/main/java/org/onap/aai/sparky/analytics/AbstractStatistics.java b/src/main/java/org/onap/aai/sparky/analytics/AbstractStatistics.java
index 6e7d854..2dd7d93 100644
--- a/src/main/java/org/onap/aai/sparky/analytics/AbstractStatistics.java
+++ b/src/main/java/org/onap/aai/sparky/analytics/AbstractStatistics.java
@@ -42,9 +42,7 @@ public class AbstractStatistics implements ComponentStatistics {
namedHistograms = new HashMap<String, HistogramSampler>();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.analytics.ComponentStatistics#addCounter(java.lang.String)
*/
/*
@@ -65,9 +63,7 @@ public class AbstractStatistics implements ComponentStatistics {
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.analytics.ComponentStatistics#pegCounter(java.lang.String)
*/
@Override
@@ -81,9 +77,7 @@ public class AbstractStatistics implements ComponentStatistics {
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.analytics.ComponentStatistics#incrementCounter(java.lang.String, int)
*/
@Override
@@ -98,11 +92,8 @@ public class AbstractStatistics implements ComponentStatistics {
}
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.analytics.ComponentStatistics#addHistogram(java.lang.String,
- * java.lang.String, long, int, int)
+ /* (non-Javadoc)
+ * @see org.openecomp.sparky.analytics.ComponentStatistics#addHistogram(java.lang.String, java.lang.String, long, int, int)
*/
@Override
public synchronized void addHistogram(String key, String histName, long maxYValue, int numBins,
@@ -116,9 +107,7 @@ public class AbstractStatistics implements ComponentStatistics {
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.analytics.ComponentStatistics#updateHistogram(java.lang.String, long)
*/
@Override
@@ -130,9 +119,7 @@ public class AbstractStatistics implements ComponentStatistics {
}
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.analytics.ComponentStatistics#reset()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/analytics/HistogramSampler.java b/src/main/java/org/onap/aai/sparky/analytics/HistogramSampler.java
index b1d55f4..1e9f970 100644
--- a/src/main/java/org/onap/aai/sparky/analytics/HistogramSampler.java
+++ b/src/main/java/org/onap/aai/sparky/analytics/HistogramSampler.java
@@ -259,8 +259,9 @@ public final class HistogramSampler {
if (counter == (numBins - 1)) {
// outlier bin
double leftBound = (stepSize * counter);
- sb.append(indentPadding).append("\t").append(
- " x >= " + String.format(floatFormatStr, leftBound) + " : " + histogramBins[counter])
+ sb.append(indentPadding).append("\t")
+ .append(" x >= " + String.format(floatFormatStr, leftBound) + " : "
+ + histogramBins[counter])
.append("\n");
} else {
diff --git a/src/main/java/org/onap/aai/sparky/analytics/HistoricalCounter.java b/src/main/java/org/onap/aai/sparky/analytics/HistoricalCounter.java
index 50941cc..76d58a5 100644
--- a/src/main/java/org/onap/aai/sparky/analytics/HistoricalCounter.java
+++ b/src/main/java/org/onap/aai/sparky/analytics/HistoricalCounter.java
@@ -117,30 +117,29 @@ public class HistoricalCounter {
return (totalOfSamples / numSamples);
}
-
public void setMin(double min) {
- this.min = min;
- }
-
+ this.min = min;
+ }
+
public void setMax(double max) {
- this.max = max;
- }
-
+ this.max = max;
+ }
+
public double getTotalOfSamples() {
- return totalOfSamples;
- }
+ return totalOfSamples;
+ }
- public void setTotalOfSamples(double totalOfSamples) {
- this.totalOfSamples = totalOfSamples;
- }
+ public void setTotalOfSamples(double totalOfSamples) {
+ this.totalOfSamples = totalOfSamples;
+ }
- public void setNumSamples(long numSamples) {
- this.numSamples = numSamples;
- }
-
- public void setMaintainSingleValue(boolean maintainSingleValue) {
- this.maintainSingleValue = maintainSingleValue;
- }
+ public void setNumSamples(long numSamples) {
+ this.numSamples = numSamples;
+ }
+
+ public void setMaintainSingleValue(boolean maintainSingleValue) {
+ this.maintainSingleValue = maintainSingleValue;
+ }
/**
@@ -154,9 +153,7 @@ public class HistoricalCounter {
value = 0.0;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java b/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java
index 950eb45..3392b3c 100644
--- a/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java
+++ b/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutoSuggestionSyncController.java
@@ -22,8 +22,11 @@
*/
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.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;
@@ -36,16 +39,16 @@ 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 AutoSuggestionSyncController extends SyncControllerImpl
- implements SyncControllerRegistrar {
+public class AutoSuggestionSyncController extends SyncControllerImpl implements SyncControllerRegistrar {
private SyncControllerRegistry syncControllerRegistry;
-
+
public AutoSuggestionSyncController(SyncControllerConfig syncControllerConfig,
ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
- NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig)
- throws Exception {
+ NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
+ OxmEntityLookup oxmEntityLookup, SuggestionEntityLookup suggestionEntityLookup,
+ FiltersConfig filtersConfig) throws Exception {
super(syncControllerConfig);
// final String controllerName = "Auto Suggestion Synchronizer";
@@ -58,7 +61,8 @@ public class AutoSuggestionSyncController extends SyncControllerImpl
AutosuggestionSynchronizer suggestionSynchronizer = new AutosuggestionSynchronizer(schemaConfig,
syncControllerConfig.getNumInternalSyncWorkers(),
syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig);
+ syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig,
+ oxmEntityLookup, suggestionEntityLookup, filtersConfig);
suggestionSynchronizer.setAaiAdapter(aaiAdapter);
suggestionSynchronizer.setElasticSearchAdapter(esAdapter);
@@ -87,11 +91,11 @@ public class AutoSuggestionSyncController extends SyncControllerImpl
@Override
public void registerController() {
- if (syncControllerRegistry != null) {
- if (syncControllerConfig.isEnabled()) {
+ if ( syncControllerRegistry != null ) {
+ if ( syncControllerConfig.isEnabled()) {
syncControllerRegistry.registerSyncController(this);
}
}
-
+
}
}
diff --git a/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java b/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java
index 4ce7ce3..709842a 100644
--- a/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java
+++ b/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java
@@ -48,10 +48,11 @@ import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
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.NetworkTransaction;
-import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
import org.onap.aai.sparky.dal.rest.HttpMethod;
import org.onap.aai.sparky.logging.AaiUiMsgs;
+import org.onap.aai.sparky.search.filters.config.FiltersConfig;
import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
import org.onap.aai.sparky.sync.IndexSynchronizer;
import org.onap.aai.sparky.sync.SynchronizerConstants;
@@ -114,6 +115,9 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
protected ExecutorService esPutExecutor;
private Deque<RetrySuggestionEntitySyncContainer> retryQueue;
private Map<String, Integer> retryLimitTracker;
+ private OxmEntityLookup oxmEntityLookup;
+ private SuggestionEntityLookup suggestionEntityLookup;
+ private FiltersConfig filtersConfig;
/**
* Instantiates a new historical entity summarizer.
@@ -123,10 +127,14 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
*/
public AutosuggestionSynchronizer(ElasticSearchSchemaConfig schemaConfig, int internalSyncWorkers,
int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig) throws Exception {
+ NetworkStatisticsConfig esStatConfig, OxmEntityLookup oxmEntityLookup,
+ SuggestionEntityLookup suggestionEntityLookup, FiltersConfig filtersConfig) throws Exception {
+
super(LOG, "ASES-" + schemaConfig.getIndexName().toUpperCase(), internalSyncWorkers, aaiWorkers,
esWorkers, schemaConfig.getIndexName(), aaiStatConfig, esStatConfig);
-
+
+ this.oxmEntityLookup = oxmEntityLookup;
+ this.suggestionEntityLookup = suggestionEntityLookup;
this.allWorkEnumerated = false;
this.selflinks = new ConcurrentLinkedDeque<SelfLinkDescriptor>();
this.entityCounters = new ConcurrentHashMap<String, AtomicInteger>();
@@ -136,6 +144,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
this.contextMap = MDC.getCopyOfContextMap();
this.esPutExecutor = NodeUtils.createNamedExecutor("SUES-ES-PUT", 5, LOG);
this.syncDurationInMs = -1;
+ this.filtersConfig = filtersConfig;
}
/**
@@ -146,7 +155,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
private OperationState collectAllTheWork() {
final Map<String, String> contextMap = MDC.getCopyOfContextMap();
Map<String, SuggestionEntityDescriptor> descriptorMap =
- SuggestionEntityLookup.getInstance().getSuggestionSearchEntityDescriptors();
+ suggestionEntityLookup.getSuggestionSearchEntityDescriptors();
if (descriptorMap.isEmpty()) {
LOG.error(AaiUiMsgs.ERROR_LOADING_OXM_SUGGESTIBLE_ENTITIES);
@@ -281,7 +290,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
if (resourceType != null && resourceLink != null) {
- descriptor = OxmEntityLookup.getInstance().getEntityDescriptors().get(resourceType);
+ descriptor = oxmEntityLookup.getEntityDescriptors().get(resourceType);
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
@@ -312,8 +321,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
if (linkDescriptor.getSelfLink() != null && linkDescriptor.getEntityType() != null) {
- descriptor = OxmEntityLookup.getInstance().getEntityDescriptors()
- .get(linkDescriptor.getEntityType());
+ descriptor = oxmEntityLookup.getEntityDescriptors().get(linkDescriptor.getEntityType());
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, linkDescriptor.getEntityType());
@@ -353,19 +361,16 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
}
/*
- * Return a set of valid suggestion attributes for the provided entityName that are present in the
- * JSON
- *
+ * Return a set of valid suggestion attributes for the provided entityName
+ * that are present in the JSON
* @param node JSON node in which the attributes should be found
- *
* @param entityName Name of the entity
- *
* @return List of all valid suggestion attributes(key's)
*/
public List<String> getSuggestableAttrNamesFromReponse(JsonNode node, String entityName) {
List<String> suggestableAttr = new ArrayList<String>();
HashMap<String, String> desc =
- SuggestionEntityLookup.getInstance().getSuggestionSearchEntityOxmModel().get(entityName);
+ suggestionEntityLookup.getSuggestionSearchEntityOxmModel().get(entityName);
String attr = desc.get("suggestibleAttributes");
suggestableAttr = Arrays.asList(attr.split(","));
List<String> suggestableValue = new ArrayList<>();
@@ -400,18 +405,17 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
List<String> availableSuggestableAttrName =
getSuggestableAttrNamesFromReponse(entityNode, entityName);
-
+
ArrayList<ArrayList<String>> uniqueLists =
SuggestionsPermutation.getNonEmptyUniqueLists(availableSuggestableAttrName);
// Now we have a list of all possible permutations for the status that are
// defined for this entity type. Try inserting a document for every combination.
for (ArrayList<String> uniqueList : uniqueLists) {
- SuggestionSearchEntity sse =
- new SuggestionSearchEntity(SuggestionEntityLookup.getInstance());
+ SuggestionSearchEntity sse = new SuggestionSearchEntity(filtersConfig, suggestionEntityLookup);
sse.setSuggestableAttr(uniqueList);
sse.setFilterBasedPayloadFromResponse(entityNode, entityName, uniqueList);
- sse.setLink(ActiveInventoryConfig.extractResourcePath(txn.getLink()));
+ sse.setLink(ActiveInventoryAdapter.extractResourcePath(txn.getLink()));
populateSuggestionSearchEntityDocument(sse, jsonResult, txn);
// The unique id for the document will be created at derive fields
sse.deriveFields();
@@ -419,7 +423,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
if (sse.isSuggestableDoc()) {
String link = null;
try {
- link = getElasticFullUrl("/" + sse.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), sse.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY, exc.getLocalizedMessage());
}
@@ -500,7 +504,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
*/
String link = null;
try {
- link = getElasticFullUrl("/" + sse.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), sse.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
return;
@@ -537,8 +541,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
updateElasticTxn.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(
- new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
+ supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -607,7 +610,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
/*
* In this retry flow the se object has already derived its fields
*/
- link = getElasticFullUrl("/" + sus.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), sus.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_URI, exc.getLocalizedMessage());
}
diff --git a/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java b/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java
index c6fa69b..9be3342 100644
--- a/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java
+++ b/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizer.java
@@ -34,6 +34,7 @@ import org.onap.aai.restclient.client.OperationResult;
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.search.filters.config.FiltersConfig;
import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
import org.onap.aai.sparky.sync.IndexSynchronizer;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
@@ -56,10 +57,11 @@ public class VnfAliasSuggestionSynchronizer extends AbstractEntitySynchronizer
private boolean shouldPerformRetry;
private Map<String, String> contextMap;
protected ExecutorService esPutExecutor;
+ private FiltersConfig filtersConfig;
public VnfAliasSuggestionSynchronizer(ElasticSearchSchemaConfig schemaConfig,
int internalSyncWorkers, int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig) throws Exception {
+ NetworkStatisticsConfig esStatConfig, FiltersConfig filtersConfig) throws Exception {
super(LOG, "VASS-" + schemaConfig.getIndexName().toUpperCase(), internalSyncWorkers, aaiWorkers,
esWorkers, schemaConfig.getIndexName(), aaiStatConfig, esStatConfig);
@@ -68,6 +70,7 @@ public class VnfAliasSuggestionSynchronizer extends AbstractEntitySynchronizer
this.synchronizerName = "VNFs Alias Suggestion Synchronizer";
this.contextMap = MDC.getCopyOfContextMap();
this.esPutExecutor = NodeUtils.createNamedExecutor("ASS-ES-PUT", 2, LOG);
+ this.filtersConfig = filtersConfig;
}
@Override
@@ -111,18 +114,18 @@ public class VnfAliasSuggestionSynchronizer extends AbstractEntitySynchronizer
private void syncEntity() {
String txnId = NodeUtils.getRandomTxnId();
MdcContext.initialize(txnId, synchronizerName, "", "Sync", "");
-
- AggregationSuggestionEntity syncEntity = new AggregationSuggestionEntity();
+
+ AggregationSuggestionEntity syncEntity = new AggregationSuggestionEntity(filtersConfig);
syncEntity.deriveFields();
syncEntity.initializeFilters();
String link = null;
try {
- link = getElasticFullUrl("/" + syncEntity.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), syncEntity.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
}
-
+
try {
String jsonPayload = null;
jsonPayload = syncEntity.getAsJson();
@@ -134,8 +137,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 PerformElasticSearchPut(jsonPayload, elasticPutTxn,
+ elasticSearchAdapter, contextMap), esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
diff --git a/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java b/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java
index 3376eed..b558718 100644
--- a/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java
+++ b/src/main/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSyncController.java
@@ -24,6 +24,7 @@ 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.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;
@@ -39,14 +40,14 @@ import org.onap.aai.sparky.sync.config.SyncControllerConfig;
public class VnfAliasSyncController extends SyncControllerImpl implements SyncControllerRegistrar {
private SyncControllerRegistry syncControllerRegistry;
-
+
public VnfAliasSyncController(SyncControllerConfig syncControllerConfig,
ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
- NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig)
- throws Exception {
+ NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
+ FiltersConfig filtersConfig) throws Exception {
super(syncControllerConfig);
-
+
// final String controllerName = "VNFs Alias Suggestion Synchronizer";
IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(esAdapter, schemaConfig,
@@ -57,7 +58,7 @@ public class VnfAliasSyncController extends SyncControllerImpl implements SyncCo
VnfAliasSuggestionSynchronizer synchronizer = new VnfAliasSuggestionSynchronizer(schemaConfig,
syncControllerConfig.getNumInternalSyncWorkers(),
syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig);
+ syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig, filtersConfig);
synchronizer.setAaiAdapter(aaiAdapter);
synchronizer.setElasticSearchAdapter(esAdapter);
@@ -82,14 +83,14 @@ public class VnfAliasSyncController extends SyncControllerImpl implements SyncCo
@Override
public void registerController() {
-
- if (syncControllerRegistry != null) {
- if (syncControllerConfig.isEnabled()) {
+
+ if ( syncControllerRegistry != null ) {
+ if ( syncControllerConfig.isEnabled()) {
syncControllerRegistry.registerSyncController(this);
}
}
-
+
}
-
-
+
+
}
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReference.java b/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReference.java
index 1df9296..8754152 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReference.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReference.java
@@ -65,9 +65,7 @@ public class CrossEntityReference {
referenceAttributes.add(additionalAttribute);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceDescriptor.java b/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceDescriptor.java
index f0e6d4e..bd636f5 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceDescriptor.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceDescriptor.java
@@ -32,7 +32,7 @@ public class CrossEntityReferenceDescriptor extends OxmEntityDescriptor {
public void setCrossEntityReference(CrossEntityReference crossEntityReference) {
this.crossEntityReference = crossEntityReference;
}
-
+
/**
* Checks for cross entity references.
*
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceLookup.java b/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceLookup.java
index 81fe943..a0e0552 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceLookup.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceLookup.java
@@ -35,36 +35,15 @@ import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
public class CrossEntityReferenceLookup implements OxmModelProcessor {
- // TODO: kill singleton collaborator pattern
- private static CrossEntityReferenceLookup instance;
-
private Map<String, HashMap<String, String>> crossReferenceEntityOxmModel;
private Map<String, CrossEntityReferenceDescriptor> crossReferenceEntityDescriptors;
- private CrossEntityReferenceLookup() {
+ public CrossEntityReferenceLookup() {
crossReferenceEntityOxmModel = new LinkedHashMap<String, HashMap<String, String>>();
crossReferenceEntityDescriptors = new HashMap<String, CrossEntityReferenceDescriptor>();
}
- public synchronized static CrossEntityReferenceLookup getInstance() {
-
- /*
- * I hate this method and I want it to go away. The singleton pattern is transitory, I want this
- * class to be wired via a bean reference instead. But from the starting point, it would require
- * fixing all the classes across the code base up front and I don't want this task to expand
- * beyond just refactoring the OxmModelLoader. For now I'll keep the singleton pattern, but I
- * really want to get rid of it once we are properly spring wired.
- */
-
- if (instance == null) {
- instance = new CrossEntityReferenceLookup();
- }
-
- return instance;
- }
-
-
@Override
public void processOxmModel(DynamicJAXBContext jaxbContext) {
@@ -85,7 +64,7 @@ public class CrossEntityReferenceLookup implements OxmModelProcessor {
}
String entityName = desc.getDefaultRootElement();
-
+
// add entityName
oxmProperties.put("entityName", entityName);
@@ -104,7 +83,7 @@ public class CrossEntityReferenceLookup implements OxmModelProcessor {
}
}
-
+
for (Entry<String, HashMap<String, String>> crossRefModel : crossReferenceEntityOxmModel
.entrySet()) {
HashMap<String, String> attribute = crossRefModel.getValue();
@@ -148,7 +127,8 @@ public class CrossEntityReferenceLookup implements OxmModelProcessor {
Map<String, CrossEntityReferenceDescriptor> crossReferenceEntityDescriptors) {
this.crossReferenceEntityDescriptors = crossReferenceEntityDescriptors;
}
+
+
-
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/GeoEntityLookup.java b/src/main/java/org/onap/aai/sparky/config/oxm/GeoEntityLookup.java
index f8b1ceb..162a32e 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/GeoEntityLookup.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/GeoEntityLookup.java
@@ -35,35 +35,15 @@ import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
public class GeoEntityLookup implements OxmModelProcessor {
- // TODO: kill singleton collaborator pattern
- private static GeoEntityLookup instance;
-
private Map<String, HashMap<String, String>> geoEntityOxmModel;
private Map<String, GeoOxmEntityDescriptor> geoEntityDescriptors;
- private GeoEntityLookup() {
+ public GeoEntityLookup() {
geoEntityOxmModel = new LinkedHashMap<String, HashMap<String, String>>();
geoEntityDescriptors = new HashMap<String, GeoOxmEntityDescriptor>();
}
- public synchronized static GeoEntityLookup getInstance() {
-
- /*
- * I hate this method and I want it to go away. The singleton pattern is transitory, I want this
- * class to be wired via a bean reference instead. But from the starting point, it would require
- * fixing all the classes across the code base up front and I don't want this task to expand
- * beyond just refactoring the OxmModelLoader. For now I'll keep the singleton pattern, but I
- * really want to get rid of it once we are properly spring wired.
- */
-
- if (instance == null) {
- instance = new GeoEntityLookup();
- }
-
- return instance;
- }
-
public Map<String, HashMap<String, String>> getGeoEntityOxmModel() {
return geoEntityOxmModel;
}
@@ -82,7 +62,7 @@ public class GeoEntityLookup implements OxmModelProcessor {
@Override
public void processOxmModel(DynamicJAXBContext jaxbContext) {
-
+
@SuppressWarnings("rawtypes")
List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/GeoOxmEntityDescriptor.java b/src/main/java/org/onap/aai/sparky/config/oxm/GeoOxmEntityDescriptor.java
index 595c81a..98636dd 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/GeoOxmEntityDescriptor.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/GeoOxmEntityDescriptor.java
@@ -43,7 +43,7 @@ public class GeoOxmEntityDescriptor extends OxmEntityDescriptor {
public void setGeoLongName(String geoLongName) {
this.geoLongName = geoLongName;
}
-
+
/**
* Checks for geo entity.
*
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/OxmEntityLookup.java b/src/main/java/org/onap/aai/sparky/config/oxm/OxmEntityLookup.java
index 168a4b1..ba8091b 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/OxmEntityLookup.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/OxmEntityLookup.java
@@ -35,9 +35,6 @@ import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
public class OxmEntityLookup implements OxmModelProcessor {
- // TODO: kill singleton collaborator pattern
- private static OxmEntityLookup instance;
-
private Map<String, HashMap<String, String>> oxmModel;
private Map<String, DynamicType> entityTypeLookup;
@@ -45,30 +42,12 @@ public class OxmEntityLookup implements OxmModelProcessor {
private Map<String, OxmEntityDescriptor> entityDescriptors;
- private OxmEntityLookup() {
+ public OxmEntityLookup() {
oxmModel = new LinkedHashMap<String, HashMap<String, String>>();
entityTypeLookup = new LinkedHashMap<String, DynamicType>();
entityDescriptors = new HashMap<String, OxmEntityDescriptor>();
}
- public synchronized static OxmEntityLookup getInstance() {
-
- /*
- * I hate this method and I want it to go away. The singleton pattern is transitory, I want this
- * class to be wired via a bean reference instead. But from the starting point, it would require
- * fixing all the classes across the code base up front and I don't want this task to expand
- * beyond just refactoring the OxmModelLoader. For now I'll keep the singleton pattern, but I
- * really want to get rid of it once we are properly spring wired.
- */
-
- if (instance == null) {
- instance = new OxmEntityLookup();
- }
-
- return instance;
- }
-
-
@Override
public void processOxmModel(DynamicJAXBContext jaxbContext) {
@@ -141,9 +120,9 @@ public class OxmEntityLookup implements OxmModelProcessor {
public void setEntityDescriptors(Map<String, OxmEntityDescriptor> entityDescriptors) {
this.entityDescriptors = entityDescriptors;
}
-
+
public void addEntityDescriptor(String type, OxmEntityDescriptor descriptor) {
- if (this.entityDescriptors != null) {
+ if ( this.entityDescriptors != null ) {
this.entityDescriptors.put(type, descriptor);
}
}
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java b/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
index b953917..110c80d 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
@@ -42,9 +42,9 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
public class OxmModelLoader {
-
+
private static final Logger LOG = LoggerFactory.getInstance().getLogger(OxmModelLoader.class);
-
+
/*
* The intent of this parameter is to be able to programmatically over-ride the latest AAI schema
* version discovered from the aai-schema jar file. This property is optional, but if set on the
@@ -57,18 +57,18 @@ public class OxmModelLoader {
protected int oxmApiVersionOverride;
protected Set<OxmModelProcessor> processors;
private int latestVersionNum = 0;
-
+
private final static Pattern p = Pattern.compile("aai_oxm_(v)(.*).xml");
-
+
public OxmModelLoader() {
this(-1, new HashSet<OxmModelProcessor>());
}
-
- public OxmModelLoader(int apiVersionOverride, Set<OxmModelProcessor> oxmModelProcessors) {
+
+ public OxmModelLoader(int apiVersionOverride,Set<OxmModelProcessor> oxmModelProcessors) {
this.oxmApiVersionOverride = apiVersionOverride;
this.processors = oxmModelProcessors;
}
-
+
protected synchronized Map<Integer, InputStream> getStreamHandlesForOxmFromResource() {
Map<Integer, InputStream> listOfOxmFiles = new HashMap<Integer, InputStream>();
ClassLoader oxmClassLoader = OxmModelLoader.class.getClassLoader();
@@ -91,16 +91,16 @@ public class OxmModelLoader {
try {
listOfOxmFiles.put(new Integer(m.group(2)), resource.getInputStream());
} catch (Exception e) {
- LOG.error(AaiUiMsgs.OXM_LOADING_ERROR, resource.getFilename(), e.getMessage());
+ LOG.error(AaiUiMsgs.OXM_LOADING_ERROR,
+ resource.getFilename(), e.getMessage());
}
}
}
return listOfOxmFiles;
}
-
+
/**
* Load an oxm model.
- *
* @param inputStream file handle for oxm
*/
protected void loadModel(InputStream inputStream) {
@@ -118,14 +118,14 @@ public class OxmModelLoader {
LOG.error(AaiUiMsgs.OXM_PARSE_ERROR_VERBOSE, "OXM v" + latestVersionNum, exc.getMessage());
}
}
-
+
/**
* Load the latest oxm model.
*/
public synchronized void loadLatestOxmModel() {
LOG.info(AaiUiMsgs.INITIALIZE_OXM_MODEL_LOADER);
-
+
// find handles for available oxm models
final Map<Integer, InputStream> listOfOxmStreams = getStreamHandlesForOxmFromResource();
if (listOfOxmStreams.isEmpty()) {
@@ -153,7 +153,7 @@ public class OxmModelLoader {
loadModel(stream);
}
-
+
public int getLatestVersionNum() {
return latestVersionNum;
}
@@ -161,7 +161,7 @@ public class OxmModelLoader {
public void setLatestVersionNum(int latestVersionNum) {
this.latestVersionNum = latestVersionNum;
}
-
+
/**
* Parses the oxm context.
*
@@ -173,12 +173,21 @@ public class OxmModelLoader {
for (OxmModelProcessor processor : processors) {
- processor.processOxmModel(oxmContext);
+ try {
+
+ processor.processOxmModel(oxmContext);
+
+ } catch (Exception exc) {
+
+ LOG.warn(AaiUiMsgs.WARN_GENERIC,
+ "OxmModelProcessor experienced an error. Error: " + exc.getMessage());
+
+ }
}
}
}
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelProcessor.java b/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelProcessor.java
index b8e7c6f..320bef7 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelProcessor.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelProcessor.java
@@ -25,7 +25,7 @@ package org.onap.aai.sparky.config.oxm;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
public interface OxmModelProcessor {
-
+
public void processOxmModel(DynamicJAXBContext jaxbContext);
}
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/SearchableEntityLookup.java b/src/main/java/org/onap/aai/sparky/config/oxm/SearchableEntityLookup.java
index d8a27ac..288ce8e 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/SearchableEntityLookup.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/SearchableEntityLookup.java
@@ -35,38 +35,17 @@ import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
public class SearchableEntityLookup implements OxmModelProcessor {
- // TODO: kill singleton collaborator pattern
- private static SearchableEntityLookup instance;
-
private Map<String, HashMap<String, String>> searchableOxmModel;
private Map<String, SearchableOxmEntityDescriptor> searchableEntityDescriptors;
- private SearchableEntityLookup() {
+ public SearchableEntityLookup() {
searchableOxmModel = new LinkedHashMap<String, HashMap<String, String>>();
searchableEntityDescriptors = new HashMap<String, SearchableOxmEntityDescriptor>();
}
- public synchronized static SearchableEntityLookup getInstance() {
-
- /*
- * I hate this method and I want it to go away. The singleton pattern is transitory, I want this
- * class to be wired via a bean reference instead. But from the starting point, it would require
- * fixing all the classes across the code base up front and I don't want this task to expand
- * beyond just refactoring the OxmModelLoader. For now I'll keep the singleton pattern, but I
- * really want to get rid of it once we are properly spring wired.
- */
-
- if (instance == null) {
- instance = new SearchableEntityLookup();
- }
-
- return instance;
- }
-
-
@Override
public void processOxmModel(DynamicJAXBContext jaxbContext) {
-
+
@SuppressWarnings("rawtypes")
List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
@@ -102,7 +81,7 @@ public class SearchableEntityLookup implements OxmModelProcessor {
if (oxmProperties.containsKey("searchableAttributes")) {
searchableOxmModel.put(entityName, oxmProperties);
}
-
+
}
for (Entry<String, HashMap<String, String>> searchableModel : searchableOxmModel.entrySet()) {
diff --git a/src/main/java/org/onap/aai/sparky/config/oxm/SuggestionEntityLookup.java b/src/main/java/org/onap/aai/sparky/config/oxm/SuggestionEntityLookup.java
index 758ae60..86262b2 100644
--- a/src/main/java/org/onap/aai/sparky/config/oxm/SuggestionEntityLookup.java
+++ b/src/main/java/org/onap/aai/sparky/config/oxm/SuggestionEntityLookup.java
@@ -35,39 +35,21 @@ import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.internal.oxm.mappings.Descriptor;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.eclipse.persistence.mappings.DatabaseMapping;
+import org.onap.aai.sparky.search.filters.config.FiltersConfig;
import org.onap.aai.sparky.sync.entity.SuggestionSearchEntity;
public class SuggestionEntityLookup implements OxmModelProcessor {
- // TODO: kill singleton collaborator pattern
- private static SuggestionEntityLookup instance;
-
private Map<String, HashMap<String, String>> suggestionSearchEntityOxmModel;
private Map<String, SuggestionEntityDescriptor> suggestionSearchEntityDescriptors;
-
- private SuggestionEntityLookup() {
+ private FiltersConfig filtersConfig;
+
+ public SuggestionEntityLookup(FiltersConfig filtersConfig) {
suggestionSearchEntityOxmModel = new LinkedHashMap<String, HashMap<String, String>>();
suggestionSearchEntityDescriptors = new HashMap<String, SuggestionEntityDescriptor>();
+ this.filtersConfig = filtersConfig;
}
-
- public synchronized static SuggestionEntityLookup getInstance() {
-
- /*
- * I hate this method and I want it to go away. The singleton pattern is transitory, I want this
- * class to be wired via a bean reference instead. But from the starting point, it would require
- * fixing all the classes across the code base up front and I don't want this task to expand
- * beyond just refactoring the OxmModelLoader. For now I'll keep the singleton pattern, but I
- * really want to get rid of it once we are properly spring wired.
- */
-
- if (instance == null) {
- instance = new SuggestionEntityLookup();
- }
-
- return instance;
- }
-
-
+
@Override
public void processOxmModel(DynamicJAXBContext jaxbContext) {
@@ -129,7 +111,7 @@ public class SuggestionEntityLookup implements OxmModelProcessor {
}
}
}
-
+
if (!listOfSuggestableAttributes.isEmpty()) {
oxmProperties.put("suggestibleAttributes",
String.join(",", listOfSuggestableAttributes));
@@ -150,7 +132,7 @@ public class SuggestionEntityLookup implements OxmModelProcessor {
HashMap<String, String> attribute = suggestionEntityModel.getValue();
String entityName = attribute.get("entityName");
- SuggestionSearchEntity suggestionSearchEntity = new SuggestionSearchEntity(this);
+ SuggestionSearchEntity suggestionSearchEntity = new SuggestionSearchEntity(filtersConfig, this);
suggestionSearchEntity.setEntityType(entityName);
if (attribute.get("suggestionAliases") != null) {
@@ -174,6 +156,7 @@ public class SuggestionEntityLookup implements OxmModelProcessor {
suggestionSearchEntityDescriptors.put(entityName, entity);
}
+
}
public Map<String, HashMap<String, String>> getSuggestionSearchEntityOxmModel() {
@@ -193,5 +176,5 @@ public class SuggestionEntityLookup implements OxmModelProcessor {
Map<String, SuggestionEntityDescriptor> suggestionSearchEntityDescriptors) {
this.suggestionSearchEntityDescriptors = suggestionSearchEntityDescriptors;
}
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java b/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java
index 39ee8c5..c8cef66 100644
--- a/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java
+++ b/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java
@@ -47,9 +47,8 @@ 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.ActiveInventoryAdapter;
import org.onap.aai.sparky.dal.NetworkTransaction;
-import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
-import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
import org.onap.aai.sparky.dal.rest.HttpMethod;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
@@ -118,7 +117,10 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
private Map<String, Integer> retryLimitTracker;
private boolean isAllWorkEnumerated;
protected ExecutorService esPutExecutor;
-
+ private CrossEntityReferenceLookup crossEntityReferenceLookup;
+ private OxmEntityLookup oxmEntityLookup;
+ private SearchableEntityLookup searchableEntityLookup;
+
/**
* Instantiates a new cross entity reference synchronizer.
@@ -128,9 +130,13 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
*/
public CrossEntityReferenceSynchronizer(ElasticSearchSchemaConfig schemaConfig,
int internalSyncWorkers, int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig) throws Exception {
+ NetworkStatisticsConfig esStatConfig, CrossEntityReferenceLookup crossEntityReferenceLookup,
+ OxmEntityLookup oxmEntityLookup, SearchableEntityLookup searchableEntityLookup) throws Exception {
super(LOG, "CERS", internalSyncWorkers, aaiWorkers, esWorkers, schemaConfig.getIndexName(),
aaiStatConfig, esStatConfig);
+ this.crossEntityReferenceLookup = crossEntityReferenceLookup;
+ this.oxmEntityLookup = oxmEntityLookup;
+ this.searchableEntityLookup = searchableEntityLookup;
this.selflinks = new ConcurrentLinkedDeque<SelfLinkDescriptor>();
this.retryQueue = new ConcurrentLinkedDeque<RetryCrossEntitySyncContainer>();
this.retryLimitTracker = new ConcurrentHashMap<String, Integer>();
@@ -138,24 +144,22 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
this.isAllWorkEnumerated = false;
this.esPutExecutor = NodeUtils.createNamedExecutor("CERS-ES-PUT", 5, LOG);
this.aaiEntityStats.intializeEntityCounters(
- CrossEntityReferenceLookup.getInstance().getCrossReferenceEntityDescriptors().keySet());
+ crossEntityReferenceLookup.getCrossReferenceEntityDescriptors().keySet());
this.esEntityStats.intializeEntityCounters(
- CrossEntityReferenceLookup.getInstance().getCrossReferenceEntityDescriptors().keySet());
+ crossEntityReferenceLookup.getCrossReferenceEntityDescriptors().keySet());
this.syncDurationInMs = -1;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#doSync()
*/
@Override
public OperationState doSync() {
this.syncDurationInMs = -1;
- String txnID = NodeUtils.getRandomTxnId();
+ String txnID = NodeUtils.getRandomTxnId();
MdcContext.initialize(txnID, "CrossEntitySynchronizer", "", "Sync", "");
-
+
resetCounters();
syncStartedTimeStampInMs = System.currentTimeMillis();
launchSyncFlow();
@@ -171,9 +175,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
return SynchronizerState.IDLE;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
*/
@Override
@@ -182,9 +184,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
return getStatReport(syncDurationInMs, showFinalReport);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#shutdown()
*/
@Override
@@ -209,9 +209,9 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
* @return the operation state
*/
private OperationState launchSyncFlow() {
- final Map<String, String> contextMap = MDC.getCopyOfContextMap();
+ final Map<String,String> contextMap = MDC.getCopyOfContextMap();
Map<String, CrossEntityReferenceDescriptor> descriptorMap =
- CrossEntityReferenceLookup.getInstance().getCrossReferenceEntityDescriptors();
+ crossEntityReferenceLookup.getCrossReferenceEntityDescriptors();
if (descriptorMap.isEmpty()) {
LOG.error(AaiUiMsgs.ERROR_LOADING_OXM);
@@ -236,7 +236,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
@Override
public Void get() {
- MDC.setContextMap(contextMap);
+ MDC.setContextMap(contextMap);
OperationResult typeLinksResult = null;
try {
typeLinksResult = aaiAdapter.getSelfLinksByEntityType(key);
@@ -300,7 +300,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
if (linkDescriptor.getSelfLink() != null && linkDescriptor.getEntityType() != null) {
- descriptor = CrossEntityReferenceLookup.getInstance().getCrossReferenceEntityDescriptors()
+ descriptor = crossEntityReferenceLookup.getCrossReferenceEntityDescriptors()
.get(linkDescriptor.getEntityType());
if (descriptor == null) {
@@ -363,8 +363,6 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
JsonNode resultData = rootNode.get("result-data");
ArrayNode resultDataArrayNode = null;
- CrossEntityReferenceLookup cerLookup = CrossEntityReferenceLookup.getInstance();
-
if (resultData.isArray()) {
resultDataArrayNode = (ArrayNode) resultData;
@@ -380,7 +378,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
CrossEntityReferenceDescriptor descriptor = null;
if (resourceType != null && resourceLink != null) {
- descriptor = cerLookup.getCrossReferenceEntityDescriptors().get(resourceType);
+ descriptor = crossEntityReferenceLookup.getCrossReferenceEntityDescriptors().get(resourceType);
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
@@ -388,8 +386,8 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
continue;
}
if (descriptor.hasCrossEntityReferences()) {
- selflinks.add(new SelfLinkDescriptor(resourceLink,
- SynchronizerConstants.DEPTH_ALL_MODIFIER, resourceType));
+ selflinks.add(new SelfLinkDescriptor(
+ resourceLink,SynchronizerConstants.DEPTH_ALL_MODIFIER, resourceType));
}
}
}
@@ -397,60 +395,60 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
}
}
-
-
+
+
/**
- * By providing the entity type and a json node for the entity, determine the primary key name(s)
- * + primary key value(s) sufficient to build an entity query string of the following format:
+ * By providing the entity type and a json node for the entity, determine the
+ * primary key name(s) + primary key value(s) sufficient to build an entity query string
+ * of the following format:
*
- * <entityType>.<primaryKeyNames>:<primaryKeyValues>
+ * <entityType>.<primaryKeyNames>:<primaryKeyValues>
*
* @return - a composite string in the above format or null
*/
private String determineEntityQueryString(String entityType, JsonNode entityJsonNode) {
-
+
OxmEntityDescriptor entityDescriptor =
- OxmEntityLookup.getInstance().getEntityDescriptors().get(entityType);
-
+ oxmEntityLookup.getEntityDescriptors().get(entityType);
+
String queryString = null;
-
- if (entityDescriptor != null) {
+
+ if ( entityDescriptor != null ) {
final List<String> primaryKeyNames = entityDescriptor.getPrimaryKeyAttributeNames();
final List<String> keyValues = new ArrayList<String>();
NodeUtils.extractFieldValuesFromObject(entityJsonNode, primaryKeyNames, keyValues);
- queryString = entityType + "." + NodeUtils.concatArray(primaryKeyNames, "/") + ":"
- + NodeUtils.concatArray(keyValues);
-
- }
+ queryString = entityType + "." + NodeUtils.concatArray(primaryKeyNames,"/") + ":" + NodeUtils.concatArray(keyValues);
+ }
+
return queryString;
-
+
}
-
+
/**
* Fetch document for upsert.
*
* @param txn the txn
*/
private void fetchDocumentForUpsert(NetworkTransaction txn) {
-
+
if (!txn.getOperationResult().wasSuccessful()) {
LOG.error(AaiUiMsgs.SELF_LINK_GET, txn.getOperationResult().getResult());
return;
}
- CrossEntityReferenceDescriptor cerDescriptor = CrossEntityReferenceLookup.getInstance()
+ CrossEntityReferenceDescriptor cerDescriptor = crossEntityReferenceLookup
.getCrossReferenceEntityDescriptors().get(txn.getDescriptor().getEntityName());
-
+
if (cerDescriptor != null && cerDescriptor.hasCrossEntityReferences()) {
final String jsonResult = txn.getOperationResult().getResult();
-
+
if (jsonResult != null && jsonResult.length() > 0) {
-
+
/**
* Here's what we are going to do:
*
@@ -462,206 +460,185 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
* <li>Generate the id that will allow the elastic-search upsert to work.
* <li>Rinse and repeat.
*/
+
+ CrossEntityReference cerDefinition = cerDescriptor.getCrossEntityReference();
- CrossEntityReference cerDefinition = cerDescriptor.getCrossEntityReference();
-
- if (cerDefinition != null) {
- JsonNode convertedNode = null;
- try {
- convertedNode =
- NodeUtils.convertJsonStrToJsonNode(txn.getOperationResult().getResult());
-
- final String parentEntityQueryString =
- determineEntityQueryString(txn.getEntityType(), convertedNode);
-
- List<String> extractedParentEntityAttributeValues = new ArrayList<String>();
-
- NodeUtils.extractFieldValuesFromObject(convertedNode,
- cerDefinition.getReferenceAttributes(), extractedParentEntityAttributeValues);
-
- List<JsonNode> nestedTargetEntityInstances = new ArrayList<JsonNode>();
- NodeUtils.extractObjectsByKey(convertedNode, cerDefinition.getTargetEntityType(),
- nestedTargetEntityInstances);
-
- for (JsonNode targetEntityInstance : nestedTargetEntityInstances) {
-
- if (cerDescriptor != null) {
-
- String childEntityType = cerDefinition.getTargetEntityType();
-
- List<String> childPrimaryKeyNames = cerDescriptor.getPrimaryKeyAttributeNames();
-
- List<String> childKeyValues = new ArrayList<String>();
- NodeUtils.extractFieldValuesFromObject(targetEntityInstance, childPrimaryKeyNames,
- childKeyValues);
-
- String childEntityQueryKeyString =
- childEntityType + "." + NodeUtils.concatArray(childPrimaryKeyNames, "/") + ":"
- + NodeUtils.concatArray(childKeyValues);
-
- /**
- * Build generic-query to query child instance self-link from AAI
- */
- List<String> orderedQueryKeyParams = new ArrayList<String>();
-
- /**
- * At present, there is an issue with resolving the self-link using the
- * generic-query with nothing more than the service-instance identifier and the
- * service-subscription. There is another level of detail we don't have access to
- * unless we parse it out of the service-subscription self-link, which is a coupling
- * I would like to avoid. Fortunately, there is a workaround, but only for
- * service-instances, which is presently our only use-case for the
- * cross-entity-reference in R1707. Going forwards hopefully there will be other
- * ways to resolve a child self-link using parental embedded meta data that we don't
- * currently have.
- *
- * The work-around with the service-instance entity-type is that it's possible to
- * request the self-link using only the service-instance-id because of a historical
- * AAI functional query requirement that it be possible to query a service-instance
- * only by it's service-instance-id. This entity type is the only one in the system
- * that can be queried this way which makes it a very limited workaround, but good
- * enough for the current release.
- */
-
- if (SERVICE_INSTANCE.equals(childEntityType)) {
- orderedQueryKeyParams.clear();
- orderedQueryKeyParams.add(childEntityQueryKeyString);
- } else {
- orderedQueryKeyParams.add(parentEntityQueryString);
- orderedQueryKeyParams.add(childEntityQueryKeyString);
- }
-
- String genericQueryStr = null;
- try {
- genericQueryStr =
- aaiAdapter.getGenericQueryForSelfLink(childEntityType, orderedQueryKeyParams);
-
- if (genericQueryStr != null) {
- aaiWorkOnHand.incrementAndGet();
-
- OperationResult aaiQueryResult = aaiAdapter.queryActiveInventoryWithRetries(
- genericQueryStr, "application/json", aaiAdapter.getNumRequestRetries());
-
- aaiWorkOnHand.decrementAndGet();
-
- if (aaiQueryResult != null && aaiQueryResult.wasSuccessful()) {
-
- Collection<JsonNode> entityLinks = new ArrayList<JsonNode>();
- JsonNode genericQueryResult = null;
- try {
- genericQueryResult =
- NodeUtils.convertJsonStrToJsonNode(aaiQueryResult.getResult());
-
- if (genericQueryResult != null) {
-
- NodeUtils.extractObjectsByKey(genericQueryResult, "resource-link",
- entityLinks);
-
- String selfLink = null;
-
- if (entityLinks.size() != 1) {
- /**
- * an ambiguity exists where we can't reliably determine the self link,
- * this should be a permanent error
- */
- LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_SELFLINK_AMBIGUITY,
- String.valueOf(entityLinks.size()));
- } else {
- selfLink = ((JsonNode) entityLinks.toArray()[0]).asText();
-
- SearchableEntityLookup searchableEntityLookup =
- SearchableEntityLookup.getInstance();
-
- SearchableOxmEntityDescriptor searchableDescriptor =
- searchableEntityLookup.getSearchableEntityDescriptors()
- .get(txn.getEntityType());
-
- if (searchableDescriptor != null
- && searchableDescriptor.getSearchableAttributes().size() > 0) {
-
- IndexableCrossEntityReference icer =
- getPopulatedDocument(targetEntityInstance, cerDescriptor);
-
- for (String parentCrossEntityReferenceAttributeValue : extractedParentEntityAttributeValues) {
- icer.addCrossEntityReferenceValue(
- parentCrossEntityReferenceAttributeValue);
- }
-
- icer.setLink(ActiveInventoryConfig.extractResourcePath(selfLink));
-
- icer.deriveFields();
-
- String link = null;
- try {
- link = getElasticFullUrl("/" + icer.getId(), getIndexName());
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY,
- exc.getLocalizedMessage());
- }
+ if (cerDefinition != null) {
+ JsonNode convertedNode = null;
+ try {
+ convertedNode = NodeUtils.convertJsonStrToJsonNode(txn.getOperationResult().getResult());
+
+ final String parentEntityQueryString = determineEntityQueryString(txn.getEntityType(), convertedNode);
+
+ List<String> extractedParentEntityAttributeValues = new ArrayList<String>();
+
+ NodeUtils.extractFieldValuesFromObject(convertedNode,
+ cerDefinition.getReferenceAttributes(),
+ extractedParentEntityAttributeValues);
+
+ List<JsonNode> nestedTargetEntityInstances = new ArrayList<JsonNode>();
+ NodeUtils.extractObjectsByKey(convertedNode, cerDefinition.getTargetEntityType(),
+ nestedTargetEntityInstances);
+
+ for (JsonNode targetEntityInstance : nestedTargetEntityInstances) {
+
+ if (cerDescriptor != null) {
+
+ String childEntityType = cerDefinition.getTargetEntityType();
+
+ List<String> childPrimaryKeyNames = cerDescriptor.getPrimaryKeyAttributeNames();
+
+ List<String> childKeyValues = new ArrayList<String>();
+ NodeUtils.extractFieldValuesFromObject(targetEntityInstance, childPrimaryKeyNames, childKeyValues);
+
+ String childEntityQueryKeyString = childEntityType + "." + NodeUtils.concatArray(childPrimaryKeyNames,"/") + ":" + NodeUtils.concatArray(childKeyValues);
+
+ /**
+ * Build generic-query to query child instance self-link from AAI
+ */
+ List<String> orderedQueryKeyParams = new ArrayList<String>();
+
+ /**
+ * At present, there is an issue with resolving the self-link using the
+ * generic-query with nothing more than the service-instance identifier and the
+ * service-subscription. There is another level of detail we don't have access to
+ * unless we parse it out of the service-subscription self-link, which is a
+ * coupling I would like to avoid. Fortunately, there is a workaround, but only
+ * for service-instances, which is presently our only use-case for the
+ * cross-entity-reference in R1707. Going forwards hopefully there will be other
+ * ways to resolve a child self-link using parental embedded meta data that we
+ * don't currently have.
+ *
+ * The work-around with the service-instance entity-type is that it's possible to
+ * request the self-link using only the service-instance-id because of a
+ * historical AAI functional query requirement that it be possible to query a
+ * service-instance only by it's service-instance-id. This entity type is the only
+ * one in the system that can be queried this way which makes it a very limited
+ * workaround, but good enough for the current release.
+ */
+
+ if (SERVICE_INSTANCE.equals(childEntityType)) {
+ orderedQueryKeyParams.clear();
+ orderedQueryKeyParams.add(childEntityQueryKeyString);
+ } else {
+ orderedQueryKeyParams.add(parentEntityQueryString);
+ orderedQueryKeyParams.add(childEntityQueryKeyString);
+ }
- 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, icer);
- }
- });
+ String genericQueryStr = null;
+ try {
+ genericQueryStr = aaiAdapter.getGenericQueryForSelfLink(childEntityType, orderedQueryKeyParams);
+
+ if (genericQueryStr != null) {
+ aaiWorkOnHand.incrementAndGet();
+
+ OperationResult aaiQueryResult = aaiAdapter.queryActiveInventoryWithRetries(
+ genericQueryStr, "application/json",
+ aaiAdapter.getEndpointConfig().getNumRequestRetries());
+
+ aaiWorkOnHand.decrementAndGet();
+
+ if (aaiQueryResult!= null && aaiQueryResult.wasSuccessful()) {
+
+ Collection<JsonNode> entityLinks = new ArrayList<JsonNode>();
+ JsonNode genericQueryResult = null;
+ try {
+ genericQueryResult = NodeUtils.convertJsonStrToJsonNode(aaiQueryResult.getResult());
+
+ if ( genericQueryResult != null ) {
+
+ NodeUtils.extractObjectsByKey(genericQueryResult, "resource-link", entityLinks);
+
+ String selfLink = null;
+
+ if (entityLinks.size() != 1) {
+ /**
+ * an ambiguity exists where we can't reliably determine the self
+ * link, this should be a permanent error
+ */
+ LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_SELFLINK_AMBIGUITY, String.valueOf(entityLinks.size()));
+ } else {
+ selfLink = ((JsonNode) entityLinks.toArray()[0]).asText();
+
+ SearchableOxmEntityDescriptor searchableDescriptor = searchableEntityLookup.getSearchableEntityDescriptors().get( txn.getEntityType());
+
+ if (searchableDescriptor != null && searchableDescriptor.getSearchableAttributes().size() > 0) {
+
+ IndexableCrossEntityReference icer =
+ getPopulatedDocument(targetEntityInstance, cerDescriptor);
+
+ for (String parentCrossEntityReferenceAttributeValue : extractedParentEntityAttributeValues) {
+ icer.addCrossEntityReferenceValue(
+ parentCrossEntityReferenceAttributeValue);
+ }
+
+ icer.setLink(ActiveInventoryAdapter.extractResourcePath(selfLink));
+
+ icer.deriveFields();
+
+ String link = null;
+ try {
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), icer.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, icer);
+ }
+ });
+ }
}
}
+ } else {
+ LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_DURING_AAI_RESPONSE_CONVERSION);
}
- } else {
- LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_DURING_AAI_RESPONSE_CONVERSION);
- }
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.JSON_CONVERSION_ERROR, JsonNode.class.toString(),
- exc.getLocalizedMessage());
+ } catch (Exception exc) {
+ LOG.error(AaiUiMsgs.JSON_CONVERSION_ERROR, JsonNode.class.toString(), exc.getLocalizedMessage());
+ }
+
+ } else {
+ String message = "Entity sync failed because AAI query failed with error " + aaiQueryResult.getResult();
+ LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_QUERY_ERROR, message);
}
-
+
} else {
- String message = "Entity sync failed because AAI query failed with error "
- + aaiQueryResult.getResult();
+ String message = "Entity Sync failed because generic query str could not be determined.";
LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_QUERY_ERROR, message);
}
-
- } else {
- String message =
- "Entity Sync failed because generic query str could not be determined.";
+ } catch (Exception exc) {
+ String message = "Failed to sync entity because generation of generic query failed with error = " + exc.getMessage();
LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_QUERY_ERROR, message);
}
- } catch (Exception exc) {
- String message =
- "Failed to sync entity because generation of generic query failed with error = "
- + exc.getMessage();
- LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_QUERY_ERROR, message);
+
}
-
}
+
+ } catch (IOException ioe) {
+ LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, ioe.getMessage());
}
-
- } catch (IOException ioe) {
- LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, ioe.getMessage());
}
- }
-
- }
-
+
+ }
+
} else {
LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_DESCRIPTOR_NOT_FOUND, txn.getEntityType());
}
@@ -690,7 +667,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
*/
String link = null;
try {
- link = getElasticFullUrl("/" + icer.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), icer.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
return;
@@ -749,9 +726,8 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
if (wasEntryDiscovered) {
if (versionNumber != null && jsonPayload != null) {
- String requestPayload = elasticSearchAdapter.buildBulkImportOperationRequest(
- getIndexName(), ElasticSearchConfig.getConfig().getType(), icer.getId(),
- versionNumber, jsonPayload);
+ String requestPayload = elasticSearchAdapter.buildBulkImportOperationRequest(getIndexName(),
+ "default", icer.getId(), versionNumber, jsonPayload);
NetworkTransaction transactionTracker = new NetworkTransaction();
transactionTracker.setEntityType(esGetResult.getEntityType());
@@ -759,7 +735,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
transactionTracker.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchUpdate(ElasticSearchConfig.getConfig().getBulkUrl(),
+ supplyAsync(new PerformElasticSearchUpdate(elasticSearchAdapter.getBulkUrl(),
requestPayload, elasticSearchAdapter, transactionTracker), esPutExecutor)
.whenComplete((result, error) -> {
@@ -784,8 +760,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
updateElasticTxn.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(
- new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
+ supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -851,7 +826,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
try {
// In this retry flow the icer object has already
// derived its fields
- link = getElasticFullUrl("/" + icer.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), icer.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_URI, exc.getLocalizedMessage());
}
diff --git a/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java b/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java
index 40bb98c..a60c853 100644
--- a/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java
+++ b/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java
@@ -23,6 +23,7 @@
package org.onap.aai.sparky.dal;
import java.io.IOException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.ArrayList;
@@ -34,7 +35,6 @@ import java.util.NoSuchElementException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
-import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
@@ -45,12 +45,11 @@ 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.dal.exception.ElasticSearchOperationException;
+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;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.util.Encryptor;
import org.onap.aai.sparky.util.NodeUtils;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
-
-
/**
* The Class ActiveInventoryAdapter.
@@ -67,75 +66,33 @@ public class ActiveInventoryAdapter {
private static final String HTTP_SCHEME = "http";
private static final String HTTPS_SCHEME = "https";
-
+
private static final String TRANSACTION_ID_PREFIX = "txnId-";
private static final String UI_APP_NAME = "AAI-UI";
private OxmModelLoader oxmModelLoader;
private OxmEntityLookup oxmEntityLookup;
+ private RestEndpointConfig endpointConfig;
private RestClient restClient;
- private String activeInventoryIpAddress;
- private String activeInventoryServerPort;
- private int numRequestRetries;
- private String basicAuthUserName;
- private String basicAuthPassword;
- private RestAuthenticationMode restAuthenticationMode;
- private int connectTimeoutInMs;
- private int readTimeoutInMs;
-
/**
* Instantiates a new active inventory adapter.
+ * @throws RestClientConstructionException
*
*/
- public ActiveInventoryAdapter(OxmModelLoader oxmModelLoader,
- RestAuthenticationMode authenticationMode, boolean validateServerHostname,
- boolean validateServerCertChain, String certFileName, String certPassword,
- String truststoreFileName, int connectTimeoutInMs, int readTimeoutInMs)
- throws ElasticSearchOperationException, IOException {
-
- this.oxmModelLoader = oxmModelLoader;
- this.restAuthenticationMode = authenticationMode;
- this.connectTimeoutInMs = connectTimeoutInMs;
- this.readTimeoutInMs = readTimeoutInMs;
-
-
- Encryptor enc = new Encryptor();
- String certFileNameFullPath = TierSupportUiConstants.CONFIG_AUTH_LOCATION + certFileName;
- String decryptedCertPassword = enc.decryptValue(certPassword);
- String truststoreFileNameFullPath =
- TierSupportUiConstants.CONFIG_AUTH_LOCATION + truststoreFileName;
-
- this.restClient = new RestClient().authenticationMode(authenticationMode)
- .validateServerCertChain(validateServerCertChain)
- .validateServerHostname(validateServerHostname).clientCertFile(certFileNameFullPath)
- .clientCertPassword(decryptedCertPassword).trustStore(truststoreFileNameFullPath)
- .connectTimeoutMs(connectTimeoutInMs).readTimeoutMs(readTimeoutInMs);
-
- }
-
- public ActiveInventoryAdapter(OxmModelLoader oxmModelLoader,
- RestAuthenticationMode authenticationMode, boolean validateServerHostname,
- boolean validateServerCertChain, String basicAuthUserName, String basicAuthPassword,
- int connectTimeoutInMs, int readTimeoutInMs)
- throws ElasticSearchOperationException, IOException {
+ public ActiveInventoryAdapter(OxmModelLoader oxmModelLoader, OxmEntityLookup oxmEntityLookup,
+ RestEndpointConfig endpointConfig)
+ throws ElasticSearchOperationException, IOException, RestClientConstructionException {
this.oxmModelLoader = oxmModelLoader;
- this.restAuthenticationMode = authenticationMode;
-
- this.restClient = new RestClient().authenticationMode(authenticationMode)
- .validateServerCertChain(validateServerCertChain)
- .validateServerHostname(validateServerHostname).connectTimeoutMs(connectTimeoutInMs)
- .readTimeoutMs(readTimeoutInMs);
-
- this.basicAuthUserName = basicAuthUserName;
- this.basicAuthPassword = basicAuthPassword;
+ this.oxmEntityLookup = oxmEntityLookup;
+ this.endpointConfig = endpointConfig;
+ this.restClient = RestClientFactory.buildClient(endpointConfig);
}
-
protected Map<String, List<String>> getMessageHeaders() {
Map<String, List<String>> headers = new HashMap<String, List<String>>();
@@ -146,7 +103,7 @@ public class ActiveInventoryAdapter {
headers.putIfAbsent(HEADER_TRANS_ID, new ArrayList<String>());
headers.get(HEADER_TRANS_ID).add(TRANSACTION_ID_PREFIX + NodeUtils.getRandomTxnId());
- if (restAuthenticationMode == RestAuthenticationMode.SSL_BASIC) {
+ if (endpointConfig.getRestAuthenticationMode() == RestAuthenticationMode.SSL_BASIC) {
headers.putIfAbsent(HEADER_AUTHORIZATION, new ArrayList<String>());
headers.get(HEADER_AUTHORIZATION).add(getBasicAuthenticationCredentials());
@@ -157,20 +114,11 @@ public class ActiveInventoryAdapter {
}
protected String getBasicAuthenticationCredentials() {
- String usernameAndPassword = String.join(":", basicAuthUserName, basicAuthPassword);
+ String usernameAndPassword = String.join(":", endpointConfig.getBasicAuthUserName(),
+ endpointConfig.getBasicAuthPassword());
return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes());
}
- public int getNumRequestRetries() {
- return numRequestRetries;
- }
-
-
-
- public void setNumRequestRetries(int numRequestRetries) {
- this.numRequestRetries = numRequestRetries;
- }
-
public OxmEntityLookup getOxmEntityLookup() {
return oxmEntityLookup;
}
@@ -179,22 +127,6 @@ public class ActiveInventoryAdapter {
this.oxmEntityLookup = oxmEntityLookup;
}
- public String getActiveInventoryIpAddress() {
- return activeInventoryIpAddress;
- }
-
- public void setActiveInventoryIpAddress(String activeInventoryIpAddress) {
- this.activeInventoryIpAddress = activeInventoryIpAddress;
- }
-
- public String getActiveInventoryServerPort() {
- return activeInventoryServerPort;
- }
-
- public void setActiveInventoryServerPort(String activeInventoryServerPort) {
- this.activeInventoryServerPort = activeInventoryServerPort;
- }
-
protected String getResourceBasePath() {
String versionStr = null;
@@ -205,15 +137,18 @@ public class ActiveInventoryAdapter {
return "/aai/v" + versionStr;
}
-
- public int getConnectTimeoutInMs() {
- return this.connectTimeoutInMs;
- }
-
- public int getReadTimeoutInMs() {
- return this.readTimeoutInMs;
+
+ public static String extractResourcePath(String selflink) {
+ try {
+ return new URI(selflink).getRawPath();
+ } catch (URISyntaxException uriSyntaxException) {
+ LOG.error(AaiUiMsgs.ERROR_EXTRACTING_RESOURCE_PATH_FROM_LINK,
+ uriSyntaxException.getMessage());
+ return selflink;
+ }
}
+
/**
* Gets the full url.
*
@@ -223,8 +158,8 @@ public class ActiveInventoryAdapter {
*/
private String getFullUrl(String resourceUrl) throws Exception {
final String basePath = getResourceBasePath();
- return String.format("https://%s:%s%s%s", activeInventoryIpAddress, activeInventoryServerPort,
- basePath, resourceUrl);
+ return String.format("https://%s:%s%s%s", endpointConfig.getEndpointIpAddress(),
+ endpointConfig.getEndpointServerPort(), basePath, resourceUrl);
}
public String getGenericQueryForSelfLink(String startNodeType, List<String> queryParams)
@@ -272,7 +207,6 @@ public class ActiveInventoryAdapter {
link = getFullUrl("/search/nodes-query?search-node-type=" + entityType + "&filter="
+ primaryKeyStr + ":EXISTS");
-
return restClient.get(link, getMessageHeaders(), MediaType.APPLICATION_JSON_TYPE);
}
@@ -319,7 +253,8 @@ public class ActiveInventoryAdapter {
}
- return queryActiveInventoryWithRetries(link, "application/json", numRequestRetries);
+ return queryActiveInventoryWithRetries(link, "application/json",
+ endpointConfig.getNumRequestRetries());
}
@@ -364,6 +299,14 @@ public class ActiveInventoryAdapter {
}
+ public RestEndpointConfig getEndpointConfig() {
+ return endpointConfig;
+ }
+
+ public void setEndpointConfig(RestEndpointConfig endpointConfig) {
+ this.endpointConfig = endpointConfig;
+ }
+
public OperationResult queryActiveInventoryWithRetries(String url, String responseType,
int numRetries) {
@@ -413,14 +356,14 @@ public class ActiveInventoryAdapter {
return result;
}
-
+
public String repairSelfLink(String selfLink) {
return repairSelfLink(selfLink, null);
}
/**
- * This method adds a scheme, host and port (if missing) to the passed-in URI. If these parts of
- * the URI are already present, they will not be duplicated.
+ * This method adds a scheme, host and port (if missing) to the passed-in URI.
+ * If these parts of the URI are already present, they will not be duplicated.
*
* @param selflink The URI to repair
* @param queryParams The query parameters as a single string
@@ -431,10 +374,10 @@ public class ActiveInventoryAdapter {
return selflink;
}
- UriBuilder builder = UriBuilder.fromPath(selflink).host(activeInventoryIpAddress)
- .port(Integer.parseInt(activeInventoryServerPort));
+ UriBuilder builder = UriBuilder.fromPath(selflink).host(endpointConfig.getEndpointIpAddress())
+ .port(Integer.parseInt(endpointConfig.getEndpointServerPort()));
- switch (restAuthenticationMode) {
+ switch (endpointConfig.getRestAuthenticationMode()) {
case SSL_BASIC:
case SSL_CERT: {
@@ -447,13 +390,11 @@ public class ActiveInventoryAdapter {
}
}
- boolean includeQueryParams = ((null != queryParams) && (!"".equals(queryParams)));
+ boolean includeQueryParams = ( (null != queryParams) && (!"".equals(queryParams)) );
- /*
- * builder.build().toString() will encode special characters to hexadecimal pairs prefixed with
- * a '%' so we're adding the query parameters separately, in their UTF-8 representations, so
- * that characters such as '?', '&', etc. remain intact as needed by the synchronizer
- */
+ /* builder.build().toString() will encode special characters to hexadecimal pairs prefixed with a '%'
+ so we're adding the query parameters separately, in their UTF-8 representations, so that
+ characters such as '?', '&', etc. remain intact as needed by the synchronizer */
return (builder.build().toString() + (includeQueryParams ? queryParams : ""));
}
diff --git a/src/main/java/org/onap/aai/sparky/dal/ElasticSearchAdapter.java b/src/main/java/org/onap/aai/sparky/dal/ElasticSearchAdapter.java
index 1e2bb8d..e881aa4 100644
--- a/src/main/java/org/onap/aai/sparky/dal/ElasticSearchAdapter.java
+++ b/src/main/java/org/onap/aai/sparky/dal/ElasticSearchAdapter.java
@@ -31,30 +31,37 @@ import javax.ws.rs.core.MediaType;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.restclient.client.RestClient;
-import org.onap.aai.restclient.enums.RestAuthenticationMode;
+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(RestAuthenticationMode restAuthenticationMode, int connectTimeoutInMs,
- int readTimeoutInMs) {
+ public ElasticSearchAdapter(RestEndpointConfig endpointConfig) throws RestClientConstructionException {
- this.restClient = new RestClient().authenticationMode(restAuthenticationMode)
- .connectTimeoutMs(connectTimeoutInMs).readTimeoutMs(readTimeoutInMs);
+ 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
@@ -81,18 +88,17 @@ public class ElasticSearchAdapter {
public OperationResult doPatch(String url, String jsonPayload, MediaType acceptContentType) {
- Map<String, List<String>> headers = getMessageHeaders();
+ 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);
+
+ 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);
@@ -109,7 +115,7 @@ public class ElasticSearchAdapter {
return requestPayload.toString();
}
-
+
public OperationResult retrieveEntityById(String host, String port, String indexName,
String docType, String resourceUrl) {
String esUrl =
@@ -117,4 +123,33 @@ public class ElasticSearchAdapter {
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/src/main/java/org/onap/aai/sparky/dal/aai/ActiveInventoryDataProvider.java b/src/main/java/org/onap/aai/sparky/dal/aai/ActiveInventoryDataProvider.java
deleted file mode 100644
index 75e7a54..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/aai/ActiveInventoryDataProvider.java
+++ /dev/null
@@ -1,94 +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.dal.aai;
-
-import java.util.List;
-
-import org.onap.aai.sparky.dal.rest.OperationResult;
-import org.onap.aai.sparky.dal.rest.RestDataProvider;
-
-/**
- * The Interface ActiveInventoryDataProvider.
- */
-
-/*
- * TODO: DELETE ME
- */
-
-public interface ActiveInventoryDataProvider extends RestDataProvider {
-
- /**
- * Gets the self links by entity type.
- *
- * @param entityType the entity type
- * @return the self links by entity type
- * @throws Exception the exception
- */
- /*
- * This one will do the nodes-query and understand enough to make that happen
- */
- OperationResult getSelfLinksByEntityType(String entityType) throws Exception;
-
- /**
- * Gets the self link for entity.
- *
- * @param entityType the entity type
- * @param primaryKeyName the primary key name
- * @param primaryKeyValue the primary key value
- * @return the self link for entity
- * @throws Exception the exception
- */
- OperationResult getSelfLinkForEntity(String entityType, String primaryKeyName,
- String primaryKeyValue) throws Exception;
-
- /**
- * Query active inventory with retries.
- *
- * @param url the url
- * @param responseType the response type
- * @param numRetries the num retries
- * @return the operation result
- */
- OperationResult queryActiveInventoryWithRetries(String url, String responseType, int numRetries);
-
-
- /**
- * Determines the self-link for an entity with passed-in key-value pairs.
- *
- * @param startNodeType
- * @param keyParams
- * @return
- * @throws Exception
- */
- String getGenericQueryForSelfLink(String startNodeType, List<String> queryKeyParams)
- throws Exception;
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#shutdown()
- */
- @Override
- void shutdown();
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatistics.java b/src/main/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatistics.java
index 6ffebef..3998992 100644
--- a/src/main/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatistics.java
+++ b/src/main/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatistics.java
@@ -108,7 +108,8 @@ public class ActiveInventoryEntityStatistics {
*
* @param descriptors the descriptors
*/
- public void intializeEntityCounters(String... entityTypes) {
+ public void intializeEntityCounters(
+ String... entityTypes) {
if (entityTypes != null && entityTypes.length > 0) {
for (String entityType : entityTypes) {
@@ -116,17 +117,18 @@ public class ActiveInventoryEntityStatistics {
}
}
-
+
}
-
- public void intializeEntityCounters(Set<String> entityTypes) {
+
+ public void intializeEntityCounters(
+ Set<String> entityTypes) {
if (entityTypes != null && entityTypes.size() > 0) {
for (String entityType : entityTypes) {
activeInventoryEntityStatistics.put(entityType, createEntityOpStats());
}
}
-
+
}
@@ -268,7 +270,7 @@ public class ActiveInventoryEntityStatistics {
sb.append("\n ")
.append(String.format(
"%-30s TOTAL: %-12d FOUND: %-12d NO_PAYLOAD:"
- + " %-12d NOT_FOUND: %-12d NUM_RETRIES: %-12d ERROR: %-12d",
+ + " %-12d NOT_FOUND: %-12d NUM_RETRIES: %-12d ERROR: %-12d",
counterEntityKey, totalValue, foundValue, noPayloadValue, notFoundValue,
numRetriesValue, errorValue));
}
diff --git a/src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryConfig.java b/src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryConfig.java
deleted file mode 100644
index d311993..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryConfig.java
+++ /dev/null
@@ -1,121 +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.dal.aai.config;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Properties;
-
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.util.ConfigHelper;
-import org.onap.aai.sparky.util.Encryptor;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
-
-/**
- * The Class ActiveInventoryConfig.
- */
-public class ActiveInventoryConfig {
-
- public static final String CONFIG_FILE =
- TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "aai.properties";
- private static ActiveInventoryConfig instance;
-
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(ActiveInventoryConfig.class);
-
-
- public static ActiveInventoryConfig getConfig() throws Exception {
- if (instance == null) {
- instance = new ActiveInventoryConfig();
- }
-
- return instance;
- }
-
- private ActiveInventoryRestConfig aaiRestConfig;
- private ActiveInventorySslConfig aaiSslConfig;
-
- /**
- * Instantiates a new active inventory config.
- *
- * @throws Exception the exception
- */
- protected ActiveInventoryConfig() throws Exception {
-
- Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
- initialize(props);
- }
-
- public ActiveInventoryConfig(Properties props) throws Exception {
- initialize(props);
- }
-
- private void initialize(Properties props) {
- aaiRestConfig = new ActiveInventoryRestConfig(props);
- aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
- }
-
- public ActiveInventoryRestConfig getAaiRestConfig() {
- return aaiRestConfig;
- }
-
- public void setAaiRestConfig(ActiveInventoryRestConfig aaiRestConfig) {
- this.aaiRestConfig = aaiRestConfig;
- }
-
- public ActiveInventorySslConfig getAaiSslConfig() {
- return aaiSslConfig;
- }
-
- public void setAaiSslConfig(ActiveInventorySslConfig aaiSslConfig) {
- this.aaiSslConfig = aaiSslConfig;
- }
-
-
-
- public static String extractResourcePath(String selflink) {
- try {
- return new URI(selflink).getRawPath();
- } catch (URISyntaxException uriSyntaxException) {
- LOG.error(AaiUiMsgs.ERROR_EXTRACTING_RESOURCE_PATH_FROM_LINK,
- uriSyntaxException.getMessage());
- return selflink;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "ActiveInventoryConfig [aaiRestConfig=" + aaiRestConfig + ", aaiSslConfig="
- + aaiSslConfig + "]";
- }
-
-
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryRestConfig.java b/src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryRestConfig.java
deleted file mode 100644
index 617a74c..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryRestConfig.java
+++ /dev/null
@@ -1,173 +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.dal.aai.config;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
-import org.onap.aai.sparky.dal.aai.enums.RestAuthenticationMode;
-import org.onap.aai.sparky.util.ConfigHelper;
-
-/**
- * The Class ActiveInventoryRestConfig.
- */
-public class ActiveInventoryRestConfig {
-
- private String host;
-
- private String port;
-
- private int connectTimeoutInMs;
-
- private int readTimeoutInMs;
-
- private int numRequestRetries;
-
- private int numResolverWorkers;
-
- private List<String> shallowEntities;
-
- private RestAuthenticationMode authenticationMode;
-
- public List<String> getShallowEntities() {
- return shallowEntities;
- }
-
- /**
- * Instantiates a new active inventory rest config.
- *
- * @param props the props
- */
- public ActiveInventoryRestConfig(Properties props) {
-
- if (props == null || props.isEmpty()) {
- return;
- }
-
- Properties restProps = ConfigHelper.getConfigWithPrefix("aai.rest", props);
-
- host = restProps.getProperty("host", "localhost");
- port = restProps.getProperty("port", "8443");
- numRequestRetries = Integer.parseInt(restProps.getProperty("numRequestRetries", "5"));
- numResolverWorkers = Integer.parseInt(restProps.getProperty("numResolverWorkers", "15"));
-
- connectTimeoutInMs = Integer.parseInt(restProps.getProperty("connectTimeoutInMs", "5000"));
- readTimeoutInMs = Integer.parseInt(restProps.getProperty("readTimeoutInMs", "10000"));
-
- String shallowEntitiesProperty = restProps.getProperty("shallowEntities", "");
- shallowEntities = Arrays.asList(shallowEntitiesProperty.split(","));
-
- authenticationMode =
- RestAuthenticationMode.getRestAuthenticationMode(restProps.getProperty("authenticationMode",
- RestAuthenticationMode.SSL_CERT.getAuthenticationModeLabel()));
-
- /*
- * In any kind of error scenario, set the authentication mode to SSL_CERT as our default. This
- * is an arbitrary default, but was chosen based on the way this code worked before introduction
- * of the SSL Basic Auth settings.
- */
- if (authenticationMode == RestAuthenticationMode.UNKNOWN_MODE) {
- authenticationMode = RestAuthenticationMode.SSL_CERT;
- }
-
- }
-
- public RestAuthenticationMode getAuthenticationMode() {
- return authenticationMode;
- }
-
- public void setAuthenticationMode(RestAuthenticationMode authenticationMode) {
- this.authenticationMode = authenticationMode;
- }
-
-
- /**
- * Checks if is shallow entity.
- *
- * @param entityType the entity type
- * @return true, if is shallow entity
- */
- public boolean isShallowEntity(String entityType) {
- if (entityType == null) {
- return false;
- }
-
- for (String entity : shallowEntities) {
- if (entityType.equalsIgnoreCase(entity)) {
- return true;
- }
- }
-
- return false;
- }
-
- public int getNumResolverWorkers() {
- return numResolverWorkers;
- }
-
- public void setNumResolverWorkers(int numResolverWorkers) {
- this.numResolverWorkers = numResolverWorkers;
- }
-
- public String getHost() {
- return host;
- }
-
- public String getPort() {
- return port;
- }
-
- public void setHost(String host) {
- this.host = host;
- }
-
- public void setPort(String port) {
- this.port = port;
- }
-
- public int getConnectTimeoutInMs() {
- return connectTimeoutInMs;
- }
-
- public void setConnectTimeoutInMs(int connectTimeoutInMs) {
- this.connectTimeoutInMs = connectTimeoutInMs;
- }
-
- public int getReadTimeoutInMs() {
- return readTimeoutInMs;
- }
-
- public void setReadTimeoutInMs(int readTimeoutInMs) {
- this.readTimeoutInMs = readTimeoutInMs;
- }
-
- public int getNumRequestRetries() {
- return numRequestRetries;
- }
-
- public void setNumRequestRetries(int numRequestRetries) {
- this.numRequestRetries = numRequestRetries;
- }
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventorySslConfig.java b/src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventorySslConfig.java
deleted file mode 100644
index 75ce36a..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/aai/config/ActiveInventorySslConfig.java
+++ /dev/null
@@ -1,215 +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.dal.aai.config;
-
-import java.util.Properties;
-
-import org.eclipse.jetty.util.security.Password;
-import org.onap.aai.sparky.util.ConfigHelper;
-import org.onap.aai.sparky.util.Encryptor;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
-
-/**
- * The Class ActiveInventorySslConfig.
- */
-public class ActiveInventorySslConfig {
-
- private Encryptor encryptor;
-
- private boolean enableSslDebug;
- private boolean validateServerHostName;
- private boolean validateServerCertificateChain;
-
- private String keystoreType;
- private String keystoreFilename;
- private String keystorePassword;
- private String truststoreType;
- private String truststoreFilename;
-
- private String basicAuthUsername;
- private String basicAuthPassword;
-
- /**
- * Instantiates a new active inventory ssl config.
- *
- * @param props the props
- */
- public ActiveInventorySslConfig(Properties props, Encryptor encryptor) {
-
- if (props == null || props.isEmpty()) {
- return;
- }
-
- Properties sslProps = ConfigHelper.getConfigWithPrefix("aai.ssl", props);
-
- enableSslDebug = Boolean.parseBoolean(sslProps.getProperty("enableDebug", "false"));
- validateServerHostName =
- Boolean.parseBoolean(sslProps.getProperty("validateServerHostName", "false"));
- validateServerCertificateChain =
- Boolean.parseBoolean(sslProps.getProperty("validateServerCertificateChain", "false"));
-
- if (enableSslDebug) {
- System.setProperty("javax.net.debug", "ssl");
- } else {
- System.setProperty("javax.net.debug", "");
- }
-
- this.encryptor = encryptor;
-
-
- keystoreType = sslProps.getProperty("keystore.type", "pkcs12");
-
- keystoreFilename =
- TierSupportUiConstants.CONFIG_AUTH_LOCATION + sslProps.getProperty("keystore.filename");
- keystorePassword = encryptor.decryptValue(sslProps.getProperty("keystore.pass", ""));
- truststoreType = sslProps.getProperty("truststore.type", "jks");
-
- truststoreFilename =
- TierSupportUiConstants.CONFIG_AUTH_LOCATION + sslProps.getProperty("truststore.filename");
-
- basicAuthUsername = sslProps.getProperty("basicAuth.username");
- basicAuthPassword = decryptPassword(sslProps.getProperty("basicAuth.password"));
-
- }
-
- private String decryptPassword(String encryptedPassword) {
-
- try {
-
- if (encryptedPassword == null) {
- return null;
- }
-
- return Password.deobfuscate(encryptedPassword);
-
- } catch (Exception exc) {
-
- return encryptedPassword;
-
- }
-
- }
-
- public String getBasicAuthUsername() {
- return basicAuthUsername;
- }
-
- public void setBasicAuthUsername(String basicAuthUsername) {
- this.basicAuthUsername = basicAuthUsername;
- }
-
- public String getBasicAuthPassword() {
- return basicAuthPassword;
- }
-
- public void setBasicAuthPassword(String basicAuthPassword) {
- this.basicAuthPassword = basicAuthPassword;
- }
-
-
- public Encryptor getEncryptor() {
- return encryptor;
- }
-
- public void setEncryptor(Encryptor encryptor) {
- this.encryptor = encryptor;
- }
-
- public String getKeystoreType() {
- return keystoreType;
- }
-
- public void setKeystoreType(String keystoreType) {
- this.keystoreType = keystoreType;
- }
-
- public String getKeystoreFilename() {
- return keystoreFilename;
- }
-
- public void setKeystoreFilename(String keystoreFilename) {
- this.keystoreFilename = keystoreFilename;
- }
-
- public String getKeystorePassword() {
- return keystorePassword;
- }
-
- public void setKeystorePassword(String keystorePassword) {
- this.keystorePassword = keystorePassword;
- }
-
- public String getTruststoreType() {
- return truststoreType;
- }
-
- public void setTruststoreType(String truststoreType) {
- this.truststoreType = truststoreType;
- }
-
- public String getTruststoreFilename() {
- return truststoreFilename;
- }
-
- public void setTruststoreFilename(String truststoreFilename) {
- this.truststoreFilename = truststoreFilename;
- }
-
- public boolean isValidateServerHostName() {
- return validateServerHostName;
- }
-
- public void setValidateServerHostName(boolean validateServerHostName) {
- this.validateServerHostName = validateServerHostName;
- }
-
- public boolean isValidateServerCertificateChain() {
- return validateServerCertificateChain;
- }
-
- public void setValidateServerCertificateChain(boolean validateServerCertificateChain) {
- this.validateServerCertificateChain = validateServerCertificateChain;
- }
-
- public String getBasicAuthenticationCredentials() {
-
- String usernameAndPassword = getBasicAuthUsername() + ":" + getBasicAuthPassword();
- return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "ActiveInventorySslConfig [enableSslDebug=" + enableSslDebug
- + ", validateServerHostName=" + validateServerHostName + ", validateServerCertificateChain="
- + validateServerCertificateChain + ", keystoreType=" + keystoreType + ", keystoreFilename="
- + keystoreFilename + ", truststoreType=" + truststoreType + ", truststoreFilename="
- + truststoreFilename + "]";
- }
-
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/aai/enums/RestAuthenticationMode.java b/src/main/java/org/onap/aai/sparky/dal/aai/enums/RestAuthenticationMode.java
deleted file mode 100644
index 846fb2f..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/aai/enums/RestAuthenticationMode.java
+++ /dev/null
@@ -1,64 +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.dal.aai.enums;
-
-/**
- * Authentication Modes:
- * <li>HTTP_NOAUTH - intended to represent basic HTTP no authentication
- * <li>SSL_BASIC - HTTP/S with username/password
- * <li>SSL_CERT - HTTP/S with client cert
- */
-
-public enum RestAuthenticationMode {
- HTTP_NOAUTH("HTTP_NO_AUTH"), SSL_BASIC("SSL_BASIC"), SSL_CERT("SSL_CERT"), UNKNOWN_MODE(
- "UNKNOWN_MODE");
-
- private String authenticationModeLabel;
-
- private RestAuthenticationMode(String authModelLabel) {
- this.authenticationModeLabel = authModelLabel;
- }
-
- public String getAuthenticationModeLabel() {
- return authenticationModeLabel;
- }
-
- public static RestAuthenticationMode getRestAuthenticationMode(String authenticationMode) {
-
- RestAuthenticationMode mappedMode = RestAuthenticationMode.UNKNOWN_MODE;
-
- if (authenticationMode == null) {
- return mappedMode;
- }
-
- try {
- mappedMode = RestAuthenticationMode.valueOf(authenticationMode);
- } catch (Exception exc) {
- mappedMode = RestAuthenticationMode.UNKNOWN_MODE;
- }
-
- return mappedMode;
-
- }
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchDataProvider.java b/src/main/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchDataProvider.java
deleted file mode 100644
index 90075fe..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchDataProvider.java
+++ /dev/null
@@ -1,69 +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.dal.elasticsearch;
-
-import org.onap.aai.sparky.dal.rest.OperationResult;
-import org.onap.aai.sparky.dal.rest.RestDataProvider;
-
-/*
- * TODO: DELETE ME
- */
-
-/**
- * The Interface ElasticSearchDataProvider.
- */
-public interface ElasticSearchDataProvider extends RestDataProvider {
-
- /**
- * Builds the bulk import operation request.
- *
- * @param index the index
- * @param type the type
- * @param id the id
- * @param version the version
- * @param payload the payload
- * @return the string
- */
- String buildBulkImportOperationRequest(String index, String type, String id, String version,
- String payload);
-
- /**
- * Do bulk operation.
- *
- * @param url the url
- * @param payload the payload
- * @return the operation result
- */
- OperationResult doBulkOperation(String url, String payload);
-
- OperationResult retrieveEntityById(String entityId) throws Exception;
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#shutdown()
- */
- @Override
- void shutdown();
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatistics.java b/src/main/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatistics.java
index ba012bd..a848971 100644
--- a/src/main/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatistics.java
+++ b/src/main/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatistics.java
@@ -47,7 +47,7 @@ public class ElasticSearchEntityStatistics {
private static final String ERROR = "ERROR";
private Map<String, HashMap<String, AtomicInteger>> entityStatistics;
-
+
/**
* Creates the entity op stats.
*
@@ -104,7 +104,8 @@ public class ElasticSearchEntityStatistics {
*
* @param descriptors the descriptors
*/
- public void intializeEntityCounters(String... entityTypes) {
+ public void intializeEntityCounters(
+ String... entityTypes) {
if (entityTypes != null && entityTypes.length > 0) {
for (String entityType : entityTypes) {
@@ -112,17 +113,18 @@ public class ElasticSearchEntityStatistics {
}
}
-
+
}
-
- public void intializeEntityCounters(Set<String> entityTypes) {
+
+ public void intializeEntityCounters(
+ Set<String> entityTypes) {
if (entityTypes != null && entityTypes.size() > 0) {
for (String entityType : entityTypes) {
entityStatistics.put(entityType, createEntityOpStats());
}
}
-
+
}
/**
@@ -246,11 +248,12 @@ public class ElasticSearchEntityStatistics {
int deletedValue = (deleted == null) ? 0 : deleted.get();
int errorValue = (error == null) ? 0 : error.get();
- sb.append("\n ").append(String.format(
- "%-30s TOTAL: %-12d CREATED: %-12d MODIFIED:"
+ sb.append("\n ")
+ .append(String.format(
+ "%-30s TOTAL: %-12d CREATED: %-12d MODIFIED:"
+ " %-12d OTHER_2XX: %-12d DELETED: %-12d ERROR: %-12d",
- counterEntityKey, totalValue, createdValue, modifiedValue, otherSuccessValue,
- deletedValue, errorValue));
+ counterEntityKey, totalValue, createdValue, modifiedValue, otherSuccessValue,
+ deletedValue, errorValue));
}
return sb.toString();
}
diff --git a/src/main/java/org/onap/aai/sparky/dal/elasticsearch/config/ElasticSearchConfig.java b/src/main/java/org/onap/aai/sparky/dal/elasticsearch/config/ElasticSearchConfig.java
deleted file mode 100644
index c3c27f8..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/elasticsearch/config/ElasticSearchConfig.java
+++ /dev/null
@@ -1,305 +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.dal.elasticsearch.config;
-
-import java.util.Properties;
-
-import org.onap.aai.sparky.util.ConfigHelper;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
-
-
-/**
- * The Class ElasticSearchConfig.
- */
-public class ElasticSearchConfig {
-
- public static final String CONFIG_FILE =
- TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "elasticsearch.properties";
-
- private static ElasticSearchConfig instance;
-
- private String ipAddress;
-
- private String httpPort;
-
- private String javaApiPort;
-
- private String indexName;
-
- private String type;
-
- private String clusterName;
-
- private String mappingsFileName;
-
- private String settingsFileName;
-
- private String topographicalSearchIndex;
-
- private String entityCountHistoryIndex;
-
- private String autosuggestIndexname;
-
- private String entityCountHistoryMappingsFileName;
-
- private String autoSuggestSettingsFileName;
-
- private String autoSuggestMappingsFileName;
-
- private String dynamicMappingsFileName;
-
- private static final String IP_ADDRESS_DEFAULT = "localhost";
-
- private static final String HTTP_PORT_DEFAULT = "9200";
-
- private static final String JAVA_API_PORT_DEFAULT = "9300";
-
- private static final String TYPE_DEFAULT = "aaiEntities";
-
- private static final String CLUSTER_NAME_DEFAULT = "elasticsearch";
-
- private static final String INDEX_NAME_DEFAULT = "entitySearchIndex";
-
- private static final String AUDIT_INDEX_NAME_DEFAULT = "auditdataindex";
-
- private static final String TOPOGRAPHICAL_INDEX_NAME_DEFAULT = "topographicalSearchIndex";
-
- private static final String ENTITY_COUNT_HISTORY_INDEX_NAME_DEFAULT = "entityCountHistory";
-
- private static final String ENTITY_AUTO_SUGGEST_INDEX_NAME_DEFAULT =
- TierSupportUiConstants.ENTITY_AUTO_SUGGEST_INDEX_NAME_DEFAULT;
-
- private static final String ENTITY_AUTO_SUGGEST_SETTINGS_FILE_DEFAULT =
- TierSupportUiConstants.ENTITY_AUTO_SUGGEST_SETTINGS_FILE_DEFAULT;
-
- private static final String ENTITY_AUTO_SUGGEST_MAPPINGS_FILE_DEFAULT =
- TierSupportUiConstants.ENTITY_AUTO_SUGGEST_SETTINGS_FILE_DEFAULT;
-
- private static final String ENTITY_DYNAMIC_MAPPINGS_FILE_DEFAULT =
- TierSupportUiConstants.ENTITY_DYNAMIC_MAPPINGS_FILE_DEFAULT;
-
- private static final String BULK_API = "_bulk";
-
- public static ElasticSearchConfig getConfig() throws Exception {
-
- if (instance == null) {
- instance = new ElasticSearchConfig();
- instance.initializeProperties();
- }
-
- return instance;
- }
-
- public static void setConfig(ElasticSearchConfig config) {
- /*
- * Explicitly allow setting the configuration singleton. This will be useful for automation.
- */
-
- ElasticSearchConfig.instance = config;
- }
-
- /**
- * Instantiates a new elastic search config.
- */
- public ElasticSearchConfig() {
- // test method
- }
-
- public String getElasticFullUrl(String resourceUrl, String indexName, String indexType)
- throws Exception {
- final String host = getIpAddress();
- final String port = getHttpPort();
- return String.format("http://%s:%s/%s/%s%s", host, port, indexName, indexType, resourceUrl);
- }
-
- public String getElasticFullUrl(String resourceUrl, String indexName) throws Exception {
- final String host = getIpAddress();
- final String port = getHttpPort();
- return String.format("http://%s:%s/%s/%s%s", host, port, indexName,
- ElasticSearchConfig.getConfig().getType(), resourceUrl);
- }
-
- public String getElasticFullUrl(String resourceUrl) throws Exception {
- final String host = getIpAddress();
- final String port = getHttpPort();
- final String indexName = getIndexName();
- return String.format("http://%s:%s/%s/%s%s", host, port, indexName, getType(), resourceUrl);
- }
-
- /**
- * Initialize properties.
- */
- private void initializeProperties() {
- Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
-
- if (props == null || props.isEmpty()) {
- return;
- }
-
- ipAddress = props.getProperty("elasticsearch.ipAddress", IP_ADDRESS_DEFAULT);
- httpPort = props.getProperty("elasticsearch.httpPort", "" + HTTP_PORT_DEFAULT);
- javaApiPort = props.getProperty("elasticsearch.javaApiPort", "" + JAVA_API_PORT_DEFAULT);
- type = props.getProperty("elasticsearch.type", TYPE_DEFAULT);
- clusterName = props.getProperty("elasticsearch.clusterName", CLUSTER_NAME_DEFAULT);
- indexName = props.getProperty("elasticsearch.indexName", INDEX_NAME_DEFAULT);
- mappingsFileName = props.getProperty("elasticsearch.mappingsFileName");
- settingsFileName = props.getProperty("elasticsearch.settingsFileName");
- topographicalSearchIndex =
- props.getProperty("elasticsearch.topographicalIndexName", TOPOGRAPHICAL_INDEX_NAME_DEFAULT);
- entityCountHistoryIndex = props.getProperty("elasticsearch.entityCountHistoryIndexName",
- ENTITY_COUNT_HISTORY_INDEX_NAME_DEFAULT);
-
- entityCountHistoryMappingsFileName =
- props.getProperty("elasticsearch.entityCountHistoryMappingsFileName");
-
- autosuggestIndexname = props.getProperty("elasticsearch.autosuggestIndexname",
- ENTITY_AUTO_SUGGEST_INDEX_NAME_DEFAULT);
- autoSuggestSettingsFileName = props.getProperty("elasticsearch.autosuggestSettingsFileName",
- ENTITY_AUTO_SUGGEST_SETTINGS_FILE_DEFAULT);
- autoSuggestMappingsFileName = props.getProperty("elasticsearch.autosuggestMappingsFileName",
- ENTITY_AUTO_SUGGEST_MAPPINGS_FILE_DEFAULT);
- dynamicMappingsFileName = props.getProperty("elasticsearch.dynamicMappingsFileName",
- ENTITY_DYNAMIC_MAPPINGS_FILE_DEFAULT);
-
- }
-
- public String getIpAddress() {
- return ipAddress;
- }
-
- public void setIpAddress(String ipAddress) {
- this.ipAddress = ipAddress;
- }
-
- public String getHttpPort() {
- return httpPort;
- }
-
- public void setHttpPort(String httpPort) {
- this.httpPort = httpPort;
- }
-
- public String getJavaApiPort() {
- return javaApiPort;
- }
-
- public void setJavaApiPort(String javaApiPort) {
- this.javaApiPort = javaApiPort;
- }
-
- public String getIndexName() {
- return indexName;
- }
-
- public void setIndexName(String indexName) {
- this.indexName = indexName;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getClusterName() {
- return clusterName;
- }
-
- public void setClusterName(String clusterName) {
- this.clusterName = clusterName;
- }
-
- public String getMappingsFileName() {
- return mappingsFileName;
- }
-
- public void setMappingsFileName(String mappingsFileName) {
- this.mappingsFileName = mappingsFileName;
- }
-
- public String getSettingsFileName() {
- return settingsFileName;
- }
-
- public void setSettingsFileName(String settingsFileName) {
- this.settingsFileName = settingsFileName;
- }
-
- public String getTopographicalSearchIndex() {
- return topographicalSearchIndex;
- }
-
- public void setTopographicalSearchIndex(String topographicalSearchIndex) {
- this.topographicalSearchIndex = topographicalSearchIndex;
- }
-
- public String getEntityCountHistoryIndex() {
- return entityCountHistoryIndex;
- }
-
- public void setEntityCountHistoryIndex(String entityCountHistoryIndex) {
- this.entityCountHistoryIndex = entityCountHistoryIndex;
- }
-
-
- public String getEntityCountHistoryMappingsFileName() {
- return entityCountHistoryMappingsFileName;
- }
-
- public void setEntityCountHistoryMappingsFileName(String entityCountHistoryMappingsFileName) {
- this.entityCountHistoryMappingsFileName = entityCountHistoryMappingsFileName;
- }
-
- public String getBulkUrl() {
- String url = this.getIpAddress();
- String port = this.getHttpPort();
- return String.format("http://%s:%s/%s", url, port, BULK_API);
- }
-
- public String getAutosuggestIndexname() {
- return autosuggestIndexname;
- }
-
- public void setAutosuggestIndexname(String autosuggestIndexname) {
- this.autosuggestIndexname = autosuggestIndexname;
- }
-
- public String getAutoSuggestSettingsFileName() {
- return autoSuggestSettingsFileName;
- }
-
- public void setAutoSuggestSettingsFileName(String autoSuggestSettingsFileName) {
- this.autoSuggestSettingsFileName = autoSuggestSettingsFileName;
- }
-
- public String getAutoSuggestMappingsFileName() {
- return autoSuggestMappingsFileName;
- }
-
- public void setAutoSuggestMappingsFileName(String autoSuggestMappingsFileName) {
- this.autoSuggestMappingsFileName = autoSuggestMappingsFileName;
- }
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/proxy/config/DataRouterConfig.java b/src/main/java/org/onap/aai/sparky/dal/proxy/config/DataRouterConfig.java
deleted file mode 100644
index df2ae13..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/proxy/config/DataRouterConfig.java
+++ /dev/null
@@ -1,132 +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.dal.proxy.config;
-
-import java.util.Properties;
-
-import org.onap.aai.sparky.util.ConfigHelper;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
-
-public class DataRouterConfig {
- private String host;
- private String port;
- private String drUriSuffix;
- private String certName;
- private String keystorePassword;
- private String keystore;
- private int connectTimeout;
- private int readTimeout;
-
- public String getHost() {
- return host;
- }
-
- public void setHost(String host) {
- this.host = host;
- }
-
- public String getPort() {
- return port;
- }
-
- public void setPort(String port) {
- this.port = port;
- }
-
- public String getCertName() {
- return certName;
- }
-
- public void setCertName(String certName) {
- this.certName = certName;
- }
-
- public String getKeystorePassword() {
- return keystorePassword;
- }
-
- public void setKeystorePassword(String keystorePassword) {
- this.keystorePassword = keystorePassword;
- }
-
- public String getKeystore() {
- return keystore;
- }
-
- public void setKeystore(String keystore) {
- this.keystore = keystore;
- }
-
- public int getConnectTimeout() {
- return connectTimeout;
- }
-
- public void setConnectTimeout(int connectTimeout) {
- this.connectTimeout = connectTimeout;
- }
-
- public int getReadTimeout() {
- return readTimeout;
- }
-
- public void setReadTimeout(int readTimeout) {
- this.readTimeout = readTimeout;
- }
-
- public String getDrUriSuffix() {
- return drUriSuffix;
- }
-
- public void setDrUriSuffix(String drUriSuffix) {
- this.drUriSuffix = drUriSuffix;
- }
-
- public DataRouterConfig(Properties props) {
-
- if (props == null) {
- return;
- }
-
- Properties restProps = ConfigHelper.getConfigWithPrefix("data-router.rest", props);
- host = restProps.getProperty(TierSupportUiConstants.IP_ADDRESS, "localhost");
- port = restProps.getProperty(TierSupportUiConstants.PORT, "9502");
- drUriSuffix = restProps.getProperty(TierSupportUiConstants.DR_URI_SUFFIX, "ui-request");
- connectTimeout =
- Integer.parseInt(restProps.getProperty(TierSupportUiConstants.DR_CONNECT_TIMEOUT, "5000"));
- readTimeout =
- Integer.parseInt(restProps.getProperty(TierSupportUiConstants.DR_READ_TIMEOUT, "1000"));
-
- Properties sslProps = ConfigHelper.getConfigWithPrefix("data-router.ssl", props);
- certName = sslProps.getProperty(TierSupportUiConstants.DR_CERT_NAME, "aai-client-cert.p12");
- keystorePassword = sslProps.getProperty(TierSupportUiConstants.DR_KEYSTORE_PASSWORD, "");
- keystore = sslProps.getProperty(TierSupportUiConstants.DR_KEYSTORE, "tomcat_keystore");
- }
-
- @Override
- public String toString() {
- return "DataRouterConfig [host=" + host + ", port=" + port + ", drUriSuffix=" + drUriSuffix
- + ", certName=" + certName + ", keystorePassword=" + keystorePassword + ", keystore="
- + keystore + ", connectTimeout=" + connectTimeout + ", readTimeout=" + readTimeout + "]";
- }
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/proxy/processor/AaiUiProxyProcessor.java b/src/main/java/org/onap/aai/sparky/dal/proxy/processor/AaiUiProxyProcessor.java
index 444a34b..04d6cf0 100644
--- a/src/main/java/org/onap/aai/sparky/dal/proxy/processor/AaiUiProxyProcessor.java
+++ b/src/main/java/org/onap/aai/sparky/dal/proxy/processor/AaiUiProxyProcessor.java
@@ -26,7 +26,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import javax.json.Json;
import javax.json.JsonObjectBuilder;
@@ -39,12 +38,12 @@ import org.onap.aai.cl.mdc.MdcContext;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.restclient.client.RestClient;
import org.onap.aai.restclient.rest.HttpUtil;
-import org.onap.aai.sparky.dal.proxy.config.DataRouterConfig;
+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;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.util.ConfigHelper;
-import org.onap.aai.sparky.util.Encryptor;
import org.onap.aai.sparky.util.NodeUtils;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import org.slf4j.MDC;
/**
@@ -55,12 +54,10 @@ public class AaiUiProxyProcessor {
LoggerFactory.getInstance().getLogger(AaiUiProxyProcessor.class);
private static Logger auditLogger =
LoggerFactory.getInstance().getAuditLogger(AaiUiProxyProcessor.class.getName());
- public String configFile =
- TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "data-router.properties";
private RestClient client;
- private DataRouterConfig config;
- private String drBaseUrl;
+ private String synapseBaseUrl;
+
private OperationResult operationResult = null;
private String xTransactionId;
@@ -68,39 +65,20 @@ public class AaiUiProxyProcessor {
private static final String ROUTER_SERVICE = "routerService";
- public String getDrBaseUrl() {
- return drBaseUrl;
- }
-
- public void setDrBaseUrl(String drBaseUrl) {
- this.drBaseUrl = drBaseUrl;
- }
/**
* Instantiates a new AaiUiProxyProcessor.
+ *
+ * @throws RestClientConstructionException
*/
- public AaiUiProxyProcessor() {
- Properties props = ConfigHelper.loadConfigFromExplicitPath(configFile);
- config = new DataRouterConfig(props);
- initializeProxyProcessor(config);
+ public AaiUiProxyProcessor(RestEndpointConfig endpointConfig, String apiGatewayEndpoint)
+ throws RestClientConstructionException {
+ client = RestClientFactory.buildClient(endpointConfig);
+ synapseBaseUrl = "https://" + endpointConfig.getEndpointIpAddress() + ":"
+ + endpointConfig.getEndpointServerPort() + "/" + apiGatewayEndpoint;
}
- public AaiUiProxyProcessor(DataRouterConfig config) {
- initializeProxyProcessor(config);
- }
-
- private void initializeProxyProcessor(DataRouterConfig config) {
- Encryptor encryptor = new Encryptor();
- client = new RestClient().validateServerHostname(false).validateServerCertChain(false)
- .clientCertFile(TierSupportUiConstants.CONFIG_AUTH_LOCATION + config.getCertName())
- .clientCertPassword(encryptor.decryptValue(config.getKeystorePassword()))
- .trustStore(TierSupportUiConstants.CONFIG_AUTH_LOCATION + config.getKeystore())
- .connectTimeoutMs(config.getConnectTimeout()).readTimeoutMs(config.getReadTimeout());
-
- drBaseUrl =
- "https://" + config.getHost() + ":" + config.getPort() + "/" + config.getDrUriSuffix();
- }
void setUpMdcContext(final Exchange exchange, final HttpServletRequest request) {
@@ -124,7 +102,7 @@ public class AaiUiProxyProcessor {
private Map<String, List<String>> getHeaders() {
Map<String, List<String>> headers = new HashMap<>();
- headers.put("X-FromAppId", Arrays.asList(TierSupportUiConstants.APP_NAME));
+ headers.put("X-FromAppId", Arrays.asList(SparkyConstants.APP_NAME));
headers.put("X-TransactionId", Arrays.asList(MDC.get(MdcContext.MDC_REQUEST_ID)));
headers.put("X-FromAppId", Arrays.asList(MDC.get(MdcContext.MDC_PARTNER_NAME)));
return headers;
@@ -151,11 +129,11 @@ public class AaiUiProxyProcessor {
return jsonBuilder.build().toString();
}
- private String getDrUrl(String requestUri) {
+ private String getSynapseUrl(String requestUri) {
String url = "";
int pos = requestUri.indexOf(ROUTER_SERVICE);
if (pos != -1) {
- url = drBaseUrl + requestUri.substring(pos + ROUTER_SERVICE.length());
+ url = synapseBaseUrl + requestUri.substring(pos + ROUTER_SERVICE.length());
} else {
LOG.error(AaiUiMsgs.DR_REQUEST_URI_FOR_PROXY_UNKNOWN, requestUri);
}
@@ -171,7 +149,7 @@ public class AaiUiProxyProcessor {
Map<String, List<String>> headers = getHeaders();
String proxyPayload = getProxyPayloadAsString(exchange);
String fromUrl = (String) exchange.getIn().getHeader(Exchange.HTTP_URI);
- String toUrl = getDrUrl(fromUrl);
+ String toUrl = getSynapseUrl(fromUrl);
auditLogger.info(AaiUiMsgs.DR_PROXY_FROM_TO, fromUrl, toUrl);
LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
"Proxying request:\n" + proxyPayload + "\n" + "Target URL:\n" + toUrl);
@@ -205,20 +183,20 @@ public class AaiUiProxyProcessor {
}
}
- public RestClient getClient() {
- return client;
+ public String getSynapseBaseUrl() {
+ return synapseBaseUrl;
}
- public void setClient(RestClient client) {
- this.client = client;
+ public void setSynapseBaseUrl(String synapseBaseUrl) {
+ this.synapseBaseUrl = synapseBaseUrl;
}
- public DataRouterConfig getConfig() {
- return config;
+ public RestClient getClient() {
+ return client;
}
- public void setConfig(DataRouterConfig config) {
- this.config = config;
+ public void setClient(RestClient client) {
+ this.client = client;
}
protected OperationResult getOperationResult() {
diff --git a/src/main/java/org/onap/aai/sparky/dal/rest/OperationResult.java b/src/main/java/org/onap/aai/sparky/dal/rest/OperationResult.java
deleted file mode 100644
index 419dc88..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/rest/OperationResult.java
+++ /dev/null
@@ -1,197 +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.dal.rest;
-
-/**
- * The Class OperationResult.
- */
-public class OperationResult {
-
- private String result;
-
- private String objectId;
- private String requestLink;
- private String requestPayload;
-
- private int resultCode;
-
- private boolean resolvedLinkFromCache;
-
- private boolean resolvedLinkFromServer;
-
- private boolean resolvedLinkFailure;
-
- private int numRequestRetries;
-
- private long responseTimeInMs;
-
- /**
- * Reset.
- */
- public void reset() {
- this.objectId = null;
- this.result = null;
- this.requestLink = null;
- this.requestPayload = null;
- this.resultCode = -1;
- this.resolvedLinkFailure = false;
- this.resolvedLinkFromServer = false;
- this.resolvedLinkFromCache = false;
- this.responseTimeInMs = 0;
- this.numRequestRetries = 0;
- }
-
- public String getObjectId() {
- return objectId;
- }
-
- public void setObjectId(String objectId) {
- this.objectId = objectId;
- }
-
- public boolean isResolvedLinkFromCache() {
- return resolvedLinkFromCache;
- }
-
- /**
- * Was successful.
- *
- * @return true, if successful
- */
- public boolean wasSuccessful() {
- return (resultCode > 199 && resultCode < 300);
- }
-
- public String getRequestLink() {
- return requestLink;
- }
-
- public void setRequestLink(String requestLink) {
- this.requestLink = requestLink;
- }
-
- public String getRequestPayload() {
- return requestPayload;
- }
-
- public void setRequestPayload(String requestPayload) {
- this.requestPayload = requestPayload;
- }
-
- public void setResolvedLinkFromCache(boolean resolvedLinkFromCache) {
- this.resolvedLinkFromCache = resolvedLinkFromCache;
- }
-
- public boolean isResolvedLinkFromServer() {
- return resolvedLinkFromServer;
- }
-
- public void setResolvedLinkFromServer(boolean resolvedLinkFromServer) {
- this.resolvedLinkFromServer = resolvedLinkFromServer;
- }
-
- public boolean isResolvedLinkFailure() {
- return resolvedLinkFailure;
- }
-
- public void setResolvedLinkFailure(boolean resolvedLinkFailure) {
- this.resolvedLinkFailure = resolvedLinkFailure;
- }
-
- public String getResult() {
- return result;
- }
-
- public int getResultCode() {
- return resultCode;
- }
-
- public void setResultCode(int resultCode) {
- this.resultCode = resultCode;
- }
-
- public void setResult(String result) {
- this.result = result;
- }
-
- /**
- * Sets the result.
- *
- * @param resultCode the result code
- * @param result the result
- */
- public void setResult(int resultCode, String result) {
- this.resultCode = resultCode;
- this.result = result;
- }
-
- /**
- * Instantiates a new operation result.
- */
- public OperationResult() {
- super();
- }
-
- /**
- * Instantiates a new operation result.
- *
- * @param resultCode the result code
- * @param result the result
- */
- public OperationResult(int resultCode, String result) {
- super();
- this.resultCode = resultCode;
- this.result = result;
- }
-
- public long getResponseTimeInMs() {
- return responseTimeInMs;
- }
-
- public void setResponseTimeInMs(long responseTimeInMs) {
- this.responseTimeInMs = responseTimeInMs;
- }
-
- public int getNumRequestRetries() {
- return numRequestRetries;
- }
-
- public void setNumRequestRetries(int numRequestRetries) {
- this.numRequestRetries = numRequestRetries;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OperationResult [result=" + result + ", resultCode=" + resultCode
- + ", resolvedLinkFromCache=" + resolvedLinkFromCache + ", resolvedLinkFromServer="
- + resolvedLinkFromServer + ", resolvedLinkFailure=" + resolvedLinkFailure
- + ", numRequestRetries=" + numRequestRetries + ", responseTimeInMs=" + responseTimeInMs
- + "]";
- }
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/rest/RestClientBuilder.java b/src/main/java/org/onap/aai/sparky/dal/rest/RestClientBuilder.java
deleted file mode 100644
index 5977a03..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/rest/RestClientBuilder.java
+++ /dev/null
@@ -1,144 +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.dal.rest;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-
-import org.onap.aai.sparky.security.SecurityContextFactory;
-import org.onap.aai.sparky.security.SecurityContextFactoryImpl;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
-
-/**
- * This is a generic REST Client builder with flexible security validation. Sometimes it's nice to
- * be able to disable server chain cert validation and hostname validation to work-around lab
- * issues, but at the same time be able to provide complete validation with client cert + hostname +
- * server cert chain validation. I used the ModelLoader REST client as a base and merged in the TSUI
- * client I wrote which also validates the server hostname and server certificate chain.
- *
- * @author DAVEA
- *
- */
-public class RestClientBuilder {
-
- /*
- * TODO: implement fluent interface?
- */
-
- private boolean useHttps;
- private boolean validateServerHostname;
- private int connectTimeoutInMs;
- private int readTimeoutInMs;
- protected SecurityContextFactory sslContextFactory;
-
- /**
- * Instantiates a new rest client builder.
- */
- public RestClientBuilder() {
- validateServerHostname = false;
- connectTimeoutInMs = 60000;
- readTimeoutInMs = 60000;
- useHttps = true;
- sslContextFactory = new SecurityContextFactoryImpl();
- }
-
- public SecurityContextFactory getSslContextFactory() {
- return sslContextFactory;
- }
-
- public void setSslContextFactory(SecurityContextFactory sslContextFactory) {
- this.sslContextFactory = sslContextFactory;
- }
-
- public boolean isUseHttps() {
- return useHttps;
- }
-
- public void setUseHttps(boolean useHttps) {
- this.useHttps = useHttps;
- }
-
- public int getConnectTimeoutInMs() {
- return connectTimeoutInMs;
- }
-
- public void setConnectTimeoutInMs(int connectTimeoutInMs) {
- this.connectTimeoutInMs = connectTimeoutInMs;
- }
-
- public int getReadTimeoutInMs() {
- return readTimeoutInMs;
- }
-
- public void setReadTimeoutInMs(int readTimeoutInMs) {
- this.readTimeoutInMs = readTimeoutInMs;
- }
-
- public boolean isValidateServerHostname() {
- return validateServerHostname;
- }
-
- public void setValidateServerHostname(boolean validateServerHostname) {
- this.validateServerHostname = validateServerHostname;
- }
-
- public Client getClient() throws Exception {
-
- Client client = null;
- ClientConfig clientConfig = new DefaultClientConfig();
-
- if (useHttps) {
- SSLContext sslContext = sslContextFactory.getSecureContext();
-
- if (validateServerHostname) {
-
- clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
- new HTTPSProperties(null, sslContext));
-
- } else {
- clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
- new HTTPSProperties(new HostnameVerifier() {
- @Override
- public boolean verify(String string, SSLSession sslSession) {
- return true;
- }
- }, sslContext));
-
- }
- }
-
- client = Client.create(clientConfig);
-
- client.setConnectTimeout(connectTimeoutInMs);
- client.setReadTimeout(readTimeoutInMs);
-
- return client;
-
- }
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/task/CollectNodeSelfLinkTask.java b/src/main/java/org/onap/aai/sparky/dal/rest/RestClientConstructionException.java
index 8683299..ff7da6f 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/task/CollectNodeSelfLinkTask.java
+++ b/src/main/java/org/onap/aai/sparky/dal/rest/RestClientConstructionException.java
@@ -20,40 +20,17 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.aai.sparky.viewandinspect.task;
+package org.onap.aai.sparky.dal.rest;
-import java.util.function.Supplier;
-
-import org.onap.aai.sparky.dal.aai.ActiveInventoryDataProvider;
-import org.onap.aai.sparky.dal.rest.OperationResult;
-
-/**
- * The Class CollectNodeSelfLinkTask.
- */
-public class CollectNodeSelfLinkTask implements Supplier<OperationResult> {
-
- private String selfLink;
- private ActiveInventoryDataProvider aaiProvider;
+public class RestClientConstructionException extends Exception {
/**
- * Instantiates a new collect node self link task.
- *
- * @param selfLink the self link
- * @param aaiProvider the aai provider
- */
- public CollectNodeSelfLinkTask(String selfLink, ActiveInventoryDataProvider aaiProvider) {
- this.selfLink = selfLink;
- this.aaiProvider = aaiProvider;
- }
-
- /*
- * (non-Javadoc)
*
- * @see java.util.function.Supplier#get()
*/
- @Override
- public OperationResult get() {
- return aaiProvider.queryActiveInventoryWithRetries(selfLink, "application/json", 5);
+ private static final long serialVersionUID = 1L;
+
+ public RestClientConstructionException(String message) {
+ super(message);
}
}
diff --git a/src/main/java/org/onap/aai/sparky/dal/rest/RestClientFactory.java b/src/main/java/org/onap/aai/sparky/dal/rest/RestClientFactory.java
new file mode 100644
index 0000000..58bf91a
--- /dev/null
+++ b/src/main/java/org/onap/aai/sparky/dal/rest/RestClientFactory.java
@@ -0,0 +1,94 @@
+/**
+ * ============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.dal.rest;
+
+import org.onap.aai.restclient.client.RestClient;
+import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
+import org.onap.aai.sparky.util.Encryptor;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
+
+public class RestClientFactory {
+
+ public static RestClient buildClient(RestEndpointConfig restEndpointConfig)
+ throws RestClientConstructionException {
+
+ if (restEndpointConfig == null) {
+ throw new RestClientConstructionException(
+ "Failed to build RestClient because RestEndpointConfig is null.");
+ }
+
+ if (restEndpointConfig.getRestAuthenticationMode() == null) {
+ throw new RestClientConstructionException(
+ "Failed to build RestClient because RestAuthenticationMode is null.");
+ }
+
+ switch (restEndpointConfig.getRestAuthenticationMode()) {
+
+ case SSL_CERT: {
+
+ Encryptor enc = new Encryptor();
+ String certFileNameFullPath =
+ SparkyConstants.CONFIG_AUTH_LOCATION + restEndpointConfig.getCertFileName();
+ String decryptedCertPassword = enc.decryptValue(restEndpointConfig.getCertPassword());
+ String truststoreFileNameFullPath =
+ SparkyConstants.CONFIG_AUTH_LOCATION + restEndpointConfig.getTruststoreFileName();
+
+ return new RestClient() //
+ .authenticationMode(restEndpointConfig.getRestAuthenticationMode()) //
+ .validateServerCertChain(restEndpointConfig.isValidateServerCertChain()) //
+ .validateServerHostname(restEndpointConfig.isValidateServerHostname()) //
+ .clientCertFile(certFileNameFullPath) //
+ .clientCertPassword(decryptedCertPassword) //
+ .trustStore(truststoreFileNameFullPath) //
+ .connectTimeoutMs(restEndpointConfig.getConnectTimeoutInMs()) //
+ .readTimeoutMs(restEndpointConfig.getReadTimeoutInMs());
+ }
+
+ case SSL_BASIC: {
+
+ return new RestClient() //
+ .authenticationMode(restEndpointConfig.getRestAuthenticationMode()) //
+ .basicAuthUsername(restEndpointConfig.getBasicAuthUserName()) //
+ .basicAuthPassword(restEndpointConfig.getBasicAuthPassword()) //
+ .connectTimeoutMs(restEndpointConfig.getConnectTimeoutInMs()) //
+ .readTimeoutMs(restEndpointConfig.getReadTimeoutInMs());
+
+ }
+
+ case HTTP_NOAUTH:
+ case UNKNOWN_MODE:
+ default: {
+
+ return new RestClient() //
+ .authenticationMode(restEndpointConfig.getRestAuthenticationMode()) //
+ .connectTimeoutMs(restEndpointConfig.getConnectTimeoutInMs()) //
+ .readTimeoutMs(restEndpointConfig.getReadTimeoutInMs());
+
+ }
+
+
+ }
+
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/sparky/dal/rest/RestDataProvider.java b/src/main/java/org/onap/aai/sparky/dal/rest/RestDataProvider.java
deleted file mode 100644
index b8780a5..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/rest/RestDataProvider.java
+++ /dev/null
@@ -1,109 +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.dal.rest;
-
-/**
- * The Interface RestDataProvider.
- */
-public interface RestDataProvider {
-
- /**
- * Do get.
- *
- * @param url the url
- * @param acceptContentType the accept content type
- * @return the operation result
- */
- OperationResult doGet(String url, String acceptContentType);
-
- /**
- * Do delete.
- *
- * @param url the url
- * @param acceptContentType the accept content type
- * @return the operation result
- */
- OperationResult doDelete(String url, String acceptContentType);
-
- /**
- * Do post.
- *
- * @param url the url
- * @param jsonPayload the json payload
- * @param acceptContentType the accept content type
- * @return the operation result
- */
- OperationResult doPost(String url, String jsonPayload, String acceptContentType);
-
- /**
- * Do put.
- *
- * @param url the url
- * @param jsonPayload the json payload
- * @param acceptContentType the accept content type
- * @return the operation result
- */
- OperationResult doPut(String url, String jsonPayload, String acceptContentType);
-
- /**
- * Do patch.
- *
- * @param url the url
- * @param jsonPayload the json payload
- * @param acceptContentType the accept content type
- * @return the operation result
- */
- OperationResult doPatch(String url, String jsonPayload, String acceptContentType);
-
- /**
- * Do head.
- *
- * @param url the url
- * @param acceptContentType the accept content type
- * @return the operation result
- */
- OperationResult doHead(String url, String acceptContentType);
-
- /**
- * Do restful operation.
- *
- * @param method the method
- * @param url the url
- * @param payload the payload
- * @param payloadType the payload type
- * @param acceptContentType the accept content type
- * @return the operation result
- */
- OperationResult doRestfulOperation(HttpMethod method, String url, String payload,
- String payloadType, String acceptContentType);
-
- /**
- * Shutdown.
- */
- void shutdown();
-
- /**
- * Clear cache.
- */
- void clearCache();
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/rest/RestfulDataAccessor.java b/src/main/java/org/onap/aai/sparky/dal/rest/RestfulDataAccessor.java
deleted file mode 100644
index 9f07aff..0000000
--- a/src/main/java/org/onap/aai/sparky/dal/rest/RestfulDataAccessor.java
+++ /dev/null
@@ -1,302 +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.dal.rest;
-
-import java.security.SecureRandom;
-
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.WebResource.Builder;
-
-/**
- * The Class RestfulDataAccessor.
- *
- * TODO: DELETE ME
- *
- */
-public class RestfulDataAccessor implements RestDataProvider {
-
- protected SecureRandom txnIdGenerator;
-
- protected RestClientBuilder clientBuilder;
-
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(RestfulDataAccessor.class);
-
- private boolean resourceNotFoundErrorsSurpressed;
-
- public static final String APPLICATION_JSON = "application/json";
- public static final String APPLICATION_MERGE_PATCH_JSON = "application/merge-patch+json";
- public static final String APPLICATION_X_WWW_FORM_URL_ENCODED =
- "application/x-www-form-urlencoded";
-
-
- /**
- * Instantiates a new restful data accessor.
- *
- * @param clientBuilder the client builder
- */
- public RestfulDataAccessor(RestClientBuilder clientBuilder) {
- this.clientBuilder = clientBuilder;
- txnIdGenerator = new SecureRandom();
- resourceNotFoundErrorsSurpressed = false;
- }
-
- /**
- * Populate operation result.
- *
- * @param response the response
- * @param opResult the op result
- */
- protected void populateOperationResult(ClientResponse response, OperationResult opResult) {
-
- if (response == null) {
- opResult.setResult(500, "Client response was null");
- return;
- }
-
- int statusCode = response.getStatus();
- String payload = response.getEntity(String.class);
-
- opResult.setResult(statusCode, payload);
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.openecomp.sparky.dal.rest.RestDataProvider#doRestfulOperation(org.openecomp.sparky.dal.rest
- * .HttpMethod, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
- */
- @Override
- public OperationResult doRestfulOperation(HttpMethod method, String url, String payload,
- String payloadType, String acceptContentType) {
-
- ClientResponse clientResponse = null;
-
- long startTimeInMs = System.currentTimeMillis();
- Client client = null;
- Builder builder = null;
-
- /*
- * else cache miss / cache disabled (default operation)
- */
-
- OperationResult operationResult = new OperationResult();
- operationResult.setRequestLink(url);
-
- try {
-
- client = clientBuilder.getClient();
-
- switch (method) {
- case GET: {
- builder = setClientDefaults(client, url, null, acceptContentType);
- clientResponse = builder.get(ClientResponse.class);
- break;
- }
-
- case PUT: {
- builder = setClientDefaults(client, url, payloadType, acceptContentType);
- clientResponse = builder.put(ClientResponse.class, payload);
- break;
- }
-
- case POST: {
- builder = setClientDefaults(client, url, payloadType, acceptContentType);
- clientResponse = builder.post(ClientResponse.class, payload);
- break;
- }
-
- case DELETE: {
- builder = setClientDefaults(client, url, null, acceptContentType);
- clientResponse = builder.delete(ClientResponse.class);
- break;
- }
-
- case PATCH: {
- builder = setClientDefaults(client, url, payloadType, acceptContentType);
- builder = builder.header("X-HTTP-Method-Override", "PATCH");
- clientResponse = builder.post(ClientResponse.class, payload);
- break;
- }
-
- case HEAD: {
- builder = setClientDefaults(client, url, null, acceptContentType);
- clientResponse = builder.head();
- break;
- }
-
-
- default: {
- operationResult.setResult(500, "Unhandled HTTP Method operation = " + method);
- return operationResult;
- }
-
- }
-
- } catch (Exception ex) {
- LOG.error(AaiUiMsgs.RESTFULL_OP_ERROR_VERBOSE, url, ex.getLocalizedMessage());
- operationResult.setResult(500,
- String.format("Error retrieving link = '%s' from restful endpoint due to error = '%s'",
- url, ex.getLocalizedMessage()));
- return operationResult;
- }
-
- populateOperationResult(clientResponse, operationResult);
-
- if (operationResult.getResultCode() != 404
- || (operationResult.getResultCode() == 404 && !isResourceNotFoundErrorsSurpressed())) {
- LOG.info(AaiUiMsgs.RESTFULL_OP_COMPLETE, method.toString(),
- String.valueOf(System.currentTimeMillis() - startTimeInMs), url,
- String.valueOf(operationResult.getResultCode()));
- }
-
- return operationResult;
-
- }
-
- public boolean isResourceNotFoundErrorsSurpressed() {
- return resourceNotFoundErrorsSurpressed;
- }
-
- public void setResourceNotFoundErrorsSurpressed(boolean resourceNotFoundErrorsSurpressed) {
- this.resourceNotFoundErrorsSurpressed = resourceNotFoundErrorsSurpressed;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#doGet(java.lang.String, java.lang.String)
- */
- @Override
- public OperationResult doGet(String url, String acceptContentType) {
- return doRestfulOperation(HttpMethod.GET, url, null, null, acceptContentType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#doDelete(java.lang.String,
- * java.lang.String)
- */
- @Override
- public OperationResult doDelete(String url, String acceptContentType) {
- return doRestfulOperation(HttpMethod.DELETE, url, null, null, acceptContentType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#doPost(java.lang.String, java.lang.String,
- * java.lang.String)
- */
- @Override
- public OperationResult doPost(String url, String jsonPayload, String acceptContentType) {
- return doRestfulOperation(HttpMethod.POST, url, jsonPayload, APPLICATION_JSON,
- acceptContentType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#doPut(java.lang.String, java.lang.String,
- * java.lang.String)
- */
- @Override
- public OperationResult doPut(String url, String jsonPayload, String acceptContentType) {
- return doRestfulOperation(HttpMethod.PUT, url, jsonPayload, APPLICATION_JSON,
- acceptContentType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#doPatch(java.lang.String, java.lang.String,
- * java.lang.String)
- */
- @Override
- public OperationResult doPatch(String url, String jsonPayload, String acceptContentType) {
- return doRestfulOperation(HttpMethod.PATCH, url, jsonPayload, APPLICATION_MERGE_PATCH_JSON,
- acceptContentType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#doHead(java.lang.String, java.lang.String)
- */
- @Override
- public OperationResult doHead(String url, String acceptContentType) {
- return doRestfulOperation(HttpMethod.HEAD, url, null, null, acceptContentType);
- }
-
- /**
- * Sets the client defaults.
- *
- * @param client the client
- * @param url the url
- * @param payloadContentType the payload content type
- * @param acceptContentType the accept content type
- * @return the builder
- */
- protected Builder setClientDefaults(Client client, String url, String payloadContentType,
- String acceptContentType) {
- WebResource resource = client.resource(url);
- Builder builder = null;
- builder = resource.accept(acceptContentType);
-
- if (payloadContentType != null) {
- builder = builder.header("Content-Type", payloadContentType);
- }
-
- return builder;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#shutdown()
- */
- @Override
- public void shutdown() {
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.openecomp.sparky.dal.rest.RestDataProvider#clearCache()
- */
- @Override
- public void clearCache() {
-
- }
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/dal/rest/config/RestEndpointConfig.java b/src/main/java/org/onap/aai/sparky/dal/rest/config/RestEndpointConfig.java
new file mode 100644
index 0000000..e28116c
--- /dev/null
+++ b/src/main/java/org/onap/aai/sparky/dal/rest/config/RestEndpointConfig.java
@@ -0,0 +1,167 @@
+/**
+ * ============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.dal.rest.config;
+
+import org.onap.aai.restclient.enums.RestAuthenticationMode;
+
+public class RestEndpointConfig {
+
+ private String endpointIpAddress;
+ private String endpointServerPort;
+ private int numRequestRetries;
+ private String basicAuthUserName;
+ private String basicAuthPassword;
+ private RestAuthenticationMode restAuthenticationMode;
+ private int connectTimeoutInMs;
+ private int readTimeoutInMs;
+ private String certFileName;
+ private String certPassword;
+ private String truststoreFileName;
+ private boolean validateServerCertChain;
+ private boolean validateServerHostname;
+
+ public boolean isValidateServerCertChain() {
+ return validateServerCertChain;
+ }
+
+ public void setValidateServerCertChain(boolean validateServerCertChain) {
+ this.validateServerCertChain = validateServerCertChain;
+ }
+
+ public boolean isValidateServerHostname() {
+ return validateServerHostname;
+ }
+
+ public void setValidateServerHostname(boolean validateServerHostname) {
+ this.validateServerHostname = validateServerHostname;
+ }
+
+ public String getEndpointIpAddress() {
+ return endpointIpAddress;
+ }
+
+ public void setEndpointIpAddress(String endpointIpAddress) {
+ this.endpointIpAddress = endpointIpAddress;
+ }
+
+ public String getEndpointServerPort() {
+ return endpointServerPort;
+ }
+
+ public void setEndpointServerPort(String endpointServerPort) {
+ this.endpointServerPort = endpointServerPort;
+ }
+
+ public int getNumRequestRetries() {
+ return numRequestRetries;
+ }
+
+ public void setNumRequestRetries(int numRequestRetries) {
+ this.numRequestRetries = numRequestRetries;
+ }
+
+ public String getBasicAuthUserName() {
+ return basicAuthUserName;
+ }
+
+ public void setBasicAuthUserName(String basicAuthUserName) {
+ this.basicAuthUserName = basicAuthUserName;
+ }
+
+ public String getBasicAuthPassword() {
+ return basicAuthPassword;
+ }
+
+ public void setBasicAuthPassword(String basicAuthPassword) {
+ this.basicAuthPassword = basicAuthPassword;
+ }
+
+ public RestAuthenticationMode getRestAuthenticationMode() {
+ return restAuthenticationMode;
+ }
+
+ public void setRestAuthenticationMode(RestAuthenticationMode restAuthenticationMode) {
+ this.restAuthenticationMode = restAuthenticationMode;
+ }
+
+ public int getConnectTimeoutInMs() {
+ return connectTimeoutInMs;
+ }
+
+ public void setConnectTimeoutInMs(int connectTimeoutInMs) {
+ this.connectTimeoutInMs = connectTimeoutInMs;
+ }
+
+ public int getReadTimeoutInMs() {
+ return readTimeoutInMs;
+ }
+
+ public void setReadTimeoutInMs(int readTimeoutInMs) {
+ this.readTimeoutInMs = readTimeoutInMs;
+ }
+
+ public String getCertFileName() {
+ return certFileName;
+ }
+
+ public void setCertFileName(String certFileName) {
+ this.certFileName = certFileName;
+ }
+
+ public String getCertPassword() {
+ return certPassword;
+ }
+
+ public void setCertPassword(String certPassword) {
+ this.certPassword = certPassword;
+ }
+
+ public String getTruststoreFileName() {
+ return truststoreFileName;
+ }
+
+ public void setTruststoreFileName(String truststoreFileName) {
+ this.truststoreFileName = truststoreFileName;
+ }
+
+ @Override
+ public String toString() {
+ return "RestEndpointConfig ["
+ + (endpointIpAddress != null ? "endpointIpAddress=" + endpointIpAddress + ", " : "")
+ + (endpointServerPort != null ? "endpointServerPort=" + endpointServerPort + ", " : "")
+ + "numRequestRetries=" + numRequestRetries + ", "
+ + (basicAuthUserName != null ? "basicAuthUserName=" + basicAuthUserName + ", " : "")
+ + (basicAuthPassword != null ? "basicAuthPassword=" + basicAuthPassword + ", " : "")
+ + (restAuthenticationMode != null
+ ? "restAuthenticationMode=" + restAuthenticationMode + ", " : "")
+ + "connectTimeoutInMs=" + connectTimeoutInMs + ", readTimeoutInMs=" + readTimeoutInMs + ", "
+ + (certFileName != null ? "certFileName=" + certFileName + ", " : "")
+ + (certPassword != null ? "certPassword=" + certPassword + ", " : "")
+ + (truststoreFileName != null ? "truststoreFileName=" + truststoreFileName + ", " : "")
+ + "validateServerCertChain=" + validateServerCertChain + ", validateServerHostname="
+ + validateServerHostname + "]";
+ }
+
+
+
+}
diff --git a/src/main/java/org/onap/aai/sparky/dal/sas/config/SearchServiceConfig.java b/src/main/java/org/onap/aai/sparky/dal/sas/config/SearchServiceConfig.java
index cb6f933..b581a78 100644
--- a/src/main/java/org/onap/aai/sparky/dal/sas/config/SearchServiceConfig.java
+++ b/src/main/java/org/onap/aai/sparky/dal/sas/config/SearchServiceConfig.java
@@ -25,7 +25,7 @@ package org.onap.aai.sparky.dal.sas.config;
import java.util.Properties;
import org.onap.aai.sparky.util.ConfigHelper;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
/**
* The Class ElasticSearchConfig.
@@ -33,7 +33,7 @@ import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
public class SearchServiceConfig {
public static final String CONFIG_FILE =
- TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "search-service.properties";
+ SparkyConstants.DYNAMIC_CONFIG_APP_LOCATION + "search-service.properties";
private static SearchServiceConfig instance;
@@ -52,11 +52,11 @@ public class SearchServiceConfig {
private String version;
private String type;
-
+
private String certName;
-
+
private String keystorePassword;
-
+
private String keystore;
private static final String IP_ADDRESS_DEFAULT = "localhost";
@@ -101,19 +101,20 @@ public class SearchServiceConfig {
*/
private void initializeProperties() {
Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
-
+
Properties sasProps = ConfigHelper.getConfigWithPrefix("search-service", props);
-
+
ipAddress = sasProps.getProperty("ipAddress", IP_ADDRESS_DEFAULT);
httpPort = sasProps.getProperty("httpPort", "" + HTTP_PORT_DEFAULT);
version = sasProps.getProperty("version", "" + VERSION_DEFAULT);
indexName = sasProps.getProperty("indexName", INDEX_NAME_DEFAULT);
auditIndexName = sasProps.getProperty("auditIndexName", AUDIT_INDEX_NAME_DEFAULT);
- topographicalSearchIndex =
- sasProps.getProperty("topographicalIndexName", TOPOGRAPHICAL_INDEX_NAME_DEFAULT);
+ topographicalSearchIndex = sasProps.getProperty("topographicalIndexName",
+ TOPOGRAPHICAL_INDEX_NAME_DEFAULT);
entityCountHistoryIndex = sasProps.getProperty("entityCountHistoryIndexName",
ENTITY_COUNT_HISTORY_INDEX_NAME_DEFAULT);
- certName = sasProps.getProperty("ssl.cert-name", "aai-client-cert.p12");
+ certName =
+ sasProps.getProperty("ssl.cert-name", "aai-client-cert.p12");
keystorePassword = sasProps.getProperty("ssl.keystore-password",
"OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o");
keystore = sasProps.getProperty("ssl.keystore", "tomcat_keystore");
@@ -182,8 +183,8 @@ public class SearchServiceConfig {
public void setType(String type) {
this.type = type;
}
-
-
+
+
public String getCertName() {
return certName;
}
diff --git a/src/main/java/org/onap/aai/sparky/dataintegrity/config/DiUiConstants.java b/src/main/java/org/onap/aai/sparky/dataintegrity/config/DiUiConstants.java
deleted file mode 100644
index c449931..0000000
--- a/src/main/java/org/onap/aai/sparky/dataintegrity/config/DiUiConstants.java
+++ /dev/null
@@ -1,77 +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.dataintegrity.config;
-
-/**
- * The Class DiUiConstants.
- */
-public class DiUiConstants {
-
- public static final String APP_JSON = "application/json";
- public static final String CATEGORY = "category";
-
- public static final String ENTITY_TYPE = "entityType";
- public static final String KEY_AGG = "aggregations";
- public static final String KEY_AGG_RESULT = "aggregationResult";
- public static final String KEY_AGG_RESULT_COUNT = "count";
- public static final String KEY_AGG_RESULT_ID = "key_as_string";
- public static final String KEY_BUCKETS = "buckets";
- public static final String KEY_ROUTE = "route";
- public static final String KEY_FILTERS = "filters";
- public static final String KEY_FILTER_VALUE = "filterValue";
- public static final String KEY_FILTER_ID = "filterId";
- public static final String KEY_START_DATE = "startDate";
- public static final String KEY_END_DATE = "endDate";
- public static final String KEY_TIME_ZONE = "time_zone";
- public static final String DEFAULT_TIME_ZONE = "+00:00";
-
- public static final String WIDGET_TYPE_SEVERITY = "severity";
- public static final String WIDGET_TYPE_CATEGORY = "category";
- public static final String WIDGET_TYPE_ENTITY_TYPE = "entityType";
- public static final String WIDGET_TYPE_PAGINATED_TABLE = "pagination";
- public static final String WIDGET_TYPE_DATE_HISTOGRAM = "dateHistogram";
-
-
- public static final String KEY_BY_ITEM = "by_item";
- public static final String KEY_ENTITY_ID = "entityId";
- public static final String KEY_HITS = "hits";
- public static final String KEY_SEARCH_RESULT = "searchResult";
- public static final String KEY_INNER_HITS = "inner_hits";
- public static final String KEY_ITEM = "item";
- public static final String KEY_ITEM_AGG = "item_aggregation";
- public static final String KEY_TIMESTAMP = "violationTimestamp";
- public static final String KEY_TOTAL_HITS = "totalHits";
- public static final String KEY_VIOLATION_DETAILS = "violationDetails";
- public static final String SEARCH_API = "query";
-
- public static final String SEVERITY = "severity";
- public static final String UI_KEY_BY_CATEGORY = "group_by_status";
- public static final String UI_KEY_BY_DATE = "group_by_date";
- public static final String UI_KEY_BY_ENTITY_TYPE = "group_by_entityType";
- public static final String UI_KEY_BY_SEVERITY = "group_by_severity";
-
- public static final String UI_KEY_ORDER_BY_DATE = "order_by_date";
- public static final String VIOLATIONS = "violations";
- public static final String KEY_VIEW_NAME = "Data Integrity";
-
-}
diff --git a/src/main/java/org/onap/aai/sparky/editattributes/AttributeEditProcessor.java b/src/main/java/org/onap/aai/sparky/editattributes/AttributeEditProcessor.java
index 42b439e..dc1c6eb 100644
--- a/src/main/java/org/onap/aai/sparky/editattributes/AttributeEditProcessor.java
+++ b/src/main/java/org/onap/aai/sparky/editattributes/AttributeEditProcessor.java
@@ -92,17 +92,15 @@ public class AttributeEditProcessor {
EditRequest editRequest = null;
OperationResult operationResult = new OperationResult();
- Response response =
- exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
- response.setStatus(Status.SUCCESS_OK); // 200 is assumed unless an actual exception occurs (a
- // failure is still a valid response)
-
+ Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
+ response.setStatus(Status.SUCCESS_OK); // 200 is assumed unless an actual exception occurs (a failure is still a valid response)
+
boolean wasErrorDuringProcessing = false;
String errorMessage = null;
-
-
+
+
try {
-
+
if (payload != null && !payload.isEmpty()) {
editRequest = mapper.readValue(payload, EditRequest.class);
@@ -111,12 +109,12 @@ public class AttributeEditProcessor {
String attUid = getAttUid(request.getCookies());
String objectUri = editRequest.getEntityUri();
Map<String, Object> attributeValues = editRequest.getAttributes();
-
+
if (attUid != null && !attUid.isEmpty() && objectUri != null && !objectUri.isEmpty()
&& attributeValues != null && !attributeValues.isEmpty()) {
LOG.info(AaiUiMsgs.ATTRIBUTES_HANDLING_EDIT, objectUri, editRequest.toString());
-
+
operationResult = attrUpdater.updateObjectAttribute(objectUri, attributeValues, attUid);
boolean wasSuccess = (operationResult.getResultCode() == 200);
@@ -135,8 +133,8 @@ public class AttributeEditProcessor {
operationResult.setResult(500, "Error encountered while trying to update attributes.");
response.setStatus(Status.SERVER_ERROR_INTERNAL);
}
-
- if (wasErrorDuringProcessing) {
+
+ if(wasErrorDuringProcessing) {
LOG.error(AaiUiMsgs.ATTRIBUTES_NOT_UPDATED_MESSAGE, errorMessage);
}
diff --git a/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java b/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java
index 5e6d652..f992da7 100644
--- a/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java
+++ b/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java
@@ -38,7 +38,6 @@ 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.aai.config.ActiveInventoryConfig;
import org.onap.aai.sparky.editattributes.exception.AttributeUpdateException;
import org.onap.aai.sparky.logging.AaiUiMsgs;
@@ -53,7 +52,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy;
*
*/
public class AttributeUpdater {
-
+
/**
* The Class AaiEditObject.
*/
@@ -131,34 +130,30 @@ public class AttributeUpdater {
private static final String MESSAGE_VERSION_EXTRACTION_REGEX = "\\/(v[0-9]+)";
private static final String ATTRIBUTES_UPDATED_SUCCESSFULLY = "Attributes updated successfully";
private static final String ATTRIBUTES_NOT_UPDATED = "Attributes not updated. ";
- private ActiveInventoryConfig aaiConfig;
+
private ActiveInventoryAdapter aaiAdapter;
private UserValidator validator;
private OxmModelLoader oxmModelLoader;
private OxmEntityLookup oxmEntityLookup;
-
+
/**
* Instantiates a new attribute updater.
- *
- * @throws AttributeUpdateException
+ * @throws AttributeUpdateException
*/
- public AttributeUpdater(OxmModelLoader oxmModelLoader, OxmEntityLookup oxmEntityLookup,
- ActiveInventoryAdapter activeInventoryAdapter) throws AttributeUpdateException {
+ public AttributeUpdater(OxmModelLoader oxmModelLoader, OxmEntityLookup oxmEntityLookup, ActiveInventoryAdapter activeInventoryAdapter) throws AttributeUpdateException {
super();
this.oxmModelLoader = oxmModelLoader;
this.oxmEntityLookup = oxmEntityLookup;
this.aaiAdapter = activeInventoryAdapter;
-
+
try {
- this.aaiConfig = ActiveInventoryConfig.getConfig(); // TODO -> Config to become a bean
this.validator = new UserValidator();
} catch (Exception exc) {
- LOG.error(AaiUiMsgs.ATTRIBUTES_ERROR_GETTING_AAI_CONFIG_OR_ADAPTER,
- exc.getLocalizedMessage());
+ LOG.error(AaiUiMsgs.ATTRIBUTES_ERROR_GETTING_AAI_CONFIG_OR_ADAPTER, exc.getLocalizedMessage());
throw new AttributeUpdateException(exc);
}
}
-
+
protected String getResourceBasePath() {
String versionStr = null;
@@ -169,26 +164,26 @@ public class AttributeUpdater {
return "/aai/v" + versionStr;
}
-
+
protected URI getBaseUri() {
- return UriBuilder.fromUri("https://" + aaiConfig.getAaiRestConfig().getHost() + ":"
- + aaiConfig.getAaiRestConfig().getPort() + getResourceBasePath()).build();
+ return UriBuilder
+ .fromUri("https://" + aaiAdapter.getEndpointConfig().getEndpointIpAddress() + ":"
+ + aaiAdapter.getEndpointConfig().getEndpointServerPort() + getResourceBasePath())
+ .build();
}
/**
* Update object attribute.
*
* @param objectUri - Valid URI of the object as per OXM model.
- * @param attributeValues - Map of (attribute-name & attribute-value) for any attributes to be
- * updated to the value.
+ * @param attributeValues - Map of (attribute-name & attribute-value) for
+ * any attributes to be updated to the value.
* @param attUid - ATTUID of the user requesting the update.
* @return - OperationResult with success or failure reason.
*/
- public OperationResult updateObjectAttribute(String objectUri,
- Map<String, Object> attributeValues, String attUid) {
+ public OperationResult updateObjectAttribute(String objectUri, Map<String, Object> attributeValues, String attUid) {
OperationResult result = new OperationResult();
- LOG.info(AaiUiMsgs.ATTRIBUTES_UPDATE_METHOD_CALLED, objectUri, attUid,
- String.valueOf(attributeValues));
+ LOG.info(AaiUiMsgs.ATTRIBUTES_UPDATE_METHOD_CALLED, objectUri, attUid, String.valueOf(attributeValues));
if (!validator.isAuthorizedUser(attUid)) {
result.setResultCode(403);
result.setResult(String.format("User %s is not authorized for Attributes update ", attUid));
@@ -210,24 +205,23 @@ public class AttributeUpdater {
String jsonPayload = convertEditRequestToJson(object, attributeValues);
String patchUri = getBaseUri().toString() + getRelativeUri(objectUri);
-
+
/*
- * FIX ME: Dave Adams, 8-Nov-2017
+ * FIX ME: Dave Adams, 8-Nov-2017
*/
-
- // result = aaiAdapter.doPatch(patchUri, jsonPayload, MediaType.APPLICATION_JSON);
+
+ //result = aaiAdapter.doPatch(patchUri, jsonPayload, MediaType.APPLICATION_JSON);
result = new OperationResult();
result.setResultCode(404);
-
+
if (result.getResultCode() == 200) {
result.setResult(ATTRIBUTES_UPDATED_SUCCESSFULLY);
String message = result.getResult() + " for " + objectUri;
LOG.info(AaiUiMsgs.INFO_GENERIC, message);
} else {
- String message =
- ATTRIBUTES_NOT_UPDATED + " For: " + objectUri + ". AAI PATCH Status Code : "
- + result.getResultCode() + ". Error : " + result.getResult();
+ String message = ATTRIBUTES_NOT_UPDATED + " For: " + objectUri + ". AAI PATCH Status Code : "
+ + result.getResultCode() + ". Error : " + result.getResult();
LOG.error(AaiUiMsgs.ATTRIBUTES_NOT_UPDATED_MESSAGE, message);
}
} catch (AttributeUpdateException exc) {
@@ -270,7 +264,7 @@ public class AttributeUpdater {
AaiEditObject object = new AaiEditObject();
String version = getVersionFromUri(objectUri);
- if (null == version) {
+ if ( null == version ) {
version = "v" + String.valueOf(oxmModelLoader.getLatestVersionNum());
}
object.setSchemaVersion(version);
@@ -288,14 +282,14 @@ public class AttributeUpdater {
String objectJavaType = null;
Map<String, DynamicType> entityTypeLookup = oxmEntityLookup.getEntityTypeLookup();
DynamicType entity = entityTypeLookup.get(rootElement);
- if (null != entity) {
+ if ( null != entity ) {
objectJavaType = entity.getName();
- String message =
- "Descriptor: Alias: " + objectJavaType + " : DefaultRootElement: " + rootElement;
+ String message = "Descriptor: Alias: " + objectJavaType + " : DefaultRootElement: "
+ + rootElement;
LOG.debug(AaiUiMsgs.DEBUG_GENERIC, message);
}
-
-
+
+
if (objectJavaType == null) {
throw new AttributeUpdateException(
"Object type could not be determined from the URI : " + objectUri);
diff --git a/src/main/java/org/onap/aai/sparky/editattributes/UserValidator.java b/src/main/java/org/onap/aai/sparky/editattributes/UserValidator.java
index cccd815..0364a66 100644
--- a/src/main/java/org/onap/aai/sparky/editattributes/UserValidator.java
+++ b/src/main/java/org/onap/aai/sparky/editattributes/UserValidator.java
@@ -29,7 +29,7 @@ import java.util.List;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
/**
* Validates users against a user authorization file.
@@ -38,7 +38,7 @@ public class UserValidator {
private static final Logger LOG = LoggerFactory.getInstance().getLogger(UserValidator.class);
private static final String USER_AUTH_FILE =
- TierSupportUiConstants.AUTHORIZED_USERS_FILE_LOCATION;
+ SparkyConstants.AUTHORIZED_USERS_FILE_LOCATION;
private UserAuthorizationReader userAuthorizationReader =
new UserAuthorizationReader(new File(USER_AUTH_FILE));
diff --git a/src/main/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilder.java b/src/main/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilder.java
index b765dc8..388fb2c 100644
--- a/src/main/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilder.java
+++ b/src/main/java/org/onap/aai/sparky/inventory/EntityHistoryQueryBuilder.java
@@ -81,14 +81,12 @@ public class EntityHistoryQueryBuilder {
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("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();
diff --git a/src/main/java/org/onap/aai/sparky/inventory/GeoVisualizationProcessor.java b/src/main/java/org/onap/aai/sparky/inventory/GeoVisualizationProcessor.java
index c356191..6ff08ca 100644
--- a/src/main/java/org/onap/aai/sparky/inventory/GeoVisualizationProcessor.java
+++ b/src/main/java/org/onap/aai/sparky/inventory/GeoVisualizationProcessor.java
@@ -32,10 +32,8 @@ 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.elasticsearch.SearchAdapter;
-import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.logging.util.ServletUtils;
import org.onap.aai.sparky.util.NodeUtils;
import org.restlet.Request;
import org.restlet.Response;
@@ -57,39 +55,20 @@ public class GeoVisualizationProcessor {
LoggerFactory.getInstance().getLogger(GeoVisualizationProcessor.class);
private ObjectMapper mapper;
- private SearchAdapter search = null;
- private ElasticSearchConfig elasticConfig = null;
+ 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 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() {
+ public GeoVisualizationProcessor(ElasticSearchAdapter elasticSearchAdapter, String topographicalSearchIndexName) {
this.mapper = new ObjectMapper();
-
- try {
- if (elasticConfig == null) {
- elasticConfig = ElasticSearchConfig.getConfig();
- }
- if (search == null) {
- search = new SearchAdapter();
- }
- this.mapper = new ObjectMapper();
- } catch (Exception exc) {
-
- }
- }
-
- public void setSearch(SearchAdapter search) {
- this.search = search;
- }
-
- public void setElasticConfig(ElasticSearchConfig elasticConfig) {
- this.elasticConfig = elasticConfig;
+ this.elasticSearchAdapter = elasticSearchAdapter;
+ this.topographicalSearchIndexName = topographicalSearchIndexName;
}
/**
@@ -103,7 +82,7 @@ public class GeoVisualizationProcessor {
protected OperationResult getGeoVisualizationResults(Exchange exchange) throws Exception {
OperationResult operationResult = new OperationResult();
-
+
Object xTransactionId = exchange.getIn().getHeader("X-TransactionId");
if (xTransactionId == null) {
xTransactionId = NodeUtils.getRandomTxnId();
@@ -116,37 +95,34 @@ public class GeoVisualizationProcessor {
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
- */
+ /* 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());
-
+ 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())) {
+ if(PARAMETER_KEY.equals(parameter.getName())) {
entityType = parameter.getName();
}
}
-
- String parameters = SEARCH_PARAMETER + entityType;
- String requestString = String.format("/%s/%s/%s", elasticConfig.getTopographicalSearchIndex(),
- SEARCH_STRING, parameters);
+
+ String api = SEARCH_STRING + SEARCH_PARAMETER + entityType;
+
+ final String requestUrl = elasticSearchAdapter.buildElasticSearchUrlForApi(topographicalSearchIndexName, api);
try {
- final String fullUrlStr = ServletUtils.getFullUrl(elasticConfig, requestString);
- OperationResult opResult = search.doGet(fullUrlStr, "application/json");
+
+ 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 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);
diff --git a/src/main/java/org/onap/aai/sparky/inventory/entity/GeoIndexDocument.java b/src/main/java/org/onap/aai/sparky/inventory/entity/GeoIndexDocument.java
index 3596c54..383172a 100644
--- a/src/main/java/org/onap/aai/sparky/inventory/entity/GeoIndexDocument.java
+++ b/src/main/java/org/onap/aai/sparky/inventory/entity/GeoIndexDocument.java
@@ -51,10 +51,10 @@ public class GeoIndexDocument implements Serializable, IndexDocument {
protected String latitude;
protected String longitude;
protected String selfLink;
-
+
@JsonIgnore
protected OxmEntityLookup oxmEntityLookup;
-
+
@JsonIgnore
protected ObjectMapper mapper = new ObjectMapper();
// generated, SHA-256 digest
@@ -164,29 +164,27 @@ public class GeoIndexDocument implements Serializable, IndexDocument {
*
* @see com.att.queryrouter.dao.DocumentStoreDataEntity#getAsJson()
*/
-
+
@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)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
*/
@Override
@@ -200,16 +198,14 @@ public class GeoIndexDocument implements Serializable, IndexDocument {
*/
OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(entityType);
- String entityPrimaryKeyName =
- NodeUtils.concatArray(descriptor.getPrimaryKeyAttributeNames(), "/");
+ String entityPrimaryKeyName = NodeUtils.concatArray(
+ descriptor.getPrimaryKeyAttributeNames(), "/");
this.id =
NodeUtils.generateUniqueShaDigest(entityType, entityPrimaryKeyName, entityPrimaryKeyValue);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
@@ -288,5 +284,5 @@ public class GeoIndexDocument implements Serializable, IndexDocument {
public void setId(String id) {
this.id = id;
}
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/inventory/entity/TopographicalEntity.java b/src/main/java/org/onap/aai/sparky/inventory/entity/TopographicalEntity.java
index 7736255..5467238 100644
--- a/src/main/java/org/onap/aai/sparky/inventory/entity/TopographicalEntity.java
+++ b/src/main/java/org/onap/aai/sparky/inventory/entity/TopographicalEntity.java
@@ -144,9 +144,7 @@ public class TopographicalEntity implements Serializable {
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/logging/AaiUiMsgs.java b/src/main/java/org/onap/aai/sparky/logging/AaiUiMsgs.java
index 5854bc7..1c7cb78 100644
--- a/src/main/java/org/onap/aai/sparky/logging/AaiUiMsgs.java
+++ b/src/main/java/org/onap/aai/sparky/logging/AaiUiMsgs.java
@@ -75,7 +75,8 @@ public enum AaiUiMsgs implements LogMessageEnum {
/** Arguments: {0} = Reason. */
FAILED_TO_ADD_SKELETON_NODE,
/** Arguments: {0} = Reason. */
- FAILED_TO_PROCESS_SKELETON_NODE, INVALID_RESOLVE_STATE_DURING_INIT,
+ FAILED_TO_PROCESS_SKELETON_NODE,
+ INVALID_RESOLVE_STATE_DURING_INIT,
/** Arguments: {0} = Reason. */
FAILED_TO_PROCESS_INITIAL_STATE,
/** Arguments: {0} = Relationship. */
@@ -127,7 +128,7 @@ public enum AaiUiMsgs implements LogMessageEnum {
/** Arguments: {0} = Current state, {1} = New state {2} = Triggering action */
ACTIVE_INV_NODE_CHANGE_STATE_NO_NODE_ID,
/** Arguments: {0} = Count Key {1} = Aggregation Key. */
- AGGREGATION_KEY_ERROR,
+ AGGREGATION_KEY_ERROR,
/** Arguments: {0} Configuration */
CONFIGURATION_ERROR,
/** Arguments: {0} = Source. */
@@ -141,7 +142,7 @@ public enum AaiUiMsgs implements LogMessageEnum {
/** No argument */
INVALID_REQUEST_PARAMS,
/** Arguments: {0} = Key. */
- ERROR_SORTING_VIOLATION_DATA,
+ ERROR_SORTING_VIOLATION_DATA,
/** Arguments: {0} = exception */
ERROR_SERVLET_PROCESSSING,
/** Arguments: {0} = exception */
@@ -210,7 +211,7 @@ public enum AaiUiMsgs implements LogMessageEnum {
COLLECT_TOTAL,
/** Arguments: {0} Number of required fetches */
SYNC_NUMBER_REQ_FETCHES,
- /** Arguments: {0} Number of total fetches {1} Number of available records */
+ /** Arguments: {0} Number of total fetches {1} Number of available records*/
SYNC_NUMBER_TOTAL_FETCHES,
/** Arguments: {0} Completion Time */
COLLECT_TOTAL_TIME,
@@ -241,32 +242,33 @@ public enum AaiUiMsgs implements LogMessageEnum {
/** No argument */
HISTORICAL_SYNC_PENDING,
/** Arguments: {0} = Time */
- HISTORICAL_SYNC_TO_BEGIN,
+ HISTORICAL_SYNC_TO_BEGIN,
/** Arguments: {0} = message */
DEBUG_GENERIC,
/** Arguments: {0} = message */
INFO_GENERIC,
/** Arguments: {0} = message */
WARN_GENERIC,
- /** Arguments: {0} = context {1} = Exception */
+ /** Arguments: {0} = context {1} = Exception*/
INTERRUPTED,
/** Arguments: {0} = Entity Type {1} Entity */
GEO_SYNC_IGNORING_ENTITY,
/** Arguments: {0} = reason */
OXM_LOADING_ERROR,
/** Arguments: {0} = type */
- OXM_FAILED_RETRIEVAL, OXM_FILE_NOT_FOUND,
+ OXM_FAILED_RETRIEVAL,
+ OXM_FILE_NOT_FOUND,
/** No argument */
OXM_READ_ERROR_NONVERBOSE,
/** Arguments: {0} = OXM File name */
OXM_READ_ERROR_VERBOSE,
/** No argument */
OXM_PARSE_ERROR_NONVERBOSE,
- /** Arguments: {0} = OXM File name {1} = Exception */
+ /** Arguments: {0} = OXM File name {1} = Exception*/
OXM_PARSE_ERROR_VERBOSE,
/** Arguments: {0} = Numerical value for loaded OXM version */
OXM_LOAD_SUCCESS,
- /** Arguments: {0} = Entity {1} = Found property-value */
+ /** Arguments: {0} = Entity {1} = Found property-value*/
OXM_PROP_DEF_ERR_CROSS_ENTITY_REF,
/** Arguments: {0} = Sequence Number */
ETAG_RETRY_SEQ,
@@ -368,7 +370,7 @@ public enum AaiUiMsgs implements LogMessageEnum {
SKIP_PERIODIC_SYNC_AS_SYNC_DIDNT_FINISH,
/** Arguments: {0} = Message */
SYNC_DURATION,
- /** Arguments: {0} = Entity Type */
+ /** Arguments: {0} = Entity Type */
ENTITY_SYNC_FAILED_DESCRIPTOR_NOT_FOUND,
/** Arguments: {0} = AAI Query Result */
ENTITY_SYNC_FAILED_DURING_AAI_RESPONSE_CONVERSION,
@@ -380,10 +382,7 @@ public enum AaiUiMsgs implements LogMessageEnum {
SELF_LINK_DETERMINATION_FAILED_UNEXPECTED_LINKS,
/** Arguments: {1} = Query {2} = Operation Result Code {3} = Operation Result */
SELF_LINK_RETRIEVAL_FAILED,
- /**
- * Arguments: {0} = Controller {1} = Synchronizer Current Internal State {2} = New State {3} =
- * Caused By Action
- */
+ /** Arguments: {0} = Controller {1} = Synchronizer Current Internal State {2} = New State {3} = Caused By Action */
SYNC_INTERNAL_STATE_CHANGED,
/** Arguments: {0} = Message */
SYNC_INVALID_CONFIG_PARAM,
@@ -402,7 +401,8 @@ public enum AaiUiMsgs implements LogMessageEnum {
/** Arguments: {0} = File name */
FILE_NOT_FOUND,
/** Arguments: {0} = File name */
- FILE_READ_IN_PROGRESS, ERROR_LOADING_OXM_SUGGESTIBLE_ENTITIES,
+ FILE_READ_IN_PROGRESS,
+ ERROR_LOADING_OXM_SUGGESTIBLE_ENTITIES,
/** Arguments: {0} = Error message */
ES_SUGGESTION_SEARCH_ENTITY_SYNC_ERROR,
/** Arguments: {0} = Error message */
@@ -426,12 +426,15 @@ public enum AaiUiMsgs implements LogMessageEnum {
/** Arguments: {0} = URL to extract parameter from */
ERROR_REMOVING_URL_PARAM,
/** Arguments: {0} = Hash value */
- ERROR_INVALID_HASH, ERROR_HASH_NOT_FOUND, ERROR_FILTERS_NOT_FOUND, ERROR_READING_HTTP_REQ_PARAMS,
+ ERROR_INVALID_HASH,
+ ERROR_HASH_NOT_FOUND,
+ ERROR_FILTERS_NOT_FOUND,
+ ERROR_READING_HTTP_REQ_PARAMS,
/** Arguments: {0} = Exception */
ERROR_D3_GRAPH_VISUALIZATION,
/** Arguments: {0} = Exception */
ERROR_AAI_QUERY_WITH_RETRY,
- /** Arguments: Error extracting resource path from self-link. Error = {0} */
+ /** Arguments: Error extracting resource path from self-link. Error = {0} */
ERROR_EXTRACTING_RESOURCE_PATH_FROM_LINK,
/** Arguments: {0} = Schema file location */
ERROR_READING_JSON_SCHEMA,
diff --git a/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java b/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java
index dd040a2..f523474 100644
--- a/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java
+++ b/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java
@@ -29,9 +29,8 @@ import javax.servlet.http.HttpServletResponse;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.elasticsearch.SearchAdapter;
-import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
import org.onap.aai.sparky.logging.AaiUiMsgs;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
/**
* The Class ServletUtils.
@@ -48,7 +47,7 @@ public class ServletUtils {
* @return the operation result
* @throws Exception the exception
*/
- public static OperationResult executeGetQuery(Logger logger, SearchAdapter search,
+ public static OperationResult executeGetQuery(Logger logger, SearchServiceAdapter search,
HttpServletResponse response, String requestUrl) throws Exception {
OperationResult opResult = search.doGet(requestUrl, "application/json");
@@ -74,7 +73,7 @@ public class ServletUtils {
* @return the operation result
* @throws Exception the exception
*/
- public static OperationResult executePostQuery(Logger logger, SearchAdapter search,
+ public static OperationResult executePostQuery(Logger logger, SearchServiceAdapter search,
HttpServletResponse response, String requestUrl, String requestJsonPayload) throws Exception {
OperationResult opResult = search.doPost(requestUrl, requestJsonPayload, "application/json");
@@ -100,8 +99,8 @@ public class ServletUtils {
*/
public static void handleSearchServletErrors(Logger logger, String errorMsg, Exception exc,
HttpServletResponse response) throws IOException {
- String errorLogMsg =
- (exc == null ? errorMsg : errorMsg + ". Error:" + exc.getLocalizedMessage());
+ String errorLogMsg = (exc == null ? errorMsg : errorMsg + ". Error:"
+ + exc.getLocalizedMessage());
logger.error(AaiUiMsgs.ERROR_GENERIC, errorLogMsg);
response.setContentType("application/json");
PrintWriter out = response.getWriter();
@@ -153,9 +152,9 @@ public class ServletUtils {
* @param resourceUrl the resource url
* @return the full url
*/
- public static String getFullUrl(ElasticSearchConfig elasticConfig, String resourceUrl) {
- final String host = elasticConfig.getIpAddress();
- final String port = elasticConfig.getHttpPort();
+ public static String getFullUrl(String eHost,String ePort, String resourceUrl) {
+ final String host = eHost;
+ final String port = ePort;
return String.format("http://%s:%s%s", host, port, resourceUrl);
}
}
diff --git a/src/main/java/org/onap/aai/sparky/search/EntityCountHistoryProcessor.java b/src/main/java/org/onap/aai/sparky/search/EntityCountHistoryProcessor.java
index e2eef7a..849ead7 100644
--- a/src/main/java/org/onap/aai/sparky/search/EntityCountHistoryProcessor.java
+++ b/src/main/java/org/onap/aai/sparky/search/EntityCountHistoryProcessor.java
@@ -38,14 +38,11 @@ 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.elasticsearch.SearchAdapter;
-import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
+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.logging.util.ServletUtils;
import org.onap.aai.sparky.util.NodeUtils;
import org.onap.aai.sparky.util.RestletUtils;
-import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.ClientInfo;
@@ -67,46 +64,45 @@ public class EntityCountHistoryProcessor implements Processor {
private static final long serialVersionUID = 1L;
- private SearchAdapter search = null;
- private ElasticSearchConfig elasticConfig = null;
- private VisualizationConfigs visualConfigs = null;
+ private ElasticSearchAdapter elasticSearchAdapter = null;
private ObjectMapper mapper;
-
- private static final String SEARCH_STRING = "_search";
+
+ 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> vnfEntityTypesToSummarize;
- private boolean summarizevnf = false;
+ 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) {
- public EntityCountHistoryProcessor(VisualizationConfigs visualizationConfigs) {
+ this.elasticSearchAdapter = elasticSearchAdapter;
+ this.entityCountHistoryIndexName = entityCountHistoryIndexName;
- this.visualConfigs = visualizationConfigs;
- vnfEntityTypesToSummarize =
- Arrays.asList(visualConfigs.getVnfEntityTypes().toLowerCase().split("[\\s,]+"));
- summarizevnf = visualConfigs.getEntityTypesToSummarize().toLowerCase().contains("vnf");
- try {
- if (elasticConfig == null) {
- elasticConfig = ElasticSearchConfig.getConfig();
- }
+ entityTypesToSummarize =
+ Arrays.asList(entityTypesToSummarizeDelimitedList.toLowerCase().split("[\\s,]+"));
- if (search == null) {
- search = new SearchAdapter();
- }
- this.mapper = new ObjectMapper();
- this.mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.CONFIGURATION_ERROR, exc.getLocalizedMessage());
- }
- }
+ 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
*
@@ -115,51 +111,51 @@ public class EntityCountHistoryProcessor implements Processor {
@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);
+
+ 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);
}
@@ -253,7 +249,7 @@ public class EntityCountHistoryProcessor implements Processor {
for (final JsonNode entityNode : bucketsNode) {
String entityType = entityNode.get("key").asText();
- boolean isAVnf = vnfEntityTypesToSummarize.contains(entityType);
+ boolean isAVnf = vnfEntityTypes.contains(entityType);
long countValue = 0;
if (isAVnf || entityCountInTable.get(entityType) != null) {
@@ -267,7 +263,7 @@ public class EntityCountHistoryProcessor implements Processor {
/*
* Special case: Add all the VNF types together to get aggregate count
*/
- if (summarizevnf && isAVnf) {
+ if (summarizeVnfs && isAVnf) {
vnfCount += countValue;
countValue = vnfCount;
entityType = "vnf";
@@ -305,15 +301,14 @@ public class EntityCountHistoryProcessor implements Processor {
public OperationResult getResults(Response response, String type) {
OperationResult operationResult = new OperationResult();
- String requestString =
- String.format("/%s/%s?pretty", elasticConfig.getEntityCountHistoryIndex(), SEARCH_STRING);
-
String reqPayload = EntityHistoryQueryBuilder.getQuery(type).toString();
try {
- final String fullUrlStr = ServletUtils.getFullUrl(elasticConfig, requestString);
- OperationResult opResult =
- restletUtils.executePostQuery(LOG, search, response, fullUrlStr, reqPayload);
+ 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)) {
@@ -355,8 +350,7 @@ public class EntityCountHistoryProcessor implements Processor {
*/
private Map<String, Long> initializeEntityMap() {
Map<String, Long> entityMap = new HashMap<String, Long>();
- String[] entityTypes = visualConfigs.getEntityTypesToSummarize().split(",");
- for (String entity : entityTypes) {
+ for (String entity : entityTypesToSummarize) {
entityMap.put(entity, (long) 0);
}
@@ -403,15 +397,9 @@ public class EntityCountHistoryProcessor implements Processor {
return typeParameter;
}
- public void setElasticConfig(ElasticSearchConfig elasticConfig) {
- this.elasticConfig = elasticConfig;
- }
public void setRestletUtils(RestletUtils restletUtils) {
this.restletUtils = restletUtils;
}
- public void setSearch(SearchAdapter search) {
- this.search = search;
- }
}
diff --git a/src/main/java/org/onap/aai/sparky/search/EntityTypeSummary.java b/src/main/java/org/onap/aai/sparky/search/EntityTypeSummary.java
index 4e55a30..cfc7a61 100644
--- a/src/main/java/org/onap/aai/sparky/search/EntityTypeSummary.java
+++ b/src/main/java/org/onap/aai/sparky/search/EntityTypeSummary.java
@@ -28,23 +28,23 @@ import java.util.List;
public class EntityTypeSummary {
private int totalChartHits;
private List<EntityTypeSummaryBucket> buckets = new ArrayList<>();
-
+
public int getTotalChartHits() {
return totalChartHits;
}
-
+
public List<EntityTypeSummaryBucket> getBuckets() {
return buckets;
}
-
+
public void setTotalChartHits(int totalChartHits) {
this.totalChartHits = totalChartHits;
}
-
+
public void setBuckets(List<EntityTypeSummaryBucket> buckets) {
this.buckets = buckets;
}
-
+
public void addBucket(EntityTypeSummaryBucket bucket) {
this.buckets.add(bucket);
}
diff --git a/src/main/java/org/onap/aai/sparky/search/EntityTypeSummaryBucket.java b/src/main/java/org/onap/aai/sparky/search/EntityTypeSummaryBucket.java
index 6185559..bc08e60 100644
--- a/src/main/java/org/onap/aai/sparky/search/EntityTypeSummaryBucket.java
+++ b/src/main/java/org/onap/aai/sparky/search/EntityTypeSummaryBucket.java
@@ -25,19 +25,19 @@ package org.onap.aai.sparky.search;
public class EntityTypeSummaryBucket {
private int count;
private String key;
-
+
public int getCount() {
return count;
}
-
+
public String getKey() {
return key;
}
-
+
public void setCount(int count) {
this.count = count;
}
-
+
public void setKey(String key) {
this.key = key;
}
diff --git a/src/main/java/org/onap/aai/sparky/search/SearchEntityProperties.java b/src/main/java/org/onap/aai/sparky/search/SearchEntityProperties.java
index 56e8fdd..c65811e 100644
--- a/src/main/java/org/onap/aai/sparky/search/SearchEntityProperties.java
+++ b/src/main/java/org/onap/aai/sparky/search/SearchEntityProperties.java
@@ -28,19 +28,19 @@ import java.util.Map;
public class SearchEntityProperties {
private String type;
private Map<String, String> fields = new HashMap<>();
-
+
public String getType() {
return type;
}
-
+
public Map<String, String> getFields() {
return fields;
}
-
+
public void setType(String type) {
this.type = type;
}
-
+
public void setFields(Map<String, String> field) {
this.fields = field;
}
diff --git a/src/main/java/org/onap/aai/sparky/search/SearchResponse.java b/src/main/java/org/onap/aai/sparky/search/SearchResponse.java
index cddce49..0620ad1 100644
--- a/src/main/java/org/onap/aai/sparky/search/SearchResponse.java
+++ b/src/main/java/org/onap/aai/sparky/search/SearchResponse.java
@@ -31,7 +31,7 @@ import org.onap.aai.sparky.search.entity.SearchSuggestion;
* The Class SearchResponse.
*/
public class SearchResponse {
-
+
private long processingTimeInMs;
private int totalFound;
@@ -53,11 +53,11 @@ public class SearchResponse {
public void setProcessingTimeInMs(long processingTimeInMs) {
this.processingTimeInMs = processingTimeInMs;
}
-
+
public int getTotalFound() {
return totalFound;
}
-
+
public void setTotalFound(int totalFound) {
this.totalFound = totalFound;
}
@@ -75,12 +75,13 @@ public class SearchResponse {
*
* @param suggestionEntry that will be converted to JSON
*/
- public void addSuggestion(SearchSuggestion suggestionEntity) {
+ public void addSuggestion(SearchSuggestion suggestionEntity){
suggestions.add(suggestionEntity);
}
-
+
/**
- * Increments the total number of hits for this SearchResponse by the value passed in.
+ * Increments the total number of hits for this SearchResponse by
+ * the value passed in.
*
* @param additionalCount - Count to increment the total found
*/
@@ -93,7 +94,7 @@ public class SearchResponse {
return "SearchResponse [processingTimeInMs=" + processingTimeInMs + ", totalFound=" + totalFound
+ ", " + (suggestions != null ? "suggestions=" + suggestions : "") + "]";
}
-
-
-
+
+
+
}
diff --git a/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java b/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java
new file mode 100644
index 0000000..f1ae6b1
--- /dev/null
+++ b/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java
@@ -0,0 +1,137 @@
+/**
+ * ============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.search;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import org.onap.aai.cl.mdc.MdcContext;
+import org.onap.aai.restclient.client.Headers;
+import org.onap.aai.restclient.client.OperationResult;
+import org.onap.aai.restclient.client.RestClient;
+import org.onap.aai.sparky.dal.rest.RestClientFactory;
+import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
+import org.slf4j.MDC;
+
+
+/**
+ * The Class SearchServiceAdapter.
+ */
+public class SearchServiceAdapter {
+
+ private static final String VALUE_QUERY = "query";
+
+ private RestClient client;
+ private RestEndpointConfig endpointConfig;
+ private String serviceApiVersion;
+
+ private Map<String, List<String>> commonHeaders;
+
+ /**
+ * Instantiates a new search adapter.
+ * @throws Exception
+ */
+ public SearchServiceAdapter(RestEndpointConfig endpointConfig, String serviceApiVersion) throws Exception {
+
+ client = RestClientFactory.buildClient(endpointConfig);
+
+ commonHeaders = new HashMap<String, List<String>>();
+ commonHeaders.put("Accept", Arrays.asList("application/json"));
+ commonHeaders.put(Headers.FROM_APP_ID, Arrays.asList("AAI-UI"));
+
+ this.serviceApiVersion = serviceApiVersion;
+ this.endpointConfig = endpointConfig;
+ }
+
+ public String getServiceApiVersion() {
+ return serviceApiVersion;
+ }
+
+ public void setServiceApiVersion(String serviceApiVersion) {
+ this.serviceApiVersion = serviceApiVersion;
+ }
+
+ public RestEndpointConfig getEndpointConfig() {
+ return endpointConfig;
+ }
+
+ public void setEndpointConfig(RestEndpointConfig endpointConfig) {
+ this.endpointConfig = endpointConfig;
+ }
+
+ public OperationResult doPost(String url, String jsonPayload, String acceptContentType) {
+ OperationResult or = client.post(url, jsonPayload, getTxnHeader(),
+ MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON_TYPE);
+ return new OperationResult(or.getResultCode(), or.getResult());
+ }
+
+ public OperationResult doGet(String url, String acceptContentType) {
+ OperationResult or =
+ client.get(url, getTxnHeader(), MediaType.APPLICATION_JSON_TYPE);
+ return new OperationResult(or.getResultCode(), or.getResult());
+ }
+
+ public OperationResult doPut(String url, String payload, String acceptContentType) {
+ OperationResult or = client.put(url, payload, getTxnHeader(),
+ MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON_TYPE);
+ return new OperationResult(or.getResultCode(), or.getResult());
+ }
+
+ public OperationResult doDelete(String url, String acceptContentType) {
+
+ OperationResult or =
+ client.delete(url, getTxnHeader(), 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>>();
+ headers.putAll(this.commonHeaders);
+ headers.put("X-TransactionId", Arrays.asList(MDC.get(MdcContext.MDC_REQUEST_ID)));
+ headers.put("X-FromAppId", Arrays.asList(MDC.get(MdcContext.MDC_PARTNER_NAME)));
+ return headers;
+ }
+
+ /**
+ * Get Full URL for search
+ *
+ * @param api the api
+ * @param indexName
+ * @return the full url
+ */
+ public String buildSearchServiceQueryUrl(String indexName) {
+ return buildSearchServiceUrlForApi(indexName, VALUE_QUERY);
+ }
+
+ 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);
+ }
+
+
+}
diff --git a/src/main/java/org/onap/aai/sparky/search/UnifiedSearchProcessor.java b/src/main/java/org/onap/aai/sparky/search/UnifiedSearchProcessor.java
index 2983163..1388a6e 100644
--- a/src/main/java/org/onap/aai/sparky/search/UnifiedSearchProcessor.java
+++ b/src/main/java/org/onap/aai/sparky/search/UnifiedSearchProcessor.java
@@ -51,7 +51,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class UnifiedSearchProcessor {
protected static final String HASH_ID_KEY = "hashId";
-
+
private static final Logger LOG =
LoggerFactory.getInstance().getLogger(UnifiedSearchProcessor.class);
@@ -63,7 +63,7 @@ public class UnifiedSearchProcessor {
mapper = new ObjectMapper();
this.useOrderedSearchProviderKeys = false;
}
-
+
public boolean isUseOrderedSearchProviderKeys() {
return useOrderedSearchProviderKeys;
}
@@ -86,10 +86,8 @@ public class UnifiedSearchProcessor {
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
- */
+ /* 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();
@@ -102,7 +100,7 @@ public class UnifiedSearchProcessor {
try {
String payload = exchange.getIn().getBody(String.class);
-
+
if (payload == null || payload.isEmpty()) {
LOG.error(AaiUiMsgs.SEARCH_SERVLET_ERROR, "Request Payload is empty");
@@ -115,7 +113,7 @@ public class UnifiedSearchProcessor {
QuerySearchEntity searchRequest = mapper.readValue(payload, QuerySearchEntity.class);
int maxResultsPerSearch = Integer.valueOf(searchRequest.getMaxResults());
-
+
Map<String, List<SearchSuggestion>> searchProviderSuggestions =
new HashMap<String, List<SearchSuggestion>>();
@@ -128,17 +126,17 @@ public class UnifiedSearchProcessor {
}
/*
- * Using ordered search provider keys allows us to deterministically calculate how many
- * results from each provider should be returned. At the moment, this behavior is primarily
- * only beneficial to test classes. As there is a cost to sorted-collections in the call
- * processing path, this behavior has been made optional.
+ * Using ordered search provider keys allows us to deterministically calculate how many results
+ * from each provider should be returned. At the moment, this behavior is primarily only beneficial
+ * to test classes. As there is a cost to sorted-collections in the call processing path, this behavior
+ * has been made optional.
*/
-
+
if (useOrderedSearchProviderKeys) {
searchProviderSuggestions =
new TreeMap<String, List<SearchSuggestion>>(searchProviderSuggestions);
}
-
+
if (totalSuggestionsFromProviders > 0) {
int suggestionIndex = 0;
@@ -146,7 +144,8 @@ public class UnifiedSearchProcessor {
Set<Entry<String, List<SearchSuggestion>>> searchProviderResults =
searchProviderSuggestions.entrySet();
- while (totalAdded < maxResultsPerSearch && (totalAdded < totalSuggestionsFromProviders)) {
+ while (totalAdded < maxResultsPerSearch
+ && (totalAdded < totalSuggestionsFromProviders)) {
for (Entry<String, List<SearchSuggestion>> searchProviderResultList : searchProviderResults) {
@@ -175,8 +174,7 @@ public class UnifiedSearchProcessor {
processTime = System.currentTimeMillis() - processTime;
searchResponse.setProcessingTimeInMs(processTime);
- Response response =
- exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
+ Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
response.setStatus(Status.SUCCESS_OK);
response.setEntity(searchResponseJson, MediaType.APPLICATION_JSON);
exchange.getOut().setBody(response);
@@ -189,7 +187,7 @@ public class UnifiedSearchProcessor {
String.class);
}
}
-
+
public SearchProviderRegistry getSearchProviderRegistry() {
return searchProviderRegistry;
}
diff --git a/src/main/java/org/onap/aai/sparky/search/api/SearchProvider.java b/src/main/java/org/onap/aai/sparky/search/api/SearchProvider.java
index e593c3e..fe536ef 100644
--- a/src/main/java/org/onap/aai/sparky/search/api/SearchProvider.java
+++ b/src/main/java/org/onap/aai/sparky/search/api/SearchProvider.java
@@ -28,7 +28,7 @@ import org.onap.aai.sparky.search.entity.QuerySearchEntity;
import org.onap.aai.sparky.search.entity.SearchSuggestion;
public interface SearchProvider {
-
+
List<SearchSuggestion> search(QuerySearchEntity queryRequest);
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/search/config/SuggestionConfig.java b/src/main/java/org/onap/aai/sparky/search/config/SuggestionConfig.java
index 9208354..458a899 100644
--- a/src/main/java/org/onap/aai/sparky/search/config/SuggestionConfig.java
+++ b/src/main/java/org/onap/aai/sparky/search/config/SuggestionConfig.java
@@ -22,100 +22,21 @@
*/
package org.onap.aai.sparky.search.config;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
-
-import org.onap.aai.sparky.util.ConfigHelper;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
public class SuggestionConfig {
- public static final String CONFIG_FILE =
- TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "suggestive-search.properties";
-
- private static SuggestionConfig config;
- private static final String INDEX_SEARCH_MAPPER_DEFAULT =
- "elasticsearch.autosuggestIndexname:SearchServiceWrapper,elasticsearch.indexName:VnfSearchService";
-
- private Map<String, String> searchIndexToSearchService;
-
- private static final String CALLED_PAIRING_KEY_DEFAULT =
- "volume-group-id,volume-group-name,physical-location-id,data-center-code,complex-name,tenant-id,tenant-name,vserver-id,vserver-name,vserver-name2,hostname,pserver-name2,pserver-id,global-customer-id,subscriber-name,service-instance-id,service-instance-name,link-name,vpn-id,vpn-name,vpe-id,vnf-id,vnf-name,vnf-name2,vnfc-name,network-id,network-name,network-policy-id,vf-module-id,vf-module-name,vnf-id2,pnf-name,circuit-id";
- private static final String CALLED_PAIRING_VALUE_DEFAULT = "called";
- private static final String AT_PAIRING_KEY_DEFAULT =
- "street1,street2,postal-code,ipv4-oam-address,network-policy-fqdn";
- private static final String AT_PAIRING_VALUE_DEFAULT = "at";
- private static final String DEFAULT_PAIRING_DEFAULT_VALUE = "with";
- private String conjunctionForAt;
- Map<String, String> pairingList;
+
+
+ private Map<String, String> pairingList;
private Collection<String> stopWords;
private String defaultPairingValue;
+ private String ViSuggestionRoute;
public SuggestionConfig() {}
- /**
- * Returns initialized instance as per singleton pattern.
- *
- * @return initialized SuggestionConfig instance
- */
- public static SuggestionConfig getConfig() {
- if (config == null) {
- config = new SuggestionConfig();
- config.initializeConfigProperties();
- }
- return config;
- }
-
- public static void setConfig(SuggestionConfig config) {
- SuggestionConfig.config = config;
- }
-
- public void initializeConfigProperties() {
-
- Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
- Properties suggestionProps = ConfigHelper.getConfigWithPrefix("suggestion", props);
-
- String indexSearchMapper = suggestionProps.getProperty("routing", INDEX_SEARCH_MAPPER_DEFAULT);
- String[] indexesToSearchClassesArray = indexSearchMapper.split(",");
- searchIndexToSearchService = new HashMap<String, String>();
- for (String pair : indexesToSearchClassesArray) {
- String[] subPair = pair.split(":");
- searchIndexToSearchService.put(subPair[0], subPair[1]);
- }
-
- defaultPairingValue =
- suggestionProps.getProperty("pairing.default.value", DEFAULT_PAIRING_DEFAULT_VALUE);
- String calledValue =
- suggestionProps.getProperty("pairing.called.value", CALLED_PAIRING_VALUE_DEFAULT);
- String[] calledPairingArray =
- suggestionProps.getProperty("pairing.called.key", CALLED_PAIRING_KEY_DEFAULT).split(",");
- pairingList = new HashMap<String, String>();
- for (String calledField : calledPairingArray) {
- pairingList.put(calledField, calledValue);
- }
-
- this.conjunctionForAt =
- suggestionProps.getProperty("pairing.at.value", AT_PAIRING_VALUE_DEFAULT);
- String[] atPairingArray =
- suggestionProps.getProperty("pairing.at.key", AT_PAIRING_KEY_DEFAULT).split(",");
- for (String atField : atPairingArray) {
- pairingList.put(atField, conjunctionForAt);
- }
-
- stopWords = Arrays.asList(suggestionProps.getProperty("stopwords", "").split(","));
-
- }
-
- public void setSearchIndexToSearchService(Map<String, String> searchIndexToSearchService) {
- this.searchIndexToSearchService = searchIndexToSearchService;
- }
-
- public Map<String, String> getSearchIndexToSearchService() {
- return searchIndexToSearchService;
- }
public Collection<String> getStopWords() {
return stopWords;
@@ -129,7 +50,7 @@ public class SuggestionConfig {
return pairingList;
}
- public void setPairingList(Map<String, String> pairingList) {
+ public void setPairingList(HashMap<String, String> pairingList) {
this.pairingList = pairingList;
}
@@ -141,12 +62,12 @@ public class SuggestionConfig {
this.defaultPairingValue = defaultPairingValue;
}
- public String getConjunctionForAt() {
- return conjunctionForAt;
+ public String getViSuggestionRoute() {
+ return ViSuggestionRoute;
}
- public void setConjunctionForAt(String conjunctionForAt) {
- this.conjunctionForAt = conjunctionForAt;
+ public void setViSuggestionRoute(String ViSuggestionRoute) {
+ this.ViSuggestionRoute = ViSuggestionRoute;
}
diff --git a/src/main/java/org/onap/aai/sparky/search/entity/ExternalSearchRequestEntity.java b/src/main/java/org/onap/aai/sparky/search/entity/ExternalSearchRequestEntity.java
deleted file mode 100644
index 465eadc..0000000
--- a/src/main/java/org/onap/aai/sparky/search/entity/ExternalSearchRequestEntity.java
+++ /dev/null
@@ -1,69 +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.search.entity;
-
-public class ExternalSearchRequestEntity {
- private String view;
- private String entityId;
- private String entityType;
-
- public ExternalSearchRequestEntity() {
- this.view = "";
- this.entityId = "";
- this.entityType = "";
- }
-
- public String getView() {
- return view;
- }
-
- public void setView(String view) {
- this.view = view;
- }
-
- public String getEntityId() {
- return entityId;
- }
-
- public void setEntityId(String entityId) {
- this.entityId = entityId;
- }
-
- public String getEntityType() {
- return entityType;
- }
-
- public void setEntityType(String entityType) {
- this.entityType = entityType;
- }
-
- public String createQueryString() {
- return entityId + " " + entityType;
- }
-
- @Override
- public String toString() {
- return "ExternalRequestEntitySearchEntity [view=" + view + ", entityId=" + entityId
- + ", entityType=" + entityType + "]";
- }
-}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java b/src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java
index 5f5dc74..9276991 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/FilterElasticSearchAdapter.java
@@ -26,118 +26,89 @@ import java.util.ArrayList;
import java.util.List;
import javax.json.JsonObject;
+import javax.ws.rs.core.MediaType;
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.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.elasticsearch.SearchAdapter;
-import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
-import org.onap.aai.sparky.dataintegrity.config.DiUiConstants;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
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.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
/**
- * Performs all Elasticsearch related queries for filters related to the Sparky-FE.
+ * Performs all Elasticsearch related queries for filters related to
+ * the Sparky-FE.
*
* @author RICHARV
*/
public class FilterElasticSearchAdapter {
-
- private static ElasticSearchConfig esConfig = null;
- private static SearchAdapter search = null;
- private static final String ES_SEARCH_API = TierSupportUiConstants.ES_SEARCH_API;
- private static final String APP_JSON = DiUiConstants.APP_JSON;
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(FilterElasticSearchAdapter.class);
+
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(FilterElasticSearchAdapter.class);
private static final String AGGS = "aggregations";
private static final String CONTAINER = "default";
private static final String BUCKETS = "buckets";
private static final String FILTER_VALUE_KEY = "key";
-
-
- public FilterElasticSearchAdapter() {
- try {
- if (esConfig == null) {
- esConfig = ElasticSearchConfig.getConfig();
- }
- if (search == null) {
- search = new SearchAdapter();
- }
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.CONFIGURATION_ERROR, "Search");
- }
- }
-
- /**
- * Get Full URL for search using elastic search configuration.
- *
- * @param api the api
- * @return the full url
- */
- private String getFullUrl(String indexName, String api) {
- final String host = esConfig.getIpAddress();
- final String port = esConfig.getHttpPort();
- return String.format("http://%s:%s/%s/%s", host, port, indexName, api);
+ private ElasticSearchAdapter elasticSearchAdapter;
+
+ public FilterElasticSearchAdapter(ElasticSearchAdapter elasticSearchAdapter) {
+ this.elasticSearchAdapter = elasticSearchAdapter;
}
-
+
/**
- * For a given UiFilterEntity, will attempt to contact an Elasticsearch instance and fetch all
- * possible values for filter's field name.
+ * For a given UiFilterEntity, will attempt to contact an Elasticsearch instance
+ * and fetch all possible values for filter's field name.
*
* @param filter - Filter object against which the search will take place.
* @param sourceData - If present, contains the index name and field value to search against.
* @return - A List of strings if results were found, else empty list.
*/
- public List<String> fetchValuesForFilter(UiFilterEntity filter,
- UiFilterDataSourceConfig dataSourceConfig) {
+ public List<String> fetchValuesForFilter(UiFilterEntity filter, UiFilterDataSourceConfig dataSourceConfig) {
ArrayList<String> filterValues = new ArrayList<String>();
-
- if (dataSourceConfig != null) {
+
+ if(dataSourceConfig != null) {
JsonObject filterValueQuery = null;
- if (dataSourceConfig.getPathToField() != null) {
- filterValueQuery = FilterQueryBuilder.createNestedFilterValueQueryObject(
- dataSourceConfig.getFieldName(), dataSourceConfig.getPathToField());
+ if(dataSourceConfig.getPathToField() != null) {
+ filterValueQuery = FilterQueryBuilder.createNestedFilterValueQueryObject(dataSourceConfig.getFieldName(), dataSourceConfig.getPathToField());
} else {
- filterValueQuery =
- FilterQueryBuilder.createFilterValueQueryObject(dataSourceConfig.getFieldName());
+ filterValueQuery = FilterQueryBuilder.createFilterValueQueryObject(dataSourceConfig.getFieldName());
}
-
- OperationResult opResult =
- search.doPost(getFullUrl(dataSourceConfig.getIndexName(), ES_SEARCH_API),
- filterValueQuery.toString(), APP_JSON);
-
+
+ OperationResult opResult = elasticSearchAdapter.doPost(
+ elasticSearchAdapter.buildElasticSearchUrlForApi(dataSourceConfig.getIndexName(),
+ SparkyConstants.ES_SEARCH_API),
+ filterValueQuery.toString(), MediaType.APPLICATION_JSON_TYPE);
+
String result = opResult.getResult();
- if (opResult.wasSuccessful() && result != null) {
+ if(opResult.wasSuccessful() && result != null) {
JSONObject responseJson = new JSONObject(result);
JSONObject aggJson = responseJson.getJSONObject(AGGS);
-
+
JSONObject containerJson = null;
- if (dataSourceConfig.getPathToField() != null) {
+ if(dataSourceConfig.getPathToField() != null) {
JSONObject nestedContainer = aggJson.getJSONObject(dataSourceConfig.getPathToField());
containerJson = nestedContainer.getJSONObject(dataSourceConfig.getFieldName());
} else {
containerJson = aggJson.getJSONObject(CONTAINER);
}
-
+
JSONArray buckets = containerJson.getJSONArray(BUCKETS);
-
+
int bucketLength = buckets.length();
- for (int i = 0; i < bucketLength; i++) {
+ for(int i = 0; i < bucketLength; i++) {
JSONObject filterBucket = buckets.getJSONObject(i);
-
+
String filterValue = filterBucket.getString(FILTER_VALUE_KEY);
- if (filterValue != null && !filterValue.isEmpty()) {
+ if(filterValue != null && !filterValue.isEmpty()) {
filterValues.add(filterValue);
}
}
} else {
- LOG.error(AaiUiMsgs.ERROR_FETCHING_FILTER_VALUES, String.valueOf(opResult.getResultCode()),
- filter.getFilterName());
+ LOG.error(AaiUiMsgs.ERROR_FETCHING_FILTER_VALUES, String.valueOf(opResult.getResultCode()), filter.getFilterName());
}
}
filterValues.sort(String::compareToIgnoreCase);
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java b/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java
index b22db96..9c3a093 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java
@@ -34,7 +34,7 @@ import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.search.filters.entity.UiFilterEntity;
import org.onap.aai.sparky.search.filters.entity.UiFiltersEntity;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.MediaType;
@@ -44,21 +44,16 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class FilterProcessor {
-
+
private static final Logger LOG = LoggerFactory.getInstance().getLogger(FilterProcessor.class);
-
+
private ObjectMapper mapper;
private FilteredSearchHelper filteredSearchHelper;
-
+
public FilterProcessor() {
this.mapper = new ObjectMapper();
}
-
- public FilterProcessor(FilteredSearchHelper filteredSearchHelper) {
- this.mapper = new ObjectMapper();
- this.filteredSearchHelper = filteredSearchHelper;
- }
-
+
public ObjectMapper getMapper() {
return mapper;
}
@@ -66,26 +61,23 @@ public class FilterProcessor {
public FilteredSearchHelper getFilteredSearchHelper() {
return filteredSearchHelper;
}
-
+
public void setFilteredSearchHelper(FilteredSearchHelper filteredSearchHelper) {
this.filteredSearchHelper = filteredSearchHelper;
}
public void getFiltersWithValues(Exchange exchange) {
- Response response =
- exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
+ Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
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
- */
+ /* Disables automatic Apache Camel Restlet component logging which prints out an undesirable log entry
+ which includes client (e.g. browser) information */
request.setLoggable(false);
-
+
UiFiltersEntity viewFiltersList = null;
boolean wasErrorDuringFilterDiscovery = false;
-
+
try {
String payload = exchange.getIn().getBody(String.class);
@@ -94,8 +86,7 @@ public class FilterProcessor {
LOG.error(AaiUiMsgs.SEARCH_SERVLET_ERROR, "Request Payload is empty");
wasErrorDuringFilterDiscovery = true;
} else {
- String viewName = mapper.readValue(payload, JsonNode.class)
- .get(TierSupportUiConstants.UI_FILTER_VIEW_NAME_PARAMETER).asText();
+ String viewName = mapper.readValue(payload, JsonNode.class).get(SparkyConstants.UI_FILTER_VIEW_NAME_PARAMETER).asText();
if (viewName == null || viewName.isEmpty()) {
wasErrorDuringFilterDiscovery = true;
@@ -103,48 +94,43 @@ public class FilterProcessor {
viewFiltersList = filteredSearchHelper.doFilterDiscovery(viewName);
}
}
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC,
- "FilterProcessor failed to get filter list due to error = " + exc.getMessage());
+ } catch(Exception exc) {
+ LOG.error(AaiUiMsgs.ERROR_GENERIC, "FilterProcessor failed to get filter list due to error = " + exc.getMessage());
wasErrorDuringFilterDiscovery = true;
}
-
+
boolean wasErrorDuringValueSearch = false;
- if (!wasErrorDuringFilterDiscovery) {
+ if(!wasErrorDuringFilterDiscovery) {
try {
- if (!viewFiltersList.getFilters().isEmpty()) {
+ if(!viewFiltersList.getFilters().isEmpty()) {
List<String> filterIds = new ArrayList<String>();
-
- for (UiFilterEntity filterEntity : viewFiltersList.getFilters()) {
+
+ for(UiFilterEntity filterEntity : viewFiltersList.getFilters()) {
filterIds.add(filterEntity.getFilterId());
}
-
+
UiFiltersEntity responseFiltersList = filteredSearchHelper.doFilterEnumeration(filterIds);
-
- JsonObject finalResponse = UiFiltersEntityConverter
- .convertUiFiltersEntityToUnifiedFilterResponse(responseFiltersList);
-
+
+ JsonObject finalResponse = UiFiltersEntityConverter.convertUiFiltersEntityToUnifiedFilterResponse(responseFiltersList);
+
response.setStatus(Status.SUCCESS_OK);
response.setEntity(finalResponse.toString(), MediaType.APPLICATION_JSON);
exchange.getOut().setBody(response);
} else {
wasErrorDuringValueSearch = true;
}
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC,
- "FilterProcessor failed to generate valid unifiedFilterRequest response due to error, "
- + exc.getMessage());
+ } catch(Exception exc) {
+ LOG.error(AaiUiMsgs.ERROR_GENERIC, "FilterProcessor failed to generate valid unifiedFilterRequest response due to error, " + exc.getMessage());
response.setStatus(Status.SERVER_ERROR_INTERNAL);
}
- }
-
+ }
+
// In the case of an error we want to respond with a valid empty response
- if (wasErrorDuringFilterDiscovery || wasErrorDuringValueSearch) {
+ if(wasErrorDuringFilterDiscovery || wasErrorDuringValueSearch) {
response.setStatus(Status.SUCCESS_OK);
- response.setEntity(UiFiltersEntityConverter.generateEmptyResponse().toString(),
- MediaType.APPLICATION_JSON);
+ response.setEntity(UiFiltersEntityConverter.generateEmptyResponse().toString(), MediaType.APPLICATION_JSON);
exchange.getOut().setBody(response);
}
}
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java b/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java
index fb668f0..50c994f 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java
@@ -42,12 +42,11 @@ import org.onap.aai.sparky.search.filters.entity.SearchFilter;
* Used to generate queries against Elasticsearch for filter related queries.
*/
public class FilterQueryBuilder {
-
+
private static final int EXISTING_FILTERS_LIMIT = 0;
private static final int SHOULD_BRANCH_LIMIT = 2;
- public static JsonObject createFilteredBoolQueryObject(List<SearchFilter> searchFilters,
- int minShouldMatch, List<String> fields) {
+ public static JsonObject createFilteredBoolQueryObject(FiltersConfig filtersConfig, List<SearchFilter> searchFilters, int minShouldMatch, List<String> fields) {
if (searchFilters == null || searchFilters.size() == 0) {
return null;
@@ -57,8 +56,6 @@ public class FilterQueryBuilder {
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
- FiltersConfig filters = FiltersConfig.getInstance();
-
for (SearchFilter searchFilter : searchFilters) {
searchFilterValueSize = searchFilter.getValues().size();
@@ -66,21 +63,21 @@ public class FilterQueryBuilder {
/*
* translate the filter-id into the filter-name from the oxm data model/config file
*/
- UiFilterConfig filter = filters.getFilterById(searchFilter.getFilterId());
+ UiFilterConfig filter = filtersConfig.getFilterById(searchFilter.getFilterId());
if (filter == null || filter.getFilterName() == null) {
// log error and continue
} else {
-
+
String fieldName = filter.getDataSource().getFieldName();
- if (!fields.contains(fieldName)) {
+ if(!fields.contains(fieldName)) {
fields.add(fieldName);
}
-
+
if (searchFilterValueSize >= SHOULD_BRANCH_LIMIT) {
// Add should branches
for (String filterValue : searchFilter.getValues()) {
- boolQueryBuilder.addShouldFilter(new MatchFilterCriteriaEntity(fieldName, filterValue));
+ boolQueryBuilder.addShouldFilter(new MatchFilterCriteriaEntity(fieldName, filterValue));
}
} else if (searchFilterValueSize > EXISTING_FILTERS_LIMIT) {
@@ -93,11 +90,11 @@ public class FilterQueryBuilder {
}
boolQueryBuilder.setMinShouldMatch(minShouldMatch);
-
+
return boolQueryBuilder.getJsonObject();
}
- public static JsonObject createAggregationQueryArray(List<SearchFilter> searchFilters) {
+ public static JsonObject createAggregationQueryArray(FiltersConfig filtersConfig, List<SearchFilter> searchFilters) {
if (searchFilters == null || searchFilters.size() == 0) {
// log error
@@ -106,14 +103,12 @@ public class FilterQueryBuilder {
FilteredAggregationQueryBuilder aggQueryBuilder = new FilteredAggregationQueryBuilder();
- FiltersConfig filters = FiltersConfig.getInstance();
-
for (SearchFilter searchFilter : searchFilters) {
/*
* translate the filter-id into the filter-name from the oxm data model/config file
*/
- UiFilterConfig filter = filters.getFilterById(searchFilter.getFilterId());
+ UiFilterConfig filter = filtersConfig.getFilterById(searchFilter.getFilterId());
if (filter == null || filter.getFilterName() == null) {
// log error and continue
@@ -127,31 +122,22 @@ public class FilterQueryBuilder {
return aggQueryBuilder.getJsonObject();
}
- public static JsonObject createCombinedBoolAndAggQuery(List<SearchFilter> searchFilters,
- int minShouldMatch) {
+ public static JsonObject createCombinedBoolAndAggQuery(FiltersConfig filtersConfig, List<SearchFilter> searchFilters, int minShouldMatch) {
JsonObjectBuilder wrappedQueryBuilder = Json.createObjectBuilder();
- if (searchFilters != null) {
+ if(searchFilters != null) {
List<String> fields = new ArrayList<String>();
- JsonObject boolQuery = createFilteredBoolQueryObject(searchFilters, minShouldMatch, fields);
- JsonObject aggQuery = createAggregationQueryArray(searchFilters);
+ JsonObject boolQuery = createFilteredBoolQueryObject(filtersConfig,searchFilters, minShouldMatch, fields);
+ JsonObject aggQuery = createAggregationQueryArray(filtersConfig, searchFilters);
if (boolQuery != null) {
wrappedQueryBuilder.add("size", 0);
-
- JsonArrayBuilder filedsArrayBuilder = Json.createBuilderFactory(null).createArrayBuilder(); // TODO
- // ->
- // Should
- // we
- // use
- // a
- // class
- // instance
- // factory?
- for (String field : fields) {
+
+ JsonArrayBuilder filedsArrayBuilder = Json.createBuilderFactory(null).createArrayBuilder(); // TODO -> Should we use a class instance factory?
+ for(String field : fields) {
filedsArrayBuilder.add(field);
}
wrappedQueryBuilder.add("fields", filedsArrayBuilder.build());
-
+
wrappedQueryBuilder.add("query", boolQuery);
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java b/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java
index 67f4d34..a75b983 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java
@@ -40,29 +40,28 @@ import org.onap.aai.sparky.search.filters.entity.UiFilterValueEntity;
import org.onap.aai.sparky.search.filters.entity.UiFiltersEntity;
public class FilteredSearchHelper {
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(FilteredSearchHelper.class);
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(FilteredSearchHelper.class);
private FiltersConfig filtersConfig;
private Map<String, UiFilterConfig> filtersMap = null;
private FilterElasticSearchAdapter filterSearchAdapter = null;
-
- public FilteredSearchHelper(FiltersConfig filterConfig) {
+
+ public FilteredSearchHelper(FiltersConfig filterConfig,FilterElasticSearchAdapter filterElasticSearchAdapter) {
this.filtersConfig = filterConfig;
+ this.filterSearchAdapter = filterElasticSearchAdapter;
if (filtersMap == null) {
filtersMap = new HashMap<>();
final FiltersDetailsConfig uiFiltersConfig = filterConfig.getFiltersConfig();
-
+
if (uiFiltersConfig != null) {
for (UiFilterConfig filter : uiFiltersConfig.getFilters()) {
filtersMap.put(filter.getFilterId(), filter);
}
}
}
-
- filterSearchAdapter = new FilterElasticSearchAdapter();
+
}
public FiltersConfig getFiltersConfig() {
@@ -77,25 +76,25 @@ public class FilteredSearchHelper {
List<UiViewListItemConfig> views = filtersConfig.getViewsConfig().getViews();
List<UiFilterListItemConfig> filters = null;
UiFiltersEntity viewFiltersList = new UiFiltersEntity();
-
- if (viewName != null) {
- for (UiViewListItemConfig view : views) {
+
+ if(viewName != null) {
+ for (UiViewListItemConfig view: views) {
if (viewName.equalsIgnoreCase(view.getViewName())) {
filters = view.getFilters();
break;
}
}
-
+
if (filters == null) {
LOG.error(AaiUiMsgs.VIEW_NAME_NOT_SUPPORTED, viewName);
} else {
for (UiFilterListItemConfig filter : filters) {
FiltersDetailsConfig filtersDetailsConfig = filtersConfig.getFiltersConfig();
-
- for (UiFilterConfig filterConfig : filtersDetailsConfig.getFilters()) {
+
+ for (UiFilterConfig filterConfig: filtersDetailsConfig.getFilters()) {
if (filterConfig.getFilterId().equals(filter.getFilterId())) {
UiFilterEntity filterEntity = new UiFilterEntity(filterConfig);
- if (filter.getDefaultValue() != null) {
+ if(filter.getDefaultValue() != null) {
filterEntity.setDefaultValue(filter.getDefaultValue());
}
viewFiltersList.addFilter(filterEntity);
@@ -106,7 +105,7 @@ public class FilteredSearchHelper {
}
return viewFiltersList;
}
-
+
public UiFiltersEntity doFilterEnumeration(List<String> requestedFilterIds) {
UiFiltersEntity viewFiltersList = new UiFiltersEntity();
@@ -118,23 +117,22 @@ public class FilteredSearchHelper {
UiFilterConfig sourceData = filtersMap.get(requestedFilterId);
UiFilterEntity filterEntity = new UiFilterEntity(sourceData);
this.getFilterEnumeration(filterEntity, sourceData);
- viewFiltersList.addFilter(filterEntity);
+ viewFiltersList.addFilter(filterEntity);
}
}
return viewFiltersList;
}
-
+
public void getFilterEnumeration(UiFilterEntity filter, UiFilterConfig sourceData) {
- List<String> filterValues =
- filterSearchAdapter.fetchValuesForFilter(filter, sourceData.getDataSource());
-
- for (String value : filterValues) {
- UiFilterValueEntity valueEntity = new UiFilterValueEntity();
- valueEntity.setDisplayName(value);
- valueEntity.setFilterValue(value);
- filter.addFilterValue(valueEntity);
- }
+ List<String> filterValues = filterSearchAdapter.fetchValuesForFilter(filter, sourceData.getDataSource());
+
+ for(String value : filterValues) {
+ UiFilterValueEntity valueEntity = new UiFilterValueEntity();
+ valueEntity.setDisplayName(value);
+ valueEntity.setFilterValue(value);
+ filter.addFilterValue(valueEntity);
+ }
}
public Map<String, UiFilterConfig> getFiltersMap() {
@@ -144,15 +142,15 @@ public class FilteredSearchHelper {
public void setFiltersMap(Map<String, UiFilterConfig> filtersMap) {
this.filtersMap = filtersMap;
}
-
+
public UiFilterDataSourceConfig getFilterDataSource(String filterId) {
UiFilterConfig filterConfig = filtersMap.get(filterId);
UiFilterDataSourceConfig returnValue = null;
-
- if (filterConfig != null) {
+
+ if(filterConfig != null) {
returnValue = filterConfig.getDataSource();
}
-
+
return returnValue;
}
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/UiFiltersEntityConverter.java b/src/main/java/org/onap/aai/sparky/search/filters/UiFiltersEntityConverter.java
index e8ce534..24851f7 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/UiFiltersEntityConverter.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/UiFiltersEntityConverter.java
@@ -36,7 +36,7 @@ import org.onap.aai.sparky.search.filters.entity.UiFilterValueEntity;
import org.onap.aai.sparky.search.filters.entity.UiFiltersEntity;
public class UiFiltersEntityConverter {
-
+
private static final String KEY_TYPE = "type";
private static final String KEY_MULTISELECT = "multiSelect";
private static final String KEY_WATERMARK = "watermark";
@@ -46,32 +46,31 @@ public class UiFiltersEntityConverter {
private static final String KEY_DECODE = "decode";
private static final String KEY_CODE = "code";
private static final String KEY_DEFAULT_VALUE = "defaultValue";
-
+
/**
- * Converts a UiFiltersEntity into a JSON object to satisfy a new (as of 23 Oct 2017) filter
- * library being used in the FE.
+ * Converts a UiFiltersEntity into a JSON object to satisfy a new (as of 23 Oct 2017)
+ * filter library being used in the FE.
*
* @param entityToConvert - The UiFiltersEntity to be converted into a JSON response.
* @return A JsonObject representing the passed in UiFiltersEntity.
*/
- public static JsonObject convertUiFiltersEntityToUnifiedFilterResponse(
- UiFiltersEntity entityToConvert) {
+ public static JsonObject convertUiFiltersEntityToUnifiedFilterResponse(UiFiltersEntity entityToConvert) {
JsonObjectBuilder filterBuilder = Json.createObjectBuilder();
-
- if (entityToConvert != null) {
+
+ if(entityToConvert != null) {
List<UiFilterEntity> filterEntities = entityToConvert.getFilters();
- if (filterEntities != null) {
- for (UiFilterEntity entity : filterEntities) {
+ if(filterEntities != null) {
+ for(UiFilterEntity entity : filterEntities) {
filterBuilder.add(entity.getFilterId(), generateFilterObject(entity));
}
}
}
-
+
JsonObjectBuilder finalObject = Json.createObjectBuilder();
finalObject.add(KEY_FILTERS, filterBuilder.build());
return finalObject.build();
}
-
+
/**
* Generates the core body of the a single filter within the JSON body.
*
@@ -80,101 +79,96 @@ public class UiFiltersEntityConverter {
*/
private static JsonObject generateFilterObject(UiFilterEntity entity) {
JsonObjectBuilder filterBuilder = Json.createObjectBuilder();
-
+
filterBuilder.add(KEY_LABEL, entity.getDisplayName());
filterBuilder.add(KEY_CONTROLS, generateControlObject(entity, entity.getFilterValueList()));
-
+
return filterBuilder.build();
}
-
+
/**
* Generates the "controls" object within the filter JSON.
*
* @param filterEntity - The filter entity on which this filter will be based.
- * @param filterValues - The list of values associated with the filter from data store queries.
+ * @param filterValues - The list of values associated with the filter
+ * from data store queries.
* @return A JsonObject representing the "controls" object of the filter JSON.
*/
- private static JsonObject generateControlObject(UiFilterEntity filterEntity,
- List<UiFilterValueEntity> filterValues) {
+ private static JsonObject generateControlObject(UiFilterEntity filterEntity, List<UiFilterValueEntity> filterValues) {
JsonObjectBuilder controls = Json.createObjectBuilder();
JsonObjectBuilder subControl = Json.createObjectBuilder();
-
+
subControl.add(KEY_TYPE, filterEntity.getDataType());
subControl.add(KEY_MULTISELECT, filterEntity.getMultiSelect());
subControl.add(KEY_WATERMARK, filterEntity.getWatermark());
-
- if (filterEntity.getDefaultValue() != null
- && !filterEntity.getDefaultValue().getCode().isEmpty()
- && !filterEntity.getDefaultValue().getDecode().isEmpty()) {
+
+ if(filterEntity.getDefaultValue() != null && !filterEntity.getDefaultValue().getCode().isEmpty() && !filterEntity.getDefaultValue().getDecode().isEmpty()) {
JsonObjectBuilder defaultValueBuilder = Json.createObjectBuilder();
-
+
defaultValueBuilder.add(KEY_DECODE, filterEntity.getDefaultValue().getDecode());
defaultValueBuilder.add(KEY_CODE, filterEntity.getDefaultValue().getCode());
-
+
subControl.add(KEY_DEFAULT_VALUE, defaultValueBuilder.build());
}
-
- if (filterEntity.getOptionsValues() == null || filterEntity.getOptionsValues().isEmpty()) {
+
+ if(filterEntity.getOptionsValues() == null || filterEntity.getOptionsValues().isEmpty()) {
subControl.add(filterEntity.getOptionsType(), generateOptionsObject(filterValues));
} else {
- subControl.add(filterEntity.getOptionsType(),
- generateOptionsValuesObject(filterEntity.getOptionsValues()));
+ subControl.add(filterEntity.getOptionsType(), generateOptionsValuesObject(filterEntity.getOptionsValues()));
}
-
+
controls.add(filterEntity.getFilterName(), subControl.build());
-
+
return controls.build();
}
-
+
/**
- * Creates a JsonArray representing the list of options for a filter. Similar to function
- * generateOptionsObject, except using different arguments.
+ * Creates a JsonArray representing the list of options for a filter.
+ * Similar to function generateOptionsObject, except using different arguments.
*
* @param optionsValues - Values that are loaded from config.
* @return JsonArray of options for a filter.
*/
- private static JsonArray generateOptionsValuesObject(
- List<UiFilterOptionsValuesConfig> optionsValues) {
+ private static JsonArray generateOptionsValuesObject(List<UiFilterOptionsValuesConfig> optionsValues) {
JsonArrayBuilder optionsBuilder = Json.createArrayBuilder();
-
- if (optionsValues != null && !optionsValues.isEmpty()) {
- for (UiFilterOptionsValuesConfig optionValue : optionsValues) {
+
+ if(optionsValues != null && !optionsValues.isEmpty()) {
+ for(UiFilterOptionsValuesConfig optionValue : optionsValues) {
JsonObjectBuilder option = Json.createObjectBuilder();
-
+
option.add(KEY_DECODE, optionValue.getDecode());
option.add(KEY_CODE, optionValue.getCode());
-
+
optionsBuilder.add(option.build());
}
}
-
+
return optionsBuilder.build();
}
-
+
/**
* Creates a JsonArray representing the list of options for a filter.
*
- * @param filterValues - The list of values associates with a filter (likely from a data store
- * query).
+ * @param filterValues - The list of values associates with a filter (likely from a data store query).
* @return JsonArray of options for a filter.
*/
private static JsonArray generateOptionsObject(List<UiFilterValueEntity> filterValues) {
JsonArrayBuilder optionsBuilder = Json.createArrayBuilder();
-
- if (filterValues != null && !filterValues.isEmpty()) {
- for (UiFilterValueEntity valueEntity : filterValues) {
+
+ if(filterValues != null && !filterValues.isEmpty()) {
+ for(UiFilterValueEntity valueEntity : filterValues) {
JsonObjectBuilder option = Json.createObjectBuilder();
-
+
option.add(KEY_DECODE, valueEntity.getDisplayName());
option.add(KEY_CODE, valueEntity.getFilterValue());
-
+
optionsBuilder.add(option.build());
}
}
-
+
return optionsBuilder.build();
}
-
+
public static JsonObject generateEmptyResponse() {
JsonObjectBuilder filterBuilder = Json.createObjectBuilder();
JsonObjectBuilder finalObject = Json.createObjectBuilder();
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java b/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java
index b202684..75b92e7 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java
@@ -27,59 +27,35 @@ import java.io.File;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import com.fasterxml.jackson.databind.ObjectMapper;
public class FiltersConfig {
private static final Logger LOG = LoggerFactory.getInstance().getLogger(FiltersConfig.class);
-
- private static FiltersConfig instance;
-
+
private String filtersFileName;
-
+
private String filterMappingsFileName;
-
+
private FiltersForViewsConfig viewsConfig;
-
+
private FiltersDetailsConfig filtersConfig;
- private NetworkStatisticsConfig processorConfig;
-
- public NetworkStatisticsConfig getProcessorConfig() {
- return processorConfig;
- }
-
- public void setProcessorConfig(NetworkStatisticsConfig processorConfig) {
- this.processorConfig = processorConfig;
- }
-
- public static FiltersConfig getInstance() {
- if (instance == null) {
- instance = new FiltersConfig();
- instance.initializeFilters();
- }
-
- return instance;
- }
-
- public static void setConfig(FiltersConfig config) {
- FiltersConfig.instance = config;
- }
-
/**
* Instantiates a new UiViewFilterConfig.
*/
- private FiltersConfig() {}
+ public FiltersConfig() {
+ initializeFilters();
+ }
/**
* Initialize config.
*/
private void initializeFilters() {
- filtersFileName = TierSupportUiConstants.FILTER_LIST_FILE_DEFAULT;
- filterMappingsFileName = TierSupportUiConstants.FILTER_MAPPING_FILE_DEFAULT;
+ filtersFileName = SparkyConstants.FILTER_LIST_FILE_DEFAULT;
+ filterMappingsFileName = SparkyConstants.FILTER_MAPPING_FILE_DEFAULT;
viewsConfig = this.readUiViewsConfig();
filtersConfig = this.readUiFiltersConfig();
@@ -112,47 +88,41 @@ public class FiltersConfig {
public FiltersDetailsConfig getFiltersConfig() {
return filtersConfig;
}
-
+
public UiFilterConfig getFilterById(String filterId) {
- for (UiFilterConfig filter : filtersConfig.getFilters()) {
- if (filter.getFilterId().equals(filterId)) {
+ for ( UiFilterConfig filter : filtersConfig.getFilters()) {
+ if ( filter.getFilterId().equals(filterId)) {
return filter;
}
}
-
+
return null;
}
-
+
public void setFiltersConfig(FiltersDetailsConfig filtersConfig) {
this.filtersConfig = filtersConfig;
}
- public FiltersDetailsConfig readUiFiltersConfig() {
+ public FiltersDetailsConfig readUiFiltersConfig(){
ObjectMapper mapper = new ObjectMapper();
FiltersDetailsConfig filtersConfig = null;
- try {
- filtersConfig =
- mapper.readValue(new File(this.getFiltersFileName()), FiltersDetailsConfig.class);
- System.out.println(String.valueOf(filtersConfig));
- } catch (Exception e) {
- LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA,
- TierSupportUiConstants.getConfigPath(this.getFiltersFileName()));
+ try{
+ filtersConfig = mapper.readValue(new File(this.getFiltersFileName()), FiltersDetailsConfig.class);
+ } catch (Exception e){
+ LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFiltersFileName()));
}
return filtersConfig;
}
- public FiltersForViewsConfig readUiViewsConfig() {
+ public FiltersForViewsConfig readUiViewsConfig(){
ObjectMapper mapper = new ObjectMapper();
FiltersForViewsConfig viewsConfig = null;
-
+
try {
- viewsConfig =
- mapper.readValue(new File(this.getFilterMappingsFileName()), FiltersForViewsConfig.class);
- System.out.println(String.valueOf(viewsConfig));
- } catch (Exception e) {
- LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA,
- TierSupportUiConstants.getConfigPath(this.getFilterMappingsFileName()));
+ viewsConfig = mapper.readValue(new File(this.getFilterMappingsFileName()), FiltersForViewsConfig.class);
+ } catch (Exception e){
+ LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFilterMappingsFileName()));
}
return viewsConfig;
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersDetailsConfig.java b/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersDetailsConfig.java
index c4905ac..09eec02 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersDetailsConfig.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersDetailsConfig.java
@@ -32,13 +32,13 @@ public class FiltersDetailsConfig {
@JsonProperty("filters")
private List<UiFilterConfig> filters = new ArrayList<UiFilterConfig>();
- public FiltersDetailsConfig() {}
+ public FiltersDetailsConfig(){}
@JsonCreator
public FiltersDetailsConfig(@JsonProperty("filters") final List<UiFilterConfig> filters) {
- this.filters = filters;
+ this.filters = filters;
}
-
+
public List<UiFilterConfig> getFilters() {
return filters;
}
@@ -50,6 +50,6 @@ public class FiltersDetailsConfig {
@Override
public String toString() {
return "UiFiltersConfig [filters=" + filters + "]";
- }
+ }
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersForViewsConfig.java b/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersForViewsConfig.java
index ea7c305..7340758 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersForViewsConfig.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersForViewsConfig.java
@@ -32,13 +32,13 @@ public class FiltersForViewsConfig {
private List<UiViewListItemConfig> views = new ArrayList<UiViewListItemConfig>();
- public FiltersForViewsConfig() {}
+ public FiltersForViewsConfig(){}
@JsonCreator
public FiltersForViewsConfig(@JsonProperty("views") final List<UiViewListItemConfig> views) {
- this.views = views;
+ this.views = views;
}
-
+
@JsonProperty("views")
public List<UiViewListItemConfig> getViews() {
return views;
@@ -46,7 +46,7 @@ public class FiltersForViewsConfig {
public void setViews(List<UiViewListItemConfig> views) {
this.views = views;
- }
+ }
@Override
public String toString() {
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterConfig.java b/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterConfig.java
index 014407e..c566565 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterConfig.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterConfig.java
@@ -31,40 +31,40 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(Include.NON_NULL)
public class UiFilterConfig {
-
+
@JsonProperty("filterId")
private String filterId;
-
+
@JsonProperty("filterName")
private String filterName;
-
+
@JsonProperty("displayName")
private String displayName;
-
+
@JsonProperty("dataType")
private String dataType;
-
+
@JsonProperty("multiSelect")
private String multiSelect;
-
+
@JsonProperty("watermark")
private String watermark;
-
+
@JsonProperty("defaultValue")
private UiFilterOptionsValuesConfig defaultValue;
-
+
@JsonProperty("optionsType")
private String optionsType;
-
+
@JsonProperty("optionsValues")
private List<UiFilterOptionsValuesConfig> optionsValues;
-
+
@JsonProperty("dataSource")
private UiFilterDataSourceConfig dataSource = new UiFilterDataSourceConfig();
-
+
@JsonCreator
- public UiFilterConfig(@JsonProperty("filterId") final String filterId,
- @JsonProperty("filterName") final String filterName,
+ public UiFilterConfig(@JsonProperty("filterId") final String filterId,
+ @JsonProperty("filterName") final String filterName,
@JsonProperty("displayName") final String displayName,
@JsonProperty("dataType") final String dataType,
@JsonProperty("multiSelect") final String multiSelect,
@@ -72,7 +72,8 @@ public class UiFilterConfig {
@JsonProperty("defaultValue") final UiFilterOptionsValuesConfig defaultValue,
@JsonProperty("optionsType") final String optionsType,
@JsonProperty("optionsValues") final List<UiFilterOptionsValuesConfig> optionsValues,
- @JsonProperty("dataSource") final UiFilterDataSourceConfig dataSource) {
+ @JsonProperty("dataSource") final UiFilterDataSourceConfig dataSource
+ ) {
this.filterId = filterId;
this.filterName = filterName;
this.displayName = displayName;
@@ -138,7 +139,7 @@ public class UiFilterConfig {
public void setWatermark(String watermark) {
this.watermark = watermark;
}
-
+
@JsonProperty("defaultValue")
public UiFilterOptionsValuesConfig getDefaultValue() {
return defaultValue;
@@ -156,7 +157,6 @@ public class UiFilterConfig {
public void setOptionsType(String optionsType) {
this.optionsType = optionsType;
}
-
@JsonProperty("optionsValues")
public List<UiFilterOptionsValuesConfig> getOptionsValues() {
return optionsValues;
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterDataSourceConfig.java b/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterDataSourceConfig.java
index 6826dff..be0603b 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterDataSourceConfig.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterDataSourceConfig.java
@@ -29,26 +29,23 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(Include.NON_NULL)
public class UiFilterDataSourceConfig {
-
+
@JsonProperty("indexName")
private String indexName;
-
+
@JsonProperty("docType")
private String docType;
-
+
@JsonProperty("fieldName")
private String fieldName;
-
+
@JsonProperty("pathToField")
private String pathToField;
-
- public UiFilterDataSourceConfig() {}
-
+
+ public UiFilterDataSourceConfig(){}
+
@JsonCreator
- public UiFilterDataSourceConfig(@JsonProperty("indexName") final String indexName,
- @JsonProperty("docType") final String docType,
- @JsonProperty("fieldName") final String fieldName,
- @JsonProperty("pathToField") final String pathToField) {
+ public UiFilterDataSourceConfig(@JsonProperty("indexName") final String indexName, @JsonProperty("docType") final String docType, @JsonProperty("fieldName") final String fieldName, @JsonProperty("pathToField") final String pathToField) {
this.indexName = indexName;
this.docType = docType;
this.fieldName = fieldName;
@@ -81,12 +78,12 @@ public class UiFilterDataSourceConfig {
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
-
+
@JsonProperty("pathToField")
public String getPathToField() {
return pathToField;
}
-
+
public void setPathToField(String pathToField) {
this.pathToField = pathToField;
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterListItemConfig.java b/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterListItemConfig.java
index af75bfc..c1ee089 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterListItemConfig.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterListItemConfig.java
@@ -31,14 +31,13 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class UiFilterListItemConfig {
@JsonProperty("filterId")
private String filterId;
-
+
@JsonProperty("defaultValue")
private UiFilterOptionsValuesConfig defaultValue;
-
+
@JsonCreator
- public UiFilterListItemConfig(@JsonProperty("filterId") final String filterId,
- @JsonProperty("defaultValue") final UiFilterOptionsValuesConfig defaultValue) {
+ public UiFilterListItemConfig(@JsonProperty("filterId") final String filterId, @JsonProperty("defaultValue") final UiFilterOptionsValuesConfig defaultValue) {
this.filterId = filterId;
this.defaultValue = defaultValue;
}
@@ -66,5 +65,5 @@ public class UiFilterListItemConfig {
return "FilterListItemEntity [filterId=" + filterId + ", defaultValue=" + defaultValue + "]";
}
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterOptionsValuesConfig.java b/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterOptionsValuesConfig.java
index 81da340..2abdfdd 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterOptionsValuesConfig.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/config/UiFilterOptionsValuesConfig.java
@@ -31,13 +31,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class UiFilterOptionsValuesConfig {
@JsonProperty("decode")
private String decode;
-
+
@JsonProperty("code")
private String code;
-
+
@JsonCreator
- public UiFilterOptionsValuesConfig(@JsonProperty("decode") final String decode,
- @JsonProperty("code") final String code) {
+ public UiFilterOptionsValuesConfig(@JsonProperty("decode") final String decode, @JsonProperty("code") final String code) {
this.decode = decode;
this.code = code;
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/config/UiViewListItemConfig.java b/src/main/java/org/onap/aai/sparky/search/filters/config/UiViewListItemConfig.java
index 7663693..3707417 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/config/UiViewListItemConfig.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/config/UiViewListItemConfig.java
@@ -31,12 +31,11 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class UiViewListItemConfig {
@JsonProperty("viewName")
private String viewName;
-
+
private List<UiFilterListItemConfig> filters = new ArrayList<UiFilterListItemConfig>();
-
+
@JsonCreator
- public UiViewListItemConfig(@JsonProperty("viewName") final String viewName,
- @JsonProperty("filters") final List<UiFilterListItemConfig> filters) {
+ public UiViewListItemConfig(@JsonProperty("viewName") final String viewName, @JsonProperty("filters") final List<UiFilterListItemConfig> filters) {
this.viewName = viewName;
this.filters = filters;
}
@@ -63,5 +62,5 @@ public class UiViewListItemConfig {
public String toString() {
return "UiViewEntity [viewName=" + viewName + ", filters=" + filters + "]";
}
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/entity/AggregationEntity.java b/src/main/java/org/onap/aai/sparky/search/filters/entity/AggregationEntity.java
index 9e4d6e3..bf901e2 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/entity/AggregationEntity.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/entity/AggregationEntity.java
@@ -68,8 +68,9 @@ public class AggregationEntity {
JsonBuilderFactory factory = Json.createBuilderFactory(null);
return factory.createObjectBuilder()
- .add("terms",
- factory.createObjectBuilder().add("field", aggregationFieldName).add("size", size))
+ .add("terms", factory.createObjectBuilder()
+ .add("field", aggregationFieldName)
+ .add("size", size))
.build();
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/entity/BoolQueryBuilder.java b/src/main/java/org/onap/aai/sparky/search/filters/entity/BoolQueryBuilder.java
index d376b7d..dabe061 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/entity/BoolQueryBuilder.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/entity/BoolQueryBuilder.java
@@ -36,7 +36,7 @@ public class BoolQueryBuilder {
private List<MatchFilterCriteriaEntity> mustFilters;
private List<MatchFilterCriteriaEntity> shouldFilters;
-
+
private int minShouldMatch;
public BoolQueryBuilder() {
@@ -62,15 +62,15 @@ public class BoolQueryBuilder {
}
}
-
+
public void setMinShouldMatch(int minShouldMatch) {
this.minShouldMatch = minShouldMatch;
}
-
+
public boolean isMatchAll() {
return (mustFilters.isEmpty() && shouldFilters.isEmpty());
}
-
+
public JsonObject getJsonObject() {
/*
* Specify a null config for now, but if we want normalize all the builders, we can do it at one
@@ -80,13 +80,13 @@ public class BoolQueryBuilder {
JsonObjectBuilder boolBuilder = factory.createObjectBuilder();
- if (!mustFilters.isEmpty()) {
+ if(!mustFilters.isEmpty()){
JsonArrayBuilder mustArrayBuilder = factory.createArrayBuilder();
-
+
for (MatchFilterCriteriaEntity matchCriteria : mustFilters) {
mustArrayBuilder.add(matchCriteria.getJsonObject());
}
-
+
JsonArray mustArray = mustArrayBuilder.build();
boolBuilder.add("must", mustArray);
}
@@ -94,7 +94,7 @@ public class BoolQueryBuilder {
if (!shouldFilters.isEmpty()) {
JsonArray shouldArray = null;
JsonArrayBuilder shouldArrayBuilder = factory.createArrayBuilder();
-
+
for (MatchFilterCriteriaEntity matchCriteria : shouldFilters) {
shouldArrayBuilder.add(matchCriteria.getJsonObject());
}
@@ -102,14 +102,14 @@ public class BoolQueryBuilder {
shouldArray = shouldArrayBuilder.build();
boolBuilder.add("should", shouldArray).add("min_should_match", minShouldMatch);
}
-
+
JsonObjectBuilder queryObjectBuilder = factory.createObjectBuilder();
-
- /*
- * If both filter lists are empty then we are doing an aggregation based off fields. Just
- * match-all for the query.
- */
- if (isMatchAll()) {
+
+ /*
+ * If both filter lists are empty then we are doing an aggregation
+ * based off fields. Just match-all for the query.
+ */
+ if(isMatchAll()) {
JsonObject matchAllObject = factory.createObjectBuilder().build();
queryObjectBuilder.add("match_all", matchAllObject);
} else {
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/entity/SearchFilter.java b/src/main/java/org/onap/aai/sparky/search/filters/entity/SearchFilter.java
index aff4da6..1b23203 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/entity/SearchFilter.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/entity/SearchFilter.java
@@ -43,18 +43,18 @@ public class SearchFilter {
public SearchFilter() {
values = new ArrayList<String>();
}
-
+
public SearchFilter(String filterId) {
this();
this.filterId = filterId;
}
-
+
public SearchFilter(String filterId, String... values) {
this();
this.filterId = filterId;
this.values.addAll(Arrays.asList(values));
}
-
+
public String getFilterId() {
return filterId;
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterEntity.java b/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterEntity.java
index d010bae..2770052 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterEntity.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterEntity.java
@@ -34,10 +34,9 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
/**
* Stores data for a single filter for a given UI view.
* <p>
- * When a UI view wants to know which filters it should display, an object of this class is created
- * for each filter discovered and stores data for that filter. Each filter/object of this class is
- * added to a ViewFilterList object which is then serialized to JSON and returned to the view in the
- * response body.
+ * When a UI view wants to know which filters it should display, an object of this class is created for each
+ * filter discovered and stores data for that filter. Each filter/object of this class is added to a
+ * ViewFilterList object which is then serialized to JSON and returned to the view in the response body.
*/
@JsonInclude(Include.NON_NULL)
public class UiFilterEntity {
@@ -45,18 +44,18 @@ public class UiFilterEntity {
private String filterName;
private String displayName;
private String dataType;
-
+
private String multiSelect;
private String watermark;
private UiFilterOptionsValuesConfig defaultValue;
private String optionsType;
-
+
private List<UiFilterOptionsValuesConfig> optionsValues;
-
+
private List<UiFilterValueEntity> filterValueList;
public UiFilterEntity() {}
-
+
public UiFilterEntity(UiFilterConfig filterConfig) {
if (filterConfig.getFilterId() != null) {
this.setFilterId(filterConfig.getFilterId());
@@ -82,13 +81,13 @@ public class UiFilterEntity {
if (filterConfig.getOptionsType() != null) {
this.setOptionsType(filterConfig.getOptionsType());
}
- if (filterConfig.getOptionsValues() != null && !filterConfig.getOptionsValues().isEmpty()) {
+ if(filterConfig.getOptionsValues() != null && !filterConfig.getOptionsValues().isEmpty()) {
this.setOptionsValues(filterConfig.getOptionsValues());
} else {
this.optionsValues = new ArrayList<UiFilterOptionsValuesConfig>();
}
}
-
+
public void addFilterValue(UiFilterValueEntity valueEntity) {
if (null == filterValueList) {
filterValueList = new ArrayList<>();
@@ -104,7 +103,7 @@ public class UiFilterEntity {
public String getFilterName() {
return filterName;
}
-
+
public String getDisplayName() {
return displayName;
}
@@ -112,11 +111,11 @@ public class UiFilterEntity {
public String getDataType() {
return dataType;
}
-
+
public UiFilterOptionsValuesConfig getDefaultValue() {
return defaultValue;
}
-
+
public List<UiFilterValueEntity> getFilterValueList() {
return filterValueList;
}
@@ -128,7 +127,7 @@ public class UiFilterEntity {
public void setFilterName(String filterName) {
this.filterName = filterName;
}
-
+
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
@@ -136,7 +135,7 @@ public class UiFilterEntity {
public void setDataType(String dataType) {
this.dataType = dataType;
}
-
+
public String getMultiSelect() {
return multiSelect;
}
@@ -160,7 +159,7 @@ public class UiFilterEntity {
public void setOptionsType(String optionsType) {
this.optionsType = optionsType;
}
-
+
public List<UiFilterOptionsValuesConfig> getOptionsValues() {
return optionsValues;
}
@@ -172,7 +171,7 @@ public class UiFilterEntity {
public void setDefaultValue(UiFilterOptionsValuesConfig defaultValue) {
this.defaultValue = defaultValue;
}
-
+
public void setFilterValueList(List<UiFilterValueEntity> values) {
this.filterValueList = values;
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterValueEntity.java b/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterValueEntity.java
index f2a238a..a0bbd90 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterValueEntity.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFilterValueEntity.java
@@ -26,9 +26,8 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
/**
- * This class represents a single item or value to populate the FE filter component with. A
- * drop-down list, for example, may be populated with the values from several instances of this
- * class.
+ * This class represents a single item or value to populate the FE filter component with.
+ * A drop-down list, for example, may be populated with the values from several instances of this class.
*/
@JsonInclude(Include.NON_NULL)
public class UiFilterValueEntity {
@@ -74,6 +73,6 @@ public class UiFilterValueEntity {
+ (filterValue != null ? "filterValue=" + filterValue + ", " : "")
+ (displayName != null ? "displayName=" + displayName : "") + "]";
}
-
-
+
+
}
diff --git a/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFiltersEntity.java b/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFiltersEntity.java
index 12036c4..2e8fd17 100644
--- a/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFiltersEntity.java
+++ b/src/main/java/org/onap/aai/sparky/search/filters/entity/UiFiltersEntity.java
@@ -28,15 +28,15 @@ import java.util.List;
/**
* Represents a list of filters that a given UI view should display.
* <p>
- * When a UI view wants to know which filters it should display, an object of this class is created
- * to keep track of all the filters that are discovered for that view and is then serialized to JSON
- * and returned to the view in the response body.
+ * When a UI view wants to know which filters it should display, an object of this class is created to keep
+ * track of all the filters that are discovered for that view and is then serialized to JSON and returned to
+ * the view in the response body.
*/
public class UiFiltersEntity {
private List<UiFilterEntity> filters = new ArrayList<>();
-
-
+
+
public void addFilter(UiFilterEntity viewFilter) {
filters.add(viewFilter);
}
diff --git a/src/main/java/org/onap/aai/sparky/security/EcompSso.java b/src/main/java/org/onap/aai/sparky/security/EcompSso.java
index de74a5a..a5dd26b 100644
--- a/src/main/java/org/onap/aai/sparky/security/EcompSso.java
+++ b/src/main/java/org/onap/aai/sparky/security/EcompSso.java
@@ -155,4 +155,4 @@ public class EcompSso {
String[] cspData = cspCookieDecrypted.split("\\|");
return cspData;
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/security/SecurityContextFactoryImpl.java b/src/main/java/org/onap/aai/sparky/security/SecurityContextFactoryImpl.java
index 030309d..1e15f11 100644
--- a/src/main/java/org/onap/aai/sparky/security/SecurityContextFactoryImpl.java
+++ b/src/main/java/org/onap/aai/sparky/security/SecurityContextFactoryImpl.java
@@ -111,7 +111,7 @@ public class SecurityContextFactoryImpl implements SecurityContextFactory {
@Override
public void setClientCertFileName(String filename) throws IOException {
this.clientCertFileName = filename;
-
+
if (filename == null) {
this.clientCertBytes = null;
} else {
@@ -153,7 +153,7 @@ public class SecurityContextFactoryImpl implements SecurityContextFactory {
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
- }};
+ } };
}
KeyManagerFactory kmf = KeyManagerFactory.getInstance(keyManagerAlgortihm);
@@ -164,7 +164,7 @@ public class SecurityContextFactoryImpl implements SecurityContextFactory {
if (clientCertPassword != null) {
pwd = clientCertPassword.toCharArray();
}
-
+
if (clientCertBytes != null) {
ks.load(new ByteArrayInputStream(clientCertBytes), pwd);
} else {
diff --git a/src/main/java/org/onap/aai/sparky/security/filter/CspCookieFilter.java b/src/main/java/org/onap/aai/sparky/security/filter/CspCookieFilter.java
index 51e77bb..f742bc8 100644
--- a/src/main/java/org/onap/aai/sparky/security/filter/CspCookieFilter.java
+++ b/src/main/java/org/onap/aai/sparky/security/filter/CspCookieFilter.java
@@ -49,7 +49,7 @@ import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.cl.mdc.MdcContext;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.util.NodeUtils;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
// import esGateKeeper.esGateKeeper;
@@ -82,17 +82,15 @@ public class CspCookieFilter implements Filter {
private static final Logger LOG = LoggerFactory.getInstance().getLogger(CspCookieFilter.class);
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/
@Override
public void init(FilterConfig filterConfig) throws ServletException {
- String txnID = NodeUtils.getRandomTxnId();
- MdcContext.initialize(txnID, "CspCookieFilter", "", "Init", "");
-
- try {
+ String txnID = NodeUtils.getRandomTxnId();
+ MdcContext.initialize(txnID, "CspCookieFilter", "", "Init", "");
+
+ try {
setConfigurationProperties(filterConfig);
} catch (IOException exc) {
LOG.error(AaiUiMsgs.ERROR_CSP_CONFIG_FILE);
@@ -101,11 +99,8 @@ public class CspCookieFilter implements Filter {
}
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
- * javax.servlet.FilterChain)
+ /* (non-Javadoc)
+ * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
@@ -134,9 +129,7 @@ public class CspCookieFilter implements Filter {
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see javax.servlet.Filter#destroy()
*/
@Override
@@ -149,15 +142,14 @@ public class CspCookieFilter implements Filter {
* @throws IOException if the properties failed to load.
*/
private void setConfigurationProperties(FilterConfig filterConfig) throws IOException {
- InputStream inputStream = new FileInputStream(TierSupportUiConstants.STATIC_CONFIG_APP_LOCATION
+ InputStream inputStream = new FileInputStream(SparkyConstants.STATIC_CONFIG_APP_LOCATION
+ filterConfig.getInitParameter(FILTER_PARAMETER_CONFIG));
Properties cspProperties = new Properties();
cspProperties.load(inputStream);
globalLoginUrl = cspProperties.getProperty(PROPERTY_GLOBAL_LOGIN_URL);
applicationId = cspProperties.getProperty(PROPERTY_APPLICATION_ID);
gateKeeperEnvironment = cspProperties.getProperty(PROPERTY_GATEKEEPER_ENVIRONMENT);
- redirectDomains =
- Arrays.asList(cspProperties.getProperty(PROPERTY_REDIRECT_DOMAINS).split(","));
+ redirectDomains = Arrays.asList(cspProperties.getProperty(PROPERTY_REDIRECT_DOMAINS).split(","));
}
/**
@@ -197,37 +189,36 @@ public class CspCookieFilter implements Filter {
// Fix for Safari 7.0.2 onwards to avoid login page cache
response.addHeader("Cache-Control", "no-cache, no-store");
String redirectURL = createRedirectUrl(request);
- if (this.isValidRedirectURL(redirectURL)) {
- response.sendRedirect(redirectURL);
- LOG.debug(AaiUiMsgs.VALID_REDIRECT_URL, redirectURL);
- } else {
- response.sendError(400, "Bad redirect URL: " + redirectURL);
- LOG.error(AaiUiMsgs.INVALID_REDIRECT_URL, redirectURL);
+ if (this.isValidRedirectURL(redirectURL)){
+ response.sendRedirect(redirectURL);
+ LOG.debug(AaiUiMsgs.VALID_REDIRECT_URL, redirectURL);
+ } else{
+ response.sendError(400, "Bad redirect URL: " + redirectURL);
+ LOG.error(AaiUiMsgs.INVALID_REDIRECT_URL, redirectURL);
}
}
}
-
+
/**
* Checks if a redirect url is valid
- *
* @param url URL to validate
* @return true if URL is a valid redirect URL, false otherwise
*/
- private boolean isValidRedirectURL(String url) {
- String redirectTo = url.substring(url.indexOf("?retURL=") + "?retURL=".length());
- try {
- redirectTo = URLDecoder.decode(redirectTo, StandardCharsets.UTF_8.toString());
- } catch (UnsupportedEncodingException e) {
- LOG.error(AaiUiMsgs.UNSUPPORTED_URL_ENCODING, e.getLocalizedMessage());
+ private boolean isValidRedirectURL (String url){
+ String redirectTo = url.substring(url.indexOf("?retURL=")+ "?retURL=".length());
+ try {
+ redirectTo = URLDecoder.decode(redirectTo, StandardCharsets.UTF_8.toString());
+ } catch (UnsupportedEncodingException e) {
+ LOG.error(AaiUiMsgs.UNSUPPORTED_URL_ENCODING, e.getLocalizedMessage());
+ return false;
+ }
+ for (String domain: this.redirectDomains){
+ if (redirectTo.endsWith(domain))
+ return true;
+ }
return false;
- }
- for (String domain : this.redirectDomains) {
- if (redirectTo.endsWith(domain))
- return true;
- }
- return false;
}
-
+
/**
* Returns <code>true</code> if the request is an AJAX request.
diff --git a/src/main/java/org/onap/aai/sparky/security/filter/LoginFilter.java b/src/main/java/org/onap/aai/sparky/security/filter/LoginFilter.java
index 2ec6b47..3cd5fc7 100644
--- a/src/main/java/org/onap/aai/sparky/security/filter/LoginFilter.java
+++ b/src/main/java/org/onap/aai/sparky/security/filter/LoginFilter.java
@@ -119,8 +119,7 @@ public class LoginFilter implements Filter {
final String restApiURI = request.getContextPath() + PortalApiConstants.API_PREFIX;
if (request.getRequestURI().startsWith(restApiURI)) {
// REST servlet checks credentials
- LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG,
- "doFilter: delegating auth to REST servlet for request " + request.getRequestURI());
+ LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG, "doFilter: delegating auth to REST servlet for request " + request.getRequestURI());
chain.doFilter(request, response);
} else {
// All other requests require ECOMP Portal authentication
@@ -137,25 +136,25 @@ public class LoginFilter implements Filter {
redirectURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL);
logMessage = "Unauthorized login attempt.";
}
-
+
LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG,
- logMessage + " | Remote IP: " + request.getRemoteAddr() + " | User agent: "
- + request.getHeader(HttpHeaders.USER_AGENT) + " | Request URL: "
- + request.getRequestURL() + " | Redirecting to: " + redirectURL);
-
+ logMessage +
+ " | Remote IP: " + request.getRemoteAddr() +
+ " | User agent: " + request.getHeader(HttpHeaders.USER_AGENT) +
+ " | Request URL: " + request.getRequestURL() +
+ " | Redirecting to: " + redirectURL);
+
response.sendRedirect(redirectURL);
} else {
HttpSession session = request.getSession(false);
if (session == null) {
// New session
session = request.getSession(true);
- LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG,
- "doFilter: created new session " + session.getId());
+ LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG, "doFilter: created new session " + session.getId());
initiateSessionMgtHandler(request);
} else {
// Existing session
- LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG,
- "doFilter: resetting idle in existing session " + session.getId());
+ LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG, "doFilter: resetting idle in existing session " + session.getId());
resetSessionMaxIdleTimeOut(request);
}
// Pass request back down the filter chain
@@ -221,16 +220,14 @@ public class LoginFilter implements Filter {
try {
HttpSession session = request.getSession(false);
if (session != null) {
- final Object maxIdleAttribute =
- session.getAttribute(PortalApiConstants.GLOBAL_SESSION_MAX_IDLE_TIME);
+ final Object maxIdleAttribute = session
+ .getAttribute(PortalApiConstants.GLOBAL_SESSION_MAX_IDLE_TIME);
if (maxIdleAttribute != null) {
session.setMaxInactiveInterval(Integer.parseInt(maxIdleAttribute.toString()));
}
}
} catch (Exception e) {
- LOG.info(AaiUiMsgs.LOGIN_FILTER_INFO,
- "resetSessionMaxIdleTimeOut: failed to set session max inactive interval - "
- + e.getLocalizedMessage());
+ LOG.info(AaiUiMsgs.LOGIN_FILTER_INFO, "resetSessionMaxIdleTimeOut: failed to set session max inactive interval - " + e.getLocalizedMessage());
}
}
diff --git a/src/main/java/org/onap/aai/sparky/security/portal/PortalRestAPIServiceImpl.java b/src/main/java/org/onap/aai/sparky/security/portal/PortalRestAPIServiceImpl.java
index d3ffac3..a39a05a 100644
--- a/src/main/java/org/onap/aai/sparky/security/portal/PortalRestAPIServiceImpl.java
+++ b/src/main/java/org/onap/aai/sparky/security/portal/PortalRestAPIServiceImpl.java
@@ -32,7 +32,7 @@ import javax.servlet.http.HttpServletRequest;
import org.onap.aai.sparky.security.EcompSso;
import org.onap.aai.sparky.security.portal.config.PortalAuthenticationConfig;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import org.openecomp.portalsdk.core.onboarding.crossapi.IPortalRestAPIService;
import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException;
import org.openecomp.portalsdk.core.restful.domain.EcompRole;
@@ -54,7 +54,7 @@ public class PortalRestAPIServiceImpl implements IPortalRestAPIService {
* Initialise user manager.
*/
public PortalRestAPIServiceImpl() {
- userManager = new UserManager(new File(TierSupportUiConstants.USERS_FILE_LOCATION));
+ userManager = new UserManager(new File(SparkyConstants.USERS_FILE_LOCATION));
}
/////////////////////////////////////////////////////////////////////////////
@@ -73,8 +73,8 @@ public class PortalRestAPIServiceImpl implements IPortalRestAPIService {
LOG.debug("Push user [loginId:" + user.getLoginId() + "]");
if (userManager.getUser(user.getLoginId()).isPresent()) {
- String message =
- getMessage(ERROR_MESSAGE, "push", user.getLoginId()) + ", user is already stored";
+ String message = getMessage(ERROR_MESSAGE, "push", user.getLoginId())
+ + ", user is already stored";
LOG.error(message);
throw new PortalAPIException(message);
}
@@ -147,12 +147,8 @@ public class PortalRestAPIServiceImpl implements IPortalRestAPIService {
/////////////////////////////////////////////////////////////////////////////
// Role interface
/////////////////////////////////////////////////////////////////////////////
- public List<EcompRole> getAvailableRoles() throws PortalAPIException {
- LOG.debug("Get available roles");
- return UserManager.getRoles();
- }
- public List<EcompRole> getAvailableRoles(String requestedLoginId) throws PortalAPIException {
+ public List<EcompRole> getAvailableRoles() throws PortalAPIException {
LOG.debug("Get available roles");
return UserManager.getRoles();
}
@@ -220,4 +216,11 @@ public class PortalRestAPIServiceImpl implements IPortalRestAPIService {
formatter.applyPattern(message);
return formatter.format(args);
}
-}
+
+ @Override
+ public List<EcompRole> getAvailableRoles(String requestedLoginId) throws PortalAPIException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/security/portal/UserManager.java b/src/main/java/org/onap/aai/sparky/security/portal/UserManager.java
index 9b8e8fc..acd6f55 100644
--- a/src/main/java/org/onap/aai/sparky/security/portal/UserManager.java
+++ b/src/main/java/org/onap/aai/sparky/security/portal/UserManager.java
@@ -69,7 +69,8 @@ public class UserManager {
* @return a list of users.
*/
public List<EcompUser> getUsers() {
- Type collectionType = new TypeToken<List<EcompUser>>() {}.getType();
+ Type collectionType = new TypeToken<List<EcompUser>>() {
+ }.getType();
Optional<String> users = read(usersFile);
if (users.isPresent()) {
@@ -164,4 +165,4 @@ public class UserManager {
READ_LOCK.unlock();
}
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/security/portal/config/PortalAuthenticationConfig.java b/src/main/java/org/onap/aai/sparky/security/portal/config/PortalAuthenticationConfig.java
index f58fc31..e707f93 100644
--- a/src/main/java/org/onap/aai/sparky/security/portal/config/PortalAuthenticationConfig.java
+++ b/src/main/java/org/onap/aai/sparky/security/portal/config/PortalAuthenticationConfig.java
@@ -26,7 +26,7 @@ import java.util.Properties;
import org.onap.aai.sparky.util.ConfigHelper;
import org.onap.aai.sparky.util.Encryptor;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
/**
@@ -41,8 +41,7 @@ public class PortalAuthenticationConfig {
public static final String PROP_USERNAME = "username";
public static final String PROP_PASSWORD = "password"; // NOSONAR
public static final String PROP_IS_ONAP_ENABLED = "onap_enabled"; // NOSONAR
- private static final String AUTHENTICATION_CONFIG_FILE =
- TierSupportUiConstants.PORTAL_AUTHENTICATION_FILE_LOCATION;
+ private static final String AUTHENTICATION_CONFIG_FILE = SparkyConstants.PORTAL_AUTHENTICATION_FILE_LOCATION;
private PortalAuthenticationConfig() {
// Prevent instantiation
@@ -74,7 +73,7 @@ public class PortalAuthenticationConfig {
Encryptor encryptor = new Encryptor();
return encryptor.decryptValue(password);
}
-
+
public boolean getIsOnapEnabled() {
return isOnapEnabled;
}
@@ -95,4 +94,4 @@ public class PortalAuthenticationConfig {
password = props.getProperty(PROP_PASSWORD);
isOnapEnabled = Boolean.parseBoolean(props.getProperty(PROP_IS_ONAP_ENABLED, "true"));
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/security/portal/config/RolesConfig.java b/src/main/java/org/onap/aai/sparky/security/portal/config/RolesConfig.java
index 3ec866e..c209340 100644
--- a/src/main/java/org/onap/aai/sparky/security/portal/config/RolesConfig.java
+++ b/src/main/java/org/onap/aai/sparky/security/portal/config/RolesConfig.java
@@ -30,7 +30,7 @@ import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import org.openecomp.portalsdk.core.restful.domain.EcompRole;
import com.google.gson.Gson;
@@ -45,7 +45,7 @@ public class RolesConfig {
private List<EcompRole> roles;
private static final Gson GSON = new Gson();
- private static final String ROLES_CONFIG_FILE = TierSupportUiConstants.ROLES_FILE_LOCATION;
+ private static final String ROLES_CONFIG_FILE = SparkyConstants.ROLES_FILE_LOCATION;
private RolesConfig() {
// Prevent instantiation
@@ -79,9 +79,10 @@ public class RolesConfig {
}
private void load() throws JsonSyntaxException, IOException, URISyntaxException {
- Type collectionType = new TypeToken<List<EcompRole>>() {}.getType();
+ Type collectionType = new TypeToken<List<EcompRole>>() {
+ }.getType();
roles = Collections.unmodifiableList(GSON
.fromJson(new String(Files.readAllBytes(Paths.get(ROLES_CONFIG_FILE))), collectionType));
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java b/src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java
index bf1a7ee..298a493 100644
--- a/src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java
+++ b/src/main/java/org/onap/aai/sparky/sync/AbstractEntitySynchronizer.java
@@ -35,7 +35,6 @@ import org.onap.aai.sparky.dal.NetworkTransaction;
import org.onap.aai.sparky.dal.aai.ActiveInventoryEntityStatistics;
import org.onap.aai.sparky.dal.aai.ActiveInventoryProcessingExceptionStatistics;
import org.onap.aai.sparky.dal.elasticsearch.ElasticSearchEntityStatistics;
-import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
import org.onap.aai.sparky.dal.rest.HttpMethod;
import org.onap.aai.sparky.dal.rest.RestOperationalStatistics;
import org.onap.aai.sparky.logging.AaiUiMsgs;
@@ -62,7 +61,8 @@ public abstract class AbstractEntitySynchronizer {
* The Enum StatFlag.
*/
protected enum StatFlag {
- AAI_REST_STATS, AAI_ENTITY_STATS, AAI_PROCESSING_EXCEPTION_STATS, AAI_TASK_PROCESSING_STATS, ES_REST_STATS, ES_ENTITY_STATS, ES_TASK_PROCESSING_STATS
+ AAI_REST_STATS, AAI_ENTITY_STATS, AAI_PROCESSING_EXCEPTION_STATS,
+ AAI_TASK_PROCESSING_STATS, ES_REST_STATS, ES_ENTITY_STATS, ES_TASK_PROCESSING_STATS
}
protected EnumSet<StatFlag> enabledStatFlags;
@@ -92,7 +92,6 @@ public abstract class AbstractEntitySynchronizer {
protected String synchronizerName;
protected abstract boolean isSyncDone();
-
protected boolean shouldSkipSync;
public String getActiveInventoryStatisticsReport() {
@@ -254,7 +253,7 @@ public abstract class AbstractEntitySynchronizer {
protected AbstractEntitySynchronizer(Logger logger, String syncName, int numSyncWorkers,
int numActiveInventoryWorkers, int numElasticsearchWorkers, String indexName,
NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig)
- throws Exception {
+ throws Exception {
this.logger = logger;
this.synchronizerExecutor =
NodeUtils.createNamedExecutor(syncName + "-INTERNAL", numSyncWorkers, logger);
@@ -263,14 +262,16 @@ public abstract class AbstractEntitySynchronizer {
this.esExecutor =
NodeUtils.createNamedExecutor(syncName + "-ES", numElasticsearchWorkers, logger);
this.mapper = new ObjectMapper();
- this.indexName = indexName;
+ this.indexName = indexName;
this.esRestStats = new RestOperationalStatistics();
this.esEntityStats = new ElasticSearchEntityStatistics();
this.aaiRestStats = new RestOperationalStatistics();
this.aaiEntityStats = new ActiveInventoryEntityStatistics();
this.aaiProcessingExceptionStats = new ActiveInventoryProcessingExceptionStatistics();
- this.aaiTaskProcessingStats = new TaskProcessingStats(aaiStatConfig);
- this.esTaskProcessingStats = new TaskProcessingStats(esStatConfig);
+ this.aaiTaskProcessingStats =
+ new TaskProcessingStats(aaiStatConfig);
+ this.esTaskProcessingStats =
+ new TaskProcessingStats(esStatConfig);
this.aaiTransactionRateController =
new TransactionRateMonitor(numActiveInventoryWorkers, aaiStatConfig);
@@ -283,9 +284,9 @@ public abstract class AbstractEntitySynchronizer {
enabledStatFlags = EnumSet.allOf(StatFlag.class);
this.synchronizerName = "Abstact Entity Synchronizer";
-
+
String txnID = NodeUtils.getRandomTxnId();
- MdcContext.initialize(txnID, "AbstractEntitySynchronizer", "", "Sync", "");
+ MdcContext.initialize(txnID, "AbstractEntitySynchronizer", "", "Sync", "");
this.shouldSkipSync = false;
this.syncStartedTimeStampInMs = System.currentTimeMillis();
@@ -345,9 +346,9 @@ public abstract class AbstractEntitySynchronizer {
if (esExecutor != null) {
esExecutor.shutdown();
}
-
+
} catch (Exception exc) {
- logger.error(AaiUiMsgs.ERROR_SHUTDOWN_EXECUTORS, exc);
+ logger.error(AaiUiMsgs.ERROR_SHUTDOWN_EXECUTORS, exc );
}
}
@@ -355,7 +356,7 @@ public abstract class AbstractEntitySynchronizer {
* Clear cache.
*/
public void clearCache() {}
-
+
public ElasticSearchAdapter getElasticSearchAdapter() {
return elasticSearchAdapter;
}
@@ -372,32 +373,6 @@ public abstract class AbstractEntitySynchronizer {
this.aaiAdapter = aaiAdapter;
}
- /**
- * Gets the elastic full url.
- *
- * @param resourceUrl the resource url
- * @param indexName the index name
- * @param indexType the index type
- * @return the elastic full url
- * @throws Exception the exception
- */
- protected String getElasticFullUrl(String resourceUrl, String indexName, String indexType)
- throws Exception {
- return ElasticSearchConfig.getConfig().getElasticFullUrl(resourceUrl, indexName, indexType);
- }
-
- /**
- * Gets the elastic full url.
- *
- * @param resourceUrl the resource url
- * @param indexName the index name
- * @return the elastic full url
- * @throws Exception the exception
- */
- protected String getElasticFullUrl(String resourceUrl, String indexName) throws Exception {
- return ElasticSearchConfig.getConfig().getElasticFullUrl(resourceUrl, indexName);
- }
-
public String getIndexName() {
return indexName;
}
@@ -473,7 +448,8 @@ public abstract class AbstractEntitySynchronizer {
esTransactionRateController.trackResponseTime(txn.getOpTimeInMs());
- esTaskProcessingStats.updateTaskResponseStatsHistogram(txn.getOpTimeInMs());
+ esTaskProcessingStats
+ .updateTaskResponseStatsHistogram(txn.getOpTimeInMs());
esTaskProcessingStats.updateTaskAgeStatsHistogram(txn.getTaskAgeInMs());
// don't know the cost of the lengh calc, we'll see if it causes a
@@ -531,9 +507,11 @@ public abstract class AbstractEntitySynchronizer {
}
if (enabledStatFlags.contains(StatFlag.AAI_TASK_PROCESSING_STATS)) {
- aaiTransactionRateController.trackResponseTime(txn.getOpTimeInMs());
+ aaiTransactionRateController
+ .trackResponseTime(txn.getOpTimeInMs());
- aaiTaskProcessingStats.updateTaskResponseStatsHistogram(txn.getOpTimeInMs());
+ aaiTaskProcessingStats
+ .updateTaskResponseStatsHistogram(txn.getOpTimeInMs());
aaiTaskProcessingStats.updateTaskAgeStatsHistogram(txn.getTaskAgeInMs());
// don't know the cost of the lengh calc, we'll see if it causes a
diff --git a/src/main/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleaner.java b/src/main/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleaner.java
index e1785d4..09056c0 100644
--- a/src/main/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleaner.java
+++ b/src/main/java/org/onap/aai/sparky/sync/ElasticSearchIndexCleaner.java
@@ -77,8 +77,7 @@ public class ElasticSearchIndexCleaner implements IndexCleaner {
* @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) {
+ public ElasticSearchIndexCleaner(ElasticSearchAdapter esAdapter, ElasticSearchEndpointConfig endpointConfig, ElasticSearchSchemaConfig schemaConfig) {
this.esAdapter = esAdapter;
this.before = null;
this.after = null;
@@ -148,8 +147,8 @@ public class ElasticSearchIndexCleaner implements IndexCleaner {
presyncIds.removeAll(after.getImportedObjectIds());
try {
- LOG.info(AaiUiMsgs.ES_SYNC_SELECTIVE_DELETE, schemaConfig.getIndexName(),
- schemaConfig.getIndexDocType(), String.valueOf(presyncIds.size()));
+ LOG.info(AaiUiMsgs.ES_SYNC_SELECTIVE_DELETE, schemaConfig.getIndexName(), schemaConfig.getIndexDocType(),
+ String.valueOf(presyncIds.size()));
ObjectIdCollection bulkIds = new ObjectIdCollection();
@@ -163,8 +162,7 @@ public class ElasticSearchIndexCleaner implements IndexCleaner {
numItemsInBulkRequest++;
if (numItemsInBulkRequest >= endpointConfig.getScrollContextBatchRequestSize()) {
- LOG.info(AaiUiMsgs.ES_BULK_DELETE, schemaConfig.getIndexName(),
- String.valueOf(bulkIds.getSize()));
+ LOG.info(AaiUiMsgs.ES_BULK_DELETE, schemaConfig.getIndexName(), String.valueOf(bulkIds.getSize()));
bulkDelete(bulkIds.getImportedObjectIds());
numItemsRemainingToBeDeleted -= numItemsInBulkRequest;
numItemsInBulkRequest = 0;
@@ -173,15 +171,13 @@ public class ElasticSearchIndexCleaner implements IndexCleaner {
}
if (numItemsRemainingToBeDeleted > 0) {
- LOG.info(AaiUiMsgs.ES_BULK_DELETE, schemaConfig.getIndexName(),
- String.valueOf(bulkIds.getSize()));
+ 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());
+ LOG.error(AaiUiMsgs.ES_BULK_DELETE_ERROR, schemaConfig.getIndexName(), exc.getLocalizedMessage());
}
}
@@ -365,9 +361,8 @@ public class ElasticSearchIndexCleaner implements IndexCleaner {
String scrollRequestPayload =
buildInitialScrollRequestPayload(endpointConfig.getScrollContextBatchRequestSize(), fields);
- final String fullUrlStr =
- getFullUrl("/" + schemaConfig.getIndexName() + "/" + schemaConfig.getIndexDocType()
- + "/_search?scroll=" + endpointConfig.getScrollContextTimeToLiveInMinutes() + "m");
+ final String fullUrlStr = getFullUrl("/" + schemaConfig.getIndexName()+ "/" + schemaConfig.getIndexDocType() + "/_search?scroll="
+ + endpointConfig.getScrollContextTimeToLiveInMinutes() + "m");
OperationResult result =
esAdapter.doPost(fullUrlStr, scrollRequestPayload, MediaType.APPLICATION_JSON_TYPE);
diff --git a/src/main/java/org/onap/aai/sparky/sync/ElasticSearchSchemaFactory.java b/src/main/java/org/onap/aai/sparky/sync/ElasticSearchSchemaFactory.java
index 9013600..77f5ad3 100644
--- a/src/main/java/org/onap/aai/sparky/sync/ElasticSearchSchemaFactory.java
+++ b/src/main/java/org/onap/aai/sparky/sync/ElasticSearchSchemaFactory.java
@@ -27,7 +27,7 @@ import java.io.IOException;
import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException;
import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
import org.onap.aai.sparky.util.ConfigHelper;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
@@ -59,8 +59,8 @@ public class ElasticSearchSchemaFactory {
return indexConfig;
}
-
-
+
+
public static String getIndexSchema(ElasticSearchSchemaConfig schemaConfig)
throws ElasticSearchOperationException {
@@ -71,18 +71,17 @@ public class ElasticSearchSchemaFactory {
if (schemaConfig.getIndexSettingsFileName() != null) {
esSettingsNode = mapper.readTree(getConfigAsString(SETTINGS,
- TierSupportUiConstants.getConfigPath(schemaConfig.getIndexSettingsFileName())));
+ SparkyConstants.getConfigPath(schemaConfig.getIndexSettingsFileName())));
}
if (schemaConfig.getIndexMappingsFileName() != null) {
esMappingsNodes = mapper.readTree(getConfigAsString(MAPPINGS,
- TierSupportUiConstants.getConfigPath(schemaConfig.getIndexMappingsFileName())));
+ SparkyConstants.getConfigPath(schemaConfig.getIndexMappingsFileName())));
}
} catch (IOException e1) {
-
- throw new ElasticSearchOperationException(
- "Caught an exception building initial ES index. Error: " + e1.getMessage());
+
+ throw new ElasticSearchOperationException("Caught an exception building initial ES index. Error: " + e1.getMessage());
}
ObjectNode esConfig = null;
diff --git a/src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java b/src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java
index a6941ad..6ba7d86 100644
--- a/src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java
+++ b/src/main/java/org/onap/aai/sparky/sync/IndexIntegrityValidator.java
@@ -101,7 +101,7 @@ public class IndexIntegrityValidator implements IndexValidator {
public boolean exists() {
final String fullUrlStr = getFullUrl("/" + schemaConfig.getIndexName() + "/");
OperationResult existsResult = esAdapter.doHead(fullUrlStr, MediaType.APPLICATION_JSON_TYPE);
-
+
int rc = existsResult.getResultCode();
if (rc >= 200 && rc < 300) {
@@ -130,7 +130,7 @@ public class IndexIntegrityValidator implements IndexValidator {
*/
@Override
public void createOrRepair() {
-
+
String message =
"IndexIntegrityValidator.createOrRepair() for indexName = " + schemaConfig.getIndexName();
LOG.info(AaiUiMsgs.INFO_GENERIC, message);
diff --git a/src/main/java/org/onap/aai/sparky/sync/SyncController.java b/src/main/java/org/onap/aai/sparky/sync/SyncController.java
index f482c66..ce6458e 100644
--- a/src/main/java/org/onap/aai/sparky/sync/SyncController.java
+++ b/src/main/java/org/onap/aai/sparky/sync/SyncController.java
@@ -32,16 +32,14 @@ import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
public interface SyncController {
String getControllerName();
-
boolean isPeriodicSyncEnabled();
-
boolean isRunOnceSyncEnabled();
/**
* Perform action.
*
* @param requestedAction the requested action
- * @return
+ * @return
*/
OperationState performAction(SyncActions requestedAction);
@@ -88,9 +86,9 @@ public interface SyncController {
Date getLastExecutionDate();
void setLastExecutionDate(Date lastExecutionDate);
-
+
Calendar getCreationTime();
-
+
String getNextSyncTime();
-
+
}
diff --git a/src/main/java/org/onap/aai/sparky/sync/SyncControllerImpl.java b/src/main/java/org/onap/aai/sparky/sync/SyncControllerImpl.java
index 1c3d425..67262ad 100644
--- a/src/main/java/org/onap/aai/sparky/sync/SyncControllerImpl.java
+++ b/src/main/java/org/onap/aai/sparky/sync/SyncControllerImpl.java
@@ -54,14 +54,16 @@ public class SyncControllerImpl implements SyncController {
* The Enum InternalState.
*/
private enum InternalState {
- IDLE, PRE_SYNC, SYNC_OPERATION, SELECTIVE_DELETE, ABORTING_SYNC, REPAIRING_INDEX, POST_SYNC, TEST_INDEX_INTEGRITY, GENERATE_FINAL_REPORT
+ IDLE, PRE_SYNC, SYNC_OPERATION, SELECTIVE_DELETE, ABORTING_SYNC, REPAIRING_INDEX, POST_SYNC,
+ TEST_INDEX_INTEGRITY, GENERATE_FINAL_REPORT
}
/**
* The Enum SyncActions.
*/
public enum SyncActions {
- SYNCHRONIZE, REPAIR_INDEX, INDEX_INTEGRITY_VALIDATION_COMPLETE, PRE_SYNC_COMPLETE, SYNC_COMPLETE, SYNC_ABORTED, SYNC_FAILURE, POST_SYNC_COMPLETE, PURGE_COMPLETE, REPORT_COMPLETE
+ SYNCHRONIZE, REPAIR_INDEX, INDEX_INTEGRITY_VALIDATION_COMPLETE, PRE_SYNC_COMPLETE,
+ SYNC_COMPLETE, SYNC_ABORTED, SYNC_FAILURE, POST_SYNC_COMPLETE, PURGE_COMPLETE, REPORT_COMPLETE
}
private Collection<IndexSynchronizer> registeredSynchronizers;
@@ -70,21 +72,22 @@ public class SyncControllerImpl implements SyncController {
private InternalState currentInternalState;
private ExecutorService syncControllerExecutor;
private ExecutorService statReporterExecutor;
-
+
private long delayInMs;
private long syncFrequencyInMs;
private Date syncStartTime;
-
+
private Date lastExecutionDate;
- private AtomicInteger runCount;
+ private AtomicInteger runCount;
private Semaphore performingActionGate;
private Calendar creationTime;
-
+
private String syncStartTimeWithTimeZone;
private String controllerName;
-
+
protected SyncControllerConfig syncControllerConfig;
-
+
+
/**
@@ -94,9 +97,9 @@ public class SyncControllerImpl implements SyncController {
* @throws Exception the exception
*/
public SyncControllerImpl(SyncControllerConfig syncControllerConfig) throws Exception {
- this(syncControllerConfig, null);
+ this(syncControllerConfig,null);
}
-
+
public SyncControllerImpl(SyncControllerConfig syncControllerConfig, String targetEntityType)
throws Exception {
@@ -117,7 +120,7 @@ public class SyncControllerImpl implements SyncController {
if (targetEntityType != null) {
controllerName += " (" + targetEntityType + ")";
}
-
+
this.controllerName = controllerName;
this.syncControllerExecutor = NodeUtils.createNamedExecutor("SyncController-" + controllerName,
@@ -127,13 +130,16 @@ public class SyncControllerImpl implements SyncController {
this.currentInternalState = InternalState.IDLE;
- this.creationTime = Calendar
- .getInstance(TimeZone.getTimeZone(syncControllerConfig.getTimeZoneOfSyncStartTimeStamp()));
+ this.creationTime =
+ Calendar.getInstance(TimeZone.getTimeZone(syncControllerConfig.getTimeZoneOfSyncStartTimeStamp()));
}
+
+
-
+
+
/**
* Change internal state.
*
@@ -141,19 +147,17 @@ public class SyncControllerImpl implements SyncController {
* @param causedByAction the caused by action
*/
private void changeInternalState(InternalState newState, SyncActions causedByAction) {
- LOG.info(AaiUiMsgs.SYNC_INTERNAL_STATE_CHANGED, controllerName, currentInternalState.toString(),
- newState.toString(), causedByAction.toString());
+ LOG.info(AaiUiMsgs.SYNC_INTERNAL_STATE_CHANGED, controllerName,
+ currentInternalState.toString(), newState.toString(), causedByAction.toString());
this.currentInternalState = newState;
performStateAction();
}
-
-
-
- /*
- * (non-Javadoc)
- *
+
+
+
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#getDelayInMs()
*/
@Override
@@ -161,9 +165,7 @@ public class SyncControllerImpl implements SyncController {
return delayInMs;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#setDelayInMs(long)
*/
@Override
@@ -171,9 +173,7 @@ public class SyncControllerImpl implements SyncController {
this.delayInMs = delayInMs;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#getSyncFrequencyInMs()
*/
@Override
@@ -181,9 +181,7 @@ public class SyncControllerImpl implements SyncController {
return syncFrequencyInMs;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#setSyncFrequencyInMs(long)
*/
@Override
@@ -191,9 +189,7 @@ public class SyncControllerImpl implements SyncController {
this.syncFrequencyInMs = syncFrequencyInMs;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#getSyncStartTime()
*/
@Override
@@ -201,9 +197,7 @@ public class SyncControllerImpl implements SyncController {
return syncStartTime;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#setSyncStartTime(java.util.Date)
*/
@Override
@@ -211,9 +205,7 @@ public class SyncControllerImpl implements SyncController {
this.syncStartTime = syncStartTime;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#getLastExecutionDate()
*/
@Override
@@ -221,35 +213,34 @@ public class SyncControllerImpl implements SyncController {
return lastExecutionDate;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#setLastExecutionDate(java.util.Date)
*/
@Override
public void setLastExecutionDate(Date lastExecutionDate) {
this.lastExecutionDate = lastExecutionDate;
}
-
+
@Override
public String getControllerName() {
return controllerName;
}
-
-
+
+
+
@Override
public OperationState performAction(SyncActions requestedAction) {
if (currentInternalState == InternalState.IDLE) {
-
+
try {
-
+
/*
* non-blocking semaphore acquire used to guarantee only 1 execution of the synchronization
* at a time.
*/
-
+
switch (requestedAction) {
case SYNCHRONIZE:
@@ -270,19 +261,18 @@ public class SyncControllerImpl implements SyncController {
long opEndTime = System.currentTimeMillis();
long opTime = (opEndTime - opStartTime);
-
+
String durationMessage =
String.format(getControllerName() + " synchronization took '%d' ms.", opTime);
LOG.info(AaiUiMsgs.SYNC_DURATION, durationMessage);
-
+
if (syncControllerConfig.isPeriodicSyncEnabled()) {
LOG.info(AaiUiMsgs.INFO_GENERIC,
getControllerName() + " next sync to begin at " + getNextSyncTime());
- TimeZone tz =
- TimeZone.getTimeZone(syncControllerConfig.getTimeZoneOfSyncStartTimeStamp());
+ TimeZone tz = TimeZone.getTimeZone(syncControllerConfig.getTimeZoneOfSyncStartTimeStamp());
if (opTime > this.getSyncFrequencyInMs()) {
@@ -311,7 +301,7 @@ public class SyncControllerImpl implements SyncController {
default:
break;
}
-
+
return OperationState.OK;
} catch (Exception exc) {
@@ -320,7 +310,7 @@ public class SyncControllerImpl implements SyncController {
LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
return OperationState.ERROR;
} finally {
-
+
}
} else {
LOG.error(AaiUiMsgs.SYNC_NOT_VALID_STATE_DURING_REQUEST, currentInternalState.toString());
@@ -538,9 +528,7 @@ public class SyncControllerImpl implements SyncController {
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncControllerInterface#shutdown()
*/
@Override
@@ -624,9 +612,9 @@ public class SyncControllerImpl implements SyncController {
}
}
- if (System.currentTimeMillis() > nextReportTimeStampInMs) {
+ if ( System.currentTimeMillis() > nextReportTimeStampInMs) {
dumpPeriodicStatReport = true;
- nextReportTimeStampInMs = System.currentTimeMillis() + 30000L;
+ nextReportTimeStampInMs = System.currentTimeMillis() + 30000L;
} else {
dumpPeriodicStatReport = false;
}
@@ -646,9 +634,7 @@ public class SyncControllerImpl implements SyncController {
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncControllerInterface#getState()
*/
@Override
@@ -688,5 +674,5 @@ public class SyncControllerImpl implements SyncController {
public boolean isRunOnceSyncEnabled() {
return syncControllerConfig.isRunOnceSyncEnabled();
}
-
-}
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/sync/SyncControllerRegistry.java b/src/main/java/org/onap/aai/sparky/sync/SyncControllerRegistry.java
index 90845e0..51ba5f8 100644
--- a/src/main/java/org/onap/aai/sparky/sync/SyncControllerRegistry.java
+++ b/src/main/java/org/onap/aai/sparky/sync/SyncControllerRegistry.java
@@ -26,13 +26,13 @@ import java.util.ArrayList;
import java.util.List;
public class SyncControllerRegistry {
-
+
private List<SyncController> controllers;
-
+
public SyncControllerRegistry() {
controllers = new ArrayList<SyncController>();
}
-
+
public void registerSyncController(SyncController controller) {
controllers.add(controller);
}
diff --git a/src/main/java/org/onap/aai/sparky/sync/SyncControllerService.java b/src/main/java/org/onap/aai/sparky/sync/SyncControllerService.java
index a137065..4836cac 100644
--- a/src/main/java/org/onap/aai/sparky/sync/SyncControllerService.java
+++ b/src/main/java/org/onap/aai/sparky/sync/SyncControllerService.java
@@ -208,7 +208,7 @@ public class SyncControllerService implements ApplicationListener<ApplicationCon
/*
* Start sync service processing when spring-context-initialization has finished
*/
-
+
if (!syncStarted) {
syncStarted = true;
startSync();
diff --git a/src/main/java/org/onap/aai/sparky/sync/SynchronizerConstants.java b/src/main/java/org/onap/aai/sparky/sync/SynchronizerConstants.java
index 73d34bc..d709454 100644
--- a/src/main/java/org/onap/aai/sparky/sync/SynchronizerConstants.java
+++ b/src/main/java/org/onap/aai/sparky/sync/SynchronizerConstants.java
@@ -39,7 +39,7 @@ public final class SynchronizerConstants {
public static final String DEPTH_ALL_MODIFIER = "?depth=all";
public static final String DEPTH_AND_NODES_ONLY_MODIFIER = "?depth=0&nodes-only";
public static final String NODES_ONLY_MODIFIER = "?nodes-only";
-
+
// constants for scheduling synchronizer
public static final int COMPONENTS_IN_TIMESTAMP = 2;
public static final String DEFAULT_INITIAL_DELAY_IN_MS = "0";
diff --git a/src/main/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfig.java b/src/main/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfig.java
index 6bea1a4..63d9828 100644
--- a/src/main/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfig.java
+++ b/src/main/java/org/onap/aai/sparky/sync/config/ElasticSearchEndpointConfig.java
@@ -30,9 +30,9 @@ public class ElasticSearchEndpointConfig {
private int scrollContextBatchRequestSize;
public ElasticSearchEndpointConfig() {
-
+
}
-
+
public String getEsIpAddress() {
return esIpAddress;
}
diff --git a/src/main/java/org/onap/aai/sparky/sync/config/NetworkStatisticsConfig.java b/src/main/java/org/onap/aai/sparky/sync/config/NetworkStatisticsConfig.java
index 34de88b..70295e0 100644
--- a/src/main/java/org/onap/aai/sparky/sync/config/NetworkStatisticsConfig.java
+++ b/src/main/java/org/onap/aai/sparky/sync/config/NetworkStatisticsConfig.java
@@ -23,7 +23,7 @@
package org.onap.aai.sparky.sync.config;
public class NetworkStatisticsConfig {
-
+
private int numSamplesPerThreadForRunningAverage;
private String bytesHistogramLabel;
@@ -73,7 +73,7 @@ public class NetworkStatisticsConfig {
public void setNumSamplesPerThreadForRunningAverage(int numSamplesPerThreadForRunningAverage) {
this.numSamplesPerThreadForRunningAverage = numSamplesPerThreadForRunningAverage;
}
-
+
public String getBytesHistogramLabel() {
return bytesHistogramLabel;
}
diff --git a/src/main/java/org/onap/aai/sparky/sync/config/SyncControllerConfig.java b/src/main/java/org/onap/aai/sparky/sync/config/SyncControllerConfig.java
index eb3a73f..3b367dc 100644
--- a/src/main/java/org/onap/aai/sparky/sync/config/SyncControllerConfig.java
+++ b/src/main/java/org/onap/aai/sparky/sync/config/SyncControllerConfig.java
@@ -43,17 +43,17 @@ public class SyncControllerConfig {
private boolean enabled;
private int syncTaskDelayInMs;
private int syncTaskFrequencyInDays;
-
+
private int numSyncControllerWorkers;
private boolean runOnceSyncEnabled;
private boolean periodicSyncEnabled;
-
+
private String targetSyncStartTimeStamp;
private int numInternalSyncWorkers;
private int numSyncElasticWorkers;
private int numSyncActiveInventoryWorkers;
-
+
/*
* calculated variables based on incoming config
*/
@@ -61,8 +61,8 @@ public class SyncControllerConfig {
private int syncTaskStartTimeHr;
private int syncTaskStartTimeMin;
private int syncTaskStartTimeSec;
-
-
+
+
public SyncControllerConfig() {
controllerName = UNKNOWN_CONTROLLER_NAME;
@@ -273,7 +273,7 @@ public class SyncControllerConfig {
* @param taskFrequencyInMs task period in ms
* @return the first sync time
*/
-
+
public long getNextSyncTime(Calendar syncTime, long timeNowInMs, int taskFrequencyInSeconds) {
if (taskFrequencyInSeconds == 0) {
return 0;
@@ -297,7 +297,7 @@ public class SyncControllerConfig {
public void setTimeZoneOfSyncStartTimeStamp(String timeZoneOfSyncStartTimeStamp) {
this.timeZoneOfSyncStartTimeStamp = timeZoneOfSyncStartTimeStamp;
}
-
-
+
+
}
diff --git a/src/main/java/org/onap/aai/sparky/sync/entity/AggregationEntity.java b/src/main/java/org/onap/aai/sparky/sync/entity/AggregationEntity.java
index c4f805e..e2061b1 100644
--- a/src/main/java/org/onap/aai/sparky/sync/entity/AggregationEntity.java
+++ b/src/main/java/org/onap/aai/sparky/sync/entity/AggregationEntity.java
@@ -36,7 +36,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
public class AggregationEntity extends IndexableEntity implements IndexDocument {
private Map<String, String> attributes = new HashMap<String, String>();
protected ObjectMapper mapper = new ObjectMapper();
-
+
/**
* Instantiates a new aggregation entity.
*/
@@ -44,9 +44,7 @@ public class AggregationEntity extends IndexableEntity implements IndexDocument
super();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
*/
@Override
@@ -58,20 +56,19 @@ public class AggregationEntity extends IndexableEntity implements IndexDocument
* 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.
*/
- this.id = NodeUtils.generateUniqueShaDigest(link);
+ this.id =
+ NodeUtils.generateUniqueShaDigest(link);
}
- public void copyAttributeKeyValuePair(Map<String, Object> map) {
- for (String key : map.keySet()) {
- if (!key.equalsIgnoreCase("relationship-list")) { // ignore relationship data which is not
- // required in aggregation
- this.attributes.put(key, map.get(key).toString()); // not sure if entity attribute can
- // contain an object as value
+ public void copyAttributeKeyValuePair(Map<String, Object> map){
+ for(String key: map.keySet()){
+ if (!key.equalsIgnoreCase("relationship-list")){ // ignore relationship data which is not required in aggregation
+ this.attributes.put(key, map.get(key).toString()); // not sure if entity attribute can contain an object as value
}
}
}
-
- public void addAttributeKeyValuePair(String key, String value) {
+
+ public void addAttributeKeyValuePair(String key, String value){
this.attributes.put(key, value);
}
@@ -80,15 +77,13 @@ public class AggregationEntity extends IndexableEntity implements IndexDocument
ObjectNode rootNode = mapper.createObjectNode();
rootNode.put("link", this.getLink());
rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
- for (String key : this.attributes.keySet()) {
+ for (String key: this.attributes.keySet()){
rootNode.put(key, this.attributes.get(key));
}
return rootNode.toString();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/sync/entity/AggregationSuggestionEntity.java b/src/main/java/org/onap/aai/sparky/sync/entity/AggregationSuggestionEntity.java
index 9ee6365..62a08b7 100644
--- a/src/main/java/org/onap/aai/sparky/sync/entity/AggregationSuggestionEntity.java
+++ b/src/main/java/org/onap/aai/sparky/sync/entity/AggregationSuggestionEntity.java
@@ -32,20 +32,25 @@ import org.onap.aai.sparky.search.filters.config.UiFilterListItemConfig;
import org.onap.aai.sparky.search.filters.config.UiViewListItemConfig;
import org.onap.aai.sparky.util.NodeUtils;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AggregationSuggestionEntity extends IndexableEntity implements IndexDocument {
private static final String FILTER_ID = "filterId";
private static final String FILTER_LIST = "filterList";
-
+
private List<String> inputs = new ArrayList<>();
private final String outputString = "VNFs";
protected ObjectMapper mapper = new ObjectMapper();
List<String> filterIds = new ArrayList<>();
-
- public AggregationSuggestionEntity() {
+
+ @JsonIgnore
+ private FiltersConfig filtersConfig;
+
+ public AggregationSuggestionEntity(FiltersConfig filtersConfig) {
super();
+ this.filtersConfig = filtersConfig;
inputs.add("VNFs");
inputs.add("generic-vnfs");
}
@@ -58,10 +63,10 @@ public class AggregationSuggestionEntity extends IndexableEntity implements Inde
@Override
public String getAsJson() {
JSONArray inputArray = new JSONArray();
- for (String input : inputs) {
- input = input.replace(",", "");
- input = input.replace("[", "");
- input = input.replace("]", "");
+ for (String input: inputs) {
+ input = input.replace(",","" );
+ input = input.replace("[","" );
+ input = input.replace("]","" );
inputArray.put(input);
}
@@ -81,7 +86,7 @@ public class AggregationSuggestionEntity extends IndexableEntity implements Inde
JSONObject payloadNode = new JSONObject();
payloadNode.put(FILTER_LIST, payloadFilters);
entitySuggest.put("payload", payloadNode);
-
+
JSONObject rootNode = new JSONObject();
rootNode.put("entity_suggest", entitySuggest);
@@ -89,7 +94,7 @@ public class AggregationSuggestionEntity extends IndexableEntity implements Inde
}
public void initializeFilters() {
- for (UiViewListItemConfig view : FiltersConfig.getInstance().getViewsConfig().getViews()) {
+ for (UiViewListItemConfig view : filtersConfig.getViewsConfig().getViews()) {
if (view.getViewName().equals("vnfSearch")) {
for (UiFilterListItemConfig currentViewFilter : view.getFilters()) {
filterIds.add(currentViewFilter.getFilterId());
diff --git a/src/main/java/org/onap/aai/sparky/sync/entity/IndexDocument.java b/src/main/java/org/onap/aai/sparky/sync/entity/IndexDocument.java
index f7818a4..551a046 100644
--- a/src/main/java/org/onap/aai/sparky/sync/entity/IndexDocument.java
+++ b/src/main/java/org/onap/aai/sparky/sync/entity/IndexDocument.java
@@ -26,14 +26,14 @@ package org.onap.aai.sparky.sync.entity;
* The Interface IndexDocument.
*/
public interface IndexDocument {
-
+
/**
* Derive fields.
*/
public void deriveFields();
public String getId();
-
- public String getAsJson() throws Exception;
-
+
+ public String getAsJson() throws Exception;
+
}
diff --git a/src/main/java/org/onap/aai/sparky/sync/entity/SearchableEntity.java b/src/main/java/org/onap/aai/sparky/sync/entity/SearchableEntity.java
index dd52bd2..786c798 100644
--- a/src/main/java/org/onap/aai/sparky/sync/entity/SearchableEntity.java
+++ b/src/main/java/org/onap/aai/sparky/sync/entity/SearchableEntity.java
@@ -36,13 +36,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
* The Class SearchableEntity.
*/
public class SearchableEntity extends IndexableEntity implements IndexDocument {
-
+
@JsonIgnore
protected List<String> searchTagCollection = new ArrayList<String>();
-
+
@JsonIgnore
protected List<String> searchTagIdCollection = new ArrayList<String>();
-
+
@JsonIgnore
protected ObjectMapper mapper = new ObjectMapper();
@@ -56,11 +56,11 @@ public class SearchableEntity extends IndexableEntity implements IndexDocument {
/*
* Generated fields, leave the settings for junit overrides
*/
-
+
protected String searchTags; // generated based on searchTagCollection values
-
+
protected String searchTagIDs;
-
+
/**
* Generates the sha based id.
*/
@@ -68,9 +68,7 @@ public class SearchableEntity extends IndexableEntity implements IndexDocument {
this.id = NodeUtils.generateUniqueShaDigest(link);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
*/
@Override
@@ -119,13 +117,11 @@ public class SearchableEntity extends IndexableEntity implements IndexDocument {
@Override
@JsonIgnore
- public String getAsJson() throws JsonProcessingException {
+ public String getAsJson() throws JsonProcessingException {
return NodeUtils.convertObjectToJson(this, false);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/sync/entity/SelfLinkDescriptor.java b/src/main/java/org/onap/aai/sparky/sync/entity/SelfLinkDescriptor.java
index 9d2886e..7636b10 100644
--- a/src/main/java/org/onap/aai/sparky/sync/entity/SelfLinkDescriptor.java
+++ b/src/main/java/org/onap/aai/sparky/sync/entity/SelfLinkDescriptor.java
@@ -57,7 +57,7 @@ public class SelfLinkDescriptor {
public SelfLinkDescriptor(String selfLink) {
this(selfLink, null, null);
}
-
+
/**
* Instantiates a new self link descriptor.
*
@@ -74,9 +74,7 @@ public class SelfLinkDescriptor {
this.depthModifier = depthModifier;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/sync/entity/SuggestionSearchEntity.java b/src/main/java/org/onap/aai/sparky/sync/entity/SuggestionSearchEntity.java
index fdabf86..5d7b55d 100644
--- a/src/main/java/org/onap/aai/sparky/sync/entity/SuggestionSearchEntity.java
+++ b/src/main/java/org/onap/aai/sparky/sync/entity/SuggestionSearchEntity.java
@@ -42,9 +42,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class SuggestionSearchEntity extends IndexableEntity implements IndexDocument {
private static final String FILTER_ID = "filterId";
- private static final String FILTER_VALUE = "filterValue";
- private static final String FILTER_LIST = "filterList";
-
+ private static final String FILTER_VALUE = "filterValue";
+ private static final String FILTER_LIST = "filterList";
+
private String entityType;
private List<String> suggestionConnectorWords = new ArrayList<String>();
private List<String> suggestionAttributeTypes = new ArrayList<String>();
@@ -52,16 +52,16 @@ public class SuggestionSearchEntity extends IndexableEntity implements IndexDocu
private List<String> suggestionTypeAliases = new ArrayList<String>();
private List<String> suggestionInputPermutations = new ArrayList<String>();
private List<String> suggestableAttr = new ArrayList<String>();
-
+
private Map<String, String> inputOutputData = new HashMap<String, String>();
Map<String, UiFilterConfig> filters = new HashMap<String, UiFilterConfig>();
private JSONObject payload = new JSONObject();
private JSONArray payloadFilters = new JSONArray();
private StringBuffer outputString = new StringBuffer();
private String aliasToUse;
-
+
private SuggestionEntityLookup entityLookup;
-
+
public JSONObject getPayload() {
return payload;
}
@@ -69,40 +69,41 @@ public class SuggestionSearchEntity extends IndexableEntity implements IndexDocu
public void setPayload(JSONObject payload) {
this.payload = payload;
}
-
+
protected ObjectMapper mapper = new ObjectMapper();
- public SuggestionSearchEntity() {
+ public SuggestionSearchEntity(FiltersConfig filtersConfig) {
super();
-
- FiltersDetailsConfig filterConfigList = FiltersConfig.getInstance().getFiltersConfig();
+
+ FiltersDetailsConfig filterConfigList = filtersConfig.getFiltersConfig();
// Populate the map with keys that will match the suggestableAttr values
- for (UiFilterConfig filter : filterConfigList.getFilters()) {
- if (filter.getDataSource() != null) {
+ for(UiFilterConfig filter : filterConfigList.getFilters()) {
+ if(filter.getDataSource() != null) {
filters.put(filter.getDataSource().getFieldName(), filter);
}
}
}
-
- public SuggestionSearchEntity(SuggestionEntityLookup entityLookup) {
-
+
+ public SuggestionSearchEntity(FiltersConfig filtersConfig, SuggestionEntityLookup entityLookup) {
+
this.entityLookup = entityLookup;
-
- FiltersDetailsConfig filterConfigList = FiltersConfig.getInstance().getFiltersConfig();
+
+ FiltersDetailsConfig filterConfigList = filtersConfig.getFiltersConfig();
+
// Populate the map with keys that will match the suggestableAttr values
- for (UiFilterConfig filter : filterConfigList.getFilters()) {
- if (filter.getDataSource() != null) {
+ for(UiFilterConfig filter : filterConfigList.getFilters()) {
+ if(filter.getDataSource() != null) {
filters.put(filter.getDataSource().getFieldName(), filter);
}
}
}
-
+
public SuggestionSearchEntity(SuggestionEntityLookup entityLookup, FiltersConfig config) {
-
+
FiltersDetailsConfig filterConfigList = config.getFiltersConfig();
// Populate the map with keys that will match the suggestableAttr values
- for (UiFilterConfig filter : filterConfigList.getFilters()) {
- if (filter.getDataSource() != null) {
+ for(UiFilterConfig filter : filterConfigList.getFilters()) {
+ if(filter.getDataSource() != null) {
filters.put(filter.getDataSource().getFieldName(), filter);
}
}
@@ -125,49 +126,49 @@ public class SuggestionSearchEntity extends IndexableEntity implements IndexDocu
}
}
}
-
- public void setFilterBasedPayloadFromResponse(JsonNode node, String entityName,
- ArrayList<String> uniqueList) {
-
+
+ public void setFilterBasedPayloadFromResponse(JsonNode node, String entityName, ArrayList<String> uniqueList) {
+
HashMap<String, String> desc = entityLookup.getSuggestionSearchEntityOxmModel().get(entityName);
-
- if (desc == null) {
+
+ if ( desc == null ) {
return;
}
-
+
String attr = desc.get("suggestibleAttributes");
-
- if (attr == null) {
+
+ if ( attr == null ) {
return;
}
-
+
List<String> suggestableAttrOxm = Arrays.asList(attr.split(","));
-
+
/*
- * Note: (1) 'uniqueList' is one item within the power set of the suggestable attributes. (2)
- * 'inputeOutputData' is used to generate permutations of strings
+ * Note:
+ * (1) 'uniqueList' is one item within the power set of the suggestable attributes.
+ * (2) 'inputeOutputData' is used to generate permutations of strings
*/
- for (String selectiveAttr : uniqueList) {
+ for (String selectiveAttr: uniqueList) {
if (node.get(selectiveAttr) != null) {
inputOutputData.put(selectiveAttr, node.get(selectiveAttr).asText());
}
}
-
+
if (suggestableAttrOxm != null) {
for (String attribute : suggestableAttrOxm) {
if (node.get(attribute) != null && uniqueList.contains(attribute)) {
UiFilterConfig filterConfig = filters.get(attribute);
- if (filterConfig != null) {
+ if(filterConfig != null) {
JSONObject filterPayload = new JSONObject();
filterPayload.put(FILTER_ID, filterConfig.getFilterId());
filterPayload.put(FILTER_VALUE, node.get(attribute).asText());
this.payloadFilters.put(filterPayload);
} else {
- this.payload.put(attribute, node.get(attribute).asText());
+ this.payload.put(attribute, node.get(attribute).asText());
}
} else {
UiFilterConfig emptyValueFilterConfig = filters.get(attribute);
- if (emptyValueFilterConfig != null) {
+ if(emptyValueFilterConfig != null) {
JSONObject emptyValueFilterPayload = new JSONObject();
emptyValueFilterPayload.put(FILTER_ID, emptyValueFilterConfig.getFilterId());
this.payloadFilters.put(emptyValueFilterPayload);
@@ -232,8 +233,7 @@ public class SuggestionSearchEntity extends IndexableEntity implements IndexDocu
List<String> entityNames = new ArrayList<>();
entityNames.add(entityType);
- HashMap<String, String> desc =
- entityLookup.getSuggestionSearchEntityOxmModel().get(this.entityType);
+ HashMap<String, String> desc = entityLookup.getSuggestionSearchEntityOxmModel().get(this.entityType);
String attr = desc.get("suggestionAliases");
String[] suggestionAliasesArray = attr.split(",");
suggestionTypeAliases = Arrays.asList(suggestionAliasesArray);
@@ -244,14 +244,14 @@ public class SuggestionSearchEntity extends IndexableEntity implements IndexDocu
ArrayList<String> listToPermutate = new ArrayList<>(inputOutputData.values());
- for (String entity : entityNames) {
+ for (String entity : entityNames){
listToPermutate.add(entity); // add entity-name or alias in list to permutate
List<List<String>> lists = SuggestionsPermutation.getListPermutations(listToPermutate);
- for (List<String> li : lists) {
+ for (List<String> li : lists){
suggestionInputPermutations.add(String.join(" ", li));
}
// prepare for the next pass: remove the entity-name or alias from the list
- listToPermutate.remove(entity);
+ listToPermutate.remove(entity);
}
}
@@ -262,20 +262,20 @@ public class SuggestionSearchEntity extends IndexableEntity implements IndexDocu
@Override
public void deriveFields() {
-
+
int entryCounter = 1;
for (Map.Entry<String, String> outputValue : inputOutputData.entrySet()) {
if (outputValue.getValue() != null && outputValue.getValue().length() > 0) {
this.outputString.append(outputValue.getValue());
if (entryCounter < inputOutputData.entrySet().size()) {
this.outputString.append(" and ");
- } else {
+ } else{
this.outputString.append(" ");
}
}
entryCounter++;
}
-
+
this.outputString.append(this.getAliasToUse());
this.id = NodeUtils.generateUniqueShaDigest(outputString.toString());
}
diff --git a/src/main/java/org/onap/aai/sparky/sync/task/PerformActiveInventoryRetrieval.java b/src/main/java/org/onap/aai/sparky/sync/task/PerformActiveInventoryRetrieval.java
index 55c8d47..126b802 100644
--- a/src/main/java/org/onap/aai/sparky/sync/task/PerformActiveInventoryRetrieval.java
+++ b/src/main/java/org/onap/aai/sparky/sync/task/PerformActiveInventoryRetrieval.java
@@ -43,8 +43,7 @@ import org.slf4j.MDC;
*/
public class PerformActiveInventoryRetrieval implements Supplier<NetworkTransaction> {
- private static Logger logger =
- LoggerFactory.getInstance().getLogger(PerformActiveInventoryRetrieval.class);
+ private static Logger logger = LoggerFactory.getInstance().getLogger(PerformActiveInventoryRetrieval.class);
private NetworkTransaction txn;
private ActiveInventoryAdapter aaiAdapter;
@@ -63,9 +62,7 @@ public class PerformActiveInventoryRetrieval implements Supplier<NetworkTransact
this.contextMap = MDC.getCopyOfContextMap();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.util.function.Supplier#get()
*/
@Override
@@ -78,12 +75,10 @@ public class PerformActiveInventoryRetrieval implements Supplier<NetworkTransact
OperationResult result = null;
try {
- final String absoluteSelfLink =
- aaiAdapter.repairSelfLink(txn.getLink(), txn.getQueryParameters());
+ final String absoluteSelfLink = aaiAdapter.repairSelfLink(txn.getLink(), txn.getQueryParameters());
result = aaiAdapter.queryActiveInventoryWithRetries(absoluteSelfLink, "application/json", 5);
} catch (Exception exc) {
- logger.error(AaiUiMsgs.ERROR_GENERIC,
- "Failure to resolve self link from AAI. Error = " + exc.getMessage());
+ logger.error(AaiUiMsgs.ERROR_GENERIC,"Failure to resolve self link from AAI. Error = " + exc.getMessage());
result = new OperationResult(500,
"Caught an exception while trying to resolve link = " + exc.getMessage());
} finally {
diff --git a/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchPut.java b/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchPut.java
index 6359dbe..1affa95 100644
--- a/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchPut.java
+++ b/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchPut.java
@@ -74,7 +74,7 @@ public class PerformElasticSearchPut implements Supplier<NetworkTransaction> {
public NetworkTransaction get() {
txn.setTaskAgeInMs();
MDC.setContextMap(contextMap);
-
+
long startTimeInMs = System.currentTimeMillis();
OperationResult or =
diff --git a/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchRetrieval.java b/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchRetrieval.java
index 0f37a0d..1e0bec6 100644
--- a/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchRetrieval.java
+++ b/src/main/java/org/onap/aai/sparky/sync/task/PerformElasticSearchRetrieval.java
@@ -54,15 +54,13 @@ public class PerformElasticSearchRetrieval implements Supplier<NetworkTransactio
this.contextMap = MDC.getCopyOfContextMap();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.util.function.Supplier#get()
*/
@Override
public NetworkTransaction get() {
- MDC.setContextMap(contextMap);
- long startTimeInMs = System.currentTimeMillis();
+ MDC.setContextMap(contextMap);
+ long startTimeInMs = System.currentTimeMillis();
OperationResult or = esAdapter.doGet(txn.getLink(), MediaType.APPLICATION_JSON_TYPE);
txn.setOperationResult(or);
txn.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);
diff --git a/src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java b/src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java
index 4ef796d..a184e50 100644
--- a/src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java
+++ b/src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java
@@ -60,9 +60,7 @@ public class StoreDocumentTask implements Supplier<NetworkTransaction> {
this.contextMap = MDC.getCopyOfContextMap();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.util.function.Supplier#get()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/topology/sync/GeoSyncController.java b/src/main/java/org/onap/aai/sparky/topology/sync/GeoSyncController.java
index a2acc06..2ea1ba7 100644
--- a/src/main/java/org/onap/aai/sparky/topology/sync/GeoSyncController.java
+++ b/src/main/java/org/onap/aai/sparky/topology/sync/GeoSyncController.java
@@ -22,6 +22,8 @@
*/
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;
@@ -43,12 +45,12 @@ public class GeoSyncController extends SyncControllerImpl implements SyncControl
public GeoSyncController(SyncControllerConfig syncControllerConfig,
ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
- NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig)
- throws Exception {
+ NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
+ GeoEntityLookup geoEntityLookup, OxmEntityLookup oxmEntityLookup) throws Exception {
super(syncControllerConfig);
// final String controllerName = "Inventory Geo Synchronizer";
-
+
IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(esAdapter, schemaConfig,
endpointConfig, ElasticSearchSchemaFactory.getIndexSchema(schemaConfig));
@@ -57,7 +59,8 @@ public class GeoSyncController extends SyncControllerImpl implements SyncControl
GeoSynchronizer synchronizer =
new GeoSynchronizer(schemaConfig, syncControllerConfig.getNumInternalSyncWorkers(),
syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig);
+ syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig,
+ geoEntityLookup, oxmEntityLookup);
synchronizer.setAaiAdapter(aaiAdapter);
synchronizer.setElasticSearchAdapter(esAdapter);
@@ -83,8 +86,8 @@ public class GeoSyncController extends SyncControllerImpl implements SyncControl
@Override
public void registerController() {
- if (syncControllerRegistry != null) {
- if (syncControllerConfig.isEnabled()) {
+ if ( syncControllerRegistry != null ) {
+ if ( syncControllerConfig.isEnabled()) {
syncControllerRegistry.registerSyncController(this);
}
}
diff --git a/src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java b/src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java
index f075ff8..a177684 100644
--- a/src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java
+++ b/src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java
@@ -43,7 +43,6 @@ 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.elasticsearch.config.ElasticSearchConfig;
import org.onap.aai.sparky.dal.rest.HttpMethod;
import org.onap.aai.sparky.inventory.entity.GeoIndexDocument;
import org.onap.aai.sparky.logging.AaiUiMsgs;
@@ -73,8 +72,9 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
private boolean allWorkEnumerated;
private Deque<SelfLinkDescriptor> selflinks;
-
- private ElasticSearchConfig elasticConfig = null;
+ private GeoEntityLookup geoEntityLookup;
+ private OxmEntityLookup oxmEntityLookup;
+
private Map<String, GeoOxmEntityDescriptor> geoDescriptorMap = null;
/**
@@ -85,23 +85,23 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
*/
public GeoSynchronizer(ElasticSearchSchemaConfig schemaConfig, int internalSyncWorkers,
int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig) throws Exception {
+ NetworkStatisticsConfig esStatConfig, GeoEntityLookup geoEntityLookup,
+ OxmEntityLookup oxmEntityLookup) throws Exception {
- super(LOG, "GEO", internalSyncWorkers, aaiWorkers, esWorkers, schemaConfig.getIndexName(),
- aaiStatConfig, esStatConfig);
+ 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.getInstance().getGeoEntityDescriptors();
+ this.geoDescriptorMap = geoEntityLookup.getGeoEntityDescriptors();
this.aaiEntityStats.intializeEntityCounters(geoDescriptorMap.keySet());
this.esEntityStats.intializeEntityCounters(geoDescriptorMap.keySet());
this.syncDurationInMs = -1;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#doSync()
*/
@Override
@@ -113,7 +113,7 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
syncStartedTimeStampInMs = System.currentTimeMillis();
String txnID = NodeUtils.getRandomTxnId();
MdcContext.initialize(txnID, "GeoSynchronizer", "", "Sync", "");
-
+
collectAllTheWork();
return OperationState.OK;
}
@@ -125,14 +125,7 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
* @return the operation state
*/
public OperationState collectAllTheWork() {
- final Map<String, String> contextMap = MDC.getCopyOfContextMap();
- if (elasticConfig == null) {
- try {
- elasticConfig = ElasticSearchConfig.getConfig();
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.CONFIGURATION_ERROR, "Search");
- }
- }
+ final Map<String,String> contextMap = MDC.getCopyOfContextMap();
if (geoDescriptorMap.isEmpty()) {
setShouldSkipSync(true);
@@ -157,7 +150,7 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
@Override
public Void get() {
- MDC.setContextMap(contextMap);
+ MDC.setContextMap(contextMap);
OperationResult typeLinksResult = null;
try {
typeLinksResult = aaiAdapter.getSelfLinksByEntityType(key);
@@ -212,8 +205,7 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
if (linkDescriptor.getSelfLink() != null && linkDescriptor.getEntityType() != null) {
- descriptor = OxmEntityLookup.getInstance().getEntityDescriptors()
- .get(linkDescriptor.getEntityType());
+ descriptor = oxmEntityLookup.getEntityDescriptors().get(linkDescriptor.getEntityType());
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, linkDescriptor.getEntityType());
@@ -311,13 +303,13 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
if (!txn.getOperationResult().wasSuccessful()) {
return;
}
-
+
GeoOxmEntityDescriptor descriptor = geoDescriptorMap.get(txn.getEntityType());
-
- if (descriptor == null) {
+
+ if ( descriptor == null ) {
return;
}
-
+
try {
if (descriptor.hasGeoEntity()) {
@@ -337,7 +329,7 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
String link = null;
try {
- link = getElasticFullUrl("/" + geoDoc.getId(), getIndexName(), "default");
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), geoDoc.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_URI, exc);
}
@@ -412,9 +404,7 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
*/
@Override
@@ -423,9 +413,7 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
return this.getStatReport(syncDurationInMs, showFinalReport);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#shutdown()
*/
@Override
@@ -445,7 +433,7 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
*/
protected void populateGeoDocument(GeoIndexDocument doc, String result,
OxmEntityDescriptor resultDescriptor, String entityLink)
- throws JsonProcessingException, IOException {
+ throws JsonProcessingException, IOException {
doc.setSelfLink(entityLink);
doc.setEntityType(resultDescriptor.getEntityName());
@@ -466,9 +454,9 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
final String primaryCompositeKeyValue = NodeUtils.concatArray(primaryKeyValues, "/");
doc.setEntityPrimaryKeyValue(primaryCompositeKeyValue);
-
+
GeoOxmEntityDescriptor descriptor = geoDescriptorMap.get(resultDescriptor.getEntityName());
-
+
String geoLatKey = descriptor.getGeoLatName();
String geoLongKey = descriptor.getGeoLongName();
diff --git a/src/main/java/org/onap/aai/sparky/util/Encryptor.java b/src/main/java/org/onap/aai/sparky/util/Encryptor.java
index 15b735b..32dfe5b 100644
--- a/src/main/java/org/onap/aai/sparky/util/Encryptor.java
+++ b/src/main/java/org/onap/aai/sparky/util/Encryptor.java
@@ -38,12 +38,12 @@ import org.onap.aai.sparky.logging.AaiUiMsgs;
public class Encryptor {
private static final Logger LOG = LoggerFactory.getInstance().getLogger(Encryptor.class);
-
/**
* Instantiates a new encryptor.
*/
- public Encryptor() {}
-
+ public Encryptor() {
+ }
+
/**
* Encrypt value.
*
@@ -59,7 +59,7 @@ public class Encryptor {
}
return encyptedValue;
}
-
+
/**
* Decrypt value.
*
diff --git a/src/main/java/org/onap/aai/sparky/util/KeystoreBuilder.java b/src/main/java/org/onap/aai/sparky/util/KeystoreBuilder.java
index 05ba3d2..0303870 100644
--- a/src/main/java/org/onap/aai/sparky/util/KeystoreBuilder.java
+++ b/src/main/java/org/onap/aai/sparky/util/KeystoreBuilder.java
@@ -96,9 +96,7 @@ public class KeystoreBuilder {
this.port = port;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
@@ -419,11 +417,8 @@ public class KeystoreBuilder {
throw new UnsupportedOperationException();
}
- /*
- * (non-Javadoc)
- *
- * @see javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert.X509Certificate[],
- * java.lang.String)
+ /* (non-Javadoc)
+ * @see javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert.X509Certificate[], java.lang.String)
*/
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
@@ -431,11 +426,8 @@ public class KeystoreBuilder {
throw new UnsupportedOperationException();
}
- /*
- * (non-Javadoc)
- *
- * @see javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate[],
- * java.lang.String)
+ /* (non-Javadoc)
+ * @see javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate[], java.lang.String)
*/
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
@@ -515,7 +507,8 @@ public class KeystoreBuilder {
*/
if (args.length != 4) {
- System.out.println("Usage: KeyBuilder <[ip:port];*> <keystoreFileName>"
+ System.out.println(
+ "Usage: KeyBuilder <[ip:port];*> <keystoreFileName>"
+ " <keystorePassword> <dumpCertDetails> ");
System.exit(1);
}
diff --git a/src/main/java/org/onap/aai/sparky/util/NodeUtils.java b/src/main/java/org/onap/aai/sparky/util/NodeUtils.java
index a34c07d..a62292d 100644
--- a/src/main/java/org/onap/aai/sparky/util/NodeUtils.java
+++ b/src/main/java/org/onap/aai/sparky/util/NodeUtils.java
@@ -54,7 +54,7 @@ import javax.xml.stream.XMLStreamConstants;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import org.restlet.Request;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -71,14 +71,14 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
*/
public class NodeUtils {
private static SecureRandom sRandom = new SecureRandom();
-
+
private static final Pattern AAI_VERSION_PREFIX = Pattern.compile("/aai/v[0-9]+/(.*)");
-
- public static synchronized String getRandomTxnId() {
- byte bytes[] = new byte[6];
- sRandom.nextBytes(bytes);
- return Integer.toUnsignedString(ByteBuffer.wrap(bytes).getInt());
+
+ public static synchronized String getRandomTxnId(){
+ byte bytes[] = new byte[6];
+ sRandom.nextBytes(bytes);
+ return Integer.toUnsignedString(ByteBuffer.wrap(bytes).getInt());
}
/**
@@ -96,30 +96,28 @@ public class NodeUtils {
return sb.toString();
}
-
-
+
+
public static String extractRawPathWithoutVersion(String selfLinkUri) {
try {
String rawPath = new URI(selfLinkUri).getRawPath();
-
+
Matcher m = AAI_VERSION_PREFIX.matcher(rawPath);
if (m.matches()) {
- // System.out.println(m.group(0));
- if (m.groupCount() >= 1) {
+ if ( m.groupCount() >= 1) {
return m.group(1);
}
- // System.out.println(m.group(2));
-
+
}
} catch (Exception e) {
}
-
+
return null;
-
+
}
/**
@@ -148,8 +146,7 @@ public class NodeUtils {
* @param logger the logger
* @return the executor service
*/
- public static ExecutorService createNamedExecutor(String name, int numWorkers,
- final Logger logger) {
+ public static ExecutorService createNamedExecutor(String name, int numWorkers, final Logger logger) {
UncaughtExceptionHandler uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
@Override
@@ -177,7 +174,7 @@ public class NodeUtils {
if (link != null) {
- Pattern pattern = Pattern.compile(TierSupportUiConstants.URI_VERSION_REGEX_PATTERN);
+ Pattern pattern = Pattern.compile(SparkyConstants.URI_VERSION_REGEX_PATTERN);
Matcher matcher = pattern.matcher(link);
if (matcher.find()) {
uri = link.substring(matcher.end());
@@ -299,15 +296,15 @@ public class NodeUtils {
public static String concatArray(List<String> list) {
return concatArray(list, " ");
}
-
- private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
-
+
+ private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
+
public static String getCurrentTimeStamp() {
SimpleDateFormat dateFormat = new SimpleDateFormat(TIMESTAMP_FORMAT);
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
return dateFormat.format(timestamp);
}
-
+
/**
* Concat array.
*
@@ -492,7 +489,7 @@ public class NodeUtils {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
-
+
if (pretty) {
ow = mapper.writer().withDefaultPrettyPrinter();
@@ -502,9 +499,10 @@ public class NodeUtils {
return ow.writeValueAsString(object);
}
-
+
/**
- * Convert object to json by selectively choosing certain fields thru filters. Example use case:
+ * Convert object to json by selectively choosing certain fields thru filters.
+ * Example use case:
* based on request type we might need to send different serialization of the UiViewFilterEntity
*
* @param object the object
@@ -518,7 +516,7 @@ public class NodeUtils {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
-
+
if (pretty) {
ow = mapper.writer(filters).withDefaultPrettyPrinter();
@@ -528,7 +526,7 @@ public class NodeUtils {
return ow.writeValueAsString(object);
}
-
+
/**
* Convert json str to json node.
@@ -575,10 +573,10 @@ public class NodeUtils {
public static void extractObjectsByKey(JsonNode node, String searchKey,
Collection<JsonNode> foundObjects) {
- if (node == null) {
+ if ( node == null ) {
return;
}
-
+
if (node.isObject()) {
Iterator<Map.Entry<String, JsonNode>> nodeIterator = node.fields();
@@ -717,7 +715,7 @@ public class NodeUtils {
return timestamp;
}
}
-
+
/**
* Gets the HttpRequest payload.
*
@@ -729,8 +727,8 @@ public class NodeUtils {
InputStream inputStream = request.getInputStream();
return getBodyFromStream(inputStream);
}
-
-
+
+
/**
* Gets the Restlet Request payload.
@@ -743,7 +741,7 @@ public class NodeUtils {
InputStream inputStream = request.getEntity().getStream();
return getBodyFromStream(inputStream);
}
-
+
/**
* Gets the payload from the input stream of a request.
@@ -785,7 +783,7 @@ public class NodeUtils {
return body;
}
-
+
/**
* The main method.
*
diff --git a/src/main/java/org/onap/aai/sparky/util/RestletUtils.java b/src/main/java/org/onap/aai/sparky/util/RestletUtils.java
index 06c8c05..6fd6080 100644
--- a/src/main/java/org/onap/aai/sparky/util/RestletUtils.java
+++ b/src/main/java/org/onap/aai/sparky/util/RestletUtils.java
@@ -26,8 +26,8 @@ import javax.servlet.http.HttpServletResponse;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.elasticsearch.SearchAdapter;
import org.onap.aai.sparky.logging.AaiUiMsgs;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.restlet.Response;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
@@ -42,7 +42,7 @@ public class RestletUtils {
public HttpServletResponse convertRestletResponseToHttpServletResponse(Response restletResponse) {
return org.restlet.ext.servlet.ServletUtils.getResponse(restletResponse);
}
-
+
/**
* Execute post query
*
@@ -53,8 +53,8 @@ public class RestletUtils {
* @param requestJsonPayload The request JSON payload
* @return The operation result
*/
- public OperationResult executePostQuery(Logger logger, SearchAdapter search, Response response,
- String requestUrl, String requestJsonPayload) {
+ public OperationResult executePostQuery(Logger logger, SearchServiceAdapter search,
+ Response response, String requestUrl, String requestJsonPayload) {
OperationResult opResult = search.doPost(requestUrl, requestJsonPayload, "application/json");
@@ -86,9 +86,8 @@ public class RestletUtils {
* @param response The response
*/
public void handleRestletErrors(Logger logger, String errorMsg, Exception exc,
- Response response) {
- String errorLogMsg =
- (exc == null ? errorMsg : errorMsg + ". Error:" + exc.getLocalizedMessage());
+ Response response) {
+ String errorLogMsg = (exc == null ? errorMsg : errorMsg + ". Error:" + exc.getLocalizedMessage());
logger.error(AaiUiMsgs.ERROR_GENERIC, errorLogMsg);
response.setEntity(generateJsonErrorResponse(errorMsg), MediaType.APPLICATION_JSON);
}
diff --git a/src/main/java/org/onap/aai/sparky/util/SuggestionsPermutation.java b/src/main/java/org/onap/aai/sparky/util/SuggestionsPermutation.java
index ba51254..5598943 100644
--- a/src/main/java/org/onap/aai/sparky/util/SuggestionsPermutation.java
+++ b/src/main/java/org/onap/aai/sparky/util/SuggestionsPermutation.java
@@ -46,7 +46,7 @@ public class SuggestionsPermutation {
List<String> list = new ArrayList<String>(originalList);
String head = list.get(0);
ArrayList<String> rest = new ArrayList<String>(list.subList(1, list.size()));
-
+
for (ArrayList<String> activeList : getUniqueListForSuggestions(rest)) {
ArrayList<String> newList = new ArrayList<String>();
newList.add(head);
@@ -56,12 +56,12 @@ public class SuggestionsPermutation {
}
return lists;
}
-
- public static ArrayList<ArrayList<String>> getNonEmptyUniqueLists(List<String> list) {
+
+ public static ArrayList<ArrayList<String>> getNonEmptyUniqueLists(List<String> list){
ArrayList<ArrayList<String>> lists = getUniqueListForSuggestions(list);
- // remove empty list from the power set
- for (ArrayList<String> emptyList : lists) {
- if (emptyList.isEmpty()) {
+ // remove empty list from the power set
+ for (ArrayList<String> emptyList : lists ){
+ if ( emptyList.isEmpty() ) {
lists.remove(emptyList);
break;
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/EntityTypeAggregation.java b/src/main/java/org/onap/aai/sparky/viewandinspect/EntityTypeAggregation.java
index 594b49f..1bb11c0 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/EntityTypeAggregation.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/EntityTypeAggregation.java
@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
+
/**
* The Class EntityTypeAggregation.
*/
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessor.java b/src/main/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessor.java
index 822b14b..e6c96b2 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessor.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessor.java
@@ -22,8 +22,6 @@
*/
package org.onap.aai.sparky.viewandinspect;
-import java.security.SecureRandom;
-import java.util.concurrent.ExecutorService;
import org.apache.camel.Exchange;
import org.apache.camel.component.restlet.RestletConstants;
@@ -31,23 +29,11 @@ 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.OxmModelLoader;
-import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
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.util.NodeUtils;
-import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
-import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
-import org.onap.aai.sparky.viewandinspect.entity.JsonNode;
-import org.onap.aai.sparky.viewandinspect.entity.NodeMeta;
import org.onap.aai.sparky.viewandinspect.entity.QueryRequest;
-import org.onap.aai.sparky.viewandinspect.services.VisualizationContext;
import org.onap.aai.sparky.viewandinspect.services.VisualizationService;
-import org.onap.aai.sparky.viewandinspect.services.VisualizationTransformer;
-import org.onap.aai.sparky.viewinspect.sync.ViewInspectSyncController;
+
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.ClientInfo;
@@ -57,118 +43,81 @@ import org.restlet.data.Status;
public class SchemaVisualizationProcessor {
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(SchemaVisualizationProcessor.class);
-
- private final VisualizationService visualizationService;
- private VisualizationTransformer visualizationTransformer;
- private VisualizationContext visualizationContext;
- private NodeMeta nodeMeta;
- private JsonNode jsonNode;
- private ActiveInventoryNode activeInventoryNode;
- private final ExecutorService tabularExecutorService;
- private final ExecutorService aaiExecutorService;
- private final SecureRandom secureRandom;
- private ActiveInventoryAdapter aaiAdapter;
- private ElasticSearchAdapter esAdapter;
- private ElasticSearchEndpointConfig endpointConfig;
- private ElasticSearchSchemaConfig schemaConfig;
- private ActiveInventoryConfig aaiConfig;
-
- public SchemaVisualizationProcessor(VisualizationConfigs visualizationConfigs,
- OxmModelLoader oxmModelLoader, ViewInspectSyncController viewInspectSynController)
- throws Exception {
-
- this.aaiAdapter = viewInspectSynController.getAaiAdapter();
- this.esAdapter = viewInspectSynController.getElasticSearchAdapter();
- this.endpointConfig = viewInspectSynController.getendpointConfig();
- this.schemaConfig = viewInspectSynController.getschemaConfig();
-
- this.visualizationService = new VisualizationService(oxmModelLoader, visualizationConfigs,
- aaiAdapter, esAdapter, endpointConfig, schemaConfig);
- this.activeInventoryNode = new ActiveInventoryNode(visualizationConfigs);
- this.nodeMeta = new NodeMeta(visualizationConfigs);
- secureRandom = new SecureRandom();
- this.tabularExecutorService = NodeUtils.createNamedExecutor("TABULAR-WORKER",
- visualizationConfigs.getNumOfThreadsToFetchNodeIntegrity(), LOG);
- /*
- * Fix ActiveInvenotryConfig with properly wired in properties
- */
- this.aaiConfig = ActiveInventoryConfig.getConfig();
- this.aaiExecutorService = NodeUtils.createNamedExecutor("SLNC-WORKER",
- aaiConfig.getAaiRestConfig().getNumResolverWorkers(), LOG);
-
- this.visualizationContext = new VisualizationContext(secureRandom.nextLong(), aaiAdapter,
- tabularExecutorService, aaiExecutorService, visualizationConfigs);
- this.visualizationTransformer = new VisualizationTransformer(visualizationConfigs);
- this.jsonNode = new JsonNode(activeInventoryNode, visualizationConfigs);
-
- }
-
- protected String generateJsonErrorResponse(String message) {
- return String.format("{ \"errorMessage\" : %s }", message);
- }
-
- public void processVisualizationRequest(Exchange exchange) {
-
- String visualizationPayload = "";
- QueryRequest hashId = null;
- OperationResult operationResult = null;
- Request request = null;
- Response response = null;
- Object xTransactionId = null;
- Object partnerName = null;
-
- xTransactionId = exchange.getIn().getHeader("X-TransactionId");
- if (xTransactionId == null) {
- xTransactionId = NodeUtils.getRandomTxnId();
- }
- partnerName = exchange.getIn().getHeader("X-FromAppId");
- if (partnerName == null) {
- partnerName = "Browser";
- }
-
- request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, Request.class);
- response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.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());
-
- visualizationPayload = exchange.getIn().getBody(String.class);
- hashId = visualizationService.analyzeQueryRequestBody(visualizationPayload);
-
- if (hashId != null) {
-
- operationResult = visualizationService.buildVisualizationUsingGenericQuery(hashId);
-
- if (operationResult.getResultCode() == Status.SUCCESS_OK.getCode()) {
-
- response.setStatus(Status.SUCCESS_OK);
- } else {
- response.setStatus(Status.SERVER_ERROR_INTERNAL);
- LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST, String
- .format("Failed to process Visualization Schema Payload = '%s'", visualizationPayload));
- }
-
- } else {
- operationResult = new OperationResult();
- operationResult.setResult(String
- .format("Failed to analyze Visualization Schema Payload = '%s'", visualizationPayload));
- response.setStatus(Status.SERVER_ERROR_INTERNAL);
- LOG.error(AaiUiMsgs.FAILED_TO_ANALYZE, String
- .format("Failed to analyze Visualization Schema Payload = '%s'", visualizationPayload));
-
- }
-
-
- response.setEntity(operationResult.getResult(), MediaType.APPLICATION_JSON);
- exchange.getOut().setBody(response);
- }
+ private static final Logger LOG =
+ LoggerFactory.getInstance().getLogger(SchemaVisualizationProcessor.class);
+
+ private VisualizationService visualizationService;
+
+ public SchemaVisualizationProcessor()throws Exception{}
+
+ protected String generateJsonErrorResponse(String message) {
+ return String.format("{ \"errorMessage\" : %s }", message);
+ }
+
+ public void setVisualizationService(VisualizationService visualizationService){
+ this.visualizationService = visualizationService;
+ }
+ public VisualizationService getVisualizationService(){
+ return visualizationService;
+ }
+
+ public void processVisualizationRequest(Exchange exchange){
+
+ String visualizationPayload="";
+ QueryRequest hashId = null;
+ OperationResult operationResult = null;
+ Request request = null;
+ Response response = null;
+ Object xTransactionId = null;
+ Object partnerName = null;
+
+ xTransactionId = exchange.getIn().getHeader("X-TransactionId");
+ if (xTransactionId == null) {
+ xTransactionId = NodeUtils.getRandomTxnId();
+ }
+ partnerName = exchange.getIn().getHeader("X-FromAppId");
+ if (partnerName == null) {
+ partnerName = "Browser";
+ }
+
+ request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, Request.class);
+ response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.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());
+
+ visualizationPayload = exchange.getIn().getBody(String.class);
+ hashId = this.getVisualizationService().analyzeQueryRequestBody(visualizationPayload);
+
+ if (hashId != null) {
+
+ operationResult = this.getVisualizationService().buildVisualizationUsingGenericQuery(hashId);
+
+ if(operationResult.getResultCode()== Status.SUCCESS_OK.getCode()){
+
+ response.setStatus(Status.SUCCESS_OK);
+ }
+ else{
+ response.setStatus(Status.SERVER_ERROR_INTERNAL);
+ LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST,
+ String.format("Failed to process Visualization Schema Payload = '%s'", visualizationPayload));
+ }
+
+ }else{
+ operationResult = new OperationResult();
+ operationResult.setResult(String.format("Failed to analyze Visualization Schema Payload = '%s'", visualizationPayload));
+ response.setStatus(Status.SERVER_ERROR_INTERNAL);
+ LOG.error(AaiUiMsgs.FAILED_TO_ANALYZE,
+ String.format("Failed to analyze Visualization Schema Payload = '%s'", visualizationPayload));
+
+ }
+
+
+ response.setEntity(operationResult.getResult(), MediaType.APPLICATION_JSON);
+ exchange.getOut().setBody(response);
+ }
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java b/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java
new file mode 100644
index 0000000..5d62646
--- /dev/null
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java
@@ -0,0 +1,100 @@
+/**
+ * ============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.config;
+
+/**
+ * The Class TierSupportUiConstants.
+ */
+public class SparkyConstants {
+
+ public static String APP_NAME = "AAIUI";
+
+ /** Default to unix file separator if system property file.separator is null */
+ public static final String FILESEP =
+ (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
+
+ public static String CONFIG_HOME = System.getProperty("CONFIG_HOME") + FILESEP;
+ public static String AJSC_HOME = System.getProperty("AJSC_HOME") + FILESEP;
+ public static String CONFIG_ROOT_LOCATION = AJSC_HOME + "bundleconfig" + FILESEP + "etc" + FILESEP;
+ public static String STATIC_CONFIG_APP_LOCATION = CONFIG_ROOT_LOCATION + "appprops" + FILESEP;
+ public static String DYNAMIC_CONFIG_APP_LOCATION = CONFIG_HOME;
+
+ public static String CONFIG_OXM_LOCATION = CONFIG_HOME + "model" + FILESEP;
+ public static String CONFIG_FILTERS_BASE_LOCATION = CONFIG_HOME + FILESEP;
+ public static String CONFIG_AUTH_LOCATION = CONFIG_HOME + "auth" + FILESEP;
+
+ public static String HOST = "host";
+ public static String IP_ADDRESS = "ipAddress";
+ public static String PORT = "port";
+ public static String HTTP_PORT = "httpPort";
+ public static String RETRIES = "numRequestRetries";
+ public static String RESOURCE_VERSION = "resource-version";
+ public static String URI = "URI";
+
+ public static String AUTHORIZED_USERS_FILE_LOCATION = DYNAMIC_CONFIG_APP_LOCATION + "authorized-users.config";
+ public static String USERS_FILE_LOCATION = DYNAMIC_CONFIG_APP_LOCATION + "users.config";
+ public static String ROLES_FILE_LOCATION = DYNAMIC_CONFIG_APP_LOCATION + "roles.config";
+ public static String PORTAL_AUTHENTICATION_FILE_LOCATION = DYNAMIC_CONFIG_APP_LOCATION + "portal" + FILESEP + "portal-authentication.properties";
+
+ // Related to data-router properties
+ public static String DR_URI_SUFFIX = "uriSuffix";
+ public static String DR_CERT_NAME = "cert-name";
+ public static String DR_KEYSTORE_PASSWORD = "keystore-password";
+ public static String DR_KEYSTORE = "keystore";
+ public static String DR_CONNECT_TIMEOUT = "connectTimeoutMs";
+ public static String DR_READ_TIMEOUT = "readTimeoutMs";
+
+ public static final String APP_JSON = "application/json";
+
+ public static final String ES_SUGGEST_API = "_suggest";
+ public static final String ES_COUNT_API = "_count";
+ public static final String ES_SEARCH_API = "_search";
+
+ public static final String UI_FILTER_VIEW_NAME_PARAMETER = "viewName";
+ public static final String UI_FILTER_ID_LIST_PARAMETER = "filterIdList";
+
+ public static final String ENTITY_AUTO_SUGGEST_INDEX_NAME_DEFAULT =
+ "entityautosuggestindex-localhost";
+ public static final String ENTITY_AUTO_SUGGEST_SETTINGS_FILE_DEFAULT =
+ "/etc/autoSuggestSettings.json";
+ public static final String ENTITY_AUTO_SUGGEST_MAPPINGS_FILE_DEFAULT =
+ "/etc/autoSuggestMappings.json";
+ public static final String ENTITY_DYNAMIC_MAPPINGS_FILE_DEFAULT =
+ "/etc/dynamicMappings.json";
+ public static final String FILTER_LIST_FILE_DEFAULT =
+ CONFIG_FILTERS_BASE_LOCATION + "filters" + FILESEP + "aaiui_filters.json";
+ public static final String FILTER_MAPPING_FILE_DEFAULT =
+ CONFIG_FILTERS_BASE_LOCATION + "filters" + FILESEP + "aaiui_views.json";
+
+ public static final String SUGGESTION_TEXT_SEPARATOR = " -- ";
+
+ // Injected Attributes
+ public static String URI_ATTR_NAME = "uri";
+
+ public static final String URI_VERSION_REGEX_PATTERN = "aai/v[\\d]+/";
+
+ public static final String getConfigPath(String configFile){
+ return AJSC_HOME + FILESEP + configFile;
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java b/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java
index 9fc9030..a0be371 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java
@@ -22,6 +22,8 @@
*/
package org.onap.aai.sparky.viewandinspect.config;
+import java.util.ArrayList;
+
/**
* The Class VisualizationConfig.
*/
@@ -41,17 +43,22 @@ public class VisualizationConfigs {
private int numOfThreadsToFetchNodeIntegrity;
- private String entityTypesToSummarize;
- private String vnfEntityTypes;
-
private boolean makeAllNeighborsBidirectional;
+
+ private ArrayList<String> shallowEntities;
/**
* Instantiates a new visualization config.
*/
public VisualizationConfigs() {}
+ public ArrayList<String> getShallowEntities() {
+ return shallowEntities;
+ }
+ public void setShallowEntities(ArrayList<String> shallowEntities) {
+ this.shallowEntities = shallowEntities;
+ }
/**
* Make all neighbors bidirectional.
@@ -122,22 +129,6 @@ public class VisualizationConfigs {
this.numOfThreadsToFetchNodeIntegrity = numOfThreadsToFetchNodeIntegrity;
}
- public String getEntityTypesToSummarize() {
- return entityTypesToSummarize;
- }
-
- public void setEntityTypesToSummarize(String entityTypesToSummarize) {
- this.entityTypesToSummarize = entityTypesToSummarize;
- }
-
- public String getVnfEntityTypes() {
- return vnfEntityTypes;
- }
-
- public void setVnfEntityTypes(String vnfEntityTypes) {
- this.vnfEntityTypes = vnfEntityTypes;
- }
-
@Override
@@ -151,19 +142,10 @@ public class VisualizationConfigs {
+ (searchNodeClassName != null ? "searchNodeClassName=" + searchNodeClassName + ", " : "")
+ (selectedSearchedNodeClassName != null
? "selectedSearchedNodeClassName=" + selectedSearchedNodeClassName + ", " : "")
- + "numOfThreadsToFetchNodeIntegrity=" + numOfThreadsToFetchNodeIntegrity + ", "
- + (entityTypesToSummarize != null
- ? "entityTypesToSummarize=" + entityTypesToSummarize + ", " : "")
- + (vnfEntityTypes != null ? "vnfEntityTypes=" + vnfEntityTypes + ", " : "")
- + "makeAllNeighborsBidirectional=" + makeAllNeighborsBidirectional + "]";
+ + "numOfThreadsToFetchNodeIntegrity=" + numOfThreadsToFetchNodeIntegrity
+ + ", makeAllNeighborsBidirectional=" + makeAllNeighborsBidirectional + "]";
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
-
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java
index 8d74d68..2c3b97f 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java
@@ -54,8 +54,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
*/
public class ActiveInventoryNode {
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(ActiveInventoryNode.class);
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(
+ ActiveInventoryNode.class);
private static final String URIRegexPattern = "aai/v[\\d]/";
public static final int DEFAULT_INIT_NODE_DEPTH = 1000;
@@ -79,12 +79,13 @@ public class ActiveInventoryNode {
private boolean processedNeighbors;
private boolean selfLinkPendingResolve;
-
+
/*
- * I think we shouldn't be using this crutch flags. If these things are meant to represent the
- * current state of the node, then they should be legitimate state transitions.
+ * I think we shouldn't be using this crutch flags. If these things are meant
+ * to represent the current state of the node, then they should be legitimate
+ * state transitions.
*/
-
+
private boolean selfLinkDeterminationPending;
private AtomicBoolean selfLinkProcessed;
@@ -107,13 +108,16 @@ public class ActiveInventoryNode {
private ArrayList<String> queryParams;
private ObjectMapper mapper;
-
+
+ private OxmEntityLookup oxmEntityLookup;
+
/**
* Instantiates a new active inventory node.
*
* @param key the key
*/
- public ActiveInventoryNode(VisualizationConfigs visualizationConfigs) {
+ public ActiveInventoryNode(VisualizationConfigs visualizationConfigs, OxmEntityLookup oxmEntityLookup) {
+ this.oxmEntityLookup = oxmEntityLookup;
this.nodeId = null;
this.entityType = null;
this.selfLink = null;
@@ -130,7 +134,7 @@ public class ActiveInventoryNode {
selfLinkProcessed = new AtomicBoolean(Boolean.FALSE);
nodeIntegrityProcessed = new AtomicBoolean(Boolean.FALSE);
oxmModelLoader = null;
- this.visualizationConfigs = visualizationConfigs;
+ this.visualizationConfigs = visualizationConfigs ;
isRootNode = false;
inboundNeighbors = new ConcurrentLinkedDeque<String>();
@@ -147,19 +151,19 @@ public class ActiveInventoryNode {
}
-
+
public void clearQueryParams() {
queryParams.clear();
}
-
+
public void addQueryParam(String queryParam) {
- if (queryParam != null) {
- if (!queryParams.contains(queryParam)) {
+ if ( queryParam!= null) {
+ if( !queryParams.contains(queryParam)) {
queryParams.add(queryParam);
}
}
}
-
+
public void addQueryParams(Collection<String> params) {
if (params != null & params.size() > 0) {
@@ -170,7 +174,7 @@ public class ActiveInventoryNode {
}
}
-
+
public List<String> getQueryParams() {
return queryParams;
}
@@ -377,8 +381,8 @@ public class ActiveInventoryNode {
boolean nodeDepthWasChanged = false;
if (newDepth < nodeDepth) {
- LOG.info(AaiUiMsgs.ACTIVE_INV_NODE_CHANGE_DEPTH, nodeId, String.valueOf(this.nodeDepth),
- String.valueOf(newDepth));
+ LOG.info(AaiUiMsgs.ACTIVE_INV_NODE_CHANGE_DEPTH, nodeId,
+ String.valueOf(this.nodeDepth), String.valueOf(newDepth));
this.nodeDepth = newDepth;
nodeDepthWasChanged = true;
}
@@ -407,15 +411,13 @@ public class ActiveInventoryNode {
*/
public void changeState(NodeProcessingState newState, NodeProcessingAction action) {
/*
- * NodeId may be null depending on the current node life-cycle state
+ * NodeId may be null depending on the current node life-cycle state
*/
-
+
if (getNodeId() != null) {
- LOG.info(AaiUiMsgs.ACTIVE_INV_NODE_CHANGE_STATE, state.toString(), newState.toString(),
- action.toString());
+ LOG.info(AaiUiMsgs.ACTIVE_INV_NODE_CHANGE_STATE, state.toString(), newState.toString(), action.toString());
} else {
- LOG.info(AaiUiMsgs.ACTIVE_INV_NODE_CHANGE_STATE_NO_NODE_ID, state.toString(),
- newState.toString(), action.toString());
+ LOG.info(AaiUiMsgs.ACTIVE_INV_NODE_CHANGE_STATE_NO_NODE_ID, state.toString(), newState.toString(), action.toString());
}
this.state = newState;
}
@@ -638,7 +640,7 @@ public class ActiveInventoryNode {
* probably more likely just for array node types, but we'll see.
*/
- if (OxmEntityLookup.getInstance().getEntityDescriptors().get(fieldName) == null) {
+ if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
/*
* this is no an entity type as far as we can tell, so we can add it to our property
* set.
@@ -658,8 +660,7 @@ public class ActiveInventoryNode {
* complex group or relationship.
*/
- if (OxmEntityLookup.getInstance().getEntityDescriptors()
- .get(field.getKey()) == null) {
+ if (oxmEntityLookup.getEntityDescriptors().get(field.getKey()) == null) {
/*
* this is no an entity type as far as we can tell, so we can add it to our property
* set.
@@ -731,7 +732,7 @@ public class ActiveInventoryNode {
public String dumpNodeTree(boolean showProperties) {
return dumpNodeTree(0, showProperties);
}
-
+
/**
* Dump node tree.
*
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutput.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutput.java
index 69971c5..68cfab5 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutput.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutput.java
@@ -31,16 +31,16 @@ import java.util.List;
public class D3VisualizationOutput {
public GraphMeta graphMeta;
- public List<JsonNode> nodes;
- public List<JsonNodeLink> links;
+ public List<SparkyGraphNode> nodes;
+ public List<SparkyGraphLink> links;
public InlineMessage inlineMessage;
/**
* Instantiates a new d 3 visualization output.
*/
public D3VisualizationOutput() {
- nodes = new ArrayList<JsonNode>();
- links = new ArrayList<JsonNodeLink>();
+ nodes = new ArrayList<SparkyGraphNode>();
+ links = new ArrayList<SparkyGraphLink>();
inlineMessage = null;
}
@@ -66,7 +66,7 @@ public class D3VisualizationOutput {
*
* @param nodes the nodes
*/
- public void addNodes(List<JsonNode> nodes) {
+ public void addNodes(List<SparkyGraphNode> nodes) {
this.nodes.addAll(nodes);
}
@@ -75,7 +75,7 @@ public class D3VisualizationOutput {
*
* @param links the links
*/
- public void addLinks(List<JsonNodeLink> links) {
+ public void addLinks(List<SparkyGraphLink> links) {
this.links.addAll(links);
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/EntityEntry.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/EntityEntry.java
index d2e5854..8436a61 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/EntityEntry.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/EntityEntry.java
@@ -76,4 +76,4 @@ public class EntityEntry {
+ (entityId != null ? "entityId=" + entityId : "") + "]";
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphMeta.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphMeta.java
index 6475fac..4c6f1f4 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphMeta.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphMeta.java
@@ -127,9 +127,7 @@ public class GraphMeta {
entitySummary.pegCounter(counterName);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphRequest.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphRequest.java
index 678a00f..29ecddd 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphRequest.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphRequest.java
@@ -23,14 +23,14 @@
package org.onap.aai.sparky.viewandinspect.entity;
public class GraphRequest {
-
+
private String hashId;
private boolean includeGraphMeta;
-
+
public GraphRequest() {
-
+
}
-
+
public String getHashId() {
return hashId;
}
@@ -53,4 +53,4 @@ public class GraphRequest {
+ "includeGraphMeta=" + includeGraphMeta + "]";
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessage.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessage.java
index 93d5cc9..7db12d3 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessage.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessage.java
@@ -57,9 +57,7 @@ public class InlineMessage {
this.message = message;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeMeta.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeMeta.java
index 26a027f..c5892d6 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeMeta.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeMeta.java
@@ -51,16 +51,16 @@ public class NodeMeta {
private NodeProcessingState processingState;
private VisualizationConfigs visualizationConfigs;
-
-
+
+
/**
* Instantiates a new node meta.
*/
public NodeMeta(VisualizationConfigs visualizationConfigs) {
this.isSearchTarget = false;
- this.visualizationConfigs = visualizationConfigs;
-
+ this.visualizationConfigs = visualizationConfigs;
+
if (this.visualizationConfigs.isVisualizationDebugEnabled()) {
nodeDebug = new NodeDebug();
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeProcessingTransaction.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeProcessingTransaction.java
index 22bea15..7437b38 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeProcessingTransaction.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/NodeProcessingTransaction.java
@@ -52,7 +52,7 @@ public class NodeProcessingTransaction {
return null;
}
- return processingNode.getSelfLink();
+ return processingNode.getSelfLink();
}
public String getSelfLinkWithModifiers() {
@@ -93,9 +93,7 @@ public class NodeProcessingTransaction {
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/QueryParams.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/QueryParams.java
index 43edeaa..1a1f24c 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/QueryParams.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/QueryParams.java
@@ -36,7 +36,7 @@ public class QueryParams {
public QueryParams() {
}
-
+
public String getSearchTargetPrimaryKeyValues() {
return searchTargetPrimaryKeyValues;
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelatedToProperty.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelatedToProperty.java
index 0e89608..7ce9de0 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelatedToProperty.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelatedToProperty.java
@@ -49,9 +49,7 @@ public class RelatedToProperty {
this.propertyValue = propertyValue;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/Relationship.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/Relationship.java
index 135ddcc..439acca 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/Relationship.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/Relationship.java
@@ -74,9 +74,7 @@ public class Relationship {
this.relatedToProperty = relatedToProperty;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipData.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipData.java
index f8e1ed3..d2400a9 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipData.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipData.java
@@ -49,9 +49,7 @@ public class RelationshipData {
this.relationshipValue = relationshipValue;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipDirectionality.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipDirectionality.java
index 5104072..6ceede3 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipDirectionality.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipDirectionality.java
@@ -25,10 +25,12 @@ package org.onap.aai.sparky.viewandinspect.entity;
/**
* This enumeration is intended to be used to help us discriminate neighbor relationships for the
* purpose of visualization and conceptualization to model in/out relationships between
- * ActiveInventoryNodes. Possible visualization behaviors could be the following: - IN ( draw a line
- * with 1 arrow ) - OUT ( draw a line with 1 arrow ) - BOTH ( draw a line with 2 arrows, or 2 lines
- * with 1 arrow each ) - UNKNOWN ( draw a line with no arrows ) The UNKNOWN case is what we have at
- * the moment where we have a collection neighbors with no knowledge of relationship directionality.
+ * ActiveInventoryNodes.
+ * Possible visualization behaviors could be the following: - IN ( draw a line with 1 arrow ) - OUT
+ * ( draw a line with 1 arrow ) - BOTH ( draw a line with 2 arrows, or 2 lines with 1 arrow each ) -
+ * UNKNOWN ( draw a line with no arrows )
+ * The UNKNOWN case is what we have at the moment where we have a collection neighbors with no
+ * knowledge of relationship directionality.
*
* @author davea
*
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipList.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipList.java
index d758543..16f4cbd 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipList.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/RelationshipList.java
@@ -42,9 +42,7 @@ public class RelationshipList {
this.relationship = relationship;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SearchableEntityList.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SearchableEntityList.java
index bed2602..6e29540 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SearchableEntityList.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SearchableEntityList.java
@@ -34,82 +34,81 @@ import java.util.Set;
public class SearchableEntityList {
- private List<SearchableEntity> entities;
-
- public SearchableEntityList() {
- entities = new ArrayList<SearchableEntity>();
- }
-
- public List<SearchableEntity> getEntities() {
- return entities;
- }
-
- public void setEntities(List<SearchableEntity> entities) {
- this.entities = entities;
- }
-
- public void addEntity(SearchableEntity entity) {
-
- if (!entities.contains(entity)) {
- entities.add(entity);
+ private List<SearchableEntity> entities;
+
+ public SearchableEntityList() {
+ entities = new ArrayList<SearchableEntity>();
}
- }
-
- protected static SearchableEntity buildEntity(String entityType, String pkeyValue, String link,
- Map<String, String> searchTags) {
-
- SearchableEntity se = new SearchableEntity();
-
- se.setEntityType(entityType);
- se.setEntityPrimaryKeyValue(pkeyValue);
- se.setLink(link);
-
- if (searchTags != null) {
-
- Set<Entry<String, String>> entrySet = searchTags.entrySet();
-
- for (Entry<String, String> entry : entrySet) {
- se.addSearchTagWithKey(entry.getKey(), entry.getValue());
- }
+ public List<SearchableEntity> getEntities() {
+ return entities;
}
- se.deriveFields();
-
- return se;
-
- }
-
- protected static Map<String, String> getSearchTagMap(String... tags) {
-
- HashMap<String, String> dataMap = new HashMap<String, String>();
-
- if (tags != null && tags.length >= 2) {
-
- int numTags = tags.length;
- int index = 0;
-
- while (index < numTags) {
-
- if (index + 1 < numTags) {
- // we have enough parameters for the current set
- dataMap.put(tags[index], tags[index + 1]);
- index += 2;
- } else {
- break;
+ public void setEntities(List<SearchableEntity> entities) {
+ this.entities = entities;
+ }
+
+ public void addEntity(SearchableEntity entity) {
+
+ if ( !entities.contains(entity)) {
+ entities.add(entity);
}
- }
-
+
}
- return dataMap;
-
-
- }
+ protected static SearchableEntity buildEntity(String entityType, String pkeyValue, String link, Map<String,String> searchTags ) {
+
+ SearchableEntity se = new SearchableEntity();
+
+ se.setEntityType(entityType);
+ se.setEntityPrimaryKeyValue(pkeyValue);
+ se.setLink(link);
+
+ if ( searchTags != null) {
+
+ Set<Entry<String, String>> entrySet = searchTags.entrySet();
+
+ for ( Entry<String, String> entry : entrySet ) {
+ se.addSearchTagWithKey(entry.getKey(), entry.getValue());
+ }
+ }
+
+ se.deriveFields();
+
+ return se;
+
+ }
+
+ protected static Map<String,String> getSearchTagMap(String... tags) {
+
+ HashMap<String,String> dataMap = new HashMap<String,String>();
+
+ if ( tags != null && tags.length >= 2 ) {
+
+ int numTags = tags.length;
+ int index = 0;
+
+ while ( index < numTags ) {
+
+ if ( index + 1 < numTags ) {
+ // we have enough parameters for the current set
+ dataMap.put(tags[index], tags[index+1]);
+ index += 2;
+ } else {
+ break;
+ }
+ }
+
+ }
+
+ return dataMap;
+
+
+ }
- @Override
- public String toString() {
- return "SearchableEntityList [" + (entities != null ? "entities=" + entities : "") + "]";
- }
+ @Override
+ public String toString() {
+ return "SearchableEntityList [" + (entities != null ? "entities=" + entities : "") + "]";
+ }
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/dal/elasticsearch/HashQueryResponse.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphLink.java
index 8abf20f..cc21548 100644
--- a/src/main/java/org/onap/aai/sparky/dal/elasticsearch/HashQueryResponse.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphLink.java
@@ -20,41 +20,54 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.aai.sparky.dal.elasticsearch;
+package org.onap.aai.sparky.viewandinspect.entity;
-import org.onap.aai.restclient.client.OperationResult;
+/*
+ * Expected JSON Output:
+ *
+ * { JsonNodeLink : { id : <value>, source : <value>, target : <value> } }
+ *
+ */
-public class HashQueryResponse {
- private String jsonPayload = null;
- private OperationResult opResult = null;
+/**
+ * The Class JsonNodeLink.
+ */
+public class SparkyGraphLink {
- public HashQueryResponse() {
- this(null, null);
+ protected String id;
+ protected String source;
+ protected String target;
+
+ public String getId() {
+ return id;
}
- public HashQueryResponse(String jsonPayload, OperationResult opResult) {
- this.jsonPayload = jsonPayload;
- this.opResult = opResult;
+ public void setId(String id) {
+ this.id = id;
}
- public String getJsonPayload() {
- return jsonPayload;
+ public String getSource() {
+ return source;
}
- public void setJsonPayload(String jsonPayload) {
- this.jsonPayload = jsonPayload;
+ public void setSource(String source) {
+ this.source = source;
}
- public OperationResult getOpResult() {
- return opResult;
+ public String getTarget() {
+ return target;
}
- public void setOpResult(OperationResult opResult) {
- this.opResult = opResult;
+ public void setTarget(String target) {
+ this.target = target;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
@Override
public String toString() {
- return "HashQueryResponse [jsonPayload=" + jsonPayload + ", opResult=" + opResult + "]";
+ return "JsonNodeLink [id=" + id + ", source=" + source + ", target=" + target + "]";
}
+
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphNode.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphNode.java
new file mode 100644
index 0000000..66c49c4
--- /dev/null
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphNode.java
@@ -0,0 +1,203 @@
+/**
+ * ============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.entity;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+/*
+ * We can use annotations to differentiate between intermediate data we use to build the node, and
+ * the data that we actually want to appear in the exported JSON.
+ */
+
+/*
+ * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
+ * right.
+ *
+ * { "item-type": "customer", "item-name-key": "subscriber-name", “item-name-value” :
+ * “subscriber-name-123456789-aai847-data-01”, "item-properties": [{ "property-name":
+ * "subscriber-name", "property-value": "subscriber-name-123456789-aai847-data-01" }, {
+ * "property-name": "global-customer-id", "property-value":
+ * "global-customer-id-123456789-aai847-data-01" } ], "node-meta": { “color” : “#f2d2d2”,
+ * "isSearchTarget" : false, "nodeGroups" : "1,2,3,4" }, }
+ *
+ */
+
+
+/**
+ * The Class JsonNode.
+ */
+public class SparkyGraphNode {
+
+ private String id;
+ private String itemType;
+ private String itemNameKey;
+ private String itemNameValue;
+ private Map<String, String> itemProperties;
+ private NodeMeta nodeMeta;
+
+ @JsonIgnore
+ private boolean isRootNode;
+
+
+ @JsonIgnore
+ private String resourceKey;
+ @JsonIgnore
+ private Collection<String> inboundNeighbors;
+
+ @JsonIgnore
+ private Collection<String> outboundNeighbors;
+
+
+ @JsonIgnore
+ private static final Logger LOG = Logger.getLogger(SparkyGraphNode.class);
+
+ private VisualizationConfigs visualizationConfigs;
+
+
+ /**
+ * Instantiates a new json node.
+ *
+ * @param ain the ain
+ */
+ public SparkyGraphNode(ActiveInventoryNode ain,VisualizationConfigs visualizationConfigs ) {
+ this.resourceKey = ain.getNodeId();
+ this.itemProperties = ain.getProperties();
+ this.setItemType(ain.getEntityType());
+ this.setItemNameKey(ain.getPrimaryKeyName());
+ this.setItemNameValue(ain.getPrimaryKeyValue());
+ this.setId(ain.getNodeId());
+ this.isRootNode = ain.isRootNode();
+ this.visualizationConfigs = visualizationConfigs;
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("---");
+ LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
+ LOG.debug("---");
+ }
+
+ inboundNeighbors = ain.getInboundNeighbors();
+ outboundNeighbors = ain.getOutboundNeighbors();
+
+ nodeMeta = new NodeMeta(this.visualizationConfigs);
+
+ nodeMeta.setNodeIssue(ain.isNodeIssue());
+ nodeMeta.setNodeValidated(ain.isNodeValidated());
+ nodeMeta.setNodeDepth(ain.getNodeDepth());
+
+ nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
+ nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
+
+ nodeMeta.setAtMaxDepth(ain.isAtMaxDepth());
+ nodeMeta.setSelfLinkResolved(!ain.isSelflinkRetrievalFailure());
+ nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred());
+ nodeMeta.setHasNeighbors(
+ ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0);
+ nodeMeta.setProcessingState(ain.getState());
+
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getItemNameKey() {
+ return itemNameKey;
+ }
+
+ public String getItemNameValue() {
+ return itemNameValue;
+ }
+
+ public Map<String, String> getItemProperties() {
+ return itemProperties;
+ }
+
+ public String getItemType() {
+ return itemType;
+ }
+
+ public String getResourceKey() {
+ return resourceKey;
+ }
+
+ public void setItemNameKey(String itemNameKey) {
+ this.itemNameKey = itemNameKey;
+ }
+
+ public void setItemNameValue(String itemNameValue) {
+ this.itemNameValue = itemNameValue;
+ }
+
+ public void setItemProperties(HashMap<String, String> itemProperties) {
+ this.itemProperties = itemProperties;
+ }
+
+ public void setItemType(String itemType) {
+ this.itemType = itemType;
+ }
+
+ public void setResourceKey(String resourceKey) {
+ this.resourceKey = resourceKey;
+ }
+
+ public NodeMeta getNodeMeta() {
+ return nodeMeta;
+ }
+
+ public void setNodeMeta(NodeMeta nodeMeta) {
+ this.nodeMeta = nodeMeta;
+ }
+
+ public boolean isRootNode() {
+ return isRootNode;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "JsonNode [" + (id != null ? "id=" + id + ", " : "")
+ + (itemType != null ? "itemType=" + itemType + ", " : "")
+ + (itemNameKey != null ? "itemNameKey=" + itemNameKey + ", " : "")
+ + (itemNameValue != null ? "itemNameValue=" + itemNameValue + ", " : "")
+ + (itemProperties != null ? "itemProperties=" + itemProperties + ", " : "")
+ + (nodeMeta != null ? "nodeMeta=" + nodeMeta + ", " : "")
+ + (resourceKey != null ? "resourceKey=" + resourceKey + ", " : "")
+ + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "")
+ + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]";
+ }
+
+
+}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingAction.java b/src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingAction.java
index b7038bf..2a6f383 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingAction.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingAction.java
@@ -26,6 +26,9 @@ package org.onap.aai.sparky.viewandinspect.enumeration;
* The Enum NodeProcessingAction.
*/
public enum NodeProcessingAction {
- SELF_LINK_SET, NEW_NODE_PROCESSED, SELF_LINK_RESOLVE_ERROR, SELF_LINK_DETERMINATION_ERROR, SELF_LINK_RESOLVE_OK, SELF_LINK_RESPONSE_PARSE_ERROR, SELF_LINK_RESPONSE_PARSE_OK, NEIGHBORS_PROCESSED_ERROR, NEIGHBORS_PROCESSED_OK, COMPLEX_ATTRIBUTE_GROUP_PARSE_ERROR, COMPLEX_ATTRIBUTE_GROUP_PARSE_OK, NODE_IDENTITY_ERROR, UNEXPECTED_STATE_TRANSITION
+ SELF_LINK_SET, NEW_NODE_PROCESSED, SELF_LINK_RESOLVE_ERROR, SELF_LINK_DETERMINATION_ERROR,
+ SELF_LINK_RESOLVE_OK, SELF_LINK_RESPONSE_PARSE_ERROR, SELF_LINK_RESPONSE_PARSE_OK,
+ NEIGHBORS_PROCESSED_ERROR, NEIGHBORS_PROCESSED_OK, COMPLEX_ATTRIBUTE_GROUP_PARSE_ERROR,
+ COMPLEX_ATTRIBUTE_GROUP_PARSE_OK, NODE_IDENTITY_ERROR,UNEXPECTED_STATE_TRANSITION
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingState.java b/src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingState.java
index 21c27f6..f287617 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingState.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/enumeration/NodeProcessingState.java
@@ -26,5 +26,4 @@ package org.onap.aai.sparky.viewandinspect.enumeration;
* The Enum NodeProcessingState.
*/
public enum NodeProcessingState {
- INIT, SELF_LINK_UNRESOLVED, SELF_LINK_RESPONSE_UNPROCESSED, NEIGHBORS_UNPROCESSED, READY, ERROR
-}
+ INIT, SELF_LINK_UNRESOLVED, SELF_LINK_RESPONSE_UNPROCESSED, NEIGHBORS_UNPROCESSED, READY, ERROR}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java b/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java
index 5101c28..8500d0d 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java
@@ -36,16 +36,14 @@ import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.sparky.common.search.CommonSearchSuggestion;
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.dal.elasticsearch.SearchAdapter;
-import org.onap.aai.sparky.dal.sas.config.SearchServiceConfig;
import org.onap.aai.sparky.logging.AaiUiMsgs;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.search.api.SearchProvider;
import org.onap.aai.sparky.search.config.SuggestionConfig;
import org.onap.aai.sparky.search.entity.QuerySearchEntity;
import org.onap.aai.sparky.search.entity.SearchSuggestion;
import org.onap.aai.sparky.util.NodeUtils;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -56,42 +54,42 @@ public class ViewInspectSearchProvider implements SearchProvider {
private static final Logger LOG =
LoggerFactory.getInstance().getLogger(ViewInspectSearchProvider.class);
- private SearchServiceConfig sasConfig = null;
- private SearchAdapter search = null;
- private OxmModelLoader oxmModelLoader;
+ private SearchServiceAdapter searchServiceAdapter = null;
+ private SuggestionConfig suggestionConfig;
private String additionalSearchSuggestionText;
-
+
private static final String KEY_SEARCH_RESULT = "searchResult";
private static final String KEY_HITS = "hits";
private static final String KEY_DOCUMENT = "document";
private static final String KEY_CONTENT = "content";
- private static final String VI_SUGGESTION_ROUTE = "schema"; // TODO -> Read route from
- // suggestive-search.properties
- // instead of hard coding
-
private static final String KEY_SEARCH_TAG_IDS = "searchTagIDs";
private static final String KEY_SEARCH_TAGS = "searchTags";
private static final String KEY_LINK = "link";
private static final String KEY_ENTITY_TYPE = "entityType";
- private static final String VALUE_QUERY = "query";
- public ViewInspectSearchProvider(OxmModelLoader oxmModelLoader) throws Exception {
-
- sasConfig = SearchServiceConfig.getConfig();
- search = new SearchAdapter();
- suggestionConfig = SuggestionConfig.getConfig();
- this.oxmModelLoader = oxmModelLoader;
+ private final String viewInspectIndexName;
+ private final String viewInspectSuggestionRoute;
+ private OxmEntityLookup oxmEntityLookup;
+
+ public ViewInspectSearchProvider(SearchServiceAdapter searchServiceAdapter,
+ SuggestionConfig suggestionConfig, String viewInspectIndexName,
+ String viewInspectSuggestionRoute, OxmEntityLookup oxmEntityLookup) throws Exception {
+
+ this.searchServiceAdapter = searchServiceAdapter;
+ this.oxmEntityLookup = oxmEntityLookup;
+ this.suggestionConfig = suggestionConfig;
additionalSearchSuggestionText = null;
+ this.viewInspectIndexName = viewInspectIndexName;
+ this.viewInspectSuggestionRoute = viewInspectSuggestionRoute;
}
-
+
@Override
public List<SearchSuggestion> search(QuerySearchEntity queryRequest) {
List<SearchSuggestion> suggestionEntityList = new ArrayList<SearchSuggestion>();
-
-
+
/*
* Based on the configured stop words, we need to strip any matched stop-words ( case
* insensitively ) from the query string, before hitting elastic to prevent the words from being
@@ -105,13 +103,12 @@ public class ViewInspectSearchProvider implements SearchProvider {
final String queryStringWithoutStopWords =
stripStopWordsFromQuery(queryRequest.getQueryStr());
- final String fullUrlStr = getSasFullUrl(sasConfig.getIndexName(), VALUE_QUERY,
- sasConfig.getIpAddress(), sasConfig.getHttpPort(), sasConfig.getVersion());
+ final String fullUrlStr = searchServiceAdapter.buildSearchServiceQueryUrl(viewInspectIndexName);
- String postBody = String.format(VIUI_SEARCH_TEMPLATE,
- Integer.parseInt(queryRequest.getMaxResults()), queryStringWithoutStopWords);
+ String postBody = String.format(VIUI_SEARCH_TEMPLATE, Integer.parseInt(queryRequest.getMaxResults()),
+ queryStringWithoutStopWords);
- OperationResult opResult = search.doPost(fullUrlStr, postBody, "application/json");
+ OperationResult opResult = searchServiceAdapter.doPost(fullUrlStr, postBody, "application/json");
if (opResult.getResultCode() == 200) {
suggestionEntityList =
generateSuggestionsForSearchResponse(opResult.getResult(), queryRequest.getQueryStr());
@@ -124,7 +121,7 @@ public class ViewInspectSearchProvider implements SearchProvider {
}
-
+
public String getAdditionalSearchSuggestionText() {
return additionalSearchSuggestionText;
}
@@ -133,22 +130,9 @@ public class ViewInspectSearchProvider implements SearchProvider {
this.additionalSearchSuggestionText = additionalSearchSuggestionText;
}
- /**
- * Get Full URL for search
- *
- * @param api the api
- * @param indexName
- * @return the full url
- */
- private String getSasFullUrl(String indexName, String type, String ipAddress, String port,
- String version) {
-
- return String.format("https://%s:%s/services/search-data-service/%s/search/indexes/%s/%s",
- ipAddress, port, version, indexName, type);
- }
-
-
+
+
/**
* Builds the search response.
*
@@ -171,7 +155,7 @@ public class ViewInspectSearchProvider implements SearchProvider {
rootNode = mapper.readTree(operationResult);
JsonNode hitsNode = rootNode.get(KEY_SEARCH_RESULT);
-
+
// Check if there are hits that are coming back
@@ -192,7 +176,7 @@ public class ViewInspectSearchProvider implements SearchProvider {
// do the point transformation as we build the response?
suggestionEntity = new CommonSearchSuggestion();
- suggestionEntity.setRoute(VI_SUGGESTION_ROUTE);
+ suggestionEntity.setRoute(viewInspectSuggestionRoute);
/*
* This is where we probably want to annotate the search tags because we also have access
@@ -217,10 +201,10 @@ public class ViewInspectSearchProvider implements SearchProvider {
// at least send back the un-annotated search tags
suggestionEntity.setText(searchTags);
}
-
- if (getAdditionalSearchSuggestionText() != null) {
- String suggestionText = suggestionEntity.getText();
- suggestionText += TierSupportUiConstants.SUGGESTION_TEXT_SEPARATOR
+
+ if ( getAdditionalSearchSuggestionText() != null ) {
+ String suggestionText = suggestionEntity.getText() ;
+ suggestionText += SparkyConstants.SUGGESTION_TEXT_SEPARATOR
+ getAdditionalSearchSuggestionText();
suggestionEntity.setText(suggestionText);
}
@@ -236,9 +220,9 @@ public class ViewInspectSearchProvider implements SearchProvider {
}
return suggestionEntityList;
}
-
-
-
+
+
+
/**
* The current format of an UI-dropdown-item is like: "search-terms entityType att1=attr1_val".
* Example, for pserver: search-terms pserver hostname=djmAG-72060,
@@ -287,7 +271,7 @@ public class ViewInspectSearchProvider implements SearchProvider {
// simpler
String[] queryTerms = queryStr.toLowerCase().split(" ");
- OxmEntityDescriptor desc = OxmEntityLookup.getInstance().getEntityDescriptors().get(entityType);
+ OxmEntityDescriptor desc = oxmEntityLookup.getEntityDescriptors().get(entityType);
if (desc == null) {
LOG.error(AaiUiMsgs.ENTITY_NOT_FOUND_IN_OXM, entityType.toString());
@@ -337,8 +321,8 @@ public class ViewInspectSearchProvider implements SearchProvider {
"Search tags length did not match search tag ID length for entity type " + entityType;
LOG.error(AaiUiMsgs.ENTITY_SYNC_SEARCH_TAG_ANNOTATION_FAILED, errorMessage);
}
-
-
+
+
/*
* if none of the user query terms matched the index entity search tags then we should still tag
@@ -363,7 +347,7 @@ public class ViewInspectSearchProvider implements SearchProvider {
return searchTagsBuilder.toString();
}
-
+
/**
* Query terms match search tag.
*
@@ -386,7 +370,7 @@ public class ViewInspectSearchProvider implements SearchProvider {
return false;
}
-
+
/**
* Gets the value from node.
*
@@ -409,15 +393,15 @@ public class ViewInspectSearchProvider implements SearchProvider {
return null;
}
-
+
private static final String VIUI_SEARCH_TEMPLATE =
"{ " + "\"results-start\": 0," + "\"results-size\": %d," + "\"queries\": [{" + "\"must\": {"
+ "\"match\": {" + "\"field\": \"entityType searchTags crossEntityReferenceValues\","
+ "\"value\": \"%s\"," + "\"operator\": \"and\", "
+ "\"analyzer\": \"whitespace_analyzer\"" + "}" + "}" + "}]" + "}";
-
- private SuggestionConfig suggestionConfig = null;
-
+
+ //private SuggestionConfig suggestionConfig = null;
+
/**
* @param queryStr - space separate query search terms
* @return - query string with stop-words removed
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContext.java b/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContext.java
new file mode 100644
index 0000000..42e8d05
--- /dev/null
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContext.java
@@ -0,0 +1,1635 @@
+/**
+ * ============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.services;
+
+import static java.util.concurrent.CompletableFuture.supplyAsync;
+
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.http.client.utils.URIBuilder;
+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.config.oxm.OxmEntityDescriptor;
+import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
+import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
+import org.onap.aai.sparky.logging.AaiUiMsgs;
+import org.onap.aai.sparky.sync.entity.SearchableEntity;
+import org.onap.aai.sparky.util.NodeUtils;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
+import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
+import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
+import org.onap.aai.sparky.viewandinspect.entity.InlineMessage;
+import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction;
+import org.onap.aai.sparky.viewandinspect.entity.QueryParams;
+import org.onap.aai.sparky.viewandinspect.entity.Relationship;
+import org.onap.aai.sparky.viewandinspect.entity.RelationshipData;
+import org.onap.aai.sparky.viewandinspect.entity.RelationshipList;
+import org.onap.aai.sparky.viewandinspect.entity.SelfLinkDeterminationTransaction;
+import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingAction;
+import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingState;
+import org.onap.aai.sparky.viewandinspect.task.PerformNodeSelfLinkProcessingTask;
+import org.onap.aai.sparky.viewandinspect.task.PerformSelfLinkDeterminationTask;
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+
+/**
+ * The Class SelfLinkNodeCollector.
+ */
+public class BaseVisualizationContext implements VisualizationContext {
+
+ private static final int MAX_DEPTH_EVALUATION_ATTEMPTS = 100;
+ private static final String DEPTH_ALL_MODIFIER = "?depth=all";
+ private static final String NODES_ONLY_MODIFIER = "?nodes-only";
+ private static final String SERVICE_INSTANCE = "service-instance";
+
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(
+ BaseVisualizationContext.class);
+ private final ActiveInventoryAdapter aaiAdapter;
+
+ private int maxSelfLinkTraversalDepth;
+ private AtomicInteger numLinksDiscovered;
+ private AtomicInteger numSuccessfulLinkResolveFromCache;
+ private AtomicInteger numSuccessfulLinkResolveFromFromServer;
+ private AtomicInteger numFailedLinkResolve;
+ private AtomicInteger aaiWorkOnHand;
+
+ private VisualizationConfigs visualizationConfigs;
+
+ private AtomicInteger totalLinksRetrieved;
+
+ private final long contextId;
+ private final String contextIdStr;
+
+ private ObjectMapper mapper;
+ private InlineMessage inlineMessage = null;
+
+ private ExecutorService aaiExecutorService;
+ private OxmEntityLookup oxmEntityLookup;
+
+ /*
+ * The node cache is intended to be a flat structure indexed by a primary key to avoid needlessly
+ * re-requesting the same self-links over-and-over again, to speed up the overall render time and
+ * more importantly to reduce the network cost of determining information we already have.
+ */
+ private ConcurrentHashMap<String, ActiveInventoryNode> nodeCache;
+
+ /**
+ * Instantiates a new self link node collector.
+ *
+ * @param loader the loader
+ * @throws Exception the exception
+ */
+ public BaseVisualizationContext(long contextId, ActiveInventoryAdapter aaiAdapter,
+ ExecutorService aaiExecutorService, VisualizationConfigs visualizationConfigs,
+ OxmEntityLookup oxmEntityLookup)
+ throws Exception {
+
+ this.contextId = contextId;
+ this.contextIdStr = "[Context-Id=" + contextId + "]";
+ this.aaiAdapter = aaiAdapter;
+ this.aaiExecutorService = aaiExecutorService;
+ this.visualizationConfigs = visualizationConfigs;
+ this.oxmEntityLookup = oxmEntityLookup;
+
+ this.nodeCache = new ConcurrentHashMap<String, ActiveInventoryNode>();
+ this.numLinksDiscovered = new AtomicInteger(0);
+ this.totalLinksRetrieved = new AtomicInteger(0);
+ this.numSuccessfulLinkResolveFromCache = new AtomicInteger(0);
+ this.numSuccessfulLinkResolveFromFromServer = new AtomicInteger(0);
+ this.numFailedLinkResolve = new AtomicInteger(0);
+ this.aaiWorkOnHand = new AtomicInteger(0);
+
+ this.maxSelfLinkTraversalDepth = this.visualizationConfigs.getMaxSelfLinkTraversalDepth();
+
+ this.mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(Include.NON_EMPTY);
+ mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.KebabCaseStrategy());
+ }
+
+ public long getContextId() {
+ return contextId;
+ }
+
+ /**
+ * A utility method for extracting all entity-type primary key values from a provided self-link
+ * and return a set of generic-query API keys.
+ *
+ * @param parentEntityType
+ * @param link
+ * @return a list of key values that can be used for this entity with the AAI generic-query API
+ */
+ protected List<String> extractQueryParamsFromSelfLink(String link) {
+
+ List<String> queryParams = new ArrayList<String>();
+
+ if (link == null) {
+ LOG.error(AaiUiMsgs.QUERY_PARAM_EXTRACTION_ERROR, "self link is null");
+ return queryParams;
+ }
+
+ Map<String, OxmEntityDescriptor> entityDescriptors = oxmEntityLookup.getEntityDescriptors();
+
+ try {
+
+ URIBuilder urlBuilder = new URIBuilder(link);
+ String urlPath = urlBuilder.getPath();
+
+ OxmEntityDescriptor descriptor = null;
+ String[] urlPathElements = urlPath.split("/");
+ List<String> primaryKeyNames = null;
+ int index = 0;
+ String entityType = null;
+
+ while (index < urlPathElements.length) {
+
+ descriptor = entityDescriptors.get(urlPathElements[index]);
+
+ if (descriptor != null) {
+ entityType = urlPathElements[index];
+ primaryKeyNames = descriptor.getPrimaryKeyAttributeNames();
+
+ /*
+ * Make sure from what ever index we matched the parent entity-type on that we can extract
+ * additional path elements for the primary key values.
+ */
+
+ if (index + primaryKeyNames.size() < urlPathElements.length) {
+
+ for (String primaryKeyName : primaryKeyNames) {
+ index++;
+ queryParams.add(entityType + "." + primaryKeyName + ":" + urlPathElements[index]);
+ }
+ } else {
+ LOG.error(AaiUiMsgs.QUERY_PARAM_EXTRACTION_ERROR,
+ "Could not extract query parametrs for entity-type = '" + entityType
+ + "' from self-link = " + link);
+ }
+ }
+
+ index++;
+ }
+
+ } catch (URISyntaxException exc) {
+
+ LOG.error(AaiUiMsgs.QUERY_PARAM_EXTRACTION_ERROR,
+ "Error extracting query parameters from self-link = " + link + ". Error = "
+ + exc.getMessage());
+ }
+
+ return queryParams;
+
+ }
+
+ /**
+ * Decode complex attribute group.
+ *
+ * @param ain the ain
+ * @param attributeGroup the attribute group
+ * @return boolean indicating whether operation was successful (true), / failure(false).
+ */
+ public boolean decodeComplexAttributeGroup(ActiveInventoryNode ain, JsonNode attributeGroup) {
+
+ try {
+
+ Iterator<Entry<String, JsonNode>> entityArrays = attributeGroup.fields();
+ Entry<String, JsonNode> entityArray = null;
+
+ if (entityArrays == null) {
+ LOG.error(AaiUiMsgs.ATTRIBUTE_GROUP_FAILURE, attributeGroup.toString());
+ ain.changeState(NodeProcessingState.ERROR, NodeProcessingAction.NEIGHBORS_PROCESSED_ERROR);
+ return false;
+ }
+
+ while (entityArrays.hasNext()) {
+
+ entityArray = entityArrays.next();
+
+ String entityType = entityArray.getKey();
+ JsonNode entityArrayObject = entityArray.getValue();
+
+ if (entityArrayObject.isArray()) {
+
+ Iterator<JsonNode> entityCollection = entityArrayObject.elements();
+ JsonNode entity = null;
+ while (entityCollection.hasNext()) {
+ entity = entityCollection.next();
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "decodeComplexAttributeGroup(),"
+ + " entity = " + entity.toString());
+ }
+
+ /**
+ * Here's what we are going to do:
+ *
+ * <li>In the ActiveInventoryNode, on construction maintain a collection of queryParams
+ * that is added to for the purpose of discovering parent->child hierarchies.
+ *
+ * <li>When we hit this block of the code then we'll use the queryParams to feed the
+ * generic query to resolve the self-link asynchronously.
+ *
+ * <li>Upon successful link determination, then and only then will we create a new node
+ * in the nodeCache and process the child
+ *
+ */
+
+ ActiveInventoryNode newNode = new ActiveInventoryNode(this.visualizationConfigs, oxmEntityLookup);
+ newNode.setEntityType(entityType);
+
+ /*
+ * This is partially a lie because we actually don't have a self-link for complex nodes
+ * discovered in this way.
+ */
+ newNode.setSelfLinkProcessed(true);
+ newNode.changeState(NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
+ NodeProcessingAction.COMPLEX_ATTRIBUTE_GROUP_PARSE_OK);
+
+ /*
+ * copy parent query params into new child
+ */
+
+ if (SERVICE_INSTANCE.equals(entityType)) {
+
+ /*
+ * 1707 AAI has an issue being tracked with AAI-8932 where the generic-query cannot be
+ * resolved if all the service-instance path keys are provided. The query only works
+ * if only the service-instance key and valude are passed due to a historical reason.
+ * A fix is being worked on for 1707, and when it becomes available we can revert this
+ * small change.
+ */
+
+ newNode.clearQueryParams();
+
+ } else {
+
+ /*
+ * For all other entity-types we want to copy the parent query parameters into the new node
+ * query parameters.
+ */
+
+ for (String queryParam : ain.getQueryParams()) {
+ newNode.addQueryParam(queryParam);
+ }
+
+ }
+
+
+ if (!addComplexGroupToNode(newNode, entity)) {
+ LOG.error(AaiUiMsgs.ATTRIBUTE_GROUP_FAILURE, "Failed to add child to parent for child = " + entity.toString());
+ }
+
+ if (!addNodeQueryParams(newNode)) {
+ LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE_NODE_ID, "Error determining node id and key for node = " + newNode.dumpNodeTree(true)
+ + " skipping relationship processing");
+ newNode.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.NODE_IDENTITY_ERROR);
+ return false;
+ } else {
+
+ newNode.changeState(NodeProcessingState.NEIGHBORS_UNPROCESSED,
+ NodeProcessingAction.COMPLEX_ATTRIBUTE_GROUP_PARSE_OK);
+
+ }
+
+
+ /*
+ * Order matters for the query params. We need to set the parent ones before the child
+ * node
+ */
+
+ String selfLinkQuery =
+ aaiAdapter.getGenericQueryForSelfLink(entityType, newNode.getQueryParams());
+
+ /**
+ * <li>get the self-link
+ * <li>add it to the new node
+ * <li>generate node id
+ * <li>add node to node cache
+ * <li>add node id to parent outbound links list
+ * <li>process node children (should be automatic) (but don't query and resolve
+ * self-link as we already have all the data)
+ */
+
+ SelfLinkDeterminationTransaction txn = new SelfLinkDeterminationTransaction();
+
+ txn.setQueryString(selfLinkQuery);
+ txn.setNewNode(newNode);
+ txn.setParentNodeId(ain.getNodeId());
+ aaiWorkOnHand.incrementAndGet();
+ supplyAsync(new PerformSelfLinkDeterminationTask(txn, null, aaiAdapter),
+ aaiExecutorService).whenComplete((nodeTxn, error) -> {
+ aaiWorkOnHand.decrementAndGet();
+ if (error != null) {
+ LOG.error(AaiUiMsgs.SELF_LINK_DETERMINATION_FAILED_GENERIC, selfLinkQuery);
+ } else {
+
+ OperationResult opResult = nodeTxn.getOpResult();
+
+ ActiveInventoryNode newChildNode = txn.getNewNode();
+
+ if (opResult != null && opResult.wasSuccessful()) {
+
+ if (!opResult.wasSuccessful()) {
+ numFailedLinkResolve.incrementAndGet();
+ }
+
+ if (opResult.isFromCache()) {
+ numSuccessfulLinkResolveFromCache.incrementAndGet();
+ } else {
+ numSuccessfulLinkResolveFromFromServer.incrementAndGet();
+ }
+
+ /*
+ * extract the self-link from the operational result.
+ */
+
+ Collection<JsonNode> entityLinks = new ArrayList<JsonNode>();
+ JsonNode genericQueryResult = null;
+ try {
+ genericQueryResult =
+ NodeUtils.convertJsonStrToJsonNode(nodeTxn.getOpResult().getResult());
+ } catch (Exception exc) {
+ LOG.error(AaiUiMsgs.JSON_CONVERSION_ERROR, JsonNode.class.toString(), exc.getMessage());
+ }
+
+ NodeUtils.extractObjectsByKey(genericQueryResult, "resource-link",
+ entityLinks);
+
+ String selfLink = null;
+
+ if (entityLinks.size() != 1) {
+
+ LOG.error(AaiUiMsgs.SELF_LINK_DETERMINATION_FAILED_UNEXPECTED_LINKS, String.valueOf(entityLinks.size()));
+
+ } else {
+ selfLink = ((JsonNode) entityLinks.toArray()[0]).asText();
+ selfLink = ActiveInventoryAdapter.extractResourcePath(selfLink);
+
+ newChildNode.setSelfLink(selfLink);
+ newChildNode.setNodeId(NodeUtils.generateUniqueShaDigest(selfLink));
+
+ String uri = NodeUtils.calculateEditAttributeUri(selfLink);
+ if (uri != null) {
+ newChildNode.addProperty(SparkyConstants.URI_ATTR_NAME, uri);
+ }
+
+ ActiveInventoryNode parent = nodeCache.get(txn.getParentNodeId());
+
+ if (parent != null) {
+ parent.addOutboundNeighbor(newChildNode.getNodeId());
+ newChildNode.addInboundNeighbor(parent.getNodeId());
+ }
+
+ newChildNode.setSelfLinkPendingResolve(false);
+ newChildNode.setSelfLinkProcessed(true);
+ newChildNode.changeState(NodeProcessingState.NEIGHBORS_UNPROCESSED,
+ NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
+
+ nodeCache.putIfAbsent(newChildNode.getNodeId(), newChildNode);
+
+ }
+
+ } else {
+ LOG.error(AaiUiMsgs.SELF_LINK_RETRIEVAL_FAILED, txn.getQueryString(),
+ String.valueOf(nodeTxn.getOpResult().getResultCode()), nodeTxn.getOpResult().getResult());
+ newChildNode.setSelflinkRetrievalFailure(true);
+ newChildNode.setSelfLinkProcessed(true);
+ newChildNode.setSelfLinkPendingResolve(false);
+
+ newChildNode.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.SELF_LINK_DETERMINATION_ERROR);
+
+ }
+
+ }
+
+ });
+
+ }
+
+ return true;
+
+ } else {
+ LOG.error(AaiUiMsgs.UNHANDLED_OBJ_TYPE_FOR_ENTITY_TYPE, entityType);
+ }
+
+ }
+ } catch (Exception exc) {
+ LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Exception caught while"
+ + " decoding complex attribute group - " + exc.getMessage());
+ }
+
+ return false;
+
+ }
+
+ /**
+ * Process self link response.
+ *
+ * @param nodeId the node id
+ */
+ private void processSelfLinkResponse(String nodeId) {
+
+ if (nodeId == null) {
+ LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Cannot process self link"
+ + " response because nodeId is null");
+ return;
+ }
+
+ ActiveInventoryNode ain = nodeCache.get(nodeId);
+
+ if (ain == null) {
+ LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Cannot process self link response"
+ + " because can't find node for id = " + nodeId);
+ return;
+ }
+
+ JsonNode jsonNode = null;
+
+ try {
+ jsonNode = mapper.readValue(ain.getOpResult().getResult(), JsonNode.class);
+ } catch (Exception exc) {
+ LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR, "Failed to marshal json"
+ + " response str into JsonNode with error, " + exc.getLocalizedMessage());
+ ain.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
+ return;
+ }
+
+ if (jsonNode == null) {
+ LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR, "Failed to parse json node str."
+ + " Parse resulted a null value.");
+ ain.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
+ return;
+ }
+
+ Iterator<Entry<String, JsonNode>> fieldNames = jsonNode.fields();
+ Entry<String, JsonNode> field = null;
+
+ RelationshipList relationshipList = null;
+
+ while (fieldNames.hasNext()) {
+
+ field = fieldNames.next();
+ String fieldName = field.getKey();
+
+ if ("relationship-list".equals(fieldName)) {
+
+ try {
+ relationshipList = mapper.readValue(field.getValue().toString(), RelationshipList.class);
+
+ if (relationshipList != null) {
+ ain.addRelationshipList(relationshipList);
+ }
+
+ } catch (Exception exc) {
+ LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR, "Failed to parse relationship-list"
+ + " attribute. Parse resulted in error, " + exc.getLocalizedMessage());
+ ain.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
+ return;
+ }
+
+ } else {
+
+ JsonNode nodeValue = field.getValue();
+
+ if (nodeValue != null && nodeValue.isValueNode()) {
+
+ if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
+
+ /*
+ * entity property name is not an entity, thus we can add this property name and value
+ * to our property set
+ */
+
+ ain.addProperty(fieldName, nodeValue.asText());
+
+ }
+
+ } else {
+
+ if (nodeValue.isArray()) {
+
+ if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
+
+ /*
+ * entity property name is not an entity, thus we can add this property name and value
+ * to our property set
+ */
+
+ ain.addProperty(field.getKey(), nodeValue.toString());
+
+ }
+
+ } else {
+
+ ain.addComplexGroup(nodeValue);
+
+ }
+
+ }
+ }
+
+ }
+
+ String uri = NodeUtils.calculateEditAttributeUri(ain.getSelfLink());
+ if (uri != null) {
+ ain.addProperty(SparkyConstants.URI_ATTR_NAME, uri);
+ }
+
+ /*
+ * We need a special behavior for intermediate entities from the REST model
+ *
+ * Tenants are not top level entities, and when we want to visualization
+ * their children, we need to construct keys that include the parent entity query
+ * keys, the current entity type keys, and the child keys. We'll always have the
+ * current entity and children, but never the parent entity in the current (1707) REST
+ * data model.
+ *
+ * We have two possible solutions:
+ *
+ * 1) Try to use the custom-query approach to learn about the entity keys
+ * - this could be done, but it could be very expensive for large objects. When we do the first
+ * query to get a tenant, it will list all the in and out edges related to this entity,
+ * there is presently no way to filter this. But the approach could be made to work and it would be
+ * somewhat data-model driven, other than the fact that we have to first realize that the entity
+ * that is being searched for is not top-level entity. Once we have globally unique ids for resources
+ * this logic will not be needed and everything will be simpler. The only reason we are in this logic
+ * at all is to be able to calculate a url for the child entities so we can hash it to generate
+ * a globally unique id that can be safely used for the node.
+ *
+ * *2* Extract the keys from the pathed self-link.
+ * This is a bad solution and I don't like it but it will be fast for all resource types, as the
+ * information is already encoded in the URI. When we get to a point where we switch to a better
+ * globally unique entity identity model, then a lot of the code being used to calculate an entity url
+ * to in-turn generate a deterministic globally unique id will disappear.
+ *
+ *
+ * right now we have the following:
+ *
+ * - cloud-regions/cloud-region/{cloud-region-id}/{cloud-owner-id}/tenants/tenant/{tenant-id}
+ *
+ */
+
+ /*
+ * For all entity types use the self-link extraction method to be consistent. Once we have a
+ * globally unique identity mechanism for entities, this logic can be revisited.
+ */
+ ain.clearQueryParams();
+ ain.addQueryParams(extractQueryParamsFromSelfLink(ain.getSelfLink()));
+ ain.changeState(NodeProcessingState.NEIGHBORS_UNPROCESSED,
+ NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
+
+
+ }
+
+ /**
+ * Perform self link resolve.
+ *
+ * @param nodeId the node id
+ */
+ private void performSelfLinkResolve(String nodeId) {
+
+ if (nodeId == null) {
+ LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Resolve of self-link"
+ + " has been skipped because provided nodeId is null");
+ return;
+ }
+
+ ActiveInventoryNode ain = nodeCache.get(nodeId);
+
+ if (ain == null) {
+ LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Failed to find node with id, " + nodeId
+ + ", from node cache. Resolve self-link method has been skipped.");
+ return;
+ }
+
+ if (!ain.isSelfLinkPendingResolve()) {
+
+ ain.setSelfLinkPendingResolve(true);
+
+ // kick off async self-link resolution
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "About to process node in SELF_LINK_UNPROCESSED State, link = " + ain.getSelfLink());
+ }
+
+ numLinksDiscovered.incrementAndGet();
+
+ String depthModifier = DEPTH_ALL_MODIFIER;
+
+ /*
+ * If the current node is the search target, we want to see everything the node has to offer
+ * from the self-link and not filter it to a single node.
+ */
+
+ if (visualizationConfigs.getShallowEntities().contains(ain.getEntityType())
+ && !ain.isRootNode()) {
+ depthModifier = NODES_ONLY_MODIFIER;
+ }
+
+ NodeProcessingTransaction txn = new NodeProcessingTransaction();
+ txn.setProcessingNode(ain);
+ txn.setRequestParameters(depthModifier);
+ aaiWorkOnHand.incrementAndGet();
+ supplyAsync(
+ new PerformNodeSelfLinkProcessingTask(txn, depthModifier, aaiAdapter),
+ aaiExecutorService).whenComplete((nodeTxn, error) -> {
+ aaiWorkOnHand.decrementAndGet();
+ if (error != null) {
+
+ /*
+ * an error processing the self link should probably result in the node processing
+ * state shifting to ERROR
+ */
+
+ nodeTxn.getProcessingNode().setSelflinkRetrievalFailure(true);
+
+ nodeTxn.getProcessingNode().changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.SELF_LINK_RESOLVE_ERROR);
+
+ nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
+
+ } else {
+
+ totalLinksRetrieved.incrementAndGet();
+
+ OperationResult opResult = nodeTxn.getOpResult();
+
+ if (opResult != null && opResult.wasSuccessful()) {
+
+ if (!opResult.wasSuccessful()) {
+ numFailedLinkResolve.incrementAndGet();
+ }
+
+ if (opResult.isFromCache()) {
+ numSuccessfulLinkResolveFromCache.incrementAndGet();
+ } else {
+ numSuccessfulLinkResolveFromFromServer.incrementAndGet();
+ }
+
+ // success path
+ nodeTxn.getProcessingNode().setOpResult(opResult);
+ nodeTxn.getProcessingNode().changeState(
+ NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
+ NodeProcessingAction.SELF_LINK_RESOLVE_OK);
+
+ nodeTxn.getProcessingNode().setSelfLinkProcessed(true);
+ nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
+
+ } else {
+ LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Self Link retrieval for link,"
+ + txn.getSelfLinkWithModifiers() + ", failed with error code,"
+ + nodeTxn.getOpResult().getResultCode() + ", and message,"
+ + nodeTxn.getOpResult().getResult());
+
+ nodeTxn.getProcessingNode().setSelflinkRetrievalFailure(true);
+ nodeTxn.getProcessingNode().setSelfLinkProcessed(true);
+
+ nodeTxn.getProcessingNode().changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.SELF_LINK_RESOLVE_ERROR);
+
+ nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
+
+ }
+ }
+
+ });
+
+ }
+
+ }
+
+
+ /**
+ * Process neighbors.
+ *
+ * @param nodeId the node id
+ */
+ private void processNeighbors(String nodeId) {
+
+ if (nodeId == null) {
+ LOG.error(AaiUiMsgs.SELF_LINK_PROCESS_NEIGHBORS_ERROR, "Failed to process"
+ + " neighbors because nodeId is null.");
+ return;
+ }
+
+ ActiveInventoryNode ain = nodeCache.get(nodeId);
+
+ if (ain == null) {
+ LOG.error(AaiUiMsgs.SELF_LINK_PROCESS_NEIGHBORS_ERROR, "Failed to process"
+ + " neighbors because node could not be found in nodeCache with id, " + nodeId);
+ return;
+ }
+
+ /*
+ * process complex attribute and relationships
+ */
+
+ boolean neighborsProcessedSuccessfully = true;
+
+ for (JsonNode n : ain.getComplexGroups()) {
+ neighborsProcessedSuccessfully &= decodeComplexAttributeGroup(ain, n);
+ }
+
+ for (RelationshipList relationshipList : ain.getRelationshipLists()) {
+ neighborsProcessedSuccessfully &= addSelfLinkRelationshipChildren(ain, relationshipList);
+ }
+
+
+ if (neighborsProcessedSuccessfully) {
+ ain.changeState(NodeProcessingState.READY, NodeProcessingAction.NEIGHBORS_PROCESSED_OK);
+ } else {
+ ain.changeState(NodeProcessingState.ERROR, NodeProcessingAction.NEIGHBORS_PROCESSED_ERROR);
+ }
+
+
+ /*
+ * If neighbors fail to process, there is already a call to change the state within the
+ * relationship and neighbor processing functions.
+ */
+
+ }
+
+ /**
+ * Find and mark root node.
+ *
+ * @param queryParams the query params
+ * @return true, if successful
+ */
+ private boolean findAndMarkRootNode(QueryParams queryParams) {
+
+ for (ActiveInventoryNode cacheNode : nodeCache.values()) {
+
+ if (queryParams.getSearchTargetNodeId().equals(cacheNode.getNodeId())) {
+ cacheNode.setNodeDepth(0);
+ cacheNode.setRootNode(true);
+ LOG.info(AaiUiMsgs.ROOT_NODE_DISCOVERED, queryParams.getSearchTargetNodeId());
+ return true;
+ }
+ }
+
+ return false;
+
+ }
+
+ /**
+ * Process current node states.
+ *
+ * @param rootNodeDiscovered the root node discovered
+ */
+ private void processCurrentNodeStates(boolean rootNodeDiscovered) {
+ /*
+ * Force an evaluation of node depths before determining if we should limit state-based
+ * traversal or processing.
+ */
+ if (rootNodeDiscovered) {
+ evaluateNodeDepths();
+ }
+
+ for (ActiveInventoryNode cacheNode : nodeCache.values()) {
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "processCurrentNodeState(), nid = "
+ + cacheNode.getNodeId() + " , nodeDepth = " + cacheNode.getNodeDepth());
+ }
+
+ switch (cacheNode.getState()) {
+
+ case INIT: {
+ processInitialState(cacheNode.getNodeId());
+ break;
+ }
+
+ case READY:
+ case ERROR: {
+ break;
+ }
+
+ case SELF_LINK_UNRESOLVED: {
+ performSelfLinkResolve(cacheNode.getNodeId());
+ break;
+ }
+
+ case SELF_LINK_RESPONSE_UNPROCESSED: {
+ processSelfLinkResponse(cacheNode.getNodeId());
+ break;
+ }
+
+ case NEIGHBORS_UNPROCESSED: {
+
+ /*
+ * We use the rootNodeDiscovered flag to ignore depth retrieval thresholds until the root
+ * node is identified. Then the evaluative depth calculations should re-balance the graph
+ * around the root node.
+ */
+
+ if (!rootNodeDiscovered || cacheNode.getNodeDepth() < this.visualizationConfigs.getMaxSelfLinkTraversalDepth()) {
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "SLNC::processCurrentNodeState() -- Node at max depth,"
+ + " halting processing at current state = -- "
+ + cacheNode.getState() + " nodeId = " + cacheNode.getNodeId());
+ }
+
+
+
+ processNeighbors(cacheNode.getNodeId());
+
+ }
+
+ break;
+ }
+ default:
+ break;
+
+
+
+ }
+
+ }
+
+ }
+
+ /**
+ * Adds the complex group to node.
+ *
+ * @param targetNode the target node
+ * @param attributeGroup the attribute group
+ * @return true, if successful
+ */
+ private boolean addComplexGroupToNode(ActiveInventoryNode targetNode, JsonNode attributeGroup) {
+
+ if (attributeGroup == null) {
+ targetNode.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.COMPLEX_ATTRIBUTE_GROUP_PARSE_OK);
+ return false;
+ }
+
+ RelationshipList relationshipList = null;
+
+ if (attributeGroup.isObject()) {
+
+ Iterator<Entry<String, JsonNode>> fields = attributeGroup.fields();
+ Entry<String, JsonNode> field = null;
+ String fieldName;
+ JsonNode fieldValue;
+
+ while (fields.hasNext()) {
+ field = fields.next();
+ fieldName = field.getKey();
+ fieldValue = field.getValue();
+
+ if (fieldValue.isObject()) {
+
+ if (fieldName.equals("relationship-list")) {
+
+ try {
+ relationshipList =
+ mapper.readValue(field.getValue().toString(), RelationshipList.class);
+
+ if (relationshipList != null) {
+ targetNode.addRelationshipList(relationshipList);
+ }
+
+ } catch (Exception exc) {
+ LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR, "Failed to parse"
+ + " relationship-list attribute. Parse resulted in error, "
+ + exc.getLocalizedMessage());
+ targetNode.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.COMPLEX_ATTRIBUTE_GROUP_PARSE_ERROR);
+ return false;
+ }
+
+ } else {
+ targetNode.addComplexGroup(fieldValue);
+ }
+
+ } else if (fieldValue.isArray()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "Unexpected array type with a key = " + fieldName);
+ }
+ } else if (fieldValue.isValueNode()) {
+ if (oxmEntityLookup.getEntityDescriptors().get(field.getKey()) == null) {
+ /*
+ * property key is not an entity type, add it to our property set.
+ */
+ targetNode.addProperty(field.getKey(), fieldValue.asText());
+ }
+
+ }
+ }
+
+ } else if (attributeGroup.isArray()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "Unexpected array type for attributeGroup = " + attributeGroup);
+ }
+ } else if (attributeGroup.isValueNode()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "Unexpected value type for attributeGroup = " + attributeGroup);
+ }
+ }
+
+ return true;
+ }
+
+ public int getNumSuccessfulLinkResolveFromCache() {
+ return numSuccessfulLinkResolveFromCache.get();
+ }
+
+ public int getNumSuccessfulLinkResolveFromFromServer() {
+ return numSuccessfulLinkResolveFromFromServer.get();
+ }
+
+ public int getNumFailedLinkResolve() {
+ return numFailedLinkResolve.get();
+ }
+
+ public InlineMessage getInlineMessage() {
+ return inlineMessage;
+ }
+
+ public void setInlineMessage(InlineMessage inlineMessage) {
+ this.inlineMessage = inlineMessage;
+ }
+
+ public void setMaxSelfLinkTraversalDepth(int depth) {
+ this.maxSelfLinkTraversalDepth = depth;
+ }
+
+ public int getMaxSelfLinkTraversalDepth() {
+ return this.maxSelfLinkTraversalDepth;
+ }
+
+ public ConcurrentHashMap<String, ActiveInventoryNode> getNodeCache() {
+ return nodeCache;
+ }
+
+ /**
+ * Gets the relationship primary key values.
+ *
+ * @param r the r
+ * @param entityType the entity type
+ * @param pkeyNames the pkey names
+ * @return the relationship primary key values
+ */
+ private String getRelationshipPrimaryKeyValues(Relationship r, String entityType,
+ List<String> pkeyNames) {
+
+ StringBuilder sb = new StringBuilder(64);
+
+ if (pkeyNames.size() > 0) {
+ String primaryKey = extractKeyValueFromRelationData(r, entityType + "." + pkeyNames.get(0));
+ if (primaryKey != null) {
+
+ sb.append(primaryKey);
+
+ } else {
+ // this should be a fatal error because unless we can
+ // successfully retrieve all the expected keys we'll end up
+ // with a garbage node
+ LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: Failed to extract"
+ + " keyName, " + entityType + "." + pkeyNames.get(0)
+ + ", from relationship data, " + r.toString());
+ return null;
+ }
+
+ for (int i = 1; i < pkeyNames.size(); i++) {
+
+ String kv = extractKeyValueFromRelationData(r, entityType + "." + pkeyNames.get(i));
+ if (kv != null) {
+ sb.append("/").append(kv);
+ } else {
+ // this should be a fatal error because unless we can
+ // successfully retrieve all the expected keys we'll end up
+ // with a garbage node
+ LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: failed to extract keyName, "
+ + entityType + "." + pkeyNames.get(i)
+ + ", from relationship data, " + r.toString());
+ return null;
+ }
+ }
+
+ return sb.toString();
+
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Extract key value from relation data.
+ *
+ * @param r the r
+ * @param keyName the key name
+ * @return the string
+ */
+ private String extractKeyValueFromRelationData(Relationship r, String keyName) {
+
+ RelationshipData[] rdList = r.getRelationshipData();
+
+ for (RelationshipData relData : rdList) {
+
+ if (relData.getRelationshipKey().equals(keyName)) {
+ return relData.getRelationshipValue();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Determine node id and key.
+ *
+ * @param ain the ain
+ * @return true, if successful
+ */
+ private boolean addNodeQueryParams(ActiveInventoryNode ain) {
+
+ if (ain == null) {
+ LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE_NODE_ID, "ActiveInventoryNode is null");
+ return false;
+ }
+
+ List<String> pkeyNames =
+ oxmEntityLookup.getEntityDescriptors().get(ain.getEntityType()).getPrimaryKeyAttributeNames();
+
+ if (pkeyNames == null || pkeyNames.size() == 0) {
+ LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE_NODE_ID, "Primary key names is empty");
+ return false;
+ }
+
+ StringBuilder sb = new StringBuilder(64);
+
+ if (pkeyNames.size() > 0) {
+ String primaryKey = ain.getProperties().get(pkeyNames.get(0));
+ if (primaryKey != null) {
+ sb.append(primaryKey);
+ } else {
+ // this should be a fatal error because unless we can
+ // successfully retrieve all the expected keys we'll end up
+ // with a garbage node
+ LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: Failed to extract keyName, "
+ + pkeyNames.get(0) + ", from entity properties");
+ return false;
+ }
+
+ for (int i = 1; i < pkeyNames.size(); i++) {
+
+ String kv = ain.getProperties().get(pkeyNames.get(i));
+ if (kv != null) {
+ sb.append("/").append(kv);
+ } else {
+ // this should be a fatal error because unless we can
+ // successfully retrieve all the expected keys we'll end up
+ // with a garbage node
+ LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: Failed to extract keyName, "
+ + pkeyNames.get(i) + ", from entity properties");
+ return false;
+ }
+ }
+
+ /*final String nodeId = NodeUtils.generateUniqueShaDigest(ain.getEntityType(),
+ NodeUtils.concatArray(pkeyNames, "/"), sb.toString());*/
+
+ //ain.setNodeId(nodeId);
+ ain.setPrimaryKeyName(NodeUtils.concatArray(pkeyNames, "/"));
+ ain.setPrimaryKeyValue(sb.toString());
+
+ if (ain.getEntityType() != null && ain.getPrimaryKeyName() != null
+ && ain.getPrimaryKeyValue() != null) {
+ ain.addQueryParam(
+ ain.getEntityType() + "." + ain.getPrimaryKeyName() + ":" + ain.getPrimaryKeyValue());
+ }
+ return true;
+
+ }
+
+ return false;
+
+ }
+
+ /**
+ * Adds the self link relationship children.
+ *
+ * @param processingNode the processing node
+ * @param relationshipList the relationship list
+ * @return true, if successful
+ */
+ private boolean addSelfLinkRelationshipChildren(ActiveInventoryNode processingNode,
+ RelationshipList relationshipList) {
+
+ if (relationshipList == null) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "No relationships added to parent node = "
+ + processingNode.getNodeId() + " because relationshipList is empty");
+ processingNode.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.NEIGHBORS_PROCESSED_ERROR);
+ return false;
+ }
+
+ Relationship[] relationshipArray = relationshipList.getRelationshipList();
+ OxmEntityDescriptor descriptor = null;
+ String repairedSelfLink = null;
+
+ if (relationshipArray != null) {
+
+ ActiveInventoryNode newNode = null;
+ String resourcePath = null;
+
+ for (Relationship r : relationshipArray) {
+
+ resourcePath = ActiveInventoryAdapter.extractResourcePath(r.getRelatedLink());
+
+ String nodeId = NodeUtils.generateUniqueShaDigest(resourcePath);
+
+ if (nodeId == null) {
+
+ LOG.error(AaiUiMsgs.SKIPPING_RELATIONSHIP, r.toString());
+ processingNode.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.NODE_IDENTITY_ERROR);
+ return false;
+ }
+
+ newNode = new ActiveInventoryNode(this.visualizationConfigs, oxmEntityLookup);
+
+ String entityType = r.getRelatedTo();
+
+ if (r.getRelationshipData() != null) {
+ for (RelationshipData rd : r.getRelationshipData()) {
+ newNode.addQueryParam(rd.getRelationshipKey() + ":" + rd.getRelationshipValue());
+ }
+ }
+
+ descriptor = oxmEntityLookup.getEntityDescriptors().get(r.getRelatedTo());
+
+ newNode.setNodeId(nodeId);
+ newNode.setEntityType(entityType);
+ newNode.setSelfLink(resourcePath);
+
+ processingNode.addOutboundNeighbor(nodeId);
+
+ if (descriptor != null) {
+
+ List<String> pkeyNames = descriptor.getPrimaryKeyAttributeNames();
+
+ newNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
+ NodeProcessingAction.SELF_LINK_SET);
+
+ newNode.setPrimaryKeyName(NodeUtils.concatArray(pkeyNames, "/"));
+
+ String primaryKeyValues = getRelationshipPrimaryKeyValues(r, entityType, pkeyNames);
+ newNode.setPrimaryKeyValue(primaryKeyValues);
+
+ } else {
+
+ LOG.error(AaiUiMsgs.VISUALIZATION_OUTPUT_ERROR,
+ "Failed to parse entity because OXM descriptor could not be found for type = "
+ + r.getRelatedTo());
+
+ newNode.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.NEIGHBORS_PROCESSED_ERROR);
+
+ }
+
+ if (nodeCache.putIfAbsent(nodeId, newNode) != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "Failed to add node to nodeCache because it already exists. Node id = "
+ + newNode.getNodeId());
+ }
+ }
+
+ }
+
+ }
+
+ return true;
+
+ }
+
+ /**
+ * Process initial state.
+ *
+ * @param nodeId the node id
+ */
+ private void processInitialState(String nodeId) {
+
+ if (nodeId == null) {
+ LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE, "Node id is null");
+ return;
+ }
+
+ ActiveInventoryNode cachedNode = nodeCache.get(nodeId);
+
+ if (cachedNode == null) {
+ LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE, "Node cannot be"
+ + " found for nodeId, " + nodeId);
+ return;
+ }
+
+ if (cachedNode.getSelfLink() == null) {
+
+ if (cachedNode.getNodeId() == null ) {
+
+ /*
+ * if the self link is null at the INIT state, which could be valid if this node is a
+ * complex attribute group which didn't originate from a self-link, but in that situation
+ * both the node id and node key should already be set.
+ */
+
+ cachedNode.changeState(NodeProcessingState.ERROR, NodeProcessingAction.NODE_IDENTITY_ERROR);
+
+ }
+
+ if (cachedNode.getNodeId() != null) {
+
+ /*
+ * This should be the success path branch if the self-link is not set
+ */
+
+ cachedNode.changeState(NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
+ NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
+
+ }
+
+ } else {
+
+ if (cachedNode.hasResolvedSelfLink()) {
+ LOG.error(AaiUiMsgs.INVALID_RESOLVE_STATE_DURING_INIT);
+ cachedNode.changeState(NodeProcessingState.ERROR,
+ NodeProcessingAction.UNEXPECTED_STATE_TRANSITION);
+ } else {
+ cachedNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
+ NodeProcessingAction.SELF_LINK_SET);
+ }
+ }
+ }
+
+ /**
+ * Process skeleton node.
+ *
+ * @param skeletonNode the skeleton node
+ * @param queryParams the query params
+ */
+ private void processSearchableEntity(SearchableEntity searchTargetEntity, QueryParams queryParams) {
+
+ if (searchTargetEntity == null) {
+ return;
+ }
+
+ if (searchTargetEntity.getId() == null) {
+ LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_SKELETON_NODE, "Failed to process skeleton"
+ + " node because nodeId is null for node, " + searchTargetEntity.getLink());
+ return;
+ }
+
+ ActiveInventoryNode newNode = new ActiveInventoryNode(this.visualizationConfigs, oxmEntityLookup);
+
+ newNode.setNodeId(searchTargetEntity.getId());
+ newNode.setEntityType(searchTargetEntity.getEntityType());
+ newNode.setPrimaryKeyName(getEntityTypePrimaryKeyName(searchTargetEntity.getEntityType()));
+ newNode.setPrimaryKeyValue(searchTargetEntity.getEntityPrimaryKeyValue());
+
+ if (newNode.getEntityType() != null && newNode.getPrimaryKeyName() != null
+ && newNode.getPrimaryKeyValue() != null) {
+ newNode.addQueryParam(
+ newNode.getEntityType() + "." + newNode.getPrimaryKeyName() + ":" + newNode.getPrimaryKeyValue());
+ }
+ /*
+ * This code may need some explanation. In any graph there will be a single root node. The root
+ * node is really the center of the universe, and for now, we are tagging the search target as
+ * the root node. Everything else in the visualization of the graph will be centered around this
+ * node as the focal point of interest.
+ *
+ * Due to it's special nature, there will only ever be one root node, and it's node depth will
+ * always be equal to zero.
+ */
+
+ if (queryParams.getSearchTargetNodeId().equals(newNode.getNodeId())) {
+ newNode.setNodeDepth(0);
+ newNode.setRootNode(true);
+ LOG.info(AaiUiMsgs.ROOT_NODE_DISCOVERED, queryParams.getSearchTargetNodeId());
+ }
+
+ newNode.setSelfLink(searchTargetEntity.getLink());
+
+ nodeCache.putIfAbsent(newNode.getNodeId(), newNode);
+ }
+
+ /**
+ * Checks for out standing work.
+ *
+ * @return true, if successful
+ */
+ private boolean hasOutStandingWork() {
+
+ int numNodesWithPendingStates = 0;
+
+ /*
+ * Force an evaluation of node depths before determining if we should limit state-based
+ * traversal or processing.
+ */
+
+ evaluateNodeDepths();
+
+ for (ActiveInventoryNode n : nodeCache.values()) {
+
+ switch (n.getState()) {
+
+ case READY:
+ case ERROR: {
+ // do nothing, these are our normal
+ // exit states
+ break;
+ }
+
+ case NEIGHBORS_UNPROCESSED: {
+
+ if (n.getNodeDepth() < this.visualizationConfigs.getMaxSelfLinkTraversalDepth()) {
+ /*
+ * Only process our neighbors relationships if our current depth is less than the max
+ * depth
+ */
+ numNodesWithPendingStates++;
+ }
+
+ break;
+ }
+
+ default: {
+
+ /*
+ * for all other states, there is work to be done
+ */
+ numNodesWithPendingStates++;
+ }
+
+ }
+
+ }
+
+ LOG.debug(AaiUiMsgs.OUTSTANDING_WORK_PENDING_NODES, String.valueOf(numNodesWithPendingStates));
+
+ return (numNodesWithPendingStates > 0);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.onap.aai.sparky.viewandinspect.services.VisualizationContext#processSelfLinks(org.onap.aai.sparky.sync.entity.SearchableEntity, org.onap.aai.sparky.viewandinspect.entity.QueryParams)
+ */
+ @Override
+ public void processSelfLinks(SearchableEntity searchtargetEntity, QueryParams queryParams) {
+
+ try {
+
+ if (searchtargetEntity == null) {
+ LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, contextIdStr + " - Failed to"
+ + " processSelfLinks, searchtargetEntity is null");
+ return;
+ }
+
+ processSearchableEntity(searchtargetEntity, queryParams);
+
+ long startTimeInMs = System.currentTimeMillis();
+
+ /*
+ * wait until all transactions are complete or guard-timer expires.
+ */
+
+ long totalResolveTime = 0;
+ boolean hasOutstandingWork = hasOutStandingWork();
+ boolean outstandingWorkGuardTimerFired = false;
+ long maxGuardTimeInMs = 5000;
+ long guardTimeInMs = 0;
+ boolean foundRootNode = false;
+
+
+ /*
+ * TODO: Put a count-down-latch in place of the while loop, but if we do that then
+ * we'll need to decouple the visualization processing from the main thread so it can continue to process while
+ * the main thread is waiting on for count-down-latch gate to open. This may also be easier once we move to the
+ * VisualizationService + VisualizationContext ideas.
+ */
+
+
+ while (hasOutstandingWork || !outstandingWorkGuardTimerFired) {
+
+ if (!foundRootNode) {
+ foundRootNode = findAndMarkRootNode(queryParams);
+ }
+
+ processCurrentNodeStates(foundRootNode);
+
+ verifyOutboundNeighbors();
+
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException exc) {
+ LOG.error(AaiUiMsgs.PROCESSING_LOOP_INTERUPTED, exc.getMessage());
+ return;
+ }
+
+ totalResolveTime = (System.currentTimeMillis() - startTimeInMs);
+
+ if (!hasOutstandingWork) {
+
+ guardTimeInMs += 500;
+
+ if (guardTimeInMs > maxGuardTimeInMs) {
+ outstandingWorkGuardTimerFired = true;
+ }
+ } else {
+ guardTimeInMs = 0;
+ }
+
+ hasOutstandingWork = hasOutStandingWork();
+
+ }
+
+ long opTime = System.currentTimeMillis() - startTimeInMs;
+
+ LOG.info(AaiUiMsgs.ALL_TRANSACTIONS_RESOLVED, String.valueOf(totalResolveTime),
+ String.valueOf(totalLinksRetrieved.get()), String.valueOf(opTime));
+
+ } catch (Exception exc) {
+ LOG.error(AaiUiMsgs.VISUALIZATION_OUTPUT_ERROR, exc.getMessage());
+ }
+
+ }
+
+ /**
+ * Verify outbound neighbors.
+ */
+ private void verifyOutboundNeighbors() {
+
+ for (ActiveInventoryNode srcNode : nodeCache.values()) {
+
+ for (String targetNodeId : srcNode.getOutboundNeighbors()) {
+
+ ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
+
+ if (targetNode != null && srcNode.getNodeId() != null) {
+
+ targetNode.addInboundNeighbor(srcNode.getNodeId());
+
+ if (this.visualizationConfigs.makeAllNeighborsBidirectional()) {
+ targetNode.addOutboundNeighbor(srcNode.getNodeId());
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ /**
+ * Evaluate node depths.
+ */
+ private void evaluateNodeDepths() {
+
+ int numChanged = -1;
+ int numAttempts = 0;
+
+ while (numChanged != 0) {
+
+ numChanged = 0;
+ numAttempts++;
+
+ for (ActiveInventoryNode srcNode : nodeCache.values()) {
+
+ if (srcNode.getState() == NodeProcessingState.INIT) {
+
+ /*
+ * this maybe the only state that we don't want to to process the node depth on, because
+ * typically it won't have any valid fields set, and it may remain in a partial state
+ * until we have processed the self-link.
+ */
+
+ continue;
+
+ }
+
+ for (String targetNodeId : srcNode.getOutboundNeighbors()) {
+ ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
+
+ if (targetNode != null) {
+
+ if (targetNode.changeDepth(srcNode.getNodeDepth() + 1)) {
+ numChanged++;
+ }
+ }
+ }
+
+ for (String targetNodeId : srcNode.getInboundNeighbors()) {
+ ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
+
+ if (targetNode != null) {
+
+ if (targetNode.changeDepth(srcNode.getNodeDepth() + 1)) {
+ numChanged++;
+ }
+ }
+ }
+ }
+
+ if (numAttempts >= MAX_DEPTH_EVALUATION_ATTEMPTS) {
+ LOG.info(AaiUiMsgs.MAX_EVALUATION_ATTEMPTS_EXCEEDED);
+ return;
+ }
+
+ }
+
+ if (LOG.isDebugEnabled()) {
+ if (numAttempts > 0) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "Evaluate node depths completed in " + numAttempts + " attempts");
+ } else {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "Evaluate node depths completed in 0 attempts because all nodes at correct depth");
+ }
+ }
+
+ }
+
+
+ /**
+ * Gets the entity type primary key name.
+ *
+ * @param entityType the entity type
+ * @return the entity type primary key name
+ */
+
+
+ private String getEntityTypePrimaryKeyName(String entityType) {
+
+ if (entityType == null) {
+ LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE, "node primary key"
+ + " name because entity type is null");
+ return null;
+ }
+
+ OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(entityType);
+
+ if (descriptor == null) {
+ LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE, "oxm entity"
+ + " descriptor for entityType = " + entityType);
+ return null;
+ }
+
+ List<String> pkeyNames = descriptor.getPrimaryKeyAttributeNames();
+
+ if (pkeyNames == null || pkeyNames.size() == 0) {
+ LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE, "node primary"
+ + " key because descriptor primary key names is empty");
+ return null;
+ }
+
+ return NodeUtils.concatArray(pkeyNames, "/");
+
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java b/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java
new file mode 100644
index 0000000..eb6f8f3
--- /dev/null
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java
@@ -0,0 +1,366 @@
+/**
+ * ============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.services;
+
+import java.io.IOException;
+import java.security.SecureRandom;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+
+import javax.servlet.ServletException;
+
+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.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.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.SearchableEntity;
+import org.onap.aai.sparky.util.NodeUtils;
+import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
+import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
+import org.onap.aai.sparky.viewandinspect.entity.D3VisualizationOutput;
+import org.onap.aai.sparky.viewandinspect.entity.GraphMeta;
+import org.onap.aai.sparky.viewandinspect.entity.QueryParams;
+import org.onap.aai.sparky.viewandinspect.entity.QueryRequest;
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class BaseVisualizationService implements VisualizationService {
+
+ private static final Logger LOG =
+ LoggerFactory.getInstance().getLogger(BaseVisualizationService.class);
+
+ private ObjectMapper mapper = new ObjectMapper();
+
+ private final ActiveInventoryAdapter aaiAdapter;
+ private final ElasticSearchAdapter esAdapter;
+ private final ExecutorService aaiExecutorService;
+
+ private ConcurrentHashMap<Long, VisualizationContext> contextMap;
+ private final SecureRandom secureRandom;
+
+ private VisualizationConfigs visualizationConfigs;
+ private ElasticSearchEndpointConfig endpointEConfig;
+ private ElasticSearchSchemaConfig schemaEConfig;
+ private OxmEntityLookup oxmEntityLookup;
+
+ public BaseVisualizationService(OxmModelLoader loader,VisualizationConfigs visualizationConfigs,
+ ActiveInventoryAdapter aaiAdapter,ElasticSearchAdapter esAdapter,
+ ElasticSearchEndpointConfig endpointConfig, ElasticSearchSchemaConfig schemaConfig, int numActiveInventoryWorkers,
+ OxmEntityLookup oxmEntityLookup) throws Exception {
+
+ this.visualizationConfigs = visualizationConfigs;
+ this.endpointEConfig = endpointConfig;
+ this.schemaEConfig = schemaConfig;
+ this.oxmEntityLookup = oxmEntityLookup;
+
+ secureRandom = new SecureRandom();
+
+ /*
+ * Fix constructor with properly wired in properties
+ */
+
+ this.aaiAdapter = aaiAdapter;
+ this.esAdapter = esAdapter;
+
+ this.mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ this.contextMap = new ConcurrentHashMap<Long, VisualizationContext>();
+
+ this.aaiExecutorService = NodeUtils.createNamedExecutor("SLNC-WORKER",
+ numActiveInventoryWorkers, LOG);
+
+ }
+
+ /**
+ * Analyze query request body.
+ *
+ * @param queryRequestJson the query request json
+ * @return the query request
+ */
+
+ public QueryRequest analyzeQueryRequestBody(String queryRequestJson) {
+
+
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "analyzeQueryRequestBody()," + " queryRequestJson = " + queryRequestJson);
+
+ ObjectMapper nonEmptyMapper = new ObjectMapper();
+ nonEmptyMapper.setSerializationInclusion(Include.NON_EMPTY);
+
+ QueryRequest queryBody = null;
+
+ try {
+ queryBody = nonEmptyMapper.readValue(queryRequestJson, QueryRequest.class);
+ } catch (Exception exc) {
+ LOG.error(AaiUiMsgs.EXCEPTION_CAUGHT, "Analyzing query request body.",
+ exc.getLocalizedMessage());
+ }
+
+ return queryBody;
+
+ }
+
+ /**
+ * Log optime.
+ *
+ * @param method the method
+ * @param opStartTimeInMs the op start time in ms
+ */
+ private void logOptime(String method, long opStartTimeInMs) {
+ LOG.info(AaiUiMsgs.OPERATION_TIME, method,
+ String.valueOf(System.currentTimeMillis() - opStartTimeInMs));
+ }
+
+ private SearchableEntity extractSearchableEntityFromElasticEntity(OperationResult operationResult) {
+ if (operationResult == null || !operationResult.wasSuccessful()) {
+ // error, return empty collection
+ return null;
+ }
+
+ SearchableEntity sourceEntity = null;
+ if (operationResult.wasSuccessful()) {
+
+ try {
+ JsonNode elasticValue = mapper.readValue(operationResult.getResult(), JsonNode.class);
+
+ if (elasticValue != null) {
+ JsonNode sourceField = elasticValue.get("_source");
+
+ if (sourceField != null) {
+ sourceEntity = new SearchableEntity();
+
+ String entityType = NodeUtils.extractFieldValueFromObject(sourceField, "entityType");
+ sourceEntity.setEntityType(entityType);
+ String entityPrimaryKeyValue = NodeUtils.extractFieldValueFromObject(sourceField, "entityPrimaryKeyValue");
+ sourceEntity.setEntityPrimaryKeyValue(entityPrimaryKeyValue);
+ String link = NodeUtils.extractFieldValueFromObject(sourceField, "link");
+ sourceEntity.setLink(link);
+ String lastmodTimestamp = NodeUtils.extractFieldValueFromObject(sourceField, "lastmodTimestamp");
+ sourceEntity.setEntityTimeStamp(lastmodTimestamp);
+ }
+ }
+ } catch (IOException ioe) {
+ LOG.error(AaiUiMsgs.JSON_CONVERSION_ERROR, "a json node ", ioe.getLocalizedMessage());
+ }
+ }
+ return sourceEntity;
+ }
+
+ /**
+ * Builds the visualization using generic query.
+ *
+ * @param queryRequest the query request
+ * @return the operation result
+ */
+ public OperationResult buildVisualizationUsingGenericQuery(QueryRequest queryRequest) {
+
+ OperationResult returnValue = new OperationResult();
+ OperationResult dataCollectionResult = null;
+ QueryParams queryParams = null;
+ SearchableEntity sourceEntity = null;
+
+ try {
+
+ /*
+ * 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());
+ sourceEntity = extractSearchableEntityFromElasticEntity(dataCollectionResult);
+
+ if (sourceEntity != null) {
+ sourceEntity.generateId();
+ }
+
+ queryParams = new QueryParams();
+ queryParams.setSearchTargetNodeId(queryRequest.getHashId());
+
+ } catch (Exception e1) {
+ LOG.error(AaiUiMsgs.FAILED_TO_GET_NODES_QUERY_RESULT, e1.getLocalizedMessage());
+ dataCollectionResult = new OperationResult(500, "Failed to get nodes-query result from AAI");
+ }
+
+ if (dataCollectionResult.getResultCode() == 200) {
+
+ String d3OutputJsonOutput = null;
+
+ try {
+
+ d3OutputJsonOutput = getVisualizationOutputBasedonGenericQuery( sourceEntity, queryParams, queryRequest);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "Generated D3" + " output as json = " + d3OutputJsonOutput);
+ }
+
+ if (d3OutputJsonOutput != null) {
+ returnValue.setResultCode(200);
+ returnValue.setResult(d3OutputJsonOutput);
+ } else {
+ returnValue.setResult(500, "Failed to generate D3 graph visualization");
+ }
+
+ } catch (Exception exc) {
+ returnValue.setResult(500,
+ "Failed to generate D3 graph visualization, due to a servlet exception.");
+ LOG.error(AaiUiMsgs.ERROR_D3_GRAPH_VISUALIZATION, exc.getLocalizedMessage());
+ }
+ } else {
+ returnValue.setResult(dataCollectionResult.getResultCode(), dataCollectionResult.getResult());
+ }
+
+ return returnValue;
+
+ }
+
+
+ /**
+ * Gets the visualization output basedon generic query.
+ *
+ * @param searchtargetEntity entity that will be used to start visualization flow
+ * @param queryParams the query params
+ * @return the visualization output basedon generic query
+ * @throws ServletException the servlet exception
+ * @throws
+ */
+ private String getVisualizationOutputBasedonGenericQuery(SearchableEntity searchtargetEntity,
+ QueryParams queryParams, QueryRequest request) throws ServletException {
+
+ long opStartTimeInMs = System.currentTimeMillis();
+
+ VisualizationTransformer transformer = null;
+ try {
+ transformer = new VisualizationTransformer(visualizationConfigs);
+ } catch (Exception exc) {
+ throw new ServletException(
+ "Failed to create VisualizationTransformer instance because of execption", exc);
+ }
+
+ VisualizationContext visContext = null;
+ long contextId = secureRandom.nextLong();
+ try {
+ visContext = new BaseVisualizationContext(contextId, this.aaiAdapter, aaiExecutorService,
+ this.visualizationConfigs, oxmEntityLookup);
+ contextMap.putIfAbsent(contextId, visContext);
+ } catch (Exception e1) {
+ LOG.error(AaiUiMsgs.EXCEPTION_CAUGHT,
+ "While building Visualization Context, " + e1.getLocalizedMessage());
+ throw new ServletException(e1);
+ }
+
+ String jsonResponse = null;
+
+ long startTimeInMs = System.currentTimeMillis();
+
+ visContext.processSelfLinks(searchtargetEntity, queryParams);
+ contextMap.remove(contextId);
+
+ logOptime("collectSelfLinkNodes()", startTimeInMs);
+
+ /*
+ * Flatten the graphs into a set of Graph and Link nodes. In this method I want the node graph
+ * resulting from the edge-tag-query to be represented first, and then we'll layer in
+ * relationship data.
+ */
+ long overlayDataStartTimeInMs = System.currentTimeMillis();
+
+ Map<String, ActiveInventoryNode> cachedNodeMap = visContext.getNodeCache();
+
+ if (LOG.isDebugEnabled()) {
+
+ StringBuilder sb = new StringBuilder(128);
+
+ sb.append("\nCached Node Map:\n");
+ for (String k : cachedNodeMap.keySet()) {
+ sb.append("\n----");
+ sb.append("\n").append(cachedNodeMap.get(k).dumpNodeTree(true));
+ }
+
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC, sb.toString());
+ }
+
+ transformer.buildFlatNodeArrayFromGraphCollection(cachedNodeMap);
+ transformer.buildLinksFromGraphCollection(cachedNodeMap);
+
+ /*
+ * - Apply configuration-driven styling
+ * - Build the final transformation response object
+ * - Use information we have to populate the GraphMeta object
+ */
+
+ transformer.addSearchTargetAttributesToRootNode();
+
+ GraphMeta graphMeta = new GraphMeta();
+
+ D3VisualizationOutput output = null;
+ try {
+ output = transformer
+ .generateVisualizationOutput((System.currentTimeMillis() - opStartTimeInMs), graphMeta);
+ } catch (JsonProcessingException exc) {
+ throw new ServletException("Caught an exception while generation visualization output", exc);
+ } catch (IOException exc) {
+ LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST, exc.getLocalizedMessage());
+ }
+
+ output.setInlineMessage(visContext.getInlineMessage());
+ output.getGraphMeta().setNumLinkResolveFailed(visContext.getNumFailedLinkResolve());
+ output.getGraphMeta().setNumLinksResolvedSuccessfullyFromCache(
+ visContext.getNumSuccessfulLinkResolveFromCache());
+ output.getGraphMeta().setNumLinksResolvedSuccessfullyFromServer(
+ visContext.getNumSuccessfulLinkResolveFromFromServer());
+
+ try {
+ jsonResponse = transformer.convertVisualizationOutputToJson(output);
+ } catch (JsonProcessingException jpe) {
+ throw new ServletException(
+ "Caught an exception while converting visualization output to json", jpe);
+ }
+
+ logOptime("[build flat node array, add relationship data, search target,"
+ + " color scheme, and generate visualization output]", overlayDataStartTimeInMs);
+
+ logOptime("doFilter()", opStartTimeInMs);
+
+ return jsonResponse;
+
+ }
+
+ public void shutdown() {
+ aaiExecutorService.shutdown();
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContext.java b/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContext.java
index b2ed4a4..cf0ef28 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContext.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContext.java
@@ -22,1411 +22,15 @@
*/
package org.onap.aai.sparky.viewandinspect.services;
-import static java.util.concurrent.CompletableFuture.supplyAsync;
-
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.http.client.utils.URIBuilder;
-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.config.oxm.OxmEntityDescriptor;
-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.aai.config.ActiveInventoryConfig;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.sync.entity.SearchableEntity;
-import org.onap.aai.sparky.util.NodeUtils;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
-import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
import org.onap.aai.sparky.viewandinspect.entity.InlineMessage;
-import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction;
import org.onap.aai.sparky.viewandinspect.entity.QueryParams;
-import org.onap.aai.sparky.viewandinspect.entity.Relationship;
-import org.onap.aai.sparky.viewandinspect.entity.RelationshipData;
-import org.onap.aai.sparky.viewandinspect.entity.RelationshipList;
-import org.onap.aai.sparky.viewandinspect.entity.SelfLinkDeterminationTransaction;
-import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingAction;
-import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingState;
-import org.onap.aai.sparky.viewandinspect.task.PerformNodeSelfLinkProcessingTask;
-import org.onap.aai.sparky.viewandinspect.task.PerformSelfLinkDeterminationTask;
-
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
-
-/**
- * The Class SelfLinkNodeCollector.
- */
-public class VisualizationContext {
-
- private static final int MAX_DEPTH_EVALUATION_ATTEMPTS = 100;
- private static final String DEPTH_ALL_MODIFIER = "?depth=all";
- private static final String NODES_ONLY_MODIFIER = "?nodes-only";
- private static final String SERVICE_INSTANCE = "service-instance";
-
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(VisualizationContext.class);
- private final ActiveInventoryAdapter aaiAdapter;
-
- private int maxSelfLinkTraversalDepth;
- private AtomicInteger numLinksDiscovered;
- private AtomicInteger numSuccessfulLinkResolveFromCache;
- private AtomicInteger numSuccessfulLinkResolveFromFromServer;
- private AtomicInteger numFailedLinkResolve;
- private AtomicInteger nodeIntegrityWorkOnHand;
- private AtomicInteger aaiWorkOnHand;
-
- private ActiveInventoryConfig aaiConfig;
- private VisualizationConfigs visualizationConfigs;
- private List<String> shallowEntities;
-
- private AtomicInteger totalLinksRetrieved;
-
- private final long contextId;
- private final String contextIdStr;
-
- private OxmModelLoader loader;
- private ObjectMapper mapper;
- private InlineMessage inlineMessage = null;
-
- private ExecutorService tabularExecutorService;
- private ExecutorService aaiExecutorService;
-
- /*
- * The node cache is intended to be a flat structure indexed by a primary key to avoid needlessly
- * re-requesting the same self-links over-and-over again, to speed up the overall render time and
- * more importantly to reduce the network cost of determining information we already have.
- */
- private ConcurrentHashMap<String, ActiveInventoryNode> nodeCache;
-
- /**
- * Instantiates a new self link node collector.
- *
- * @param loader the loader
- * @throws Exception the exception
- */
- public VisualizationContext(long contextId, ActiveInventoryAdapter aaiAdapter,
- ExecutorService tabularExecutorService, ExecutorService aaiExecutorService,
- VisualizationConfigs visualizationConfigs) throws Exception {
-
- this.contextId = contextId;
- this.contextIdStr = "[Context-Id=" + contextId + "]";
- this.aaiAdapter = aaiAdapter;
- this.tabularExecutorService = tabularExecutorService;
- this.aaiExecutorService = aaiExecutorService;
- this.visualizationConfigs = visualizationConfigs;
-
- this.nodeCache = new ConcurrentHashMap<String, ActiveInventoryNode>();
- this.numLinksDiscovered = new AtomicInteger(0);
- this.totalLinksRetrieved = new AtomicInteger(0);
- this.numSuccessfulLinkResolveFromCache = new AtomicInteger(0);
- this.numSuccessfulLinkResolveFromFromServer = new AtomicInteger(0);
- this.numFailedLinkResolve = new AtomicInteger(0);
- this.nodeIntegrityWorkOnHand = new AtomicInteger(0);
- this.aaiWorkOnHand = new AtomicInteger(0);
-
- this.aaiConfig = ActiveInventoryConfig.getConfig();
- this.shallowEntities = aaiConfig.getAaiRestConfig().getShallowEntities();
-
- this.maxSelfLinkTraversalDepth = this.visualizationConfigs.getMaxSelfLinkTraversalDepth();
-
- this.mapper = new ObjectMapper();
- mapper.setSerializationInclusion(Include.NON_EMPTY);
- mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.KebabCaseStrategy());
- }
-
- public long getContextId() {
- return contextId;
- }
-
- /**
- * A utility method for extracting all entity-type primary key values from a provided self-link
- * and return a set of generic-query API keys.
- *
- * @param parentEntityType
- * @param link
- * @return a list of key values that can be used for this entity with the AAI generic-query API
- */
- protected List<String> extractQueryParamsFromSelfLink(String link) {
-
- List<String> queryParams = new ArrayList<String>();
-
- if (link == null) {
- LOG.error(AaiUiMsgs.QUERY_PARAM_EXTRACTION_ERROR, "self link is null");
- return queryParams;
- }
-
- Map<String, OxmEntityDescriptor> entityDescriptors =
- OxmEntityLookup.getInstance().getEntityDescriptors();
-
- try {
-
- URIBuilder urlBuilder = new URIBuilder(link);
- String urlPath = urlBuilder.getPath();
-
- OxmEntityDescriptor descriptor = null;
- String[] urlPathElements = urlPath.split("/");
- List<String> primaryKeyNames = null;
- int index = 0;
- String entityType = null;
-
- while (index < urlPathElements.length) {
-
- descriptor = entityDescriptors.get(urlPathElements[index]);
-
- if (descriptor != null) {
- entityType = urlPathElements[index];
- primaryKeyNames = descriptor.getPrimaryKeyAttributeNames();
-
- /*
- * Make sure from what ever index we matched the parent entity-type on that we can extract
- * additional path elements for the primary key values.
- */
-
- if (index + primaryKeyNames.size() < urlPathElements.length) {
-
- for (String primaryKeyName : primaryKeyNames) {
- index++;
- queryParams.add(entityType + "." + primaryKeyName + ":" + urlPathElements[index]);
- }
- } else {
- LOG.error(AaiUiMsgs.QUERY_PARAM_EXTRACTION_ERROR,
- "Could not extract query parametrs for entity-type = '" + entityType
- + "' from self-link = " + link);
- }
- }
-
- index++;
- }
-
- } catch (URISyntaxException exc) {
-
- LOG.error(AaiUiMsgs.QUERY_PARAM_EXTRACTION_ERROR,
- "Error extracting query parameters from self-link = " + link + ". Error = "
- + exc.getMessage());
- }
-
- return queryParams;
-
- }
-
- /**
- * Decode complex attribute group.
- *
- * @param ain the ain
- * @param attributeGroup the attribute group
- * @return boolean indicating whether operation was successful (true), / failure(false).
- */
- public boolean decodeComplexAttributeGroup(ActiveInventoryNode ain, JsonNode attributeGroup) {
-
- try {
-
- Iterator<Entry<String, JsonNode>> entityArrays = attributeGroup.fields();
- Entry<String, JsonNode> entityArray = null;
-
- if (entityArrays == null) {
- LOG.error(AaiUiMsgs.ATTRIBUTE_GROUP_FAILURE, attributeGroup.toString());
- ain.changeState(NodeProcessingState.ERROR, NodeProcessingAction.NEIGHBORS_PROCESSED_ERROR);
- return false;
- }
-
- while (entityArrays.hasNext()) {
-
- entityArray = entityArrays.next();
-
- String entityType = entityArray.getKey();
- JsonNode entityArrayObject = entityArray.getValue();
-
- if (entityArrayObject.isArray()) {
-
- Iterator<JsonNode> entityCollection = entityArrayObject.elements();
- JsonNode entity = null;
- while (entityCollection.hasNext()) {
- entity = entityCollection.next();
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "decodeComplexAttributeGroup()," + " entity = " + entity.toString());
- }
-
- /**
- * Here's what we are going to do:
- *
- * <li>In the ActiveInventoryNode, on construction maintain a collection of queryParams
- * that is added to for the purpose of discovering parent->child hierarchies.
- *
- * <li>When we hit this block of the code then we'll use the queryParams to feed the
- * generic query to resolve the self-link asynchronously.
- *
- * <li>Upon successful link determination, then and only then will we create a new node
- * in the nodeCache and process the child
- *
- */
-
- ActiveInventoryNode newNode = new ActiveInventoryNode(this.visualizationConfigs);
- newNode.setEntityType(entityType);
-
- /*
- * This is partially a lie because we actually don't have a self-link for complex nodes
- * discovered in this way.
- */
- newNode.setSelfLinkProcessed(true);
- newNode.changeState(NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
- NodeProcessingAction.COMPLEX_ATTRIBUTE_GROUP_PARSE_OK);
-
- /*
- * copy parent query params into new child
- */
-
- if (SERVICE_INSTANCE.equals(entityType)) {
-
- /*
- * 1707 AAI has an issue being tracked with AAI-8932 where the generic-query cannot be
- * resolved if all the service-instance path keys are provided. The query only works
- * if only the service-instance key and valude are passed due to a historical reason.
- * A fix is being worked on for 1707, and when it becomes available we can revert this
- * small change.
- */
-
- newNode.clearQueryParams();
-
- } else {
-
- /*
- * For all other entity-types we want to copy the parent query parameters into the new
- * node query parameters.
- */
-
- for (String queryParam : ain.getQueryParams()) {
- newNode.addQueryParam(queryParam);
- }
-
- }
-
-
- if (!addComplexGroupToNode(newNode, entity)) {
- LOG.error(AaiUiMsgs.ATTRIBUTE_GROUP_FAILURE,
- "Failed to add child to parent for child = " + entity.toString());
- }
-
- if (!addNodeQueryParams(newNode)) {
- LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE_NODE_ID,
- "Error determining node id and key for node = " + newNode.dumpNodeTree(true)
- + " skipping relationship processing");
- newNode.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.NODE_IDENTITY_ERROR);
- return false;
- } else {
-
- newNode.changeState(NodeProcessingState.NEIGHBORS_UNPROCESSED,
- NodeProcessingAction.COMPLEX_ATTRIBUTE_GROUP_PARSE_OK);
-
- }
-
-
- /*
- * Order matters for the query params. We need to set the parent ones before the child
- * node
- */
-
- String selfLinkQuery =
- aaiAdapter.getGenericQueryForSelfLink(entityType, newNode.getQueryParams());
-
- /**
- * <li>get the self-link
- * <li>add it to the new node
- * <li>generate node id
- * <li>add node to node cache
- * <li>add node id to parent outbound links list
- * <li>process node children (should be automatic) (but don't query and resolve
- * self-link as we already have all the data)
- */
-
- SelfLinkDeterminationTransaction txn = new SelfLinkDeterminationTransaction();
-
- txn.setQueryString(selfLinkQuery);
- txn.setNewNode(newNode);
- txn.setParentNodeId(ain.getNodeId());
- aaiWorkOnHand.incrementAndGet();
- supplyAsync(new PerformSelfLinkDeterminationTask(txn, null, aaiAdapter),
- aaiExecutorService).whenComplete((nodeTxn, error) -> {
- aaiWorkOnHand.decrementAndGet();
- if (error != null) {
- LOG.error(AaiUiMsgs.SELF_LINK_DETERMINATION_FAILED_GENERIC, selfLinkQuery);
- } else {
-
- OperationResult opResult = nodeTxn.getOpResult();
-
- ActiveInventoryNode newChildNode = txn.getNewNode();
-
- if (opResult != null && opResult.wasSuccessful()) {
-
- if (!opResult.wasSuccessful()) {
- numFailedLinkResolve.incrementAndGet();
- }
-
- if (opResult.isFromCache()) {
- numSuccessfulLinkResolveFromCache.incrementAndGet();
- } else {
- numSuccessfulLinkResolveFromFromServer.incrementAndGet();
- }
-
- /*
- * extract the self-link from the operational result.
- */
-
- Collection<JsonNode> entityLinks = new ArrayList<JsonNode>();
- JsonNode genericQueryResult = null;
- try {
- genericQueryResult =
- NodeUtils.convertJsonStrToJsonNode(nodeTxn.getOpResult().getResult());
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.JSON_CONVERSION_ERROR, JsonNode.class.toString(),
- exc.getMessage());
- }
-
- NodeUtils.extractObjectsByKey(genericQueryResult, "resource-link",
- entityLinks);
-
- String selfLink = null;
-
- if (entityLinks.size() != 1) {
-
- LOG.error(AaiUiMsgs.SELF_LINK_DETERMINATION_FAILED_UNEXPECTED_LINKS,
- String.valueOf(entityLinks.size()));
-
- } else {
- selfLink = ((JsonNode) entityLinks.toArray()[0]).asText();
- selfLink = ActiveInventoryConfig.extractResourcePath(selfLink);
-
- newChildNode.setSelfLink(selfLink);
- newChildNode.setNodeId(NodeUtils.generateUniqueShaDigest(selfLink));
-
- String uri = NodeUtils.calculateEditAttributeUri(selfLink);
- if (uri != null) {
- newChildNode.addProperty(TierSupportUiConstants.URI_ATTR_NAME, uri);
- }
-
- ActiveInventoryNode parent = nodeCache.get(txn.getParentNodeId());
-
- if (parent != null) {
- parent.addOutboundNeighbor(newChildNode.getNodeId());
- newChildNode.addInboundNeighbor(parent.getNodeId());
- }
-
- newChildNode.setSelfLinkPendingResolve(false);
- newChildNode.setSelfLinkProcessed(true);
- newChildNode.changeState(NodeProcessingState.NEIGHBORS_UNPROCESSED,
- NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
-
- nodeCache.putIfAbsent(newChildNode.getNodeId(), newChildNode);
-
- }
-
- } else {
- LOG.error(AaiUiMsgs.SELF_LINK_RETRIEVAL_FAILED, txn.getQueryString(),
- String.valueOf(nodeTxn.getOpResult().getResultCode()),
- nodeTxn.getOpResult().getResult());
- newChildNode.setSelflinkRetrievalFailure(true);
- newChildNode.setSelfLinkProcessed(true);
- newChildNode.setSelfLinkPendingResolve(false);
-
- newChildNode.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.SELF_LINK_DETERMINATION_ERROR);
-
- }
-
- }
-
- });
-
- }
-
- return true;
-
- } else {
- LOG.error(AaiUiMsgs.UNHANDLED_OBJ_TYPE_FOR_ENTITY_TYPE, entityType);
- }
-
- }
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
- "Exception caught while" + " decoding complex attribute group - " + exc.getMessage());
- }
-
- return false;
-
- }
-
- /**
- * Process self link response.
- *
- * @param nodeId the node id
- */
- private void processSelfLinkResponse(String nodeId) {
- if (nodeId == null) {
- LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
- "Cannot process self link" + " response because nodeId is null");
- return;
- }
-
- ActiveInventoryNode ain = nodeCache.get(nodeId);
-
- if (ain == null) {
- LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
- "Cannot process self link response" + " because can't find node for id = " + nodeId);
- return;
- }
-
- JsonNode jsonNode = null;
-
- try {
- jsonNode = mapper.readValue(ain.getOpResult().getResult(), JsonNode.class);
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR, "Failed to marshal json"
- + " response str into JsonNode with error, " + exc.getLocalizedMessage());
- ain.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
- return;
- }
-
- if (jsonNode == null) {
- LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR,
- "Failed to parse json node str." + " Parse resulted a null value.");
- ain.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
- return;
- }
-
- Iterator<Entry<String, JsonNode>> fieldNames = jsonNode.fields();
- Entry<String, JsonNode> field = null;
-
- RelationshipList relationshipList = null;
-
- while (fieldNames.hasNext()) {
-
- field = fieldNames.next();
- String fieldName = field.getKey();
-
- if ("relationship-list".equals(fieldName)) {
-
- try {
- relationshipList = mapper.readValue(field.getValue().toString(), RelationshipList.class);
-
- if (relationshipList != null) {
- ain.addRelationshipList(relationshipList);
- }
-
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR, "Failed to parse relationship-list"
- + " attribute. Parse resulted in error, " + exc.getLocalizedMessage());
- ain.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
- return;
- }
-
- } else {
-
- JsonNode nodeValue = field.getValue();
-
- if (nodeValue != null && nodeValue.isValueNode()) {
-
- if (OxmEntityLookup.getInstance().getEntityDescriptors().get(fieldName) == null) {
-
- /*
- * entity property name is not an entity, thus we can add this property name and value
- * to our property set
- */
-
- ain.addProperty(fieldName, nodeValue.asText());
-
- }
-
- } else {
-
- if (nodeValue.isArray()) {
-
- if (OxmEntityLookup.getInstance().getEntityDescriptors().get(fieldName) == null) {
-
- /*
- * entity property name is not an entity, thus we can add this property name and value
- * to our property set
- */
-
- ain.addProperty(field.getKey(), nodeValue.toString());
-
- }
-
- } else {
-
- ain.addComplexGroup(nodeValue);
-
- }
-
- }
- }
-
- }
-
- String uri = NodeUtils.calculateEditAttributeUri(ain.getSelfLink());
- if (uri != null) {
- ain.addProperty(TierSupportUiConstants.URI_ATTR_NAME, uri);
- }
-
- /*
- * We need a special behavior for intermediate entities from the REST model
- *
- * Tenants are not top level entities, and when we want to visualization their children, we need
- * to construct keys that include the parent entity query keys, the current entity type keys,
- * and the child keys. We'll always have the current entity and children, but never the parent
- * entity in the current (1707) REST data model.
- *
- * We have two possible solutions:
- *
- * 1) Try to use the custom-query approach to learn about the entity keys - this could be done,
- * but it could be very expensive for large objects. When we do the first query to get a tenant,
- * it will list all the in and out edges related to this entity, there is presently no way to
- * filter this. But the approach could be made to work and it would be somewhat data-model
- * driven, other than the fact that we have to first realize that the entity that is being
- * searched for is not top-level entity. Once we have globally unique ids for resources this
- * logic will not be needed and everything will be simpler. The only reason we are in this logic
- * at all is to be able to calculate a url for the child entities so we can hash it to generate
- * a globally unique id that can be safely used for the node.
- *
- * *2* Extract the keys from the pathed self-link. This is a bad solution and I don't like it
- * but it will be fast for all resource types, as the information is already encoded in the URI.
- * When we get to a point where we switch to a better globally unique entity identity model,
- * then a lot of the code being used to calculate an entity url to in-turn generate a
- * deterministic globally unique id will disappear.
- *
- *
- * right now we have the following:
- *
- * - cloud-regions/cloud-region/{cloud-region-id}/{cloud-owner-id}/tenants/tenant/{tenant-id}
- *
- */
-
- /*
- * For all entity types use the self-link extraction method to be consistent. Once we have a
- * globally unique identity mechanism for entities, this logic can be revisited.
- */
- ain.clearQueryParams();
- ain.addQueryParams(extractQueryParamsFromSelfLink(ain.getSelfLink()));
- ain.changeState(NodeProcessingState.NEIGHBORS_UNPROCESSED,
- NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
-
-
- }
-
- /**
- * Perform self link resolve.
- *
- * @param nodeId the node id
- */
- private void performSelfLinkResolve(String nodeId) {
-
- if (nodeId == null) {
- LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
- "Resolve of self-link" + " has been skipped because provided nodeId is null");
- return;
- }
-
- ActiveInventoryNode ain = nodeCache.get(nodeId);
-
- if (ain == null) {
- LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Failed to find node with id, " + nodeId
- + ", from node cache. Resolve self-link method has been skipped.");
- return;
- }
-
- if (!ain.isSelfLinkPendingResolve()) {
-
- ain.setSelfLinkPendingResolve(true);
-
- // kick off async self-link resolution
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "About to process node in SELF_LINK_UNPROCESSED State, link = " + ain.getSelfLink());
- }
-
- numLinksDiscovered.incrementAndGet();
-
- String depthModifier = DEPTH_ALL_MODIFIER;
-
- /*
- * If the current node is the search target, we want to see everything the node has to offer
- * from the self-link and not filter it to a single node.
- */
-
- if (shallowEntities.contains(ain.getEntityType()) && !ain.isRootNode()) {
- depthModifier = NODES_ONLY_MODIFIER;
- }
-
- NodeProcessingTransaction txn = new NodeProcessingTransaction();
- txn.setProcessingNode(ain);
- txn.setRequestParameters(depthModifier);
- aaiWorkOnHand.incrementAndGet();
- supplyAsync(new PerformNodeSelfLinkProcessingTask(txn, depthModifier, aaiAdapter, aaiConfig),
- aaiExecutorService).whenComplete((nodeTxn, error) -> {
- aaiWorkOnHand.decrementAndGet();
- if (error != null) {
-
- /*
- * an error processing the self link should probably result in the node processing
- * state shifting to ERROR
- */
-
- nodeTxn.getProcessingNode().setSelflinkRetrievalFailure(true);
-
- nodeTxn.getProcessingNode().changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.SELF_LINK_RESOLVE_ERROR);
-
- nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
-
- } else {
-
- totalLinksRetrieved.incrementAndGet();
-
- OperationResult opResult = nodeTxn.getOpResult();
-
- if (opResult != null && opResult.wasSuccessful()) {
-
- if (!opResult.wasSuccessful()) {
- numFailedLinkResolve.incrementAndGet();
- }
-
- if (opResult.isFromCache()) {
- numSuccessfulLinkResolveFromCache.incrementAndGet();
- } else {
- numSuccessfulLinkResolveFromFromServer.incrementAndGet();
- }
-
- // success path
- nodeTxn.getProcessingNode().setOpResult(opResult);
- nodeTxn.getProcessingNode().changeState(
- NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
- NodeProcessingAction.SELF_LINK_RESOLVE_OK);
-
- nodeTxn.getProcessingNode().setSelfLinkProcessed(true);
- nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
-
- } else {
- LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
- "Self Link retrieval for link," + txn.getSelfLinkWithModifiers()
- + ", failed with error code," + nodeTxn.getOpResult().getResultCode()
- + ", and message," + nodeTxn.getOpResult().getResult());
-
- nodeTxn.getProcessingNode().setSelflinkRetrievalFailure(true);
- nodeTxn.getProcessingNode().setSelfLinkProcessed(true);
-
- nodeTxn.getProcessingNode().changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.SELF_LINK_RESOLVE_ERROR);
-
- nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
-
- }
- }
-
- });
-
- }
-
- }
-
- /**
- * Process neighbors.
- *
- * @param nodeId the node id
- */
- private void processNeighbors(String nodeId) {
-
- if (nodeId == null) {
- LOG.error(AaiUiMsgs.SELF_LINK_PROCESS_NEIGHBORS_ERROR,
- "Failed to process" + " neighbors because nodeId is null.");
- return;
- }
-
- ActiveInventoryNode ain = nodeCache.get(nodeId);
-
- if (ain == null) {
- LOG.error(AaiUiMsgs.SELF_LINK_PROCESS_NEIGHBORS_ERROR, "Failed to process"
- + " neighbors because node could not be found in nodeCache with id, " + nodeId);
- return;
- }
-
- /*
- * process complex attribute and relationships
- */
-
- boolean neighborsProcessedSuccessfully = true;
-
- for (JsonNode n : ain.getComplexGroups()) {
- neighborsProcessedSuccessfully &= decodeComplexAttributeGroup(ain, n);
- }
-
- for (RelationshipList relationshipList : ain.getRelationshipLists()) {
- neighborsProcessedSuccessfully &= addSelfLinkRelationshipChildren(ain, relationshipList);
- }
-
-
- if (neighborsProcessedSuccessfully) {
- ain.changeState(NodeProcessingState.READY, NodeProcessingAction.NEIGHBORS_PROCESSED_OK);
- } else {
- ain.changeState(NodeProcessingState.ERROR, NodeProcessingAction.NEIGHBORS_PROCESSED_ERROR);
- }
-
-
- /*
- * If neighbors fail to process, there is already a call to change the state within the
- * relationship and neighbor processing functions.
- */
-
- }
-
- /**
- * Find and mark root node.
- *
- * @param queryParams the query params
- * @return true, if successful
- */
- private boolean findAndMarkRootNode(QueryParams queryParams) {
-
- for (ActiveInventoryNode cacheNode : nodeCache.values()) {
-
- if (queryParams.getSearchTargetNodeId().equals(cacheNode.getNodeId())) {
- cacheNode.setNodeDepth(0);
- cacheNode.setRootNode(true);
- LOG.info(AaiUiMsgs.ROOT_NODE_DISCOVERED, queryParams.getSearchTargetNodeId());
- return true;
- }
- }
-
- return false;
-
- }
-
- /**
- * Process current node states.
- *
- * @param rootNodeDiscovered the root node discovered
- */
- private void processCurrentNodeStates(boolean rootNodeDiscovered) {
- /*
- * Force an evaluation of node depths before determining if we should limit state-based
- * traversal or processing.
- */
- if (rootNodeDiscovered) {
- evaluateNodeDepths();
- }
-
- for (ActiveInventoryNode cacheNode : nodeCache.values()) {
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "processCurrentNodeState(), nid = "
- + cacheNode.getNodeId() + " , nodeDepth = " + cacheNode.getNodeDepth());
- }
-
- switch (cacheNode.getState()) {
-
- case INIT: {
- processInitialState(cacheNode.getNodeId());
- break;
- }
-
- case READY:
- case ERROR: {
- break;
- }
-
- case SELF_LINK_UNRESOLVED: {
- performSelfLinkResolve(cacheNode.getNodeId());
- break;
- }
-
- case SELF_LINK_RESPONSE_UNPROCESSED: {
- processSelfLinkResponse(cacheNode.getNodeId());
- break;
- }
-
- case NEIGHBORS_UNPROCESSED: {
-
- /*
- * We use the rootNodeDiscovered flag to ignore depth retrieval thresholds until the root
- * node is identified. Then the evaluative depth calculations should re-balance the graph
- * around the root node.
- */
-
- if (!rootNodeDiscovered || cacheNode.getNodeDepth() < this.visualizationConfigs
- .getMaxSelfLinkTraversalDepth()) {
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "SLNC::processCurrentNodeState() -- Node at max depth,"
- + " halting processing at current state = -- " + cacheNode.getState()
- + " nodeId = " + cacheNode.getNodeId());
- }
-
-
-
- processNeighbors(cacheNode.getNodeId());
-
- }
-
- break;
- }
- default:
- break;
-
-
-
- }
-
- }
-
- }
-
- /**
- * Adds the complex group to node.
- *
- * @param targetNode the target node
- * @param attributeGroup the attribute group
- * @return true, if successful
- */
- private boolean addComplexGroupToNode(ActiveInventoryNode targetNode, JsonNode attributeGroup) {
-
- if (attributeGroup == null) {
- targetNode.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.COMPLEX_ATTRIBUTE_GROUP_PARSE_OK);
- return false;
- }
-
- RelationshipList relationshipList = null;
-
- if (attributeGroup.isObject()) {
-
- Iterator<Entry<String, JsonNode>> fields = attributeGroup.fields();
- Entry<String, JsonNode> field = null;
- String fieldName;
- JsonNode fieldValue;
-
- while (fields.hasNext()) {
- field = fields.next();
- fieldName = field.getKey();
- fieldValue = field.getValue();
-
- if (fieldValue.isObject()) {
-
- if (fieldName.equals("relationship-list")) {
-
- try {
- relationshipList =
- mapper.readValue(field.getValue().toString(), RelationshipList.class);
-
- if (relationshipList != null) {
- targetNode.addRelationshipList(relationshipList);
- }
-
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR,
- "Failed to parse" + " relationship-list attribute. Parse resulted in error, "
- + exc.getLocalizedMessage());
- targetNode.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.COMPLEX_ATTRIBUTE_GROUP_PARSE_ERROR);
- return false;
- }
-
- } else {
- targetNode.addComplexGroup(fieldValue);
- }
-
- } else if (fieldValue.isArray()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "Unexpected array type with a key = " + fieldName);
- }
- } else if (fieldValue.isValueNode()) {
- if (OxmEntityLookup.getInstance().getEntityDescriptors().get(field.getKey()) == null) {
- /*
- * property key is not an entity type, add it to our property set.
- */
- targetNode.addProperty(field.getKey(), fieldValue.asText());
- }
-
- }
- }
-
- } else if (attributeGroup.isArray()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "Unexpected array type for attributeGroup = " + attributeGroup);
- }
- } else if (attributeGroup.isValueNode()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "Unexpected value type for attributeGroup = " + attributeGroup);
- }
- }
-
- return true;
- }
-
- public int getNumSuccessfulLinkResolveFromCache() {
- return numSuccessfulLinkResolveFromCache.get();
- }
-
- public int getNumSuccessfulLinkResolveFromFromServer() {
- return numSuccessfulLinkResolveFromFromServer.get();
- }
-
- public int getNumFailedLinkResolve() {
- return numFailedLinkResolve.get();
- }
-
- public InlineMessage getInlineMessage() {
- return inlineMessage;
- }
-
- public void setInlineMessage(InlineMessage inlineMessage) {
- this.inlineMessage = inlineMessage;
- }
-
- public void setMaxSelfLinkTraversalDepth(int depth) {
- this.maxSelfLinkTraversalDepth = depth;
- }
-
- public int getMaxSelfLinkTraversalDepth() {
- return this.maxSelfLinkTraversalDepth;
- }
-
- public ConcurrentHashMap<String, ActiveInventoryNode> getNodeCache() {
- return nodeCache;
- }
-
- /**
- * Gets the relationship primary key values.
- *
- * @param r the r
- * @param entityType the entity type
- * @param pkeyNames the pkey names
- * @return the relationship primary key values
- */
- private String getRelationshipPrimaryKeyValues(Relationship r, String entityType,
- List<String> pkeyNames) {
-
- StringBuilder sb = new StringBuilder(64);
-
- if (pkeyNames.size() > 0) {
- String primaryKey = extractKeyValueFromRelationData(r, entityType + "." + pkeyNames.get(0));
- if (primaryKey != null) {
-
- sb.append(primaryKey);
-
- } else {
- // this should be a fatal error because unless we can
- // successfully retrieve all the expected keys we'll end up
- // with a garbage node
- LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: Failed to extract" + " keyName, " + entityType
- + "." + pkeyNames.get(0) + ", from relationship data, " + r.toString());
- return null;
- }
-
- for (int i = 1; i < pkeyNames.size(); i++) {
-
- String kv = extractKeyValueFromRelationData(r, entityType + "." + pkeyNames.get(i));
- if (kv != null) {
- sb.append("/").append(kv);
- } else {
- // this should be a fatal error because unless we can
- // successfully retrieve all the expected keys we'll end up
- // with a garbage node
- LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: failed to extract keyName, " + entityType
- + "." + pkeyNames.get(i) + ", from relationship data, " + r.toString());
- return null;
- }
- }
-
- return sb.toString();
-
- }
-
- return null;
-
- }
-
- /**
- * Extract key value from relation data.
- *
- * @param r the r
- * @param keyName the key name
- * @return the string
- */
- private String extractKeyValueFromRelationData(Relationship r, String keyName) {
-
- RelationshipData[] rdList = r.getRelationshipData();
-
- for (RelationshipData relData : rdList) {
-
- if (relData.getRelationshipKey().equals(keyName)) {
- return relData.getRelationshipValue();
- }
- }
-
- return null;
- }
-
- /**
- * Determine node id and key.
- *
- * @param ain the ain
- * @return true, if successful
- */
- private boolean addNodeQueryParams(ActiveInventoryNode ain) {
-
- if (ain == null) {
- LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE_NODE_ID, "ActiveInventoryNode is null");
- return false;
- }
-
- List<String> pkeyNames = OxmEntityLookup.getInstance().getEntityDescriptors()
- .get(ain.getEntityType()).getPrimaryKeyAttributeNames();
-
- if (pkeyNames == null || pkeyNames.size() == 0) {
- LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE_NODE_ID, "Primary key names is empty");
- return false;
- }
-
- StringBuilder sb = new StringBuilder(64);
-
- if (pkeyNames.size() > 0) {
- String primaryKey = ain.getProperties().get(pkeyNames.get(0));
- if (primaryKey != null) {
- sb.append(primaryKey);
- } else {
- // this should be a fatal error because unless we can
- // successfully retrieve all the expected keys we'll end up
- // with a garbage node
- LOG.error(AaiUiMsgs.EXTRACTION_ERROR,
- "ERROR: Failed to extract keyName, " + pkeyNames.get(0) + ", from entity properties");
- return false;
- }
-
- for (int i = 1; i < pkeyNames.size(); i++) {
-
- String kv = ain.getProperties().get(pkeyNames.get(i));
- if (kv != null) {
- sb.append("/").append(kv);
- } else {
- // this should be a fatal error because unless we can
- // successfully retrieve all the expected keys we'll end up
- // with a garbage node
- LOG.error(AaiUiMsgs.EXTRACTION_ERROR,
- "ERROR: Failed to extract keyName, " + pkeyNames.get(i) + ", from entity properties");
- return false;
- }
- }
-
- /*
- * final String nodeId = NodeUtils.generateUniqueShaDigest(ain.getEntityType(),
- * NodeUtils.concatArray(pkeyNames, "/"), sb.toString());
- */
-
- // ain.setNodeId(nodeId);
- ain.setPrimaryKeyName(NodeUtils.concatArray(pkeyNames, "/"));
- ain.setPrimaryKeyValue(sb.toString());
-
- if (ain.getEntityType() != null && ain.getPrimaryKeyName() != null
- && ain.getPrimaryKeyValue() != null) {
- ain.addQueryParam(
- ain.getEntityType() + "." + ain.getPrimaryKeyName() + ":" + ain.getPrimaryKeyValue());
- }
- return true;
-
- }
-
- return false;
-
- }
-
- /**
- * Adds the self link relationship children.
- *
- * @param processingNode the processing node
- * @param relationshipList the relationship list
- * @return true, if successful
- */
- private boolean addSelfLinkRelationshipChildren(ActiveInventoryNode processingNode,
- RelationshipList relationshipList) {
-
- if (relationshipList == null) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "No relationships added to parent node = "
- + processingNode.getNodeId() + " because relationshipList is empty");
- processingNode.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.NEIGHBORS_PROCESSED_ERROR);
- return false;
- }
-
- Relationship[] relationshipArray = relationshipList.getRelationshipList();
- OxmEntityDescriptor descriptor = null;
- String repairedSelfLink = null;
-
- if (relationshipArray != null) {
-
- ActiveInventoryNode newNode = null;
- String resourcePath = null;
-
- for (Relationship r : relationshipArray) {
-
- resourcePath = ActiveInventoryConfig.extractResourcePath(r.getRelatedLink());
-
- String nodeId = NodeUtils.generateUniqueShaDigest(resourcePath);
-
- if (nodeId == null) {
-
- LOG.error(AaiUiMsgs.SKIPPING_RELATIONSHIP, r.toString());
- processingNode.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.NODE_IDENTITY_ERROR);
- return false;
- }
-
- newNode = new ActiveInventoryNode(this.visualizationConfigs);
-
- String entityType = r.getRelatedTo();
-
- if (r.getRelationshipData() != null) {
- for (RelationshipData rd : r.getRelationshipData()) {
- newNode.addQueryParam(rd.getRelationshipKey() + ":" + rd.getRelationshipValue());
- }
- }
-
- descriptor = OxmEntityLookup.getInstance().getEntityDescriptors().get(r.getRelatedTo());
-
- newNode.setNodeId(nodeId);
- newNode.setEntityType(entityType);
- newNode.setSelfLink(resourcePath);
-
- processingNode.addOutboundNeighbor(nodeId);
-
- if (descriptor != null) {
-
- List<String> pkeyNames = descriptor.getPrimaryKeyAttributeNames();
-
- newNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
- NodeProcessingAction.SELF_LINK_SET);
-
- newNode.setPrimaryKeyName(NodeUtils.concatArray(pkeyNames, "/"));
-
- String primaryKeyValues = getRelationshipPrimaryKeyValues(r, entityType, pkeyNames);
- newNode.setPrimaryKeyValue(primaryKeyValues);
-
- } else {
-
- LOG.error(AaiUiMsgs.VISUALIZATION_OUTPUT_ERROR,
- "Failed to parse entity because OXM descriptor could not be found for type = "
- + r.getRelatedTo());
-
- newNode.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.NEIGHBORS_PROCESSED_ERROR);
-
- }
-
- if (nodeCache.putIfAbsent(nodeId, newNode) != null) {
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "Failed to add node to nodeCache because it already exists. Node id = "
- + newNode.getNodeId());
- }
- }
-
- }
-
- }
-
- return true;
-
- }
-
- /**
- * Process initial state.
- *
- * @param nodeId the node id
- */
- private void processInitialState(String nodeId) {
-
- if (nodeId == null) {
- LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE, "Node id is null");
- return;
- }
-
- ActiveInventoryNode cachedNode = nodeCache.get(nodeId);
-
- if (cachedNode == null) {
- LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE,
- "Node cannot be" + " found for nodeId, " + nodeId);
- return;
- }
-
- if (cachedNode.getSelfLink() == null) {
-
- if (cachedNode.getNodeId() == null) {
-
- /*
- * if the self link is null at the INIT state, which could be valid if this node is a
- * complex attribute group which didn't originate from a self-link, but in that situation
- * both the node id and node key should already be set.
- */
-
- cachedNode.changeState(NodeProcessingState.ERROR, NodeProcessingAction.NODE_IDENTITY_ERROR);
-
- }
-
- if (cachedNode.getNodeId() != null) {
-
- /*
- * This should be the success path branch if the self-link is not set
- */
-
- cachedNode.changeState(NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
- NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
-
- }
-
- } else {
-
- if (cachedNode.hasResolvedSelfLink()) {
- LOG.error(AaiUiMsgs.INVALID_RESOLVE_STATE_DURING_INIT);
- cachedNode.changeState(NodeProcessingState.ERROR,
- NodeProcessingAction.UNEXPECTED_STATE_TRANSITION);
- } else {
- cachedNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
- NodeProcessingAction.SELF_LINK_SET);
- }
- }
- }
-
- /**
- * Process skeleton node.
- *
- * @param skeletonNode the skeleton node
- * @param queryParams the query params
- */
- private void processSearchableEntity(SearchableEntity searchTargetEntity,
- QueryParams queryParams) {
-
- if (searchTargetEntity == null) {
- return;
- }
-
- if (searchTargetEntity.getId() == null) {
- LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_SKELETON_NODE, "Failed to process skeleton"
- + " node because nodeId is null for node, " + searchTargetEntity.getLink());
- return;
- }
-
- ActiveInventoryNode newNode = new ActiveInventoryNode(this.visualizationConfigs);
-
- newNode.setNodeId(searchTargetEntity.getId());
- newNode.setEntityType(searchTargetEntity.getEntityType());
- newNode.setPrimaryKeyName(getEntityTypePrimaryKeyName(searchTargetEntity.getEntityType()));
- newNode.setPrimaryKeyValue(searchTargetEntity.getEntityPrimaryKeyValue());
-
- if (newNode.getEntityType() != null && newNode.getPrimaryKeyName() != null
- && newNode.getPrimaryKeyValue() != null) {
- newNode.addQueryParam(newNode.getEntityType() + "." + newNode.getPrimaryKeyName() + ":"
- + newNode.getPrimaryKeyValue());
- }
- /*
- * This code may need some explanation. In any graph there will be a single root node. The root
- * node is really the center of the universe, and for now, we are tagging the search target as
- * the root node. Everything else in the visualization of the graph will be centered around this
- * node as the focal point of interest.
- *
- * Due to it's special nature, there will only ever be one root node, and it's node depth will
- * always be equal to zero.
- */
-
- if (queryParams.getSearchTargetNodeId().equals(newNode.getNodeId())) {
- newNode.setNodeDepth(0);
- newNode.setRootNode(true);
- LOG.info(AaiUiMsgs.ROOT_NODE_DISCOVERED, queryParams.getSearchTargetNodeId());
- }
-
- newNode.setSelfLink(searchTargetEntity.getLink());
-
- nodeCache.putIfAbsent(newNode.getNodeId(), newNode);
- }
-
- /**
- * Checks for out standing work.
- *
- * @return true, if successful
- */
- private boolean hasOutStandingWork() {
-
- int numNodesWithPendingStates = 0;
-
- /*
- * Force an evaluation of node depths before determining if we should limit state-based
- * traversal or processing.
- */
-
- evaluateNodeDepths();
-
- for (ActiveInventoryNode n : nodeCache.values()) {
-
- switch (n.getState()) {
-
- case READY:
- case ERROR: {
- // do nothing, these are our normal
- // exit states
- break;
- }
-
- case NEIGHBORS_UNPROCESSED: {
-
- if (n.getNodeDepth() < this.visualizationConfigs.getMaxSelfLinkTraversalDepth()) {
- /*
- * Only process our neighbors relationships if our current depth is less than the max
- * depth
- */
- numNodesWithPendingStates++;
- }
-
- break;
- }
-
- default: {
-
- /*
- * for all other states, there is work to be done
- */
- numNodesWithPendingStates++;
- }
-
- }
-
- }
-
- LOG.debug(AaiUiMsgs.OUTSTANDING_WORK_PENDING_NODES, String.valueOf(numNodesWithPendingStates));
-
- return (numNodesWithPendingStates > 0);
-
- }
+public interface VisualizationContext {
/**
* Process self links.
@@ -1434,217 +38,16 @@ public class VisualizationContext {
* @param skeletonNode the skeleton node
* @param queryParams the query params
*/
- public void processSelfLinks(SearchableEntity searchtargetEntity, QueryParams queryParams) {
-
- try {
-
- if (searchtargetEntity == null) {
- LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
- contextIdStr + " - Failed to" + " processSelfLinks, searchtargetEntity is null");
- return;
- }
-
- processSearchableEntity(searchtargetEntity, queryParams);
-
- long startTimeInMs = System.currentTimeMillis();
-
- /*
- * wait until all transactions are complete or guard-timer expires.
- */
-
- long totalResolveTime = 0;
- boolean hasOutstandingWork = hasOutStandingWork();
- boolean outstandingWorkGuardTimerFired = false;
- long maxGuardTimeInMs = 5000;
- long guardTimeInMs = 0;
- boolean foundRootNode = false;
-
-
- /*
- * TODO: Put a count-down-latch in place of the while loop, but if we do that then we'll need
- * to decouple the visualization processing from the main thread so it can continue to process
- * while the main thread is waiting on for count-down-latch gate to open. This may also be
- * easier once we move to the VisualizationService + VisualizationContext ideas.
- */
-
-
- while (hasOutstandingWork || !outstandingWorkGuardTimerFired) {
-
- if (!foundRootNode) {
- foundRootNode = findAndMarkRootNode(queryParams);
- }
-
- processCurrentNodeStates(foundRootNode);
-
- verifyOutboundNeighbors();
-
- try {
- Thread.sleep(500);
- } catch (InterruptedException exc) {
- LOG.error(AaiUiMsgs.PROCESSING_LOOP_INTERUPTED, exc.getMessage());
- return;
- }
-
- totalResolveTime = (System.currentTimeMillis() - startTimeInMs);
-
- if (!hasOutstandingWork) {
-
- guardTimeInMs += 500;
-
- if (guardTimeInMs > maxGuardTimeInMs) {
- outstandingWorkGuardTimerFired = true;
- }
- } else {
- guardTimeInMs = 0;
- }
-
- hasOutstandingWork = hasOutStandingWork();
-
- }
-
- long opTime = System.currentTimeMillis() - startTimeInMs;
-
- LOG.info(AaiUiMsgs.ALL_TRANSACTIONS_RESOLVED, String.valueOf(totalResolveTime),
- String.valueOf(totalLinksRetrieved.get()), String.valueOf(opTime));
-
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.VISUALIZATION_OUTPUT_ERROR, exc.getMessage());
- }
-
- }
-
- /**
- * Verify outbound neighbors.
- */
- private void verifyOutboundNeighbors() {
-
- for (ActiveInventoryNode srcNode : nodeCache.values()) {
-
- for (String targetNodeId : srcNode.getOutboundNeighbors()) {
-
- ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
-
- if (targetNode != null && srcNode.getNodeId() != null) {
-
- targetNode.addInboundNeighbor(srcNode.getNodeId());
-
- if (this.visualizationConfigs.makeAllNeighborsBidirectional()) {
- targetNode.addOutboundNeighbor(srcNode.getNodeId());
- }
-
- }
-
- }
-
- }
-
- }
-
- /**
- * Evaluate node depths.
- */
- private void evaluateNodeDepths() {
-
- int numChanged = -1;
- int numAttempts = 0;
-
- while (numChanged != 0) {
-
- numChanged = 0;
- numAttempts++;
-
- for (ActiveInventoryNode srcNode : nodeCache.values()) {
-
- if (srcNode.getState() == NodeProcessingState.INIT) {
-
- /*
- * this maybe the only state that we don't want to to process the node depth on, because
- * typically it won't have any valid fields set, and it may remain in a partial state
- * until we have processed the self-link.
- */
-
- continue;
-
- }
-
- for (String targetNodeId : srcNode.getOutboundNeighbors()) {
- ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
-
- if (targetNode != null) {
-
- if (targetNode.changeDepth(srcNode.getNodeDepth() + 1)) {
- numChanged++;
- }
- }
- }
-
- for (String targetNodeId : srcNode.getInboundNeighbors()) {
- ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
-
- if (targetNode != null) {
-
- if (targetNode.changeDepth(srcNode.getNodeDepth() + 1)) {
- numChanged++;
- }
- }
- }
- }
-
- if (numAttempts >= MAX_DEPTH_EVALUATION_ATTEMPTS) {
- LOG.info(AaiUiMsgs.MAX_EVALUATION_ATTEMPTS_EXCEEDED);
- return;
- }
-
- }
-
- if (LOG.isDebugEnabled()) {
- if (numAttempts > 0) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "Evaluate node depths completed in " + numAttempts + " attempts");
- } else {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "Evaluate node depths completed in 0 attempts because all nodes at correct depth");
- }
- }
-
- }
-
-
- /**
- * Gets the entity type primary key name.
- *
- * @param entityType the entity type
- * @return the entity type primary key name
- */
-
-
- private String getEntityTypePrimaryKeyName(String entityType) {
-
- if (entityType == null) {
- LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE,
- "node primary key" + " name because entity type is null");
- return null;
- }
-
- OxmEntityDescriptor descriptor =
- OxmEntityLookup.getInstance().getEntityDescriptors().get(entityType);
-
- if (descriptor == null) {
- LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE,
- "oxm entity" + " descriptor for entityType = " + entityType);
- return null;
- }
+ void processSelfLinks(SearchableEntity searchtargetEntity, QueryParams queryParams);
- List<String> pkeyNames = descriptor.getPrimaryKeyAttributeNames();
+ ConcurrentHashMap<String, ActiveInventoryNode> getNodeCache();
- if (pkeyNames == null || pkeyNames.size() == 0) {
- LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE,
- "node primary" + " key because descriptor primary key names is empty");
- return null;
- }
+ InlineMessage getInlineMessage();
+
+ int getNumFailedLinkResolve();
- return NodeUtils.concatArray(pkeyNames, "/");
+ int getNumSuccessfulLinkResolveFromCache();
- }
+ int getNumSuccessfulLinkResolveFromFromServer();
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationService.java b/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationService.java
index 69ef774..5ea5609 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationService.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationService.java
@@ -22,350 +22,29 @@
*/
package org.onap.aai.sparky.viewandinspect.services;
-import java.io.IOException;
-import java.security.SecureRandom;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import javax.servlet.ServletException;
-
-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.config.oxm.OxmModelLoader;
-import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
-import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
-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.SearchableEntity;
-import org.onap.aai.sparky.util.NodeUtils;
-import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
-import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
-import org.onap.aai.sparky.viewandinspect.entity.D3VisualizationOutput;
-import org.onap.aai.sparky.viewandinspect.entity.GraphMeta;
-import org.onap.aai.sparky.viewandinspect.entity.QueryParams;
import org.onap.aai.sparky.viewandinspect.entity.QueryRequest;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class VisualizationService {
-
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(VisualizationService.class);
-
- private ObjectMapper mapper = new ObjectMapper();
-
- private final ActiveInventoryAdapter aaiAdapter;
- private final ElasticSearchAdapter esAdapter;
- private final ExecutorService tabularExecutorService;
- private final ExecutorService aaiExecutorService;
-
- private ConcurrentHashMap<Long, VisualizationContext> contextMap;
- private final SecureRandom secureRandom;
-
- private ActiveInventoryConfig aaiConfig;
- private VisualizationConfigs visualizationConfigs;
- private ElasticSearchEndpointConfig endpointEConfig;
- private ElasticSearchSchemaConfig schemaEConfig;
-
- public VisualizationService(OxmModelLoader loader, VisualizationConfigs visualizationConfigs,
- ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
- ElasticSearchEndpointConfig endpointConfig, ElasticSearchSchemaConfig schemaConfig)
- throws Exception {
-
-
- this.visualizationConfigs = visualizationConfigs;
- this.endpointEConfig = endpointConfig;
- this.schemaEConfig = schemaConfig;
-
- secureRandom = new SecureRandom();
-
- /*
- * Fix constructor with properly wired in properties
- */
-
- this.aaiAdapter = aaiAdapter;
- this.esAdapter = esAdapter;
-
- this.mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-
- this.contextMap = new ConcurrentHashMap<Long, VisualizationContext>();
- this.tabularExecutorService = NodeUtils.createNamedExecutor("TABULAR-WORKER",
- this.visualizationConfigs.getNumOfThreadsToFetchNodeIntegrity(), LOG);
- this.aaiConfig = ActiveInventoryConfig.getConfig();
- this.aaiExecutorService = NodeUtils.createNamedExecutor("SLNC-WORKER",
- aaiConfig.getAaiRestConfig().getNumResolverWorkers(), LOG);
-
- }
-
- /**
- * Analyze query request body.
- *
- * @param queryRequestJson the query request json
- * @return the query request
- */
-
- public QueryRequest analyzeQueryRequestBody(String queryRequestJson) {
-
-
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "analyzeQueryRequestBody()," + " queryRequestJson = " + queryRequestJson);
-
- ObjectMapper nonEmptyMapper = new ObjectMapper();
- nonEmptyMapper.setSerializationInclusion(Include.NON_EMPTY);
-
- QueryRequest queryBody = null;
-
- try {
- queryBody = nonEmptyMapper.readValue(queryRequestJson, QueryRequest.class);
- } catch (Exception exc) {
- LOG.error(AaiUiMsgs.EXCEPTION_CAUGHT, "Analyzing query request body.",
- exc.getLocalizedMessage());
- }
-
- return queryBody;
-
- }
-
- /**
- * Log optime.
- *
- * @param method the method
- * @param opStartTimeInMs the op start time in ms
- */
- private void logOptime(String method, long opStartTimeInMs) {
- LOG.info(AaiUiMsgs.OPERATION_TIME, method,
- String.valueOf(System.currentTimeMillis() - opStartTimeInMs));
- }
-
- private SearchableEntity extractSearchableEntityFromElasticEntity(
- OperationResult operationResult) {
- if (operationResult == null || !operationResult.wasSuccessful()) {
- // error, return empty collection
- return null;
- }
-
- SearchableEntity sourceEntity = null;
- if (operationResult.wasSuccessful()) {
-
- try {
- JsonNode elasticValue = mapper.readValue(operationResult.getResult(), JsonNode.class);
-
- if (elasticValue != null) {
- JsonNode sourceField = elasticValue.get("_source");
-
- if (sourceField != null) {
- sourceEntity = new SearchableEntity();
-
- String entityType = NodeUtils.extractFieldValueFromObject(sourceField, "entityType");
- sourceEntity.setEntityType(entityType);
- String entityPrimaryKeyValue =
- NodeUtils.extractFieldValueFromObject(sourceField, "entityPrimaryKeyValue");
- sourceEntity.setEntityPrimaryKeyValue(entityPrimaryKeyValue);
- String link = NodeUtils.extractFieldValueFromObject(sourceField, "link");
- sourceEntity.setLink(link);
- String lastmodTimestamp =
- NodeUtils.extractFieldValueFromObject(sourceField, "lastmodTimestamp");
- sourceEntity.setEntityTimeStamp(lastmodTimestamp);
- }
- }
- } catch (IOException ioe) {
- LOG.error(AaiUiMsgs.JSON_CONVERSION_ERROR, "a json node ", ioe.getLocalizedMessage());
- }
- }
- return sourceEntity;
- }
-
- /**
- * Builds the visualization using generic query.
- *
- * @param queryRequest the query request
- * @return the operation result
- */
- public OperationResult buildVisualizationUsingGenericQuery(QueryRequest queryRequest) {
-
- OperationResult returnValue = new OperationResult();
- OperationResult dataCollectionResult = null;
- QueryParams queryParams = null;
- SearchableEntity sourceEntity = null;
-
- try {
-
- /*
- * 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());
- sourceEntity = extractSearchableEntityFromElasticEntity(dataCollectionResult);
-
- if (sourceEntity != null) {
- sourceEntity.generateId();
- }
-
- queryParams = new QueryParams();
- queryParams.setSearchTargetNodeId(queryRequest.getHashId());
-
- } catch (Exception e1) {
- LOG.error(AaiUiMsgs.FAILED_TO_GET_NODES_QUERY_RESULT, e1.getLocalizedMessage());
- dataCollectionResult = new OperationResult(500, "Failed to get nodes-query result from AAI");
- }
-
- if (dataCollectionResult.getResultCode() == 200) {
-
- String d3OutputJsonOutput = null;
-
- try {
-
- d3OutputJsonOutput =
- getVisualizationOutputBasedonGenericQuery(sourceEntity, queryParams, queryRequest);
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
- "Generated D3" + " output as json = " + d3OutputJsonOutput);
- }
-
- if (d3OutputJsonOutput != null) {
- returnValue.setResultCode(200);
- returnValue.setResult(d3OutputJsonOutput);
- } else {
- returnValue.setResult(500, "Failed to generate D3 graph visualization");
- }
-
- } catch (Exception exc) {
- returnValue.setResult(500,
- "Failed to generate D3 graph visualization, due to a servlet exception.");
- LOG.error(AaiUiMsgs.ERROR_D3_GRAPH_VISUALIZATION, exc.getLocalizedMessage());
- }
- } else {
- returnValue.setResult(dataCollectionResult.getResultCode(), dataCollectionResult.getResult());
- }
-
- return returnValue;
-
- }
-
-
- /**
- * Gets the visualization output basedon generic query.
- *
- * @param searchtargetEntity entity that will be used to start visualization flow @param
- * queryParams the query params @return the visualization output basedon generic
- * query @throws ServletException the servlet exception @throws
- */
- private String getVisualizationOutputBasedonGenericQuery(SearchableEntity searchtargetEntity,
- QueryParams queryParams, QueryRequest request) throws ServletException {
-
- long opStartTimeInMs = System.currentTimeMillis();
-
- VisualizationTransformer transformer = null;
- try {
- transformer = new VisualizationTransformer(visualizationConfigs);
- } catch (Exception exc) {
- throw new ServletException(
- "Failed to create VisualizationTransformer instance because of execption", exc);
- }
-
- VisualizationContext visContext = null;
- long contextId = secureRandom.nextLong();
- try {
- visContext = new VisualizationContext(contextId, this.aaiAdapter, tabularExecutorService,
- aaiExecutorService, this.visualizationConfigs);
- contextMap.putIfAbsent(contextId, visContext);
- } catch (Exception e1) {
- LOG.error(AaiUiMsgs.EXCEPTION_CAUGHT,
- "While building Visualization Context, " + e1.getLocalizedMessage());
- throw new ServletException(e1);
- }
-
- String jsonResponse = null;
-
- long startTimeInMs = System.currentTimeMillis();
-
- visContext.processSelfLinks(searchtargetEntity, queryParams);
- contextMap.remove(contextId);
-
- logOptime("collectSelfLinkNodes()", startTimeInMs);
-
- /*
- * Flatten the graphs into a set of Graph and Link nodes. In this method I want the node graph
- * resulting from the edge-tag-query to be represented first, and then we'll layer in
- * relationship data.
- */
- long overlayDataStartTimeInMs = System.currentTimeMillis();
-
- Map<String, ActiveInventoryNode> cachedNodeMap = visContext.getNodeCache();
-
- if (LOG.isDebugEnabled()) {
-
- StringBuilder sb = new StringBuilder(128);
-
- sb.append("\nCached Node Map:\n");
- for (String k : cachedNodeMap.keySet()) {
- sb.append("\n----");
- sb.append("\n").append(cachedNodeMap.get(k).dumpNodeTree(true));
- }
-
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, sb.toString());
- }
-
- transformer.buildFlatNodeArrayFromGraphCollection(cachedNodeMap);
- transformer.buildLinksFromGraphCollection(cachedNodeMap);
-
- /*
- * - Apply configuration-driven styling - Build the final transformation response object - Use
- * information we have to populate the GraphMeta object
- */
-
- transformer.addSearchTargetAttributesToRootNode();
-
- GraphMeta graphMeta = new GraphMeta();
-
- D3VisualizationOutput output = null;
- try {
- output = transformer
- .generateVisualizationOutput((System.currentTimeMillis() - opStartTimeInMs), graphMeta);
- } catch (JsonProcessingException exc) {
- throw new ServletException("Caught an exception while generation visualization output", exc);
- } catch (IOException exc) {
- LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST, exc.getLocalizedMessage());
- }
-
- output.setInlineMessage(visContext.getInlineMessage());
- output.getGraphMeta().setNumLinkResolveFailed(visContext.getNumFailedLinkResolve());
- output.getGraphMeta().setNumLinksResolvedSuccessfullyFromCache(
- visContext.getNumSuccessfulLinkResolveFromCache());
- output.getGraphMeta().setNumLinksResolvedSuccessfullyFromServer(
- visContext.getNumSuccessfulLinkResolveFromFromServer());
-
- try {
- jsonResponse = transformer.convertVisualizationOutputToJson(output);
- } catch (JsonProcessingException jpe) {
- throw new ServletException(
- "Caught an exception while converting visualization output to json", jpe);
- }
-
- logOptime("[build flat node array, add relationship data, search target,"
- + " color scheme, and generate visualization output]", overlayDataStartTimeInMs);
+public interface VisualizationService {
- logOptime("doFilter()", opStartTimeInMs);
+ /**
+ * Analyze query request body.
+ *
+ * @param queryRequestJson the query request json
+ * @return the query request
+ */
- return jsonResponse;
+ QueryRequest analyzeQueryRequestBody(String queryRequestJson);
- }
+ /**
+ * Builds the visualization using generic query.
+ *
+ * @param queryRequest the query request
+ * @return the operation result
+ */
+ OperationResult buildVisualizationUsingGenericQuery(QueryRequest queryRequest);
- public void shutdown() {
- tabularExecutorService.shutdown();
- aaiExecutorService.shutdown();
- }
+ void shutdown();
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java b/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java
index 7c1d16d..ec76ac1 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java
@@ -37,8 +37,8 @@ import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
import org.onap.aai.sparky.viewandinspect.entity.D3VisualizationOutput;
import org.onap.aai.sparky.viewandinspect.entity.GraphMeta;
-import org.onap.aai.sparky.viewandinspect.entity.JsonNode;
-import org.onap.aai.sparky.viewandinspect.entity.JsonNodeLink;
+import org.onap.aai.sparky.viewandinspect.entity.SparkyGraphNode;
+import org.onap.aai.sparky.viewandinspect.entity.SparkyGraphLink;
import org.onap.aai.sparky.viewandinspect.entity.NodeDebug;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -57,10 +57,10 @@ import com.fasterxml.jackson.databind.ObjectWriter;
public class VisualizationTransformer {
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(VisualizationTransformer.class);
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(
+ VisualizationTransformer.class);
- List<JsonNode> flatNodeArray = new ArrayList<JsonNode>();
+ List<SparkyGraphNode> flatNodeArray = new ArrayList<SparkyGraphNode>();
/*
* Maybe this isn't a string but Json-Model objects that we will convert to final string
@@ -68,10 +68,10 @@ public class VisualizationTransformer {
* HttpServletResponse.
*/
- List<JsonNodeLink> linkArrayOutput = new ArrayList<JsonNodeLink>();
-
+ List<SparkyGraphLink> linkArrayOutput = new ArrayList<SparkyGraphLink>();
+
private VisualizationConfigs visualizationConfigs;
@@ -80,8 +80,8 @@ public class VisualizationTransformer {
*
* @throws Exception the exception
*/
- public VisualizationTransformer(VisualizationConfigs visualizationConfigs) throws Exception {
- this.visualizationConfigs = visualizationConfigs;
+ public VisualizationTransformer(VisualizationConfigs visualizationConfigs )throws Exception{
+ this.visualizationConfigs = visualizationConfigs;
}
@@ -101,7 +101,7 @@ public class VisualizationTransformer {
*/
public void addSearchTargetAttributesToRootNode() {
- for (JsonNode n : flatNodeArray) {
+ for (SparkyGraphNode n : flatNodeArray) {
if (n.isRootNode()) {
n.getNodeMeta().setSearchTarget(true);
n.getNodeMeta().setClassName(this.visualizationConfigs.getSelectedSearchedNodeClassName());
@@ -134,8 +134,8 @@ public class VisualizationTransformer {
output.setGraphMeta(graphMeta);
- for (JsonNode n : flatNodeArray) {
- if (n.getItemType() != null) {
+ for (SparkyGraphNode n : flatNodeArray) {
+ if ( n.getItemType()!= null) {
output.pegCounter(n.getItemType());
}
}
@@ -150,7 +150,8 @@ public class VisualizationTransformer {
String.valueOf(numLinks));
if (numLinks < (numNodes - 1)) {
- LOG.warn(AaiUiMsgs.DANGLING_NODE_WARNING, String.valueOf(numLinks), String.valueOf(numNodes));
+ LOG.warn(AaiUiMsgs.DANGLING_NODE_WARNING, String.valueOf(numLinks),
+ String.valueOf(numNodes));
}
ObjectMapper mapper = new ObjectMapper();
@@ -213,7 +214,7 @@ public class VisualizationTransformer {
for (String outboundNeighbor : outboundNeighbors) {
- JsonNodeLink nodeLink = new JsonNodeLink();
+ SparkyGraphLink nodeLink = new SparkyGraphLink();
nodeLink.setId(UUID.randomUUID().toString());
nodeLink.setSource(ain.getNodeId());
@@ -227,7 +228,7 @@ public class VisualizationTransformer {
for (String inboundNeighbor : inboundNeighbors) {
- JsonNodeLink nodeLink = new JsonNodeLink();
+ SparkyGraphLink nodeLink = new SparkyGraphLink();
nodeLink.setId(UUID.randomUUID().toString());
nodeLink.setSource(ain.getNodeId());
@@ -240,8 +241,9 @@ public class VisualizationTransformer {
} else {
if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "buildLinks()," + " Filtering node = "
- + ain.getNodeId() + " @ depth = " + ain.getNodeDepth());
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "buildLinks(),"
+ + " Filtering node = " + ain.getNodeId() + " @ depth = "
+ + ain.getNodeDepth());
}
}
@@ -264,7 +266,7 @@ public class VisualizationTransformer {
if (n.getNodeDepth() <= this.visualizationConfigs.getMaxSelfLinkTraversalDepth()) {
- JsonNode jsonNode = new JsonNode(n, this.visualizationConfigs);
+ SparkyGraphNode jsonNode = new SparkyGraphNode(n,this.visualizationConfigs);
jsonNode.getNodeMeta().setClassName(this.visualizationConfigs.getGeneralNodeClassName());
@@ -280,8 +282,9 @@ public class VisualizationTransformer {
flatNodeArray.add(jsonNode);
} else {
if (LOG.isDebugEnabled()) {
- LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "Filtering node from visualization: " + n.getNodeId()
- + " @ depth = " + n.getNodeDepth());
+ LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
+ "Filtering node from visualization: " + n.getNodeId() + " @ depth = "
+ + n.getNodeDepth());
}
}
}
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformNodeSelfLinkProcessingTask.java b/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformNodeSelfLinkProcessingTask.java
index 7c59ffa..e5a123a 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformNodeSelfLinkProcessingTask.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformNodeSelfLinkProcessingTask.java
@@ -29,7 +29,6 @@ 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.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction;
import org.slf4j.MDC;
@@ -45,7 +44,6 @@ public class PerformNodeSelfLinkProcessingTask implements Supplier<NodeProcessin
private NodeProcessingTransaction txn;
private ActiveInventoryAdapter aaiAdapter;
private Map<String, String> contextMap;
- private ActiveInventoryConfig aaiConfig;
/**
* Instantiates a new perform node self link processing task.
@@ -62,11 +60,10 @@ public class PerformNodeSelfLinkProcessingTask implements Supplier<NodeProcessin
* @param aaiConfig
*/
public PerformNodeSelfLinkProcessingTask(NodeProcessingTransaction txn, String requestParameters,
- ActiveInventoryAdapter aaiAdapter, ActiveInventoryConfig aaiConfig) {
+ ActiveInventoryAdapter aaiAdapter) {
this.aaiAdapter = aaiAdapter;
this.txn = txn;
this.contextMap = MDC.getCopyOfContextMap();
- this.aaiConfig = aaiConfig;
}
/*
@@ -88,7 +85,7 @@ public class PerformNodeSelfLinkProcessingTask implements Supplier<NodeProcessin
/**
* Rebuild the self link:
- *
+ *
* <li>build the base url with the configured scheme + authority (server:port)
* <li>recombine baseUrl + originalEncodedLink + queryStringParameters
*
@@ -98,7 +95,7 @@ public class PerformNodeSelfLinkProcessingTask implements Supplier<NodeProcessin
String parameters = txn.getRequestParameters();
link = urlSchemeAndAuthority + link;
-
+
if (parameters != null) {
link += parameters;
}
@@ -111,7 +108,7 @@ public class PerformNodeSelfLinkProcessingTask implements Supplier<NodeProcessin
try {
opResult = aaiAdapter.queryActiveInventoryWithRetries(link, "application/json",
- aaiConfig.getAaiRestConfig().getNumRequestRetries());
+ aaiAdapter.getEndpointConfig().getNumRequestRetries());
} catch (Exception exc) {
opResult = new OperationResult();
opResult.setResult(500, "Querying AAI with retry failed due to an exception.");
diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformSelfLinkDeterminationTask.java b/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformSelfLinkDeterminationTask.java
index b041a7d..a23ce59 100644
--- a/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformSelfLinkDeterminationTask.java
+++ b/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformSelfLinkDeterminationTask.java
@@ -29,13 +29,11 @@ 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.ActiveInventoryAdapter;
-import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.viewandinspect.entity.SelfLinkDeterminationTransaction;
import org.slf4j.MDC;
-public class PerformSelfLinkDeterminationTask
- implements Supplier<SelfLinkDeterminationTransaction> {
+public class PerformSelfLinkDeterminationTask implements Supplier<SelfLinkDeterminationTransaction> {
private static final Logger logger =
LoggerFactory.getInstance().getLogger(PerformSelfLinkDeterminationTask.class);
@@ -52,17 +50,15 @@ public class PerformSelfLinkDeterminationTask
* @param requestParameters the request parameters
* @param aaiProvider the aai provider
*/
- public PerformSelfLinkDeterminationTask(SelfLinkDeterminationTransaction txn,
- String requestParameters, ActiveInventoryAdapter aaiAdapter) {
-
+ public PerformSelfLinkDeterminationTask(SelfLinkDeterminationTransaction txn, String requestParameters,
+ ActiveInventoryAdapter aaiAdapter) {
+
this.aaiAdapter = aaiAdapter;
this.txn = txn;
this.contextMap = MDC.getCopyOfContextMap();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see java.util.function.Supplier#get()
*/
@Override
@@ -77,9 +73,8 @@ public class PerformSelfLinkDeterminationTask
OperationResult opResult = null;
try {
- opResult =
- aaiAdapter.queryActiveInventoryWithRetries(txn.getQueryString(), "application/json",
- ActiveInventoryConfig.getConfig().getAaiRestConfig().getNumRequestRetries());
+ opResult = aaiAdapter.queryActiveInventoryWithRetries(txn.getQueryString(), "application/json",
+ aaiAdapter.getEndpointConfig().getNumRequestRetries());
} catch (Exception exc) {
opResult = new OperationResult();
opResult.setResult(500, "Querying AAI with retry failed due to an exception.");
@@ -95,4 +90,4 @@ public class PerformSelfLinkDeterminationTask
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java b/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java
index ccce3b0..9de2973 100644
--- a/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java
+++ b/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java
@@ -44,9 +44,8 @@ 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.ActiveInventoryAdapter;
import org.onap.aai.sparky.dal.NetworkTransaction;
-import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
-import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
import org.onap.aai.sparky.dal.rest.HttpMethod;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
@@ -112,6 +111,8 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
private Deque<RetrySearchableEntitySyncContainer> retryQueue;
private Map<String, Integer> retryLimitTracker;
protected ExecutorService esPutExecutor;
+ private OxmEntityLookup oxmEntityLookup;
+ private SearchableEntityLookup searchableEntityLookup;
/**
* Instantiates a new searchable entity synchronizer.
@@ -121,9 +122,13 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
*/
public ViewInspectEntitySynchronizer(ElasticSearchSchemaConfig schemaConfig,
int internalSyncWorkers, int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
- NetworkStatisticsConfig esStatConfig) throws Exception {
+ NetworkStatisticsConfig esStatConfig, OxmEntityLookup oxmEntityLookup,
+ SearchableEntityLookup searchableEntityLookup) throws Exception {
super(LOG, "SES", internalSyncWorkers, aaiWorkers, esWorkers, schemaConfig.getIndexName(),
aaiStatConfig, esStatConfig);
+
+ this.oxmEntityLookup = oxmEntityLookup;
+ this.searchableEntityLookup = searchableEntityLookup;
this.allWorkEnumerated = false;
this.selflinks = new ConcurrentLinkedDeque<SelfLinkDescriptor>();
this.retryQueue = new ConcurrentLinkedDeque<RetrySearchableEntitySyncContainer>();
@@ -131,9 +136,9 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
this.synchronizerName = "Searchable Entity Synchronizer";
this.esPutExecutor = NodeUtils.createNamedExecutor("SES-ES-PUT", 5, LOG);
this.aaiEntityStats.intializeEntityCounters(
- SearchableEntityLookup.getInstance().getSearchableEntityDescriptors().keySet());
+ searchableEntityLookup.getSearchableEntityDescriptors().keySet());
this.esEntityStats.intializeEntityCounters(
- SearchableEntityLookup.getInstance().getSearchableEntityDescriptors().keySet());
+ searchableEntityLookup.getSearchableEntityDescriptors().keySet());
this.syncDurationInMs = -1;
}
@@ -143,10 +148,13 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
* @return the operation state
*/
private OperationState collectAllTheWork() {
+
+
+
final Map<String, String> contextMap = MDC.getCopyOfContextMap();
Map<String, SearchableOxmEntityDescriptor> descriptorMap =
- SearchableEntityLookup.getInstance().getSearchableEntityDescriptors();
-
+ searchableEntityLookup.getSearchableEntityDescriptors();
+
if (descriptorMap.isEmpty()) {
LOG.error(AaiUiMsgs.ERROR_LOADING_OXM_SEARCHABLE_ENTITIES);
LOG.info(AaiUiMsgs.ERROR_LOADING_OXM_SEARCHABLE_ENTITIES);
@@ -155,15 +163,14 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
Collection<String> syncTypes = descriptorMap.keySet();
- /*
- * Collection<String> syncTypes = new ArrayList<String>(); syncTypes.add("service-instance");
- */
+ /*Collection<String> syncTypes = new ArrayList<String>();
+ syncTypes.add("service-instance");*/
try {
/*
- * launch a parallel async thread to process the documents for each entity-type (to max the of
- * the configured executor anyway)
+ * 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());
@@ -228,9 +235,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
return OperationState.OK;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#doSync()
*/
@Override
@@ -238,7 +243,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
this.syncDurationInMs = -1;
String txnID = NodeUtils.getRandomTxnId();
MdcContext.initialize(txnID, "SearchableEntitySynchronizer", "", "Sync", "");
-
+
resetCounters();
this.allWorkEnumerated = false;
syncStartedTimeStampInMs = System.currentTimeMillis();
@@ -263,8 +268,9 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
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();
+ String message =
+ "Could not deserialize JSON (representing operation result) as node tree. " +
+ "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
}
@@ -287,8 +293,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
if (resourceType != null && resourceLink != null) {
- descriptor = SearchableEntityLookup.getInstance().getSearchableEntityDescriptors()
- .get(resourceType);
+ descriptor = searchableEntityLookup.getSearchableEntityDescriptors().get(resourceType);
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
@@ -297,8 +302,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
}
if (descriptor.hasSearchableAttributes()) {
- selflinks.add(new SelfLinkDescriptor(resourceLink,
- SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
+ selflinks.add(new SelfLinkDescriptor(resourceLink, SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
}
}
@@ -322,8 +326,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
if (linkDescriptor.getSelfLink() != null && linkDescriptor.getEntityType() != null) {
- descriptor = OxmEntityLookup.getInstance().getEntityDescriptors()
- .get(linkDescriptor.getEntityType());
+ descriptor = oxmEntityLookup.getEntityDescriptors().get(linkDescriptor.getEntityType());
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, linkDescriptor.getEntityType());
@@ -384,7 +387,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
*/
String link = null;
try {
- link = getElasticFullUrl("/" + se.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), se.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_LINK_UPSERT, exc.getLocalizedMessage());
return;
@@ -430,7 +433,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
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));
+ MergableEntity merged = updater.readValue(NodeUtils.convertObjectToJson(se,false));
jsonPayload = mapper.writeValueAsString(merged);
}
} catch (IOException exc) {
@@ -441,15 +444,14 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
return;
}
} else {
- jsonPayload = se.getAsJson();
+ jsonPayload = se.getAsJson();
}
if (wasEntryDiscovered) {
if (versionNumber != null && jsonPayload != null) {
- String requestPayload = elasticSearchAdapter.buildBulkImportOperationRequest(
- getIndexName(), ElasticSearchConfig.getConfig().getType(), se.getId(), versionNumber,
- jsonPayload);
+ String requestPayload = elasticSearchAdapter.buildBulkImportOperationRequest(getIndexName(),
+ "default", se.getId(), versionNumber, jsonPayload);
NetworkTransaction transactionTracker = new NetworkTransaction();
transactionTracker.setEntityType(esGetTxn.getEntityType());
@@ -457,7 +459,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
transactionTracker.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchUpdate(ElasticSearchConfig.getConfig().getBulkUrl(),
+ supplyAsync(new PerformElasticSearchUpdate(elasticSearchAdapter.getBulkUrl(),
requestPayload, elasticSearchAdapter, transactionTracker), esPutExecutor)
.whenComplete((result, error) -> {
@@ -475,7 +477,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
}
} else {
-
+
if (link != null && jsonPayload != null) {
NetworkTransaction updateElasticTxn = new NetworkTransaction();
@@ -485,8 +487,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
updateElasticTxn.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(
- new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
+ supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
@@ -528,9 +529,8 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
List<String> primaryKeyValues = new ArrayList<String>();
String pkeyValue = null;
- SearchableOxmEntityDescriptor searchableDescriptor = SearchableEntityLookup.getInstance()
- .getSearchableEntityDescriptors().get(resultDescriptor.getEntityName());
-
+ SearchableOxmEntityDescriptor searchableDescriptor = searchableEntityLookup.getSearchableEntityDescriptors().get(resultDescriptor.getEntityName());
+
for (String keyName : searchableDescriptor.getPrimaryKeyAttributeNames()) {
pkeyValue = NodeUtils.getNodeFieldAsText(entityNode, keyName);
if (pkeyValue != null) {
@@ -571,9 +571,9 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
return;
}
- SearchableOxmEntityDescriptor searchableDescriptor = SearchableEntityLookup.getInstance()
+ SearchableOxmEntityDescriptor searchableDescriptor = searchableEntityLookup
.getSearchableEntityDescriptors().get(txn.getDescriptor().getEntityName());
-
+
try {
if (searchableDescriptor.hasSearchableAttributes()) {
@@ -581,13 +581,13 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
if (jsonResult != null && jsonResult.length() > 0) {
SearchableEntity se = new SearchableEntity();
- se.setLink(ActiveInventoryConfig.extractResourcePath(txn.getLink()));
+ se.setLink(ActiveInventoryAdapter.extractResourcePath(txn.getLink()));
populateSearchableEntityDocument(se, jsonResult, txn.getDescriptor());
se.deriveFields();
String link = null;
try {
- link = getElasticFullUrl("/" + se.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), se.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_QUERY, exc.getLocalizedMessage());
}
@@ -676,7 +676,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
/*
* In this retry flow the se object has already derived its fields
*/
- link = getElasticFullUrl("/" + se.getId(), getIndexName());
+ link = elasticSearchAdapter.buildElasticSearchGetDocUrl(getIndexName(), se.getId());
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ES_FAILED_TO_CONSTRUCT_URI, exc.getLocalizedMessage());
}
@@ -748,9 +748,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
*/
@Override
@@ -759,9 +757,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
return this.getStatReport(syncDurationInMs, showFinalReport);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.IndexSynchronizer#shutdown()
*/
@Override
diff --git a/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java b/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java
index c2ecbb1..8d53d16 100644
--- a/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java
+++ b/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectSyncController.java
@@ -22,6 +22,9 @@
*/
package org.onap.aai.sparky.viewinspect.sync;
+import org.onap.aai.sparky.config.oxm.CrossEntityReferenceLookup;
+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;
@@ -49,42 +52,45 @@ public class ViewInspectSyncController extends SyncControllerImpl
public ViewInspectSyncController(SyncControllerConfig syncControllerConfig,
ActiveInventoryAdapter aaiAdapter, ElasticSearchAdapter esAdapter,
ElasticSearchSchemaConfig schemaConfig, ElasticSearchEndpointConfig endpointConfig,
- NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig)
- throws Exception {
+ NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
+ CrossEntityReferenceLookup crossEntityReferenceLookup, OxmEntityLookup oxmEntityLookup,
+ SearchableEntityLookup searchableEntityLookup) throws Exception {
super(syncControllerConfig);
-
// final String controllerName = "View and Inspect Entity Synchronizer";
- this.aaiAdapter = aaiAdapter;
- this.esAdapter = esAdapter;
- this.schemaConfig = schemaConfig;
- this.endpointConfig = endpointConfig;
+ this.aaiAdapter = aaiAdapter;
+ this.esAdapter = esAdapter;
+ this.schemaConfig = schemaConfig;
+ this.endpointConfig = endpointConfig;
IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(esAdapter, schemaConfig,
endpointConfig, ElasticSearchSchemaFactory.getIndexSchema(schemaConfig));
registerIndexValidator(indexValidator);
-
ViewInspectEntitySynchronizer ses = new ViewInspectEntitySynchronizer(schemaConfig,
syncControllerConfig.getNumInternalSyncWorkers(),
syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig);
+ syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig,
+ oxmEntityLookup, searchableEntityLookup);
+
+
ses.setAaiAdapter(aaiAdapter);
ses.setElasticSearchAdapter(esAdapter);
registerEntitySynchronizer(ses);
-
+
CrossEntityReferenceSynchronizer cers = new CrossEntityReferenceSynchronizer(schemaConfig,
syncControllerConfig.getNumInternalSyncWorkers(),
syncControllerConfig.getNumSyncActiveInventoryWorkers(),
- syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig);
-
+ syncControllerConfig.getNumSyncElasticWorkers(),aaiStatConfig,esStatConfig,
+ crossEntityReferenceLookup, oxmEntityLookup, searchableEntityLookup);
+
cers.setAaiAdapter(aaiAdapter);
cers.setElasticSearchAdapter(esAdapter);
registerEntitySynchronizer(cers);
-
+
IndexCleaner indexCleaner =
new ElasticSearchIndexCleaner(esAdapter, endpointConfig, schemaConfig);
@@ -99,28 +105,11 @@ public class ViewInspectSyncController extends SyncControllerImpl
public void setSyncControllerRegistry(SyncControllerRegistry syncControllerRegistry) {
this.syncControllerRegistry = syncControllerRegistry;
}
-
- public ActiveInventoryAdapter getAaiAdapter() {
- return this.aaiAdapter;
- }
-
- public ElasticSearchAdapter getElasticSearchAdapter() {
- return this.esAdapter;
- }
-
- public ElasticSearchEndpointConfig getendpointConfig() {
- return this.endpointConfig;
- }
-
- public ElasticSearchSchemaConfig getschemaConfig() {
- return this.schemaConfig;
- }
-
-
+
@Override
public void registerController() {
- if (syncControllerRegistry != null) {
- if (syncControllerConfig.isEnabled()) {
+ if ( syncControllerRegistry != null ) {
+ if ( syncControllerConfig.isEnabled()) {
syncControllerRegistry.registerSyncController(this);
}
}