Update indexes for schemaInitialized 26/139626/4
authorankita.singhal <ankita.f.singhal@accenture.com>
Mon, 25 Nov 2024 08:01:13 +0000 (09:01 +0100)
committerankita.singhal <ankita.f.singhal@accenture.com>
Mon, 2 Dec 2024 09:43:30 +0000 (10:43 +0100)
Issue-ID: AAI-4062
Change-Id: I0709470ac83badd06e499b22df2277cceba0a615
Signed-off-by: ankita.singhal <ankita.f.singhal@accenture.com>
src/main/java/org/onap/aai/datagrooming/DataGrooming.java
src/main/java/org/onap/aai/schema/GenTester.java
src/main/java/org/onap/aai/service/SchemaJobStatusService.java
version.properties

index 796e491..7360abf 100644 (file)
@@ -269,6 +269,16 @@ public class DataGrooming {
                                                cArgs.skipEdgeCheckFlag, cArgs.timeWindowMinutes,
                                                cArgs.singleNodeType, cArgs.skipIndexUpdateFix );
                        }
+                       LOGGER.info("===== Data Grooming Summary after all fixes =====");
+            LOGGER.info("Ghost Node Count: " + getGhostNodeCount());
+            LOGGER.info("Bad Index Node Count: " + getBadIndexNodeCount());
+            LOGGER.info("Bad URI Node Count: " + getBadUriNodeCount());
+            LOGGER.info("Orphan Node Count: " + getOrphanNodeCount());
+            LOGGER.info("Missing AAI NT Node Count: " + getMissingAaiNtNodeCount());
+            LOGGER.info("One-Armed Edge Hash Count: " + getOneArmedEdgeHashCount());
+                       // Add more logging if needed for other nodes like Duplicate Groups, Delete Candidates, etc.
+            LOGGER.info("===== End of Data Grooming Summary =====");
                } catch (Exception ex) {
                        LOGGER.debug("Exception while grooming data " + LogFormatTools.getStackTop(ex));
                }
index cb79f2c..ea18288 100644 (file)
  */
 package org.onap.aai.schema;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.janusgraph.core.EdgeLabel;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.janusgraph.core.JanusGraph;
-import org.janusgraph.core.JanusGraphVertex;
+import org.janusgraph.core.PropertyKey;
 import org.janusgraph.core.schema.JanusGraphManagement;
-import org.janusgraph.core.schema.RelationTypeIndex;
 import org.janusgraph.core.schema.SchemaAction;
 import org.janusgraph.graphdb.database.StandardJanusGraph;
 import org.janusgraph.graphdb.database.management.ManagementSystem;
-import org.onap.aai.restclient.PropertyPasswordConfiguration;
 import org.onap.aai.dbgen.SchemaGenerator;
 import org.onap.aai.dbmap.AAIGraph;
 import org.onap.aai.exceptions.AAIException;
 import org.onap.aai.logging.ErrorLogHelper;
-import org.onap.aai.util.*;
+import org.onap.aai.restclient.PropertyPasswordConfiguration;
+import org.onap.aai.util.AAIConfig;
+import org.onap.aai.util.ExceptionTranslator;
+import org.onap.aai.util.GraphAdminDBUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import java.util.UUID;
-
 public class GenTester {
 
        private static Logger LOGGER;
        private static boolean historyEnabled;
        private static boolean isSchemaInitialized;
     private static final String SCHEMA_INITIALIZED = "schema-initialized";
+       private static final String bySchemaInitialized = "bySchemaInitialized";
 
        /**
         * The main method.
@@ -141,13 +141,44 @@ public class GenTester {
 
                        if (isSchemaInitialized) {
                                // Setting property schema-initialized to false as vertex is already there
-                               LOGGER.debug("-- Adding a vertex with property schema-initialized as false");
-                               graph.traversal().V().has(SCHEMA_INITIALIZED).property(SCHEMA_INITIALIZED, "false");
-                       } else {
-                               // Adding a new vertex with property schema-initialized to false
-                               LOGGER.debug("-- Adding a vertex with property schema-initialized as false");
-                               graph.addVertex(SCHEMA_INITIALIZED, "false");
+                               LOGGER.debug("-- Vertex with property 'schema-initialized' present in db. Updating it to false");
+                               graph.traversal().V().has(SCHEMA_INITIALIZED).property(SCHEMA_INITIALIZED, false).next();
+               
+                               // Reindexing the existing index
+                               LOGGER.debug("-- Reindexing existing schema-initialized index");
+                               JanusGraphManagement mgmt = graph.openManagement();
+                       try {
+                               if (mgmt.getGraphIndex(bySchemaInitialized) != null) {
+                                       LOGGER.info("Reindexing 'bySchemaInitialized' to include existing vertices.");
+                                       mgmt.updateIndex(mgmt.getGraphIndex(bySchemaInitialized), SchemaAction.REINDEX).get();
+                               }
+                               mgmt.commit();
+                       } catch (Exception e) {
+                               mgmt.rollback();
+                               LOGGER.error("Error during reindexing: " + e.getMessage());
+                               throw e;
                        }
+               } else {
+                       LOGGER.debug("-- Adding a new vertex with property schema-initialized as false");
+                       JanusGraphManagement mgmt = graph.openManagement();
+                       try{
+                               //creating  a composite index
+                               PropertyKey schemaInitialized = mgmt.makePropertyKey(SCHEMA_INITIALIZED).dataType(Boolean.class).make();
+                               mgmt.buildIndex(bySchemaInitialized, Vertex.class)
+                                                                               .addKey(schemaInitialized)
+                                                                               .buildCompositeIndex();
+                               mgmt.commit();
+
+                               //Wait for the index to become available
+                               ManagementSystem.awaitGraphIndexStatus(graph, bySchemaInitialized).call();
+                       }catch(Exception e) {
+                               mgmt.rollback();
+                               LOGGER.error("Problems creating an index for schema-initialized vertex " + e.getMessage());
+                               throw e;
+                       }
+                       //Adding a new vertex
+                       graph.addVertex(SCHEMA_INITIALIZED, false);
+               }
 
                        GraphAdminDBUtils.logConfigs(graph.configuration());
 
@@ -171,11 +202,11 @@ public class GenTester {
                        }
 
                        // Setting property schema-initialized to true
-                       LOGGER.debug("-- Updating vertex with property schema-initialized as true ");
-                       graph.traversal().V().has(SCHEMA_INITIALIZED).property(SCHEMA_INITIALIZED, "true");
+                       LOGGER.debug("-- Updating vertex with property schema-initialized to true ");
+                       graph.traversal().V().has(SCHEMA_INITIALIZED).property(SCHEMA_INITIALIZED, true).next();
                        LOGGER.debug("-- committing transaction ");
                        graph.tx().commit();
-
+                       
                        graph.close();
                        LOGGER.info("Closed the graph");
 
index 53e3773..eeefdc5 100644 (file)
@@ -43,7 +43,7 @@ public class SchemaJobStatusService {
         GraphTraversalSource g = graph.traversal();
         try {
             // Check if there is a vertex with the property "schema-initialized" set to "true"
-            return g.V().has("schema-initialized", "true").hasNext();
+            return g.V().has("schema-initialized", true).hasNext();
         } catch (Exception e) {
             LOGGER.error("Error during schema initialization check", e);
             throw new AAIException("Error checking schema initialization: " + e.getMessage(), e);
index df31475..08fc17c 100644 (file)
@@ -5,7 +5,7 @@
 
 major_version=1
 minor_version=15
-patch_version=2
+patch_version=3
 
 base_version=${major_version}.${minor_version}.${patch_version}