Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.grpc.Status;
import io.grpc.stub.StreamObserver;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.hypertrace.alerting.config.service.v1.CreateEventConditionRequest;
import org.hypertrace.alerting.config.service.v1.CreateEventConditionResponse;
Expand All @@ -17,6 +18,7 @@
import org.hypertrace.alerting.config.service.v1.NewEventCondition;
import org.hypertrace.alerting.config.service.v1.UpdateEventConditionRequest;
import org.hypertrace.alerting.config.service.v1.UpdateEventConditionResponse;
import org.hypertrace.config.objectstore.ContextualConfigObject;
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
import org.hypertrace.core.grpcutils.context.RequestContext;

Expand Down Expand Up @@ -50,7 +52,8 @@ public void createEventCondition(
builder.setId(UUID.randomUUID().toString());
responseObserver.onNext(
CreateEventConditionResponse.newBuilder()
.setEventCondition(eventConditionStore.upsertObject(requestContext, builder.build()))
.setEventCondition(
eventConditionStore.upsertObject(requestContext, builder.build()).getData())
.build());
responseObserver.onCompleted();
} catch (Exception e) {
Expand All @@ -69,7 +72,9 @@ public void updateEventCondition(
responseObserver.onNext(
UpdateEventConditionResponse.newBuilder()
.setEventCondition(
eventConditionStore.upsertObject(requestContext, request.getEventCondition()))
eventConditionStore
.upsertObject(requestContext, request.getEventCondition())
.getData())
.build());
responseObserver.onCompleted();
} catch (Exception e) {
Expand All @@ -87,7 +92,10 @@ public void getAllEventConditions(
requestValidator.validateGetAllEventConditionsRequest(requestContext, request);
responseObserver.onNext(
GetAllEventConditionsResponse.newBuilder()
.addAllEventCondition(eventConditionStore.getAllObjects(requestContext))
.addAllEventCondition(
eventConditionStore.getAllObjects(requestContext).stream()
.map(ContextualConfigObject::getData)
.collect(Collectors.toUnmodifiableList()))
.build());
responseObserver.onCompleted();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public EventConditionStore(
}

@Override
protected Optional<EventCondition> buildObjectFromValue(Value value) {
protected Optional<EventCondition> buildDataFromValue(Value value) {
EventCondition.Builder builder = EventCondition.newBuilder();
try {
ConfigProtoConverter.mergeFromValue(value, builder);
Expand All @@ -45,12 +45,12 @@ protected Optional<EventCondition> buildObjectFromValue(Value value) {

@SneakyThrows
@Override
protected Value buildValueFromObject(EventCondition object) {
protected Value buildValueFromData(EventCondition object) {
return ConfigProtoConverter.convertToValue(object);
}

@Override
protected String getContextFromObject(EventCondition object) {
protected String getContextFromData(EventCondition object) {
return object.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import io.grpc.stub.StreamObserver;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.hypertrace.config.objectstore.ConfigObject;
import org.hypertrace.config.objectstore.IdentifiedObjectStore;
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
import org.hypertrace.config.service.v1.ConfigServiceGrpc;
Expand Down Expand Up @@ -51,7 +53,9 @@ public void createLabelApplicationRule(
.setData(request.getData())
.build();
LabelApplicationRule createdLabelApplicationRule =
this.labelApplicationRuleStore.upsertObject(requestContext, labelApplicationRule);
this.labelApplicationRuleStore
.upsertObject(requestContext, labelApplicationRule)
.getData();
responseObserver.onNext(
CreateLabelApplicationRuleResponse.newBuilder()
.setLabelApplicationRule(createdLabelApplicationRule)
Expand All @@ -70,7 +74,9 @@ public void getLabelApplicationRules(
RequestContext requestContext = RequestContext.CURRENT.get();
this.requestValidator.validateOrThrow(requestContext, request);
List<LabelApplicationRule> labelApplicationRules =
this.labelApplicationRuleStore.getAllObjects(requestContext);
this.labelApplicationRuleStore.getAllObjects(requestContext).stream()
.map(ConfigObject::getData)
.collect(Collectors.toUnmodifiableList());
responseObserver.onNext(
GetLabelApplicationRulesResponse.newBuilder()
.addAllLabelApplicationRules(labelApplicationRules)
Expand All @@ -90,12 +96,14 @@ public void updateLabelApplicationRule(
this.requestValidator.validateOrThrow(requestContext, request);
LabelApplicationRule existingRule =
this.labelApplicationRuleStore
.getObject(requestContext, request.getId())
.getData(requestContext, request.getId())
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
LabelApplicationRule updateLabelApplicationRule =
existingRule.toBuilder().setData(request.getData()).build();
LabelApplicationRule upsertedLabelApplicationRule =
this.labelApplicationRuleStore.upsertObject(requestContext, updateLabelApplicationRule);
this.labelApplicationRuleStore
.upsertObject(requestContext, updateLabelApplicationRule)
.getData();
responseObserver.onNext(
UpdateLabelApplicationRuleResponse.newBuilder()
.setLabelApplicationRule(upsertedLabelApplicationRule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LabelApplicationRuleStore extends IdentifiedObjectStore<LabelApplic
}

@Override
protected Optional<LabelApplicationRule> buildObjectFromValue(Value value) {
protected Optional<LabelApplicationRule> buildDataFromValue(Value value) {
try {
LabelApplicationRule.Builder builder = LabelApplicationRule.newBuilder();
ConfigProtoConverter.mergeFromValue(value, builder);
Expand All @@ -37,12 +37,12 @@ protected Optional<LabelApplicationRule> buildObjectFromValue(Value value) {

@SneakyThrows
@Override
protected Value buildValueFromObject(LabelApplicationRule object) {
protected Value buildValueFromData(LabelApplicationRule object) {
return ConfigProtoConverter.convertToValue(object);
}

@Override
protected String getContextFromObject(LabelApplicationRule object) {
protected String getContextFromData(LabelApplicationRule object) {
return object.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected LabelStore(
}

@Override
protected Optional<Label> buildObjectFromValue(Value value) {
protected Optional<Label> buildDataFromValue(Value value) {
try {
Label.Builder builder = Label.newBuilder();
ConfigProtoConverter.mergeFromValue(value, builder);
Expand All @@ -36,12 +36,12 @@ protected Optional<Label> buildObjectFromValue(Value value) {

@Override
@SneakyThrows
protected Value buildValueFromObject(Label object) {
protected Value buildValueFromData(Label object) {
return ConfigProtoConverter.convertToValue(object);
}

@Override
protected String getContextFromObject(Label object) {
protected String getContextFromData(Label object) {
return object.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.stream.Collectors;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.hypertrace.config.objectstore.ContextualConfigObject;
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
import org.hypertrace.config.service.v1.ConfigServiceGrpc;
import org.hypertrace.core.grpcutils.client.RequestContextClientCallCredsProviderFactory;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void createLabel(
.setId(UUID.randomUUID().toString())
.setKey(createLabel.getKey())
.build();
Label createdLabel = labelStore.upsertObject(requestContext, label);
Label createdLabel = labelStore.upsertObject(requestContext, label).getData();
responseObserver.onNext(CreateLabelResponse.newBuilder().setLabel(createdLabel).build());
responseObserver.onCompleted();
} finally {
Expand All @@ -142,7 +143,7 @@ public void getLabel(GetLabelRequest request, StreamObserver<GetLabelResponse> r
} else {
label =
labelStore
.getObject(requestContext, labelId)
.getData(requestContext, labelId)
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
}
responseObserver.onNext(GetLabelResponse.newBuilder().setLabel(label).build());
Expand All @@ -158,7 +159,10 @@ public void getLabels(
RequestContext requestContext = RequestContext.CURRENT.get();
List<Label> allLabels = new ArrayList<>();
allLabels.addAll(systemLabels);
List<Label> tenantLabels = labelStore.getAllObjects(requestContext);
List<Label> tenantLabels =
labelStore.getAllObjects(requestContext).stream()
.map(ContextualConfigObject::getData)
.collect(Collectors.toUnmodifiableList());
allLabels.addAll(tenantLabels);
responseObserver.onNext(GetLabelsResponse.newBuilder().addAllLabels(allLabels).build());
responseObserver.onCompleted();
Expand All @@ -184,9 +188,10 @@ public void updateLabel(
return;
}
labelStore
.getObject(requestContext, updatedLabelInReq.getId())
.getData(requestContext, updatedLabelInReq.getId())
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
Label updatedLabelInRes = labelStore.upsertObject(requestContext, updatedLabelInReq);
Label updatedLabelInRes =
labelStore.upsertObject(requestContext, updatedLabelInReq).getData();
responseObserver.onNext(
UpdateLabelResponse.newBuilder().setLabel(updatedLabelInRes).build());
responseObserver.onCompleted();
Expand Down Expand Up @@ -234,7 +239,10 @@ public void deleteLabel(

private boolean isDuplicateKey(String key) {
RequestContext requestContext = RequestContext.CURRENT.get();
List<Label> labelList = labelStore.getAllObjects(requestContext);
List<Label> labelList =
labelStore.getAllObjects(requestContext).stream()
.map(ContextualConfigObject::getData)
.collect(Collectors.toUnmodifiableList());
Optional<Label> match =
labelList.stream().filter(label -> label.getKey().equals(key)).findAny();
return match.isPresent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import io.grpc.stub.StreamObserver;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.hypertrace.config.objectstore.ConfigObject;
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
import org.hypertrace.core.grpcutils.context.RequestContext;
import org.hypertrace.notification.config.service.v1.CreateNotificationChannelRequest;
Expand Down Expand Up @@ -49,7 +51,7 @@ public void createNotificationChannel(
responseObserver.onNext(
CreateNotificationChannelResponse.newBuilder()
.setNotificationChannel(
notificationChannelStore.upsertObject(requestContext, builder.build()))
notificationChannelStore.upsertObject(requestContext, builder.build()).getData())
.build());
responseObserver.onCompleted();
} catch (Exception e) {
Expand All @@ -68,13 +70,15 @@ public void updateNotificationChannel(
responseObserver.onNext(
UpdateNotificationChannelResponse.newBuilder()
.setNotificationChannel(
notificationChannelStore.upsertObject(
requestContext,
NotificationChannel.newBuilder()
.setId(request.getId())
.setNotificationChannelMutableData(
request.getNotificationChannelMutableData())
.build()))
notificationChannelStore
.upsertObject(
requestContext,
NotificationChannel.newBuilder()
.setId(request.getId())
.setNotificationChannelMutableData(
request.getNotificationChannelMutableData())
.build())
.getData())
.build());
responseObserver.onCompleted();
} catch (Exception e) {
Expand All @@ -91,7 +95,9 @@ public void getAllNotificationChannels(
RequestContext requestContext = RequestContext.CURRENT.get();
validator.validateGetAllNotificationChannelsRequest(requestContext, request);
List<NotificationChannel> notificationChannels =
notificationChannelStore.getAllObjects(requestContext);
notificationChannelStore.getAllObjects(requestContext).stream()
.map(ConfigObject::getData)
.collect(Collectors.toUnmodifiableList());
GetAllNotificationChannelsResponse getAllNotificationChannelsResponse =
GetAllNotificationChannelsResponse.newBuilder()
.addAllNotificationChannels(notificationChannels)
Expand Down Expand Up @@ -131,7 +137,7 @@ public void getNotificationChannel(
validator.validateGetNotificationChannelRequest(requestContext, request);
NotificationChannel notificationChannel =
notificationChannelStore
.getObject(requestContext, request.getNotificationChannelId())
.getData(requestContext, request.getNotificationChannelId())
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
responseObserver.onNext(
GetNotificationChannelResponse.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public NotificationChannelStore(
}

@Override
protected Optional<NotificationChannel> buildObjectFromValue(Value value) {
protected Optional<NotificationChannel> buildDataFromValue(Value value) {
NotificationChannel.Builder builder = NotificationChannel.newBuilder();
try {
ConfigProtoConverter.mergeFromValue(value, builder);
Expand All @@ -45,12 +45,12 @@ protected Optional<NotificationChannel> buildObjectFromValue(Value value) {

@SneakyThrows
@Override
protected Value buildValueFromObject(NotificationChannel object) {
protected Value buildValueFromData(NotificationChannel object) {
return ConfigProtoConverter.convertToValue(object);
}

@Override
protected String getContextFromObject(NotificationChannel object) {
protected String getContextFromData(NotificationChannel object) {
return object.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import io.grpc.Status;
import io.grpc.stub.StreamObserver;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.hypertrace.config.objectstore.ConfigObject;
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
import org.hypertrace.core.grpcutils.context.RequestContext;
import org.hypertrace.notification.config.service.v1.CreateNotificationRuleRequest;
Expand Down Expand Up @@ -48,7 +50,7 @@ public void createNotificationRule(
responseObserver.onNext(
CreateNotificationRuleResponse.newBuilder()
.setNotificationRule(
notificationRuleStore.upsertObject(requestContext, builder.build()))
notificationRuleStore.upsertObject(requestContext, builder.build()).getData())
.build());
responseObserver.onCompleted();
} catch (Exception e) {
Expand All @@ -67,12 +69,15 @@ public void updateNotificationRule(
responseObserver.onNext(
UpdateNotificationRuleResponse.newBuilder()
.setNotificationRule(
notificationRuleStore.upsertObject(
requestContext,
NotificationRule.newBuilder()
.setId(request.getId())
.setNotificationRuleMutableData(request.getNotificationRuleMutableData())
.build()))
notificationRuleStore
.upsertObject(
requestContext,
NotificationRule.newBuilder()
.setId(request.getId())
.setNotificationRuleMutableData(
request.getNotificationRuleMutableData())
.build())
.getData())
.build());
responseObserver.onCompleted();
} catch (Exception e) {
Expand All @@ -90,7 +95,10 @@ public void getAllNotificationRules(
validator.validateGetAllNotificationRulesRequest(requestContext, request);
responseObserver.onNext(
GetAllNotificationRulesResponse.newBuilder()
.addAllNotificationRules(notificationRuleStore.getAllObjects(requestContext))
.addAllNotificationRules(
notificationRuleStore.getAllObjects(requestContext).stream()
.map(ConfigObject::getData)
.collect(Collectors.toUnmodifiableList()))
.build());
responseObserver.onCompleted();
} catch (Exception e) {
Expand Down Expand Up @@ -126,7 +134,7 @@ public void getNotificationRule(
validator.validateGetNotificationRuleRequest(requestContext, request);
NotificationRule notificationRule =
notificationRuleStore
.getObject(requestContext, request.getNotificationRuleId())
.getData(requestContext, request.getNotificationRuleId())
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
responseObserver.onNext(
GetNotificationRuleResponse.newBuilder().setNotificationRule(notificationRule).build());
Expand Down
Loading