*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.aai.sparky.synchronizer;
+package org.onap.aai.sparky.autosuggestion.sync;
import static java.util.concurrent.CompletableFuture.supplyAsync;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.cl.mdc.MdcContext;
+import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.sparky.config.oxm.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.NetworkTransaction;
import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
import org.onap.aai.sparky.dal.rest.HttpMethod;
-import org.onap.aai.sparky.dal.rest.OperationResult;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.synchronizer.config.SynchronizerConfiguration;
-import org.onap.aai.sparky.synchronizer.entity.SelfLinkDescriptor;
-import org.onap.aai.sparky.synchronizer.entity.SuggestionSearchEntity;
-import org.onap.aai.sparky.synchronizer.enumeration.OperationState;
-import org.onap.aai.sparky.synchronizer.enumeration.SynchronizerState;
-import org.onap.aai.sparky.synchronizer.task.PerformActiveInventoryRetrieval;
-import org.onap.aai.sparky.synchronizer.task.PerformElasticSearchPut;
-import org.onap.aai.sparky.synchronizer.task.PerformElasticSearchRetrieval;
+import org.onap.aai.sparky.sync.AbstractEntitySynchronizer;
+import org.onap.aai.sparky.sync.IndexSynchronizer;
+import org.onap.aai.sparky.sync.SynchronizerConstants;
+import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
+import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
+import org.onap.aai.sparky.sync.entity.SelfLinkDescriptor;
+import org.onap.aai.sparky.sync.entity.SuggestionSearchEntity;
+import org.onap.aai.sparky.sync.enumeration.OperationState;
+import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
+import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
+import org.onap.aai.sparky.sync.task.PerformElasticSearchPut;
+import org.onap.aai.sparky.sync.task.PerformElasticSearchRetrieval;
import org.onap.aai.sparky.util.NodeUtils;
import org.onap.aai.sparky.util.SuggestionsPermutation;
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.cl.mdc.MdcContext;
import org.slf4j.MDC;
import com.fasterxml.jackson.core.JsonProcessingException;
* @param indexName the index name
* @throws Exception the exception
*/
- public AutosuggestionSynchronizer(String indexName) throws Exception {
- super(LOG, "ASES-" + indexName.toUpperCase(), 2, 5, 5, indexName); // multiple Autosuggestion
- // Entity Synchronizer will
- // run for different indices
+ public AutosuggestionSynchronizer(ElasticSearchSchemaConfig schemaConfig, int internalSyncWorkers,
+ int aaiWorkers, int esWorkers, NetworkStatisticsConfig aaiStatConfig,
+ NetworkStatisticsConfig esStatConfig) throws Exception {
+ super(LOG, "ASES-" + schemaConfig.getIndexName().toUpperCase(), internalSyncWorkers, aaiWorkers,
+ esWorkers, schemaConfig.getIndexName(), aaiStatConfig, esStatConfig);
this.allWorkEnumerated = false;
this.selflinks = new ConcurrentLinkedDeque<SelfLinkDescriptor>();
*/
private OperationState collectAllTheWork() {
final Map<String, String> contextMap = MDC.getCopyOfContextMap();
- Map<String, OxmEntityDescriptor> descriptorMap =
- oxmModelLoader.getSuggestionSearchEntityDescriptors();
+ Map<String, SuggestionEntityDescriptor> descriptorMap =
+ SuggestionEntityLookup.getInstance().getSuggestionSearchEntityDescriptors();
if (descriptorMap.isEmpty()) {
LOG.error(AaiUiMsgs.ERROR_LOADING_OXM_SUGGESTIBLE_ENTITIES);
MDC.setContextMap(contextMap);
OperationResult typeLinksResult = null;
try {
- typeLinksResult = aaiDataProvider.getSelfLinksByEntityType(key);
+ typeLinksResult = aaiAdapter.getSelfLinksByEntityType(key);
aaiWorkOnHand.decrementAndGet();
processEntityTypeSelfLinks(typeLinksResult);
} catch (Exception exc) {
/*
* (non-Javadoc)
*
- * @see org.onap.aai.sparky.synchronizer.IndexSynchronizer#doSync()
+ * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#doSync()
*/
@Override
public OperationState doSync() {
String message = "Could not deserialize JSON (representing operation result) as node tree. "
+ "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
- return;
}
JsonNode resultData = rootNode.get("result-data");
if (resourceType != null && resourceLink != null) {
- descriptor = oxmModelLoader.getEntityDescriptor(resourceType);
+ descriptor = OxmEntityLookup.getInstance().getEntityDescriptors().get(resourceType);
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
continue;
}
selflinks.add(new SelfLinkDescriptor(resourceLink,
- SynchronizerConfiguration.NODES_ONLY_MODIFIER, resourceType));
+ SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
}
if (linkDescriptor.getSelfLink() != null && linkDescriptor.getEntityType() != null) {
- descriptor = oxmModelLoader.getEntityDescriptor(linkDescriptor.getEntityType());
+ descriptor = OxmEntityLookup.getInstance().getEntityDescriptors()
+ .get(linkDescriptor.getEntityType());
if (descriptor == null) {
LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, linkDescriptor.getEntityType());
aaiWorkOnHand.incrementAndGet();
- supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiDataProvider), aaiExecutor)
+ supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter), aaiExecutor)
.whenComplete((result, error) -> {
aaiWorkOnHand.decrementAndGet();
*
* @return List of all valid suggestion attributes(key's)
*/
- public List<String> getSuggestionFromReponse(JsonNode node, String entityName) {
+ public List<String> getSuggestableAttrNamesFromReponse(JsonNode node, String entityName) {
List<String> suggestableAttr = new ArrayList<String>();
- HashMap<String, String> desc = oxmModelLoader.getOxmModel().get(entityName);
+ HashMap<String, String> desc =
+ SuggestionEntityLookup.getInstance().getSuggestionSearchEntityOxmModel().get(entityName);
String attr = desc.get("suggestibleAttributes");
suggestableAttr = Arrays.asList(attr.split(","));
List<String> suggestableValue = new ArrayList<>();
String entityName = txn.getDescriptor().getEntityName();
JsonNode entityNode = mapper.readTree(jsonResult);
- SuggestionsPermutation suggPermutation = new SuggestionsPermutation();
- ArrayList<ArrayList<String>> uniqueLists = suggPermutation
- .getSuggestionsPermutation(getSuggestionFromReponse(entityNode, entityName));
+ 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(oxmModelLoader);
+
+ SuggestionSearchEntity sse =
+ new SuggestionSearchEntity(SuggestionEntityLookup.getInstance());
sse.setSuggestableAttr(uniqueList);
- sse.setPayloadFromResponse(entityNode);
- sse.setLink(txn.getLink());
+ sse.setFilterBasedPayloadFromResponse(entityNode, entityName, uniqueList);
sse.setLink(ActiveInventoryConfig.extractResourcePath(txn.getLink()));
populateSuggestionSearchEntityDocument(sse, jsonResult, txn);
// The unique id for the document will be created at derive fields
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchRetrieval(n2, esDataProvider), esExecutor)
+ supplyAsync(new PerformElasticSearchRetrieval(n2, elasticSearchAdapter), esExecutor)
.whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
List<String> primaryKeyValues = new ArrayList<String>();
String pkeyValue = null;
- for (String keyName : resultDescriptor.getPrimaryKeyAttributeName()) {
+ for (String keyName : resultDescriptor.getPrimaryKeyAttributeNames()) {
pkeyValue = NodeUtils.getNodeFieldAsText(entityNode, keyName);
if (pkeyValue != null) {
primaryKeyValues.add(pkeyValue);
try {
String jsonPayload = null;
- jsonPayload = sse.getIndexDocumentJson();
+ jsonPayload = sse.getAsJson();
if (link != null && jsonPayload != null) {
NetworkTransaction updateElasticTxn = new NetworkTransaction();
updateElasticTxn.setOperationType(HttpMethod.PUT);
esWorkOnHand.incrementAndGet();
- supplyAsync(new PerformElasticSearchPut(jsonPayload, updateElasticTxn, esDataProvider),
+ supplyAsync(
+ new PerformElasticSearchPut(jsonPayload, updateElasticTxn, elasticSearchAdapter),
esPutExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
* called incrementAndGet when queuing the failed PUT!
*/
- supplyAsync(new PerformElasticSearchRetrieval(retryTransaction, esDataProvider),
+ supplyAsync(new PerformElasticSearchRetrieval(retryTransaction, elasticSearchAdapter),
esExecutor).whenComplete((result, error) -> {
esWorkOnHand.decrementAndGet();
/*
* (non-Javadoc)
*
- * @see org.onap.aai.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
+ * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#getStatReport(boolean)
*/
@Override
public String getStatReport(boolean showFinalReport) {
/*
* (non-Javadoc)
*
- * @see org.onap.aai.sparky.synchronizer.IndexSynchronizer#shutdown()
+ * @see org.openecomp.sparky.synchronizer.IndexSynchronizer#shutdown()
*/
@Override
public void shutdown() {
/*
* (non-Javadoc)
*
- * @see org.onap.aai.sparky.synchronizer.AbstractEntitySynchronizer#clearCache()
+ * @see org.openecomp.sparky.synchronizer.AbstractEntitySynchronizer#clearCache()
*/
@Override
public void clearCache() {