aboutsummaryrefslogtreecommitdiffstats
path: root/champ-lib/champ-titan
diff options
context:
space:
mode:
authorDaniel Silverthorn <daniel.silverthorn@amdocs.com>2019-03-15 14:20:53 -0400
committerDaniel Silverthorn <daniel.silverthorn@amdocs.com>2019-03-15 14:36:49 -0400
commit56253dc9561d5b24919bf59f83ccc55934d8ad50 (patch)
treee9e1815a84338ae615cbbbf05df1b24a96d71939 /champ-lib/champ-titan
parent73fc9e36510c27899e60a707e8fcadb8a759f0d1 (diff)
Create vertex and edge indicies on startup
Change-Id: I3ee538796e21a0667df4b4dbbdfec40f5b4ca30d Issue-ID: AAI-2265 Signed-off-by: Daniel Silverthorn <daniel.silverthorn@amdocs.com>
Diffstat (limited to 'champ-lib/champ-titan')
-rw-r--r--champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/TitanChampGraphImpl.java29
-rw-r--r--champ-lib/champ-titan/src/test/java/org/onap/aai/champtitan/perf/ChampAPIPerformanceTest.java4
2 files changed, 27 insertions, 6 deletions
diff --git a/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/TitanChampGraphImpl.java b/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/TitanChampGraphImpl.java
index 209bf79..293b51c 100644
--- a/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/TitanChampGraphImpl.java
+++ b/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/TitanChampGraphImpl.java
@@ -36,6 +36,7 @@ import org.onap.aai.champcore.exceptions.ChampIndexNotExistsException;
import org.onap.aai.champcore.exceptions.ChampSchemaViolationException;
import org.onap.aai.champcore.graph.impl.AbstractTinkerpopChampGraph;
import org.onap.aai.champcore.model.ChampCardinality;
+import org.onap.aai.champcore.model.ChampField;
import org.onap.aai.champcore.model.ChampObject;
import org.onap.aai.champcore.model.ChampObjectConstraint;
import org.onap.aai.champcore.model.ChampObjectIndex;
@@ -61,6 +62,7 @@ import com.thinkaurelius.titan.core.schema.SchemaAction;
import com.thinkaurelius.titan.core.schema.SchemaStatus;
import com.thinkaurelius.titan.core.schema.TitanGraphIndex;
import com.thinkaurelius.titan.core.schema.TitanManagement;
+import com.thinkaurelius.titan.core.schema.TitanManagement.IndexBuilder;
import com.thinkaurelius.titan.graphdb.database.management.ManagementSystem;
public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph {
@@ -171,15 +173,18 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph {
final TitanGraph graph = getGraph();
final TitanManagement createIndexMgmt = graph.openManagement();
- final PropertyKey pk = createIndexMgmt.getOrCreatePropertyKey(index.getField().getName());
if (createIndexMgmt.getGraphIndex(index.getName()) != null) {
createIndexMgmt.rollback();
return; //Ignore, index already exists
}
- createIndexMgmt.buildIndex(index.getName(), Vertex.class).addKey(pk).buildCompositeIndex();
-
+ IndexBuilder ib = createIndexMgmt.buildIndex(index.getName(), Vertex.class);
+ for (ChampField field : index.getFields()) {
+ PropertyKey pk = createIndexMgmt.getOrCreatePropertyKey(field.getName());
+ ib = ib.addKey(pk);
+ }
+ ib.buildCompositeIndex();
createIndexMgmt.commit();
graph.tx().commit();
@@ -195,11 +200,15 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph {
if (index == null) return Optional.empty();
if (index.getIndexedElement() != TitanVertex.class) return Optional.empty();
+ List<String> fieldNames = new ArrayList<String>();
+ for (int i = 0; i < index.getFieldKeys().length; i++) {
+ fieldNames.add(index.getFieldKeys()[i].name());
+ }
return Optional.of(ChampObjectIndex.create()
.ofName(indexName)
.onType(ChampObject.ReservedTypes.ANY.toString())
- .forField(index.getFieldKeys()[0].name())
+ .forFields(fieldNames)
.build());
}
@@ -218,11 +227,16 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph {
public boolean hasNext() {
if (indices.hasNext()) {
final TitanGraphIndex index = indices.next();
+
+ List<String> fieldNames = new ArrayList<String>();
+ for (int i = 0; i < index.getFieldKeys().length; i++) {
+ fieldNames.add(index.getFieldKeys()[i].name());
+ }
next = ChampObjectIndex.create()
.ofName(index.name())
.onType(ChampObject.ReservedTypes.ANY.toString())
- .forField(index.getFieldKeys()[0].name())
+ .forFields(fieldNames)
.build();
return true;
}
@@ -472,4 +486,9 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph {
public GraphTraversal<?, ?> hasLabel(GraphTraversal<?, ?> query, Object type) {
return query.hasLabel((String) type);
}
+
+ @Override
+ public void createDefaultIndexes() {
+ LOGGER.error("No default indexes being created");
+ }
}
diff --git a/champ-lib/champ-titan/src/test/java/org/onap/aai/champtitan/perf/ChampAPIPerformanceTest.java b/champ-lib/champ-titan/src/test/java/org/onap/aai/champtitan/perf/ChampAPIPerformanceTest.java
index cb9ad91..89dbe96 100644
--- a/champ-lib/champ-titan/src/test/java/org/onap/aai/champtitan/perf/ChampAPIPerformanceTest.java
+++ b/champ-lib/champ-titan/src/test/java/org/onap/aai/champtitan/perf/ChampAPIPerformanceTest.java
@@ -225,11 +225,13 @@ public class ChampAPIPerformanceTest {
}
private static void storeIndices(ChampGraph graph, boolean warmUp) {
+ List<String> fields = new ArrayList<String>();
+ fields.add("objectNumber");
graph.storeObjectIndex(
ChampObjectIndex.create()
.ofName("objectNumberIndex")
.onType("foo")
- .forField("objectNumber")
+ .forFields(fields)
.build()
);