Search in sources :

Example 36 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EntityDataServiceImpl method upsertEnrichedEntities.

@Override
public void upsertEnrichedEntities(EnrichedEntities request, StreamObserver<Empty> responseObserver) {
    String tenantId = RequestContext.CURRENT.get().getTenantId().orElse(null);
    if (isNull(tenantId)) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    for (EnrichedEntity entity : request.getEntitiesList()) {
        if (StringUtils.isEmpty(entity.getEntityType())) {
            LOG.info("{}. Invalid upsertEnrichedEntities request:{}", entity, ErrorMessages.ENTITY_TYPE_EMPTY);
            responseObserver.onError(new RuntimeException(ErrorMessages.ENTITY_TYPE_EMPTY));
            return;
        }
        if (StringUtils.isEmpty(entity.getEntityId())) {
            LOG.info("{}. Invalid upsertEnrichedEntities request:{}", entity, ErrorMessages.ENTITY_ID_EMPTY);
            responseObserver.onError(new RuntimeException(ErrorMessages.ENTITY_ID_EMPTY));
            return;
        }
    }
    Map<Key, EnrichedEntity> entities = request.getEntitiesList().stream().collect(Collectors.toUnmodifiableMap(entity -> this.entityNormalizer.getEntityDocKey(tenantId, entity.getEntityType(), entity.getEntityId()), Function.identity()));
    upsertEntities(entities, enrichedEntitiesCollection, responseObserver);
}
Also used : ByIdRequest(org.hypertrace.entity.data.service.v1.ByIdRequest) ServiceException(com.google.protobuf.ServiceException) LoggerFactory(org.slf4j.LoggerFactory) Channel(io.grpc.Channel) EntityTypeClient(org.hypertrace.entity.type.service.rxclient.EntityTypeClient) StreamObserver(io.grpc.stub.StreamObserver) Map(java.util.Map) Objects.isNull(java.util.Objects.isNull) ENRICHED_ENTITIES_COLLECTION(org.hypertrace.entity.service.constants.EntityCollectionConstants.ENRICHED_ENTITIES_COLLECTION) DocStoreConverter(org.hypertrace.entity.service.util.DocStoreConverter) InvalidRequestException(org.hypertrace.entity.service.exception.InvalidRequestException) StringUtils(org.hypertrace.entity.service.util.StringUtils) Streams(com.google.common.collect.Streams) Empty(org.hypertrace.entity.data.service.v1.Empty) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) EntityRelationship(org.hypertrace.entity.data.service.v1.EntityRelationship) EntityRelationships(org.hypertrace.entity.data.service.v1.EntityRelationships) MergeAndUpsertEntityRequest(org.hypertrace.entity.data.service.v1.MergeAndUpsertEntityRequest) Optional(java.util.Optional) EntityChangeEventGenerator(org.hypertrace.entity.service.change.event.api.EntityChangeEventGenerator) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Builder(org.hypertrace.entity.data.service.v1.Entity.Builder) Document(org.hypertrace.core.documentstore.Document) RequestContext(org.hypertrace.core.grpcutils.context.RequestContext) ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes) DocStoreJsonFormat(org.hypertrace.entity.service.util.DocStoreJsonFormat) Descriptors(com.google.protobuf.Descriptors) Filter(org.hypertrace.core.documentstore.Filter) HashMap(java.util.HashMap) Function(java.util.function.Function) Collection(org.hypertrace.core.documentstore.Collection) Entities(org.hypertrace.entity.data.service.v1.Entities) ArrayList(java.util.ArrayList) Datastore(org.hypertrace.core.documentstore.Datastore) Key(org.hypertrace.core.documentstore.Key) EntityServiceConstants(org.hypertrace.entity.service.constants.EntityServiceConstants) Entity(org.hypertrace.entity.data.service.v1.Entity) EntityDataServiceImplBase(org.hypertrace.entity.data.service.v1.EntityDataServiceGrpc.EntityDataServiceImplBase) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) IOException(java.io.IOException) ENTITY_RELATIONSHIPS_COLLECTION(org.hypertrace.entity.service.constants.EntityCollectionConstants.ENTITY_RELATIONSHIPS_COLLECTION) EnrichedEntities(org.hypertrace.entity.data.service.v1.EnrichedEntities) Query(org.hypertrace.entity.data.service.v1.Query) RAW_ENTITIES_COLLECTION(org.hypertrace.entity.service.constants.EntityCollectionConstants.RAW_ENTITIES_COLLECTION) Message(com.google.protobuf.Message) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) MergeAndUpsertEntityResponse(org.hypertrace.entity.data.service.v1.MergeAndUpsertEntityResponse) Collections(java.util.Collections) RelationshipsQuery(org.hypertrace.entity.data.service.v1.RelationshipsQuery) ServiceException(com.google.protobuf.ServiceException) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Key(org.hypertrace.core.documentstore.Key)

Example 37 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EntityChangeEventGeneratorImpl method sendChangeNotification.

@Override
public void sendChangeNotification(RequestContext requestContext, Collection<Entity> existingEntities, Collection<Entity> updatedEntities) {
    Map<String, Entity> existingEntityMap = existingEntities.stream().collect(Collectors.toMap(Entity::getEntityId, identity()));
    Map<String, Entity> upsertedEntityMap = updatedEntities.stream().collect(Collectors.toMap(Entity::getEntityId, identity()));
    MapDifference<String, Entity> mapDifference = Maps.difference(existingEntityMap, upsertedEntityMap);
    mapDifference.entriesOnlyOnRight().entrySet().forEach(entry -> {
        sendCreateNotification(requestContext, entry.getValue());
    });
    mapDifference.entriesDiffering().entrySet().forEach(entry -> {
        MapDifference.ValueDifference<Entity> valueDifference = entry.getValue();
        Entity prevEntity = valueDifference.leftValue();
        Entity currEntity = valueDifference.rightValue();
        sendUpdateNotification(requestContext, prevEntity, currEntity);
    });
    mapDifference.entriesOnlyOnLeft().entrySet().forEach(entry -> {
        sendDeleteNotification(requestContext, entry.getValue());
    });
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) MapDifference(com.google.common.collect.MapDifference)

Example 38 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EntityChangeEventGeneratorImplTest method sendCreateNotification.

@Test
void sendCreateNotification() {
    List<Entity> entities = createEntities(2);
    changeEventGenerator.sendCreateNotification(requestContext, entities);
    InOrder inOrderVerifier = inOrder(eventProducer);
    inOrderVerifier.verify(eventProducer).send(KeyUtil.getKey(entities.get(0)), EntityChangeEventValue.newBuilder().setCreateEvent(EntityCreateEvent.newBuilder().setCreatedEntity(entities.get(0)).build()).setEventTimeMillis(CURRENT_TIME_MILLIS).build());
    inOrderVerifier.verify(eventProducer).send(KeyUtil.getKey(entities.get(1)), EntityChangeEventValue.newBuilder().setCreateEvent(EntityCreateEvent.newBuilder().setCreatedEntity(entities.get(1)).build()).setEventTimeMillis(CURRENT_TIME_MILLIS).build());
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) InOrder(org.mockito.InOrder) Test(org.junit.jupiter.api.Test)

Example 39 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EntityChangeEventGeneratorImplTest method sendDeleteNotification.

@Test
void sendDeleteNotification() {
    List<Entity> entities = createEntities(2);
    changeEventGenerator.sendDeleteNotification(requestContext, entities);
    InOrder inOrderVerifier = inOrder(eventProducer);
    inOrderVerifier.verify(eventProducer).send(KeyUtil.getKey(entities.get(0)), EntityChangeEventValue.newBuilder().setDeleteEvent(EntityDeleteEvent.newBuilder().setDeletedEntity(entities.get(0)).build()).setEventTimeMillis(CURRENT_TIME_MILLIS).build());
    inOrderVerifier.verify(eventProducer).send(KeyUtil.getKey(entities.get(1)), EntityChangeEventValue.newBuilder().setDeleteEvent(EntityDeleteEvent.newBuilder().setDeletedEntity(entities.get(1)).build()).setEventTimeMillis(CURRENT_TIME_MILLIS).build());
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) InOrder(org.mockito.InOrder) Test(org.junit.jupiter.api.Test)

Example 40 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EdsCacheClient method initCache.

private void initCache(EntityServiceClientCacheConfig cacheConfig, Executor executor) {
    this.enrichedEntityCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEnrichedEntityCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEnrichedEntityCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEnrichedEntityMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {

        public EnrichedEntity load(@Nonnull EdsCacheKey key) throws Exception {
            EnrichedEntity enrichedEntity = client.getEnrichedEntityById(key.tenantId, key.entityId);
            if (enrichedEntity == null) {
                throw new NotFoundException("Enriched entity not found");
            }
            return enrichedEntity;
        }
    }, executor));
    this.entityCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEntityCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEntityCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEntityMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {

        public Entity load(@Nonnull EdsCacheKey key) throws Exception {
            Entity entity = client.getById(key.tenantId, key.entityId);
            if (entity == null) {
                throw new NotFoundException("Entity not found");
            }
            return entity;
        }
    }, executor));
    this.entityIdsCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEntityIdsCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEntityIdsCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEntityIdsMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {

        public String load(@Nonnull EdsTypeAndIdAttributesCacheKey key) throws Exception {
            Entity entity = client.getByTypeAndIdentifyingAttributes(key.tenantId, key.byTypeAndIdentifyingAttributes);
            if (entity == null) {
                throw new NotFoundException("Entity not found!!");
            }
            entityCache.put(new EdsCacheKey(entity.getTenantId(), entity.getEntityId()), entity);
            return entity.getEntityId();
        }
    }, executor));
    PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".enrichedEntityCache", enrichedEntityCache, Collections.emptyMap());
    PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".entityCache", entityCache, Collections.emptyMap());
    PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".entityIdsCache", entityIdsCache, Collections.emptyMap());
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) NotFoundException(org.hypertrace.entity.data.service.client.exception.NotFoundException) NotFoundException(org.hypertrace.entity.data.service.client.exception.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity)

Aggregations

Entity (org.hypertrace.entity.data.service.v1.Entity)110 LivingEntity (org.bukkit.entity.LivingEntity)95 Test (org.junit.jupiter.api.Test)95 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)88 net.minecraft.world.entity (net.minecraft.world.entity)40 org.bukkit.entity (org.bukkit.entity)40 Entity (com.google.datastore.v1.Entity)33 ArrayList (java.util.ArrayList)33 Location (org.bukkit.Location)33 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)32 Event (org.hypertrace.core.datamodel.Event)27 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)21 Mob (net.minecraft.world.entity.Mob)20 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)18 Entity (net.minecraft.server.v1_8_R3.Entity)18 AnnotateVideoProgress (com.google.cloud.videointelligence.v1.AnnotateVideoProgress)17 AnnotateVideoRequest (com.google.cloud.videointelligence.v1.AnnotateVideoRequest)17 AnnotateVideoResponse (com.google.cloud.videointelligence.v1.AnnotateVideoResponse)17 Entity (com.google.cloud.videointelligence.v1.Entity)17