Skip to content

Commit 597ad5f

Browse files
kamaleshnneerasakamaleshnneerasasaxenakshitiz
authored
Implementing graphql apis for label application rules (#108)
* 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]>
1 parent ed9fa50 commit 597ad5f

File tree

38 files changed

+1669
-0
lines changed

38 files changed

+1669
-0
lines changed

hypertrace-graphql-impl/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
implementation(project(":hypertrace-graphql-entity-type"))
3333
implementation(project(":hypertrace-graphql-spaces-schema"))
3434
implementation(project(":hypertrace-graphql-labels-schema"))
35+
implementation(project(":hypertrace-graphql-label-application-rules-schema"))
3536

3637
implementation("org.slf4j:slf4j-api")
3738
implementation("com.google.inject:guice")

hypertrace-graphql-impl/src/main/java/org/hypertrace/graphql/impl/GraphQlModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.hypertrace.graphql.explorer.ExplorerSchemaModule;
2828
import org.hypertrace.graphql.explorer.context.HypertraceExplorerContextModule;
2929
import org.hypertrace.graphql.label.LabelSchemaModule;
30+
import org.hypertrace.graphql.label.application.rules.LabelApplicationRuleSchemaModule;
3031
import org.hypertrace.graphql.metric.MetricModule;
3132
import org.hypertrace.graphql.spaces.SpacesSchemaModule;
3233
import org.hypertrace.graphql.utils.metrics.gateway.GatewayMetricUtilsModule;
@@ -73,5 +74,6 @@ protected void configure() {
7374
install(new SpacesSchemaModule());
7475
install(new RequestTransformationModule());
7576
install(new LabelSchemaModule());
77+
install(new LabelApplicationRuleSchemaModule());
7678
}
7779
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
plugins {
2+
`java-library`
3+
jacoco
4+
id("org.hypertrace.jacoco-report-plugin")
5+
}
6+
7+
dependencies {
8+
api("com.google.inject:guice")
9+
api("com.graphql-java:graphql-java")
10+
api("org.hypertrace.core.graphql:hypertrace-core-graphql-spi")
11+
api("io.github.graphql-java:graphql-java-annotations")
12+
api("org.hypertrace.core.graphql:hypertrace-core-graphql-common-schema")
13+
14+
annotationProcessor("org.projectlombok:lombok")
15+
compileOnly("org.projectlombok:lombok")
16+
17+
implementation("org.slf4j:slf4j-api")
18+
implementation("io.reactivex.rxjava3:rxjava")
19+
implementation("org.hypertrace.config.service:label-application-rule-config-service-api")
20+
implementation("com.google.protobuf:protobuf-java-util")
21+
implementation("com.google.guava:guava")
22+
23+
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-context")
24+
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-grpc-utils")
25+
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-schema-utils")
26+
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-rx-utils")
27+
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-deserialization")
28+
29+
implementation(project(":hypertrace-graphql-service-config"))
30+
}
31+
32+
tasks.test {
33+
useJUnitPlatform()
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.hypertrace.graphql.label.application.rules;
2+
3+
import org.hypertrace.core.graphql.spi.schema.GraphQlSchemaFragment;
4+
import org.hypertrace.graphql.label.application.rules.schema.mutation.LabelApplicationRuleMutationSchema;
5+
import org.hypertrace.graphql.label.application.rules.schema.query.LabelApplicationRuleQuerySchema;
6+
7+
public class LabelApplicationRuleSchemaFragment implements GraphQlSchemaFragment {
8+
9+
@Override
10+
public String fragmentName() {
11+
return "Label Application Rules Schema";
12+
}
13+
14+
@Override
15+
public Class<LabelApplicationRuleQuerySchema> annotatedQueryClass() {
16+
return LabelApplicationRuleQuerySchema.class;
17+
}
18+
19+
@Override
20+
public Class<?> annotatedMutationClass() {
21+
return LabelApplicationRuleMutationSchema.class;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.hypertrace.graphql.label.application.rules;
2+
3+
import com.google.inject.AbstractModule;
4+
import com.google.inject.multibindings.Multibinder;
5+
import org.hypertrace.core.graphql.spi.schema.GraphQlSchemaFragment;
6+
import org.hypertrace.graphql.label.application.rules.dao.LabelApplicationRuleDaoModule;
7+
import org.hypertrace.graphql.label.application.rules.deserialization.LabelApplicationRuleDeserializationModule;
8+
import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleRequestModule;
9+
10+
public class LabelApplicationRuleSchemaModule extends AbstractModule {
11+
@Override
12+
protected void configure() {
13+
Multibinder.newSetBinder(binder(), GraphQlSchemaFragment.class)
14+
.addBinding()
15+
.to(LabelApplicationRuleSchemaFragment.class);
16+
17+
install(new LabelApplicationRuleDaoModule());
18+
install(new LabelApplicationRuleRequestModule());
19+
install(new LabelApplicationRuleDeserializationModule());
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package org.hypertrace.graphql.label.application.rules.dao;
2+
3+
import io.grpc.CallCredentials;
4+
import io.reactivex.rxjava3.core.Single;
5+
import java.util.concurrent.TimeUnit;
6+
import javax.inject.Inject;
7+
import org.hypertrace.core.graphql.common.request.ContextualRequest;
8+
import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry;
9+
import org.hypertrace.core.graphql.utils.grpc.GrpcContextBuilder;
10+
import org.hypertrace.graphql.config.HypertraceGraphQlServiceConfig;
11+
import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleCreateRequest;
12+
import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleDeleteRequest;
13+
import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleUpdateRequest;
14+
import org.hypertrace.graphql.label.application.rules.schema.query.LabelApplicationRuleResultSet;
15+
import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule;
16+
import org.hypertrace.label.application.rule.config.service.v1.GetLabelApplicationRulesRequest;
17+
import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleConfigServiceGrpc;
18+
import org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleConfigServiceGrpc.LabelApplicationRuleConfigServiceFutureStub;
19+
20+
class LabelApplicationRuleConfigServiceDao implements LabelApplicationRuleDao {
21+
22+
private final LabelApplicationRuleConfigServiceFutureStub
23+
labelApplicationRuleConfigServiceFutureStub;
24+
private final GrpcContextBuilder grpcContextBuilder;
25+
private final HypertraceGraphQlServiceConfig serviceConfig;
26+
private final LabelApplicationRuleRequestConverter requestConverter;
27+
private final LabelApplicationRuleResponseConverter responseConverter;
28+
29+
@Inject
30+
LabelApplicationRuleConfigServiceDao(
31+
HypertraceGraphQlServiceConfig serviceConfig,
32+
CallCredentials credentials,
33+
GrpcContextBuilder grpcContextBuilder,
34+
GrpcChannelRegistry grpcChannelRegistry,
35+
LabelApplicationRuleRequestConverter requestConverter,
36+
LabelApplicationRuleResponseConverter responseConverter) {
37+
this.grpcContextBuilder = grpcContextBuilder;
38+
this.serviceConfig = serviceConfig;
39+
this.requestConverter = requestConverter;
40+
this.responseConverter = responseConverter;
41+
this.labelApplicationRuleConfigServiceFutureStub =
42+
LabelApplicationRuleConfigServiceGrpc.newFutureStub(
43+
grpcChannelRegistry.forAddress(
44+
serviceConfig.getConfigServiceHost(), serviceConfig.getConfigServicePort()))
45+
.withCallCredentials(credentials);
46+
}
47+
48+
@Override
49+
public Single<LabelApplicationRule> createLabelApplicationRule(
50+
LabelApplicationRuleCreateRequest request) {
51+
return Single.fromFuture(
52+
this.grpcContextBuilder
53+
.build(request.context())
54+
.call(
55+
() ->
56+
this.labelApplicationRuleConfigServiceFutureStub
57+
.withDeadlineAfter(
58+
serviceConfig.getConfigServiceTimeout().toMillis(),
59+
TimeUnit.MILLISECONDS)
60+
.createLabelApplicationRule(
61+
this.requestConverter.convertCreationRequest(request))))
62+
.flatMap(this.responseConverter::convertCreateLabelApplicationRuleResponse);
63+
}
64+
65+
@Override
66+
public Single<LabelApplicationRuleResultSet> getLabelApplicationRules(ContextualRequest request) {
67+
return Single.fromFuture(
68+
this.grpcContextBuilder
69+
.build(request.context())
70+
.call(
71+
() ->
72+
this.labelApplicationRuleConfigServiceFutureStub
73+
.withDeadlineAfter(
74+
serviceConfig.getConfigServiceTimeout().toMillis(),
75+
TimeUnit.MILLISECONDS)
76+
.getLabelApplicationRules(
77+
GetLabelApplicationRulesRequest.getDefaultInstance())))
78+
.flatMap(this.responseConverter::convertGetLabelApplicationsRuleResponse);
79+
}
80+
81+
@Override
82+
public Single<LabelApplicationRule> updateLabelApplicationRule(
83+
LabelApplicationRuleUpdateRequest request) {
84+
return Single.fromFuture(
85+
this.grpcContextBuilder
86+
.build(request.context())
87+
.call(
88+
() ->
89+
this.labelApplicationRuleConfigServiceFutureStub
90+
.withDeadlineAfter(
91+
serviceConfig.getConfigServiceTimeout().toMillis(),
92+
TimeUnit.MILLISECONDS)
93+
.updateLabelApplicationRule(
94+
this.requestConverter.convertUpdateRequest(request))))
95+
.flatMap(this.responseConverter::convertUpdateLabelApplicationRuleResponse);
96+
}
97+
98+
@Override
99+
public Single<Boolean> deleteLabelApplicationRule(LabelApplicationRuleDeleteRequest request) {
100+
return Single.fromFuture(
101+
this.grpcContextBuilder
102+
.build(request.context())
103+
.call(
104+
() ->
105+
this.labelApplicationRuleConfigServiceFutureStub
106+
.withDeadlineAfter(
107+
serviceConfig.getConfigServiceTimeout().toMillis(),
108+
TimeUnit.MILLISECONDS)
109+
.deleteLabelApplicationRule(
110+
this.requestConverter.convertDeleteRequest(request))))
111+
.flatMap(
112+
unusedResponse -> this.responseConverter.buildDeleteLabelApplicationRuleResponse());
113+
}
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.hypertrace.graphql.label.application.rules.dao;
2+
3+
import io.reactivex.rxjava3.core.Single;
4+
import org.hypertrace.core.graphql.common.request.ContextualRequest;
5+
import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleCreateRequest;
6+
import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleDeleteRequest;
7+
import org.hypertrace.graphql.label.application.rules.request.LabelApplicationRuleUpdateRequest;
8+
import org.hypertrace.graphql.label.application.rules.schema.query.LabelApplicationRuleResultSet;
9+
import org.hypertrace.graphql.label.application.rules.schema.shared.LabelApplicationRule;
10+
11+
public interface LabelApplicationRuleDao {
12+
Single<LabelApplicationRule> createLabelApplicationRule(
13+
LabelApplicationRuleCreateRequest request);
14+
15+
Single<LabelApplicationRuleResultSet> getLabelApplicationRules(ContextualRequest request);
16+
17+
Single<LabelApplicationRule> updateLabelApplicationRule(
18+
LabelApplicationRuleUpdateRequest request);
19+
20+
Single<Boolean> deleteLabelApplicationRule(LabelApplicationRuleDeleteRequest request);
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.hypertrace.graphql.label.application.rules.dao;
2+
3+
import com.google.inject.AbstractModule;
4+
import io.grpc.CallCredentials;
5+
import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig;
6+
import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry;
7+
import org.hypertrace.core.graphql.utils.grpc.GrpcContextBuilder;
8+
9+
public class LabelApplicationRuleDaoModule extends AbstractModule {
10+
@Override
11+
protected void configure() {
12+
bind(LabelApplicationRuleDao.class).to(LabelApplicationRuleConfigServiceDao.class);
13+
requireBinding(CallCredentials.class);
14+
requireBinding(GraphQlServiceConfig.class);
15+
requireBinding(GrpcChannelRegistry.class);
16+
requireBinding(GrpcContextBuilder.class);
17+
}
18+
}

0 commit comments

Comments
 (0)