use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class AbstractIndexManagementIT method testRepairGraphIndex.
@Test
public void testRepairGraphIndex() throws InterruptedException, BackendException, ExecutionException {
tx.commit();
mgmt.commit();
// Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
// Create and enable a graph index on age
JanusGraphManagement m = graph.openManagement();
PropertyKey age = m.getPropertyKey("age");
m.buildIndex("verticesByAge", Vertex.class).addKey(age).buildCompositeIndex();
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to REGISTERED
assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge").status(SchemaStatus.REGISTERED).call().getSucceeded());
m = graph.openManagement();
JanusGraphIndex index = m.getGraphIndex("verticesByAge");
m.updateIndex(index, SchemaAction.ENABLE_INDEX);
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to ENABLED
assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge").status(SchemaStatus.ENABLED).call().getSucceeded());
// Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
assertFalse(graph.query().has("age", 10000).vertices().iterator().hasNext());
// Repair
MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
m = graph.openManagement();
index = m.getGraphIndex("verticesByAge");
ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
assertEquals(6, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
// Test the index
Iterable<JanusGraphVertex> hits = graph.query().has("age", 4500).vertices();
assertNotNull(hits);
assertEquals(1, Iterables.size(hits));
JanusGraphVertex v = Iterables.getOnlyElement(hits);
assertNotNull(v);
assertEquals("neptune", v.value("name"));
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class SaslAndHMACAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.
@Test
public void testSetupEmptyCredGraphNoUserIndex() {
final SaslAndHMACAuthenticator authenticator = createMockBuilder(SaslAndHMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").addMockedMethod("createHMACAuthenticator").createMock();
final Map<String, Object> configMap = new HashMap<String, Object>();
configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_USER, "user");
final JanusGraph graph = createMock(JanusGraph.class);
final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
final ManagementSystem mgmt = createMock(ManagementSystem.class);
final JanusGraphSimpleAuthenticator janusSimpleAuthenticator = createMock(JanusGraphSimpleAuthenticator.class);
final HMACAuthenticator hmacAuthenticator = createMock(HMACAuthenticator.class);
final SimpleAuthenticator simpleAuthenticator = createMock(SimpleAuthenticator.class);
final Transaction tx = createMock(Transaction.class);
final PropertyKey pk = createMock(PropertyKey.class);
final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
final JanusGraphIndex index = createMock(JanusGraphIndex.class);
final PropertyKey[] pks = { pk };
expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
expect(authenticator.createSimpleAuthenticator()).andReturn(janusSimpleAuthenticator);
expect(authenticator.createHMACAuthenticator()).andReturn(hmacAuthenticator);
hmacAuthenticator.setup(configMap);
expectLastCall();
expect(janusSimpleAuthenticator.createSimpleAuthenticator()).andReturn(simpleAuthenticator);
simpleAuthenticator.setup(configMap);
expectLastCall();
expect(credentialGraph.findUser("user")).andReturn(null);
expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
expect(graph.openManagement()).andReturn(mgmt).times(2);
expect(graph.tx()).andReturn(tx);
expect(index.getFieldKeys()).andReturn(pks);
expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
tx.rollback();
expectLastCall();
expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
expect(pkm.dataType(eq(String.class))).andReturn(pkm);
expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
expect(pkm.make()).andReturn(pk);
expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
expect(indexBuilder.unique()).andReturn(indexBuilder);
expect(indexBuilder.buildCompositeIndex()).andReturn(index);
mgmt.commit();
expectLastCall();
mgmt.rollback();
expectLastCall();
replayAll();
authenticator.setup(configMap);
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class AbstractJanusGraphProvider method createIndices.
private void createIndices(final JanusGraph g, final LoadGraphWith.GraphData graphData) {
JanusGraphManagement management = g.openManagement();
if (graphData.equals(LoadGraphWith.GraphData.GRATEFUL)) {
VertexLabel artist = management.makeVertexLabel("artist").make();
VertexLabel song = management.makeVertexLabel("song").make();
PropertyKey name = management.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make();
PropertyKey songType = management.makePropertyKey("songType").cardinality(Cardinality.LIST).dataType(String.class).make();
PropertyKey performances = management.makePropertyKey("performances").cardinality(Cardinality.LIST).dataType(Integer.class).make();
management.buildIndex("artistByName", Vertex.class).addKey(name).indexOnly(artist).buildCompositeIndex();
management.buildIndex("songByName", Vertex.class).addKey(name).indexOnly(song).buildCompositeIndex();
management.buildIndex("songByType", Vertex.class).addKey(songType).indexOnly(song).buildCompositeIndex();
management.buildIndex("songByPerformances", Vertex.class).addKey(performances).indexOnly(song).buildCompositeIndex();
} else if (graphData.equals(LoadGraphWith.GraphData.MODERN)) {
VertexLabel person = management.makeVertexLabel("person").make();
VertexLabel software = management.makeVertexLabel("software").make();
PropertyKey name = management.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make();
PropertyKey lang = management.makePropertyKey("lang").cardinality(Cardinality.LIST).dataType(String.class).make();
PropertyKey age = management.makePropertyKey("age").cardinality(Cardinality.LIST).dataType(Integer.class).make();
management.buildIndex("personByName", Vertex.class).addKey(name).indexOnly(person).buildCompositeIndex();
management.buildIndex("softwareByName", Vertex.class).addKey(name).indexOnly(software).buildCompositeIndex();
management.buildIndex("personByAge", Vertex.class).addKey(age).indexOnly(person).buildCompositeIndex();
management.buildIndex("softwareByLang", Vertex.class).addKey(lang).indexOnly(software).buildCompositeIndex();
} else if (graphData.equals(LoadGraphWith.GraphData.CLASSIC)) {
PropertyKey name = management.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make();
PropertyKey lang = management.makePropertyKey("lang").cardinality(Cardinality.LIST).dataType(String.class).make();
PropertyKey age = management.makePropertyKey("age").cardinality(Cardinality.LIST).dataType(Integer.class).make();
management.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex();
management.buildIndex("byAge", Vertex.class).addKey(age).buildCompositeIndex();
management.buildIndex("byLang", Vertex.class).addKey(lang).buildCompositeIndex();
} else {
// TODO: add CREW work here.
// TODO: add meta_property indices when meta_property graph is provided
// throw new RuntimeException("Could not load graph with " + graphData);
}
management.commit();
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphSimpleAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.
@Test
public void testSetupEmptyCredGraphNoUserIndex() {
final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").createMock();
final Map<String, Object> configMap = new HashMap<String, Object>();
configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_USER, "user");
final JanusGraph graph = createMock(JanusGraph.class);
final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
final ManagementSystem mgmt = createMock(ManagementSystem.class);
final Transaction tx = createMock(Transaction.class);
final PropertyKey pk = createMock(PropertyKey.class);
final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
final JanusGraphIndex index = createMock(JanusGraphIndex.class);
final PropertyKey[] pks = { pk };
final SimpleAuthenticator sa = createMock(SimpleAuthenticator.class);
expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
expect(authenticator.createSimpleAuthenticator()).andReturn(sa);
expect(credentialGraph.findUser("user")).andReturn(null);
expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
expect(graph.openManagement()).andReturn(mgmt);
expect(graph.tx()).andReturn(tx);
sa.setup(configMap);
EasyMock.expectLastCall();
graph.close();
EasyMock.expectLastCall();
tx.rollback();
EasyMock.expectLastCall();
expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
expect(pkm.dataType(eq(String.class))).andReturn(pkm);
expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
expect(pkm.make()).andReturn(pk);
expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
expect(indexBuilder.unique()).andReturn(indexBuilder);
expect(indexBuilder.buildCompositeIndex()).andReturn(index);
expect(index.getFieldKeys()).andReturn(pks);
expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
expect(graph.tx()).andReturn(tx);
expect(graph.openManagement()).andReturn(mgmt);
tx.rollback();
EasyMock.expectLastCall().atLeastOnce();
mgmt.commit();
EasyMock.expectLastCall();
mgmt.rollback();
EasyMock.expectLastCall();
replayAll();
authenticator.setup(configMap);
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class ConfigurationManagementGraph method createIndexIfDoesNotExist.
private void createIndexIfDoesNotExist(String indexName, String propertyKeyName, Class dataType, boolean unique) {
graph.tx().rollback();
JanusGraphManagement management = graph.openManagement();
if (null == management.getGraphIndex(indexName)) {
final PropertyKey key = management.makePropertyKey(propertyKeyName).dataType(dataType).make();
final JanusGraphIndex index;
if (unique)
index = management.buildIndex(indexName, Vertex.class).addKey(key).unique().buildCompositeIndex();
else
index = management.buildIndex(indexName, Vertex.class).addKey(key).buildCompositeIndex();
try {
if (index.getIndexStatus(key) == INSTALLED) {
management.commit();
ManagementSystem.awaitGraphIndexStatus(graph, indexName).call();
management = graph.openManagement();
management.updateIndex(index, ENABLE_INDEX).get();
} else if (index.getIndexStatus(key) == REGISTERED) {
management.updateIndex(index, ENABLE_INDEX).get();
}
} catch (InterruptedException | ExecutionException e) {
log.warn("Failed to create index {} for ConfigurationManagementGraph with exception: {}", indexName, e.toString());
management.rollback();
graph.tx().rollback();
}
management.commit();
graph.tx().commit();
}
}
Aggregations