Commit 52489d60 by Madhan Neethiraj

ATLAS-2014: populate createdBy, updatedBy fields on type create and update

parent eb82ef9b
...@@ -30,12 +30,14 @@ import org.apache.atlas.model.typedef.AtlasClassificationDef; ...@@ -30,12 +30,14 @@ import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef; import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef; import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasStructDef; import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -59,6 +61,8 @@ public final class TestUtilsV2 { ...@@ -59,6 +61,8 @@ public final class TestUtilsV2 {
public static final long TEST_DATE_IN_LONG = 1418265358440L; public static final long TEST_DATE_IN_LONG = 1418265358440L;
public static final String TEST_USER = "testUser";
private static AtomicInteger seq = new AtomicInteger(); private static AtomicInteger seq = new AtomicInteger();
private TestUtilsV2() { private TestUtilsV2() {
...@@ -147,9 +151,13 @@ public final class TestUtilsV2 { ...@@ -147,9 +151,13 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createTraitTypeDef("SecurityClearance", "SecurityClearance"+_description, ImmutableSet.<String>of(), AtlasTypeUtil.createTraitTypeDef("SecurityClearance", "SecurityClearance"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("level", "int")); AtlasTypeUtil.createRequiredAttrDef("level", "int"));
return new AtlasTypesDef(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails), AtlasTypesDef ret = new AtlasTypesDef(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails),
ImmutableList.of(securityClearanceTypeDef), ImmutableList.of(securityClearanceTypeDef),
ImmutableList.of(deptTypeDef, personTypeDef, employeeTypeDef, managerTypeDef)); ImmutableList.of(deptTypeDef, personTypeDef, employeeTypeDef, managerTypeDef));
populateSystemAttributes(ret);
return ret;
} }
public static AtlasTypesDef defineInverseReferenceTestTypes() { public static AtlasTypesDef defineInverseReferenceTestTypes() {
...@@ -175,7 +183,11 @@ public final class TestUtilsV2 { ...@@ -175,7 +183,11 @@ public final class TestUtilsV2 {
AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, Collections.<String, Object>singletonMap(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "manyB")))), AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, Collections.<String, Object>singletonMap(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "manyB")))),
new AtlasAttributeDef("mappedFromA", "A", true, Cardinality.SINGLE, 0, 1, false, false, Collections.<AtlasConstraintDef>emptyList())); new AtlasAttributeDef("mappedFromA", "A", true, Cardinality.SINGLE, 0, 1, false, false, Collections.<AtlasConstraintDef>emptyList()));
return new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.<AtlasEntityDef>of(aDef, bDef)); AtlasTypesDef ret = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.<AtlasEntityDef>of(aDef, bDef));
populateSystemAttributes(ret);
return ret;
} }
public static AtlasTypesDef defineValidUpdatedDeptEmployeeTypes() { public static AtlasTypesDef defineValidUpdatedDeptEmployeeTypes() {
...@@ -255,10 +267,14 @@ public final class TestUtilsV2 { ...@@ -255,10 +267,14 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createTraitTypeDef("SecurityClearance", "SecurityClearance"+_description, ImmutableSet.<String>of(), AtlasTypeUtil.createTraitTypeDef("SecurityClearance", "SecurityClearance"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("level", "int")); AtlasTypeUtil.createRequiredAttrDef("level", "int"));
return new AtlasTypesDef(ImmutableList.of(orgLevelEnum), AtlasTypesDef ret = new AtlasTypesDef(ImmutableList.of(orgLevelEnum),
ImmutableList.of(addressDetails), ImmutableList.of(addressDetails),
ImmutableList.of(securityClearanceTypeDef), ImmutableList.of(securityClearanceTypeDef),
ImmutableList.of(deptTypeDef, personTypeDef, employeeTypeDef, managerTypeDef)); ImmutableList.of(deptTypeDef, personTypeDef, employeeTypeDef, managerTypeDef));
populateSystemAttributes(ret);
return ret;
} }
public static AtlasTypesDef defineInvalidUpdatedDeptEmployeeTypes() { public static AtlasTypesDef defineInvalidUpdatedDeptEmployeeTypes() {
...@@ -322,10 +338,14 @@ public final class TestUtilsV2 { ...@@ -322,10 +338,14 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", "bigdecimal") AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", "bigdecimal")
); );
return new AtlasTypesDef(ImmutableList.of(orgLevelEnum), AtlasTypesDef ret = new AtlasTypesDef(ImmutableList.of(orgLevelEnum),
ImmutableList.of(addressDetails), ImmutableList.of(addressDetails),
ImmutableList.<AtlasClassificationDef>of(), ImmutableList.<AtlasClassificationDef>of(),
ImmutableList.of(deptTypeDef, personTypeDef)); ImmutableList.of(deptTypeDef, personTypeDef));
populateSystemAttributes(ret);
return ret;
} }
public static final String DEPARTMENT_TYPE = "Department"; public static final String DEPARTMENT_TYPE = "Department";
...@@ -541,8 +561,12 @@ public final class TestUtilsV2 { ...@@ -541,8 +561,12 @@ public final class TestUtilsV2 {
AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", "enumType", "1.0", AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", "enumType", "1.0",
Arrays.asList(new AtlasEnumElementDef("ONE", "Element Description", 1))); Arrays.asList(new AtlasEnumElementDef("ONE", "Element Description", 1)));
return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition), AtlasTypesDef ret = AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition),
ImmutableList.of(traitTypeDefinition), ImmutableList.of(superTypeDefinition)); ImmutableList.of(traitTypeDefinition), ImmutableList.of(superTypeDefinition));
populateSystemAttributes(ret);
return ret;
} }
public static AtlasTypesDef simpleTypeUpdated(){ public static AtlasTypesDef simpleTypeUpdated(){
...@@ -562,8 +586,12 @@ public final class TestUtilsV2 { ...@@ -562,8 +586,12 @@ public final class TestUtilsV2 {
AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", "enumType", AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", "enumType",
Arrays.asList(new AtlasEnumElementDef("ONE", "Element Description", 1))); Arrays.asList(new AtlasEnumElementDef("ONE", "Element Description", 1)));
return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition), AtlasTypesDef ret = AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition),
ImmutableList.of(traitTypeDefinition), ImmutableList.of(superTypeDefinition, newSuperTypeDefinition)); ImmutableList.of(traitTypeDefinition), ImmutableList.of(superTypeDefinition, newSuperTypeDefinition));
populateSystemAttributes(ret);
return ret;
} }
public static AtlasTypesDef simpleTypeUpdatedDiff() { public static AtlasTypesDef simpleTypeUpdatedDiff() {
...@@ -571,10 +599,14 @@ public final class TestUtilsV2 { ...@@ -571,10 +599,14 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createClassTypeDef("new_h_type", ImmutableSet.<String>of(), AtlasTypeUtil.createClassTypeDef("new_h_type", ImmutableSet.<String>of(),
AtlasTypeUtil.createOptionalAttrDef("attr", "string")); AtlasTypeUtil.createOptionalAttrDef("attr", "string"));
return AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(), AtlasTypesDef ret = AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(),
ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasStructDef>of(),
ImmutableList.<AtlasClassificationDef>of(), ImmutableList.<AtlasClassificationDef>of(),
ImmutableList.of(newSuperTypeDefinition)); ImmutableList.of(newSuperTypeDefinition));
populateSystemAttributes(ret);
return ret;
} }
...@@ -793,11 +825,15 @@ public final class TestUtilsV2 { ...@@ -793,11 +825,15 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createRequiredAttrDef("booleanAttr", "boolean"), AtlasTypeUtil.createRequiredAttrDef("booleanAttr", "boolean"),
AtlasTypeUtil.createRequiredAttrDef("integerAttr", "int")); AtlasTypeUtil.createRequiredAttrDef("integerAttr", "int"));
return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), AtlasTypesDef ret = AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition),
ImmutableList.of(structTypeDefinition, partitionDefinition), ImmutableList.of(structTypeDefinition, partitionDefinition),
ImmutableList.of(classificationTypeDefinition, fetlClassificationTypeDefinition, piiTypeDefinition, phiTypeDefinition), ImmutableList.of(classificationTypeDefinition, fetlClassificationTypeDefinition, piiTypeDefinition, phiTypeDefinition),
ImmutableList.of(superTypeDefinition, databaseTypeDefinition, columnsDefinition, tableTypeDefinition, ImmutableList.of(superTypeDefinition, databaseTypeDefinition, columnsDefinition, tableTypeDefinition,
storageDescClsDef, partClsDef, processClsType)); storageDescClsDef, partClsDef, processClsType));
populateSystemAttributes(ret);
return ret;
} }
public static final String randomString() { public static final String randomString() {
...@@ -926,6 +962,8 @@ public final class TestUtilsV2 { ...@@ -926,6 +962,8 @@ public final class TestUtilsV2 {
newtestEntityDef.addAttribute(attrDiskUsage); newtestEntityDef.addAttribute(attrDiskUsage);
newtestEntityDef.addAttribute(attrisStoreUse); newtestEntityDef.addAttribute(attrisStoreUse);
populateSystemAttributes(newtestEntityDef);
return newtestEntityDef; return newtestEntityDef;
} }
...@@ -959,8 +997,13 @@ public final class TestUtilsV2 { ...@@ -959,8 +997,13 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createTraitTypeDef("JanitorClearance", "JanitorClearance_description", ImmutableSet.of("SecurityClearance1"), AtlasTypeUtil.createTraitTypeDef("JanitorClearance", "JanitorClearance_description", ImmutableSet.of("SecurityClearance1"),
AtlasTypeUtil.createRequiredAttrDef("level", "int")); AtlasTypeUtil.createRequiredAttrDef("level", "int"));
return Arrays.asList(securityClearanceTypeDef, janitorSecurityClearanceTypeDef); List<AtlasClassificationDef> ret = Arrays.asList(securityClearanceTypeDef, janitorSecurityClearanceTypeDef);
populateSystemAttributes(ret);
return ret;
} }
public static List<AtlasClassificationDef> getClassificationWithValidAttribute(){ public static List<AtlasClassificationDef> getClassificationWithValidAttribute(){
return getClassificationWithValidSuperType(); return getClassificationWithValidSuperType();
} }
...@@ -971,7 +1014,11 @@ public final class TestUtilsV2 { ...@@ -971,7 +1014,11 @@ public final class TestUtilsV2 {
1, 10, false, false, 1, 10, false, false,
Collections.<AtlasConstraintDef>emptyList())); Collections.<AtlasConstraintDef>emptyList()));
return Arrays.asList(developerTypeDef); List<AtlasEntityDef> ret = Arrays.asList(developerTypeDef);
populateSystemAttributes(ret);
return ret;
} }
public static List<AtlasEntityDef> getEntityWithValidAttribute() { public static List<AtlasEntityDef> getEntityWithValidAttribute() {
...@@ -991,4 +1038,25 @@ public final class TestUtilsV2 { ...@@ -991,4 +1038,25 @@ public final class TestUtilsV2 {
entityDef.addSuperType("!@#$%"); entityDef.addSuperType("!@#$%");
return entityDef; return entityDef;
} }
public static void populateSystemAttributes(AtlasTypesDef typesDef) {
populateSystemAttributes(typesDef.getEnumDefs());
populateSystemAttributes(typesDef.getStructDefs());
populateSystemAttributes(typesDef.getClassificationDefs());
populateSystemAttributes(typesDef.getEntityDefs());
populateSystemAttributes(typesDef.getRelationshipDefs());
}
public static void populateSystemAttributes(List<? extends AtlasBaseTypeDef> typeDefs) {
if (CollectionUtils.isNotEmpty(typeDefs)) {
for (AtlasBaseTypeDef typeDef : typeDefs) {
populateSystemAttributes(typeDef);
}
}
}
public static void populateSystemAttributes(AtlasBaseTypeDef typeDef) {
typeDef.setCreatedBy(TestUtilsV2.TEST_USER);
typeDef.setUpdatedBy(TestUtilsV2.TEST_USER);
}
} }
...@@ -320,6 +320,12 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ ...@@ -320,6 +320,12 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ
AtlasTypesDef ret = addToGraphStore(typesDef, ttr); AtlasTypesDef ret = addToGraphStore(typesDef, ttr);
try {
ttr.updateTypes(ret);
} 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()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={})", LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={})",
CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getEnumDefs()),
......
...@@ -31,6 +31,7 @@ import java.util.Map; ...@@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.RequestContextV1;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.TypeDefChangeListener; import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
...@@ -205,7 +206,9 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { ...@@ -205,7 +206,9 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
StringUtils.isNotBlank(typeDef.getDescription()) ? typeDef.getDescription() : typeDef.getName()); StringUtils.isNotBlank(typeDef.getDescription()) ? typeDef.getDescription() : typeDef.getName());
ret.setProperty(Constants.TYPEVERSION_PROPERTY_KEY, typeDef.getTypeVersion()); ret.setProperty(Constants.TYPEVERSION_PROPERTY_KEY, typeDef.getTypeVersion());
ret.setProperty(Constants.GUID_PROPERTY_KEY, typeDef.getGuid()); ret.setProperty(Constants.GUID_PROPERTY_KEY, typeDef.getGuid());
ret.setProperty(Constants.CREATED_BY_KEY, getCurrentUser());
ret.setProperty(Constants.TIMESTAMP_PROPERTY_KEY, typeDef.getCreateTime().getTime()); ret.setProperty(Constants.TIMESTAMP_PROPERTY_KEY, typeDef.getCreateTime().getTime());
ret.setProperty(Constants.MODIFIED_BY_KEY, getCurrentUser());
ret.setProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, typeDef.getUpdateTime().getTime()); ret.setProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, typeDef.getUpdateTime().getTime());
ret.setProperty(Constants.VERSION_PROPERTY_KEY, typeDef.getVersion()); ret.setProperty(Constants.VERSION_PROPERTY_KEY, typeDef.getVersion());
ret.setProperty(Constants.TYPEOPTIONS_PROPERTY_KEY, AtlasType.toJson(typeDef.getOptions())); ret.setProperty(Constants.TYPEOPTIONS_PROPERTY_KEY, AtlasType.toJson(typeDef.getOptions()));
...@@ -284,6 +287,8 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { ...@@ -284,6 +287,8 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
String description = vertex.getProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class); String description = vertex.getProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class);
String typeVersion = vertex.getProperty(Constants.TYPEVERSION_PROPERTY_KEY, String.class); String typeVersion = vertex.getProperty(Constants.TYPEVERSION_PROPERTY_KEY, String.class);
String guid = vertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class); String guid = vertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class);
String createdBy = vertex.getProperty(Constants.CREATED_BY_KEY, String.class);
String updatedBy = vertex.getProperty(Constants.MODIFIED_BY_KEY, String.class);
Long createTime = vertex.getProperty(Constants.TIMESTAMP_PROPERTY_KEY, Long.class); Long createTime = vertex.getProperty(Constants.TIMESTAMP_PROPERTY_KEY, Long.class);
Long updateTime = vertex.getProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class); Long updateTime = vertex.getProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
Long version = vertex.getProperty(Constants.VERSION_PROPERTY_KEY, Long.class); Long version = vertex.getProperty(Constants.VERSION_PROPERTY_KEY, Long.class);
...@@ -293,6 +298,8 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { ...@@ -293,6 +298,8 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
typeDef.setDescription(description); typeDef.setDescription(description);
typeDef.setTypeVersion(typeVersion); typeDef.setTypeVersion(typeVersion);
typeDef.setGuid(guid); typeDef.setGuid(guid);
typeDef.setCreatedBy(createdBy);
typeDef.setUpdatedBy(updatedBy);
if (createTime != null) { if (createTime != null) {
typeDef.setCreateTime(new Date(createTime)); typeDef.setCreateTime(new Date(createTime));
...@@ -456,7 +463,22 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { ...@@ -456,7 +463,22 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
Number currVersion = vertex.getProperty(Constants.VERSION_PROPERTY_KEY, Number.class); Number currVersion = vertex.getProperty(Constants.VERSION_PROPERTY_KEY, Number.class);
long newVersion = currVersion == null ? 1 : (currVersion.longValue() + 1); long newVersion = currVersion == null ? 1 : (currVersion.longValue() + 1);
vertex.setProperty(Constants.MODIFIED_BY_KEY, getCurrentUser());
vertex.setProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, now.getTime()); vertex.setProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, now.getTime());
vertex.setProperty(Constants.VERSION_PROPERTY_KEY, newVersion); vertex.setProperty(Constants.VERSION_PROPERTY_KEY, newVersion);
} }
private String getCurrentUser() {
String ret = RequestContextV1.get().getUser();
if (StringUtils.isBlank(ret)) {
ret = System.getProperty("user.name");
if (StringUtils.isBlank(ret)) {
ret = "atlas";
}
}
return ret;
}
} }
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.repository.impexp; package org.apache.atlas.repository.impexp;
import org.apache.atlas.RequestContextV1;
import org.apache.atlas.TestModules; import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtilsV2; import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
...@@ -42,6 +43,7 @@ import org.slf4j.LoggerFactory; ...@@ -42,6 +43,7 @@ import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
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 scala.actors.threadpool.Arrays; import scala.actors.threadpool.Arrays;
...@@ -79,6 +81,12 @@ public class ExportServiceTest { ...@@ -79,6 +81,12 @@ public class ExportServiceTest {
private AtlasEntityChangeNotifier mockChangeNotifier = mock(AtlasEntityChangeNotifier.class); private AtlasEntityChangeNotifier mockChangeNotifier = mock(AtlasEntityChangeNotifier.class);
private AtlasEntityStoreV1 entityStore; private AtlasEntityStoreV1 entityStore;
@BeforeTest
public void setupTest() {
RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
}
@BeforeClass @BeforeClass
public void setupSampleData() throws AtlasBaseException { public void setupSampleData() throws AtlasBaseException {
entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier, graphMapper);; entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier, graphMapper);;
......
...@@ -20,6 +20,7 @@ package org.apache.atlas.repository.impexp; ...@@ -20,6 +20,7 @@ package org.apache.atlas.repository.impexp;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.atlas.RequestContextV1; import org.apache.atlas.RequestContextV1;
import org.apache.atlas.TestModules; import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.impexp.AtlasImportRequest; import org.apache.atlas.model.impexp.AtlasImportRequest;
import org.apache.atlas.repository.store.graph.AtlasEntityStore; import org.apache.atlas.repository.store.graph.AtlasEntityStore;
...@@ -28,6 +29,7 @@ import org.apache.atlas.type.AtlasTypeRegistry; ...@@ -28,6 +29,7 @@ import org.apache.atlas.type.AtlasTypeRegistry;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.ITestContext; import org.testng.ITestContext;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider; 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;
...@@ -53,6 +55,12 @@ public class ImportServiceTest { ...@@ -53,6 +55,12 @@ public class ImportServiceTest {
@Inject @Inject
private AtlasEntityStore entityStore; private AtlasEntityStore entityStore;
@BeforeTest
public void setupTest() {
RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
}
@DataProvider(name = "sales") @DataProvider(name = "sales")
public static Object[][] getDataFromQuickStart_v1_Sales(ITestContext context) throws IOException { public static Object[][] getDataFromQuickStart_v1_Sales(ITestContext context) throws IOException {
return getZipSource("sales-v1-full.zip"); return getZipSource("sales-v1-full.zip");
......
...@@ -19,6 +19,7 @@ package org.apache.atlas.repository.impexp; ...@@ -19,6 +19,7 @@ package org.apache.atlas.repository.impexp;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.apache.atlas.RequestContextV1; import org.apache.atlas.RequestContextV1;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.impexp.AtlasExportResult; import org.apache.atlas.model.impexp.AtlasExportResult;
import org.apache.atlas.model.impexp.AtlasImportRequest; import org.apache.atlas.model.impexp.AtlasImportRequest;
...@@ -151,6 +152,7 @@ public class ZipFileResourceTestUtils { ...@@ -151,6 +152,7 @@ public class ZipFileResourceTestUtils {
List<String> creationOrder = zipSource.getCreationOrder(); List<String> creationOrder = zipSource.getCreationOrder();
RequestContextV1.clear(); RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
AtlasImportRequest request = getDefaultImportRequest(); AtlasImportRequest request = getDefaultImportRequest();
AtlasImportResult result = runImportWithParameters(importService, request, zipSource); AtlasImportResult result = runImportWithParameters(importService, request, zipSource);
......
...@@ -20,6 +20,7 @@ package org.apache.atlas.repository.store.graph; ...@@ -20,6 +20,7 @@ package org.apache.atlas.repository.store.graph;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.atlas.TestModules; import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtilsV2; import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.RequestContextV1;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
...@@ -33,6 +34,7 @@ import org.apache.atlas.type.AtlasType; ...@@ -33,6 +34,7 @@ import org.apache.atlas.type.AtlasType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider; 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;
...@@ -52,6 +54,12 @@ public class AtlasTypeDefGraphStoreTest { ...@@ -52,6 +54,12 @@ public class AtlasTypeDefGraphStoreTest {
private private
AtlasTypeDefStore typeDefStore; AtlasTypeDefStore typeDefStore;
@BeforeTest
public void setupTest() {
RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
}
@Test(priority = 1) @Test(priority = 1)
public void testGet() { public void testGet() {
try { try {
......
...@@ -101,6 +101,9 @@ public abstract class AtlasDeleteHandlerV1Test { ...@@ -101,6 +101,9 @@ public abstract class AtlasDeleteHandlerV1Test {
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
metadataService = TestUtils.addSessionCleanupWrapper(metadataService); metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
final AtlasTypesDef deptTypesDef = TestUtilsV2.defineDeptEmployeeTypes(); final AtlasTypesDef deptTypesDef = TestUtilsV2.defineDeptEmployeeTypes();
typeDefStore.createTypesDef(deptTypesDef); typeDefStore.createTypesDef(deptTypesDef);
...@@ -143,7 +146,7 @@ public abstract class AtlasDeleteHandlerV1Test { ...@@ -143,7 +146,7 @@ public abstract class AtlasDeleteHandlerV1Test {
@BeforeTest @BeforeTest
public void init() throws Exception { public void init() throws Exception {
RequestContextV1.clear(); RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
} }
@AfterClass @AfterClass
...@@ -335,7 +338,6 @@ public abstract class AtlasDeleteHandlerV1Test { ...@@ -335,7 +338,6 @@ public abstract class AtlasDeleteHandlerV1Test {
AtlasEntity.AtlasEntitiesWithExtInfo hrDept = TestUtilsV2.createDeptEg2(); AtlasEntity.AtlasEntitiesWithExtInfo hrDept = TestUtilsV2.createDeptEg2();
init(); init();
RequestContextV1.clear();
final EntityMutationResponse hrDeptCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(hrDept), false); final EntityMutationResponse hrDeptCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(hrDept), false);
final AtlasEntityHeader deptCreated = hrDeptCreationResponse.getFirstUpdatedEntityByTypeName(DEPARTMENT_TYPE); final AtlasEntityHeader deptCreated = hrDeptCreationResponse.getFirstUpdatedEntityByTypeName(DEPARTMENT_TYPE);
final AtlasEntityHeader maxEmployeeCreated = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "Max"); final AtlasEntityHeader maxEmployeeCreated = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "Max");
...@@ -893,7 +895,7 @@ public abstract class AtlasDeleteHandlerV1Test { ...@@ -893,7 +895,7 @@ public abstract class AtlasDeleteHandlerV1Test {
object = mapOwnerVertex.getProperty(atlasEdgeLabel.getQualifiedMapKey(), Object.class); object = mapOwnerVertex.getProperty(atlasEdgeLabel.getQualifiedMapKey(), Object.class);
Assert.assertNotNull(object); Assert.assertNotNull(object);
RequestContextV1.clear(); init();
List<AtlasEntityHeader> deletedEntities = entityStore.deleteById(mapOwnerGuid).getDeletedEntities(); List<AtlasEntityHeader> deletedEntities = entityStore.deleteById(mapOwnerGuid).getDeletedEntities();
Assert.assertEquals(deletedEntities.size(), 2); Assert.assertEquals(deletedEntities.size(), 2);
Assert.assertTrue(extractGuids(deletedEntities).contains(mapOwnerGuid)); Assert.assertTrue(extractGuids(deletedEntities).contains(mapOwnerGuid));
...@@ -927,6 +929,8 @@ public abstract class AtlasDeleteHandlerV1Test { ...@@ -927,6 +929,8 @@ public abstract class AtlasDeleteHandlerV1Test {
ImmutableList.<AtlasClassificationDef>of(), ImmutableList.<AtlasClassificationDef>of(),
ImmutableList.<AtlasEntityDef>of(mapValueDef, mapOwnerDef)); ImmutableList.<AtlasEntityDef>of(mapValueDef, mapOwnerDef));
TestUtilsV2.populateSystemAttributes(typesDef);
typeDefStore.createTypesDef(typesDef); typeDefStore.createTypesDef(typesDef);
AtlasEntityType mapOwnerType = typeRegistry.getEntityTypeByName("RequiredMapOwner"); AtlasEntityType mapOwnerType = typeRegistry.getEntityTypeByName("RequiredMapOwner");
...@@ -1033,7 +1037,7 @@ public abstract class AtlasDeleteHandlerV1Test { ...@@ -1033,7 +1037,7 @@ public abstract class AtlasDeleteHandlerV1Test {
String mapValueGuid = mapValueInstance.getId()._getId(); String mapValueGuid = mapValueInstance.getId()._getId();
// Create instance of MapValueReferencerContainer // Create instance of MapValueReferencerContainer
RequestContextV1.clear(); init();
AtlasEntity mapValueReferencer = new AtlasEntity(mapValueDef.getName()); AtlasEntity mapValueReferencer = new AtlasEntity(mapValueDef.getName());
mapValueReferencer.setAttribute("refToMapValue", new AtlasObjectId(mapValueInstance.getId()._getId(), mapValueInstance.getTypeName())); mapValueReferencer.setAttribute("refToMapValue", new AtlasObjectId(mapValueInstance.getId()._getId(), mapValueInstance.getTypeName()));
AtlasEntity.AtlasEntitiesWithExtInfo entities = new AtlasEntity.AtlasEntitiesWithExtInfo(); AtlasEntity.AtlasEntitiesWithExtInfo entities = new AtlasEntity.AtlasEntitiesWithExtInfo();
...@@ -1051,7 +1055,7 @@ public abstract class AtlasDeleteHandlerV1Test { ...@@ -1051,7 +1055,7 @@ public abstract class AtlasDeleteHandlerV1Test {
mapValueReferenceContainer.setAttribute("requiredMap", Collections.singletonMap("value1", AtlasTypeUtil.getAtlasObjectId(mapValueReferencer))); mapValueReferenceContainer.setAttribute("requiredMap", Collections.singletonMap("value1", AtlasTypeUtil.getAtlasObjectId(mapValueReferencer)));
RequestContextV1.clear(); init();
EntityMutationResponse updateEntitiesResult = entityStore.createOrUpdate(new AtlasEntityStream(entities), false); EntityMutationResponse updateEntitiesResult = entityStore.createOrUpdate(new AtlasEntityStream(entities), false);
String mapValueReferencerContainerGuid = updateEntitiesResult.getCreatedEntitiesByTypeName("MapValueReferencerContainer").get(0).getGuid(); String mapValueReferencerContainerGuid = updateEntitiesResult.getCreatedEntitiesByTypeName("MapValueReferencerContainer").get(0).getGuid();
......
...@@ -114,6 +114,9 @@ public class AtlasEntityStoreV1Test { ...@@ -114,6 +114,9 @@ public class AtlasEntityStoreV1Test {
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
metadataService = TestUtils.addSessionCleanupWrapper(metadataService); metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
new GraphBackedSearchIndexer(typeRegistry); new GraphBackedSearchIndexer(typeRegistry);
...@@ -151,6 +154,7 @@ public class AtlasEntityStoreV1Test { ...@@ -151,6 +154,7 @@ public class AtlasEntityStoreV1Test {
public void init() throws Exception { public void init() throws Exception {
entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier, graphMapper); entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier, graphMapper);
RequestContextV1.clear(); RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
} }
@Test @Test
......
...@@ -20,6 +20,7 @@ package org.apache.atlas.repository.store.graph.v1; ...@@ -20,6 +20,7 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.apache.atlas.RequestContextV1; import org.apache.atlas.RequestContextV1;
import org.apache.atlas.TestModules; import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
...@@ -113,6 +114,7 @@ public abstract class AtlasRelationshipStoreV1Test { ...@@ -113,6 +114,7 @@ public abstract class AtlasRelationshipStoreV1Test {
relationshipStore = new AtlasRelationshipStoreV1(typeRegistry); relationshipStore = new AtlasRelationshipStoreV1(typeRegistry);
RequestContextV1.clear(); RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
} }
@AfterClass @AfterClass
......
...@@ -76,6 +76,9 @@ public abstract class InverseReferenceUpdateV1Test { ...@@ -76,6 +76,9 @@ public abstract class InverseReferenceUpdateV1Test {
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
metadataService = TestUtils.addSessionCleanupWrapper(metadataService); metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(), AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(),
...@@ -106,6 +109,7 @@ public abstract class InverseReferenceUpdateV1Test { ...@@ -106,6 +109,7 @@ public abstract class InverseReferenceUpdateV1Test {
@BeforeMethod @BeforeMethod
public void init() throws Exception { public void init() throws Exception {
RequestContextV1.clear(); RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER);
} }
@Test @Test
......
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