org.janusgraph.core.schema.SchemaStatus Java Examples

The following examples show how to use org.janusgraph.core.schema.SchemaStatus. 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: RepairIndex.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void restoreAll() throws Exception {
    for (String indexName : getIndexes()){
        displayCrlf("Restoring: " + indexName);
        long startTime = System.currentTimeMillis();

        ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
        JanusGraphIndex index = mgmt.getGraphIndex(indexName);
        mgmt.updateIndex(index, SchemaAction.REINDEX).get();
        mgmt.commit();

        ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.ENABLED).call();

        display(": Time taken: " + (System.currentTimeMillis() - startTime) + " ms");
        displayCrlf(": Done!");
    }
}
 
Example #2
Source File: GraphOMRSGraphFactory.java    From egeria with Apache License 2.0 4 votes vote down vote up
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;
        }

    }