2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.db.schema;
25 import java.util.Iterator;
26 import java.util.LinkedHashSet;
28 import org.apache.tinkerpop.gremlin.structure.Vertex;
30 import com.thinkaurelius.titan.core.EdgeLabel;
31 import com.thinkaurelius.titan.core.PropertyKey;
32 import com.thinkaurelius.titan.core.TitanGraph;
33 import com.thinkaurelius.titan.core.schema.TitanGraphIndex;
34 import com.thinkaurelius.titan.core.schema.TitanManagement;
36 public class AuditTitan extends Auditor {
38 private final TitanGraph graph;
41 * Instantiates a new audit titan.
45 public AuditTitan (TitanGraph g) {
53 private void buildSchema() {
60 * Populate properties.
62 private void populateProperties() {
63 TitanManagement mgmt = graph.openManagement();
64 Iterable<PropertyKey> iterable = mgmt.getRelationTypes(PropertyKey.class);
65 Iterator<PropertyKey> titanProperties = iterable.iterator();
67 while (titanProperties.hasNext()) {
68 propKey = titanProperties.next();
69 DBProperty prop = new DBProperty();
71 prop.setName(propKey.name());
72 prop.setCardinality(propKey.cardinality());
73 prop.setTypeClass(propKey.dataType());
75 this.properties.put(prop.getName(), prop);
82 private void populateIndexes() {
83 TitanManagement mgmt = graph.openManagement();
84 Iterable<TitanGraphIndex> iterable = mgmt.getGraphIndexes(Vertex.class);
85 Iterator<TitanGraphIndex> titanIndexes = iterable.iterator();
86 TitanGraphIndex titanIndex;
87 while (titanIndexes.hasNext()) {
88 titanIndex = titanIndexes.next();
89 if (titanIndex.isCompositeIndex()) {
90 DBIndex index = new DBIndex();
91 LinkedHashSet<DBProperty> dbProperties = new LinkedHashSet<>();
92 index.setName(titanIndex.name());
93 index.setUnique(titanIndex.isUnique());
94 PropertyKey[] keys = titanIndex.getFieldKeys();
95 for (PropertyKey key : keys) {
96 dbProperties.add(this.properties.get(key.name()));
98 index.setProperties(dbProperties);
99 index.setStatus(titanIndex.getIndexStatus(keys[0]));
100 this.indexes.put(index.getName(), index);
106 * Populate edge labels.
108 private void populateEdgeLabels() {
109 TitanManagement mgmt = graph.openManagement();
110 Iterable<EdgeLabel> iterable = mgmt.getRelationTypes(EdgeLabel.class);
111 Iterator<EdgeLabel> titanEdgeLabels = iterable.iterator();
113 while (titanEdgeLabels.hasNext()) {
114 edgeLabel = titanEdgeLabels.next();
115 EdgeProperty edgeProperty = new EdgeProperty();
117 edgeProperty.setName(edgeLabel.name());
118 edgeProperty.setMultiplicity(edgeLabel.multiplicity());
120 this.edgeLabels.put(edgeProperty.getName(), edgeProperty);