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


##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/ApiEndpointsV1.java:
##########
@@ -109,6 +109,16 @@ public final class ApiEndpointsV1
     public static final String ABORT_RESTORE_JOB_ROUTE = RESTORE_JOB_ROUTE + 
ABORT;
     public static final String RESTORE_JOB_PROGRESS_ROUTE = RESTORE_JOB_ROUTE 
+ PROGRESS;
 
+    // CDC APIs
+    public static final String CDC_PATH = "/cdc";
+    public static final String LIST_ALL_TABLE_IDS_ROUTE = API_V1 + 
"/table-ids";
+    public static final String LIST_TABLE_IDS_BY_KEYSPACE_ROUTE = 
LIST_ALL_TABLE_IDS_ROUTE + "/keyspace/" + KEYSPACE_PATH_PARAM;

Review Comment:
   let's use keyspaces plural here:
   ```suggestion
       public static final String LIST_TABLE_IDS_BY_KEYSPACE_ROUTE = 
LIST_ALL_TABLE_IDS_ROUTE + PER_KEYSPACE;
   ```



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/ApiEndpointsV1.java:
##########
@@ -109,6 +109,16 @@ public final class ApiEndpointsV1
     public static final String ABORT_RESTORE_JOB_ROUTE = RESTORE_JOB_ROUTE + 
ABORT;
     public static final String RESTORE_JOB_PROGRESS_ROUTE = RESTORE_JOB_ROUTE 
+ PROGRESS;
 
+    // CDC APIs
+    public static final String CDC_PATH = "/cdc";
+    public static final String LIST_ALL_TABLE_IDS_ROUTE = API_V1 + 
"/table-ids";
+    public static final String LIST_TABLE_IDS_BY_KEYSPACE_ROUTE = 
LIST_ALL_TABLE_IDS_ROUTE + "/keyspace/" + KEYSPACE_PATH_PARAM;
+    public static final String LIST_TABLE_IDS_ROUTE_BY_KEYSPACE_TABLE = 
LIST_TABLE_IDS_BY_KEYSPACE_ROUTE + "/table/" + TABLE_PATH_PARAM;

Review Comment:
   Same for tables:
   ```suggestion
       public static final String LIST_TABLE_IDS_ROUTE_BY_KEYSPACE_TABLE = 
LIST_TABLE_IDS_BY_KEYSPACE_ROUTE + PER_TABLE;
   ```



##########
server/src/main/java/org/apache/cassandra/sidecar/routes/cdc/ListCDCDirHandler.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.cassandra.sidecar.routes.cdc;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Pair;
+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.json.Json;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.common.response.ListCDCSegmentResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.ServiceConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.routes.AbstractHandler;
+import org.apache.cassandra.sidecar.utils.CDCUtil;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getIdxFileName;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getLogFilePrefix;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.isIndexFile;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.parseIndexFile;
+
+/**
+ * Provides REST endpoint for listing commit logs in CDC directory.
+ */
+@Singleton
+public class ListCDCDirHandler extends AbstractHandler<Void>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ListCDCDirHandler.class);
+    private final ServiceConfiguration config;
+
+    @Inject
+    public ListCDCDirHandler(InstanceMetadataFetcher metadataFetcher,
+                             SidecarConfiguration config,
+                             ExecutorPools executorPools,
+                             CassandraInputValidator validator)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.config = config.serviceConfiguration();
+    }
+
+    @Override
+    protected void handleInternal(RoutingContext context,
+                                  HttpServerRequest httpRequest,
+                                  String host,
+                                  SocketAddress remoteAddress,
+                                  Void request)
+    {
+        String cdcDir = metadataFetcher.instance(host).cdcDir();
+        ListCDCSegmentResponse listCDCSegmentResponse = new 
ListCDCSegmentResponse(config.host(),
+                                                                               
    config.port(),
+                                                                               
    new LinkedList<>());
+        try
+        {
+            addResources(cdcDir, listCDCSegmentResponse);
+        }
+        catch (IOException e)
+        {
+            LOGGER.warn("Error listing the CDC commit log segments", e);
+            context.response()
+                   
.setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code())
+                   .setStatusMessage(e.getMessage())
+                   .end();
+            return;
+        }
+
+        context.response().end(Json.encodePrettily(listCDCSegmentResponse));
+    }
+
+    private void addResources(final String cdcDirPath, final 
ListCDCSegmentResponse listResponse) throws IOException
+    {
+        final File cdcDir = Paths.get(cdcDirPath).toAbsolutePath().toFile();
+        if (!cdcDir.isDirectory())
+        {
+            throw new IOException("CDC directory does not exist");
+        }
+
+        final File[] cdcFiles = cdcDir.listFiles();

Review Comment:
   ```suggestion
          File[] cdcFiles = cdcDir.listFiles();
   ```



##########
server/src/main/java/org/apache/cassandra/sidecar/routes/cdc/ListCDCDirHandler.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.cassandra.sidecar.routes.cdc;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Pair;
+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.json.Json;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.common.response.ListCDCSegmentResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.ServiceConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.routes.AbstractHandler;
+import org.apache.cassandra.sidecar.utils.CDCUtil;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getIdxFileName;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getLogFilePrefix;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.isIndexFile;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.parseIndexFile;
+
+/**
+ * Provides REST endpoint for listing commit logs in CDC directory.
+ */
+@Singleton
+public class ListCDCDirHandler extends AbstractHandler<Void>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ListCDCDirHandler.class);
+    private final ServiceConfiguration config;
+
+    @Inject
+    public ListCDCDirHandler(InstanceMetadataFetcher metadataFetcher,
+                             SidecarConfiguration config,
+                             ExecutorPools executorPools,
+                             CassandraInputValidator validator)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.config = config.serviceConfiguration();
+    }
+
+    @Override
+    protected void handleInternal(RoutingContext context,
+                                  HttpServerRequest httpRequest,
+                                  String host,
+                                  SocketAddress remoteAddress,
+                                  Void request)
+    {
+        String cdcDir = metadataFetcher.instance(host).cdcDir();
+        ListCDCSegmentResponse listCDCSegmentResponse = new 
ListCDCSegmentResponse(config.host(),
+                                                                               
    config.port(),
+                                                                               
    new LinkedList<>());
+        try
+        {
+            addResources(cdcDir, listCDCSegmentResponse);
+        }
+        catch (IOException e)
+        {
+            LOGGER.warn("Error listing the CDC commit log segments", e);
+            context.response()
+                   
.setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code())
+                   .setStatusMessage(e.getMessage())
+                   .end();
+            return;
+        }
+
+        context.response().end(Json.encodePrettily(listCDCSegmentResponse));
+    }
+
+    private void addResources(final String cdcDirPath, final 
ListCDCSegmentResponse listResponse) throws IOException
+    {
+        final File cdcDir = Paths.get(cdcDirPath).toAbsolutePath().toFile();

Review Comment:
   ```suggestion
          File cdcDir = Paths.get(cdcDirPath).toAbsolutePath().toFile();
   ```



##########
server/src/main/java/org/apache/cassandra/sidecar/routes/cdc/ListCDCDirHandler.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.cassandra.sidecar.routes.cdc;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Pair;
+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.json.Json;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.common.response.ListCDCSegmentResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.ServiceConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.routes.AbstractHandler;
+import org.apache.cassandra.sidecar.utils.CDCUtil;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getIdxFileName;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getLogFilePrefix;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.isIndexFile;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.parseIndexFile;
+
+/**
+ * Provides REST endpoint for listing commit logs in CDC directory.
+ */
+@Singleton
+public class ListCDCDirHandler extends AbstractHandler<Void>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ListCDCDirHandler.class);
+    private final ServiceConfiguration config;
+
+    @Inject
+    public ListCDCDirHandler(InstanceMetadataFetcher metadataFetcher,
+                             SidecarConfiguration config,
+                             ExecutorPools executorPools,
+                             CassandraInputValidator validator)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.config = config.serviceConfiguration();
+    }
+
+    @Override
+    protected void handleInternal(RoutingContext context,
+                                  HttpServerRequest httpRequest,
+                                  String host,
+                                  SocketAddress remoteAddress,
+                                  Void request)
+    {
+        String cdcDir = metadataFetcher.instance(host).cdcDir();
+        ListCDCSegmentResponse listCDCSegmentResponse = new 
ListCDCSegmentResponse(config.host(),
+                                                                               
    config.port(),
+                                                                               
    new LinkedList<>());

Review Comment:
   ```suggestion
                                                                                
      new ArrayList<>());
   ```



##########
server/src/main/java/org/apache/cassandra/sidecar/routes/cdc/ListCDCDirHandler.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.cassandra.sidecar.routes.cdc;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Pair;
+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.json.Json;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.common.response.ListCDCSegmentResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.ServiceConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.routes.AbstractHandler;
+import org.apache.cassandra.sidecar.utils.CDCUtil;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getIdxFileName;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getLogFilePrefix;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.isIndexFile;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.parseIndexFile;
+
+/**
+ * Provides REST endpoint for listing commit logs in CDC directory.
+ */
+@Singleton
+public class ListCDCDirHandler extends AbstractHandler<Void>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ListCDCDirHandler.class);
+    private final ServiceConfiguration config;
+
+    @Inject
+    public ListCDCDirHandler(InstanceMetadataFetcher metadataFetcher,
+                             SidecarConfiguration config,
+                             ExecutorPools executorPools,
+                             CassandraInputValidator validator)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.config = config.serviceConfiguration();
+    }
+
+    @Override
+    protected void handleInternal(RoutingContext context,
+                                  HttpServerRequest httpRequest,
+                                  String host,
+                                  SocketAddress remoteAddress,
+                                  Void request)
+    {
+        String cdcDir = metadataFetcher.instance(host).cdcDir();
+        ListCDCSegmentResponse listCDCSegmentResponse = new 
ListCDCSegmentResponse(config.host(),
+                                                                               
    config.port(),
+                                                                               
    new LinkedList<>());
+        try
+        {
+            addResources(cdcDir, listCDCSegmentResponse);
+        }
+        catch (IOException e)
+        {
+            LOGGER.warn("Error listing the CDC commit log segments", e);
+            context.response()
+                   
.setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code())
+                   .setStatusMessage(e.getMessage())
+                   .end();
+            return;
+        }
+
+        context.response().end(Json.encodePrettily(listCDCSegmentResponse));
+    }
+
+    private void addResources(final String cdcDirPath, final 
ListCDCSegmentResponse listResponse) throws IOException
+    {
+        final File cdcDir = Paths.get(cdcDirPath).toAbsolutePath().toFile();
+        if (!cdcDir.isDirectory())
+        {
+            throw new IOException("CDC directory does not exist");
+        }
+
+        final File[] cdcFiles = cdcDir.listFiles();
+        if (cdcFiles == null || cdcFiles.length == 0)
+        {
+            return;
+        }
+
+        final Set<String> idxFileNamePrefixes = Arrays.stream(cdcFiles)

Review Comment:
   ```suggestion
          Set<String> idxFileNamePrefixes = Arrays.stream(cdcFiles)
   ```



##########
server/src/main/java/org/apache/cassandra/sidecar/routes/cdc/ListCDCDirHandler.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.cassandra.sidecar.routes.cdc;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Pair;
+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.json.Json;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.common.response.ListCDCSegmentResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.ServiceConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.routes.AbstractHandler;
+import org.apache.cassandra.sidecar.utils.CDCUtil;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getIdxFileName;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getLogFilePrefix;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.isIndexFile;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.parseIndexFile;
+
+/**
+ * Provides REST endpoint for listing commit logs in CDC directory.
+ */
+@Singleton
+public class ListCDCDirHandler extends AbstractHandler<Void>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ListCDCDirHandler.class);
+    private final ServiceConfiguration config;
+
+    @Inject
+    public ListCDCDirHandler(InstanceMetadataFetcher metadataFetcher,
+                             SidecarConfiguration config,
+                             ExecutorPools executorPools,
+                             CassandraInputValidator validator)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.config = config.serviceConfiguration();
+    }
+
+    @Override
+    protected void handleInternal(RoutingContext context,
+                                  HttpServerRequest httpRequest,
+                                  String host,
+                                  SocketAddress remoteAddress,
+                                  Void request)
+    {
+        String cdcDir = metadataFetcher.instance(host).cdcDir();
+        ListCDCSegmentResponse listCDCSegmentResponse = new 
ListCDCSegmentResponse(config.host(),
+                                                                               
    config.port(),
+                                                                               
    new LinkedList<>());
+        try
+        {
+            addResources(cdcDir, listCDCSegmentResponse);
+        }
+        catch (IOException e)
+        {
+            LOGGER.warn("Error listing the CDC commit log segments", e);
+            context.response()
+                   
.setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code())
+                   .setStatusMessage(e.getMessage())
+                   .end();
+            return;
+        }
+
+        context.response().end(Json.encodePrettily(listCDCSegmentResponse));
+    }
+
+    private void addResources(final String cdcDirPath, final 
ListCDCSegmentResponse listResponse) throws IOException
+    {
+        final File cdcDir = Paths.get(cdcDirPath).toAbsolutePath().toFile();
+        if (!cdcDir.isDirectory())
+        {
+            throw new IOException("CDC directory does not exist");
+        }
+
+        final File[] cdcFiles = cdcDir.listFiles();
+        if (cdcFiles == null || cdcFiles.length == 0)
+        {
+            return;
+        }
+
+        final Set<String> idxFileNamePrefixes = Arrays.stream(cdcFiles)
+                                                      .map(File::getName)
+                                                      
.filter(CDCUtil::matchIndexExtension)
+                                                      
.map(CDCUtil::getIdxFilePrefix)
+                                                      
.collect(Collectors.toSet());
+        for (File resource : cdcFiles)
+        {
+            final String resourceName = resource.getName();

Review Comment:
   ```suggestion
              String resourceName = resource.getName();
   ```



##########
server/src/main/java/org/apache/cassandra/sidecar/routes/cdc/ListCDCDirHandler.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.cassandra.sidecar.routes.cdc;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Pair;
+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.json.Json;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.common.response.ListCDCSegmentResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.ServiceConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.routes.AbstractHandler;
+import org.apache.cassandra.sidecar.utils.CDCUtil;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getIdxFileName;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.getLogFilePrefix;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.isIndexFile;
+import static org.apache.cassandra.sidecar.utils.CDCUtil.parseIndexFile;
+
+/**
+ * Provides REST endpoint for listing commit logs in CDC directory.
+ */
+@Singleton
+public class ListCDCDirHandler extends AbstractHandler<Void>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ListCDCDirHandler.class);
+    private final ServiceConfiguration config;
+
+    @Inject
+    public ListCDCDirHandler(InstanceMetadataFetcher metadataFetcher,
+                             SidecarConfiguration config,
+                             ExecutorPools executorPools,
+                             CassandraInputValidator validator)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.config = config.serviceConfiguration();
+    }
+
+    @Override
+    protected void handleInternal(RoutingContext context,
+                                  HttpServerRequest httpRequest,
+                                  String host,
+                                  SocketAddress remoteAddress,
+                                  Void request)
+    {
+        String cdcDir = metadataFetcher.instance(host).cdcDir();
+        ListCDCSegmentResponse listCDCSegmentResponse = new 
ListCDCSegmentResponse(config.host(),
+                                                                               
    config.port(),
+                                                                               
    new LinkedList<>());
+        try
+        {
+            addResources(cdcDir, listCDCSegmentResponse);
+        }
+        catch (IOException e)
+        {
+            LOGGER.warn("Error listing the CDC commit log segments", e);
+            context.response()
+                   
.setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code())
+                   .setStatusMessage(e.getMessage())
+                   .end();
+            return;
+        }
+
+        context.response().end(Json.encodePrettily(listCDCSegmentResponse));
+    }
+
+    private void addResources(final String cdcDirPath, final 
ListCDCSegmentResponse listResponse) throws IOException

Review Comment:
   let's not use final here:
   ```suggestion
       private void addResources(String cdcDirPath, ListCDCSegmentResponse 
listResponse) throws IOException
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to