Commit 0b85d5a0 by Suma Shivaprasad

ATLAS-1240 Adding Change listeners to react on changes in TypesDef (apoorvnaik via sumasai)

parent 9dc4cfbc
...@@ -55,6 +55,11 @@ ...@@ -55,6 +55,11 @@
<version>${codehaus.jackson.version}</version> <version>${codehaus.jackson.version}</version>
</dependency> </dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>${javax-inject.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
......
...@@ -51,7 +51,10 @@ public enum AtlasErrorCode { ...@@ -51,7 +51,10 @@ public enum AtlasErrorCode {
TYPE_HAS_REFERENCES(409, "ATLAS4092E", "Given type {0} has references"), TYPE_HAS_REFERENCES(409, "ATLAS4092E", "Given type {0} has references"),
TYPE_MATCH_FAILED(409, "ATLAS4093E", "Given type {0} doesn't match {1}"), TYPE_MATCH_FAILED(409, "ATLAS4093E", "Given type {0} doesn't match {1}"),
INTERNAL_ERROR(500, "ATLAS5001E", "Internal server error {0}"); INTERNAL_ERROR(500, "ATLAS5001E", "Internal server error {0}"),
INDEX_CREATION_FAILED(500, "ATLAS5002E", "Index creation failed for {0}"),
INDEX_ROLLBACK_FAILED(500, "ATLAS5003E", "Index rollback failed for {0}")
;
private String errorCode; private String errorCode;
private String errorMessage; private String errorMessage;
......
...@@ -42,6 +42,11 @@ public class AtlasBaseException extends Exception { ...@@ -42,6 +42,11 @@ public class AtlasBaseException extends Exception {
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR; this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
} }
public AtlasBaseException(AtlasErrorCode errorCode, Throwable cause, String... params) {
super(errorCode.getFormattedErrorMessage(params), cause);
this.atlasErrorCode = errorCode;
}
public AtlasBaseException(String message, Throwable cause) { public AtlasBaseException(String message, Throwable cause) {
super(message, cause); super(message, cause);
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR; this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
...@@ -52,7 +57,14 @@ public class AtlasBaseException extends Exception { ...@@ -52,7 +57,14 @@ public class AtlasBaseException extends Exception {
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR; this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
} }
public AtlasBaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { public AtlasBaseException(AtlasErrorCode errorCode, Throwable cause, boolean enableSuppression,
boolean writableStackTrace, String ... params) {
super(errorCode.getFormattedErrorMessage(params), cause, enableSuppression, writableStackTrace);
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
}
public AtlasBaseException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace); super(message, cause, enableSuppression, writableStackTrace);
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR; this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
} }
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.listener;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import java.util.ArrayList;
import java.util.List;
public class ChangedTypeDefs {
private List<? extends AtlasBaseTypeDef> createTypeDefs;
private List<? extends AtlasBaseTypeDef> updatedTypeDefs;
private List<? extends AtlasBaseTypeDef> deletedTypeDefs;
public ChangedTypeDefs(List<? extends AtlasBaseTypeDef> createTypeDefs,
List<? extends AtlasBaseTypeDef> updatedTypeDefs,
List<? extends AtlasBaseTypeDef> deletedTypeDefs) {
this.createTypeDefs = createTypeDefs;
this.updatedTypeDefs = updatedTypeDefs;
this.deletedTypeDefs = deletedTypeDefs;
}
public ChangedTypeDefs() {
createTypeDefs = new ArrayList<>();
updatedTypeDefs = new ArrayList<>();
deletedTypeDefs = new ArrayList<>();
}
public List<? extends AtlasBaseTypeDef> getCreateTypeDefs() {
return createTypeDefs;
}
public ChangedTypeDefs setCreateTypeDefs(List<? extends AtlasBaseTypeDef> createTypeDefs) {
this.createTypeDefs = createTypeDefs;
return this;
}
public List<? extends AtlasBaseTypeDef> getUpdatedTypeDefs() {
return updatedTypeDefs;
}
public ChangedTypeDefs setUpdatedTypeDefs(List<? extends AtlasBaseTypeDef> updatedTypeDefs) {
this.updatedTypeDefs = updatedTypeDefs;
return this;
}
public List<? extends AtlasBaseTypeDef> getDeletedTypeDefs() {
return deletedTypeDefs;
}
public ChangedTypeDefs setDeletedTypeDefs(List<? extends AtlasBaseTypeDef> deletedTypeDefs) {
this.deletedTypeDefs = deletedTypeDefs;
return this;
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.listener;
import org.apache.atlas.exception.AtlasBaseException;
public interface TypeDefChangeListener {
void onChange(ChangedTypeDefs changedTypeDefs) throws AtlasBaseException;
}
...@@ -18,17 +18,19 @@ ...@@ -18,17 +18,19 @@
package org.apache.atlas.type; package org.apache.atlas.type;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_PREFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_SUFFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_PREFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_SUFFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_KEY_VAL_SEP;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_PREFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_SUFFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_KEY_VAL_SEP;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_PREFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_SUFFIX;
/** /**
* Utility methods for AtlasType/AtlasTypeDef. * Utility methods for AtlasType/AtlasTypeDef.
*/ */
...@@ -36,9 +38,7 @@ public class AtlasTypeUtil { ...@@ -36,9 +38,7 @@ public class AtlasTypeUtil {
private static final Set<String> ATLAS_BUILTIN_TYPENAMES = new HashSet<String>(); private static final Set<String> ATLAS_BUILTIN_TYPENAMES = new HashSet<String>();
static { static {
for (String typeName : AtlasBaseTypeDef.ATLAS_BUILTIN_TYPES) { Collections.addAll(ATLAS_BUILTIN_TYPENAMES, AtlasBaseTypeDef.ATLAS_BUILTIN_TYPES);
ATLAS_BUILTIN_TYPENAMES.add(typeName);
}
} }
public static Set<String> getReferencedTypeNames(String typeName) { public static Set<String> getReferencedTypeNames(String typeName) {
...@@ -63,6 +63,7 @@ public class AtlasTypeUtil { ...@@ -63,6 +63,7 @@ public class AtlasTypeUtil {
&& StringUtils.endsWith(typeName, ATLAS_TYPE_MAP_SUFFIX); && StringUtils.endsWith(typeName, ATLAS_TYPE_MAP_SUFFIX);
} }
public static String getStringValue(Map map, Object key) { public static String getStringValue(Map map, Object key) {
Object ret = map != null ? map.get(key) : null; Object ret = map != null ? map.get(key) : null;
...@@ -90,6 +91,5 @@ public class AtlasTypeUtil { ...@@ -90,6 +91,5 @@ public class AtlasTypeUtil {
referencedTypeNames.add(typeName); referencedTypeNames.add(typeName);
} }
} }
} }
} }
...@@ -17,17 +17,16 @@ ...@@ -17,17 +17,16 @@
*/ */
package org.apache.atlas.model.typedef; package org.apache.atlas.model.typedef;
import java.util.List;
import org.apache.atlas.model.ModelTestUtil; import org.apache.atlas.model.ModelTestUtil;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.List;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
public class TestAtlasStructDef { public class TestAtlasStructDef {
......
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
ATLAS-1240 Adding Change listeners to react on changes in TypesDef (apoorvnaik via sumasai)
ATLAS-1239 when stopping Atlas on the command line it should explicitly say when it has stopped (ayubkhan via sumasai) ATLAS-1239 when stopping Atlas on the command line it should explicitly say when it has stopped (ayubkhan via sumasai)
ATLAS-1253 Extract error codes into AtlasErrorCode Enum (apoorvnaik via sumasai) ATLAS-1253 Extract error codes into AtlasErrorCode Enum (apoorvnaik via sumasai)
ATLAS-1195 Clean up DSL Translation (jnhagelb via dkantor) ATLAS-1195 Clean up DSL Translation (jnhagelb via dkantor)
......
...@@ -29,6 +29,7 @@ import org.apache.atlas.discovery.DiscoveryService; ...@@ -29,6 +29,7 @@ import org.apache.atlas.discovery.DiscoveryService;
import org.apache.atlas.discovery.LineageService; import org.apache.atlas.discovery.LineageService;
import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService; import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
import org.apache.atlas.listener.EntityChangeListener; import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.listener.TypesChangeListener; import org.apache.atlas.listener.TypesChangeListener;
import org.apache.atlas.repository.MetadataRepository; import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.audit.EntityAuditListener; import org.apache.atlas.repository.audit.EntityAuditListener;
...@@ -76,6 +77,12 @@ public class RepositoryMetadataModule extends com.google.inject.AbstractModule { ...@@ -76,6 +77,12 @@ public class RepositoryMetadataModule extends com.google.inject.AbstractModule {
Multibinder.newSetBinder(binder(), TypesChangeListener.class); Multibinder.newSetBinder(binder(), TypesChangeListener.class);
typesChangeListenerBinder.addBinding().to(GraphBackedSearchIndexer.class).asEagerSingleton(); typesChangeListenerBinder.addBinding().to(GraphBackedSearchIndexer.class).asEagerSingleton();
// New typesdef/instance change listener should also be bound to the corresponding implementation
Multibinder<TypeDefChangeListener> typeDefChangeListenerMultibinder =
Multibinder.newSetBinder(binder(), TypeDefChangeListener.class);
typeDefChangeListenerMultibinder.addBinding().to(DefaultMetadataService.class);
typeDefChangeListenerMultibinder.addBinding().to(GraphBackedSearchIndexer.class).asEagerSingleton();
// bind the MetadataService interface to an implementation // bind the MetadataService interface to an implementation
bind(MetadataService.class).to(DefaultMetadataService.class).asEagerSingleton(); bind(MetadataService.class).to(DefaultMetadataService.class).asEagerSingleton();
......
...@@ -18,21 +18,22 @@ ...@@ -18,21 +18,22 @@
package org.apache.atlas.repository.graph; package org.apache.atlas.repository.graph;
import java.math.BigDecimal; import com.google.common.annotations.VisibleForTesting;
import java.math.BigInteger; import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.discovery.SearchIndexer; import org.apache.atlas.discovery.SearchIndexer;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.ha.HAConfiguration; import org.apache.atlas.ha.HAConfiguration;
import org.apache.atlas.listener.ActiveStateChangeHandler; import org.apache.atlas.listener.ActiveStateChangeHandler;
import org.apache.atlas.listener.ChangedTypeDefs;
import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.IndexCreationException; import org.apache.atlas.repository.IndexCreationException;
import org.apache.atlas.repository.IndexException; import org.apache.atlas.repository.IndexException;
...@@ -42,6 +43,13 @@ import org.apache.atlas.repository.graphdb.AtlasGraph; ...@@ -42,6 +43,13 @@ import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphIndex; import org.apache.atlas.repository.graphdb.AtlasGraphIndex;
import org.apache.atlas.repository.graphdb.AtlasGraphManagement; import org.apache.atlas.repository.graphdb.AtlasGraphManagement;
import org.apache.atlas.repository.graphdb.AtlasPropertyKey; import org.apache.atlas.repository.graphdb.AtlasPropertyKey;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasEnumType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.typesystem.types.AttributeInfo; import org.apache.atlas.typesystem.types.AttributeInfo;
import org.apache.atlas.typesystem.types.ClassType; import org.apache.atlas.typesystem.types.ClassType;
import org.apache.atlas.typesystem.types.DataTypes; import org.apache.atlas.typesystem.types.DataTypes;
...@@ -49,17 +57,39 @@ import org.apache.atlas.typesystem.types.IDataType; ...@@ -49,17 +57,39 @@ import org.apache.atlas.typesystem.types.IDataType;
import org.apache.atlas.typesystem.types.Multiplicity; import org.apache.atlas.typesystem.types.Multiplicity;
import org.apache.atlas.typesystem.types.StructType; import org.apache.atlas.typesystem.types.StructType;
import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TraitType;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting; import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BYTE;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_DATE;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_FLOAT;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_INT;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_LONG;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_SHORT;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_STRING;
/** /**
* Adds index for properties of a given type when its added before any instances are added. * Adds index for properties of a given type when its added before any instances are added.
*/ */
public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChangeHandler { public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChangeHandler,
TypeDefChangeListener {
private static final Logger LOG = LoggerFactory.getLogger(GraphBackedSearchIndexer.class); private static final Logger LOG = LoggerFactory.getLogger(GraphBackedSearchIndexer.class);
...@@ -70,19 +100,23 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -70,19 +100,23 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
add(BigInteger.class); add(BigInteger.class);
} }
}; };
// Added for type lookup when indexing the new typedefs
private final AtlasTypeRegistry typeRegistry;
//allows injection of a dummy graph for testing //allows injection of a dummy graph for testing
private IAtlasGraphProvider provider; private IAtlasGraphProvider provider;
@Inject @Inject
public GraphBackedSearchIndexer() throws RepositoryException, AtlasException { public GraphBackedSearchIndexer(AtlasTypeRegistry typeRegistry) throws AtlasException {
this(new AtlasGraphProvider(), ApplicationProperties.get()); this(new AtlasGraphProvider(), ApplicationProperties.get(), typeRegistry);
} }
@VisibleForTesting @VisibleForTesting
GraphBackedSearchIndexer( IAtlasGraphProvider provider, Configuration configuration) GraphBackedSearchIndexer( IAtlasGraphProvider provider, Configuration configuration, AtlasTypeRegistry typeRegistry)
throws IndexException, RepositoryException { throws IndexException, RepositoryException {
this.provider = provider; this.provider = provider;
this.typeRegistry = typeRegistry;
if (!HAConfiguration.isHAEnabled(configuration)) { if (!HAConfiguration.isHAEnabled(configuration)) {
initialize(provider.get()); initialize(provider.get());
} }
...@@ -211,6 +245,117 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -211,6 +245,117 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
onAdd(dataTypes); onAdd(dataTypes);
} }
private void addIndexForType(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
if (typeDef instanceof AtlasEnumDef) {
// Only handle complex types like Struct, Classification and Entity
return;
}
if (typeDef instanceof AtlasStructDef) {
AtlasStructDef structDef = (AtlasStructDef) typeDef;
List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
if (CollectionUtils.isNotEmpty(attributeDefs)) {
for (AtlasAttributeDef attributeDef : attributeDefs) {
createIndexForAttribute(management, typeDef.getName(), attributeDef);
}
}
} else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())){
throw new IllegalArgumentException("bad data type" + typeDef.getName());
}
}
private void createIndexForAttribute(AtlasGraphManagement management, String typeName,
AtlasAttributeDef attributeDef) {
final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName());
AtlasCardinality cardinality = toAtlasCardinality(attributeDef.getCardinality());
boolean isUnique = attributeDef.isUnique();
boolean isIndexable = attributeDef.isIndexable();
String attribTypeName = attributeDef.getTypeName();
boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName);
boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName);
boolean isMapType = AtlasTypeUtil.isMapType(attribTypeName);
try {
AtlasType atlasType = typeRegistry.getType(attribTypeName);
if (isMapType || isArrayType || isClassificationType(atlasType) || isEntityType(atlasType)) {
LOG.warn("Ignoring non-indexable attribute {}", attribTypeName);
}
if (isBuiltInType) {
createIndexes(management, propertyName, getPrimitiveClass(attribTypeName), isUnique, cardinality, false, isIndexable);
}
if (isEnumType(atlasType)) {
createIndexes(management, propertyName, String.class, isUnique, cardinality, false, isIndexable);
}
if (isStructType(atlasType)) {
AtlasStructDef structDef = typeRegistry.getStructDefByName(attributeDef.getName());
updateIndexForTypeDef(management, structDef);
}
} catch (AtlasBaseException e) {
LOG.error("No type exists for {}", attribTypeName, e);
}
}
private boolean isEntityType(AtlasType type) {
return type instanceof AtlasEntityType;
}
private boolean isClassificationType(AtlasType type) {
return type instanceof AtlasClassificationType;
}
private boolean isEnumType(AtlasType type) {
return type instanceof AtlasEnumType;
}
private boolean isStructType(AtlasType type) {
return type instanceof AtlasStructType;
}
private Class getPrimitiveClass(String attribTypeName) {
switch (attribTypeName.toLowerCase()) {
case ATLAS_TYPE_BOOLEAN:
return Boolean.class;
case ATLAS_TYPE_BYTE:
return Byte.class;
case ATLAS_TYPE_SHORT:
return Short.class;
case ATLAS_TYPE_INT:
return Integer.class;
case ATLAS_TYPE_LONG:
case ATLAS_TYPE_DATE:
return Long.class;
case ATLAS_TYPE_FLOAT:
return Float.class;
case ATLAS_TYPE_DOUBLE:
return Double.class;
case ATLAS_TYPE_BIGINTEGER:
return BigInteger.class;
case ATLAS_TYPE_BIGDECIMAL:
return BigDecimal.class;
case ATLAS_TYPE_STRING:
return String.class;
}
throw new IllegalArgumentException(String.format("Unknown primitive typename %s", attribTypeName));
}
private AtlasCardinality toAtlasCardinality(AtlasAttributeDef.Cardinality cardinality) {
switch (cardinality) {
case SINGLE:
return AtlasCardinality.SINGLE;
case LIST:
return AtlasCardinality.LIST;
case SET:
return AtlasCardinality.SET;
}
// Should never reach this point
throw new IllegalArgumentException(String.format("Bad cardinality %s", cardinality));
}
private void addIndexForType(AtlasGraphManagement management, IDataType dataType) { private void addIndexForType(AtlasGraphManagement management, IDataType dataType) {
switch (dataType.getTypeCategory()) { switch (dataType.getTypeCategory()) {
case PRIMITIVE: case PRIMITIVE:
...@@ -456,9 +601,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -456,9 +601,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
LOG.info("Reacting to active: initializing index"); LOG.info("Reacting to active: initializing index");
try { try {
initialize(); initialize();
} catch (RepositoryException e) { } catch (RepositoryException | IndexException e) {
throw new AtlasException("Error in reacting to active on initialization", e);
} catch (IndexException e) {
throw new AtlasException("Error in reacting to active on initialization", e); throw new AtlasException("Error in reacting to active on initialization", e);
} }
} }
...@@ -467,7 +610,59 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -467,7 +610,59 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
public void instanceIsPassive() { public void instanceIsPassive() {
LOG.info("Reacting to passive state: No action right now."); LOG.info("Reacting to passive state: No action right now.");
} }
@Override
public void onChange(ChangedTypeDefs changedTypeDefs) throws AtlasBaseException {
LOG.info("Adding indexes for changed typedefs");
AtlasGraphManagement management = null;
try {
management = provider.get().getManagementSystem();
// Update index for newly created types
if (CollectionUtils.isNotEmpty(changedTypeDefs.getCreateTypeDefs())) {
for (AtlasBaseTypeDef typeDef : changedTypeDefs.getCreateTypeDefs()) {
updateIndexForTypeDef(management, typeDef);
}
}
// Update index for updated types
if (CollectionUtils.isNotEmpty(changedTypeDefs.getUpdatedTypeDefs())) {
for (AtlasBaseTypeDef typeDef : changedTypeDefs.getUpdatedTypeDefs()) {
updateIndexForTypeDef(management, typeDef);
}
}
//Commit indexes
commit(management);
} catch (RepositoryException | IndexException e) {
LOG.error("Failed to update indexes for changed typedefs", e);
attemptRollback(changedTypeDefs, management);
}
}
private void attemptRollback(ChangedTypeDefs changedTypeDefs, AtlasGraphManagement management)
throws AtlasBaseException {
if (null != management) {
try {
rollback(management);
} catch (IndexException e) {
LOG.error("Index rollback has failed", e);
throw new AtlasBaseException(AtlasErrorCode.INDEX_ROLLBACK_FAILED, e,
changedTypeDefs.toString());
}
}
}
private void updateIndexForTypeDef(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
Preconditions.checkNotNull(typeDef, "Cannot index on null typedefs");
if (LOG.isDebugEnabled()) {
LOG.debug("Creating indexes for type name={}, definition={}", typeDef.getName(), typeDef.getClass());
}
addIndexForType(management, typeDef);
LOG.info("Index creation for type {} complete", typeDef.getName());
}
/* Commenting this out since we do not need an index for edge label here /* Commenting this out since we do not need an index for edge label here
private void createEdgeMixedIndex(String propertyName) { private void createEdgeMixedIndex(String propertyName) {
EdgeLabel edgeLabel = management.getEdgeLabel(propertyName); EdgeLabel edgeLabel = management.getEdgeLabel(propertyName);
......
...@@ -17,10 +17,18 @@ ...@@ -17,10 +17,18 @@
*/ */
package org.apache.atlas.repository.store.graph; package org.apache.atlas.repository.store.graph;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.GraphTransaction; import org.apache.atlas.GraphTransaction;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.ActiveStateChangeHandler;
import org.apache.atlas.listener.ChangedTypeDefs;
import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs; import org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs;
import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEntityDef;
...@@ -41,22 +49,28 @@ import org.slf4j.Logger; ...@@ -41,22 +49,28 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* Abstract class for graph persistence store for TypeDef * Abstract class for graph persistence store for TypeDef
*/ */
public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, ActiveStateChangeHandler {
private static final Logger LOG = LoggerFactory.getLogger(AtlasTypeDefGraphStore.class); private static final Logger LOG = LoggerFactory.getLogger(AtlasTypeDefGraphStore.class);
private final AtlasTypeRegistry typeRegistry; private final AtlasTypeRegistry typeRegistry;
protected AtlasTypeDefGraphStore(AtlasTypeRegistry typeRegistry) { private final Set<TypeDefChangeListener> typeDefChangeListeners;
protected AtlasTypeDefGraphStore(AtlasTypeRegistry typeRegistry,
Set<TypeDefChangeListener> typeDefChangeListeners) {
this.typeRegistry = typeRegistry; this.typeRegistry = typeRegistry;
this.typeDefChangeListeners = typeDefChangeListeners;
} }
protected abstract AtlasEnumDefStore getEnumDefStore(AtlasTypeRegistry typeRegistry); protected abstract AtlasEnumDefStore getEnumDefStore(AtlasTypeRegistry typeRegistry);
...@@ -92,6 +106,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -92,6 +106,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.updateGuid(ret.getName(), ret.getGuid()); ttr.updateGuid(ret.getName(), ret.getGuid());
notifyListeners(TypeDefChangeType.CREATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -139,6 +155,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -139,6 +155,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasEnumDef ret = getEnumDefStore(ttr).updateByName(name, enumDef); AtlasEnumDef ret = getEnumDefStore(ttr).updateByName(name, enumDef);
notifyListeners(TypeDefChangeType.UPDATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -153,6 +171,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -153,6 +171,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasEnumDef ret = getEnumDefStore(ttr).updateByGuid(guid, enumDef); AtlasEnumDef ret = getEnumDefStore(ttr).updateByGuid(guid, enumDef);
notifyListeners(TypeDefChangeType.UPDATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -163,10 +183,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -163,10 +183,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public void deleteEnumDefByName(String name) throws AtlasBaseException { public void deleteEnumDefByName(String name) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
AtlasEnumDef byName = typeRegistry.getEnumDefByName(name);
ttr.removeTypeByName(name); ttr.removeTypeByName(name);
getEnumDefStore(ttr).deleteByName(name); getEnumDefStore(ttr).deleteByName(name);
notifyListeners(TypeDefChangeType.DELETE, Lists.newArrayList(byName));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
} }
...@@ -175,10 +199,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -175,10 +199,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public void deleteEnumDefByGuid(String guid) throws AtlasBaseException { public void deleteEnumDefByGuid(String guid) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
AtlasEnumDef byGuid = typeRegistry.getEnumDefByGuid(guid);
ttr.removeTypeByGuid(guid); ttr.removeTypeByGuid(guid);
getEnumDefStore(ttr).deleteByGuid(guid); getEnumDefStore(ttr).deleteByGuid(guid);
notifyListeners(TypeDefChangeType.DELETE, Lists.newArrayList(byGuid));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
} }
...@@ -203,6 +231,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -203,6 +231,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.updateGuid(ret.getName(), ret.getGuid()); ttr.updateGuid(ret.getName(), ret.getGuid());
notifyListeners(TypeDefChangeType.CREATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -250,6 +280,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -250,6 +280,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasStructDef ret = getStructDefStore(ttr).updateByName(name, structDef); AtlasStructDef ret = getStructDefStore(ttr).updateByName(name, structDef);
notifyListeners(TypeDefChangeType.UPDATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -264,6 +296,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -264,6 +296,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasStructDef ret = getStructDefStore(ttr).updateByGuid(guid, structDef); AtlasStructDef ret = getStructDefStore(ttr).updateByGuid(guid, structDef);
notifyListeners(TypeDefChangeType.UPDATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -274,10 +308,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -274,10 +308,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public void deleteStructDefByName(String name) throws AtlasBaseException { public void deleteStructDefByName(String name) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
AtlasStructDef byName = typeRegistry.getStructDefByName(name);
ttr.removeTypeByName(name); ttr.removeTypeByName(name);
getStructDefStore(ttr).deleteByName(name, null); getStructDefStore(ttr).deleteByName(name, null);
notifyListeners(TypeDefChangeType.DELETE, Lists.newArrayList(byName));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
} }
...@@ -286,10 +324,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -286,10 +324,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public void deleteStructDefByGuid(String guid) throws AtlasBaseException { public void deleteStructDefByGuid(String guid) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
AtlasStructDef byGuid = typeRegistry.getStructDefByGuid(guid);
ttr.removeTypeByGuid(guid); ttr.removeTypeByGuid(guid);
getStructDefStore(ttr).deleteByGuid(guid, null); getStructDefStore(ttr).deleteByGuid(guid, null);
notifyListeners(TypeDefChangeType.DELETE, Lists.newArrayList(byGuid));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
} }
...@@ -315,6 +357,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -315,6 +357,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.updateGuid(ret.getName(), ret.getGuid()); ttr.updateGuid(ret.getName(), ret.getGuid());
notifyListeners(TypeDefChangeType.CREATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -364,6 +408,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -364,6 +408,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasClassificationDef ret = getClassificationDefStore(ttr).updateByName(name, classificationDef); AtlasClassificationDef ret = getClassificationDefStore(ttr).updateByName(name, classificationDef);
notifyListeners(TypeDefChangeType.UPDATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -379,6 +425,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -379,6 +425,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasClassificationDef ret = getClassificationDefStore(ttr).updateByGuid(guid, classificationDef); AtlasClassificationDef ret = getClassificationDefStore(ttr).updateByGuid(guid, classificationDef);
notifyListeners(TypeDefChangeType.UPDATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -389,10 +437,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -389,10 +437,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public void deleteClassificationDefByName(String name) throws AtlasBaseException { public void deleteClassificationDefByName(String name) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
AtlasClassificationDef byName = typeRegistry.getClassificationDefByName(name);
ttr.removeTypeByName(name); ttr.removeTypeByName(name);
getClassificationDefStore(ttr).deleteByName(name, null); getClassificationDefStore(ttr).deleteByName(name, null);
notifyListeners(TypeDefChangeType.DELETE, Lists.newArrayList(byName));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
} }
...@@ -401,10 +453,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -401,10 +453,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public void deleteClassificationDefByGuid(String guid) throws AtlasBaseException { public void deleteClassificationDefByGuid(String guid) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
AtlasClassificationDef byGuid = typeRegistry.getClassificationDefByGuid(guid);
ttr.removeTypeByGuid(guid); ttr.removeTypeByGuid(guid);
getClassificationDefStore(ttr).deleteByGuid(guid, null); getClassificationDefStore(ttr).deleteByGuid(guid, null);
notifyListeners(TypeDefChangeType.DELETE, Lists.newArrayList(byGuid));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
} }
...@@ -429,6 +485,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -429,6 +485,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.updateGuid(ret.getName(), ret.getGuid()); ttr.updateGuid(ret.getName(), ret.getGuid());
notifyListeners(TypeDefChangeType.CREATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -476,6 +534,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -476,6 +534,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasEntityDef ret = getEntityDefStore(ttr).updateByName(name, entityDef); AtlasEntityDef ret = getEntityDefStore(ttr).updateByName(name, entityDef);
notifyListeners(TypeDefChangeType.UPDATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -490,6 +550,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -490,6 +550,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasEntityDef ret = getEntityDefStore(ttr).updateByGuid(guid, entityDef); AtlasEntityDef ret = getEntityDefStore(ttr).updateByGuid(guid, entityDef);
notifyListeners(TypeDefChangeType.UPDATE, Arrays.asList(ret));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
return ret; return ret;
...@@ -500,10 +562,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -500,10 +562,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public void deleteEntityDefByName(String name) throws AtlasBaseException { public void deleteEntityDefByName(String name) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
AtlasEntityDef byName = typeRegistry.getEntityDefByName(name);
ttr.removeTypeByName(name); ttr.removeTypeByName(name);
getEntityDefStore(ttr).deleteByName(name, null); getEntityDefStore(ttr).deleteByName(name, null);
notifyListeners(TypeDefChangeType.DELETE, Lists.newArrayList(byName));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
} }
...@@ -512,10 +578,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -512,10 +578,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public void deleteEntityDefByGuid(String guid) throws AtlasBaseException { public void deleteEntityDefByGuid(String guid) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
AtlasEntityDef byGuid = typeRegistry.getEntityDefByGuid(guid);
ttr.removeTypeByGuid(guid); ttr.removeTypeByGuid(guid);
getEntityDefStore(ttr).deleteByGuid(guid, null); getEntityDefStore(ttr).deleteByGuid(guid, null);
notifyListeners(TypeDefChangeType.DELETE, Lists.newArrayList(byGuid));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
} }
...@@ -619,6 +689,17 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -619,6 +689,17 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
} }
} }
List<AtlasBaseTypeDef> createdTypeDefs = new ArrayList<>();
createdTypeDefs.addAll(ret.getEnumDefs());
createdTypeDefs.addAll(ret.getStructDefs());
createdTypeDefs.addAll(ret.getClassificationDefs());
createdTypeDefs.addAll(ret.getEntityDefs());
ChangedTypeDefs changedTypeDefs = new ChangedTypeDefs();
changedTypeDefs.setCreateTypeDefs(createdTypeDefs);
notifyListeners(changedTypeDefs);
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
...@@ -678,6 +759,17 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -678,6 +759,17 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
} }
} }
List<AtlasBaseTypeDef> updatedTypeDefs = new ArrayList<>();
updatedTypeDefs.addAll(ret.getEnumDefs());
updatedTypeDefs.addAll(ret.getStructDefs());
updatedTypeDefs.addAll(ret.getClassificationDefs());
updatedTypeDefs.addAll(ret.getEntityDefs());
ChangedTypeDefs changedTypeDefs = new ChangedTypeDefs();
changedTypeDefs.setUpdatedTypeDefs(updatedTypeDefs);
notifyListeners(changedTypeDefs);
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
...@@ -792,6 +884,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -792,6 +884,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
} }
} }
Iterable<AtlasBaseTypeDef> deleted = Iterables.concat(typesDef.getEnumDefs(), typesDef.getClassificationDefs(),
typesDef.getClassificationDefs(), typesDef.getEntityDefs());
notifyListeners(TypeDefChangeType.DELETE, Lists.newArrayList(deleted));
typeRegistry.commitTransientTypeRegistry(ttr); typeRegistry.commitTransientTypeRegistry(ttr);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
...@@ -845,4 +942,53 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -845,4 +942,53 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
} }
return typesDef; return typesDef;
} }
@Override
public void instanceIsActive() throws AtlasException {
try {
init();
} catch (AtlasBaseException e) {
LOG.error("Failed to init after becoming active", e);
}
}
@Override
public void instanceIsPassive() throws AtlasException {
LOG.info("Not reacting to a Passive state change");
}
private void notifyListeners(TypeDefChangeType type, List<? extends AtlasBaseTypeDef> typeDefs)
throws AtlasBaseException {
ChangedTypeDefs changedTypeDefs = new ChangedTypeDefs();
switch (type) {
case CREATE:
changedTypeDefs.setCreateTypeDefs(typeDefs);
break;
case UPDATE:
changedTypeDefs.setUpdatedTypeDefs(typeDefs);
break;
case DELETE:
changedTypeDefs.setDeletedTypeDefs(typeDefs);
break;
}
notifyListeners(changedTypeDefs);
}
private void notifyListeners(ChangedTypeDefs changedTypeDefs) throws AtlasBaseException {
if (CollectionUtils.isNotEmpty(typeDefChangeListeners)) {
for (TypeDefChangeListener changeListener : typeDefChangeListeners) {
try {
changeListener.onChange(changedTypeDefs);
} catch (AtlasBaseException e) {
LOG.error("OnChange failed for listener {}", changeListener.getClass().getName());
throw e;
}
}
}
}
private enum TypeDefChangeType {
CREATE, UPDATE, DELETE
}
} }
...@@ -22,6 +22,7 @@ import com.google.inject.Inject; ...@@ -22,6 +22,7 @@ import com.google.inject.Inject;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEntityDef;
...@@ -65,8 +66,9 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { ...@@ -65,8 +66,9 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
protected final AtlasGraph atlasGraph = AtlasGraphProvider.getGraphInstance(); protected final AtlasGraph atlasGraph = AtlasGraphProvider.getGraphInstance();
@Inject @Inject
public AtlasTypeDefGraphStoreV1(AtlasTypeRegistry typeRegistry) { public AtlasTypeDefGraphStoreV1(AtlasTypeRegistry typeRegistry,
super(typeRegistry); Set<TypeDefChangeListener> typeDefChangeListeners) {
super(typeRegistry, typeDefChangeListeners);
LOG.info("==> AtlasTypeDefGraphStoreV1()"); LOG.info("==> AtlasTypeDefGraphStoreV1()");
......
...@@ -18,29 +18,25 @@ ...@@ -18,29 +18,25 @@
package org.apache.atlas.services; package org.apache.atlas.services;
import static org.apache.atlas.AtlasClient.PROCESS_ATTRIBUTE_INPUTS; import com.google.common.base.Preconditions;
import static org.apache.atlas.AtlasClient.PROCESS_ATTRIBUTE_OUTPUTS; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList; import com.google.inject.Provider;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.EntityAuditEvent; import org.apache.atlas.EntityAuditEvent;
import org.apache.atlas.RequestContext; import org.apache.atlas.RequestContext;
import org.apache.atlas.classification.InterfaceAudience; import org.apache.atlas.classification.InterfaceAudience;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.ha.HAConfiguration; import org.apache.atlas.ha.HAConfiguration;
import org.apache.atlas.listener.ActiveStateChangeHandler; import org.apache.atlas.listener.ActiveStateChangeHandler;
import org.apache.atlas.listener.ChangedTypeDefs;
import org.apache.atlas.listener.EntityChangeListener; import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.listener.TypesChangeListener; import org.apache.atlas.listener.TypesChangeListener;
import org.apache.atlas.query.QueryParser;
import org.apache.atlas.repository.MetadataRepository; import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.RepositoryException; import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.audit.EntityAuditRepository; import org.apache.atlas.repository.audit.EntityAuditRepository;
...@@ -72,17 +68,23 @@ import org.apache.atlas.typesystem.types.TypeSystem; ...@@ -72,17 +68,23 @@ import org.apache.atlas.typesystem.types.TypeSystem;
import org.apache.atlas.typesystem.types.cache.TypeCache; import org.apache.atlas.typesystem.types.cache.TypeCache;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.ParamChecker; import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions; import java.util.ArrayList;
import com.google.common.collect.ImmutableList; import java.util.Collection;
import com.google.common.collect.ImmutableSet; import java.util.LinkedHashSet;
import com.google.inject.Provider; import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import static org.apache.atlas.AtlasClient.PROCESS_ATTRIBUTE_INPUTS;
import static org.apache.atlas.AtlasClient.PROCESS_ATTRIBUTE_OUTPUTS;
...@@ -91,7 +93,7 @@ import com.google.inject.Provider; ...@@ -91,7 +93,7 @@ import com.google.inject.Provider;
* for listening to changes to the repository. * for listening to changes to the repository.
*/ */
@Singleton @Singleton
public class DefaultMetadataService implements MetadataService, ActiveStateChangeHandler { public class DefaultMetadataService implements MetadataService, ActiveStateChangeHandler, TypeDefChangeListener {
private static final Logger LOG = LoggerFactory.getLogger(DefaultMetadataService.class); private static final Logger LOG = LoggerFactory.getLogger(DefaultMetadataService.class);
private final short maxAuditResults; private final short maxAuditResults;
...@@ -774,4 +776,22 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang ...@@ -774,4 +776,22 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
public void instanceIsPassive() { public void instanceIsPassive() {
LOG.info("Reacting to passive state: no action right now"); LOG.info("Reacting to passive state: no action right now");
} }
@Override
public void onChange(ChangedTypeDefs changedTypeDefs) throws AtlasBaseException {
// All we need here is a restore of the type-system
LOG.info("TypeSystem reset invoked by TypeRegistry changes");
try {
TypesDef typesDef = typeStore.restore();
typeSystem.reset();
TypeSystem.TransientTypeSystem transientTypeSystem
= typeSystem.createTransientTypeSystem(typesDef, false);
Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded();
LOG.info("Number of types got from transient type system: " + typesAdded.size());
typeSystem.commitTypes(typesAdded);
} catch (AtlasException e) {
LOG.error("Failed to restore type-system after TypeRegistry changes", e);
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
}
}
} }
...@@ -20,10 +20,12 @@ package org.apache.atlas; ...@@ -20,10 +20,12 @@ package org.apache.atlas;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.apache.atlas.repository.MetadataRepository; import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.graph.AtlasGraphProvider; import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer; import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
...@@ -42,11 +44,12 @@ import org.apache.atlas.typesystem.types.TypeSystem; ...@@ -42,11 +44,12 @@ import org.apache.atlas.typesystem.types.TypeSystem;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.inject.Inject;
/** /**
* Base Class to set up hive types and instances for tests * Base Class to set up hive types and instances for tests
*/ */
...@@ -65,7 +68,7 @@ public class BaseRepositoryTest { ...@@ -65,7 +68,7 @@ public class BaseRepositoryTest {
//force graph initialization / built in type registration //force graph initialization / built in type registration
TestUtils.getGraph(); TestUtils.getGraph();
setUpTypes(); setUpTypes();
new GraphBackedSearchIndexer(); new GraphBackedSearchIndexer(new AtlasTypeRegistry());
TestUtils.resetRequestContext(); TestUtils.resetRequestContext();
setupInstances(); setupInstances();
TestUtils.dumpGraph(TestUtils.getGraph()); TestUtils.dumpGraph(TestUtils.getGraph());
......
...@@ -18,23 +18,9 @@ ...@@ -18,23 +18,9 @@
package org.apache.atlas; package org.apache.atlas;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef; import com.google.common.collect.ImmutableList;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef; import com.google.common.collect.ImmutableSet;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAttrDef; import com.google.inject.Provider;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createStructTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createTraitTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createUniqueRequiredAttrDef;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.atlas.listener.EntityChangeListener; import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.listener.TypesChangeListener; import org.apache.atlas.listener.TypesChangeListener;
...@@ -48,6 +34,7 @@ import org.apache.atlas.repository.typestore.ITypeStore; ...@@ -48,6 +34,7 @@ import org.apache.atlas.repository.typestore.ITypeStore;
import org.apache.atlas.services.DefaultMetadataService; import org.apache.atlas.services.DefaultMetadataService;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
import org.apache.atlas.services.ReservedTypesRegistrar; import org.apache.atlas.services.ReservedTypesRegistrar;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
...@@ -73,9 +60,23 @@ import org.apache.commons.lang.RandomStringUtils; ...@@ -73,9 +60,23 @@ import org.apache.commons.lang.RandomStringUtils;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.testng.Assert; import org.testng.Assert;
import com.google.common.collect.ImmutableList; import java.io.File;
import com.google.common.collect.ImmutableSet; import java.io.FileOutputStream;
import com.google.inject.Provider; import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAttrDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createStructTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createTraitTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createUniqueRequiredAttrDef;
/** /**
* Test utility class. * Test utility class.
...@@ -513,7 +514,7 @@ public final class TestUtils { ...@@ -513,7 +514,7 @@ public final class TestUtils {
catch(Throwable t) { catch(Throwable t) {
typeCache = new DefaultTypeCache(); typeCache = new DefaultTypeCache();
} }
final GraphBackedSearchIndexer indexer = new GraphBackedSearchIndexer(); final GraphBackedSearchIndexer indexer = new GraphBackedSearchIndexer(new AtlasTypeRegistry());
Provider<TypesChangeListener> indexerProvider = new Provider<TypesChangeListener>() { Provider<TypesChangeListener> indexerProvider = new Provider<TypesChangeListener>() {
@Override @Override
......
...@@ -18,22 +18,7 @@ ...@@ -18,22 +18,7 @@
package org.apache.atlas.discovery; package org.apache.atlas.discovery;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef; import com.google.common.collect.ImmutableSet;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAttrDef;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.BaseRepositoryTest; import org.apache.atlas.BaseRepositoryTest;
...@@ -46,6 +31,7 @@ import org.apache.atlas.repository.Constants; ...@@ -46,6 +31,7 @@ import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.MetadataRepository; import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.graph.AtlasGraphProvider; import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer; import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.persistence.Id; import org.apache.atlas.typesystem.persistence.Id;
...@@ -65,7 +51,22 @@ import org.testng.annotations.DataProvider; ...@@ -65,7 +51,22 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAttrDef;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@Guice(modules = RepositoryMetadataModule.class) @Guice(modules = RepositoryMetadataModule.class)
public class GraphBackedDiscoveryServiceTest extends BaseRepositoryTest { public class GraphBackedDiscoveryServiceTest extends BaseRepositoryTest {
...@@ -119,7 +120,7 @@ public class GraphBackedDiscoveryServiceTest extends BaseRepositoryTest { ...@@ -119,7 +120,7 @@ public class GraphBackedDiscoveryServiceTest extends BaseRepositoryTest {
//We need to commit the transaction before creating the indices to release the locks held by the transaction. //We need to commit the transaction before creating the indices to release the locks held by the transaction.
//otherwise, the index commit will fail while waiting for the those locks to be released. //otherwise, the index commit will fail while waiting for the those locks to be released.
AtlasGraphProvider.getGraphInstance().commit(); AtlasGraphProvider.getGraphInstance().commit();
GraphBackedSearchIndexer idx = new GraphBackedSearchIndexer(); GraphBackedSearchIndexer idx = new GraphBackedSearchIndexer(new AtlasTypeRegistry());
idx.onAdd(newTypes); idx.onAdd(newTypes);
} }
......
...@@ -18,30 +18,8 @@ ...@@ -18,30 +18,8 @@
package org.apache.atlas.repository.graph; package org.apache.atlas.repository.graph;
import static org.apache.atlas.TestUtils.COLUMNS_ATTR_NAME; import com.google.common.collect.ImmutableList;
import static org.apache.atlas.TestUtils.COLUMN_TYPE; import com.google.common.collect.ImmutableSet;
import static org.apache.atlas.TestUtils.NAME;
import static org.apache.atlas.TestUtils.PII;
import static org.apache.atlas.TestUtils.PROCESS_TYPE;
import static org.apache.atlas.TestUtils.TABLE_TYPE;
import static org.apache.atlas.TestUtils.createColumnEntity;
import static org.apache.atlas.TestUtils.createDBEntity;
import static org.apache.atlas.TestUtils.createTableEntity;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasClient.EntityResult; import org.apache.atlas.AtlasClient.EntityResult;
...@@ -55,6 +33,7 @@ import org.apache.atlas.repository.MetadataRepository; ...@@ -55,6 +33,7 @@ import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.RepositoryException; import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
...@@ -84,8 +63,30 @@ import org.testng.annotations.BeforeMethod; ...@@ -84,8 +63,30 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import java.lang.reflect.InvocationHandler;
import com.google.common.collect.ImmutableSet; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.apache.atlas.TestUtils.COLUMNS_ATTR_NAME;
import static org.apache.atlas.TestUtils.COLUMN_TYPE;
import static org.apache.atlas.TestUtils.NAME;
import static org.apache.atlas.TestUtils.PII;
import static org.apache.atlas.TestUtils.PROCESS_TYPE;
import static org.apache.atlas.TestUtils.TABLE_TYPE;
import static org.apache.atlas.TestUtils.createColumnEntity;
import static org.apache.atlas.TestUtils.createDBEntity;
import static org.apache.atlas.TestUtils.createTableEntity;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
/** /**
* Test for GraphBackedMetadataRepository.deleteEntities * Test for GraphBackedMetadataRepository.deleteEntities
...@@ -110,7 +111,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase { ...@@ -110,7 +111,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
typeSystem = TypeSystem.getInstance(); typeSystem = TypeSystem.getInstance();
typeSystem.reset(); typeSystem.reset();
new GraphBackedSearchIndexer(); new GraphBackedSearchIndexer(new AtlasTypeRegistry());
final GraphBackedMetadataRepository delegate = new GraphBackedMetadataRepository(getDeleteHandler(typeSystem)); final GraphBackedMetadataRepository delegate = new GraphBackedMetadataRepository(getDeleteHandler(typeSystem));
repositoryService = (MetadataRepository)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), repositoryService = (MetadataRepository)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
......
...@@ -18,25 +18,8 @@ ...@@ -18,25 +18,8 @@
package org.apache.atlas.repository.graph; package org.apache.atlas.repository.graph;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef; import com.google.common.collect.ImmutableList;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createUniqueRequiredAttrDef; import com.google.common.collect.ImmutableSet;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.inject.Inject;
import org.apache.atlas.GraphTransaction; import org.apache.atlas.GraphTransaction;
import org.apache.atlas.RepositoryMetadataModule; import org.apache.atlas.RepositoryMetadataModule;
...@@ -52,6 +35,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph; ...@@ -52,6 +35,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery; import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator; import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.ITypedStruct; import org.apache.atlas.typesystem.ITypedStruct;
...@@ -78,11 +62,28 @@ import org.testng.annotations.BeforeMethod; ...@@ -78,11 +62,28 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import java.util.ArrayList;
import com.google.common.collect.ImmutableSet; import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.inject.Inject;
import scala.actors.threadpool.Arrays; import scala.actors.threadpool.Arrays;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createUniqueRequiredAttrDef;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
/** /**
* GraphBackedMetadataRepository test * GraphBackedMetadataRepository test
* *
...@@ -107,7 +108,7 @@ public class GraphBackedMetadataRepositoryTest { ...@@ -107,7 +108,7 @@ public class GraphBackedMetadataRepositoryTest {
typeSystem = TypeSystem.getInstance(); typeSystem = TypeSystem.getInstance();
typeSystem.reset(); typeSystem.reset();
new GraphBackedSearchIndexer(); new GraphBackedSearchIndexer(new AtlasTypeRegistry());
TestUtils.defineDeptEmployeeTypes(typeSystem); TestUtils.defineDeptEmployeeTypes(typeSystem);
TestUtils.createHiveTypes(typeSystem); TestUtils.createHiveTypes(typeSystem);
......
...@@ -18,10 +18,6 @@ ...@@ -18,10 +18,6 @@
package org.apache.atlas.repository.graph; package org.apache.atlas.repository.graph;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.ha.HAConfiguration; import org.apache.atlas.ha.HAConfiguration;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
...@@ -29,12 +25,17 @@ import org.apache.atlas.repository.IndexException; ...@@ -29,12 +25,17 @@ import org.apache.atlas.repository.IndexException;
import org.apache.atlas.repository.RepositoryException; import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphManagement; import org.apache.atlas.repository.graphdb.AtlasGraphManagement;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider { public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider {
@Mock @Mock
...@@ -46,6 +47,9 @@ public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider { ...@@ -46,6 +47,9 @@ public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider {
@Mock @Mock
private AtlasGraphManagement management; private AtlasGraphManagement management;
@Mock
private AtlasTypeRegistry typeRegistry;
@BeforeMethod @BeforeMethod
public void setup() { public void setup() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
...@@ -57,7 +61,7 @@ public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider { ...@@ -57,7 +61,7 @@ public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider {
when(graph.getManagementSystem()).thenReturn(management); when(graph.getManagementSystem()).thenReturn(management);
when(management.containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY)).thenReturn(true); when(management.containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY)).thenReturn(true);
GraphBackedSearchIndexer graphBackedSearchIndexer = new GraphBackedSearchIndexer(this, configuration); GraphBackedSearchIndexer graphBackedSearchIndexer = new GraphBackedSearchIndexer(this, configuration, typeRegistry);
verify(management).containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY); verify(management).containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY);
} }
...@@ -69,7 +73,7 @@ public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider { ...@@ -69,7 +73,7 @@ public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider {
when(graph.getManagementSystem()).thenReturn(management); when(graph.getManagementSystem()).thenReturn(management);
when(management.containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY)).thenReturn(true); when(management.containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY)).thenReturn(true);
new GraphBackedSearchIndexer(this, configuration); new GraphBackedSearchIndexer(this, configuration, typeRegistry);
verifyZeroInteractions(management); verifyZeroInteractions(management);
} }
...@@ -81,7 +85,7 @@ public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider { ...@@ -81,7 +85,7 @@ public class GraphBackedSearchIndexerMockTest implements IAtlasGraphProvider {
when(graph.getManagementSystem()).thenReturn(management); when(graph.getManagementSystem()).thenReturn(management);
when(management.containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY)).thenReturn(true); when(management.containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY)).thenReturn(true);
GraphBackedSearchIndexer graphBackedSearchIndexer = new GraphBackedSearchIndexer(this, configuration); GraphBackedSearchIndexer graphBackedSearchIndexer = new GraphBackedSearchIndexer(this, configuration, typeRegistry);
graphBackedSearchIndexer.instanceIsActive(); graphBackedSearchIndexer.instanceIsActive();
verify(management).containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY); verify(management).containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY);
......
...@@ -18,26 +18,13 @@ ...@@ -18,26 +18,13 @@
package org.apache.atlas.repository.graph; package org.apache.atlas.repository.graph;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import org.apache.atlas.RepositoryMetadataModule; import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.TestUtils; import org.apache.atlas.TestUtils;
import org.apache.atlas.repository.graph.GraphHelper.VertexInfo; import org.apache.atlas.repository.graph.GraphHelper.VertexInfo;
import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.types.TypeSystem; import org.apache.atlas.typesystem.types.TypeSystem;
import org.testng.Assert; import org.testng.Assert;
...@@ -47,6 +34,20 @@ import org.testng.annotations.DataProvider; ...@@ -47,6 +34,20 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
@Guice(modules = RepositoryMetadataModule.class) @Guice(modules = RepositoryMetadataModule.class)
public class GraphHelperTest { public class GraphHelperTest {
...@@ -72,12 +73,15 @@ public class GraphHelperTest { ...@@ -72,12 +73,15 @@ public class GraphHelperTest {
private TypeSystem typeSystem; private TypeSystem typeSystem;
@Inject
private AtlasTypeRegistry typeRegistry;
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
typeSystem = TypeSystem.getInstance(); typeSystem = TypeSystem.getInstance();
typeSystem.reset(); typeSystem.reset();
new GraphBackedSearchIndexer(); new GraphBackedSearchIndexer(typeRegistry);
TestUtils.defineDeptEmployeeTypes(typeSystem); TestUtils.defineDeptEmployeeTypes(typeSystem);
} }
......
...@@ -18,13 +18,6 @@ ...@@ -18,13 +18,6 @@
package org.apache.atlas.repository.graph; package org.apache.atlas.repository.graph;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import javax.inject.Inject;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.GraphTransaction; import org.apache.atlas.GraphTransaction;
import org.apache.atlas.RepositoryMetadataModule; import org.apache.atlas.RepositoryMetadataModule;
...@@ -35,6 +28,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraphQuery; ...@@ -35,6 +28,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator; import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator;
import org.apache.atlas.repository.graphdb.AtlasIndexQuery; import org.apache.atlas.repository.graphdb.AtlasIndexQuery;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct; import org.apache.atlas.typesystem.Struct;
...@@ -50,6 +44,13 @@ import org.testng.annotations.BeforeMethod; ...@@ -50,6 +44,13 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import javax.inject.Inject;
@Test @Test
@Guice(modules = RepositoryMetadataModule.class) @Guice(modules = RepositoryMetadataModule.class)
public class GraphRepoMapperScaleTest { public class GraphRepoMapperScaleTest {
...@@ -72,7 +73,7 @@ public class GraphRepoMapperScaleTest { ...@@ -72,7 +73,7 @@ public class GraphRepoMapperScaleTest {
public void setUp() throws Exception { public void setUp() throws Exception {
//force up front graph initialization //force up front graph initialization
TestUtils.getGraph(); TestUtils.getGraph();
searchIndexer = new GraphBackedSearchIndexer(new AtlasGraphProvider(), ApplicationProperties.get()); searchIndexer = new GraphBackedSearchIndexer(new AtlasGraphProvider(), ApplicationProperties.get(), new AtlasTypeRegistry());
//Make sure we can cleanup the index directory //Make sure we can cleanup the index directory
Collection<IDataType> typesAdded = TestUtils.createHiveTypes(typeSystem); Collection<IDataType> typesAdded = TestUtils.createHiveTypes(typeSystem);
searchIndexer.onAdd(typesAdded); searchIndexer.onAdd(typesAdded);
......
...@@ -18,29 +18,9 @@ ...@@ -18,29 +18,9 @@
package org.apache.atlas.service; package org.apache.atlas.service;
import static org.apache.atlas.TestUtils.COLUMNS_ATTR_NAME; import com.google.common.collect.ImmutableList;
import static org.apache.atlas.TestUtils.COLUMN_TYPE; import com.google.common.collect.ImmutableSet;
import static org.apache.atlas.TestUtils.PII; import com.google.inject.Inject;
import static org.apache.atlas.TestUtils.TABLE_TYPE;
import static org.apache.atlas.TestUtils.createColumnEntity;
import static org.apache.atlas.TestUtils.createDBEntity;
import static org.apache.atlas.TestUtils.createInstance;
import static org.apache.atlas.TestUtils.createTableEntity;
import static org.apache.atlas.TestUtils.randomString;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
...@@ -49,12 +29,15 @@ import org.apache.atlas.RepositoryMetadataModule; ...@@ -49,12 +29,15 @@ import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.RequestContext; import org.apache.atlas.RequestContext;
import org.apache.atlas.TestUtils; import org.apache.atlas.TestUtils;
import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService; import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.ChangedTypeDefs;
import org.apache.atlas.listener.EntityChangeListener; import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.query.QueryParams; import org.apache.atlas.query.QueryParams;
import org.apache.atlas.repository.audit.EntityAuditRepository; import org.apache.atlas.repository.audit.EntityAuditRepository;
import org.apache.atlas.repository.audit.HBaseBasedAuditRepository; import org.apache.atlas.repository.audit.HBaseBasedAuditRepository;
import org.apache.atlas.repository.audit.HBaseTestUtils; import org.apache.atlas.repository.audit.HBaseTestUtils;
import org.apache.atlas.repository.graph.AtlasGraphProvider; import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.services.DefaultMetadataService;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.IStruct;
...@@ -75,6 +58,7 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; ...@@ -75,6 +58,7 @@ import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
import org.apache.atlas.typesystem.types.Multiplicity; import org.apache.atlas.typesystem.types.Multiplicity;
import org.apache.atlas.typesystem.types.TypeSystem; import org.apache.atlas.typesystem.types.TypeSystem;
import org.apache.atlas.typesystem.types.ValueConversionException; import org.apache.atlas.typesystem.types.ValueConversionException;
import org.apache.atlas.typesystem.types.cache.TypeCache;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.ParamChecker; import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
...@@ -87,9 +71,29 @@ import org.testng.annotations.BeforeTest; ...@@ -87,9 +71,29 @@ import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import java.util.ArrayList;
import com.google.common.collect.ImmutableSet; import java.util.Arrays;
import com.google.inject.Inject; import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.apache.atlas.TestUtils.COLUMNS_ATTR_NAME;
import static org.apache.atlas.TestUtils.COLUMN_TYPE;
import static org.apache.atlas.TestUtils.PII;
import static org.apache.atlas.TestUtils.TABLE_TYPE;
import static org.apache.atlas.TestUtils.createColumnEntity;
import static org.apache.atlas.TestUtils.createDBEntity;
import static org.apache.atlas.TestUtils.createInstance;
import static org.apache.atlas.TestUtils.createTableEntity;
import static org.apache.atlas.TestUtils.randomString;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@Guice(modules = RepositoryMetadataModule.class) @Guice(modules = RepositoryMetadataModule.class)
public class DefaultMetadataServiceTest { public class DefaultMetadataServiceTest {
...@@ -1131,6 +1135,22 @@ public class DefaultMetadataServiceTest { ...@@ -1131,6 +1135,22 @@ public class DefaultMetadataServiceTest {
} }
} }
@Test
public void testOnChangeRefresh() {
try {
List<String> beforeChangeTypeNames = metadataService.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>());
((DefaultMetadataService)metadataService).onChange(new ChangedTypeDefs());
List<String> afterChangeTypeNames = metadataService.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>());
assertEquals(afterChangeTypeNames, beforeChangeTypeNames);
} catch (AtlasBaseException e) {
fail("Should've succeeded", e);
} catch (AtlasException e) {
fail("getTypeNames should've succeeded", e);
}
}
private static class EntitiesChangeListener implements EntityChangeListener { private static class EntitiesChangeListener implements EntityChangeListener {
private List<String> deletedEntities = new ArrayList<>(); private List<String> deletedEntities = new ArrayList<>();
private List<String> updatedEntities = new ArrayList<>(); private List<String> updatedEntities = new ArrayList<>();
......
...@@ -74,7 +74,8 @@ trait GraphUtils { ...@@ -74,7 +74,8 @@ trait GraphUtils {
object QueryTestsUtils extends GraphUtils { object QueryTestsUtils extends GraphUtils {
def setupTypesAndIndices() : Unit = { def setupTypesAndIndices() : Unit = {
val indexer = new GraphBackedSearchIndexer(); // FIXME: Do we need to init the AtlasTypeRegistry here ?
val indexer = new GraphBackedSearchIndexer(null);
val typesDef : TypesDef = defineTypes; val typesDef : TypesDef = defineTypes;
val newTypes = TypeSystem.getInstance.defineTypes(typesDef); val newTypes = TypeSystem.getInstance.defineTypes(typesDef);
indexer.onAdd(newTypes.values()); indexer.onAdd(newTypes.values());
......
...@@ -116,6 +116,10 @@ ...@@ -116,6 +116,10 @@
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.atlas</groupId>
<artifactId>atlas-intg</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -20,6 +20,7 @@ package org.apache.atlas.typesystem.types; ...@@ -20,6 +20,7 @@ package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.classification.InterfaceAudience; import org.apache.atlas.classification.InterfaceAudience;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
...@@ -30,7 +31,6 @@ import org.apache.atlas.typesystem.types.cache.TypeCache; ...@@ -30,7 +31,6 @@ import org.apache.atlas.typesystem.types.cache.TypeCache;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.inject.Singleton;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -41,6 +41,8 @@ import java.util.Set; ...@@ -41,6 +41,8 @@ import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Singleton;
@Singleton @Singleton
@InterfaceAudience.Private @InterfaceAudience.Private
public class TypeSystem { public class TypeSystem {
......
...@@ -31,7 +31,6 @@ import org.apache.atlas.model.typedef.AtlasStructDef; ...@@ -31,7 +31,6 @@ import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs;
import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.apache.http.annotation.Experimental; import org.apache.http.annotation.Experimental;
import org.slf4j.Logger; import org.slf4j.Logger;
......
...@@ -24,6 +24,7 @@ import org.apache.atlas.listener.ActiveStateChangeHandler; ...@@ -24,6 +24,7 @@ import org.apache.atlas.listener.ActiveStateChangeHandler;
import org.apache.atlas.notification.NotificationHookConsumer; import org.apache.atlas.notification.NotificationHookConsumer;
import org.apache.atlas.repository.audit.HBaseBasedAuditRepository; import org.apache.atlas.repository.audit.HBaseBasedAuditRepository;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer; import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1;
import org.apache.atlas.service.Service; import org.apache.atlas.service.Service;
import org.apache.atlas.services.DefaultMetadataService; import org.apache.atlas.services.DefaultMetadataService;
...@@ -41,6 +42,7 @@ public class ActiveInstanceElectorModule extends AbstractModule { ...@@ -41,6 +42,7 @@ public class ActiveInstanceElectorModule extends AbstractModule {
activeStateChangeHandlerBinder.addBinding().to(DefaultMetadataService.class); activeStateChangeHandlerBinder.addBinding().to(DefaultMetadataService.class);
activeStateChangeHandlerBinder.addBinding().to(NotificationHookConsumer.class); activeStateChangeHandlerBinder.addBinding().to(NotificationHookConsumer.class);
activeStateChangeHandlerBinder.addBinding().to(HBaseBasedAuditRepository.class); activeStateChangeHandlerBinder.addBinding().to(HBaseBasedAuditRepository.class);
activeStateChangeHandlerBinder.addBinding().to(AtlasTypeDefGraphStoreV1.class);
Multibinder<Service> serviceBinder = Multibinder.newSetBinder(binder(), Service.class); Multibinder<Service> serviceBinder = Multibinder.newSetBinder(binder(), Service.class);
serviceBinder.addBinding().to(ActiveInstanceElectorService.class); serviceBinder.addBinding().to(ActiveInstanceElectorService.class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment