2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.aai.db.schema;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.Iterator;
27 import java.util.LinkedHashSet;
28 import java.util.List;
31 import org.apache.tinkerpop.gremlin.structure.Vertex;
33 import com.thinkaurelius.titan.core.EdgeLabel;
34 import com.thinkaurelius.titan.core.PropertyKey;
35 import com.thinkaurelius.titan.core.TitanGraph;
36 import com.thinkaurelius.titan.core.schema.TitanGraphIndex;
37 import com.thinkaurelius.titan.core.schema.TitanManagement;
39 public class AuditTitan extends Auditor {
41 private final TitanGraph graph;
44 * Instantiates a new audit titan.
48 public AuditTitan (TitanGraph g) {
56 private void buildSchema() {
63 * Populate properties.
65 private void populateProperties() {
66 TitanManagement mgmt = graph.openManagement();
67 Iterable<PropertyKey> iterable = mgmt.getRelationTypes(PropertyKey.class);
68 Iterator<PropertyKey> titanProperties = iterable.iterator();
69 PropertyKey propKey = null;
70 while (titanProperties.hasNext()) {
71 propKey = titanProperties.next();
72 DBProperty prop = new DBProperty();
74 prop.setName(propKey.name());
75 prop.setCardinality(propKey.cardinality());
76 prop.setTypeClass(propKey.dataType());
78 this.properties.put(prop.getName(), prop);
85 private void populateIndexes() {
86 TitanManagement mgmt = graph.openManagement();
87 Iterable<TitanGraphIndex> iterable = mgmt.getGraphIndexes(Vertex.class);
88 Iterator<TitanGraphIndex> titanIndexes = iterable.iterator();
89 TitanGraphIndex titanIndex = null;
90 while (titanIndexes.hasNext()) {
91 titanIndex = titanIndexes.next();
92 if (titanIndex.isCompositeIndex()) {
93 DBIndex index = new DBIndex();
94 LinkedHashSet<DBProperty> dbProperties = new LinkedHashSet<>();
95 index.setName(titanIndex.name());
96 index.setUnique(titanIndex.isUnique());
97 PropertyKey[] keys = titanIndex.getFieldKeys();
98 for (PropertyKey key : keys) {
99 dbProperties.add(this.properties.get(key.name()));
101 index.setProperties(dbProperties);
102 index.setStatus(titanIndex.getIndexStatus(keys[0]));
103 this.indexes.put(index.getName(), index);
109 * Populate edge labels.
111 private void populateEdgeLabels() {
112 TitanManagement mgmt = graph.openManagement();
113 Iterable<EdgeLabel> iterable = mgmt.getRelationTypes(EdgeLabel.class);
114 Iterator<EdgeLabel> titanEdgeLabels = iterable.iterator();
115 EdgeLabel edgeLabel = null;
116 while (titanEdgeLabels.hasNext()) {
117 edgeLabel = titanEdgeLabels.next();
118 EdgeProperty edgeProperty = new EdgeProperty();
120 edgeProperty.setName(edgeLabel.name());
121 edgeProperty.setMultiplicity(edgeLabel.multiplicity());
123 this.edgeLabels.put(edgeProperty.getName(), edgeProperty);