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();
}
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);
}
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");
}
}
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);
}
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;
}
Aggregations