Search in sources :

Example 6 with AttributeMetadata

use of org.hypertrace.core.attribute.service.v1.AttributeMetadata 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 7 with AttributeMetadata

use of org.hypertrace.core.attribute.service.v1.AttributeMetadata 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)

Example 8 with AttributeMetadata

use of org.hypertrace.core.attribute.service.v1.AttributeMetadata in project gateway-service by hypertrace.

the class UpdateEntityRequestValidator method validate.

@Override
public void validate(UpdateEntityRequest updateEntityRequest, Map<String, AttributeMetadata> attributeMetadataMap) {
    Preconditions.checkArgument(StringUtils.isNotBlank(updateEntityRequest.getEntityType()), "entity_type is mandatory in the request.");
    Preconditions.checkArgument(StringUtils.isNotBlank(updateEntityRequest.getEntityId()), "entity_id is mandatory in the request.");
    Preconditions.checkArgument(updateEntityRequest.getSelectionCount() > 0, "Selection list can't be empty in the request.");
    Preconditions.checkArgument(updateEntityRequest.hasOperation(), "operation needs to be specified in the request");
    if (updateEntityRequest.getOperation().hasSetAttribute()) {
        // check attribute exists
        String attributeId = updateEntityRequest.getOperation().getSetAttribute().getAttribute().getColumnName();
        Preconditions.checkArgument(attributeMetadataMap.containsKey(attributeId), attributeId + " attribute doesn't exist.");
        // only 1 attribute source is supported
        AttributeMetadata metadata = attributeMetadataMap.get(attributeId);
        Preconditions.checkArgument(metadata.getSourcesCount() == 1 && metadata.getSources(0).equals(AttributeSource.EDS), "Only EDS attributes are supported for update right now");
    }
}
Also used : AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata)

Example 9 with AttributeMetadata

use of org.hypertrace.core.attribute.service.v1.AttributeMetadata in project gateway-service by hypertrace.

the class MetricAggregationFunctionUtil method getValueTypeForFunctionType.

public static AttributeKind getValueTypeForFunctionType(FunctionExpression functionExpression, Map<String, AttributeMetadata> attributeMetadataMap) {
    // assumes 1 level of aggregation for now, like the rest of the code
    // Also, for the type, it should follow the outer most aggregation type
    String attributeId = ExpressionReader.getAttributeIdFromAttributeSelection(functionExpression).orElseThrow();
    // AggregationValidator
    AttributeMetadata metadata = attributeMetadataMap.get(attributeId);
    Preconditions.checkArgument(metadata != null, "Failed to find value type for this function because it is unable to find the metadata for %s", attributeId);
    return getValueTypeForFunctionType(functionExpression.getFunction(), metadata);
}
Also used : AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata)

Example 10 with AttributeMetadata

use of org.hypertrace.core.attribute.service.v1.AttributeMetadata in project gateway-service by hypertrace.

the class BulkUpdateEntitiesRequestValidator method validate.

public Status validate(BulkUpdateEntitiesRequest request, Map<String, AttributeMetadata> attributeMetadataMap) {
    if (StringUtils.isBlank(request.getEntityType())) {
        return Status.INVALID_ARGUMENT.withDescription("entity_type is mandatory in the request.");
    }
    if (ObjectUtils.isEmpty(request.getEntityIdsList())) {
        return Status.INVALID_ARGUMENT.withDescription("entity_ids are mandatory in the request.");
    }
    if (!request.hasOperation()) {
        return Status.INVALID_ARGUMENT.withDescription("operation is mandatory in the request.");
    }
    if (!request.getOperation().hasMultiValuedAttributeOperation()) {
        return Status.INVALID_ARGUMENT.withDescription("Only multi-valued operation is currently supported in the request," + " and must be provided as part of the request.");
    }
    MultiValuedAttributeOperation multiValuedAttributeOperation = request.getOperation().getMultiValuedAttributeOperation();
    if (!multiValuedAttributeOperation.hasAttribute()) {
        return Status.INVALID_ARGUMENT.withDescription("attribute needs to be specified in the request");
    }
    // check attribute exists
    String attributeId = multiValuedAttributeOperation.getAttribute().getColumnName();
    if (!attributeMetadataMap.containsKey(attributeId)) {
        return Status.INVALID_ARGUMENT.withDescription(attributeId + " attribute doesn't exist.");
    }
    AttributeMetadata metadata = attributeMetadataMap.get(attributeId);
    if (!metadata.getSourcesList().stream().anyMatch(attributeSource -> attributeSource.equals(AttributeSource.EDS))) {
        return Status.INVALID_ARGUMENT.withDescription("Only EDS attributes are supported for update right now");
    }
    if (multiValuedAttributeOperation.getType() == OPERATION_TYPE_UNSPECIFIED) {
        return Status.INVALID_ARGUMENT.withDescription("operation type needs to be correctly specified in the request");
    }
    return Status.OK;
}
Also used : AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata) MultiValuedAttributeOperation(org.hypertrace.gateway.service.v1.entity.MultiValuedAttributeOperation) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Map(java.util.Map) OPERATION_TYPE_UNSPECIFIED(org.hypertrace.gateway.service.v1.entity.MultiValuedAttributeOperation.OperationType.OPERATION_TYPE_UNSPECIFIED) Status(io.grpc.Status) StringUtils(org.apache.commons.lang3.StringUtils) AttributeSource(org.hypertrace.core.attribute.service.v1.AttributeSource) BulkUpdateEntitiesRequest(org.hypertrace.gateway.service.v1.entity.BulkUpdateEntitiesRequest) MultiValuedAttributeOperation(org.hypertrace.gateway.service.v1.entity.MultiValuedAttributeOperation) AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata)

Aggregations

AttributeMetadata (org.hypertrace.core.attribute.service.v1.AttributeMetadata)140 Test (org.junit.jupiter.api.Test)109 Value (org.hypertrace.core.query.service.api.Value)55 HashMap (java.util.HashMap)44 ExploreRequest (org.hypertrace.gateway.service.v1.explore.ExploreRequest)15 QueryRequest (org.hypertrace.core.query.service.api.QueryRequest)11 ResultSetChunk (org.hypertrace.core.query.service.api.ResultSetChunk)11 EntitiesRequest (org.hypertrace.gateway.service.v1.entity.EntitiesRequest)11 Event (org.hypertrace.core.datamodel.Event)10 TimeAggregation (org.hypertrace.gateway.service.v1.common.TimeAggregation)9 Map (java.util.Map)8 Row (org.hypertrace.core.query.service.api.Row)8 List (java.util.List)7 ColumnMetadata (org.hypertrace.core.query.service.api.ColumnMetadata)7 RequestContext (org.hypertrace.gateway.service.common.RequestContext)7 ArrayList (java.util.ArrayList)6 TracesRequest (org.hypertrace.gateway.service.v1.trace.TracesRequest)6 Iterator (java.util.Iterator)5 BaselineEntitiesRequest (org.hypertrace.gateway.service.v1.baseline.BaselineEntitiesRequest)5 Instant (java.time.Instant)4