Search in sources :

Example 46 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class StormAtlasHook method createBoltInstance.

private Referenceable createBoltInstance(String boltName, Bolt stormBolt) {
    Referenceable boltReferenceable = new Referenceable(StormDataTypes.STORM_BOLT.getName());
    boltReferenceable.set(AtlasClient.NAME, boltName);
    Serializable instance = Utils.javaDeserialize(stormBolt.get_bolt_object().get_serialized_java(), Serializable.class);
    boltReferenceable.set("driverClass", instance.getClass().getName());
    Map<String, String> flatConfigMap = StormTopologyUtil.getFieldValues(instance, true, null);
    boltReferenceable.set("conf", flatConfigMap);
    return boltReferenceable;
}
Also used : Serializable(java.io.Serializable) Referenceable(org.apache.atlas.v1.model.instance.Referenceable)

Example 47 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class StormAtlasHookIT method testAddEntities.

// TODO: Fix failing test
@Test(enabled = false)
public void testAddEntities() throws Exception {
    StormTopology stormTopology = StormTestUtil.createTestTopology();
    StormTestUtil.submitTopology(stormCluster, TOPOLOGY_NAME, stormTopology);
    LOG.info("Submitted topology {}", TOPOLOGY_NAME);
    // todo: test if topology metadata is registered in atlas
    String guid = getTopologyGUID();
    Assert.assertNotNull(guid);
    LOG.info("GUID is {}", guid);
    Referenceable topologyReferenceable = atlasClient.getEntity(guid);
    Assert.assertNotNull(topologyReferenceable);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) StormTopology(org.apache.storm.generated.StormTopology) Test(org.testng.annotations.Test)

Example 48 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class AtlasHook method notifyEntities.

protected void notifyEntities(String user, List<Referenceable> entities) {
    List<HookNotification> hookNotifications = new ArrayList<>();
    hookNotifications.add(new EntityCreateRequest(user, entities));
    notifyEntities(hookNotifications);
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) ArrayList(java.util.ArrayList) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)

Example 49 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class EntityNotificationV1 method getAllTraits.

// ----- helper methods ----------------------------------------------------
private static List<Struct> getAllTraits(Referenceable entityDefinition, AtlasTypeRegistry typeRegistry) {
    List<Struct> ret = new LinkedList<>();
    for (String traitName : entityDefinition.getTraitNames()) {
        Struct trait = entityDefinition.getTrait(traitName);
        AtlasClassificationType traitType = typeRegistry.getClassificationTypeByName(traitName);
        Set<String> superTypeNames = traitType != null ? traitType.getAllSuperTypes() : null;
        ret.add(trait);
        if (CollectionUtils.isNotEmpty(superTypeNames)) {
            for (String superTypeName : superTypeNames) {
                Struct superTypeTrait = new Struct(superTypeName);
                if (MapUtils.isNotEmpty(trait.getValues())) {
                    AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName);
                    if (superType != null && MapUtils.isNotEmpty(superType.getAllAttributes())) {
                        Map<String, Object> superTypeTraitAttributes = new HashMap<>();
                        for (Map.Entry<String, Object> attrEntry : trait.getValues().entrySet()) {
                            String attrName = attrEntry.getKey();
                            if (superType.getAllAttributes().containsKey(attrName)) {
                                superTypeTraitAttributes.put(attrName, attrEntry.getValue());
                            }
                        }
                        superTypeTrait.setValues(superTypeTraitAttributes);
                    }
                }
                ret.add(superTypeTrait);
            }
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 50 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class EntityJerseyResourceIT method testUTF8.

@Test
public void testUTF8() throws Exception {
    // Type names cannot be arbitrary UTF8 characters. See org.apache.atlas.type.AtlasTypeUtil#validateType()
    String classType = randomString();
    String attrName = random();
    String attrValue = random();
    ClassTypeDefinition classTypeDefinition = TypesUtil.createClassTypeDef(classType, null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef(attrName, AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef typesDef = new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(), Collections.<TraitTypeDefinition>emptyList(), Collections.singletonList(classTypeDefinition));
    createType(typesDef);
    Referenceable instance = new Referenceable(classType);
    instance.set(attrName, attrValue);
    Id guid = createInstance(instance);
    ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
    Referenceable getReferenceable = AtlasType.fromV1Json(AtlasType.toJson(response.get(AtlasClient.DEFINITION)), Referenceable.class);
    Assert.assertEquals(getReferenceable.get(attrName), attrValue);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)143 Test (org.testng.annotations.Test)64 Id (org.apache.atlas.v1.model.instance.Id)37 Struct (org.apache.atlas.v1.model.instance.Struct)23 ArrayList (java.util.ArrayList)20 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 HashMap (java.util.HashMap)12 List (java.util.List)10 AtlasException (org.apache.atlas.AtlasException)10 HookNotification (org.apache.atlas.model.notification.HookNotification)10 Map (java.util.Map)9 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)9 AtlasServiceException (org.apache.atlas.AtlasServiceException)8 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)8 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)7 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)7 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)5