use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class AuditRepositoryTestBase method testListPagination.
@Test
public void testListPagination() throws Exception {
String id1 = "id1" + rand();
String id2 = "id2" + rand();
String id3 = "id3" + rand();
long ts = System.currentTimeMillis();
Referenceable entity = new Referenceable(rand());
List<EntityAuditEvent> expectedEvents = new ArrayList<>(3);
for (int i = 0; i < 3; i++) {
// Add events for both ids
EntityAuditEvent event = new EntityAuditEvent(id2, ts - i, "user" + i, EntityAuditEvent.EntityAuditAction.ENTITY_UPDATE, "details" + i, entity);
eventRepository.putEventsV1(event);
expectedEvents.add(event);
eventRepository.putEventsV1(new EntityAuditEvent(id1, ts - i, "user" + i, EntityAuditEvent.EntityAuditAction.TAG_DELETE, "details" + i, entity));
eventRepository.putEventsV1(new EntityAuditEvent(id3, ts - i, "user" + i, EntityAuditEvent.EntityAuditAction.TAG_ADD, "details" + i, entity));
}
// Use ts for which there is no event - ts + 2
List<EntityAuditEvent> events = eventRepository.listEventsV1(id2, null, (short) 3);
assertEquals(events.size(), 3);
assertEventEquals(events.get(0), expectedEvents.get(0));
assertEventEquals(events.get(1), expectedEvents.get(1));
assertEventEquals(events.get(2), expectedEvents.get(2));
// Use last event's timestamp for next list(). Should give only 1 event and shouldn't include events from other id
events = eventRepository.listEventsV1(id2, events.get(2).getEventKey(), (short) 3);
assertEquals(events.size(), 1);
assertEventEquals(events.get(0), expectedEvents.get(2));
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class AtlasObjectIdConverter method fromV1ToV2.
@Override
public Object fromV1ToV2(Object v1Obj, AtlasType type, AtlasFormatConverter.ConverterContext converterContext) throws AtlasBaseException {
Object ret = null;
if (v1Obj != null) {
if (v1Obj instanceof Id) {
Id id = (Id) v1Obj;
ret = new AtlasObjectId(id.getId(), id.getTypeName());
} else if (v1Obj instanceof Referenceable) {
Referenceable refInst = (Referenceable) v1Obj;
String guid = refInst.getId().getId();
ret = new AtlasObjectId(guid, refInst.getTypeName());
if (!converterContext.entityExists(guid) && hasAnyAssignedAttribute(refInst)) {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(refInst.getTypeName());
AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) converterRegistry.getConverter(TypeCategory.ENTITY);
AtlasEntity entity = converter.fromV1ToV2(v1Obj, entityType, converterContext);
converterContext.addReferredEntity(entity);
}
}
}
return ret;
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class AtlasObjectIdConverter method fromV2ToV1.
@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
Id ret = null;
if (v2Obj != null) {
if (v2Obj instanceof Map) {
Map v2Map = (Map) v2Obj;
String idStr = (String) v2Map.get(AtlasObjectId.KEY_GUID);
String typeName = (String) v2Map.get(AtlasObjectId.KEY_TYPENAME);
if (StringUtils.isEmpty(idStr)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
ret = new Id(idStr, 0, typeName);
} else if (v2Obj instanceof AtlasObjectId) {
// transient-id
AtlasObjectId objId = (AtlasObjectId) v2Obj;
ret = new Id(objId.getGuid(), 0, objId.getTypeName());
} else if (v2Obj instanceof AtlasEntity) {
AtlasEntity entity = (AtlasEntity) v2Obj;
ret = new Id(entity.getGuid(), entity.getVersion() == null ? 0 : entity.getVersion().intValue(), entity.getTypeName());
} else {
throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, type.getTypeCategory().name());
}
}
return ret;
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class FalconHookIT method testCreateProcess.
@Test
public void testCreateProcess() throws Exception {
Cluster cluster = loadEntity(EntityType.CLUSTER, CLUSTER_RESOURCE, "cluster" + random());
STORE.publish(EntityType.CLUSTER, cluster);
assertClusterIsRegistered(cluster);
Feed infeed = getTableFeed(FEED_RESOURCE, cluster.getName(), null);
String infeedId = atlasClient.getEntity(FalconDataTypes.FALCON_FEED.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, FalconBridge.getFeedQualifiedName(infeed.getName(), cluster.getName())).getId()._getId();
Feed outfeed = getTableFeed(FEED_RESOURCE, cluster.getName());
String outFeedId = atlasClient.getEntity(FalconDataTypes.FALCON_FEED.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, FalconBridge.getFeedQualifiedName(outfeed.getName(), cluster.getName())).getId()._getId();
Process process = loadEntity(EntityType.PROCESS, PROCESS_RESOURCE, "process" + random());
process.getClusters().getClusters().get(0).setName(cluster.getName());
process.getInputs().getInputs().get(0).setFeed(infeed.getName());
process.getOutputs().getOutputs().get(0).setFeed(outfeed.getName());
STORE.publish(EntityType.PROCESS, process);
String pid = assertProcessIsRegistered(process, cluster.getName());
Referenceable processEntity = atlasClient.getEntity(pid);
assertNotNull(processEntity);
assertEquals(processEntity.get(AtlasClient.NAME), process.getName());
assertEquals(((List<Id>) processEntity.get("inputs")).get(0)._getId(), infeedId);
assertEquals(((List<Id>) processEntity.get("outputs")).get(0)._getId(), outFeedId);
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class EntityResource method partialUpdateEntityByGuid.
private Response partialUpdateEntityByGuid(String guid, HttpServletRequest request) {
String entityJson = null;
try {
guid = ParamChecker.notEmpty(guid, "Guid property cannot be null");
entityJson = Servlets.getRequestPayload(request);
if (LOG.isDebugEnabled()) {
LOG.debug("partially updating entity for guid {} : {} ", guid, entityJson);
}
Referenceable updatedEntity = AtlasType.fromV1Json(entityJson, Referenceable.class);
// update referenceable with Id if not specified in payload
Id updateId = updatedEntity.getId();
if (updateId != null && !AtlasTypeUtil.isAssignedGuid(updateId.getId())) {
updatedEntity.setId(new Id(guid, 0, updatedEntity.getTypeName()));
}
AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntity(updatedEntity);
EntityMutationResponse mutationResponse = entitiesStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), true);
CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
if (LOG.isDebugEnabled()) {
LOG.debug("Updated entities: {}", result.getEntityResult());
}
String response = getResponse(result);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
throw toWebApplicationException(e);
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to update entity by GUID {} {}", guid, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
Aggregations