Skip to content

Commit

Permalink
Implementing graphql apis for label application rules (#108)
Browse files Browse the repository at this point in the history
* Implementing graphql apis for label application rules

* Implementing graphql apis for label application rules

* Implementing graphql apis for label application rules

* Implementing graphql apis for label application rules

* Implementing graphql apis for label application rules

* Implementing graphql apis for label application rules

* Implementing graphql apis for label application rules

* Implementing graphql apis for label application rules

* Fixing small bug

* Simplifying schema

* Addessing PR comments

* Addessing PR comments

* Addressing PR comments

* Addressing PR comments

* Upgrade hypertrace-core-graphql from origin/main

Co-authored-by: kamaleshnneerasa <[email protected]>
Co-authored-by: saxenakshitiz <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2021
1 parent ed9fa50 commit 597ad5f
Show file tree
Hide file tree
Showing 38 changed files with 1,669 additions and 0 deletions.
1 change: 1 addition & 0 deletions hypertrace-graphql-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,5 +74,6 @@ protected void configure() {
install(new SpacesSchemaModule());
install(new RequestTransformationModule());
install(new LabelSchemaModule());
install(new LabelApplicationRuleSchemaModule());
}
}
34 changes: 34 additions & 0 deletions hypertrace-graphql-label-application-rules-schema/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -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<LabelApplicationRuleQuerySchema> annotatedQueryClass() {
return LabelApplicationRuleQuerySchema.class;
}

@Override
public Class<?> annotatedMutationClass() {
return LabelApplicationRuleMutationSchema.class;
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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<LabelApplicationRule> 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<LabelApplicationRuleResultSet> 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<LabelApplicationRule> 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<Boolean> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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<LabelApplicationRule> createLabelApplicationRule(
LabelApplicationRuleCreateRequest request);

Single<LabelApplicationRuleResultSet> getLabelApplicationRules(ContextualRequest request);

Single<LabelApplicationRule> updateLabelApplicationRule(
LabelApplicationRuleUpdateRequest request);

Single<Boolean> deleteLabelApplicationRule(LabelApplicationRuleDeleteRequest request);
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit 597ad5f

Please sign in to comment.