*/
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;
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;
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;
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";
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");
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();
}
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();
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());
}
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;
}
.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;
}
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 {
.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;
}
}
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");
+ }
}