Commit f87f5f22 by Sarath Subramanian Committed by Madhan Neethiraj

ATLAS-1648: Fix HiveHookIT failures

parent d0e9d48b
......@@ -942,7 +942,8 @@ public class HiveHookIT extends HiveITBase {
private String createTrait(String guid) throws AtlasServiceException, JSONException {
//add trait
String traitName = "PII_Trait" + RandomStringUtils.random(10);
//valid type names in v2 must consist of a letter followed by a sequence of letter, number, or _ characters
String traitName = "PII_Trait" + random();
atlasClient.createTraitType(traitName);
Struct traitInstance = new Struct(traitName);
......
......@@ -35,6 +35,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.TimeZone;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
......@@ -110,6 +111,10 @@ public abstract class AtlasBaseTypeDef implements java.io.Serializable {
public static final String SERIALIZED_DATE_FORMAT_STR = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
public static final DateFormat DATE_FORMATTER = new SimpleDateFormat(SERIALIZED_DATE_FORMAT_STR);
static {
DATE_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC"));
}
private final TypeCategory category;
private String guid = null;
private String createdBy = null;
......
......@@ -19,6 +19,7 @@ package org.apache.atlas.repository.converters;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasEntity;
......@@ -27,7 +28,10 @@ import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.persistence.Id;
import org.apache.atlas.typesystem.persistence.StructInstance;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
......@@ -50,23 +54,24 @@ AtlasObjectIdConverter extends AtlasAbstractFormatConverter {
if (v1Obj != null) {
if (v1Obj instanceof Id) {
Id id = (Id) v1Obj;
ret = new AtlasObjectId(id._getId(), id.getTypeName());
} else if (v1Obj instanceof IReferenceableInstance) {
IReferenceableInstance refInst = (IReferenceableInstance) v1Obj;
String guid = refInst.getId()._getId();
ret = new AtlasObjectId(guid, refInst.getTypeName());
if (!converterContext.entityExists(guid)) {
if (!converterContext.entityExists(guid) && hasAnyAssignedAttribute(refInst)) {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(refInst.getTypeName());
AtlasEntityFormatConverter entityFormatConverter = (AtlasEntityFormatConverter) converterRegistry.getConverter(TypeCategory.ENTITY);
AtlasEntity entity = entityFormatConverter.fromV1ToV2(v1Obj, entityType, converterContext);
AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) converterRegistry.getConverter(TypeCategory.ENTITY);
AtlasEntity entity = converter.fromV1ToV2(v1Obj, entityType, converterContext);
converterContext.addReferredEntity(entity);
}
}
}
return ret;
}
......@@ -97,4 +102,39 @@ AtlasObjectIdConverter extends AtlasAbstractFormatConverter {
}
return ret;
}
private boolean hasAnyAssignedAttribute(IReferenceableInstance rInstance) {
boolean ret = false;
if (rInstance instanceof StructInstance) {
StructInstance sInstance = (StructInstance) rInstance;
Map<String, Object> attributes = null;
try {
attributes = sInstance.getValuesMap();
} catch (AtlasException e) {
// ignore
}
if (MapUtils.isNotEmpty(attributes)) {
for (String attrName : attributes.keySet()) {
try {
if (sInstance.isValueSet(attrName)) {
ret = true;
break;
}
} catch (AtlasException e) {
// ignore
}
}
}
} else if (rInstance instanceof Referenceable) {
Referenceable referenceable = (Referenceable) rInstance;
ret = MapUtils.isNotEmpty(referenceable.getValuesMap());
}
return ret;
}
}
......@@ -738,7 +738,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
LOG.debug("Updating entity= {}", tableUpdated);
AtlasClient.EntityResult entityResult = atlasClientV1.updateEntity(tableId._getId(), tableUpdated);
assertEquals(entityResult.getUpdateEntities().size(), 2);
assertEquals(entityResult.getUpdateEntities().size(), 1);
assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId());
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, tableId._getId());
......
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