Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseExce

AtlasTypesDef ret = updateGraphStore(typesDef, ttr);

try {
ttr.updateTypesWithNoRefResolve(ret);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call updateTypes(), instead of updateTypesWithNoRefResolve() - "*WithNoRefResolve()" calls will not run resolveReferences() hence will leave type objects with no reference to other types (for example: an entity-type will not have its references set for other entity-types references by it).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mneethiraj, thanks for your comment, I got you and I fixed that

} catch (AtlasBaseException e) { // this shouldn't happen, as the types were already validated
LOG.error("failed to update the registry after updating the store", e);
}

if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={})",
CollectionUtils.size(typesDef.getEnumDefs()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
Expand All @@ -38,6 +39,7 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import static org.testng.Assert.*;
Expand Down Expand Up @@ -432,4 +434,67 @@ public void testTypeDeletionAndRecreate() {
}
}

@Test
public void testTypeRegistryIsUpdatedAfterGraphStorage() throws AtlasBaseException {
String classificationDef = "{"
+ "\"name\":\"test_classification_11\","
+ "\"description\":\"\","
+ "\"createdBy\":\"admin\","
+ "\"superTypes\":[],"
+ "\"attributeDefs\":[{"
+ "\"name\":\"test_class_11\","
+ "\"typeName\":\"string\","
+ "\"isOptional\":true,"
+ "\"isUnique\":true,"
+ "\"isIndexable\":true,"
+ "\"cardinality\":\"SINGLE\","
+ "\"valuesMinCount\":0,"
+ "\"valuesMaxCount\":1}]}";

String jsonStr = "{"
+ "\"classificationDefs\":[" + classificationDef + "],"
+ "\"entityDefs\":[],"
+ "\"enumDefs\":[],"
+ "\"structDefs\":[]}";

// create type from json string
AtlasTypesDef testTypesDefFromJson = AtlasType.fromJson(jsonStr, AtlasTypesDef.class);
AtlasTypesDef createdTypesDef = typeDefStore.createTypesDef(testTypesDefFromJson);
// check returned type
assertEquals("test_classification_11", createdTypesDef.getClassificationDefs().get(0).getName());
assertTrue(createdTypesDef.getClassificationDefs().get(0).getAttributeDefs().get(0).getIsIndexable());
// save guid
String guid = createdTypesDef.getClassificationDefs().get(0).getGuid();
Date createdTime = createdTypesDef.getClassificationDefs().get(0).getCreateTime();

// get created type and check again
AtlasClassificationDef getBackFromCache = typeDefStore.getClassificationDefByName("test_classification_11");
assertEquals("test_classification_11", getBackFromCache.getName());
assertTrue(getBackFromCache.getAttributeDefs().get(0).getIsIndexable());
assertEquals(guid, getBackFromCache.getGuid());
assertNotNull(getBackFromCache.getCreatedBy());
assertEquals(createdTime, getBackFromCache.getCreateTime());

// update type, change isIndexable, check the update result
testTypesDefFromJson = AtlasType.fromJson(jsonStr, AtlasTypesDef.class);
testTypesDefFromJson.getClassificationDefs().get(0).getAttributeDefs().get(0).setIsIndexable(false);
AtlasTypesDef updatedTypesDef = typeDefStore.updateTypesDef(testTypesDefFromJson);
assertEquals("test_classification_11", updatedTypesDef.getClassificationDefs().get(0).getName());
assertFalse(updatedTypesDef.getClassificationDefs().get(0).getAttributeDefs().get(0).getIsIndexable());
assertEquals(guid, updatedTypesDef.getClassificationDefs().get(0).getGuid());
assertEquals(createdTime, updatedTypesDef.getClassificationDefs().get(0).getCreateTime());

// get updated type (both by name and guid) and check again
getBackFromCache = typeDefStore.getClassificationDefByName("test_classification_11");
assertEquals("test_classification_11", getBackFromCache.getName());
assertFalse(getBackFromCache.getAttributeDefs().get(0).getIsIndexable());
assertEquals(guid, getBackFromCache.getGuid());
assertEquals(createdTime, getBackFromCache.getCreateTime());
getBackFromCache = typeDefStore.getClassificationDefByGuid(guid);
assertEquals("test_classification_11", getBackFromCache.getName());
assertFalse(getBackFromCache.getAttributeDefs().get(0).getIsIndexable());
assertEquals(guid, getBackFromCache.getGuid());
assertEquals(createdTime, getBackFromCache.getCreateTime());
}

}