From c8fbdfcf5110c400f63fefe5fd08fe5f12164f01 Mon Sep 17 00:00:00 2001 From: kuldipr Date: Tue, 29 Sep 2020 15:13:36 -0400 Subject: [PATCH] Fixed concurrency issue in PNF uploading Issue-ID: AAI-3100 Signed-off-by: kuldipr Change-Id: I27b9b5f44229798cc1fe116a27b480e61ba0e339 --- .../java/org/onap/aai/dbgen/SchemaGenerator.java | 25 +++++++++++++++++++--- .../parsers/uri/URIToExtensionInformationTest.java | 3 +++ .../main/java/org/onap/aai/util/AAIConstants.java | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/aai-core/src/main/java/org/onap/aai/dbgen/SchemaGenerator.java b/aai-core/src/main/java/org/onap/aai/dbgen/SchemaGenerator.java index d253f876..c1ef1cc2 100644 --- a/aai-core/src/main/java/org/onap/aai/dbgen/SchemaGenerator.java +++ b/aai-core/src/main/java/org/onap/aai/dbgen/SchemaGenerator.java @@ -20,6 +20,7 @@ package org.onap.aai.dbgen; +import org.onap.aai.util.AAIConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Multimap; @@ -36,6 +37,8 @@ import org.janusgraph.core.JanusGraph; import org.janusgraph.core.Multiplicity; import org.janusgraph.core.PropertyKey; import org.janusgraph.core.schema.JanusGraphManagement; +import org.janusgraph.core.schema.JanusGraphIndex; +import org.janusgraph.core.schema.ConsistencyModifier; import org.onap.aai.config.SpringContextAware; import org.onap.aai.db.props.AAIProperties; import org.onap.aai.edges.EdgeIngestor; @@ -145,6 +148,14 @@ public class SchemaGenerator { if (!seenProps.containsKey(dbPropName)) { propK = graphMgmt.makePropertyKey(dbPropName).dataType(type).cardinality(cardinality) .make(); + if (dbPropName.equals("aai-uri")) { + String aai_uri_lock_enabled = AAIConfig.get(AAIConstants.AAI_LOCK_URI_ENABLED, "false"); + LOGGER.info(" Info: aai_uri_lock_enabled:" + aai_uri_lock_enabled); + if ("true".equals(aai_uri_lock_enabled)) { + LOGGER.info(" Lock is being set for aai-uri Property."); + graphMgmt.setConsistency(propK, ConsistencyModifier.LOCK); + } + } seenProps.put(dbPropName, propK); } else { propK = seenProps.get(dbPropName); @@ -154,15 +165,23 @@ public class SchemaGenerator { LOGGER.debug(dmsg); } else { if (obj.getIndexedProperties().contains(propName)) { + JanusGraphIndex indexG = null; if (obj.getUniqueProperties().contains(propName)) { imsg = "Add Unique index for PropertyKey: [" + dbPropName + "]"; LOGGER.info(imsg); - graphMgmt.buildIndex(dbPropName, Vertex.class).addKey(propK).unique() - .buildCompositeIndex(); + indexG = graphMgmt.buildIndex(dbPropName, Vertex.class).addKey(propK).unique().buildCompositeIndex(); } else { imsg = "Add index for PropertyKey: [" + dbPropName + "]"; LOGGER.info(imsg); - graphMgmt.buildIndex(dbPropName, Vertex.class).addKey(propK).buildCompositeIndex(); + indexG = graphMgmt.buildIndex(dbPropName, Vertex.class).addKey(propK).buildCompositeIndex(); + } + if (indexG != null && dbPropName.equals("aai-uri")) { + String aai_uri_lock_enabled = AAIConfig.get(AAIConstants.AAI_LOCK_URI_ENABLED, "false"); + LOGGER.info(" Info:: aai_uri_lock_enabled:" + aai_uri_lock_enabled); + if ("true".equals(aai_uri_lock_enabled)) { + LOGGER.info("Lock is being set for aai-uri Index."); + graphMgmt.setConsistency(indexG, ConsistencyModifier.LOCK); + } } } else { imsg = "No index added for PropertyKey: [" + dbPropName + "]"; diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java index 7d7d284d..3035d4b8 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java @@ -30,6 +30,8 @@ import javax.ws.rs.core.UriBuilder; import javax.xml.bind.JAXBException; import org.junit.Test; +import org.springframework.test.annotation.DirtiesContext; + import org.onap.aai.AAISetup; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; @@ -37,6 +39,7 @@ import org.onap.aai.introspection.ModelType; import org.onap.aai.restcore.HttpMethod; import org.onap.aai.setup.SchemaVersion; +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class URIToExtensionInformationTest extends AAISetup { private Loader specificLoader; diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConstants.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConstants.java index 3ddd008f..f44f736c 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConstants.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConstants.java @@ -154,6 +154,9 @@ public final class AAIConstants { public static final String AAI_TRAVERSAL_MS = "aai-traversal"; public static final String AAI_RESOURCES_MS = "aai-resources"; + /** Flag to control concurrency lock */ + public static final String AAI_LOCK_URI_ENABLED = "aai.lock.uri.enabled"; + /** * Instantiates a new AAI constants. */ -- 2.16.6