Skip to content

Commit a0a880c

Browse files
authored
Merge pull request #327 from RamAnvesh/facet_ids_restructure
Krystal 9 Base work
2 parents 46b1bb8 + 660d87c commit a0a880c

File tree

318 files changed

+33238
-7671
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

318 files changed

+33238
-7671
lines changed

.idea/inspectionProfiles/Project_Default.xml

+808-1,011
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Single Bill-Of-Materials artefact with all krystal artefacts versions defined.
3131
independant and agnostic of each other. Classes common to both vajram and krystex modules are
3232
in `krystal-common` module.
3333
6. `com.flipkart.krystal:vajram-guice`: This module contains a kryon decorator which allows
34-
the `@Inject` facets in vajrams to be provided by the guice injector. See `vajram-samples` module
34+
the `@Inject` facetValues in vajrams to be provided by the guice injector. See `vajram-samples` module
3535
for how to use this decorator.
3636

3737
## Preface

assets/krystal_execution_flow_animation/krystal_execution_flow_animation.srt

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
00:00:01,000 --> 00:00:02,000
33
<font size="10px">
44
Krystal receives a request to execute Vajram V1.
5-
The request contains the values of all the inputDef facets of V1.
5+
The request contains the values of all the facetDef facets of V1.
66
V1 is ready for execution.
77
</font>
88

@@ -11,8 +11,8 @@ V1 is ready for execution.
1111
<font size="10px">
1212
V1 depends on vajrams V2, V3, and V4 in sequential order,
1313
i.e V3 waits for V2 and V4 waits for V3.
14-
V1 constructs the request for V2 containing values for V2's inputDef facets.
15-
This is called inputDef resolution.
14+
V1 constructs the request for V2 containing values for V2's facetDef facets.
15+
This is called facetDef resolution.
1616
V2 is ready for execution.
1717
</font>
1818

@@ -142,7 +142,7 @@ V8 succeeds.
142142
00:00:40,000 --> 00:00:42,000
143143
<font size="10px">
144144
V8's response is intercepted by the caching decorator.
145-
The response is cached with the inputDef facets values of V8 as key.
145+
The response is cached with the facetDef facets values of V8 as key.
146146
</font>
147147

148148
22

build.gradle

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
plugins {
2-
id 'com.flipkart.java.code.standard' version '0.1.2-SNAPSHOT'
2+
id 'com.flipkart.java.code.standard' version '3.5'
33
}
44

55
ext {
66
clojarsusername = project.properties['clojarsusername'] ?: ""
77
clojarspassword = project.properties['clojarspassword'] ?: ""
88
krystal_version = '9.0.0-SNAPSHOT'
9-
}
10-
11-
checkerFramework {
12-
extraJavacArgs = [
13-
"-Astubs=${rootDir}/config/checker/stubs",
14-
]
9+
//Use this during development time to fasten compilation by disabling heavy compiler plugins
10+
fast_compile = false
1511
}
1612

1713
subprojects {
@@ -44,14 +40,14 @@ subprojects {
4440
}
4541
}
4642

47-
configure(subprojects.findAll { it.name != 'krystal-bom' }) {
43+
configure(subprojects.findAll { it.name != 'krystal-bom' && it.name != "code-coverage-report" }) {
4844
apply plugin: 'java-library'
49-
apply plugin: 'com.flipkart.java.code.standard'
50-
apply plugin: 'jacoco'
45+
if (!fast_compile) {
46+
apply plugin: 'com.flipkart.java.code.standard'
47+
}
5148

5249
dependencies {
5350
implementation 'com.google.guava:guava'
54-
implementation 'org.checkerframework:checker-qual'
5551
implementation 'org.slf4j:slf4j-api'
5652
implementation 'jakarta.inject:jakarta.inject-api'
5753

@@ -82,7 +78,6 @@ configure(subprojects.findAll { it.name != 'krystal-bom' }) {
8278
implementation 'org.yaml:snakeyaml:2.2'
8379

8480
implementation 'com.google.guava:guava:33.0.0-jre'
85-
implementation 'org.checkerframework:checker-qual:3.42.0'
8681
implementation 'org.slf4j:slf4j-api:2.0.11'
8782
implementation 'jakarta.inject:jakarta.inject-api:2.0.1'
8883
implementation 'org.reflections:reflections:0.10.2'
@@ -95,30 +90,37 @@ configure(subprojects.findAll { it.name != 'krystal-bom' }) {
9590
annotationProcessor 'com.flipkart.krystal:vajram-codegen:' + krystal_version
9691
testAnnotationProcessor 'com.flipkart.krystal:vajram-codegen:' + krystal_version
9792

98-
String lombok_version = '1.18.30'
93+
String lombok_version = '1.18.36'
9994
implementation 'org.projectlombok:lombok:' + lombok_version
10095
annotationProcessor 'org.projectlombok:lombok:' + lombok_version
10196
testAnnotationProcessor 'org.projectlombok:lombok:' + lombok_version
10297
}
10398
}
10499

105-
checkerFramework {
106-
extraJavacArgs = ["-Astubs=${rootDir}/config/checker/stubs",]
107-
excludeTests = true
108-
}
109-
110-
jacoco {
111-
toolVersion = "0.8.11"
100+
if (!fast_compile) {
101+
checkerFramework {
102+
excludeTests = true
103+
}
112104
}
113105

114106
java {
115107
withSourcesJar()
116108
}
117109

118-
tasks.withType(JavaCompile).configureEach {
110+
compileJava {
119111
options.compilerArgs += '-Xlint:unchecked'
120112
options.deprecation = true
121113
}
114+
122115
tasks.named('sourcesJar').configure { mustRunAfter('compileJava') }
116+
}
123117

118+
gradle.taskGraph.whenReady { taskGraph ->
119+
println "======================================="
120+
println "Tasks"
121+
println "======================================="
122+
taskGraph.getAllTasks().eachWithIndex { task, n ->
123+
println "${n + 1} $task"
124+
task.dependsOn.eachWithIndex { depObj, m -> println " ${m + 1} $depObj" }
125+
}
124126
}

docs/Krystal_AutoGenerated_Models.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Scope
2+
3+
This document describes the models that are auto-generated by Krystal and their function and design.
4+
5+
When a developer writes a vajram, the Vajram code generation annotation processor generates a few
6+
classes which model the facetValues of the vajram. These models are of these types:
7+
8+
* Request
9+
* This object contains only and all [
10+
`@Input`](../vajram/vajram-java-sdk/src/main/java/com/flipkart/krystal/vajram/facets/Input.java)
11+
facetValues of the vajram. It is intended to be usable as an independant object by application
12+
developers (Ex: when
13+
invoking a vajram using the [
14+
`KrystalVajramExecutor`](../vajram/vajram-krystex/src/main/java/com/flipkart/krystal/vajramexecutor/krystex/KrystexVajramExecutor.java)
15+
or in some complex input resolvers which set inputs into Request Builders)
16+
* Facets
17+
* This object contains all the Facets of the vajram.
18+
* It is not intended to be used by application developers directly. Instead it acts as a
19+
state holder for the facetValues values as
20+
they are computed during the lifecycle of the vajram's execution.
21+
* In older versions of Krystal, this was done using simple Maps which contained the facet name
22+
as key and facet value
23+
as the value. Since Krystal 9, this facetValues class is generated and used instead as getting and
24+
setting fields in objects takes lesser CPU cycles and is lighter on memory footprint.
25+
* Batch Facets (Only applicable if batching is enabled)
26+
* This object contains values of all facets which have been configured to be batched together
27+
across vajram invocations, i.e. annotated with [
28+
`@Batch(forOutputLogic = true)`](../vajram/vajram-java-sdk/src/main/java/com/flipkart/krystal/vajram/batching/Batch.java)
29+
* Unlike the other the Request and Facets classes which primiarily used for communication across
30+
vajrams (maybe over the wire), persistance of facet values (in case of async orchestration) or
31+
for internal platform use, the Batch Facets class is excusilvely generated so that the
32+
application developer can access all the Batched facets which have been marked as
33+
`@Batch(forOutputLogic = true)`
34+
* Common Facets (Only applicable if batching is enabled)
35+
* This object contains all facetValues which are not tagged with `@Batch`. These are those facetValues
36+
which remain same across the various batches. In Query Language terminology they are analogous
37+
the "group by" operation.
38+
39+
## Class Design
40+
41+
Each of these four categories of objects actually correspond to 3 interfaces:
42+
43+
* An Interface
44+
* An Immuatable final class
45+
* An Mutable builder for the Immutable class
46+
47+
This design allows code to

extensions/vajram-guice/src/main/java/com/flipkart/krystal/vajram/guice/VajramGuiceInjector.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.flipkart.krystal.vajram.guice;
22

33
import static com.flipkart.krystal.data.Errable.errableFrom;
4+
import static com.flipkart.krystal.data.Errable.nil;
5+
import static com.flipkart.krystal.facets.FacetType.INJECTION;
46

57
import com.flipkart.krystal.data.Errable;
68
import com.flipkart.krystal.except.StackTracelessException;
79
import com.flipkart.krystal.vajram.VajramID;
8-
import com.flipkart.krystal.vajram.facets.InputDef;
9-
import com.flipkart.krystal.vajram.facets.InputSource;
10+
import com.flipkart.krystal.vajram.facets.specs.FacetSpec;
1011
import com.flipkart.krystal.vajramexecutor.krystex.inputinjection.VajramInjectionProvider;
1112
import com.google.inject.Injector;
1213
import com.google.inject.Key;
@@ -18,6 +19,7 @@
1819
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Optional;
22+
import lombok.NonNull;
2123
import lombok.extern.slf4j.Slf4j;
2224

2325
@Slf4j
@@ -31,9 +33,9 @@ public VajramGuiceInjector(Injector injector) {
3133
}
3234

3335
@Override
34-
public <T> Errable<T> get(VajramID vajramID, InputDef<T> inputDef) {
35-
if (!inputDef.sources().contains(InputSource.SESSION)) {
36-
return Errable.empty();
36+
public <T> Errable<@NonNull T> get(VajramID vajramID, FacetSpec<T, ?> facetDef) {
37+
if (!facetDef.facetTypes().contains(INJECTION)) {
38+
return nil();
3739
}
3840
return errableFrom(
3941
() -> {
@@ -43,11 +45,11 @@ public <T> Errable<T> get(VajramID vajramID, InputDef<T> inputDef) {
4345
providerCache
4446
.computeIfAbsent(vajramID, _v -> new LinkedHashMap<>())
4547
.computeIfAbsent(
46-
inputDef.name(),
48+
facetDef.name(),
4749
_i -> {
4850
try {
49-
Type type = inputDef.type().javaReflectType();
50-
var annotation = getQualifier(vajramID, inputDef);
51+
Type type = facetDef.type().javaReflectType();
52+
var annotation = getQualifier(vajramID, facetDef);
5153
if (annotation.isEmpty()) {
5254
return injector.getProvider(Key.get(type));
5355
} else {
@@ -62,9 +64,9 @@ public <T> Errable<T> get(VajramID vajramID, InputDef<T> inputDef) {
6264
});
6365
}
6466

65-
private Optional<Annotation> getQualifier(VajramID vajramID, InputDef<?> inputDef) {
67+
private <T> Optional<Annotation> getQualifier(VajramID vajramID, FacetSpec<T, ?> facetDef) {
6668
List<Annotation> qualifierAnnotations =
67-
inputDef.tags().annotations().stream()
69+
facetDef.tags().annotations().stream()
6870
.<Annotation>mapMulti(
6971
(tag, consumer) -> {
7072
boolean isQualifierAnno =
@@ -82,7 +84,7 @@ private Optional<Annotation> getQualifier(VajramID vajramID, InputDef<?> inputDe
8284
throw new IllegalStateException(
8385
("More than one @jakarta.inject.Qualifier annotations (%s) found on input '%s' of vajram '%s'."
8486
+ " This is not allowed")
85-
.formatted(qualifierAnnotations, inputDef.name(), vajramID.vajramId()));
87+
.formatted(qualifierAnnotations, facetDef.name(), vajramID.vajramId()));
8688
}
8789
}
8890
}

fk-java-code-std-plugin/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins {
1515
}
1616

1717
group 'com.flipkart.java.code.standard'
18-
version '3.4'
18+
version '3.5'
1919

2020
gradlePlugin {
2121
plugins {

fk-java-code-std-plugin/src/main/groovy/com/flipkart/java/code/FkJavaCodeStandard.groovy

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.diffplug.gradle.spotless.SpotlessExtension
44
import org.checkerframework.gradle.plugin.CheckerFrameworkExtension
55
import org.gradle.api.Plugin
66
import org.gradle.api.Project
7+
import org.gradle.api.Task
8+
import org.gradle.api.tasks.compile.JavaCompile
79
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
810

911
class FkJavaCodeStandard implements Plugin<Project> {
@@ -85,6 +87,10 @@ class FkJavaCodeStandard implements Plugin<Project> {
8587
project.pluginManager.apply('net.ltgt.errorprone')
8688

8789
project.dependencies.add('errorprone', 'com.google.errorprone:error_prone_core:2.27.1')
90+
project.tasks.compileTestJava.configure { JavaCompile task -> task.options.errorprone.enabled = false }
91+
project.tasks.withType(JavaCompile).configureEach { JavaCompile task ->
92+
task.options.errorprone.disableWarningsInGeneratedCode = true
93+
}
8894
}
8995

9096
private static void junitPlatform(Project project) {

honeycomb/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ asynchronous workflows involving hundreds of steps. The core features supported
88
1. Understanding individual fields and nested fields in the workflow payload.
99
1. Tracking workflow instance progress at individual field level in the payload.
1010
1. Support fork-join where one workflow forks into N instances of another workflow and then collects
11-
the results from all of them.
11+
the depResponses from all of them.
1212
1. Maintain a call-hierarchy of parent to forked workflow instance.
1313
1. Manage queueing and asynchronous communications among all asynchronous portions of the workflow.
1414
1. Support observability by providing visual interfaces to the following data
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.flipkart.krystal.data;
2+
3+
public sealed interface DepResponse<R extends Request<T>, T> extends FacetValue<T>
4+
permits FanoutDepResponses, One2OneDepResponse {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.flipkart.krystal.data;
2+
3+
import java.util.Optional;
4+
import org.checkerframework.checker.nullness.qual.Nullable;
5+
6+
public interface DividerRequest {
7+
public interface Option1 {
8+
int numerator();
9+
10+
Optional<Integer> denominator();
11+
}
12+
13+
public interface Option2 {
14+
15+
Optional<Integer> numerator();
16+
17+
Optional<Integer> denominator();
18+
}
19+
20+
public interface Option3 {
21+
int numerator();
22+
23+
int denominator_OrDefault();
24+
}
25+
26+
public interface Option4 {
27+
@Nullable Integer numerator();
28+
29+
@Nullable Integer denominator();
30+
}
31+
32+
public interface Option5 {
33+
int numerator();
34+
35+
@Nullable Integer denominator();
36+
}
37+
}

0 commit comments

Comments
 (0)