* ============LICENSE_START==========================================
* org.onap.aai
* ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 Amdocs
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
* ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.champtitan.graph.impl;
+import java.security.SecureRandom;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.Map.Entry;
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 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 {
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");
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;
}
}
} catch (InterruptedException e) {
LOGGER.warn("Interrupted while waiting for object index creation status");
+ Thread.currentThread().interrupt();
return;
}
updateIndexMgmt.commit();
} catch (InterruptedException e) {
LOGGER.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);
.call();
} catch (InterruptedException e) {
LOGGER.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("No default indexes being created");
+ }
}