From 29eb85d1568500ff3d387c1fc7406f08abe4a431 Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Wed, 20 Mar 2024 13:04:53 +0530 Subject: [PATCH 01/12] Added rotationmanagement and removed unused imports --- .../core/config/RotationManagementConfig.java | 15 ++++++ .../core/task/RotationManagementTask.java | 35 ++++++++++++ .../helloworld/HelloWorldApplication.java | 1 + .../examples/helloworld/bean/HelloBean.java | 4 +- .../helloworld/client/HelloWorldClient.java | 1 + .../client/HelloWorldClientInterceptor.java | 1 - .../config/HelloWorldConfiguration.java | 32 +++++++++-- .../helloworld/filter/AuthFilter.java | 5 +- .../helloworld/filter/LoggingFilter.java | 7 +-- .../helloworld/guice/HelloWorldModule.java | 18 +++---- .../healthcheck/AllIsWellHealthCheck.java | 41 +++++++++++--- .../helloworld/service/GreeterService.java | 15 +++--- .../helloworld/service/HelloBeanService.java | 10 ++-- .../web/HelloWorldHealthCheckResource.java | 35 ++++++++++++ .../web/HelloWorldResourceConfig.java | 12 +++-- .../web/RotationManagementResource.java | 53 +++++++++++++++++++ 16 files changed, 237 insertions(+), 48 deletions(-) create mode 100644 core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java create mode 100644 core/src/main/java/com/flipkart/gjex/core/task/RotationManagementTask.java create mode 100644 examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java create mode 100644 examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/RotationManagementResource.java diff --git a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java new file mode 100644 index 00000000..8fcaadf2 --- /dev/null +++ b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java @@ -0,0 +1,15 @@ +package com.flipkart.gjex.core.config; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import javax.inject.Singleton; + +@Singleton +public class RotationManagementConfig { + @JsonProperty("defaultRotationState") + private boolean defaultRotationState; + + public boolean getDefaultRotationState() { + return defaultRotationState; + } +} diff --git a/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementTask.java b/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementTask.java new file mode 100644 index 00000000..14df60f7 --- /dev/null +++ b/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementTask.java @@ -0,0 +1,35 @@ +package com.flipkart.gjex.core.task; + +import javax.inject.Singleton; +import java.util.concurrent.atomic.AtomicBoolean; + +@Singleton +public class RotationManagementTask { + private static final String BIR = "bir"; + private static final String OOR = "oor"; + + private AtomicBoolean state; + + public RotationManagementTask() { + state = new AtomicBoolean(true); + } + + public String getStatus() { + return isBir() ? BIR : OOR; + } + + public String makeOor() { + state.set(false); + return OOR; + } + + public String makeBir() { + state.set(true); + return BIR; + } + + public boolean isBir() { + return state.get(); + } + +} diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/HelloWorldApplication.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/HelloWorldApplication.java index 2e6ead1a..c4e1bc96 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/HelloWorldApplication.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/HelloWorldApplication.java @@ -15,6 +15,7 @@ */ package com.flipkart.gjex.examples.helloworld; +import com.fasterxml.jackson.core.JsonProcessingException; import com.flipkart.gjex.core.Application; import com.flipkart.gjex.core.setup.Bootstrap; import com.flipkart.gjex.core.setup.Environment; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/bean/HelloBean.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/bean/HelloBean.java index 5f19a3c3..6ccf0346 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/bean/HelloBean.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/bean/HelloBean.java @@ -15,10 +15,10 @@ */ package com.flipkart.gjex.examples.helloworld.bean; -import javax.validation.constraints.NotNull; - import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; + /** * An entity class for testing validation * @author regu.b diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClient.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClient.java index 7fb10365..25cd5e98 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClient.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClient.java @@ -24,6 +24,7 @@ import io.grpc.examples.helloworld.GreeterGrpc; import io.grpc.examples.helloworld.HelloReply; import io.grpc.examples.helloworld.HelloRequest; + import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClientInterceptor.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClientInterceptor.java index 10e1d897..7d49dc31 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClientInterceptor.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClientInterceptor.java @@ -16,7 +16,6 @@ package com.flipkart.gjex.examples.helloworld.client; import com.google.common.annotations.VisibleForTesting; - import io.grpc.CallOptions; import io.grpc.Channel; import io.grpc.ClientCall; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/config/HelloWorldConfiguration.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/config/HelloWorldConfiguration.java index 183da399..ee3aaa45 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/config/HelloWorldConfiguration.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/config/HelloWorldConfiguration.java @@ -1,14 +1,13 @@ package com.flipkart.gjex.examples.helloworld.config; -import java.util.Map; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.flipkart.gjex.core.GJEXConfiguration; - import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.Map; + @Data @EqualsAndHashCode(callSuper=true) @@ -21,4 +20,31 @@ public class HelloWorldConfiguration extends GJEXConfiguration { @JsonProperty("task.properties") private Map taskProperties; + @JsonProperty("rotationManagement") + private Map rotationManagement; + + public Map getApiProperties() { + return apiProperties; + } + + public void setApiProperties(Map apiProperties) { + this.apiProperties = apiProperties; + } + + public Map getTaskProperties() { + return taskProperties; + } + + public void setTaskProperties(Map taskProperties) { + this.taskProperties = taskProperties; + } + + public Map getRotationManagement() { + return rotationManagement; + } + + public void setRotationManagement(Map rotationManagement) { + this.rotationManagement = rotationManagement; + } + } diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/AuthFilter.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/AuthFilter.java index 2da03437..97c0cd5c 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/AuthFilter.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/AuthFilter.java @@ -15,17 +15,16 @@ */ package com.flipkart.gjex.examples.helloworld.filter; -import javax.inject.Named; - import com.flipkart.gjex.core.filter.Filter; import com.flipkart.gjex.core.logging.Logging; - import io.grpc.Metadata; import io.grpc.Status; import io.grpc.StatusRuntimeException; import io.grpc.examples.helloworld.HelloReply; import io.grpc.examples.helloworld.HelloRequest; +import javax.inject.Named; + /** * An implementation of the {@link Filter} interface as example that performs naive authentication based on * information contained in the Request headers diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/LoggingFilter.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/LoggingFilter.java index c6d5103d..3c233920 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/LoggingFilter.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/LoggingFilter.java @@ -15,15 +15,12 @@ */ package com.flipkart.gjex.examples.helloworld.filter; -import javax.inject.Named; - import com.flipkart.gjex.core.filter.Filter; import com.flipkart.gjex.core.logging.Logging; - import com.google.protobuf.GeneratedMessageV3; import io.grpc.Metadata; -import io.grpc.examples.helloworld.HelloReply; -import io.grpc.examples.helloworld.HelloRequest; + +import javax.inject.Named; /** * An implementation of the {@link Filter} interface as example that simply logs Request information diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java index 4f0784a3..4869db4e 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java @@ -15,26 +15,21 @@ */ package com.flipkart.gjex.examples.helloworld.guice; -import org.glassfish.jersey.server.ResourceConfig; - -import io.dropwizard.metrics5.health.HealthCheck; import com.flipkart.gjex.core.filter.Filter; +import com.flipkart.gjex.core.task.RotationManagementTask; import com.flipkart.gjex.core.tracing.TracingSampler; +import com.flipkart.gjex.examples.helloworld.config.HelloWorldConfiguration; import com.flipkart.gjex.examples.helloworld.filter.AuthFilter; import com.flipkart.gjex.examples.helloworld.filter.LoggingFilter; import com.flipkart.gjex.examples.helloworld.healthcheck.AllIsWellHealthCheck; -import com.flipkart.gjex.examples.helloworld.service.GreeterService; import com.flipkart.gjex.examples.helloworld.tracing.AllWhitelistTracingSampler; import com.flipkart.gjex.examples.helloworld.web.HelloWorldResourceConfig; import com.google.inject.AbstractModule; import com.google.inject.name.Names; - -import io.grpc.BindableService; +import io.dropwizard.metrics5.health.HealthCheck; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import io.grpc.examples.helloworld.GreeterGrpc; - - +import org.glassfish.jersey.server.ResourceConfig; /** * Guice module for wiring sample Service to GJEX runtime @@ -51,11 +46,12 @@ protected void configure() { .usePlaintext() .build(); // install(new ClientModule(GreeterGrpc.GreeterBlockingStub.class,new ChannelConfig("localhost",9999))); - bind(GreeterGrpc.GreeterBlockingStub.class).toInstance(GreeterGrpc.newBlockingStub(channel)); - bind(BindableService.class).annotatedWith(Names.named("GreeterService")).to(GreeterService.class); +// bind(GreeterGrpc.GreeterBlockingStub.class).toInstance(GreeterGrpc.newBlockingStub(channel)); +// bind(BindableService.class).annotatedWith(Names.named("GreeterService")).to(GreeterService.class); bind(Filter.class).annotatedWith(Names.named("LoggingFilter")).to(LoggingFilter.class); bind(Filter.class).annotatedWith(Names.named("AuthFilter")).to(AuthFilter.class); bind(TracingSampler.class).to(AllWhitelistTracingSampler.class); + bind(RotationManagementTask.class).toInstance(new RotationManagementTask()); bind(HealthCheck.class).to(AllIsWellHealthCheck.class); bind(ResourceConfig.class).annotatedWith(Names.named("HelloWorldResourceConfig")).to(HelloWorldResourceConfig.class); } diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java index d0409b71..221b066a 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java @@ -15,22 +15,51 @@ */ package com.flipkart.gjex.examples.helloworld.healthcheck; -import io.dropwizard.metrics5.health.HealthCheck; import com.flipkart.gjex.core.logging.Logging; - - +import com.flipkart.gjex.core.task.RotationManagementTask; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import io.dropwizard.metrics5.health.HealthCheck; /** * A HealthCheck implementation that reports positive results always * @author regu.b * */ +@Singleton public class AllIsWellHealthCheck extends HealthCheck implements Logging { + private RotationManagementTask rotationManagementTask; + + @Inject + public AllIsWellHealthCheck(RotationManagementTask rotationManagementTask) { + this.rotationManagementTask = rotationManagementTask; + } + @Override - protected Result check() throws Exception { - info("Returning healthy status."); - return Result.healthy("All Is Well"); + protected Result check() { + if (rotationManagementTask.isBir()) { + info("Returning healthy status."); + return Result.healthy("Server is " + rotationManagementTask.getStatus()); + } else { + info("Returning unhealthy status."); + return Result.unhealthy("Server is " + rotationManagementTask.getStatus()); + } } + public String getStatus() { + return rotationManagementTask.getStatus(); + } + + public String makeOor() { + return rotationManagementTask.makeOor(); + } + + public String makeBir() { + return rotationManagementTask.makeBir(); + } + + public boolean isBir() { + return rotationManagementTask.isBir(); + } } diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java index 923e4cfb..e403ec98 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java @@ -15,10 +15,6 @@ */ package com.flipkart.gjex.examples.helloworld.service; -import javax.inject.Inject; -import javax.inject.Named; - -import io.dropwizard.metrics5.annotation.Timed; import com.flipkart.gjex.core.filter.ApplicationHeaders; import com.flipkart.gjex.core.filter.MethodFilters; import com.flipkart.gjex.core.logging.Logging; @@ -28,15 +24,20 @@ import com.flipkart.gjex.examples.helloworld.bean.HelloBean; import com.flipkart.gjex.examples.helloworld.filter.AuthFilter; import com.flipkart.gjex.examples.helloworld.filter.LoggingFilter; - +import io.dropwizard.metrics5.annotation.Timed; import io.grpc.Metadata; import io.grpc.Status; import io.grpc.StatusException; import io.grpc.StatusRuntimeException; -import io.grpc.examples.helloworld.*; +import io.grpc.examples.helloworld.GreeterGrpc; +import io.grpc.examples.helloworld.HelloReply; +import io.grpc.examples.helloworld.HelloRequest; +import io.grpc.examples.helloworld.Ping; +import io.grpc.examples.helloworld.Pong; import io.grpc.stub.StreamObserver; -import static io.grpc.examples.helloworld.GreeterGrpc.getPingPongMethod; +import javax.inject.Inject; +import javax.inject.Named; /** diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/HelloBeanService.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/HelloBeanService.java index 350a89dc..7a82c6f4 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/HelloBeanService.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/HelloBeanService.java @@ -15,11 +15,6 @@ */ package com.flipkart.gjex.examples.helloworld.service; -import java.util.concurrent.Future; - -import javax.validation.Valid; -import javax.validation.constraints.NotNull; - import com.flipkart.gjex.core.filter.ApplicationHeaders; import com.flipkart.gjex.core.logging.Logging; import com.flipkart.gjex.core.task.AsyncResult; @@ -27,9 +22,12 @@ import com.flipkart.gjex.core.task.FutureDecorator; import com.flipkart.gjex.core.tracing.Traced; import com.flipkart.gjex.examples.helloworld.bean.HelloBean; - import io.reactivex.functions.BiFunction; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.util.concurrent.Future; + /** * A sample business logic implementation that is called with an entity that is validated for correctness * diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java new file mode 100644 index 00000000..9977f45a --- /dev/null +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java @@ -0,0 +1,35 @@ +package com.flipkart.gjex.examples.helloworld.web; + +import com.flipkart.gjex.examples.helloworld.healthcheck.AllIsWellHealthCheck; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Singleton +@Path("/app-healthcheck") +@Named +public class HelloWorldHealthCheckResource { + private AllIsWellHealthCheck allIsWellHealthCheck; + + @Inject + public HelloWorldHealthCheckResource(AllIsWellHealthCheck allIsWellHealthCheck) { + this.allIsWellHealthCheck = allIsWellHealthCheck; + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/") + public Response health() { + if (allIsWellHealthCheck.isBir()) { + return Response.status(Response.Status.OK).build(); + } else { + return Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); + } + } +} diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java index 14dd6385..4867721b 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java @@ -15,12 +15,12 @@ */ package com.flipkart.gjex.examples.helloworld.web; +import org.glassfish.jersey.server.ResourceConfig; + import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.glassfish.jersey.server.ResourceConfig; - /** * ResourceConfig example for registering all custom web resources for a GJEX application. * @author regu.b @@ -31,10 +31,14 @@ public class HelloWorldResourceConfig extends ResourceConfig { @Inject - public HelloWorldResourceConfig (HelloWorldResource1 helloWorldresource1, - HelloWorldResource2 helloWorldresource2) { + public HelloWorldResourceConfig (HelloWorldResource1 helloWorldresource1, + HelloWorldResource2 helloWorldresource2, + RotationManagementResource rotationManagementResource, + HelloWorldHealthCheckResource helloWorldHealthCheckResource) { register(helloWorldresource1); register(helloWorldresource2); + register(rotationManagementResource); + register(helloWorldHealthCheckResource); } } diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/RotationManagementResource.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/RotationManagementResource.java new file mode 100644 index 00000000..58668742 --- /dev/null +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/RotationManagementResource.java @@ -0,0 +1,53 @@ +package com.flipkart.gjex.examples.helloworld.web; + +import com.flipkart.gjex.examples.helloworld.healthcheck.AllIsWellHealthCheck; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Singleton +@Path("/rotation_status") +@Named +public class RotationManagementResource { + + private AllIsWellHealthCheck allIsWellHealthCheck; + + @Inject + public RotationManagementResource(AllIsWellHealthCheck allIsWellHealthCheck) { + this.allIsWellHealthCheck = allIsWellHealthCheck; + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/oor") + public Response oor() { + String response = this.allIsWellHealthCheck.makeOor(); + return Response.status(Response.Status.OK).entity(response).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/bir") + public Response bir() { + String response = this.allIsWellHealthCheck.makeBir(); + return Response.status(Response.Status.OK).entity(response).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/status") + public Response status() { + String response = this.allIsWellHealthCheck.getStatus(); + if (this.allIsWellHealthCheck.isBir()) { + return Response.status(Response.Status.OK).entity(response).build(); + } + return Response.status(Response.Status.NOT_FOUND).entity(response).build(); + } + +} From a0ffdd8a3a0d266e362f69e43d491e1c9f27e031 Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Wed, 20 Mar 2024 18:44:14 +0530 Subject: [PATCH 02/12] Added rotationmanagement and removed unused imports --- .../core/config/RotationManagementConfig.java | 15 ----------- ...> RotationManagementBasedHealthCheck.java} | 18 +++++++++++-- .../core}/web/RotationManagementResource.java | 23 +++++++++------- .../helloworld/guice/HelloWorldModule.java | 8 +++--- .../web/HelloWorldHealthCheckResource.java | 10 +++---- .../web/HelloWorldResourceConfig.java | 1 + .../flipkart/gjex/guice/module/ApiModule.java | 4 +++ .../gjex/guice/module/DashboardModule.java | 27 ++++++++++++++++--- 8 files changed, 66 insertions(+), 40 deletions(-) delete mode 100644 core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java rename core/src/main/java/com/flipkart/gjex/core/task/{RotationManagementTask.java => RotationManagementBasedHealthCheck.java} (51%) rename {examples/src/main/java/com/flipkart/gjex/examples/helloworld => core/src/main/java/com/flipkart/gjex/core}/web/RotationManagementResource.java (56%) diff --git a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java deleted file mode 100644 index 8fcaadf2..00000000 --- a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.flipkart.gjex.core.config; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import javax.inject.Singleton; - -@Singleton -public class RotationManagementConfig { - @JsonProperty("defaultRotationState") - private boolean defaultRotationState; - - public boolean getDefaultRotationState() { - return defaultRotationState; - } -} diff --git a/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementTask.java b/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java similarity index 51% rename from core/src/main/java/com/flipkart/gjex/core/task/RotationManagementTask.java rename to core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java index 14df60f7..79816782 100644 --- a/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementTask.java +++ b/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java @@ -1,19 +1,33 @@ package com.flipkart.gjex.core.task; +import com.flipkart.gjex.core.logging.Logging; +import io.dropwizard.metrics5.health.HealthCheck; + import javax.inject.Singleton; import java.util.concurrent.atomic.AtomicBoolean; @Singleton -public class RotationManagementTask { +public class RotationManagementBasedHealthCheck extends HealthCheck implements Logging { private static final String BIR = "bir"; private static final String OOR = "oor"; private AtomicBoolean state; - public RotationManagementTask() { + public RotationManagementBasedHealthCheck() { state = new AtomicBoolean(true); } + @Override + protected Result check() { + if (isBir()) { + info("Returning healthy status."); + return Result.healthy("Server is " + getStatus()); + } else { + info("Returning unhealthy status."); + return Result.unhealthy("Server is " + getStatus()); + } + } + public String getStatus() { return isBir() ? BIR : OOR; } diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/RotationManagementResource.java b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java similarity index 56% rename from examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/RotationManagementResource.java rename to core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java index 58668742..2df64cc4 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/RotationManagementResource.java +++ b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java @@ -1,6 +1,6 @@ -package com.flipkart.gjex.examples.helloworld.web; +package com.flipkart.gjex.core.web; -import com.flipkart.gjex.examples.helloworld.healthcheck.AllIsWellHealthCheck; +import com.flipkart.gjex.core.task.RotationManagementBasedHealthCheck; import javax.inject.Inject; import javax.inject.Named; @@ -11,23 +11,28 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +/** + * Resource for rotation management + * @author ajay.jalgaonkar + */ + @Singleton @Path("/rotation_status") @Named public class RotationManagementResource { - private AllIsWellHealthCheck allIsWellHealthCheck; + private RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck; @Inject - public RotationManagementResource(AllIsWellHealthCheck allIsWellHealthCheck) { - this.allIsWellHealthCheck = allIsWellHealthCheck; + public RotationManagementResource(RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck) { + this.rotationManagementBasedHealthCheck = rotationManagementBasedHealthCheck; } @GET @Produces(MediaType.APPLICATION_JSON) @Path("/oor") public Response oor() { - String response = this.allIsWellHealthCheck.makeOor(); + String response = this.rotationManagementBasedHealthCheck.makeOor(); return Response.status(Response.Status.OK).entity(response).build(); } @@ -35,7 +40,7 @@ public Response oor() { @Produces(MediaType.APPLICATION_JSON) @Path("/bir") public Response bir() { - String response = this.allIsWellHealthCheck.makeBir(); + String response = this.rotationManagementBasedHealthCheck.makeBir(); return Response.status(Response.Status.OK).entity(response).build(); } @@ -43,8 +48,8 @@ public Response bir() { @Produces(MediaType.APPLICATION_JSON) @Path("/status") public Response status() { - String response = this.allIsWellHealthCheck.getStatus(); - if (this.allIsWellHealthCheck.isBir()) { + String response = this.rotationManagementBasedHealthCheck.getStatus(); + if (this.rotationManagementBasedHealthCheck.isBir()) { return Response.status(Response.Status.OK).entity(response).build(); } return Response.status(Response.Status.NOT_FOUND).entity(response).build(); diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java index 4869db4e..c7bf0ac1 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java @@ -16,12 +16,10 @@ package com.flipkart.gjex.examples.helloworld.guice; import com.flipkart.gjex.core.filter.Filter; -import com.flipkart.gjex.core.task.RotationManagementTask; +import com.flipkart.gjex.core.task.RotationManagementBasedHealthCheck; import com.flipkart.gjex.core.tracing.TracingSampler; -import com.flipkart.gjex.examples.helloworld.config.HelloWorldConfiguration; import com.flipkart.gjex.examples.helloworld.filter.AuthFilter; import com.flipkart.gjex.examples.helloworld.filter.LoggingFilter; -import com.flipkart.gjex.examples.helloworld.healthcheck.AllIsWellHealthCheck; import com.flipkart.gjex.examples.helloworld.tracing.AllWhitelistTracingSampler; import com.flipkart.gjex.examples.helloworld.web.HelloWorldResourceConfig; import com.google.inject.AbstractModule; @@ -51,8 +49,8 @@ protected void configure() { bind(Filter.class).annotatedWith(Names.named("LoggingFilter")).to(LoggingFilter.class); bind(Filter.class).annotatedWith(Names.named("AuthFilter")).to(AuthFilter.class); bind(TracingSampler.class).to(AllWhitelistTracingSampler.class); - bind(RotationManagementTask.class).toInstance(new RotationManagementTask()); - bind(HealthCheck.class).to(AllIsWellHealthCheck.class); + bind(RotationManagementBasedHealthCheck.class).toInstance(new RotationManagementBasedHealthCheck()); + bind(HealthCheck.class).to(RotationManagementBasedHealthCheck.class); bind(ResourceConfig.class).annotatedWith(Names.named("HelloWorldResourceConfig")).to(HelloWorldResourceConfig.class); } diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java index 9977f45a..6128f1ef 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java @@ -1,6 +1,6 @@ package com.flipkart.gjex.examples.helloworld.web; -import com.flipkart.gjex.examples.helloworld.healthcheck.AllIsWellHealthCheck; +import com.flipkart.gjex.core.task.RotationManagementBasedHealthCheck; import javax.inject.Inject; import javax.inject.Named; @@ -15,18 +15,18 @@ @Path("/app-healthcheck") @Named public class HelloWorldHealthCheckResource { - private AllIsWellHealthCheck allIsWellHealthCheck; + private RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck; @Inject - public HelloWorldHealthCheckResource(AllIsWellHealthCheck allIsWellHealthCheck) { - this.allIsWellHealthCheck = allIsWellHealthCheck; + public HelloWorldHealthCheckResource(RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck) { + this.rotationManagementBasedHealthCheck = rotationManagementBasedHealthCheck; } @GET @Produces(MediaType.APPLICATION_JSON) @Path("/") public Response health() { - if (allIsWellHealthCheck.isBir()) { + if (rotationManagementBasedHealthCheck.isBir()) { return Response.status(Response.Status.OK).build(); } else { return Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java index 4867721b..b8a51cdb 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java @@ -15,6 +15,7 @@ */ package com.flipkart.gjex.examples.helloworld.web; +import com.flipkart.gjex.core.web.RotationManagementResource; import org.glassfish.jersey.server.ResourceConfig; import javax.inject.Inject; diff --git a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java index f4668f1f..50a20a2d 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java @@ -15,9 +15,12 @@ */ package com.flipkart.gjex.guice.module; +import com.flipkart.gjex.Constants; import com.flipkart.gjex.core.GJEXConfiguration; import com.flipkart.gjex.core.logging.Logging; import com.flipkart.gjex.core.service.Api; +import com.flipkart.gjex.core.web.HealthCheckResource; +import com.flipkart.gjex.core.web.RotationManagementResource; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.matcher.AbstractMatcher; @@ -27,6 +30,7 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.configuration.Configuration; +import org.glassfish.jersey.server.ResourceConfig; import javax.inject.Inject; import javax.inject.Named; diff --git a/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java b/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java index 07c60fe7..92dbe83d 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java @@ -25,6 +25,7 @@ import javax.inject.Named; import javax.inject.Singleton; +import com.flipkart.gjex.core.web.RotationManagementResource; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.DefaultServlet; @@ -139,13 +140,21 @@ Server getDashboardJettyServer(@Named("Dashboard.service.port") int port, @Singleton Server getAPIJettyServer(@Named("APIVanillaJettyServer")Server server, @Named("ApiServletContext") ServletContextHandler context, - @Named("HealthCheckResourceConfig")ResourceConfig healthcheckResourceConfig, + @Named("HealthCheckResourceConfig")ResourceConfig healthCheckResourceConfig, + @Named("RotationManagementResourceConfig") ResourceConfig rotationManagementResourceConfig, @Named("TracingResourceConfig")ResourceConfig tracingResourceConfig, @Named("TracingSamplerHolder")TracingSamplerHolder tracingSamplerHolder, @Named("JSONMarshallingProvider")JacksonJaxbJsonProvider provider) throws URISyntaxException, UnknownHostException { - healthcheckResourceConfig.register(provider); - ServletHolder healthcheckServlet = new ServletHolder(new ServletContainer(healthcheckResourceConfig)); - context.addServlet(healthcheckServlet, "/healthcheck"); // registering Health Check servlet under the /healthcheck path + healthCheckResourceConfig.register(provider); + ServletHolder healthCheckServlet = + new ServletHolder(new ServletContainer(healthCheckResourceConfig)); + context.addServlet(healthCheckServlet, "/healthcheck"); // registering Health Check servlet under the /healthcheck path + + rotationManagementResourceConfig.register(provider); + ServletHolder rotationManagementServlet = + new ServletHolder(new ServletContainer(rotationManagementResourceConfig)); + context.addServlet(rotationManagementServlet, "/rotation"); // registering Rotation + // Management servlet under the /rotation path tracingResourceConfig.register(provider); ServletHolder tracingServlet = new ServletHolder(new ServletContainer(tracingResourceConfig)); @@ -209,6 +218,16 @@ ResourceConfig getAPIResourceConfig(HealthCheckResource healthCheckResource) { return resourceConfig; } + @Named("RotationManagementResourceConfig") + @Singleton + @Provides + ResourceConfig getAPIResourceConfig(RotationManagementResource rotationManagementResource) { + ResourceConfig resourceConfig = new ResourceConfig(); + resourceConfig.register(rotationManagementResource); + resourceConfig.setApplicationName(Constants.GJEX_CORE_APPLICATION); + return resourceConfig; + } + @Named("TracingResourceConfig") @Singleton @Provides From e88fac0c7a0c49945fda5a06c6953731b68e484b Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Wed, 20 Mar 2024 18:49:09 +0530 Subject: [PATCH 03/12] Added rotationmanagement and removed unused imports --- .../healthcheck/AllIsWellHealthCheck.java | 45 ++++--------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java index 221b066a..7bb2f050 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java @@ -15,51 +15,22 @@ */ package com.flipkart.gjex.examples.helloworld.healthcheck; -import com.flipkart.gjex.core.logging.Logging; -import com.flipkart.gjex.core.task.RotationManagementTask; -import com.google.inject.Inject; -import com.google.inject.Singleton; import io.dropwizard.metrics5.health.HealthCheck; +import com.flipkart.gjex.core.logging.Logging; + + /** * A HealthCheck implementation that reports positive results always * @author regu.b * */ -@Singleton public class AllIsWellHealthCheck extends HealthCheck implements Logging { - private RotationManagementTask rotationManagementTask; - - @Inject - public AllIsWellHealthCheck(RotationManagementTask rotationManagementTask) { - this.rotationManagementTask = rotationManagementTask; - } - - @Override - protected Result check() { - if (rotationManagementTask.isBir()) { - info("Returning healthy status."); - return Result.healthy("Server is " + rotationManagementTask.getStatus()); - } else { - info("Returning unhealthy status."); - return Result.unhealthy("Server is " + rotationManagementTask.getStatus()); - } - } - - public String getStatus() { - return rotationManagementTask.getStatus(); - } - - public String makeOor() { - return rotationManagementTask.makeOor(); - } - - public String makeBir() { - return rotationManagementTask.makeBir(); - } + @Override + protected Result check() throws Exception { + info("Returning healthy status."); + return Result.healthy("All Is Well"); + } - public boolean isBir() { - return rotationManagementTask.isBir(); - } } From 96e0f9af0e589dd3a9245037a2d95aa4aa1cb65f Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Wed, 20 Mar 2024 18:52:23 +0530 Subject: [PATCH 04/12] uncommenting greeter service --- .../gjex/examples/helloworld/guice/HelloWorldModule.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java index c7bf0ac1..ecb08f67 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java @@ -20,13 +20,16 @@ import com.flipkart.gjex.core.tracing.TracingSampler; import com.flipkart.gjex.examples.helloworld.filter.AuthFilter; import com.flipkart.gjex.examples.helloworld.filter.LoggingFilter; +import com.flipkart.gjex.examples.helloworld.service.GreeterService; import com.flipkart.gjex.examples.helloworld.tracing.AllWhitelistTracingSampler; import com.flipkart.gjex.examples.helloworld.web.HelloWorldResourceConfig; import com.google.inject.AbstractModule; import com.google.inject.name.Names; import io.dropwizard.metrics5.health.HealthCheck; +import io.grpc.BindableService; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import io.grpc.examples.helloworld.GreeterGrpc; import org.glassfish.jersey.server.ResourceConfig; /** @@ -44,8 +47,8 @@ protected void configure() { .usePlaintext() .build(); // install(new ClientModule(GreeterGrpc.GreeterBlockingStub.class,new ChannelConfig("localhost",9999))); -// bind(GreeterGrpc.GreeterBlockingStub.class).toInstance(GreeterGrpc.newBlockingStub(channel)); -// bind(BindableService.class).annotatedWith(Names.named("GreeterService")).to(GreeterService.class); + bind(GreeterGrpc.GreeterBlockingStub.class).toInstance(GreeterGrpc.newBlockingStub(channel)); + bind(BindableService.class).annotatedWith(Names.named("GreeterService")).to(GreeterService.class); bind(Filter.class).annotatedWith(Names.named("LoggingFilter")).to(LoggingFilter.class); bind(Filter.class).annotatedWith(Names.named("AuthFilter")).to(AuthFilter.class); bind(TracingSampler.class).to(AllWhitelistTracingSampler.class); From 282db60af2c01caf23bc9549b1e3de22aaaca04c Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Wed, 20 Mar 2024 18:58:18 +0530 Subject: [PATCH 05/12] resetting only import related files --- .../RotationManagementBasedHealthCheck.java | 4 +++ .../helloworld/HelloWorldApplication.java | 1 - .../examples/helloworld/bean/HelloBean.java | 4 +-- .../helloworld/client/HelloWorldClient.java | 1 - .../client/HelloWorldClientInterceptor.java | 1 + .../config/HelloWorldConfiguration.java | 32 ++----------------- .../helloworld/filter/AuthFilter.java | 5 +-- .../helloworld/filter/LoggingFilter.java | 7 ++-- .../healthcheck/AllIsWellHealthCheck.java | 10 +++--- .../helloworld/service/GreeterService.java | 15 ++++----- .../helloworld/service/HelloBeanService.java | 10 +++--- .../flipkart/gjex/guice/module/ApiModule.java | 4 --- 12 files changed, 36 insertions(+), 58 deletions(-) diff --git a/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java b/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java index 79816782..f0171790 100644 --- a/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java +++ b/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java @@ -6,6 +6,10 @@ import javax.inject.Singleton; import java.util.concurrent.atomic.AtomicBoolean; +/** + * Rotation management based health check for the app + * @author ajay.jalgaonkar + */ @Singleton public class RotationManagementBasedHealthCheck extends HealthCheck implements Logging { private static final String BIR = "bir"; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/HelloWorldApplication.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/HelloWorldApplication.java index c4e1bc96..2e6ead1a 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/HelloWorldApplication.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/HelloWorldApplication.java @@ -15,7 +15,6 @@ */ package com.flipkart.gjex.examples.helloworld; -import com.fasterxml.jackson.core.JsonProcessingException; import com.flipkart.gjex.core.Application; import com.flipkart.gjex.core.setup.Bootstrap; import com.flipkart.gjex.core.setup.Environment; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/bean/HelloBean.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/bean/HelloBean.java index 6ccf0346..5f19a3c3 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/bean/HelloBean.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/bean/HelloBean.java @@ -15,10 +15,10 @@ */ package com.flipkart.gjex.examples.helloworld.bean; -import org.hibernate.validator.constraints.NotBlank; - import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.NotBlank; + /** * An entity class for testing validation * @author regu.b diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClient.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClient.java index 25cd5e98..7fb10365 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClient.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClient.java @@ -24,7 +24,6 @@ import io.grpc.examples.helloworld.GreeterGrpc; import io.grpc.examples.helloworld.HelloReply; import io.grpc.examples.helloworld.HelloRequest; - import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClientInterceptor.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClientInterceptor.java index 7d49dc31..10e1d897 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClientInterceptor.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/client/HelloWorldClientInterceptor.java @@ -16,6 +16,7 @@ package com.flipkart.gjex.examples.helloworld.client; import com.google.common.annotations.VisibleForTesting; + import io.grpc.CallOptions; import io.grpc.Channel; import io.grpc.ClientCall; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/config/HelloWorldConfiguration.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/config/HelloWorldConfiguration.java index ee3aaa45..183da399 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/config/HelloWorldConfiguration.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/config/HelloWorldConfiguration.java @@ -1,13 +1,14 @@ package com.flipkart.gjex.examples.helloworld.config; +import java.util.Map; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.flipkart.gjex.core.GJEXConfiguration; + import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.Map; - @Data @EqualsAndHashCode(callSuper=true) @@ -20,31 +21,4 @@ public class HelloWorldConfiguration extends GJEXConfiguration { @JsonProperty("task.properties") private Map taskProperties; - @JsonProperty("rotationManagement") - private Map rotationManagement; - - public Map getApiProperties() { - return apiProperties; - } - - public void setApiProperties(Map apiProperties) { - this.apiProperties = apiProperties; - } - - public Map getTaskProperties() { - return taskProperties; - } - - public void setTaskProperties(Map taskProperties) { - this.taskProperties = taskProperties; - } - - public Map getRotationManagement() { - return rotationManagement; - } - - public void setRotationManagement(Map rotationManagement) { - this.rotationManagement = rotationManagement; - } - } diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/AuthFilter.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/AuthFilter.java index 97c0cd5c..2da03437 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/AuthFilter.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/AuthFilter.java @@ -15,16 +15,17 @@ */ package com.flipkart.gjex.examples.helloworld.filter; +import javax.inject.Named; + import com.flipkart.gjex.core.filter.Filter; import com.flipkart.gjex.core.logging.Logging; + import io.grpc.Metadata; import io.grpc.Status; import io.grpc.StatusRuntimeException; import io.grpc.examples.helloworld.HelloReply; import io.grpc.examples.helloworld.HelloRequest; -import javax.inject.Named; - /** * An implementation of the {@link Filter} interface as example that performs naive authentication based on * information contained in the Request headers diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/LoggingFilter.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/LoggingFilter.java index 3c233920..c6d5103d 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/LoggingFilter.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/LoggingFilter.java @@ -15,12 +15,15 @@ */ package com.flipkart.gjex.examples.helloworld.filter; +import javax.inject.Named; + import com.flipkart.gjex.core.filter.Filter; import com.flipkart.gjex.core.logging.Logging; + import com.google.protobuf.GeneratedMessageV3; import io.grpc.Metadata; - -import javax.inject.Named; +import io.grpc.examples.helloworld.HelloReply; +import io.grpc.examples.helloworld.HelloRequest; /** * An implementation of the {@link Filter} interface as example that simply logs Request information diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java index 7bb2f050..d0409b71 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java @@ -27,10 +27,10 @@ */ public class AllIsWellHealthCheck extends HealthCheck implements Logging { - @Override - protected Result check() throws Exception { - info("Returning healthy status."); - return Result.healthy("All Is Well"); - } + @Override + protected Result check() throws Exception { + info("Returning healthy status."); + return Result.healthy("All Is Well"); + } } diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java index e403ec98..923e4cfb 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java @@ -15,6 +15,10 @@ */ package com.flipkart.gjex.examples.helloworld.service; +import javax.inject.Inject; +import javax.inject.Named; + +import io.dropwizard.metrics5.annotation.Timed; import com.flipkart.gjex.core.filter.ApplicationHeaders; import com.flipkart.gjex.core.filter.MethodFilters; import com.flipkart.gjex.core.logging.Logging; @@ -24,20 +28,15 @@ import com.flipkart.gjex.examples.helloworld.bean.HelloBean; import com.flipkart.gjex.examples.helloworld.filter.AuthFilter; import com.flipkart.gjex.examples.helloworld.filter.LoggingFilter; -import io.dropwizard.metrics5.annotation.Timed; + import io.grpc.Metadata; import io.grpc.Status; import io.grpc.StatusException; import io.grpc.StatusRuntimeException; -import io.grpc.examples.helloworld.GreeterGrpc; -import io.grpc.examples.helloworld.HelloReply; -import io.grpc.examples.helloworld.HelloRequest; -import io.grpc.examples.helloworld.Ping; -import io.grpc.examples.helloworld.Pong; +import io.grpc.examples.helloworld.*; import io.grpc.stub.StreamObserver; -import javax.inject.Inject; -import javax.inject.Named; +import static io.grpc.examples.helloworld.GreeterGrpc.getPingPongMethod; /** diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/HelloBeanService.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/HelloBeanService.java index 7a82c6f4..350a89dc 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/HelloBeanService.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/HelloBeanService.java @@ -15,6 +15,11 @@ */ package com.flipkart.gjex.examples.helloworld.service; +import java.util.concurrent.Future; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + import com.flipkart.gjex.core.filter.ApplicationHeaders; import com.flipkart.gjex.core.logging.Logging; import com.flipkart.gjex.core.task.AsyncResult; @@ -22,11 +27,8 @@ import com.flipkart.gjex.core.task.FutureDecorator; import com.flipkart.gjex.core.tracing.Traced; import com.flipkart.gjex.examples.helloworld.bean.HelloBean; -import io.reactivex.functions.BiFunction; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import java.util.concurrent.Future; +import io.reactivex.functions.BiFunction; /** * A sample business logic implementation that is called with an entity that is validated for correctness diff --git a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java index 50a20a2d..f4668f1f 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java @@ -15,12 +15,9 @@ */ package com.flipkart.gjex.guice.module; -import com.flipkart.gjex.Constants; import com.flipkart.gjex.core.GJEXConfiguration; import com.flipkart.gjex.core.logging.Logging; import com.flipkart.gjex.core.service.Api; -import com.flipkart.gjex.core.web.HealthCheckResource; -import com.flipkart.gjex.core.web.RotationManagementResource; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.matcher.AbstractMatcher; @@ -30,7 +27,6 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.configuration.Configuration; -import org.glassfish.jersey.server.ResourceConfig; import javax.inject.Inject; import javax.inject.Named; From c8ce346c7827f9833511e91d6ab3c48edcec4865 Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Fri, 22 Mar 2024 12:49:54 +0530 Subject: [PATCH 06/12] Removed HelloWorldHealthCheckResource.java, added RotationManagementConfig and removed binding of RotationManagementResource --- .../core/config/RotationManagementConfig.java | 22 ++++++++++++ .../core/web/RotationManagementResource.java | 7 +++- .../helloworld/guice/HelloWorldModule.java | 1 - .../web/HelloWorldHealthCheckResource.java | 35 ------------------- .../web/HelloWorldResourceConfig.java | 6 ++-- 5 files changed, 30 insertions(+), 41 deletions(-) create mode 100644 core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java delete mode 100644 examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java diff --git a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java new file mode 100644 index 00000000..779ed8c9 --- /dev/null +++ b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java @@ -0,0 +1,22 @@ +package com.flipkart.gjex.core.config; + +import com.flipkart.gjex.core.web.RotationManagementResource; +import org.glassfish.jersey.server.ResourceConfig; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +/** + * RotationManagementConfig for registering RotationManagementResource. + * @author ajay.jalgaonkar + * + */ +@Singleton +@Named("RotationManagementConfig") +public class RotationManagementConfig extends ResourceConfig { + @Inject + public RotationManagementConfig (RotationManagementResource rotationManagementResource) { + register(rotationManagementResource); + } +} diff --git a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java index 2df64cc4..bb983880 100644 --- a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java +++ b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java @@ -5,9 +5,11 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import javax.servlet.ServletContext; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -17,10 +19,13 @@ */ @Singleton -@Path("/rotation_status") +@Path("/rotation") @Named public class RotationManagementResource { + @Context + private ServletContext servletContext; + private RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck; @Inject diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java index ecb08f67..61c284e8 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java @@ -52,7 +52,6 @@ protected void configure() { bind(Filter.class).annotatedWith(Names.named("LoggingFilter")).to(LoggingFilter.class); bind(Filter.class).annotatedWith(Names.named("AuthFilter")).to(AuthFilter.class); bind(TracingSampler.class).to(AllWhitelistTracingSampler.class); - bind(RotationManagementBasedHealthCheck.class).toInstance(new RotationManagementBasedHealthCheck()); bind(HealthCheck.class).to(RotationManagementBasedHealthCheck.class); bind(ResourceConfig.class).annotatedWith(Names.named("HelloWorldResourceConfig")).to(HelloWorldResourceConfig.class); } diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java deleted file mode 100644 index 6128f1ef..00000000 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldHealthCheckResource.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.flipkart.gjex.examples.helloworld.web; - -import com.flipkart.gjex.core.task.RotationManagementBasedHealthCheck; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -@Singleton -@Path("/app-healthcheck") -@Named -public class HelloWorldHealthCheckResource { - private RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck; - - @Inject - public HelloWorldHealthCheckResource(RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck) { - this.rotationManagementBasedHealthCheck = rotationManagementBasedHealthCheck; - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("/") - public Response health() { - if (rotationManagementBasedHealthCheck.isBir()) { - return Response.status(Response.Status.OK).build(); - } else { - return Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); - } - } -} diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java index b8a51cdb..50107109 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java @@ -34,12 +34,10 @@ public class HelloWorldResourceConfig extends ResourceConfig { @Inject public HelloWorldResourceConfig (HelloWorldResource1 helloWorldresource1, HelloWorldResource2 helloWorldresource2, - RotationManagementResource rotationManagementResource, - HelloWorldHealthCheckResource helloWorldHealthCheckResource) { + RotationManagementResource rotationManagementResource) { register(helloWorldresource1); register(helloWorldresource2); - register(rotationManagementResource); - register(helloWorldHealthCheckResource); +// register(rotationManagementResource); } } From e549aa3a09263d08af07dcc82c1ab047aa3521f8 Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Tue, 26 Mar 2024 18:19:31 +0530 Subject: [PATCH 07/12] rotation changes --- .../core/config/RotationManagementConfig.java | 1 + .../RotationManagementBasedHealthCheck.java | 1 + .../core/web/RotationManagementResource.java | 25 ++++++++----------- .../gjex/core/web/TracingResource.java | 2 ++ .../web/HelloWorldResourceConfig.java | 3 ++- .../com/flipkart/gjex/guice/GuiceBundle.java | 3 +++ .../flipkart/gjex/guice/module/ApiModule.java | 5 ++++ .../gjex/guice/module/DashboardModule.java | 4 +-- 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java index 779ed8c9..148446a2 100644 --- a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java +++ b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java @@ -15,6 +15,7 @@ @Singleton @Named("RotationManagementConfig") public class RotationManagementConfig extends ResourceConfig { + @Inject public RotationManagementConfig (RotationManagementResource rotationManagementResource) { register(rotationManagementResource); diff --git a/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java b/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java index f0171790..a46ddb4e 100644 --- a/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java +++ b/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java @@ -10,6 +10,7 @@ * Rotation management based health check for the app * @author ajay.jalgaonkar */ + @Singleton public class RotationManagementBasedHealthCheck extends HealthCheck implements Logging { private static final String BIR = "bir"; diff --git a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java index bb983880..96811d70 100644 --- a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java +++ b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java @@ -19,23 +19,31 @@ */ @Singleton -@Path("/rotation") +@Path("/") @Named public class RotationManagementResource { @Context private ServletContext servletContext; - private RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck; + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response base() { +// String response = this.rotationManagementBasedHealthCheck.makeOor(); + String response = "hello from rmr base"; + return Response.status(Response.Status.OK).entity(response).build(); + } @Inject public RotationManagementResource(RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck) { this.rotationManagementBasedHealthCheck = rotationManagementBasedHealthCheck; } + private RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck; + @GET - @Produces(MediaType.APPLICATION_JSON) @Path("/oor") + @Produces(MediaType.APPLICATION_JSON) public Response oor() { String response = this.rotationManagementBasedHealthCheck.makeOor(); return Response.status(Response.Status.OK).entity(response).build(); @@ -49,15 +57,4 @@ public Response bir() { return Response.status(Response.Status.OK).entity(response).build(); } - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("/status") - public Response status() { - String response = this.rotationManagementBasedHealthCheck.getStatus(); - if (this.rotationManagementBasedHealthCheck.isBir()) { - return Response.status(Response.Status.OK).entity(response).build(); - } - return Response.status(Response.Status.NOT_FOUND).entity(response).build(); - } - } diff --git a/core/src/main/java/com/flipkart/gjex/core/web/TracingResource.java b/core/src/main/java/com/flipkart/gjex/core/web/TracingResource.java index 60bbb6ae..6a7b66db 100644 --- a/core/src/main/java/com/flipkart/gjex/core/web/TracingResource.java +++ b/core/src/main/java/com/flipkart/gjex/core/web/TracingResource.java @@ -18,11 +18,13 @@ import javax.inject.Named; import javax.inject.Singleton; import javax.servlet.ServletContext; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import com.flipkart.gjex.core.GJEXError; import com.flipkart.gjex.core.tracing.TracingSamplerHolder; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java index 50107109..113a64ff 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java @@ -15,6 +15,7 @@ */ package com.flipkart.gjex.examples.helloworld.web; +import com.flipkart.gjex.core.config.RotationManagementConfig; import com.flipkart.gjex.core.web.RotationManagementResource; import org.glassfish.jersey.server.ResourceConfig; @@ -37,7 +38,7 @@ public HelloWorldResourceConfig (HelloWorldResource1 helloWorldresource1, RotationManagementResource rotationManagementResource) { register(helloWorldresource1); register(helloWorldresource2); -// register(rotationManagementResource); + register(rotationManagementResource); } } diff --git a/guice/src/main/java/com/flipkart/gjex/guice/GuiceBundle.java b/guice/src/main/java/com/flipkart/gjex/guice/GuiceBundle.java index 15192257..578db714 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/GuiceBundle.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/GuiceBundle.java @@ -166,6 +166,9 @@ public void run(T configuration, U configMap, Environment environment) { ApiServer apiServer = baseInjector.getInstance(ApiServer.class); // Add all custom web resources resourceConfigs = getInstances(baseInjector, ResourceConfig.class); + + // Lookup the rotation management config +// resourceConfigs.addAll(getInstances(baseInjector, RotationManagementConfig.class)); apiServer.registerResources(resourceConfigs); } diff --git a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java index f4668f1f..73fe7fc4 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java @@ -16,17 +16,21 @@ package com.flipkart.gjex.guice.module; import com.flipkart.gjex.core.GJEXConfiguration; +import com.flipkart.gjex.core.config.RotationManagementConfig; import com.flipkart.gjex.core.logging.Logging; import com.flipkart.gjex.core.service.Api; +import com.flipkart.gjex.core.web.RotationManagementResource; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.matcher.AbstractMatcher; import com.google.inject.matcher.Matchers; +import com.google.inject.name.Names; import io.grpc.BindableService; import io.grpc.Context; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.configuration.Configuration; +import org.glassfish.jersey.server.ResourceConfig; import javax.inject.Inject; import javax.inject.Named; @@ -50,6 +54,7 @@ protected void configure() { ApiMethodInterceptor methodInterceptor = new ApiMethodInterceptor(); requestInjection(methodInterceptor); bindInterceptor(Matchers.any(), new ApiMethodMatcher(), methodInterceptor); +// bind(RotationManagementConfig.class).annotatedWith(Names.named("RotationManagementConfig")).to(RotationManagementConfig.class); } @Named("ApiScheduledExecutor") diff --git a/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java b/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java index 92dbe83d..865c67b8 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java @@ -140,7 +140,7 @@ Server getDashboardJettyServer(@Named("Dashboard.service.port") int port, @Singleton Server getAPIJettyServer(@Named("APIVanillaJettyServer")Server server, @Named("ApiServletContext") ServletContextHandler context, - @Named("HealthCheckResourceConfig")ResourceConfig healthCheckResourceConfig, + @Named("HealthCheckResourceConfig") ResourceConfig healthCheckResourceConfig, @Named("RotationManagementResourceConfig") ResourceConfig rotationManagementResourceConfig, @Named("TracingResourceConfig")ResourceConfig tracingResourceConfig, @Named("TracingSamplerHolder")TracingSamplerHolder tracingSamplerHolder, @@ -221,7 +221,7 @@ ResourceConfig getAPIResourceConfig(HealthCheckResource healthCheckResource) { @Named("RotationManagementResourceConfig") @Singleton @Provides - ResourceConfig getAPIResourceConfig(RotationManagementResource rotationManagementResource) { + ResourceConfig getRotationManagementResourceConfig(RotationManagementResource rotationManagementResource) { ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.register(rotationManagementResource); resourceConfig.setApplicationName(Constants.GJEX_CORE_APPLICATION); From bb6cfd41c639fcc3c5c27883df8943b2435c80d6 Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Wed, 27 Mar 2024 12:41:38 +0530 Subject: [PATCH 08/12] updated path for rotation and removed rotation from HelloWorldResourceConfig --- .../gjex/core/web/RotationManagementResource.java | 8 -------- .../examples/helloworld/web/HelloWorldResourceConfig.java | 4 +--- .../com/flipkart/gjex/guice/module/DashboardModule.java | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java index 96811d70..8a7383a7 100644 --- a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java +++ b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java @@ -26,14 +26,6 @@ public class RotationManagementResource { @Context private ServletContext servletContext; - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response base() { -// String response = this.rotationManagementBasedHealthCheck.makeOor(); - String response = "hello from rmr base"; - return Response.status(Response.Status.OK).entity(response).build(); - } - @Inject public RotationManagementResource(RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck) { this.rotationManagementBasedHealthCheck = rotationManagementBasedHealthCheck; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java index 113a64ff..393d07b7 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java @@ -34,11 +34,9 @@ public class HelloWorldResourceConfig extends ResourceConfig { @Inject public HelloWorldResourceConfig (HelloWorldResource1 helloWorldresource1, - HelloWorldResource2 helloWorldresource2, - RotationManagementResource rotationManagementResource) { + HelloWorldResource2 helloWorldresource2) { register(helloWorldresource1); register(helloWorldresource2); - register(rotationManagementResource); } } diff --git a/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java b/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java index 865c67b8..60c49b31 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java @@ -153,7 +153,7 @@ Server getAPIJettyServer(@Named("APIVanillaJettyServer")Server server, rotationManagementResourceConfig.register(provider); ServletHolder rotationManagementServlet = new ServletHolder(new ServletContainer(rotationManagementResourceConfig)); - context.addServlet(rotationManagementServlet, "/rotation"); // registering Rotation + context.addServlet(rotationManagementServlet, "/rotation/*"); // registering Rotation // Management servlet under the /rotation path tracingResourceConfig.register(provider); From 58163380f95e89835bdb032dc637a83e975625e4 Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Wed, 27 Mar 2024 12:46:00 +0530 Subject: [PATCH 09/12] removed unnecessary changes and imports --- .../flipkart/gjex/core/config/RotationManagementConfig.java | 1 + .../java/com/flipkart/gjex/core/web/TracingResource.java | 2 -- guice/src/main/java/com/flipkart/gjex/guice/GuiceBundle.java | 3 --- .../main/java/com/flipkart/gjex/guice/module/ApiModule.java | 5 ----- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java index 148446a2..29c4c037 100644 --- a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java +++ b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java @@ -12,6 +12,7 @@ * @author ajay.jalgaonkar * */ + @Singleton @Named("RotationManagementConfig") public class RotationManagementConfig extends ResourceConfig { diff --git a/core/src/main/java/com/flipkart/gjex/core/web/TracingResource.java b/core/src/main/java/com/flipkart/gjex/core/web/TracingResource.java index 6a7b66db..60bbb6ae 100644 --- a/core/src/main/java/com/flipkart/gjex/core/web/TracingResource.java +++ b/core/src/main/java/com/flipkart/gjex/core/web/TracingResource.java @@ -18,13 +18,11 @@ import javax.inject.Named; import javax.inject.Singleton; import javax.servlet.ServletContext; -import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import com.flipkart.gjex.core.GJEXError; import com.flipkart.gjex.core.tracing.TracingSamplerHolder; diff --git a/guice/src/main/java/com/flipkart/gjex/guice/GuiceBundle.java b/guice/src/main/java/com/flipkart/gjex/guice/GuiceBundle.java index 578db714..15192257 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/GuiceBundle.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/GuiceBundle.java @@ -166,9 +166,6 @@ public void run(T configuration, U configMap, Environment environment) { ApiServer apiServer = baseInjector.getInstance(ApiServer.class); // Add all custom web resources resourceConfigs = getInstances(baseInjector, ResourceConfig.class); - - // Lookup the rotation management config -// resourceConfigs.addAll(getInstances(baseInjector, RotationManagementConfig.class)); apiServer.registerResources(resourceConfigs); } diff --git a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java index 73fe7fc4..f4668f1f 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java @@ -16,21 +16,17 @@ package com.flipkart.gjex.guice.module; import com.flipkart.gjex.core.GJEXConfiguration; -import com.flipkart.gjex.core.config.RotationManagementConfig; import com.flipkart.gjex.core.logging.Logging; import com.flipkart.gjex.core.service.Api; -import com.flipkart.gjex.core.web.RotationManagementResource; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.matcher.AbstractMatcher; import com.google.inject.matcher.Matchers; -import com.google.inject.name.Names; import io.grpc.BindableService; import io.grpc.Context; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.configuration.Configuration; -import org.glassfish.jersey.server.ResourceConfig; import javax.inject.Inject; import javax.inject.Named; @@ -54,7 +50,6 @@ protected void configure() { ApiMethodInterceptor methodInterceptor = new ApiMethodInterceptor(); requestInjection(methodInterceptor); bindInterceptor(Matchers.any(), new ApiMethodMatcher(), methodInterceptor); -// bind(RotationManagementConfig.class).annotatedWith(Names.named("RotationManagementConfig")).to(RotationManagementConfig.class); } @Named("ApiScheduledExecutor") From 6d74d24edb9897cf77e77b663db01ad4c8c2ac45 Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Fri, 29 Mar 2024 15:54:23 +0530 Subject: [PATCH 10/12] moved healthcheck files and removed RotationManagementConfig.java --- .../core/config/RotationManagementConfig.java | 24 ------------- .../HealthCheckRegistry.java | 2 +- .../RotationManagementBasedHealthCheck.java | 17 ++++----- .../flipkart/gjex/core/setup/Bootstrap.java | 1 + .../flipkart/gjex/core/setup/Environment.java | 1 + .../gjex/core/web/HealthCheckResource.java | 2 +- .../core/web/RotationManagementResource.java | 7 +--- .../helloworld/guice/HelloWorldModule.java | 2 +- .../healthcheck/AllIsWellHealthCheck.java | 36 ------------------- .../web/HelloWorldResourceConfig.java | 10 +++--- .../gjex/guice/module/DashboardModule.java | 2 +- 11 files changed, 17 insertions(+), 87 deletions(-) delete mode 100644 core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java rename core/src/main/java/com/flipkart/gjex/core/{setup => healthcheck}/HealthCheckRegistry.java (97%) rename core/src/main/java/com/flipkart/gjex/core/{task => healthcheck}/RotationManagementBasedHealthCheck.java (73%) delete mode 100644 examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java diff --git a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java b/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java deleted file mode 100644 index 29c4c037..00000000 --- a/core/src/main/java/com/flipkart/gjex/core/config/RotationManagementConfig.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.flipkart.gjex.core.config; - -import com.flipkart.gjex.core.web.RotationManagementResource; -import org.glassfish.jersey.server.ResourceConfig; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -/** - * RotationManagementConfig for registering RotationManagementResource. - * @author ajay.jalgaonkar - * - */ - -@Singleton -@Named("RotationManagementConfig") -public class RotationManagementConfig extends ResourceConfig { - - @Inject - public RotationManagementConfig (RotationManagementResource rotationManagementResource) { - register(rotationManagementResource); - } -} diff --git a/core/src/main/java/com/flipkart/gjex/core/setup/HealthCheckRegistry.java b/core/src/main/java/com/flipkart/gjex/core/healthcheck/HealthCheckRegistry.java similarity index 97% rename from core/src/main/java/com/flipkart/gjex/core/setup/HealthCheckRegistry.java rename to core/src/main/java/com/flipkart/gjex/core/healthcheck/HealthCheckRegistry.java index fb008db2..6156d1e0 100644 --- a/core/src/main/java/com/flipkart/gjex/core/setup/HealthCheckRegistry.java +++ b/core/src/main/java/com/flipkart/gjex/core/healthcheck/HealthCheckRegistry.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.flipkart.gjex.core.setup; +package com.flipkart.gjex.core.healthcheck; import java.util.SortedMap; import java.util.concurrent.ExecutorService; diff --git a/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java b/core/src/main/java/com/flipkart/gjex/core/healthcheck/RotationManagementBasedHealthCheck.java similarity index 73% rename from core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java rename to core/src/main/java/com/flipkart/gjex/core/healthcheck/RotationManagementBasedHealthCheck.java index a46ddb4e..a194d868 100644 --- a/core/src/main/java/com/flipkart/gjex/core/task/RotationManagementBasedHealthCheck.java +++ b/core/src/main/java/com/flipkart/gjex/core/healthcheck/RotationManagementBasedHealthCheck.java @@ -1,4 +1,4 @@ -package com.flipkart.gjex.core.task; +package com.flipkart.gjex.core.healthcheck; import com.flipkart.gjex.core.logging.Logging; import io.dropwizard.metrics5.health.HealthCheck; @@ -15,20 +15,15 @@ public class RotationManagementBasedHealthCheck extends HealthCheck implements Logging { private static final String BIR = "bir"; private static final String OOR = "oor"; + private static final AtomicBoolean rotationStatus = new AtomicBoolean(true); - private AtomicBoolean state; - - public RotationManagementBasedHealthCheck() { - state = new AtomicBoolean(true); - } + public RotationManagementBasedHealthCheck() {} @Override protected Result check() { if (isBir()) { - info("Returning healthy status."); return Result.healthy("Server is " + getStatus()); } else { - info("Returning unhealthy status."); return Result.unhealthy("Server is " + getStatus()); } } @@ -38,17 +33,17 @@ public String getStatus() { } public String makeOor() { - state.set(false); + rotationStatus.set(false); return OOR; } public String makeBir() { - state.set(true); + rotationStatus.set(true); return BIR; } public boolean isBir() { - return state.get(); + return rotationStatus.get(); } } diff --git a/core/src/main/java/com/flipkart/gjex/core/setup/Bootstrap.java b/core/src/main/java/com/flipkart/gjex/core/setup/Bootstrap.java index e80b0c89..96f6afdc 100644 --- a/core/src/main/java/com/flipkart/gjex/core/setup/Bootstrap.java +++ b/core/src/main/java/com/flipkart/gjex/core/setup/Bootstrap.java @@ -25,6 +25,7 @@ import javax.validation.Validator; import javax.validation.ValidatorFactory; +import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry; import io.dropwizard.metrics5.MetricRegistry; import io.dropwizard.metrics5.jmx.JmxReporter; import io.dropwizard.metrics5.jvm.BufferPoolMetricSet; diff --git a/core/src/main/java/com/flipkart/gjex/core/setup/Environment.java b/core/src/main/java/com/flipkart/gjex/core/setup/Environment.java index 86b1526d..b44a8bc9 100644 --- a/core/src/main/java/com/flipkart/gjex/core/setup/Environment.java +++ b/core/src/main/java/com/flipkart/gjex/core/setup/Environment.java @@ -15,6 +15,7 @@ */ package com.flipkart.gjex.core.setup; +import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry; import io.dropwizard.metrics5.MetricRegistry; import java.util.concurrent.Executors; diff --git a/core/src/main/java/com/flipkart/gjex/core/web/HealthCheckResource.java b/core/src/main/java/com/flipkart/gjex/core/web/HealthCheckResource.java index fcc6861e..904ce8dc 100644 --- a/core/src/main/java/com/flipkart/gjex/core/web/HealthCheckResource.java +++ b/core/src/main/java/com/flipkart/gjex/core/web/HealthCheckResource.java @@ -28,7 +28,7 @@ import javax.ws.rs.core.Response; import io.dropwizard.metrics5.health.HealthCheck; -import com.flipkart.gjex.core.setup.HealthCheckRegistry; +import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry; /** * Servlet Resource for the HealthCheck API diff --git a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java index 8a7383a7..7dc6f914 100644 --- a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java +++ b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java @@ -1,15 +1,13 @@ package com.flipkart.gjex.core.web; -import com.flipkart.gjex.core.task.RotationManagementBasedHealthCheck; +import com.flipkart.gjex.core.healthcheck.RotationManagementBasedHealthCheck; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import javax.servlet.ServletContext; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -23,9 +21,6 @@ @Named public class RotationManagementResource { - @Context - private ServletContext servletContext; - @Inject public RotationManagementResource(RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck) { this.rotationManagementBasedHealthCheck = rotationManagementBasedHealthCheck; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java index 61c284e8..8c95fa82 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java @@ -16,7 +16,7 @@ package com.flipkart.gjex.examples.helloworld.guice; import com.flipkart.gjex.core.filter.Filter; -import com.flipkart.gjex.core.task.RotationManagementBasedHealthCheck; +import com.flipkart.gjex.core.healthcheck.RotationManagementBasedHealthCheck; import com.flipkart.gjex.core.tracing.TracingSampler; import com.flipkart.gjex.examples.helloworld.filter.AuthFilter; import com.flipkart.gjex.examples.helloworld.filter.LoggingFilter; diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java deleted file mode 100644 index d0409b71..00000000 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/healthcheck/AllIsWellHealthCheck.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) The original author or authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.flipkart.gjex.examples.helloworld.healthcheck; - -import io.dropwizard.metrics5.health.HealthCheck; -import com.flipkart.gjex.core.logging.Logging; - - - -/** - * A HealthCheck implementation that reports positive results always - * @author regu.b - * - */ -public class AllIsWellHealthCheck extends HealthCheck implements Logging { - - @Override - protected Result check() throws Exception { - info("Returning healthy status."); - return Result.healthy("All Is Well"); - } - -} diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java index 393d07b7..14dd6385 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/web/HelloWorldResourceConfig.java @@ -15,14 +15,12 @@ */ package com.flipkart.gjex.examples.helloworld.web; -import com.flipkart.gjex.core.config.RotationManagementConfig; -import com.flipkart.gjex.core.web.RotationManagementResource; -import org.glassfish.jersey.server.ResourceConfig; - import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import org.glassfish.jersey.server.ResourceConfig; + /** * ResourceConfig example for registering all custom web resources for a GJEX application. * @author regu.b @@ -33,8 +31,8 @@ public class HelloWorldResourceConfig extends ResourceConfig { @Inject - public HelloWorldResourceConfig (HelloWorldResource1 helloWorldresource1, - HelloWorldResource2 helloWorldresource2) { + public HelloWorldResourceConfig (HelloWorldResource1 helloWorldresource1, + HelloWorldResource2 helloWorldresource2) { register(helloWorldresource1); register(helloWorldresource2); } diff --git a/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java b/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java index 60c49b31..be64fcad 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/module/DashboardModule.java @@ -44,7 +44,7 @@ import com.flipkart.gjex.core.GJEXConfiguration; import com.flipkart.gjex.core.logging.Logging; import com.flipkart.gjex.core.setup.Bootstrap; -import com.flipkart.gjex.core.setup.HealthCheckRegistry; +import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry; import com.flipkart.gjex.core.tracing.TracingSamplerHolder; import com.flipkart.gjex.core.web.DashboardResource; import com.flipkart.gjex.core.web.HealthCheckResource; From 2bb44b6b34710c0b892cc29e4aa3ee4691ee83fb Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Mon, 1 Apr 2024 20:35:23 +0530 Subject: [PATCH 11/12] binding RotationManagementBasedHealthCheck in ApiModule --- .../gjex/examples/helloworld/guice/HelloWorldModule.java | 3 --- .../main/java/com/flipkart/gjex/guice/module/ApiModule.java | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java index 8c95fa82..96993c3c 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java @@ -16,7 +16,6 @@ package com.flipkart.gjex.examples.helloworld.guice; import com.flipkart.gjex.core.filter.Filter; -import com.flipkart.gjex.core.healthcheck.RotationManagementBasedHealthCheck; import com.flipkart.gjex.core.tracing.TracingSampler; import com.flipkart.gjex.examples.helloworld.filter.AuthFilter; import com.flipkart.gjex.examples.helloworld.filter.LoggingFilter; @@ -25,7 +24,6 @@ import com.flipkart.gjex.examples.helloworld.web.HelloWorldResourceConfig; import com.google.inject.AbstractModule; import com.google.inject.name.Names; -import io.dropwizard.metrics5.health.HealthCheck; import io.grpc.BindableService; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; @@ -52,7 +50,6 @@ protected void configure() { bind(Filter.class).annotatedWith(Names.named("LoggingFilter")).to(LoggingFilter.class); bind(Filter.class).annotatedWith(Names.named("AuthFilter")).to(AuthFilter.class); bind(TracingSampler.class).to(AllWhitelistTracingSampler.class); - bind(HealthCheck.class).to(RotationManagementBasedHealthCheck.class); bind(ResourceConfig.class).annotatedWith(Names.named("HelloWorldResourceConfig")).to(HelloWorldResourceConfig.class); } diff --git a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java index f4668f1f..aea2a36a 100644 --- a/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java +++ b/guice/src/main/java/com/flipkart/gjex/guice/module/ApiModule.java @@ -16,12 +16,14 @@ package com.flipkart.gjex.guice.module; import com.flipkart.gjex.core.GJEXConfiguration; +import com.flipkart.gjex.core.healthcheck.RotationManagementBasedHealthCheck; import com.flipkart.gjex.core.logging.Logging; import com.flipkart.gjex.core.service.Api; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.matcher.AbstractMatcher; import com.google.inject.matcher.Matchers; +import io.dropwizard.metrics5.health.HealthCheck; import io.grpc.BindableService; import io.grpc.Context; import org.aopalliance.intercept.MethodInterceptor; @@ -50,6 +52,7 @@ protected void configure() { ApiMethodInterceptor methodInterceptor = new ApiMethodInterceptor(); requestInjection(methodInterceptor); bindInterceptor(Matchers.any(), new ApiMethodMatcher(), methodInterceptor); + bind(HealthCheck.class).to(RotationManagementBasedHealthCheck.class); } @Named("ApiScheduledExecutor") From ec9e44eecb33d4fd66b474e28f20bbda83156308 Mon Sep 17 00:00:00 2001 From: "ajay.jalgaonkar" Date: Mon, 1 Apr 2024 22:59:45 +0530 Subject: [PATCH 12/12] renamed isBir function and made oor and bir calls POST requests --- .../healthcheck/RotationManagementBasedHealthCheck.java | 6 +++--- .../flipkart/gjex/core/web/RotationManagementResource.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/flipkart/gjex/core/healthcheck/RotationManagementBasedHealthCheck.java b/core/src/main/java/com/flipkart/gjex/core/healthcheck/RotationManagementBasedHealthCheck.java index a194d868..51166984 100644 --- a/core/src/main/java/com/flipkart/gjex/core/healthcheck/RotationManagementBasedHealthCheck.java +++ b/core/src/main/java/com/flipkart/gjex/core/healthcheck/RotationManagementBasedHealthCheck.java @@ -21,7 +21,7 @@ public RotationManagementBasedHealthCheck() {} @Override protected Result check() { - if (isBir()) { + if (inRotation()) { return Result.healthy("Server is " + getStatus()); } else { return Result.unhealthy("Server is " + getStatus()); @@ -29,7 +29,7 @@ protected Result check() { } public String getStatus() { - return isBir() ? BIR : OOR; + return inRotation() ? BIR : OOR; } public String makeOor() { @@ -42,7 +42,7 @@ public String makeBir() { return BIR; } - public boolean isBir() { + public boolean inRotation() { return rotationStatus.get(); } diff --git a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java index 7dc6f914..d850ebdb 100644 --- a/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java +++ b/core/src/main/java/com/flipkart/gjex/core/web/RotationManagementResource.java @@ -5,7 +5,7 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import javax.ws.rs.GET; +import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @@ -28,7 +28,7 @@ public RotationManagementResource(RotationManagementBasedHealthCheck rotationMan private RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck; - @GET + @POST @Path("/oor") @Produces(MediaType.APPLICATION_JSON) public Response oor() { @@ -36,7 +36,7 @@ public Response oor() { return Response.status(Response.Status.OK).entity(response).build(); } - @GET + @POST @Produces(MediaType.APPLICATION_JSON) @Path("/bir") public Response bir() {