Search in sources :

Example 6 with EnrichedEntity

use of org.hypertrace.entity.data.service.v1.EnrichedEntity in project entity-service by hypertrace.

the class EntityDataServiceClient method getEnrichedEntityById.

@Nullable
@Override
public EnrichedEntity getEnrichedEntityById(String tenantId, String entityId) {
    ByIdRequest byIdRequest = ByIdRequest.newBuilder().setEntityId(entityId).build();
    EnrichedEntity entity = execute(tenantId, () -> blockingStub.getEnrichedEntityById(byIdRequest));
    // Handle this here, so that callers can just do a null check
    return entity.equals(EnrichedEntity.getDefaultInstance()) ? null : entity;
}
Also used : ByIdRequest(org.hypertrace.entity.data.service.v1.ByIdRequest) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Nullable(javax.annotation.Nullable)

Example 7 with EnrichedEntity

use of org.hypertrace.entity.data.service.v1.EnrichedEntity in project entity-service by hypertrace.

the class EdsCacheClientTest method testGetEnrichedEntityByIdForNull.

@Test
public void testGetEnrichedEntityByIdForNull() {
    String tenantId = "tenant";
    String enrichedEntityId = "enriched-12345";
    when(entityDataServiceClient.getEnrichedEntityById(anyString(), anyString())).thenReturn(null);
    EnrichedEntity enrichedEntity = edsCacheClient.getEnrichedEntityById(tenantId, enrichedEntityId);
    Assertions.assertNull(enrichedEntity);
    enrichedEntity = edsCacheClient.getEnrichedEntityById(tenantId, enrichedEntityId);
    Assertions.assertNull(enrichedEntity);
    verify(entityDataServiceClient, times(2)).getEnrichedEntityById("tenant", "enriched-12345");
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Test(org.junit.jupiter.api.Test)

Example 8 with EnrichedEntity

use of org.hypertrace.entity.data.service.v1.EnrichedEntity in project entity-service by hypertrace.

the class EntityDataServiceTest method testBulkUpsertEnrichedEntities.

@Test
public void testBulkUpsertEnrichedEntities() {
    EnrichedEntity entity1 = EnrichedEntity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service").setEntityId(UUID.randomUUID().toString()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).build();
    EnrichedEntity entity2 = EnrichedEntity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.DOCKER_CONTAINER.name()).setEntityName("Some container").setEntityId(UUID.randomUUID().toString()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).putRelatedEntities(EntityType.K8S_POD.name(), EnrichedEntities.newBuilder().addEntities(entity1).build()).build();
    entityDataServiceClient.upsertEnrichedEntities(TENANT_ID, EnrichedEntities.newBuilder().addEntities(entity1).addEntities(entity2).build());
    EnrichedEntity actualEntity1 = entityDataServiceClient.getEnrichedEntityById(TENANT_ID, entity1.getEntityId());
    assertEquals(entity1, actualEntity1);
    EnrichedEntity actualEntity2 = entityDataServiceClient.getEnrichedEntityById(TENANT_ID, entity2.getEntityId());
    assertEquals(entity2, actualEntity2);
}
Also used : EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Test(org.junit.jupiter.api.Test)

Aggregations

EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)8 Test (org.junit.jupiter.api.Test)4 HashMap (java.util.HashMap)2 ByIdRequest (org.hypertrace.entity.data.service.v1.ByIdRequest)2 Entity (org.hypertrace.entity.data.service.v1.Entity)2 Streams (com.google.common.collect.Streams)1 Descriptors (com.google.protobuf.Descriptors)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 Message (com.google.protobuf.Message)1 ServiceException (com.google.protobuf.ServiceException)1 Channel (io.grpc.Channel)1 StreamObserver (io.grpc.stub.StreamObserver)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Objects.isNull (java.util.Objects.isNull)1 Optional (java.util.Optional)1