-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CASSSIDECAR-208: Guice modularization #200
base: trunk
Are you sure you want to change the base?
Conversation
5fbc063
to
74613ae
Compare
@@ -124,7 +124,7 @@ public final class ApiEndpointsV1 | |||
|
|||
public static final String CONNECTED_CLIENT_STATS_ROUTE = API_V1 + CASSANDRA + "/stats/connected-clients"; | |||
|
|||
public static final String OPERATIONAL_JOBS = "/operational-jobs"; | |||
private static final String OPERATIONAL_JOBS = "/operational-jobs"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not the route. It is the intermediate string to define routes that share the same prefix. Such intermediate string does not need to be exposed.
api(project(path: ":server")) { | ||
exclude(group: 'org.apache.logging.log4j') | ||
exclude(group: 'org.slf4j') | ||
exclude(group: 'ch.qos.logback') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excluding the dependencies loses the test log of sidecar in the pacakge
SchemaResponse response = getBlocking(trustedClient() | ||
.get(server.actualPort(), "localhost", testRoute) | ||
.send() | ||
.expecting(HttpResponseExpectation.SC_OK)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expecting
is replacing the deprecated expect
@Override | ||
public String toString() | ||
{ | ||
return keyspaceName() + '.' + tableName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string value is used when registering table schema fails
/** | ||
* Initializer that retries until sidecar schema is initialized. Once initialized, it un-schedules itself. | ||
*/ | ||
private class SidecarSchemaInitializer implements PeriodicTask |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SidecarSchemaInitializer
is moved to its own class file.
@Override | ||
public String toString() | ||
{ | ||
return keyspaceName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guy has multiple tables. Therefore showing the keyspace name only.
{ | ||
Objects.requireNonNull(router, "Router must be set"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
router must present now in the VertxRoute
lambda
66166a6
to
d3f15ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Yifan, modules look neat and well organized. Left some comments
CQLSessionProvider cqlSessionProvider) | ||
{ | ||
super(restoreSlicesSchema, cqlSessionProvider); | ||
super(sidecarSchema.tableSchema(RestoreSlicesSchema.class), cqlSessionProvider); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should we call this method tableSchemaByClass
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is to get the instance using the class to look up.
else if (ex instanceof SidecarSchemaModificationException) | ||
{ | ||
LOGGER.warn("Failed to modify schema", ex); | ||
schemaMetrics.failedModifications.metric.update(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are initializing, we should use failedInitializations
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original implementation is reporting as failedModifications
. I would like to keep it as-is.
server/src/main/java/org/apache/cassandra/sidecar/handlers/CassandraHealthHandler.java
Show resolved
Hide resolved
@@ -16,7 +16,7 @@ | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.apache.cassandra.sidecar.routes; | |||
package org.apache.cassandra.sidecar.handlers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern with this package name change is, currently we have just API route specific handlers here, other speciality handlers in their respective packages, which keeps handlers more organized. Naming it generic, might lead to all handlers being put here. How about moving handlers
package under routes
package?
server/src/main/java/org/apache/cassandra/sidecar/routes/VertxRoute.java
Outdated
Show resolved
Hide resolved
VertxRoute cassandraSchemaRoute(RouteBuilder.Factory factory, | ||
SchemaHandler schemaHandler) | ||
{ | ||
return factory.builderForRoute() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Getting schema information doesn't seem like a operation related. We can leave it as is for now, but later we can move it to CassandraModule
or CassandraInfoModule
?. Same with ring, token, gossip endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cassandra related operations, i.e. trigger task or retrieving information, are grouped in the same module. If splitting the module up helps with readability, we can do that in the future.
server/src/main/java/org/apache/cassandra/sidecar/modules/HealthCheckModule.java
Outdated
Show resolved
Hide resolved
new AuthModule(), | ||
new CassandraOperationsModule(), | ||
new CdcModule(), | ||
new ConfigurationModule(confPath), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: If we have VertxSetupModule
we can move ConfigurationModule
after it for easier reading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this PR, I would like to stick to the idea of group bindings by feature. VertxSetup is not a feature.
Btw, the order of the modules in the list does not affect bindings. They are just sorted alphabetically to look neat.
/** | ||
* Allows {@literal @}{@link ProvidesIntoMap} to specify a {@link ClassKey} class as map key. | ||
* The class must extends from {@link ClassKey} | ||
* <p>The annotation name {@link KeyClassMapKey} is read as "map key type is of {@link ClassKey} class" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Shall we name this class to ClassKeyMapKey
? that way name matches this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The full name was ClassKey Class MapKey
, map key using the class of ClassKey
. There are 2 "Class" in the name, so I dropped one of them. It does not use the ClassKey
instance, but its class. Therefore, the later "Class` is reserved.
TypeLiteral<Class<? extends ClassKey>> keyType = new TypeLiteral<>() {}; | ||
TypeLiteral<PeriodicTask> valueType = new TypeLiteral<>() {}; | ||
MapBinder<Class<? extends ClassKey>, PeriodicTask> periodicTaskMapBinder = MapBinder.newMapBinder(binder(), keyType, valueType); | ||
periodicTaskMapBinder.addBinding(PeriodicTaskMapKeys.RestoreJobDiscovererKey.class).to(RestoreJobDiscoverer.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, why do we inject for these periodic tasks and bind them this way. Where as for HealthCheckPeriodicTask
we provide with ProvidesIntoMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are equivalent. I wanted to demo that there are different ways to add bindings. Plus, binding to a class (that is annotated with @Inject
) has simpler code.
55a6e82
to
ea31d0e
Compare
Patch by Yifan Cai; Reviewed by TBD for CASSSIDECAR-208
ea31d0e
to
ec0d834
Compare
Patch by Yifan Cai; Reviewed by TBD for CASSSIDECAR-208