You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/06/11 18:30:48 UTC

[GitHub] [cassandra-sidecar] frankgh commented on a diff in pull request #29: Optimize file path builder and have separate handler for streaming file

frankgh commented on code in PR #29:
URL: https://github.com/apache/cassandra-sidecar/pull/29#discussion_r874234938


##########
common/build.gradle:
##########
@@ -22,6 +22,7 @@ test {
 }
 
 dependencies {
+    compile "io.vertx:vertx-web-api-contract:$vertxVersion"

Review Comment:
   do we need this dependency?



##########
src/main/java/org/apache/cassandra/sidecar/MainModule.java:
##########
@@ -144,6 +148,22 @@ public Router vertxRouter(Vertx vertx, LoggerHandler loggerHandler, ErrorHandler
         // Docs index.html page
         StaticHandler docs = StaticHandler.create("docs");
         router.route().path("/docs/*").handler(docs);
+
+        // add custom routers
+        final String apiVersion = "/api/v1";

Review Comment:
   do we have a constant for this?



##########
common/src/main/java/org/apache/cassandra/sidecar/common/SidecarProps.java:
##########
@@ -0,0 +1,10 @@
+package org.apache.cassandra.sidecar.common;
+
+/**
+ * Properties maintained in common for all sub projects.
+ */
+public class SidecarProps

Review Comment:
   do we need to introduce this class? Can the property be moved somewhere else?



##########
src/main/java/org/apache/cassandra/sidecar/routes/StreamSSTableComponentHandler.java:
##########
@@ -0,0 +1,99 @@
+package org.apache.cassandra.sidecar.routes;
+
+import java.io.FileNotFoundException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.web.RoutingContext;
+import io.vertx.ext.web.handler.HttpException;
+import org.apache.cassandra.sidecar.cluster.InstancesConfig;
+import org.apache.cassandra.sidecar.common.data.StreamSSTableComponentRequest;
+import org.apache.cassandra.sidecar.utils.SnapshotPathBuilder;
+
+import static org.apache.cassandra.sidecar.utils.RequestUtils.extractHostAddressWithoutPort;
+
+/**
+ * This handler validates that the component exists in the cluster and sets up the context
+ * for the {@link FileStreamHandler} to stream the component back to the client
+ */
+@Singleton
+public class StreamSSTableComponentHandler
+{
+    private static final Logger logger = LoggerFactory.getLogger(StreamSSTableComponentHandler.class);
+
+    private final SnapshotPathBuilder builder;
+    private final InstancesConfig instancesConfig;
+
+    @Inject
+    public StreamSSTableComponentHandler(SnapshotPathBuilder builder, InstancesConfig instancesConfig)
+    {
+        this.builder = builder;
+        this.instancesConfig = instancesConfig;
+    }
+
+    public void handleAllRequests(RoutingContext context)
+    {
+        final HttpServerRequest request = context.request();
+        final String host = extractHostAddressWithoutPort(request.host());
+        streamFilesForHost(host, context);
+    }
+
+    public void handlePerInstanceRequests(RoutingContext context)
+    {
+        final String instanceIdParam = context.request().getParam("InstanceId");
+        if (instanceIdParam == null)
+        {
+            context.fail(new HttpException(HttpResponseStatus.BAD_REQUEST.code(),
+                                           "Instance id param can't be missing"));

Review Comment:
   ```suggestion
                                              "InstanceId path parameter must be provided"));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org