diff options
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans')
11 files changed, 655 insertions, 0 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ArtifactCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ArtifactCassandraDaoMock.java new file mode 100644 index 0000000000..290ba07883 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ArtifactCassandraDaoMock.java @@ -0,0 +1,15 @@ +package org.openecomp.sdc.be.components.path.beans; + +import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component("artifact-cassandra-dao") +public class ArtifactCassandraDaoMock extends ArtifactCassandraDao { + @PostConstruct + @Override + public void init() { + + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/AuditCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/AuditCassandraDaoMock.java new file mode 100644 index 0000000000..c4885e1f07 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/AuditCassandraDaoMock.java @@ -0,0 +1,15 @@ +package org.openecomp.sdc.be.components.path.beans; + +import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component("audit-cassandra-dao") +public class AuditCassandraDaoMock extends AuditCassandraDao{ + + @PostConstruct + public void init() { + + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/CassandraClientMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/CassandraClientMock.java new file mode 100644 index 0000000000..0d4b2f1e7e --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/CassandraClientMock.java @@ -0,0 +1,21 @@ +package org.openecomp.sdc.be.components.path.beans; + +import com.datastax.driver.core.Session; +import com.datastax.driver.mapping.MappingManager; +import fj.data.Either; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; +import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; +import org.springframework.stereotype.Component; + +@Component("cassandra-client") +public class CassandraClientMock extends CassandraClient{ + public CassandraClientMock() { + + } + + @Override + public Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> connect(String keyspace) { + return null; + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ComponentCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ComponentCassandraDaoMock.java new file mode 100644 index 0000000000..6a9731e86d --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ComponentCassandraDaoMock.java @@ -0,0 +1,68 @@ +package org.openecomp.sdc.be.components.path.beans; + +import fj.data.Either; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; +import org.openecomp.sdc.be.dao.cassandra.ComponentCacheAccessor; +import org.openecomp.sdc.be.dao.cassandra.ComponentCassandraDao; +import org.openecomp.sdc.be.resources.data.ComponentCacheData; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@Component("component-cassandra-dao") +public class ComponentCassandraDaoMock extends ComponentCassandraDao { + + public static Integer DEFAULT_FETCH_SIZE = 500; + private ComponentCacheAccessor componentCacheAccessor; + + public ComponentCassandraDaoMock() { + super(); + } + + @PostConstruct + public void init() { + + } + + public Either<List<ComponentCacheData>, ActionStatus> getComponents(List<String> ids) { + + return null; + } + + public Either<List<ComponentCacheData>, ActionStatus> getAllComponentIdTimeAndType() { + return null; + } + + + public Either<ComponentCacheData, ActionStatus> getComponent(String id) { + + return null; + } + + public CassandraOperationStatus saveComponent(ComponentCacheData componentCacheData) { + return null; + } + + + public Either<Boolean, CassandraOperationStatus> isTableEmpty(String tableName) { + return null; + } + + + public Either<ImmutablePair<List<ComponentCacheData>, Set<String>>, ActionStatus> getComponents( + Map<String, Long> idToTimestampMap) { + + return null; + } + + public CassandraOperationStatus deleteComponent(String id) { + return null; + } + + } + diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/DistributionEngineMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/DistributionEngineMock.java new file mode 100644 index 0000000000..748ae56bd7 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/DistributionEngineMock.java @@ -0,0 +1,61 @@ +package org.openecomp.sdc.be.components.path.beans; + +import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine; +import org.openecomp.sdc.be.components.distribution.engine.INotificationData; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry; + +public class DistributionEngineMock implements IDistributionEngine { + @Override + public boolean isActive() { + return false; + } + + @Override + public ActionStatus notifyService(String distributionId, Service service, INotificationData notificationData, String envName, String userId, String modifierName) { + return null; + } + + @Override + public ActionStatus notifyService(String distributionId, Service service, INotificationData notificationData, String envId, String envName, String userId, String modifierName) { + return null; + } + + @Override + public StorageOperationStatus isEnvironmentAvailable(String envName) { + return null; + } + + @Override + public StorageOperationStatus isEnvironmentAvailable() { + return null; + } + + @Override + public void disableEnvironment(String envName) { + + } + + @Override + public StorageOperationStatus isReadyForDistribution(Service service, String envName) { + return null; + } + + @Override + public INotificationData buildServiceForDistribution(Service service, String distributionId, String workloadContext) { + return null; + } + + @Override + public StorageOperationStatus verifyServiceHasDeploymentArtifacts(Service service) { + return null; + } + + @Override + public OperationalEnvironmentEntry getEnvironmentById(String opEnvId) { + return null; + } + +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/EnvironmentCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/EnvironmentCassandraDaoMock.java new file mode 100644 index 0000000000..2d7b1ad287 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/EnvironmentCassandraDaoMock.java @@ -0,0 +1,15 @@ +package org.openecomp.sdc.be.components.path.beans; + +import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component("operational-environment-dao") +public class EnvironmentCassandraDaoMock extends OperationalEnvironmentDao { + @PostConstruct + @Override + public void init() { + + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathToscaOperationFacade.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathToscaOperationFacade.java new file mode 100644 index 0000000000..09e1a72b44 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathToscaOperationFacade.java @@ -0,0 +1,45 @@ +package org.openecomp.sdc.be.components.path.beans; + +import fj.data.Either; +import org.openecomp.sdc.be.impl.ForwardingPathUtils; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; + +@org.springframework.stereotype.Component("tosca-operation-facade") +public class ForwardingPathToscaOperationFacade extends ToscaOperationFacade { + protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service"; + @Override + public Either<Resource, StorageOperationStatus> getLatestCertifiedNodeTypeByToscaResourceName(String toscaResourceName) { + + return Either.left(setupGenericServiceMock()); + } + + protected Resource setupGenericServiceMock(){ + Resource genericService = new Resource(); + genericService.setVersion("1.0"); + genericService.setToscaResourceName(GENERIC_SERVICE_NAME); + return genericService; + } + + @Override + public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName) { + if(resourceName.equals(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME) || resourceName.equals(ForwardingPathUtils.FORWARDER_CAPABILITY)){ + Resource component = new Resource(); + component.setToscaResourceName(GENERIC_SERVICE_NAME); + return Either.left((T)component); + } + return super.getLatestByName(resourceName); + } + + @Override + public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) { + if(toscaResourceName.equals(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME) || toscaResourceName.equals(ForwardingPathUtils.FORWARDER_CAPABILITY)){ + Resource component = new Resource(); + component.setToscaResourceName(GENERIC_SERVICE_NAME); + return Either.left((T)component); + } + return super.getLatestByToscaResourceName(toscaResourceName); + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathValidatorMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathValidatorMock.java new file mode 100644 index 0000000000..1aa3ab8102 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathValidatorMock.java @@ -0,0 +1,16 @@ +package org.openecomp.sdc.be.components.path.beans; + +import fj.data.Either; +import org.openecomp.sdc.be.components.path.ForwardingPathValidator; +import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; +import org.openecomp.sdc.exception.ResponseFormat; + +import java.util.Collection; + +public class ForwardingPathValidatorMock extends ForwardingPathValidator { + @Override + public Either<Boolean, ResponseFormat> validateForwardingPaths(Collection<ForwardingPathDataDefinition> paths, String serviceId, + boolean isUpdate) { + return Either.left(Boolean.TRUE); + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/InMemoryTitanGraphClient.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/InMemoryTitanGraphClient.java new file mode 100644 index 0000000000..4e3923d2ea --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/InMemoryTitanGraphClient.java @@ -0,0 +1,218 @@ +package org.openecomp.sdc.be.components.path.beans; + + +import com.thinkaurelius.titan.core.InvalidElementException; +import com.thinkaurelius.titan.core.InvalidIDException; +import com.thinkaurelius.titan.core.PropertyKey; +import com.thinkaurelius.titan.core.QueryException; +import com.thinkaurelius.titan.core.SchemaViolationException; +import com.thinkaurelius.titan.core.TitanConfigurationException; +import com.thinkaurelius.titan.core.TitanFactory; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.schema.ConsistencyModifier; +import com.thinkaurelius.titan.core.schema.TitanGraphIndex; +import com.thinkaurelius.titan.core.schema.TitanManagement; +import com.thinkaurelius.titan.core.util.TitanCleanup; +import com.thinkaurelius.titan.diskstorage.ResourceUnavailableException; +import com.thinkaurelius.titan.diskstorage.locking.PermanentLockingException; +import com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException; +import fj.data.Either; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.openecomp.sdc.be.dao.TitanClientStrategy; +import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; +import org.openecomp.sdc.be.dao.titan.TitanGraphClient; +import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.HashMap; + +@Component("titan-client") +public class InMemoryTitanGraphClient extends TitanGraphClient { + + + private static final Logger logger = LoggerFactory.getLogger(InMemoryTitanGraphClient.class); + + private static final String OK = "GOOD"; + + public InMemoryTitanGraphClient() { + } + + + private TitanGraph graph; + TitanClientStrategy titanClientStrategy; + + public InMemoryTitanGraphClient(TitanClientStrategy titanClientStrategy) { + super(); + this.titanClientStrategy = titanClientStrategy; + logger.info("** TitanGraphClient created"); + } + + @PostConstruct + public TitanOperationStatus createGraph() { + + logger.info("** createGraph started **"); + graph = TitanFactory.build().set("storage.backend", "inmemory").open(); + createTitanSchema(); + + logger.info("** in memory graph created"); + return TitanOperationStatus.OK; + + } + + + public void cleanupGraph() { + if (graph != null) { + // graph.shutdown(); + graph.close(); + TitanCleanup.clear(graph); + } + } + + public TitanOperationStatus createGraph(String titanCfgFile) { + logger.info("** open graph with {} started", titanCfgFile); + try { + logger.info("openGraph : try to load file {}", titanCfgFile); + graph = TitanFactory.open(titanCfgFile); + if (graph.isClosed()) { + logger.error("titan graph was not initialized"); + return TitanOperationStatus.NOT_CREATED; + } + + } catch (Exception e) { + this.graph = null; + logger.info("createGraph : failed to open Titan graph with configuration file: {}", titanCfgFile, e); + return TitanOperationStatus.NOT_CONNECTED; + } + + logger.info("** Titan graph created "); + + return TitanOperationStatus.OK; + } + + + public Either<TitanGraph, TitanOperationStatus> getGraph() { + if (graph != null) { + return Either.left(graph); + } else { + return Either.right(TitanOperationStatus.NOT_CREATED); + } + } + + public TitanOperationStatus commit() { + if (graph != null) { + try { + graph.tx().commit(); + return TitanOperationStatus.OK; + } catch (Exception e) { + return handleTitanException(e); + } + } else { + return TitanOperationStatus.NOT_CREATED; + } + } + + public TitanOperationStatus rollback() { + if (graph != null) { + try { + // graph.rollback(); + graph.tx().rollback(); + return TitanOperationStatus.OK; + } catch (Exception e) { + return handleTitanException(e); + } + } else { + return TitanOperationStatus.NOT_CREATED; + } + } + + public static TitanOperationStatus handleTitanException(Exception e) { + if (e instanceof TitanConfigurationException) { + return TitanOperationStatus.TITAN_CONFIGURATION; + } + if (e instanceof SchemaViolationException) { + return TitanOperationStatus.TITAN_SCHEMA_VIOLATION; + } + if (e instanceof PermanentLockingException) { + return TitanOperationStatus.TITAN_SCHEMA_VIOLATION; + } + if (e instanceof IDPoolExhaustedException) { + return TitanOperationStatus.GENERAL_ERROR; + } + if (e instanceof InvalidElementException) { + return TitanOperationStatus.INVALID_ELEMENT; + } + if (e instanceof InvalidIDException) { + return TitanOperationStatus.INVALID_ID; + } + if (e instanceof QueryException) { + return TitanOperationStatus.INVALID_QUERY; + } + if (e instanceof ResourceUnavailableException) { + return TitanOperationStatus.RESOURCE_UNAVAILABLE; + } + if (e instanceof IllegalArgumentException) { + // TODO check the error message?? + return TitanOperationStatus.ILLEGAL_ARGUMENT; + } + + return TitanOperationStatus.GENERAL_ERROR; + } + + public boolean getHealth() { + return true; + } + + private boolean isGraphOpen() { + return true; + } + + + private static final String TITAN_HEALTH_CHECK_STR = "titanHealthCheck"; + + + private void createTitanSchema() { + + TitanManagement graphMgt = graph.openManagement(); + TitanGraphIndex index = null; + for (GraphPropertiesDictionary prop : GraphPropertiesDictionary.values()) { + PropertyKey propKey = null; + if (!graphMgt.containsPropertyKey(prop.getProperty())) { + Class<?> clazz = prop.getClazz(); + if (!ArrayList.class.getName().equals(clazz.getName()) && !HashMap.class.getName().equals(clazz.getName())) { + propKey = graphMgt.makePropertyKey(prop.getProperty()).dataType(prop.getClazz()).make(); + } + } else { + propKey = graphMgt.getPropertyKey(prop.getProperty()); + } + if (prop.isIndexed()) { + if (!graphMgt.containsGraphIndex(prop.getProperty())) { + if (prop.isUnique()) { + index = graphMgt.buildIndex(prop.getProperty(), Vertex.class).addKey(propKey).unique().buildCompositeIndex(); + + graphMgt.setConsistency(propKey, ConsistencyModifier.LOCK); // Ensures + // only + // one + // name + // per + // vertex + graphMgt.setConsistency(index, ConsistencyModifier.LOCK); // Ensures + // name + // uniqueness + // in + // the + // graph + + } else { + graphMgt.buildIndex(prop.getProperty(), Vertex.class).addKey(propKey).buildCompositeIndex(); + } + } + } + } + graphMgt.commit(); + } + +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/SdcSchemaFilesCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/SdcSchemaFilesCassandraDaoMock.java new file mode 100644 index 0000000000..4e0105f067 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/SdcSchemaFilesCassandraDaoMock.java @@ -0,0 +1,15 @@ +package org.openecomp.sdc.be.components.path.beans; + +import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component("sdc-schema-files-cassandra-dao") +public class SdcSchemaFilesCassandraDaoMock extends SdcSchemaFilesCassandraDao { + + @PostConstruct + @Override + public void init() { + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/TitanGraphTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/TitanGraphTestSetup.java new file mode 100644 index 0000000000..7a7eff879a --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/TitanGraphTestSetup.java @@ -0,0 +1,166 @@ +package org.openecomp.sdc.be.components.path.beans; + +import com.thinkaurelius.titan.core.PropertyKey; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanGraphQuery; +import com.thinkaurelius.titan.core.schema.ConsistencyModifier; +import com.thinkaurelius.titan.core.schema.TitanGraphIndex; +import com.thinkaurelius.titan.core.schema.TitanManagement; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.openecomp.sdc.be.dao.graph.datatype.ActionEnum; +import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.dao.jsongraph.utils.IdBuilderUtils; +import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary; +import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; +import org.openecomp.sdc.be.dao.utils.UserStatusEnum; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; +import org.openecomp.sdc.be.resources.data.UserData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class TitanGraphTestSetup { + + + private static final Logger logger = LoggerFactory.getLogger(TitanGraphTestSetup.class); + + private static TitanGraph graph; + + public static boolean createGraph( TitanGraph graph) { + TitanGraphTestSetup.graph = graph; + createIndexesAndDefaults(); + + logger.info("** Titan graph created "); + + return true; + } + + private static boolean isVertexExist(Map<String, Object> properties) { + TitanGraphQuery query = graph.query(); + + if (properties != null && !properties.isEmpty()) { + for (Map.Entry<String, Object> entry : properties.entrySet()) { + query = query.has(entry.getKey(), entry.getValue()); + } + } + Iterable<Vertex> vertecies = query.vertices(); + java.util.Iterator<Vertex> iterator = vertecies.iterator(); + if (iterator.hasNext()) { + return true; + } + return false; + } + + private static void createDefaultAdminUser() { + createUser(getDefaultUserAdmin()); + graph.tx().commit(); + + } + + private static void createUser(UserData user) { + Map<String, Object> checkedProperties = new HashMap<>(); + checkedProperties.put(GraphPropertiesDictionary.USERID.getProperty(), user.getUserId()); + checkedProperties.put(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.User.getName()); + Map<String, Object> properties = null; + if (!isVertexExist(checkedProperties)) { + Vertex vertex = graph.addVertex(); + vertex.property(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.User.getName()); + properties = user.toGraphMap(); + for (Map.Entry<String, Object> entry : properties.entrySet()) { + vertex.property(entry.getKey(), entry.getValue()); + } + } + } + + private static UserData getDefaultUserAdmin() { + UserData userData = new UserData(); + userData.setAction(ActionEnum.Create); + userData.setElementType(GraphElementTypeEnum.Node); + userData.setUserId("jh0003"); + userData.setEmail("admin@sdc.com"); + userData.setFirstName("Jimmy"); + userData.setLastName("Hendrix"); + userData.setRole("ADMIN"); + userData.setStatus(UserStatusEnum.ACTIVE.name()); + userData.setLastLoginTime(0L); + return userData; + } + + + private static void createVertexIndixes() { + logger.info("** createVertexIndixes started"); + + TitanManagement graphMgt = graph.openManagement(); + TitanGraphIndex index = null; + for (GraphPropertiesDictionary prop : GraphPropertiesDictionary.values()) { + PropertyKey propKey = null; + if (!graphMgt.containsPropertyKey(prop.getProperty())) { + Class<?> clazz = prop.getClazz(); + if (!ArrayList.class.getName().equals(clazz.getName()) && !HashMap.class.getName().equals(clazz.getName())) { + propKey = graphMgt.makePropertyKey(prop.getProperty()).dataType(prop.getClazz()).make(); + } + } else { + propKey = graphMgt.getPropertyKey(prop.getProperty()); + } + if (prop.isIndexed()) { + if (!graphMgt.containsGraphIndex(prop.getProperty())) { + if (prop.isUnique()) { + index = graphMgt.buildIndex(prop.getProperty(), Vertex.class).addKey(propKey).unique().buildCompositeIndex(); + + graphMgt.setConsistency(propKey, ConsistencyModifier.LOCK); // Ensures + // only + // one + // name + // per + // vertex + graphMgt.setConsistency(index, ConsistencyModifier.LOCK); // Ensures + // name + // uniqueness + // in + // the + // graph + + } else { + graphMgt.buildIndex(prop.getProperty(), Vertex.class).addKey(propKey).buildCompositeIndex(); + } + } + } + } + graphMgt.commit(); + logger.info("** createVertexIndixes ended"); + + } + + private static void createEdgeIndixes() { + logger.info("** createEdgeIndixes started"); + TitanManagement graphMgt = graph.openManagement(); + for (GraphEdgePropertiesDictionary prop : GraphEdgePropertiesDictionary.values()) { + if (!graphMgt.containsGraphIndex(prop.getProperty())) { + PropertyKey propKey = graphMgt.makePropertyKey(prop.getProperty()).dataType(prop.getClazz()).make(); + graphMgt.buildIndex(prop.getProperty(), Edge.class).addKey(propKey).buildCompositeIndex(); + + } + } + graphMgt.commit(); + logger.info("** createEdgeIndixes ended"); + } + + private static void createIndexesAndDefaults() { + createVertexIndixes(); + createEdgeIndixes(); + createDefaultAdminUser(); + createRootCatalogVertex(); + } + private static void createRootCatalogVertex(){ + Vertex vertex = graph.addVertex(); + vertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty(), IdBuilderUtils.generateUniqueId()); + vertex.property(GraphPropertyEnum.LABEL.getProperty(), VertexTypeEnum.CATALOG_ROOT.getName()); + graph.tx().commit(); + } +} |