use of org.janusgraph.core.schema.JanusGraphManagement in project aai-graphadmin by onap.
the class AuditJanusGraph method populateIndexes.
/**
* Populate indexes.
*/
private void populateIndexes() {
JanusGraphManagement mgmt = graph.openManagement();
Iterable<JanusGraphIndex> iterable = mgmt.getGraphIndexes(Vertex.class);
Iterator<JanusGraphIndex> JanusGraphIndexes = iterable.iterator();
JanusGraphIndex JanusGraphIndex;
while (JanusGraphIndexes.hasNext()) {
JanusGraphIndex = JanusGraphIndexes.next();
if (JanusGraphIndex.isCompositeIndex()) {
DBIndex index = new DBIndex();
LinkedHashSet<DBProperty> dbProperties = new LinkedHashSet<>();
index.setName(JanusGraphIndex.name());
index.setUnique(JanusGraphIndex.isUnique());
PropertyKey[] keys = JanusGraphIndex.getFieldKeys();
for (PropertyKey key : keys) {
dbProperties.add(this.properties.get(key.name()));
}
index.setProperties(dbProperties);
index.setStatus(JanusGraphIndex.getIndexStatus(keys[0]));
this.indexes.put(index.getName(), index);
}
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project aai-graphadmin by onap.
the class AuditJanusGraph method populateEdgeLabels.
/**
* Populate edge labels.
*/
private void populateEdgeLabels() {
JanusGraphManagement mgmt = graph.openManagement();
Iterable<EdgeLabel> iterable = mgmt.getRelationTypes(EdgeLabel.class);
Iterator<EdgeLabel> JanusGraphEdgeLabels = iterable.iterator();
EdgeLabel edgeLabel;
while (JanusGraphEdgeLabels.hasNext()) {
edgeLabel = JanusGraphEdgeLabels.next();
EdgeProperty edgeProperty = new EdgeProperty();
edgeProperty.setName(edgeLabel.name());
edgeProperty.setMultiplicity(edgeLabel.multiplicity());
this.edgeLabels.put(edgeProperty.getName(), edgeProperty);
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project aai-graphadmin by onap.
the class AuditJanusGraph method populateProperties.
/**
* Populate properties.
*/
private void populateProperties() {
JanusGraphManagement mgmt = graph.openManagement();
Iterable<PropertyKey> iterable = mgmt.getRelationTypes(PropertyKey.class);
Iterator<PropertyKey> JanusGraphProperties = iterable.iterator();
PropertyKey propKey;
while (JanusGraphProperties.hasNext()) {
propKey = JanusGraphProperties.next();
DBProperty prop = new DBProperty();
prop.setName(propKey.name());
prop.setCardinality(propKey.cardinality());
prop.setTypeClass(propKey.dataType());
this.properties.put(prop.getName(), prop);
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project aai-graphadmin by onap.
the class SchemaModInternal4Hist method execute.
public void execute() {
JanusGraphManagement graphMgt = null;
boolean success = false;
try {
// Make sure this property is in the DB.
graphMgt = engine.asAdmin().getManagementSystem();
if (graphMgt == null) {
String emsg = "Not able to get a graph Management object in SchemaModInternal4Hist.java\n";
logAndPrint(logger, emsg);
System.exit(1);
}
PropertyKey origPropKey = graphMgt.getPropertyKey(propName);
if (origPropKey == null) {
String emsg = "The propName = [" + propName + "] is not defined in our graph. ";
logAndPrint(logger, emsg);
System.exit(1);
}
// Rename this property to a backup name (old name with "retired_"
// appended plus a dateStr)
FormatDate fd = new FormatDate("MMddHHmm", "GMT");
String dteStr = fd.getDateTime();
String retiredName = propName + "-" + dteStr + "-RETIRED";
graphMgt.changeName(origPropKey, retiredName);
// Create a new property using the original property name and the
// targetDataType
PropertyKey freshPropKey = graphMgt.makePropertyKey(propName).dataType(type).cardinality(cardinality).make();
// Create an index if needed (regular index will be used instead of unique for history)
if (indexType.equals("index") || indexType.equals("uniqueIndex")) {
String freshIndexName = propName + dteStr;
graphMgt.buildIndex(freshIndexName, Vertex.class).addKey(freshPropKey).buildCompositeIndex();
}
logAndPrint(logger, "Committing schema changes with graphMgt.commit()");
graphMgt.commit();
engine.commit();
Graph grTmp2 = engine.startTransaction();
// For each node that has this property, update the new from the old
// and then remove the
// old property from that node
Iterator<Vertex> verts = grTmp2.traversal().V().has(retiredName);
int vtxCount = 0;
while (verts.hasNext()) {
vtxCount++;
Vertex tmpVtx = verts.next();
String tmpVid = tmpVtx.id().toString();
Object origVal = tmpVtx.<Object>property(retiredName).orElse(null);
if (preserveData) {
tmpVtx.property(propName, origVal);
logAndPrint(logger, "INFO -- just did the add of the freshPropertyKey and updated it with the orig value (" + origVal.toString() + ")");
} else {
// existing nodes just won't have that property anymore
// Not sure if we'd ever actually want to do this -- maybe
// we'd do this if the new
// data type was not compatible with the old?
}
tmpVtx.property(retiredName).remove();
logAndPrint(logger, "INFO -- just did the remove of the " + retiredName + " from this vertex. (vid=" + tmpVid + ")");
}
success = true;
} catch (Exception ex) {
logAndPrint(logger, "Threw a regular Exception: ");
logAndPrint(logger, ex.getMessage());
} finally {
if (graphMgt != null && graphMgt.isOpen()) {
// Any changes that worked correctly should have already done
// their commits.
graphMgt.rollback();
}
if (engine != null) {
if (success) {
engine.commit();
} else {
engine.rollback();
}
}
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project aai-aai-common by onap.
the class AAIGraph method loadSchema.
private void loadSchema(JanusGraph graph) {
// Load the propertyKeys, indexes and edge-Labels into the DB
JanusGraphManagement graphMgt = graph.openManagement();
logger.info("-- loading schema into JanusGraph");
if ("true".equals(SpringContextAware.getApplicationContext().getEnvironment().getProperty("history.enabled", "false"))) {
SchemaGenerator4Hist.loadSchemaIntoJanusGraph(graphMgt, IN_MEMORY);
} else {
SchemaGenerator.loadSchemaIntoJanusGraph(graphMgt, IN_MEMORY);
}
}
Aggregations