diff --git a/hypertrace-graphql-impl/build.gradle.kts b/hypertrace-graphql-impl/build.gradle.kts index 90c3d9fb..af462d87 100644 --- a/hypertrace-graphql-impl/build.gradle.kts +++ b/hypertrace-graphql-impl/build.gradle.kts @@ -32,6 +32,7 @@ dependencies { implementation(project(":hypertrace-graphql-entity-type")) implementation(project(":hypertrace-graphql-spaces-schema")) implementation(project(":hypertrace-graphql-labels-schema")) + implementation(project(":hypertrace-graphql-label-application-rules-schema")) implementation("org.slf4j:slf4j-api") implementation("com.google.inject:guice") diff --git a/hypertrace-graphql-impl/src/main/java/org/hypertrace/graphql/impl/GraphQlModule.java b/hypertrace-graphql-impl/src/main/java/org/hypertrace/graphql/impl/GraphQlModule.java index 72e21f4a..f8198506 100644 --- a/hypertrace-graphql-impl/src/main/java/org/hypertrace/graphql/impl/GraphQlModule.java +++ b/hypertrace-graphql-impl/src/main/java/org/hypertrace/graphql/impl/GraphQlModule.java @@ -27,6 +27,7 @@ import org.hypertrace.graphql.explorer.ExplorerSchemaModule; import org.hypertrace.graphql.explorer.context.HypertraceExplorerContextModule; import org.hypertrace.graphql.label.LabelSchemaModule; +import org.hypertrace.graphql.label.application.rules.LabelApplicationRuleSchemaModule; import org.hypertrace.graphql.metric.MetricModule; import org.hypertrace.graphql.spaces.SpacesSchemaModule; import org.hypertrace.graphql.utils.metrics.gateway.GatewayMetricUtilsModule; @@ -73,5 +74,6 @@ protected void configure() { install(new SpacesSchemaModule()); install(new RequestTransformationModule()); install(new LabelSchemaModule()); + install(new LabelApplicationRuleSchemaModule()); } } diff --git a/hypertrace-graphql-label-application-rules-schema/build.gradle.kts b/hypertrace-graphql-label-application-rules-schema/build.gradle.kts new file mode 100644 index 00000000..a207d31a --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + `java-library` + jacoco + id("org.hypertrace.jacoco-report-plugin") +} + +dependencies { + api("com.google.inject:guice") + api("com.graphql-java:graphql-java") + api("org.hypertrace.core.graphql:hypertrace-core-graphql-spi") + api("io.github.graphql-java:graphql-java-annotations") + api("org.hypertrace.core.graphql:hypertrace-core-graphql-common-schema") + + annotationProcessor("org.projectlombok:lombok") + compileOnly("org.projectlombok:lombok") + + implementation("org.slf4j:slf4j-api") + implementation("io.reactivex.rxjava3:rxjava") + implementation("org.hypertrace.config.service:label-application-rule-config-service-api") + implementation("com.google.protobuf:protobuf-java-util") + implementation("com.google.guava:guava") + + implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-context") + implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-grpc-utils") + implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-schema-utils") + implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-rx-utils") + implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-deserialization") + + implementation(project(":hypertrace-graphql-service-config")) +} + +tasks.test { + useJUnitPlatform() +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/LabelApplicationRuleSchemaFragment.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/LabelApplicationRuleSchemaFragment.java new file mode 100644 index 00000000..2a2f6c17 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/LabelApplicationRuleSchemaFragment.java @@ -0,0 +1,23 @@ +package org.hypertrace.graphql.label.application.rules; + +import org.hypertrace.core.graphql.spi.schema.GraphQlSchemaFragment; +import org.hypertrace.graphql.label.application.rules.schema.mutation.LabelApplicationRuleMutationSchema; +import org.hypertrace.graphql.label.application.rules.schema.query.LabelApplicationRuleQuerySchema; + +public class LabelApplicationRuleSchemaFragment implements GraphQlSchemaFragment { + + @Override + public String fragmentName() { + return "Label Application Rules Schema"; + } + + @Override + public Class annotatedQueryClass() { + return LabelApplicationRuleQuerySchema.class; + } + + @Override + public Class annotatedMutationClass() { + return LabelApplicationRuleMutationSchema.class; + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/LabelApplicationRuleSchemaModule.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/LabelApplicationRuleSchemaModule.java new file mode 100644 index 00000000..c3a37921 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/LabelApplicationRuleSchemaModule.java @@ -0,0 +1,21 @@ +package org.hypertrace.graphql.label.application.rules; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; +import org.hypertrace.core.graphql.spi.schema.GraphQlSchemaFragment; +import org.hypertrace.graphql.label.application.rules.dao.LabelApplicationRuleDaoModule; +import org.hypertrace.graphql.label.application.rules.deserialization.LabelApplicationRuleDeserializationModule; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleRequestModule; + +public class LabelApplicationRuleSchemaModule extends AbstractModule { + @Override + protected void configure() { + Multibinder.newSetBinder(binder(), GraphQlSchemaFragment.class) + .addBinding() + .to(LabelApplicationRuleSchemaFragment.class); + + install(new LabelApplicationRuleDaoModule()); + install(new LabelApplicationRuleRequestModule()); + install(new LabelApplicationRuleDeserializationModule()); + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleConfigServiceDao.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleConfigServiceDao.java new file mode 100644 index 00000000..40d0a2a0 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleConfigServiceDao.java @@ -0,0 +1,114 @@ +package org.hypertrace.graphql.label.application.rules.dao; + +import io.grpc.CallCredentials; +import io.reactivex.rxjava3.core.Single; +import java.util.concurrent.TimeUnit; +import javax.inject.Inject; +import org.hypertrace.core.graphql.common.request.ContextualRequest; +import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry; +import org.hypertrace.core.graphql.utils.grpc.GrpcContextBuilder; +import org.hypertrace.graphql.config.HypertraceGraphQlServiceConfig; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleCreateRequest; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleDeleteRequest; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleUpdateRequest; +import org.hypertrace.graphql.label.application.rules.schema.query.LabelApplicationRuleResultSet; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; +import org.hypertrace.label.application.rule.config.service.v1.GetLabelApplicationRulesRequest; +import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleConfigServiceGrpc; +import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleConfigServiceGrpc.LabelApplicationRuleConfigServiceFutureStub; + +class LabelApplicationRuleConfigServiceDao implements LabelApplicationRuleDao { + + private final LabelApplicationRuleConfigServiceFutureStub + labelApplicationRuleConfigServiceFutureStub; + private final GrpcContextBuilder grpcContextBuilder; + private final HypertraceGraphQlServiceConfig serviceConfig; + private final LabelApplicationRuleRequestConverter requestConverter; + private final LabelApplicationRuleResponseConverter responseConverter; + + @Inject + LabelApplicationRuleConfigServiceDao( + HypertraceGraphQlServiceConfig serviceConfig, + CallCredentials credentials, + GrpcContextBuilder grpcContextBuilder, + GrpcChannelRegistry grpcChannelRegistry, + LabelApplicationRuleRequestConverter requestConverter, + LabelApplicationRuleResponseConverter responseConverter) { + this.grpcContextBuilder = grpcContextBuilder; + this.serviceConfig = serviceConfig; + this.requestConverter = requestConverter; + this.responseConverter = responseConverter; + this.labelApplicationRuleConfigServiceFutureStub = + LabelApplicationRuleConfigServiceGrpc.newFutureStub( + grpcChannelRegistry.forAddress( + serviceConfig.getConfigServiceHost(), serviceConfig.getConfigServicePort())) + .withCallCredentials(credentials); + } + + @Override + public Single createLabelApplicationRule( + LabelApplicationRuleCreateRequest request) { + return Single.fromFuture( + this.grpcContextBuilder + .build(request.context()) + .call( + () -> + this.labelApplicationRuleConfigServiceFutureStub + .withDeadlineAfter( + serviceConfig.getConfigServiceTimeout().toMillis(), + TimeUnit.MILLISECONDS) + .createLabelApplicationRule( + this.requestConverter.convertCreationRequest(request)))) + .flatMap(this.responseConverter::convertCreateLabelApplicationRuleResponse); + } + + @Override + public Single getLabelApplicationRules(ContextualRequest request) { + return Single.fromFuture( + this.grpcContextBuilder + .build(request.context()) + .call( + () -> + this.labelApplicationRuleConfigServiceFutureStub + .withDeadlineAfter( + serviceConfig.getConfigServiceTimeout().toMillis(), + TimeUnit.MILLISECONDS) + .getLabelApplicationRules( + GetLabelApplicationRulesRequest.getDefaultInstance()))) + .flatMap(this.responseConverter::convertGetLabelApplicationsRuleResponse); + } + + @Override + public Single updateLabelApplicationRule( + LabelApplicationRuleUpdateRequest request) { + return Single.fromFuture( + this.grpcContextBuilder + .build(request.context()) + .call( + () -> + this.labelApplicationRuleConfigServiceFutureStub + .withDeadlineAfter( + serviceConfig.getConfigServiceTimeout().toMillis(), + TimeUnit.MILLISECONDS) + .updateLabelApplicationRule( + this.requestConverter.convertUpdateRequest(request)))) + .flatMap(this.responseConverter::convertUpdateLabelApplicationRuleResponse); + } + + @Override + public Single deleteLabelApplicationRule(LabelApplicationRuleDeleteRequest request) { + return Single.fromFuture( + this.grpcContextBuilder + .build(request.context()) + .call( + () -> + this.labelApplicationRuleConfigServiceFutureStub + .withDeadlineAfter( + serviceConfig.getConfigServiceTimeout().toMillis(), + TimeUnit.MILLISECONDS) + .deleteLabelApplicationRule( + this.requestConverter.convertDeleteRequest(request)))) + .flatMap( + unusedResponse -> this.responseConverter.buildDeleteLabelApplicationRuleResponse()); + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleDao.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleDao.java new file mode 100644 index 00000000..a52ea49d --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleDao.java @@ -0,0 +1,21 @@ +package org.hypertrace.graphql.label.application.rules.dao; + +import io.reactivex.rxjava3.core.Single; +import org.hypertrace.core.graphql.common.request.ContextualRequest; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleCreateRequest; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleDeleteRequest; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleUpdateRequest; +import org.hypertrace.graphql.label.application.rules.schema.query.LabelApplicationRuleResultSet; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; + +public interface LabelApplicationRuleDao { + Single createLabelApplicationRule( + LabelApplicationRuleCreateRequest request); + + Single getLabelApplicationRules(ContextualRequest request); + + Single updateLabelApplicationRule( + LabelApplicationRuleUpdateRequest request); + + Single deleteLabelApplicationRule(LabelApplicationRuleDeleteRequest request); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleDaoModule.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleDaoModule.java new file mode 100644 index 00000000..7f7387dc --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleDaoModule.java @@ -0,0 +1,18 @@ +package org.hypertrace.graphql.label.application.rules.dao; + +import com.google.inject.AbstractModule; +import io.grpc.CallCredentials; +import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig; +import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry; +import org.hypertrace.core.graphql.utils.grpc.GrpcContextBuilder; + +public class LabelApplicationRuleDaoModule extends AbstractModule { + @Override + protected void configure() { + bind(LabelApplicationRuleDao.class).to(LabelApplicationRuleConfigServiceDao.class); + requireBinding(CallCredentials.class); + requireBinding(GraphQlServiceConfig.class); + requireBinding(GrpcChannelRegistry.class); + requireBinding(GrpcContextBuilder.class); + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleRequestConverter.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleRequestConverter.java new file mode 100644 index 00000000..bc05ea3d --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleRequestConverter.java @@ -0,0 +1,168 @@ +package org.hypertrace.graphql.label.application.rules.dao; + +import java.util.List; +import java.util.stream.Collectors; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleCreateRequest; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleDeleteRequest; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleUpdateRequest; +import org.hypertrace.label.application.rule.config.service.v1.CreateLabelApplicationRuleRequest; +import org.hypertrace.label.application.rule.config.service.v1.DeleteLabelApplicationRuleRequest; +import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData; +import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.Action; +import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.CompositeCondition; +import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.Condition; +import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.LeafCondition; +import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.StringCondition; +import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.UnaryCondition; +import org.hypertrace.label.application.rule.config.service.v1.UpdateLabelApplicationRuleRequest; + +class LabelApplicationRuleRequestConverter { + public CreateLabelApplicationRuleRequest convertCreationRequest( + LabelApplicationRuleCreateRequest labelApplicationRuleCreateRequest) { + org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRuleData data = + labelApplicationRuleCreateRequest.labelApplicationRuleData(); + return CreateLabelApplicationRuleRequest.newBuilder() + .setData(convertLabelApplicationRuleData(data)) + .build(); + } + + public UpdateLabelApplicationRuleRequest convertUpdateRequest( + LabelApplicationRuleUpdateRequest labelApplicationRuleUpdateRequest) { + return UpdateLabelApplicationRuleRequest.newBuilder() + .setId(labelApplicationRuleUpdateRequest.labelApplicationRule().id()) + .setData( + convertLabelApplicationRuleData( + labelApplicationRuleUpdateRequest + .labelApplicationRule() + .labelApplicationRuleData())) + .build(); + } + + public DeleteLabelApplicationRuleRequest convertDeleteRequest( + LabelApplicationRuleDeleteRequest labelApplicationRuleDeleteRequest) { + return DeleteLabelApplicationRuleRequest.newBuilder() + .setId(labelApplicationRuleDeleteRequest.id()) + .build(); + } + + private LabelApplicationRuleData convertLabelApplicationRuleData( + org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRuleData data) { + return LabelApplicationRuleData.newBuilder() + .setName(data.name()) + .setMatchingCondition(convertConditionList(data.conditionList())) + .setLabelAction(convertLabelAction(data.action())) + .build(); + } + + private Action.Operation getOperationFromAction( + org.hypertrace.graphql.label.application.rules.schema.shared.Action action) { + switch (action.operation()) { + case OPERATION_MERGE: + return Action.Operation.OPERATION_MERGE; + default: + throw new IllegalArgumentException("Unsupported Operation"); + } + } + + private Action convertLabelAction( + org.hypertrace.graphql.label.application.rules.schema.shared.Action action) { + Action.Operation operation = getOperationFromAction(action); + Action.Builder actionBuilder = + Action.newBuilder().setOperation(operation).addAllEntityTypes(action.entityTypes()); + switch (action.type()) { + case STATIC_LABELS: + return actionBuilder + .setStaticLabels( + Action.StaticLabels.newBuilder().addAllIds(action.staticLabels().ids()).build()) + .build(); + case DYNAMIC_LABEL_KEY: + return actionBuilder.setDynamicLabelKey(action.dynamicLabelKey()).build(); + default: + throw new IllegalArgumentException("Unsupported action value"); + } + } + + Condition convertConditionList( + List conditionList) { + if (conditionList.size() == 1) { + return convertCondition(conditionList.get(0)); + } else { + List childConditions = + conditionList.stream().map(this::convertCondition).collect(Collectors.toList()); + + CompositeCondition compositeCondition = + CompositeCondition.newBuilder() + .addAllChildren(childConditions) + .setOperator(CompositeCondition.LogicalOperator.LOGICAL_OPERATOR_AND) + .build(); + return Condition.newBuilder().setCompositeCondition(compositeCondition).build(); + } + } + + Condition convertCondition( + org.hypertrace.graphql.label.application.rules.schema.shared.Condition condition) { + LeafCondition leafCondition = convertLeafCondition(condition.leafCondition()); + return Condition.newBuilder().setLeafCondition(leafCondition).build(); + } + + LeafCondition convertLeafCondition( + org.hypertrace.graphql.label.application.rules.schema.shared.LeafCondition leafCondition) { + LeafCondition.Builder leafConditionBuilder = + LeafCondition.newBuilder() + .setKeyCondition(convertStringCondition(leafCondition.keyCondition())); + switch (leafCondition.valueCondition().valueConditionType()) { + case STRING_CONDITION: + return leafConditionBuilder + .setStringCondition( + convertStringCondition(leafCondition.valueCondition().stringCondition())) + .build(); + case UNARY_CONDITION: + return leafConditionBuilder + .setUnaryCondition( + convertUnaryCondition(leafCondition.valueCondition().unaryCondition())) + .build(); + default: + throw new IllegalArgumentException("Unsupported Leaf Condition"); + } + } + + StringCondition convertStringCondition( + org.hypertrace.graphql.label.application.rules.schema.shared.StringCondition + stringCondition) { + return StringCondition.newBuilder() + .setOperator(convertStringConditionOperator(stringCondition.operator())) + .setValue(stringCondition.value()) + .build(); + } + + UnaryCondition convertUnaryCondition( + org.hypertrace.graphql.label.application.rules.schema.shared.UnaryCondition unaryCondition) { + return UnaryCondition.newBuilder() + .setOperator(convertUnaryOperator(unaryCondition.operator())) + .build(); + } + + StringCondition.Operator convertStringConditionOperator( + org.hypertrace.graphql.label.application.rules.schema.shared.StringCondition.Operator + operator) { + switch (operator) { + case OPERATOR_EQUALS: + return StringCondition.Operator.OPERATOR_EQUALS; + case OPERATOR_MATCHES_REGEX: + return StringCondition.Operator.OPERATOR_MATCHES_REGEX; + default: + throw new IllegalArgumentException("Unsupported String Condition Operator"); + } + } + + UnaryCondition.Operator convertUnaryOperator( + org.hypertrace.graphql.label.application.rules.schema.shared.UnaryCondition.Operator + operator) { + switch (operator) { + case OPERATOR_EXISTS: + return UnaryCondition.Operator.OPERATOR_EXISTS; + default: + throw new IllegalArgumentException("Unsupported Unary Condition Operator"); + } + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleResponseConverter.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleResponseConverter.java new file mode 100644 index 00000000..35ef25ee --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/dao/LabelApplicationRuleResponseConverter.java @@ -0,0 +1,326 @@ +package org.hypertrace.graphql.label.application.rules.dao; + +import io.reactivex.rxjava3.core.Maybe; +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.core.Single; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import lombok.Value; +import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; +import org.hypertrace.graphql.label.application.rules.schema.query.LabelApplicationRuleResultSet; +import org.hypertrace.graphql.label.application.rules.schema.shared.Action; +import org.hypertrace.graphql.label.application.rules.schema.shared.Condition; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRuleData; +import org.hypertrace.graphql.label.application.rules.schema.shared.LeafCondition; +import org.hypertrace.graphql.label.application.rules.schema.shared.StaticLabels; +import org.hypertrace.graphql.label.application.rules.schema.shared.StringCondition; +import org.hypertrace.graphql.label.application.rules.schema.shared.UnaryCondition; +import org.hypertrace.graphql.label.application.rules.schema.shared.ValueCondition; +import org.hypertrace.label.application.rule.config.service.v1.CreateLabelApplicationRuleResponse; +import org.hypertrace.label.application.rule.config.service.v1.GetLabelApplicationRulesResponse; +import org.hypertrace.label.application.rule.config.service.v1.UpdateLabelApplicationRuleResponse; + +@Slf4j +class LabelApplicationRuleResponseConverter { + Single convertCreateLabelApplicationRuleResponse( + CreateLabelApplicationRuleResponse response) { + Optional labelApplicationRule = + convertLabelApplicationRule(response.getLabelApplicationRule()); + return labelApplicationRule + .map(Single::just) + .orElse( + Single.error(new IllegalArgumentException("Unable to convert rule create response"))); + } + + Single convertGetLabelApplicationsRuleResponse( + GetLabelApplicationRulesResponse response) { + return Observable.fromIterable(response.getLabelApplicationRulesList()) + .map(this::convertLabelApplicationRule) + .flatMapMaybe(Maybe::fromOptional) + .toList() + .map(ConvertedLabelApplicationRuleResultSet::forRuleList); + } + + Single convertUpdateLabelApplicationRuleResponse( + UpdateLabelApplicationRuleResponse response) { + Optional labelApplicationRule = + convertLabelApplicationRule(response.getLabelApplicationRule()); + return labelApplicationRule + .map(Single::just) + .orElse( + Single.error(new IllegalArgumentException("Unable to convert rule update response"))); + } + + Single buildDeleteLabelApplicationRuleResponse() { + return Single.just(true); + } + + private Optional convertLabelApplicationRule( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRule rule) { + Optional ruleData = convertLabelApplicationRuleData(rule.getData()); + return ruleData.map(data -> new ConvertedLabelApplicationRule(rule.getId(), data)); + } + + private Optional convertLabelApplicationRuleData( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData data) { + Optional action = convertAction(data.getLabelAction()); + List conditionList = convertCondition(data.getMatchingCondition()); + if (conditionList.isEmpty()) { + return Optional.empty(); + } + return action.map( + labelAction -> + new ConvertedLabelApplicationRuleData(data.getName(), conditionList, labelAction)); + } + + private Optional convertOperationInAction( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.Action + action) { + switch (action.getOperation()) { + case OPERATION_MERGE: + return Optional.of(Action.Operation.OPERATION_MERGE); + default: + log.error("Unrecognized Operation type in Action{}", action.getOperation().name()); + return Optional.empty(); + } + } + + private Optional convertAction( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.Action + action) { + List entityTypes = action.getEntityTypesList(); + Optional operation = convertOperationInAction(action); + switch (action.getValueCase()) { + case STATIC_LABELS: + StaticLabels staticLabels = convertStaticLabels(action.getStaticLabels()); + return operation.map( + op -> + new ConvertedAction( + entityTypes, op, staticLabels, null, Action.ActionType.STATIC_LABELS)); + case DYNAMIC_LABEL_KEY: + return operation.map( + op -> + new ConvertedAction( + entityTypes, + op, + null, + action.getDynamicLabelKey(), + Action.ActionType.DYNAMIC_LABEL_KEY)); + default: + log.error("Unrecognized Value type in Action {}", action.getValueCase().name()); + return Optional.empty(); + } + } + + private StaticLabels convertStaticLabels( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.Action + .StaticLabels + staticLabels) { + return new ConvertedStaticLabels(staticLabels.getIdsList()); + } + + private List convertCondition( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.Condition + condition) { + switch (condition.getConditionCase()) { + case LEAF_CONDITION: + Optional convertedCondition = + convertLeafCondition(condition.getLeafCondition()).map(ConvertedCondition::new); + return convertedCondition.map(List::of).orElse(Collections.emptyList()); + case COMPOSITE_CONDITION: + return convertCompositeCondition(condition.getCompositeCondition()); + default: + log.error("Unrecognized Condition Type {}", condition.getConditionCase().name()); + return Collections.emptyList(); + } + } + + private List convertCompositeCondition( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData + .CompositeCondition + compositeCondition) { + List leafConditionList = + compositeCondition.getChildrenList().stream() + .filter(this::isLeafCondition) + .map(condition -> convertLeafCondition(condition.getLeafCondition())) + .flatMap(Optional::stream) + .map(ConvertedCondition::new) + .collect(Collectors.toList()); + if (leafConditionList.size() != compositeCondition.getChildrenList().size()) { + return Collections.emptyList(); + } + return leafConditionList; + } + + private boolean isLeafCondition( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.Condition + condition) { + switch (condition.getConditionCase()) { + case LEAF_CONDITION: + return true; + case COMPOSITE_CONDITION: + default: + return false; + } + } + + private Optional convertLeafCondition( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.LeafCondition + leafCondition) { + Optional keyCondition = + convertStringCondition(leafCondition.getKeyCondition()); + Optional valueCondition = convertValueCondition(leafCondition); + if (keyCondition.isEmpty() || valueCondition.isEmpty()) { + return Optional.empty(); + } + return Optional.of( + new ConvertedLeafCondition(keyCondition.orElseThrow(), valueCondition.orElseThrow())); + } + + private Optional convertValueCondition( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.LeafCondition + leafCondition) { + switch (leafCondition.getConditionCase()) { + case STRING_CONDITION: + Optional stringValueCondition = + convertStringCondition(leafCondition.getStringCondition()); + return stringValueCondition.map( + stringCondition -> + new ConvertedValueCondition( + stringCondition, null, ValueCondition.ValueConditionType.STRING_CONDITION)); + case UNARY_CONDITION: + Optional unaryValueCondition = + convertUnaryCondition(leafCondition.getUnaryCondition()); + return unaryValueCondition.map( + unaryCondition -> + new ConvertedValueCondition( + null, unaryCondition, ValueCondition.ValueConditionType.UNARY_CONDITION)); + case JSON_CONDITION: + default: + log.error("Unrecognized Value Condition Type {}", leafCondition.getConditionCase().name()); + return Optional.empty(); + } + } + + private Optional convertStringCondition( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData + .StringCondition + stringCondition) { + Optional operator = convertOperatorInStringCondition(stringCondition); + return operator.map(op -> new ConvertedStringCondition(op, stringCondition.getValue())); + } + + private Optional convertOperatorInStringCondition( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData + .StringCondition + stringCondition) { + switch (stringCondition.getOperator()) { + case OPERATOR_EQUALS: + return Optional.of(StringCondition.Operator.OPERATOR_EQUALS); + case OPERATOR_MATCHES_REGEX: + return Optional.of(StringCondition.Operator.OPERATOR_MATCHES_REGEX); + default: + log.error( + "Unrecognized Operator Type in String Condition {}", + stringCondition.getOperator().name()); + return Optional.empty(); + } + } + + private Optional convertUnaryCondition( + org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData + .UnaryCondition + unaryCondition) { + switch (unaryCondition.getOperator()) { + case OPERATOR_EXISTS: + return Optional.of(new ConvertedUnaryCondition(UnaryCondition.Operator.OPERATOR_EXISTS)); + default: + log.error( + "Unrecognized Operator Type in Unary Condition {}", + unaryCondition.getOperator().name()); + return Optional.empty(); + } + } + + @Value + @Accessors(fluent = true) + private static class ConvertedLabelApplicationRule implements LabelApplicationRule { + String id; + LabelApplicationRuleData labelApplicationRuleData; + } + + @Value + @Accessors(fluent = true) + private static class ConvertedLabelApplicationRuleData implements LabelApplicationRuleData { + String name; + List conditionList; + Action action; + } + + @Value + @Accessors(fluent = true) + private static class ConvertedAction implements Action { + List entityTypes; + Operation operation; + StaticLabels staticLabels; + String dynamicLabelKey; + ActionType type; + } + + @Value + @Accessors(fluent = true) + private static class ConvertedStaticLabels implements StaticLabels { + List ids; + } + + @Value + @Accessors(fluent = true) + private static class ConvertedCondition implements Condition { + LeafCondition leafCondition; + } + + @Value + @Accessors(fluent = true) + private static class ConvertedLeafCondition implements LeafCondition { + StringCondition keyCondition; + ValueCondition valueCondition; + } + + @Value + @Accessors(fluent = true) + private static class ConvertedValueCondition implements ValueCondition { + StringCondition stringCondition; + UnaryCondition unaryCondition; + ValueConditionType valueConditionType; + } + + @Value + @Accessors(fluent = true) + private static class ConvertedUnaryCondition implements UnaryCondition { + Operator operator; + } + + @Value + @Accessors(fluent = true) + private static class ConvertedStringCondition implements StringCondition { + Operator operator; + String value; + } + + @Value + @Accessors(fluent = true) + private static class ConvertedLabelApplicationRuleResultSet + implements LabelApplicationRuleResultSet { + private static LabelApplicationRuleResultSet forRuleList(List ruleList) { + return new ConvertedLabelApplicationRuleResultSet(ruleList, ruleList.size(), ruleList.size()); + } + + List results; + long total; + long count; + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleDataDeserializationConfig.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleDataDeserializationConfig.java new file mode 100644 index 00000000..7d7fc531 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleDataDeserializationConfig.java @@ -0,0 +1,140 @@ +package org.hypertrace.graphql.label.application.rules.deserialization; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.module.SimpleModule; +import java.util.List; +import lombok.NoArgsConstructor; +import lombok.Value; +import lombok.experimental.Accessors; +import org.hypertrace.core.graphql.deserialization.ArgumentDeserializationConfig; +import org.hypertrace.graphql.label.application.rules.schema.shared.Action; +import org.hypertrace.graphql.label.application.rules.schema.shared.Condition; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRuleData; +import org.hypertrace.graphql.label.application.rules.schema.shared.LeafCondition; +import org.hypertrace.graphql.label.application.rules.schema.shared.StaticLabels; +import org.hypertrace.graphql.label.application.rules.schema.shared.StringCondition; +import org.hypertrace.graphql.label.application.rules.schema.shared.UnaryCondition; +import org.hypertrace.graphql.label.application.rules.schema.shared.ValueCondition; + +public class LabelApplicationRuleDataDeserializationConfig + implements ArgumentDeserializationConfig { + @Override + public String getArgumentKey() { + return LabelApplicationRuleData.ARGUMENT_NAME; + } + + @Override + public Class getArgumentSchema() { + return LabelApplicationRuleData.class; + } + + @Override + public List jacksonModules() { + return List.of( + new SimpleModule() + .addAbstractTypeMapping( + LabelApplicationRuleData.class, LabelApplicationRuleDataArgument.class) + .addAbstractTypeMapping(Action.class, ActionArgument.class) + .addAbstractTypeMapping(StaticLabels.class, StaticLabelsArgument.class) + .addAbstractTypeMapping(Condition.class, ConditionArgument.class) + .addAbstractTypeMapping(LeafCondition.class, LeafConditionArgument.class) + .addAbstractTypeMapping(ValueCondition.class, ValueConditionArgument.class) + .addAbstractTypeMapping(StringCondition.class, StringConditionArgument.class) + .addAbstractTypeMapping(UnaryCondition.class, UnaryConditionArgument.class)); + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class LabelApplicationRuleDataArgument implements LabelApplicationRuleData { + @JsonProperty(NAME_KEY) + String name; + + @JsonProperty(CONDITION_LIST_KEY) + List conditionList; + + @JsonProperty(ACTION_KEY) + Action action; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class ActionArgument implements Action { + @JsonProperty(ENTITY_TYPES_KEY) + List entityTypes; + + @JsonProperty(OPERATION_KEY) + Operation operation; + + @JsonProperty(STATIC_LABELS) + StaticLabels staticLabels; + + @JsonProperty(DYNAMIC_LABEL_KEY_KEY) + String dynamicLabelKey; + + @JsonProperty(ACTION_TYPE_KEY) + ActionType type; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class StaticLabelsArgument implements StaticLabels { + @JsonProperty(IDS_KEY) + List ids; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class ConditionArgument implements Condition { + @JsonProperty(LEAF_CONDITION_KEY) + LeafCondition leafCondition; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class LeafConditionArgument implements LeafCondition { + @JsonProperty(KEY_CONDITION_KEY) + StringCondition keyCondition; + + @JsonProperty(VALUE_CONDITION_KEY) + ValueCondition valueCondition; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class ValueConditionArgument implements ValueCondition { + @JsonProperty(STRING_CONDITION_KEY) + StringCondition stringCondition; + + @JsonProperty(UNARY_CONDITION_KEY) + UnaryCondition unaryCondition; + + @JsonProperty(VALUE_CONDITION_TYPE_KEY) + ValueConditionType valueConditionType; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class StringConditionArgument implements StringCondition { + @JsonProperty(OPERATOR_KEY) + Operator operator; + + @JsonProperty(VALUE_KEY) + String value; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class UnaryConditionArgument implements UnaryCondition { + @JsonProperty(OPERATOR_KEY) + Operator operator; + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleDeserializationConfig.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleDeserializationConfig.java new file mode 100644 index 00000000..1eecc2aa --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleDeserializationConfig.java @@ -0,0 +1,152 @@ +package org.hypertrace.graphql.label.application.rules.deserialization; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.module.SimpleModule; +import java.util.List; +import lombok.NoArgsConstructor; +import lombok.Value; +import lombok.experimental.Accessors; +import org.hypertrace.core.graphql.deserialization.ArgumentDeserializationConfig; +import org.hypertrace.graphql.label.application.rules.schema.shared.Action; +import org.hypertrace.graphql.label.application.rules.schema.shared.Condition; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRuleData; +import org.hypertrace.graphql.label.application.rules.schema.shared.LeafCondition; +import org.hypertrace.graphql.label.application.rules.schema.shared.StaticLabels; +import org.hypertrace.graphql.label.application.rules.schema.shared.StringCondition; +import org.hypertrace.graphql.label.application.rules.schema.shared.UnaryCondition; +import org.hypertrace.graphql.label.application.rules.schema.shared.ValueCondition; + +public class LabelApplicationRuleDeserializationConfig implements ArgumentDeserializationConfig { + @Override + public String getArgumentKey() { + return LabelApplicationRule.ARGUMENT_NAME; + } + + @Override + public Class getArgumentSchema() { + return LabelApplicationRule.class; + } + + @Override + public List jacksonModules() { + return List.of( + new SimpleModule() + .addAbstractTypeMapping(LabelApplicationRule.class, LabelApplicationRuleArgument.class) + .addAbstractTypeMapping( + LabelApplicationRuleData.class, LabelApplicationRuleDataArgument.class) + .addAbstractTypeMapping(Action.class, ActionArgument.class) + .addAbstractTypeMapping(StaticLabels.class, StaticLabelsArgument.class) + .addAbstractTypeMapping(Condition.class, ConditionArgument.class) + .addAbstractTypeMapping(LeafCondition.class, LeafConditionArgument.class) + .addAbstractTypeMapping(ValueCondition.class, ValueConditionArgument.class) + .addAbstractTypeMapping(StringCondition.class, StringConditionArgument.class) + .addAbstractTypeMapping(UnaryCondition.class, UnaryConditionArgument.class)); + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class LabelApplicationRuleArgument implements LabelApplicationRule { + @JsonProperty(IDENTITY_FIELD_NAME) + String id; + + @JsonProperty(LABEL_APPLICATION_RULE_DATA_KEY) + LabelApplicationRuleData labelApplicationRuleData; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class LabelApplicationRuleDataArgument implements LabelApplicationRuleData { + @JsonProperty(NAME_KEY) + String name; + + @JsonProperty(CONDITION_LIST_KEY) + List conditionList; + + @JsonProperty(ACTION_KEY) + Action action; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class ActionArgument implements Action { + @JsonProperty(ENTITY_TYPES_KEY) + List entityTypes; + + @JsonProperty(OPERATION_KEY) + Operation operation; + + @JsonProperty(STATIC_LABELS) + StaticLabels staticLabels; + + @JsonProperty(DYNAMIC_LABEL_KEY_KEY) + String dynamicLabelKey; + + @JsonProperty(ACTION_TYPE_KEY) + ActionType type; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class StaticLabelsArgument implements StaticLabels { + @JsonProperty(IDS_KEY) + List ids; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class ConditionArgument implements Condition { + @JsonProperty(LEAF_CONDITION_KEY) + LeafCondition leafCondition; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class LeafConditionArgument implements LeafCondition { + @JsonProperty(KEY_CONDITION_KEY) + StringCondition keyCondition; + + @JsonProperty(VALUE_CONDITION_KEY) + ValueCondition valueCondition; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class ValueConditionArgument implements ValueCondition { + @JsonProperty(STRING_CONDITION_KEY) + StringCondition stringCondition; + + @JsonProperty(UNARY_CONDITION_KEY) + UnaryCondition unaryCondition; + + @JsonProperty(VALUE_CONDITION_TYPE_KEY) + ValueConditionType valueConditionType; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class StringConditionArgument implements StringCondition { + @JsonProperty(OPERATOR_KEY) + Operator operator; + + @JsonProperty(VALUE_KEY) + String value; + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class UnaryConditionArgument implements UnaryCondition { + @JsonProperty(OPERATOR_KEY) + Operator operator; + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleDeserializationModule.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleDeserializationModule.java new file mode 100644 index 00000000..a280c1a5 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleDeserializationModule.java @@ -0,0 +1,25 @@ +package org.hypertrace.graphql.label.application.rules.deserialization; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; +import org.hypertrace.core.graphql.deserialization.ArgumentDeserializationConfig; + +public class LabelApplicationRuleDeserializationModule extends AbstractModule { + @Override + protected void configure() { + Multibinder deserializationConfigBinder = + Multibinder.newSetBinder(binder(), ArgumentDeserializationConfig.class); + + deserializationConfigBinder + .addBinding() + .to(LabelApplicationRuleDataDeserializationConfig.class); + deserializationConfigBinder.addBinding().to(LabelApplicationRuleDeserializationConfig.class); + + deserializationConfigBinder + .addBinding() + .toInstance( + ArgumentDeserializationConfig.forPrimitive( + LabelApplicationRuleIdArgument.ARGUMENT_NAME, + LabelApplicationRuleIdArgument.class)); + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleIdArgument.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleIdArgument.java new file mode 100644 index 00000000..b41688cc --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/deserialization/LabelApplicationRuleIdArgument.java @@ -0,0 +1,7 @@ +package org.hypertrace.graphql.label.application.rules.deserialization; + +import org.hypertrace.core.graphql.deserialization.PrimitiveArgument; + +public interface LabelApplicationRuleIdArgument extends PrimitiveArgument { + String ARGUMENT_NAME = "id"; +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/fetcher/LabelApplicationRuleFetcher.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/fetcher/LabelApplicationRuleFetcher.java new file mode 100644 index 00000000..444c7ddd --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/fetcher/LabelApplicationRuleFetcher.java @@ -0,0 +1,39 @@ +package org.hypertrace.graphql.label.application.rules.fetcher; + +import graphql.schema.DataFetcher; +import graphql.schema.DataFetchingEnvironment; +import java.util.concurrent.CompletableFuture; +import javax.inject.Inject; +import org.hypertrace.core.graphql.common.fetcher.InjectableDataFetcher; +import org.hypertrace.core.graphql.common.request.ContextualRequestBuilder; +import org.hypertrace.graphql.label.application.rules.dao.LabelApplicationRuleDao; +import org.hypertrace.graphql.label.application.rules.schema.query.LabelApplicationRuleResultSet; + +public class LabelApplicationRuleFetcher + extends InjectableDataFetcher { + public LabelApplicationRuleFetcher() { + super(LabelApplicationRuleFetcherImpl.class); + } + + static final class LabelApplicationRuleFetcherImpl + implements DataFetcher> { + private final ContextualRequestBuilder requestBuilder; + private final LabelApplicationRuleDao labelApplicationRuleDao; + + @Inject + LabelApplicationRuleFetcherImpl( + ContextualRequestBuilder requestBuilder, LabelApplicationRuleDao labelApplicationRuleDao) { + this.requestBuilder = requestBuilder; + this.labelApplicationRuleDao = labelApplicationRuleDao; + } + + @Override + public CompletableFuture get( + DataFetchingEnvironment environment) { + return this.labelApplicationRuleDao + .getLabelApplicationRules(this.requestBuilder.build(environment.getContext())) + .toCompletionStage() + .toCompletableFuture(); + } + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/mutator/LabelApplicationRuleCreateMutator.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/mutator/LabelApplicationRuleCreateMutator.java new file mode 100644 index 00000000..d8fe6fb1 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/mutator/LabelApplicationRuleCreateMutator.java @@ -0,0 +1,41 @@ +package org.hypertrace.graphql.label.application.rules.mutator; + +import graphql.schema.DataFetcher; +import graphql.schema.DataFetchingEnvironment; +import java.util.concurrent.CompletableFuture; +import javax.inject.Inject; +import org.hypertrace.core.graphql.common.fetcher.InjectableDataFetcher; +import org.hypertrace.graphql.label.application.rules.dao.LabelApplicationRuleDao; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleRequestBuilder; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; + +public class LabelApplicationRuleCreateMutator extends InjectableDataFetcher { + + public LabelApplicationRuleCreateMutator() { + super(LabelApplicationRuleCreateMutatorImpl.class); + } + + static final class LabelApplicationRuleCreateMutatorImpl + implements DataFetcher> { + private final LabelApplicationRuleRequestBuilder requestBuilder; + private final LabelApplicationRuleDao labelApplicationRuleDao; + + @Inject + LabelApplicationRuleCreateMutatorImpl( + LabelApplicationRuleRequestBuilder requestBuilder, + LabelApplicationRuleDao labelApplicationRuleDao) { + this.requestBuilder = requestBuilder; + this.labelApplicationRuleDao = labelApplicationRuleDao; + } + + @Override + public CompletableFuture get(DataFetchingEnvironment environment) { + return this.labelApplicationRuleDao + .createLabelApplicationRule( + this.requestBuilder.buildCreateLabelApplicationRuleRequest( + environment.getContext(), environment.getArguments())) + .toCompletionStage() + .toCompletableFuture(); + } + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/mutator/LabelApplicationRuleDeleteMutator.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/mutator/LabelApplicationRuleDeleteMutator.java new file mode 100644 index 00000000..c2fadffe --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/mutator/LabelApplicationRuleDeleteMutator.java @@ -0,0 +1,39 @@ +package org.hypertrace.graphql.label.application.rules.mutator; + +import graphql.schema.DataFetcher; +import graphql.schema.DataFetchingEnvironment; +import java.util.concurrent.CompletableFuture; +import javax.inject.Inject; +import org.hypertrace.core.graphql.common.fetcher.InjectableDataFetcher; +import org.hypertrace.graphql.label.application.rules.dao.LabelApplicationRuleDao; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleRequestBuilder; + +public class LabelApplicationRuleDeleteMutator extends InjectableDataFetcher { + public LabelApplicationRuleDeleteMutator() { + super(LabelApplicationRuleDeleteMutatorImpl.class); + } + + static final class LabelApplicationRuleDeleteMutatorImpl + implements DataFetcher> { + private final LabelApplicationRuleRequestBuilder requestBuilder; + private final LabelApplicationRuleDao labelApplicationRuleDao; + + @Inject + LabelApplicationRuleDeleteMutatorImpl( + LabelApplicationRuleRequestBuilder requestBuilder, + LabelApplicationRuleDao labelApplicationRuleDao) { + this.requestBuilder = requestBuilder; + this.labelApplicationRuleDao = labelApplicationRuleDao; + } + + @Override + public CompletableFuture get(DataFetchingEnvironment environment) { + return this.labelApplicationRuleDao + .deleteLabelApplicationRule( + this.requestBuilder.buildDeleteLabelApplicationRuleRequest( + environment.getContext(), environment.getArguments())) + .toCompletionStage() + .toCompletableFuture(); + } + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/mutator/LabelApplicationRuleUpdateMutator.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/mutator/LabelApplicationRuleUpdateMutator.java new file mode 100644 index 00000000..f9d8eea3 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/mutator/LabelApplicationRuleUpdateMutator.java @@ -0,0 +1,41 @@ +package org.hypertrace.graphql.label.application.rules.mutator; + +import graphql.schema.DataFetcher; +import graphql.schema.DataFetchingEnvironment; +import java.util.concurrent.CompletableFuture; +import javax.inject.Inject; +import org.hypertrace.core.graphql.common.fetcher.InjectableDataFetcher; +import org.hypertrace.graphql.label.application.rules.dao.LabelApplicationRuleDao; +import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleRequestBuilder; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; + +public class LabelApplicationRuleUpdateMutator extends InjectableDataFetcher { + + public LabelApplicationRuleUpdateMutator() { + super(LabelApplicationRuleUpdateMutatorImpl.class); + } + + static final class LabelApplicationRuleUpdateMutatorImpl + implements DataFetcher> { + private final LabelApplicationRuleRequestBuilder requestBuilder; + private final LabelApplicationRuleDao labelApplicationRuleDao; + + @Inject + LabelApplicationRuleUpdateMutatorImpl( + LabelApplicationRuleRequestBuilder requestBuilder, + LabelApplicationRuleDao labelApplicationRuleDao) { + this.requestBuilder = requestBuilder; + this.labelApplicationRuleDao = labelApplicationRuleDao; + } + + @Override + public CompletableFuture get(DataFetchingEnvironment environment) { + return this.labelApplicationRuleDao + .updateLabelApplicationRule( + this.requestBuilder.buildUpdateLabelApplicationRuleRequest( + environment.getContext(), environment.getArguments())) + .toCompletionStage() + .toCompletableFuture(); + } + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleCreateRequest.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleCreateRequest.java new file mode 100644 index 00000000..2f9eb649 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleCreateRequest.java @@ -0,0 +1,8 @@ +package org.hypertrace.graphql.label.application.rules.request; + +import org.hypertrace.core.graphql.common.request.ContextualRequest; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRuleData; + +public interface LabelApplicationRuleCreateRequest extends ContextualRequest { + LabelApplicationRuleData labelApplicationRuleData(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleDeleteRequest.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleDeleteRequest.java new file mode 100644 index 00000000..c7425dd4 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleDeleteRequest.java @@ -0,0 +1,7 @@ +package org.hypertrace.graphql.label.application.rules.request; + +import org.hypertrace.core.graphql.common.request.ContextualRequest; + +public interface LabelApplicationRuleDeleteRequest extends ContextualRequest { + String id(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleRequestBuilder.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleRequestBuilder.java new file mode 100644 index 00000000..589aaf2a --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleRequestBuilder.java @@ -0,0 +1,15 @@ +package org.hypertrace.graphql.label.application.rules.request; + +import java.util.Map; +import org.hypertrace.core.graphql.context.GraphQlRequestContext; + +public interface LabelApplicationRuleRequestBuilder { + LabelApplicationRuleCreateRequest buildCreateLabelApplicationRuleRequest( + GraphQlRequestContext requestContext, Map arguments); + + LabelApplicationRuleUpdateRequest buildUpdateLabelApplicationRuleRequest( + GraphQlRequestContext requestContext, Map arguments); + + LabelApplicationRuleDeleteRequest buildDeleteLabelApplicationRuleRequest( + GraphQlRequestContext requestContext, Map arguments); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleRequestBuilderImpl.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleRequestBuilderImpl.java new file mode 100644 index 00000000..cde65c0a --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleRequestBuilderImpl.java @@ -0,0 +1,74 @@ +package org.hypertrace.graphql.label.application.rules.request; + +import java.util.Map; +import javax.inject.Inject; +import lombok.Value; +import lombok.experimental.Accessors; +import org.hypertrace.core.graphql.context.GraphQlRequestContext; +import org.hypertrace.core.graphql.deserialization.ArgumentDeserializer; +import org.hypertrace.graphql.label.application.rules.deserialization.LabelApplicationRuleIdArgument; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRuleData; + +public class LabelApplicationRuleRequestBuilderImpl implements LabelApplicationRuleRequestBuilder { + private final ArgumentDeserializer argumentDeserializer; + + @Inject + public LabelApplicationRuleRequestBuilderImpl(ArgumentDeserializer argumentDeserializer) { + this.argumentDeserializer = argumentDeserializer; + } + + @Override + public LabelApplicationRuleCreateRequest buildCreateLabelApplicationRuleRequest( + GraphQlRequestContext requestContext, Map arguments) { + return new LabelApplicationRuleCreateRequestImpl( + requestContext, + this.argumentDeserializer + .deserializeObject(arguments, LabelApplicationRuleData.class) + .orElseThrow()); + } + + @Override + public LabelApplicationRuleUpdateRequest buildUpdateLabelApplicationRuleRequest( + GraphQlRequestContext requestContext, Map arguments) { + return new LabelApplicationRuleUpdateRequestImpl( + requestContext, + this.argumentDeserializer + .deserializeObject(arguments, LabelApplicationRule.class) + .orElseThrow()); + } + + @Override + public LabelApplicationRuleDeleteRequest buildDeleteLabelApplicationRuleRequest( + GraphQlRequestContext requestContext, Map arguments) { + return new LabelApplicationRuleIdArgumentImpl( + requestContext, + this.argumentDeserializer + .deserializePrimitive(arguments, LabelApplicationRuleIdArgument.class) + .orElseThrow()); + } + + @Value + @Accessors(fluent = true) + private static class LabelApplicationRuleCreateRequestImpl + implements LabelApplicationRuleCreateRequest { + GraphQlRequestContext context; + LabelApplicationRuleData labelApplicationRuleData; + } + + @Value + @Accessors(fluent = true) + private static class LabelApplicationRuleUpdateRequestImpl + implements LabelApplicationRuleUpdateRequest { + GraphQlRequestContext context; + LabelApplicationRule labelApplicationRule; + } + + @Value + @Accessors(fluent = true) + private static class LabelApplicationRuleIdArgumentImpl + implements LabelApplicationRuleDeleteRequest { + GraphQlRequestContext context; + String id; + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleRequestModule.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleRequestModule.java new file mode 100644 index 00000000..4ef58515 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleRequestModule.java @@ -0,0 +1,12 @@ +package org.hypertrace.graphql.label.application.rules.request; + +import com.google.inject.AbstractModule; +import org.hypertrace.core.graphql.deserialization.ArgumentDeserializer; + +public class LabelApplicationRuleRequestModule extends AbstractModule { + @Override + protected void configure() { + bind(LabelApplicationRuleRequestBuilder.class).to(LabelApplicationRuleRequestBuilderImpl.class); + requireBinding(ArgumentDeserializer.class); + } +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleUpdateRequest.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleUpdateRequest.java new file mode 100644 index 00000000..04f8ffc2 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/request/LabelApplicationRuleUpdateRequest.java @@ -0,0 +1,8 @@ +package org.hypertrace.graphql.label.application.rules.request; + +import org.hypertrace.core.graphql.common.request.ContextualRequest; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; + +public interface LabelApplicationRuleUpdateRequest extends ContextualRequest { + LabelApplicationRule labelApplicationRule(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/mutation/LabelApplicationRuleMutationSchema.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/mutation/LabelApplicationRuleMutationSchema.java new file mode 100644 index 00000000..b811c638 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/mutation/LabelApplicationRuleMutationSchema.java @@ -0,0 +1,41 @@ +package org.hypertrace.graphql.label.application.rules.schema.mutation; + +import graphql.annotations.annotationTypes.GraphQLDataFetcher; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; +import org.hypertrace.graphql.label.application.rules.deserialization.LabelApplicationRuleIdArgument; +import org.hypertrace.graphql.label.application.rules.mutator.LabelApplicationRuleCreateMutator; +import org.hypertrace.graphql.label.application.rules.mutator.LabelApplicationRuleDeleteMutator; +import org.hypertrace.graphql.label.application.rules.mutator.LabelApplicationRuleUpdateMutator; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRuleData; + +public interface LabelApplicationRuleMutationSchema { + String CREATE_LABEL_APPLICATION_RULE = "createLabelApplicationRule"; + String UPDATE_LABEL_APPLICATION_RULE = "updateLabelApplicationRule"; + String DELETE_LABEL_APPLICATION_RULE = "deleteLabelApplicationRule"; + + @GraphQLField + @GraphQLNonNull + @GraphQLName(CREATE_LABEL_APPLICATION_RULE) + @GraphQLDataFetcher(LabelApplicationRuleCreateMutator.class) + LabelApplicationRule createLabelApplicationRule( + @GraphQLNonNull @GraphQLName(LabelApplicationRuleData.ARGUMENT_NAME) + LabelApplicationRuleData labelApplicationRuleData); + + @GraphQLField + @GraphQLNonNull + @GraphQLName(UPDATE_LABEL_APPLICATION_RULE) + @GraphQLDataFetcher(LabelApplicationRuleUpdateMutator.class) + LabelApplicationRule updateLabelApplicationRule( + @GraphQLNonNull @GraphQLName(LabelApplicationRule.ARGUMENT_NAME) + LabelApplicationRule labelApplicationRule); + + @GraphQLField + @GraphQLNonNull + @GraphQLName(DELETE_LABEL_APPLICATION_RULE) + @GraphQLDataFetcher(LabelApplicationRuleDeleteMutator.class) + Boolean deleteLabelApplicationRule( + @GraphQLNonNull @GraphQLName(LabelApplicationRuleIdArgument.ARGUMENT_NAME) String id); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/query/LabelApplicationRuleQuerySchema.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/query/LabelApplicationRuleQuerySchema.java new file mode 100644 index 00000000..bcde3c49 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/query/LabelApplicationRuleQuerySchema.java @@ -0,0 +1,17 @@ +package org.hypertrace.graphql.label.application.rules.schema.query; + +import graphql.annotations.annotationTypes.GraphQLDataFetcher; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; +import org.hypertrace.graphql.label.application.rules.fetcher.LabelApplicationRuleFetcher; + +public interface LabelApplicationRuleQuerySchema { + String LABEL_APPLICATION_RULE_QUERY_NAME = "labelApplicationRules"; + + @GraphQLField + @GraphQLNonNull + @GraphQLName(LABEL_APPLICATION_RULE_QUERY_NAME) + @GraphQLDataFetcher(LabelApplicationRuleFetcher.class) + LabelApplicationRuleResultSet labelApplicationRules(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/query/LabelApplicationRuleResultSet.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/query/LabelApplicationRuleResultSet.java new file mode 100644 index 00000000..3f002bf9 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/query/LabelApplicationRuleResultSet.java @@ -0,0 +1,19 @@ +package org.hypertrace.graphql.label.application.rules.schema.query; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; +import java.util.List; +import org.hypertrace.core.graphql.common.schema.results.ResultSet; +import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule; + +@GraphQLName(LabelApplicationRuleResultSet.TYPE_NAME) +public interface LabelApplicationRuleResultSet extends ResultSet { + String TYPE_NAME = "LabelApplicationRuleResultSet"; + + @Override + @GraphQLField + @GraphQLNonNull + @GraphQLName(RESULT_SET_RESULTS_NAME) + List results(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/Action.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/Action.java new file mode 100644 index 00000000..e8673193 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/Action.java @@ -0,0 +1,56 @@ +package org.hypertrace.graphql.label.application.rules.schema.shared; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; +import java.util.List; +import javax.annotation.Nullable; + +@GraphQLName(Action.TYPE_NAME) +public interface Action { + String TYPE_NAME = "LabelApplicationAction"; + + String ENTITY_TYPES_KEY = "entityTypes"; + String OPERATION_KEY = "operation"; + String STATIC_LABELS = "staticLabels"; + String DYNAMIC_LABEL_KEY_KEY = "dynamicLabelKey"; + String ACTION_TYPE_KEY = "type"; + + @GraphQLName(Operation.TYPE_NAME) + enum Operation { + OPERATION_MERGE; + private static final String TYPE_NAME = "LabelApplicationActionOperator"; + } + + @GraphQLName(ActionType.TYPE_NAME) + enum ActionType { + STATIC_LABELS, + DYNAMIC_LABEL_KEY; + private static final String TYPE_NAME = "LabelApplicationActionType"; + } + + @GraphQLField + @GraphQLNonNull + @GraphQLName(ENTITY_TYPES_KEY) + List entityTypes(); + + @GraphQLField + @GraphQLNonNull + @GraphQLName(OPERATION_KEY) + Operation operation(); + + @GraphQLField + @Nullable + @GraphQLName(STATIC_LABELS) + StaticLabels staticLabels(); + + @GraphQLField + @Nullable + @GraphQLName(DYNAMIC_LABEL_KEY_KEY) + String dynamicLabelKey(); + + @GraphQLField + @GraphQLNonNull + @GraphQLName(ACTION_TYPE_KEY) + ActionType type(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/Condition.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/Condition.java new file mode 100644 index 00000000..6a3d1b1a --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/Condition.java @@ -0,0 +1,17 @@ +package org.hypertrace.graphql.label.application.rules.schema.shared; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; + +@GraphQLName(Condition.TYPE_NAME) +public interface Condition { + String TYPE_NAME = "LabelApplicationCondition"; + + String LEAF_CONDITION_KEY = "leafCondition"; + + @GraphQLField + @GraphQLName(LEAF_CONDITION_KEY) + @GraphQLNonNull + LeafCondition leafCondition(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/LabelApplicationRule.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/LabelApplicationRule.java new file mode 100644 index 00000000..4ffa4010 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/LabelApplicationRule.java @@ -0,0 +1,19 @@ +package org.hypertrace.graphql.label.application.rules.schema.shared; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; +import org.hypertrace.core.graphql.common.schema.id.Identifiable; + +@GraphQLName(LabelApplicationRule.TYPE_NAME) +public interface LabelApplicationRule extends Identifiable { + String TYPE_NAME = "LabelApplicationRule"; + String ARGUMENT_NAME = "labelApplicationRule"; + + String LABEL_APPLICATION_RULE_DATA_KEY = "labelApplicationRuleData"; + + @GraphQLField + @GraphQLNonNull + @GraphQLName(LABEL_APPLICATION_RULE_DATA_KEY) + LabelApplicationRuleData labelApplicationRuleData(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/LabelApplicationRuleData.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/LabelApplicationRuleData.java new file mode 100644 index 00000000..42b7f744 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/LabelApplicationRuleData.java @@ -0,0 +1,31 @@ +package org.hypertrace.graphql.label.application.rules.schema.shared; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; +import java.util.List; + +@GraphQLName(LabelApplicationRuleData.TYPE_NAME) +public interface LabelApplicationRuleData { + String TYPE_NAME = "LabelApplicationRuleData"; + String ARGUMENT_NAME = "labelApplicationRuleData"; + + String NAME_KEY = "name"; + String CONDITION_LIST_KEY = "conditionList"; + String ACTION_KEY = "action"; + + @GraphQLField + @GraphQLNonNull + @GraphQLName(NAME_KEY) + String name(); + + @GraphQLField + @GraphQLNonNull + @GraphQLName(CONDITION_LIST_KEY) + List conditionList(); + + @GraphQLField + @GraphQLNonNull + @GraphQLName(ACTION_KEY) + Action action(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/LeafCondition.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/LeafCondition.java new file mode 100644 index 00000000..f5e60fa5 --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/LeafCondition.java @@ -0,0 +1,23 @@ +package org.hypertrace.graphql.label.application.rules.schema.shared; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; + +@GraphQLName(LeafCondition.TYPE_NAME) +public interface LeafCondition { + String TYPE_NAME = "LabelApplicationLeafCondition"; + + String KEY_CONDITION_KEY = "keyCondition"; + String VALUE_CONDITION_KEY = "valueCondition"; + + @GraphQLField + @GraphQLNonNull + @GraphQLName(KEY_CONDITION_KEY) + StringCondition keyCondition(); + + @GraphQLField + @GraphQLNonNull + @GraphQLName(VALUE_CONDITION_KEY) + ValueCondition valueCondition(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/StaticLabels.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/StaticLabels.java new file mode 100644 index 00000000..697a96de --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/StaticLabels.java @@ -0,0 +1,18 @@ +package org.hypertrace.graphql.label.application.rules.schema.shared; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; +import java.util.List; + +@GraphQLName(StaticLabels.TYPE_NAME) +public interface StaticLabels { + String TYPE_NAME = "LabelApplicationStaticLabels"; + + String IDS_KEY = "ids"; + + @GraphQLField + @GraphQLNonNull + @GraphQLName(IDS_KEY) + List ids(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/StringCondition.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/StringCondition.java new file mode 100644 index 00000000..d978293a --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/StringCondition.java @@ -0,0 +1,30 @@ +package org.hypertrace.graphql.label.application.rules.schema.shared; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; + +@GraphQLName(StringCondition.TYPE_NAME) +public interface StringCondition { + String TYPE_NAME = "LabelApplicationStringCondition"; + + String OPERATOR_KEY = "operator"; + String VALUE_KEY = "value"; + + @GraphQLName(Operator.TYPE_NAME) + enum Operator { + OPERATOR_EQUALS, + OPERATOR_MATCHES_REGEX; + private static final String TYPE_NAME = "StringConditionOperator"; + } + + @GraphQLField + @GraphQLNonNull + @GraphQLName(OPERATOR_KEY) + Operator operator(); + + @GraphQLField + @GraphQLNonNull + @GraphQLName(VALUE_KEY) + String value(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/UnaryCondition.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/UnaryCondition.java new file mode 100644 index 00000000..3887623a --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/UnaryCondition.java @@ -0,0 +1,23 @@ +package org.hypertrace.graphql.label.application.rules.schema.shared; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; + +@GraphQLName(UnaryCondition.TYPE_NAME) +public interface UnaryCondition { + String TYPE_NAME = "LabelApplicationUnaryCondition"; + + String OPERATOR_KEY = "operator"; + + @GraphQLName(Operator.TYPE_NAME) + enum Operator { + OPERATOR_EXISTS; + private static final String TYPE_NAME = "UnaryConditionOperator"; + } + + @GraphQLField + @GraphQLNonNull + @GraphQLName(OPERATOR_KEY) + Operator operator(); +} diff --git a/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/ValueCondition.java b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/ValueCondition.java new file mode 100644 index 00000000..d72063ec --- /dev/null +++ b/hypertrace-graphql-label-application-rules-schema/src/main/java/org/hypertrace/graphql/label/application/rules/schema/shared/ValueCondition.java @@ -0,0 +1,37 @@ +package org.hypertrace.graphql.label.application.rules.schema.shared; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; +import javax.annotation.Nullable; + +@GraphQLName(ValueCondition.TYPE_NAME) +public interface ValueCondition { + String TYPE_NAME = "LabelApplicationValueCondition"; + + String STRING_CONDITION_KEY = "stringCondition"; + String UNARY_CONDITION_KEY = "unaryCondition"; + String VALUE_CONDITION_TYPE_KEY = "valueConditionType"; + + @GraphQLName(ValueConditionType.TYPE_NAME) + enum ValueConditionType { + STRING_CONDITION, + UNARY_CONDITION; + private static final String TYPE_NAME = "ValueConditionType"; + } + + @GraphQLField + @GraphQLName(STRING_CONDITION_KEY) + @Nullable + StringCondition stringCondition(); + + @GraphQLField + @GraphQLName(UNARY_CONDITION_KEY) + @Nullable + UnaryCondition unaryCondition(); + + @GraphQLField + @GraphQLName(VALUE_CONDITION_TYPE_KEY) + @GraphQLNonNull + ValueConditionType valueConditionType(); +} diff --git a/hypertrace-graphql-platform/build.gradle.kts b/hypertrace-graphql-platform/build.gradle.kts index d6d0f6bf..0611e171 100644 --- a/hypertrace-graphql-platform/build.gradle.kts +++ b/hypertrace-graphql-platform/build.gradle.kts @@ -12,5 +12,6 @@ dependencies { api("org.hypertrace.entity.service:entity-type-service-rx-client:0.5.6") api("org.hypertrace.config.service:spaces-config-service-api:0.1.1") api("org.hypertrace.config.service:labels-config-service-api:0.1.8") + api("org.hypertrace.config.service:label-application-rule-config-service-api:0.1.14") } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 7754a791..5b845ba3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -26,3 +26,4 @@ include(":hypertrace-graphql-service-config") include(":hypertrace-graphql-platform") include(":hypertrace-graphql-spaces-schema") include(":hypertrace-graphql-labels-schema") +include(":hypertrace-graphql-label-application-rules-schema") \ No newline at end of file