org.janusgraph.core.schema.JanusGraphManagement Java Examples
The following examples show how to use
org.janusgraph.core.schema.JanusGraphManagement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AtlasJanusGraph.java From atlas with Apache License 2.0 | 6 votes |
public AtlasJanusGraph(JanusGraph graphInstance) { //determine multi-properties once at startup JanusGraphManagement mgmt = null; try { mgmt = graphInstance.openManagement(); Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class); for (PropertyKey key : keys) { if (key.cardinality() != Cardinality.SINGLE) { multiProperties.add(key.name()); } } } finally { if (mgmt != null) { mgmt.rollback(); } } janusGraph = (StandardJanusGraph) graphInstance; }
Example #2
Source File: GraphFactory.java From egeria with Apache License 2.0 | 5 votes |
/** * Set up the schema for the Janus Graph instance * * @param janusGraph - Janus Graph instance * @param graphType - type of the graph to be initiated */ private JanusGraph initializeGraph(JanusGraph janusGraph, String graphType) throws JanusConnectorException { final String methodName = "initializeGraph"; log.info("Updating graph schema, if necessary"); try { JanusGraphManagement management = janusGraph.openManagement(); Set<String> vertexLabels = new HashSet<>(); Set<String> relationshipsLabels = new HashSet<>(); if ("bufferGraph".equals(graphType)) { vertexLabels = schemaBasedOnGraphType(VertexLabelsBufferGraph.class); relationshipsLabels = schemaBasedOnGraphType(EdgeLabelsBufferGraph.class); } if ("mainGraph".equals(graphType)) { vertexLabels = schemaBasedOnGraphType(VertexLabelsMainGraph.class); relationshipsLabels = schemaBasedOnGraphType(EdgeLabelsMainGraph.class); } checkAndAddLabelVertex(management, vertexLabels); checkAndAddLabelEdge(management, relationshipsLabels); //TODO define properties management.commit(); createIndexes(janusGraph, graphType); return janusGraph; } catch (Exception e) { log.error("{} failed during graph initialize operation with error: {}", graphType, e); JanusConnectorErrorCode errorCode = JanusConnectorErrorCode.GRAPH_INITIALIZATION_ERROR; String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(e.getMessage(), methodName, GraphFactory.class.getName()); throw new JanusConnectorException(GraphFactory.class.getName(), methodName, errorMessage, errorCode.getSystemAction(), errorCode.getUserAction()); } }
Example #3
Source File: GraphFactory.java From egeria with Apache License 2.0 | 5 votes |
/** * Set up the vertex labels of the schema for the Janus Graph instance * * @param labels - set of labels * @param management - management instance of Janus Graph */ private void checkAndAddLabelVertex(final JanusGraphManagement management, Set<String> labels) { for (String label : labels) { if (management.getVertexLabel(label) == null) management.makeVertexLabel(label).make(); } }
Example #4
Source File: GraphFactory.java From egeria with Apache License 2.0 | 5 votes |
/** * Set up the edge labels of the schema for the Janus Graph instance * * @param labels - set of labels * @param management - management instance of Janus Graph */ private void checkAndAddLabelEdge(final JanusGraphManagement management, Set<String> labels) { for (String label : labels) { if (management.getEdgeLabel(label) == null) management.makeEdgeLabel(label).make(); } }
Example #5
Source File: AtlasJanusGraphDatabase.java From atlas with Apache License 2.0 | 5 votes |
static void validateIndexBackend(Configuration config) { String configuredIndexBackend = config.getString(INDEX_BACKEND_CONF); JanusGraphManagement managementSystem = getGraphInstance().openManagement(); String currentIndexBackend = managementSystem.get(INDEX_BACKEND_CONF); managementSystem.commit(); if (!configuredIndexBackend.equals(currentIndexBackend)) { throw new RuntimeException("Configured Index Backend " + configuredIndexBackend + " differs from earlier configured Index Backend " + currentIndexBackend + ". Aborting!"); } }
Example #6
Source File: AtlasJanusGraph.java From atlas with Apache License 2.0 | 5 votes |
private Set<String> getIndexKeys(Class<? extends Element> janusGraphElementClass) { JanusGraphManagement mgmt = getGraph().openManagement(); Iterable<JanusGraphIndex> indices = mgmt.getGraphIndexes(janusGraphElementClass); Set<String> result = new HashSet<String>(); for (JanusGraphIndex index : indices) { result.add(index.name()); } mgmt.commit(); return result; }
Example #7
Source File: ScenarioTests.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 5 votes |
private static void createHotelSchema(final JanusGraph graph) { //another issue, you should only try to create the schema once. //you use uniqueness constraints, so you need to define the schema up front with the unique() call, //but if you did not use uniqueness constraints, you could just let JanusGraph create the schema for you. final JanusGraphManagement mgmt = graph.openManagement(); final PropertyKey brandtypePropertyKey = mgmt.makePropertyKey("brandtype").dataType(String.class).make(); mgmt.buildIndex("brandtypeIndex", Vertex.class).addKey(brandtypePropertyKey).unique().buildCompositeIndex(); final PropertyKey namePropertyKey = mgmt.makePropertyKey("name").dataType(String.class).make(); mgmt.buildIndex("nameIndex", Vertex.class).addKey(namePropertyKey).unique().buildCompositeIndex(); mgmt.makeEdgeLabel(Relationship.hotelBrandType.name()).multiplicity(Multiplicity.MANY2ONE).make(); mgmt.makeEdgeLabel(Relationship.instanceOf.name()).multiplicity(Multiplicity.MANY2ONE).make(); mgmt.commit(); }
Example #8
Source File: GraphContextImpl.java From windup with Eclipse Public License 1.0 | 5 votes |
private PropertyKey getOrCreatePropertyKey(JanusGraphManagement janusGraphManagement, String key, Class<?> dataType, Cardinality cardinality) { PropertyKey propertyKey = janusGraphManagement.getPropertyKey(key); if (propertyKey == null) { propertyKey = janusGraphManagement.makePropertyKey(key).dataType(dataType).cardinality(cardinality).make(); } return propertyKey; }
Example #9
Source File: GraphOMRSGraphFactory.java From egeria with Apache License 2.0 | 4 votes |
private boolean createControlIndex() { final String methodName = "createControlIndex"; // Prior to creating the control vertex - create an index to allow us to find it without a full scan JanusGraphManagement management = graph.openManagement(); String indexName = "controlIndex"; try { // Check if index exists JanusGraphIndex controlIndex = management.getGraphIndex(indexName); if (controlIndex == null) { log.info("{} index create {} for control vertex", methodName, indexName); // Property key should not already exist - but check it anyway. PropertyKey propertyKey = management.getPropertyKey(controlVertexIdPropertyName); if (propertyKey != null) { // Somehow - despite this being a new graph - the property key already exists. Stop. log.error("{} property key {} already exists", methodName, controlVertexIdPropertyName); management.rollback(); return false; } else { log.info("{} make property key {}", methodName, controlVertexIdPropertyName); propertyKey = management.makePropertyKey(controlVertexIdPropertyName).dataType(String.class).make(); } if (propertyKey == null) { // Could not create property key. Stop. log.error("{} property key {} could not be created", methodName, controlVertexIdPropertyName); management.rollback(); return false; } else { log.info("{} create index {}", methodName, indexName); JanusGraphManagement.IndexBuilder indexBuilder = management.buildIndex(indexName, Vertex.class).addKey(propertyKey).unique(); JanusGraphIndex index = indexBuilder.buildCompositeIndex(); management.setConsistency(index, ConsistencyModifier.LOCK); management.commit(); // Enable the index - set a relatively short timeout (10 s vs the default of 1 minute) log.info("{} await ENABLED for {}", methodName, indexName); ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.ENABLED).timeout(10, ChronoUnit.SECONDS).call(); return true; } } else { // That really should not be possible - a new graph should not have the index. Stop. log.error("{} control index already exists", methodName); management.rollback(); return false; } } catch (Exception e) { log.error("{} caught interrupted exception from awaitGraphIndexStatus ENABLED {}", methodName, e); management.rollback(); return false; } }