Commit 5bc6f6bd by Shwetha GS

ATLAS-296 IllegalArgumentException during hive HiveHookIT integration tests…

ATLAS-296 IllegalArgumentException during hive HiveHookIT integration tests (tbeerbower via shwethags)
parent 6f421e99
......@@ -18,14 +18,22 @@
package org.apache.atlas.notification.entity;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.apache.atlas.AtlasException;
import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.notification.NotificationInterface;
import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.json.InstanceSerialization;
import org.apache.atlas.typesystem.types.TypeSystem;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
......@@ -36,9 +44,11 @@ import java.util.List;
*/
public class NotificationEntityChangeListener implements EntityChangeListener {
private static final Gson GSON = new GsonBuilder().
registerTypeAdapter(Referenceable.class, new ReferencableSerializer()).create();
private final NotificationInterface notificationInterface;
private final TypeSystem typeSystem;
private final Gson gson = new Gson();
// ----- Constructors ------------------------------------------------------
......@@ -78,23 +88,37 @@ public class NotificationEntityChangeListener implements EntityChangeListener {
}
// ----- helper methods ----------------------------------------------------
// ----- helper methods -------------------------------------------------
// send notification of entity change
private void notifyOfEntityEvent(Collection<ITypedReferenceableInstance> entityDefinitions,
EntityNotification.OperationType operationType) throws AtlasException {
List<String> messages = new LinkedList<>();
for (ITypedReferenceableInstance entityDefinition : entityDefinitions) {
for (IReferenceableInstance entityDefinition : entityDefinitions) {
Referenceable entity = new Referenceable(entityDefinition);
EntityNotificationImpl notification =
new EntityNotificationImpl(entity, operationType, typeSystem);
messages.add(gson.toJson(notification));
messages.add(GSON.toJson(notification));
}
notificationInterface.send(NotificationInterface.NotificationType.ENTITIES,
messages.toArray(new String[messages.size()]));
}
// ----- inner class : ReferencableSerializer ---------------------------
private static class ReferencableSerializer implements JsonSerializer<Referenceable> {
public static final JsonParser JSON_PARSER = new JsonParser();
@Override
public JsonElement serialize(Referenceable referenceable, Type type,
JsonSerializationContext jsonSerializationContext) {
return JSON_PARSER.parse(InstanceSerialization.toJson(referenceable, true)).getAsJsonObject();
}
}
}
......@@ -9,6 +9,7 @@ ATLAS-54 Rename configs in hive hook (shwethags)
ATLAS-3 Mixed Index creation fails with Date types (sumasai via shwethags)
ALL CHANGES:
ATLAS-296 IllegalArgumentException during hive HiveHookIT integration tests (tbeerbower via shwethags)
ATLAS-158 Provide Atlas Entity Change Notification (tbeerbower via shwethags)
ATALS-238 atlas_start.py- the Atlas server won’t restart after improper shutdown(ndjouri via sumasai)
ATLAS-293 UI Requires Internet Access For UI Facelift (darshankumar89 via shwethags)
......
......@@ -42,7 +42,7 @@ public class Referenceable extends Struct implements IReferenceableInstance {
super(typeName);
id = new Id(typeName);
this.traitNames = ImmutableList.copyOf(traitNames);
ImmutableMap.Builder<String, IStruct> b = new ImmutableMap.Builder<String, IStruct>();
ImmutableMap.Builder<String, IStruct> b = new ImmutableMap.Builder<>();
for (String t : traitNames) {
b.put(t, new Struct(t));
}
......@@ -65,9 +65,9 @@ public class Referenceable extends Struct implements IReferenceableInstance {
/**
* Not public - only use during deserialization
* @param guid
* @param typeName
* @param values
* @param guid the unique id
* @param typeName the type name
* @param values the entity attribute values
*/
@InterfaceAudience.Private
public Referenceable(String guid, String typeName, Map<String, Object> values, List<String> _traitNames,
......@@ -79,13 +79,13 @@ public class Referenceable extends Struct implements IReferenceableInstance {
}
/**
* Construct a Referenceable from the given ITypedReferenceableInstance.
* Construct a Referenceable from the given IReferenceableInstance.
*
* @param instance the typed referenceable instance to copy
* @param instance the referenceable instance to copy
*
* @throws AtlasException if the referenceable can not be created
*/
public Referenceable(ITypedReferenceableInstance instance) throws AtlasException {
public Referenceable(IReferenceableInstance instance) throws AtlasException {
this(instance.getId()._getId(), instance.getTypeName(), instance.getValuesMap(), instance.getTraits(),
getTraits(instance));
}
......@@ -114,11 +114,10 @@ public class Referenceable extends Struct implements IReferenceableInstance {
return traits.get(typeName);
}
private static Map<String, IStruct> getTraits(ITypedReferenceableInstance instance) {
private static Map<String, IStruct> getTraits(IReferenceableInstance instance) throws AtlasException {
Map<String, IStruct> traits = new HashMap<>();
for (String traitName : instance.getTraits() ) {
traits.put(traitName, instance.getTrait(traitName));
traits.put(traitName, new Struct(traitName, instance.getTrait(traitName).getValuesMap()));
}
return traits;
}
......
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