Search in sources :

Example 1 with RequestContext

use of org.hypertrace.gateway.service.common.RequestContext in project gateway-service by hypertrace.

the class GatewayServiceImpl method getTraces.

@Override
public void getTraces(org.hypertrace.gateway.service.v1.trace.TracesRequest request, io.grpc.stub.StreamObserver<org.hypertrace.gateway.service.v1.trace.TracesResponse> responseObserver) {
    Optional<String> tenantId = org.hypertrace.core.grpcutils.context.RequestContext.CURRENT.get().getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    try {
        RequestContext requestContext = new RequestContext(tenantId.get(), org.hypertrace.core.grpcutils.context.RequestContext.CURRENT.get().getRequestHeaders());
        TracesResponse response = traceService.getTracesByFilter(requestContext, request);
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    } catch (Exception e) {
        LOG.error("Error while handling traces request: {}", request, e);
        responseObserver.onError(e);
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) TracesResponse(org.hypertrace.gateway.service.v1.trace.TracesResponse) RequestContext(org.hypertrace.gateway.service.common.RequestContext) ServiceException(com.google.protobuf.ServiceException)

Example 2 with RequestContext

use of org.hypertrace.gateway.service.common.RequestContext in project gateway-service by hypertrace.

the class GatewayServiceImpl method getSpans.

@Override
public void getSpans(org.hypertrace.gateway.service.v1.span.SpansRequest request, io.grpc.stub.StreamObserver<org.hypertrace.gateway.service.v1.span.SpansResponse> responseObserver) {
    Optional<String> tenantId = org.hypertrace.core.grpcutils.context.RequestContext.CURRENT.get().getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    try {
        RequestContext context = new RequestContext(tenantId.get(), org.hypertrace.core.grpcutils.context.RequestContext.CURRENT.get().getRequestHeaders());
        SpansResponse response = spanService.getSpansByFilter(context, request);
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    } catch (Exception e) {
        LOG.error("Error while handling spans request: {}", request, e);
        responseObserver.onError(e);
    }
}
Also used : SpansResponse(org.hypertrace.gateway.service.v1.span.SpansResponse) ServiceException(com.google.protobuf.ServiceException) RequestContext(org.hypertrace.gateway.service.common.RequestContext) ServiceException(com.google.protobuf.ServiceException)

Example 3 with RequestContext

use of org.hypertrace.gateway.service.common.RequestContext in project gateway-service by hypertrace.

the class GatewayServiceImpl method getLogEvents.

@Override
public void getLogEvents(LogEventsRequest request, StreamObserver<LogEventsResponse> responseObserver) {
    Optional<String> tenantId = org.hypertrace.core.grpcutils.context.RequestContext.CURRENT.get().getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    try {
        RequestContext context = new RequestContext(tenantId.get(), org.hypertrace.core.grpcutils.context.RequestContext.CURRENT.get().getRequestHeaders());
        LogEventsResponse response = logEventsService.getLogEventsByFilter(context, request);
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    } catch (Exception e) {
        LOG.error("Error while handling logEvents request: {}", request, e);
        responseObserver.onError(e);
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) RequestContext(org.hypertrace.gateway.service.common.RequestContext) LogEventsResponse(org.hypertrace.gateway.service.v1.log.events.LogEventsResponse) ServiceException(com.google.protobuf.ServiceException)

Example 4 with RequestContext

use of org.hypertrace.gateway.service.common.RequestContext in project gateway-service by hypertrace.

the class EntityService method updateEntity.

public UpdateEntityResponse updateEntity(String tenantId, UpdateEntityRequest request, Map<String, String> requestHeaders) {
    Preconditions.checkArgument(StringUtils.isNotBlank(request.getEntityType()), "entity_type is mandatory in the request.");
    RequestContext requestContext = new RequestContext(tenantId, requestHeaders);
    Map<String, AttributeMetadata> attributeMetadataMap = metadataProvider.getAttributesMetadata(requestContext, request.getEntityType());
    updateEntityRequestValidator.validate(request, attributeMetadataMap);
    UpdateExecutionContext updateExecutionContext = new UpdateExecutionContext(requestHeaders, attributeMetadataMap);
    // Validations have ensured that only EDS update operation is supported.
    // If in the future we need more sophisticated update across data sources, we'll need
    // to add the capability similar to what we have for querying.
    UpdateEntityResponse.Builder responseBuilder = edsEntityUpdater.update(request, updateExecutionContext);
    return responseBuilder.build();
}
Also used : AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata) UpdateEntityResponse(org.hypertrace.gateway.service.v1.entity.UpdateEntityResponse) RequestContext(org.hypertrace.gateway.service.common.RequestContext) UpdateExecutionContext(org.hypertrace.gateway.service.entity.update.UpdateExecutionContext)

Example 5 with RequestContext

use of org.hypertrace.gateway.service.common.RequestContext in project gateway-service by hypertrace.

the class EntityService method bulkUpdateEntities.

public BulkUpdateEntitiesResponse bulkUpdateEntities(String tenantId, BulkUpdateEntitiesRequest request, Map<String, String> requestHeaders) {
    RequestContext requestContext = new RequestContext(tenantId, requestHeaders);
    Map<String, AttributeMetadata> attributeMetadataMap = metadataProvider.getAttributesMetadata(requestContext, request.getEntityType());
    Status status = BULK_UPDATE_ENTITIES_REQUEST_VALIDATOR.validate(request, attributeMetadataMap);
    if (!status.isOk()) {
        LOG.error("Bulk update entities request is not valid: {}", status.getDescription());
        throw status.asRuntimeException();
    }
    UpdateExecutionContext updateExecutionContext = new UpdateExecutionContext(requestHeaders, attributeMetadataMap);
    return edsEntityUpdater.bulkUpdateEntities(request, updateExecutionContext);
}
Also used : Status(io.grpc.Status) AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata) RequestContext(org.hypertrace.gateway.service.common.RequestContext) UpdateExecutionContext(org.hypertrace.gateway.service.entity.update.UpdateExecutionContext)

Aggregations

RequestContext (org.hypertrace.gateway.service.common.RequestContext)13 Test (org.junit.jupiter.api.Test)6 AttributeMetadataProvider (org.hypertrace.gateway.service.common.AttributeMetadataProvider)4 ServiceException (com.google.protobuf.ServiceException)3 Config (com.typesafe.config.Config)3 Filter (org.hypertrace.gateway.service.v1.common.Filter)3 AttributeMetadata (org.hypertrace.core.attribute.service.v1.AttributeMetadata)2 AbstractGatewayServiceTest (org.hypertrace.gateway.service.AbstractGatewayServiceTest)2 EntitiesRequestContext (org.hypertrace.gateway.service.entity.EntitiesRequestContext)2 UpdateExecutionContext (org.hypertrace.gateway.service.entity.update.UpdateExecutionContext)2 EntitiesRequest (org.hypertrace.gateway.service.v1.entity.EntitiesRequest)2 UpdateEntityResponse (org.hypertrace.gateway.service.v1.entity.UpdateEntityResponse)2 LogEventsResponse (org.hypertrace.gateway.service.v1.log.events.LogEventsResponse)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Status (io.grpc.Status)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 EntityFetcherResponse (org.hypertrace.gateway.service.common.datafetcher.EntityFetcherResponse)1 EntityResponse (org.hypertrace.gateway.service.common.datafetcher.EntityResponse)1 EntityExecutionContext (org.hypertrace.gateway.service.entity.query.EntityExecutionContext)1