X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=aai-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Faai%2Fdbgen%2FSchemaGenerator.java;h=c5186b0141788d188822e4082baae6c15b55386b;hb=9941d0d8597d9d69954819ca9458962aee281b10;hp=fa1d8e498b82b16dc5497138cfb3e2a0bb3bdf9b;hpb=96bf8c7b86bbf3350edcedcd19ad4dff97e62bb7;p=aai%2Faai-common.git diff --git a/aai-core/src/main/java/org/openecomp/aai/dbgen/SchemaGenerator.java b/aai-core/src/main/java/org/openecomp/aai/dbgen/SchemaGenerator.java index fa1d8e49..c5186b01 100644 --- a/aai-core/src/main/java/org/openecomp/aai/dbgen/SchemaGenerator.java +++ b/aai-core/src/main/java/org/openecomp/aai/dbgen/SchemaGenerator.java @@ -21,12 +21,14 @@ package org.openecomp.aai.dbgen; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.common.collect.Multimap; -import com.thinkaurelius.titan.core.*; -import com.thinkaurelius.titan.core.schema.TitanManagement; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + import org.apache.tinkerpop.gremlin.structure.Vertex; + import org.openecomp.aai.db.props.AAIProperties; import org.openecomp.aai.exceptions.AAIException; import org.openecomp.aai.introspection.Introspector; @@ -37,11 +39,18 @@ import org.openecomp.aai.schema.enums.PropertyMetadata; import org.openecomp.aai.serialization.db.EdgeRule; import org.openecomp.aai.serialization.db.EdgeRules; import org.openecomp.aai.util.AAIConfig; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.collect.Multimap; +import com.thinkaurelius.titan.core.Cardinality; +import com.thinkaurelius.titan.core.Multiplicity; +import com.thinkaurelius.titan.core.PropertyKey; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.schema.TitanManagement; -import java.util.*; -public class SchemaGenerator { +public class SchemaGenerator{ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(SchemaGenerator.class); private static boolean addDefaultCR = true; @@ -72,6 +81,7 @@ public class SchemaGenerator { } catch (Exception ex){ LOGGER.error(" ERROR - Could not run AAIConfig.init(). ", ex); + System.out.println(" ERROR - Could not run AAIConfig.init(). "); System.exit(1); } @@ -86,20 +96,21 @@ public class SchemaGenerator { Multimap edges = null; Set labels = new HashSet<>(); - try { - edges = EdgeRules.getInstance().getAllRules(); - for (EdgeRule rule : edges.values()) { - labels.add(rule.getLabel()); - } - } catch (AAIException e) { - LOGGER.error("could not get edge rules", e); - System.exit(1); + + edges = EdgeRules.getInstance().getAllRules(); + for (EdgeRule rule : edges.values()) { + labels.add(rule.getLabel()); } + for( String label: labels){ if( graphMgmt.containsRelationType(label) ) { - LOGGER.debug(" EdgeLabel [" + label + "] already existed. "); + String dmsg = " EdgeLabel [" + label + "] already existed. "; + System.out.println(dmsg); + LOGGER.debug(dmsg); } else { - LOGGER.debug("Making EdgeLabel: [" + label + "]"); + String dmsg = "Making EdgeLabel: [" + label + "]"; + System.out.println(dmsg); + LOGGER.debug(dmsg); graphMgmt.makeEdgeLabel(label).multiplicity(Multiplicity.valueOf("MULTI")).make(); } } @@ -116,7 +127,9 @@ public class SchemaGenerator { dbPropName = alias.get(); } if( graphMgmt.containsRelationType(propName) ){ - LOGGER.debug(" PropertyKey [" + propName + "] already existed in the DB. "); + String dmsg = " PropertyKey [" + propName + "] already existed in the DB. "; + System.out.println(dmsg); + LOGGER.debug(dmsg); } else { Class type = obj.getClass(propName); Cardinality cardinality = Cardinality.SINGLE; @@ -131,7 +144,9 @@ public class SchemaGenerator { if (process) { - LOGGER.info("Creating PropertyKey: [" + dbPropName + "], ["+ type.getSimpleName() + "], [" + cardinality + "]"); + String imsg = "Creating PropertyKey: [" + dbPropName + "], ["+ type.getSimpleName() + "], [" + cardinality + "]"; + System.out.println(imsg); + LOGGER.info(imsg); PropertyKey propK; if (!seenProps.containsKey(dbPropName)) { propK = graphMgmt.makePropertyKey(dbPropName).dataType(type).cardinality(cardinality).make(); @@ -140,18 +155,26 @@ public class SchemaGenerator { propK = seenProps.get(dbPropName); } if (graphMgmt.containsGraphIndex(dbPropName)) { - LOGGER.debug(" Index [" + dbPropName + "] already existed in the DB. "); + String dmsg = " Index [" + dbPropName + "] already existed in the DB. "; + System.out.println(dmsg); + LOGGER.debug(dmsg); } else { if( obj.getIndexedProperties().contains(propName) ){ if( obj.getUniqueProperties().contains(propName) ){ - LOGGER.info("Add Unique index for PropertyKey: [" + dbPropName + "]"); - graphMgmt.buildIndex(dbPropName,Vertex.class).addKey(propK).unique().buildCompositeIndex(); + imsg = "Add Unique index for PropertyKey: [" + dbPropName + "]"; + System.out.println(imsg); + LOGGER.info(imsg); + graphMgmt.buildIndex(dbPropName,Vertex.class).addKey(propK).unique().buildCompositeIndex(); } else { - LOGGER.info("Add index for PropertyKey: [" + dbPropName + "]"); - graphMgmt.buildIndex(dbPropName,Vertex.class).addKey(propK).buildCompositeIndex(); + imsg = "Add index for PropertyKey: [" + dbPropName + "]"; + System.out.println(imsg); + LOGGER.info(imsg); + graphMgmt.buildIndex(dbPropName,Vertex.class).addKey(propK).buildCompositeIndex(); } } else { - LOGGER.info("No index added for PropertyKey: [" + dbPropName + "]"); + imsg = "No index added for PropertyKey: [" + dbPropName + "]"; + System.out.println(imsg); + LOGGER.info(imsg); } } } @@ -159,7 +182,10 @@ public class SchemaGenerator { } } - LOGGER.info("-- About to call graphMgmt commit"); + String imsg = "-- About to call graphMgmt commit"; + System.out.println(imsg); + LOGGER.info(imsg); + graphMgmt.commit(); }// End of loadSchemaIntoTitan()