X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=champ-lib%2Fchamp-titan%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fchamptitan%2Fgraph%2Fimpl%2FTitanChampGraphImpl.java;h=2cec6ef6dbcaa53615a13f9eec3c713c4692f941;hb=e9f19eaf902ff2c1cdc02a5f90aa06fd582848a6;hp=d72d69d2118067f5b1411a3f218a4e7a38f08904;hpb=970b263b6b1e12e11d3de4147caea150d0b74051;p=aai%2Fchamp.git 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 d72d69d..2cec6ef 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 @@ -20,9 +20,18 @@ */ package org.onap.aai.champtitan.graph.impl; +import java.security.SecureRandom; import java.time.temporal.ChronoUnit; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.Spliterator; +import java.util.Spliterators; import java.util.concurrent.ExecutionException; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -31,12 +40,11 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.onap.aai.champcore.ChampCapabilities; -import org.onap.aai.champcore.FormatMapper; -import org.onap.aai.champcore.Formatter; 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; @@ -47,8 +55,8 @@ import org.onap.aai.champcore.model.ChampRelationshipIndex; import org.onap.aai.champcore.model.ChampSchema; import org.onap.aai.champcore.schema.ChampSchemaEnforcer; import org.onap.aai.champcore.schema.DefaultChampSchemaEnforcer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; import com.thinkaurelius.titan.core.Cardinality; import com.thinkaurelius.titan.core.EdgeLabel; @@ -62,11 +70,12 @@ 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 { - private static final Logger LOGGER = LoggerFactory.getLogger(TitanChampGraphImpl.class); + private static final Logger LOGGER = LoggerFactory.getInstance().getLogger(TitanChampGraphImpl.class); private static final String TITAN_UNIQUE_SUFFIX = "graph.unique-instance-id-suffix"; private static final String TITAN_CASSANDRA_KEYSPACE = "storage.cassandra.keyspace"; private static final String TITAN_HBASE_TABLE = "storage.hbase.table"; @@ -96,7 +105,7 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { titanGraphBuilder.set(titanGraphProperty.getKey(), titanGraphProperty.getValue()); } - titanGraphBuilder.set(TITAN_UNIQUE_SUFFIX, ((short) new Random().nextInt(Short.MAX_VALUE)+"")); + titanGraphBuilder.set(TITAN_UNIQUE_SUFFIX, ((short) new SecureRandom().nextInt(Short.MAX_VALUE)+"")); final Object storageBackend = builder.graphConfiguration.get("storage.backend"); @@ -114,7 +123,8 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { throw new RuntimeException("Unknown storage.backend=" + storageBackend); } - LOGGER.info("Instantiated data access layer for Titan graph data store with backend: " + storageBackend); + LOGGER.info(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_INFO, + "Instantiated data access layer for Titan graph data store with backend: " + storageBackend); this.graph = titanGraphBuilder.open(); } @@ -172,15 +182,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(); @@ -196,11 +209,15 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { if (index == null) return Optional.empty(); if (index.getIndexedElement() != TitanVertex.class) return Optional.empty(); + List fieldNames = new ArrayList(); + 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()); } @@ -219,11 +236,16 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { public boolean hasNext() { if (indices.hasNext()) { final TitanGraphIndex index = indices.next(); + + List fieldNames = new ArrayList(); + 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; } @@ -358,11 +380,14 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { .timeout(REGISTER_OBJECT_INDEX_TIMEOUT_SECS, ChronoUnit.SECONDS) .call() .getSucceeded()) { - LOGGER.warn("Object index was created, but timed out while waiting for it to be registered"); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Object index was created, but timed out while waiting for it to be registered"); return; } } catch (InterruptedException e) { - LOGGER.warn("Interrupted while waiting for object index creation status"); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Interrupted while waiting for object index creation status"); + Thread.currentThread().interrupt(); return; } @@ -373,10 +398,13 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { updateIndexMgmt.updateIndex(updateIndexMgmt.getGraphIndex(indexName),SchemaAction.REINDEX).get(); updateIndexMgmt.commit(); } catch (InterruptedException e) { - LOGGER.warn("Interrupted while reindexing for object index"); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Interrupted while reindexing for object index"); + Thread.currentThread().interrupt(); return; } catch (ExecutionException e) { - LOGGER.warn("Exception occurred during reindexing procedure for creating object index " + indexName, e); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Exception occurred during reindexing procedure for creating object index " + indexName + ". " + e.getMessage()); } try { @@ -385,7 +413,9 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { .timeout(10, ChronoUnit.MINUTES) .call(); } catch (InterruptedException e) { - LOGGER.warn("Interrupted while waiting for index to transition to ENABLED state"); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Interrupted while waiting for index to transition to ENABLED state"); + Thread.currentThread().interrupt(); return; } } @@ -470,4 +500,10 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { public GraphTraversal hasLabel(GraphTraversal query, Object type) { return query.hasLabel((String) type); } + + @Override + public void createDefaultIndexes() { + LOGGER.error(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_ERROR, + "No default indexes being created"); + } }