use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class ManagementTest method testReservedNamesRejectedForVertexLabels.
@Test
public void testReservedNamesRejectedForVertexLabels() {
for (String s : ILLEGAL_USER_DEFINED_NAMES) {
JanusGraphManagement tm = graph.openManagement();
try {
tm.makeVertexLabel(s);
fail("Vertex label \"" + s + "\" must be rejected");
} catch (IllegalArgumentException e) {
log.debug("Caught expected exception", e);
} finally {
tm.commit();
}
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class ManagementTest method testReservedNamesRejectedForPropertyKeys.
@Test
public void testReservedNamesRejectedForPropertyKeys() {
for (String s : ILLEGAL_USER_DEFINED_NAMES) {
JanusGraphManagement tm = graph.openManagement();
try {
tm.makePropertyKey(s);
fail("Property key \"" + s + "\" must be rejected");
} catch (IllegalArgumentException e) {
log.debug("Caught expected exception", e);
} finally {
tm.commit();
}
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project sunbird-rc-core by Sunbird-RC.
the class JanusGraphStorage method createIndex.
@Override
public void createIndex(Graph graph, String label, List<String> propertyNames) {
if (propertyNames.size() > 0) {
List<JanusGraphIndex> graphIndexList = new ArrayList<>();
VertexLabel vlabel = ((JanusGraph) graph).getVertexLabel(label);
graph.tx().commit();
JanusGraphManagement janusGraphManagement = ((JanusGraph) graph).openManagement();
propertyNames.forEach(propertyName -> {
PropertyKey propertyKey = janusGraphManagement.getPropertyKey(propertyName);
JanusGraphIndex graphIndex = janusGraphManagement.buildIndex(vlabel.name() + propertyKey.toString(), Vertex.class).addKey(propertyKey).buildCompositeIndex();
graphIndexList.add(graphIndex);
});
janusGraphManagement.commit();
} else {
logger.info("Could not create single index for empty properties");
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project sunbird-rc-core by Sunbird-RC.
the class JanusGraphStorage method createUniqueIndex.
@Override
public void createUniqueIndex(Graph graph, String label, List<String> propertyNames) {
if (propertyNames.size() > 0) {
List<JanusGraphIndex> graphIndexList = new ArrayList<>();
VertexLabel vlabel = ((JanusGraph) graph).getVertexLabel(label);
graph.tx().commit();
JanusGraphManagement janusGraphManagement = ((JanusGraph) graph).openManagement();
propertyNames.forEach(propertyName -> {
PropertyKey propertyKey = janusGraphManagement.getPropertyKey(propertyName);
JanusGraphIndex graphIndex = janusGraphManagement.buildIndex(vlabel.name() + propertyKey.toString(), Vertex.class).addKey(propertyKey).unique().buildCompositeIndex();
graphIndexList.add(graphIndex);
});
janusGraphManagement.commit();
} else {
logger.info("Could not create unique index for empty properties");
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project atlas by apache.
the class AtlasJanusGraphManagement method updateSchemaStatus.
public static void updateSchemaStatus(JanusGraphManagement mgmt, JanusGraph graph, Class<? extends Element> elementType) {
LOG.info("updating SchemaStatus for {}: Starting...", elementType.getSimpleName());
int count = 0;
Iterable<JanusGraphIndex> iterable = mgmt.getGraphIndexes(elementType);
for (JanusGraphIndex index : iterable) {
if (index.isCompositeIndex()) {
PropertyKey[] propertyKeys = index.getFieldKeys();
SchemaStatus status = index.getIndexStatus(propertyKeys[0]);
String indexName = index.name();
try {
if (status == REGISTERED) {
JanusGraphManagement management = graph.openManagement();
JanusGraphIndex indexToUpdate = management.getGraphIndex(indexName);
management.updateIndex(indexToUpdate, ENABLE_INDEX).get();
management.commit();
GraphIndexStatusReport report = ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(ENABLED).call();
if (!report.getConvergedKeys().isEmpty() && report.getConvergedKeys().containsKey(indexName)) {
LOG.info("SchemaStatus updated for index: {}, from {} to {}.", index.name(), REGISTERED, ENABLED);
count++;
} else if (!report.getNotConvergedKeys().isEmpty() && report.getNotConvergedKeys().containsKey(indexName)) {
LOG.error("SchemaStatus failed to update index: {}, from {} to {}.", index.name(), REGISTERED, ENABLED);
}
} else if (status == INSTALLED) {
LOG.warn("SchemaStatus {} found for index: {}", INSTALLED, indexName);
}
} catch (InterruptedException e) {
LOG.error("IllegalStateException for indexName : {}, Exception: ", indexName, e);
} catch (ExecutionException e) {
LOG.error("ExecutionException for indexName : {}, Exception: ", indexName, e);
}
}
}
LOG.info("updating SchemaStatus for {}: {}: Done!", elementType.getSimpleName(), count);
}
Aggregations