nvharikrishna commented on code in PR #212:
URL: https://github.com/apache/cassandra-sidecar/pull/212#discussion_r2094406223


##########
server/src/main/java/org/apache/cassandra/sidecar/modules/LiveMigrationModule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.modules;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.ProvidesIntoMap;
+import 
org.apache.cassandra.sidecar.handlers.livemigration.LiveMigrationApiEnableDisableHandler;
+import 
org.apache.cassandra.sidecar.handlers.livemigration.LiveMigrationListInstanceFilesHandler;
+import org.apache.cassandra.sidecar.handlers.livemigration.LiveMigrationMap;
+import 
org.apache.cassandra.sidecar.handlers.livemigration.LiveMigrationMapSidecarConfigImpl;
+import org.apache.cassandra.sidecar.modules.multibindings.KeyClassMapKey;
+import org.apache.cassandra.sidecar.modules.multibindings.VertxRouteMapKeys;
+import org.apache.cassandra.sidecar.routes.RouteBuilder;
+import org.apache.cassandra.sidecar.routes.VertxRoute;
+
+/**
+ * Module for supporting LiveMigration feature.
+ */
+public class LiveMigrationModule extends AbstractModule
+{
+
+    protected void configure()

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/modules/multibindings/VertxRouteMapKeys.java:
##########
@@ -248,4 +248,9 @@ interface UpdateServiceConfigurationRouteKey extends 
RouteClassKey
         HttpMethod HTTP_METHOD = HttpMethod.PUT;
         String ROUTE_URI = ApiEndpointsV1.SERVICE_CONFIG_ROUTE;
     }
+    interface LiveMigrationListInstanceFilesRouteKey extends RouteClassKey

Review Comment:
   Thanks! done.



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/InstanceFileInfo.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.common.response;
+
+import java.util.Objects;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Class for holding information of a downloadable file during Live Migration.
+ */
+public class InstanceFileInfo
+{
+    public final String fileUrl;
+    // size is only relevant when the fileType is 'FILE'
+    public final long size;
+    public final FileType fileType;
+
+    // The latest timestamp at which the file/dir was modified represented in 
milliseconds.
+    public final long lastModifiedTime;
+
+    public InstanceFileInfo(@JsonProperty("fileUrl") final String fileUrl,
+                            @JsonProperty("size") final long size,
+                            @JsonProperty("fileType") final FileType fileType,
+                            @JsonProperty("lastModifiedTime") final long 
lastModifiedTime)
+    {
+        this.fileUrl = fileUrl;
+        this.size = size;
+        this.fileType = fileType;
+        this.lastModifiedTime = lastModifiedTime;
+    }
+
+    /**
+     * Enum for file type
+     */
+    public enum FileType
+    {
+        FILE,
+        DIRECTORY
+    }
+
+    public boolean equals(Object o)
+    {
+        if (o == null || getClass() != o.getClass()) return false;
+        InstanceFileInfo that = (InstanceFileInfo) o;
+        return size == that.size
+               && lastModifiedTime == that.lastModifiedTime
+               && Objects.equals(fileUrl, that.fileUrl)
+               && fileType == that.fileType;
+    }
+
+    public int hashCode()

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationApiEnableDisableHandler.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.handlers.livemigration;
+
+import com.google.inject.Inject;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.config.LiveMigrationConfiguration;
+
+import static 
org.apache.cassandra.sidecar.handlers.AbstractHandler.extractHostAddressWithoutPort;
+
+
+/**
+ * Handler for enabling or disabling live-migration APIs. It helps to enable 
Live Migration APIs for
+ * either source/destination specified in {@link 
LiveMigrationConfiguration#migrationMap()}.
+ */
+public class LiveMigrationApiEnableDisableHandler
+{
+    final LiveMigrationMap liveMigrationMap;
+    final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationApiEnableDisableHandler(final LiveMigrationMap 
liveMigrationMap,
+                                                final InstancesMetadata 
instancesMetadata)
+    {
+        this.liveMigrationMap = liveMigrationMap;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    /**
+     * Enables route if local instance is getting live migrated (source).
+     *
+     * @param rc - routing context
+     */
+    public void isSource(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isSource(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    /**
+     * Enables route if local instance is the destination.
+     *
+     * @param rc - routing context
+     */
+    public void isDestination(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isDestination(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    /**
+     * Enables route if local instance is either source or destination in live 
migration map.
+     *
+     * @param rc - routing context
+     */
+    public void isSourceOrDestination(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationMapSidecarConfigImpl.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.handlers.livemigration;
+
+import java.util.Map;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.config.LiveMigrationConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Implementation for {@link LiveMigrationMap} using Sidecar configuration.
+ */
+@Singleton
+public class LiveMigrationMapSidecarConfigImpl implements LiveMigrationMap
+{
+    private final LiveMigrationConfiguration liveMigrationConfiguration;
+
+    @Inject
+    public LiveMigrationMapSidecarConfigImpl(SidecarConfiguration 
sidecarConfiguration)
+    {
+        this.liveMigrationConfiguration = 
sidecarConfiguration.liveMigrationConfiguration();
+    }
+
+    public boolean isSource(@NotNull InstanceMetadata instanceMeta)

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationApiEnableDisableHandler.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.handlers.livemigration;
+
+import com.google.inject.Inject;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.config.LiveMigrationConfiguration;
+
+import static 
org.apache.cassandra.sidecar.handlers.AbstractHandler.extractHostAddressWithoutPort;
+
+
+/**
+ * Handler for enabling or disabling live-migration APIs. It helps to enable 
Live Migration APIs for
+ * either source/destination specified in {@link 
LiveMigrationConfiguration#migrationMap()}.
+ */
+public class LiveMigrationApiEnableDisableHandler
+{
+    final LiveMigrationMap liveMigrationMap;
+    final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationApiEnableDisableHandler(final LiveMigrationMap 
liveMigrationMap,
+                                                final InstancesMetadata 
instancesMetadata)
+    {
+        this.liveMigrationMap = liveMigrationMap;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    /**
+     * Enables route if local instance is getting live migrated (source).
+     *
+     * @param rc - routing context
+     */
+    public void isSource(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isSource(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    /**
+     * Enables route if local instance is the destination.
+     *
+     * @param rc - routing context
+     */
+    public void isDestination(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isDestination(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    /**
+     * Enables route if local instance is either source or destination in live 
migration map.
+     *
+     * @param rc - routing context
+     */
+    public void isSourceOrDestination(final RoutingContext rc)

Review Comment:
   done



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/InstanceFilesListResponse.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.common.response;
+
+import java.util.List;
+import java.util.Objects;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Class representing response for

Review Comment:
   right, missed it!! Updated it.



##########
server/src/main/java/org/apache/cassandra/sidecar/modules/LiveMigrationModule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.modules;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.ProvidesIntoMap;
+import 
org.apache.cassandra.sidecar.handlers.livemigration.LiveMigrationApiEnableDisableHandler;
+import 
org.apache.cassandra.sidecar.handlers.livemigration.LiveMigrationListInstanceFilesHandler;
+import org.apache.cassandra.sidecar.handlers.livemigration.LiveMigrationMap;
+import 
org.apache.cassandra.sidecar.handlers.livemigration.LiveMigrationMapSidecarConfigImpl;
+import org.apache.cassandra.sidecar.modules.multibindings.KeyClassMapKey;
+import org.apache.cassandra.sidecar.modules.multibindings.VertxRouteMapKeys;
+import org.apache.cassandra.sidecar.routes.RouteBuilder;
+import org.apache.cassandra.sidecar.routes.VertxRoute;
+
+/**
+ * Module for supporting LiveMigration feature.
+ */
+public class LiveMigrationModule extends AbstractModule
+{
+
+    protected void configure()
+    {
+        
bind(LiveMigrationMap.class).to(LiveMigrationMapSidecarConfigImpl.class);
+        super.configure();

Review Comment:
   done



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/InstanceFilesListResponse.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.common.response;
+
+import java.util.List;
+import java.util.Objects;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Class representing response for
+ * Holds list of file urls (with their individual sizes) + total size of files
+ * <p>
+ * Sample format:
+ * <pre>
+ * {
+ *   "totalSize": 123456789,
+ *   "files" : [
+ *     {
+ *       "fileUrl": 
"/api/v1/live-migration/files/{type_of_directory}/{directory_index}/{relative_file_path}",
+ *       "size": 123456789,
+ *       "fileType": "FILE",
+ *       "lastModifiedTime": 1707193655406
+ *     },
+ *
+ *     {
+ *       "fileUrl": 
"/api/v1/live-migration/files/{type_of_directory}/{directory_index}/{relative_file_path}",
+ *       "size": -1,
+ *       "fileType": "DIRECTORY",
+ *       "lastModifiedTime": 1707798915999
+ *     }
+ *   ]
+ * }
+ * </pre>
+ */
+public class InstanceFilesListResponse
+{
+    private final List<InstanceFileInfo> files;
+    private final long totalSize;
+
+    public InstanceFilesListResponse(@NotNull final List<InstanceFileInfo> 
files)
+    {
+        this.files = files;
+        long sum = 0L;
+        for (InstanceFileInfo file : files)
+        {
+            if (file.fileType.equals(InstanceFileInfo.FileType.FILE))
+            {
+                long size = file.size;
+                sum += size;
+            }
+        }
+        totalSize = sum;
+    }
+
+    @SuppressWarnings("unused")

Review Comment:
   done



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/InstanceFileInfo.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.common.response;
+
+import java.util.Objects;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Class for holding information of a downloadable file during Live Migration.
+ */
+public class InstanceFileInfo

Review Comment:
   done



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/InstanceFileInfo.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.common.response;
+
+import java.util.Objects;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Class for holding information of a downloadable file during Live Migration.
+ */
+public class InstanceFileInfo
+{
+    public final String fileUrl;
+    // size is only relevant when the fileType is 'FILE'
+    public final long size;
+    public final FileType fileType;
+
+    // The latest timestamp at which the file/dir was modified represented in 
milliseconds.
+    public final long lastModifiedTime;
+
+    public InstanceFileInfo(@JsonProperty("fileUrl") final String fileUrl,
+                            @JsonProperty("size") final long size,
+                            @JsonProperty("fileType") final FileType fileType,
+                            @JsonProperty("lastModifiedTime") final long 
lastModifiedTime)
+    {
+        this.fileUrl = fileUrl;
+        this.size = size;
+        this.fileType = fileType;
+        this.lastModifiedTime = lastModifiedTime;
+    }
+
+    /**
+     * Enum for file type
+     */
+    public enum FileType
+    {
+        FILE,
+        DIRECTORY
+    }
+
+    public boolean equals(Object o)

Review Comment:
   done



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/InstanceFilesListResponse.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.common.response;
+
+import java.util.List;
+import java.util.Objects;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Class representing response for
+ * Holds list of file urls (with their individual sizes) + total size of files
+ * <p>
+ * Sample format:
+ * <pre>
+ * {
+ *   "totalSize": 123456789,
+ *   "files" : [
+ *     {
+ *       "fileUrl": 
"/api/v1/live-migration/files/{type_of_directory}/{directory_index}/{relative_file_path}",
+ *       "size": 123456789,
+ *       "fileType": "FILE",
+ *       "lastModifiedTime": 1707193655406
+ *     },
+ *
+ *     {
+ *       "fileUrl": 
"/api/v1/live-migration/files/{type_of_directory}/{directory_index}/{relative_file_path}",
+ *       "size": -1,
+ *       "fileType": "DIRECTORY",
+ *       "lastModifiedTime": 1707798915999
+ *     }
+ *   ]
+ * }
+ * </pre>
+ */
+public class InstanceFilesListResponse
+{
+    private final List<InstanceFileInfo> files;
+    private final long totalSize;
+
+    public InstanceFilesListResponse(@NotNull final List<InstanceFileInfo> 
files)
+    {
+        this.files = files;
+        long sum = 0L;
+        for (InstanceFileInfo file : files)
+        {
+            if (file.fileType.equals(InstanceFileInfo.FileType.FILE))
+            {
+                long size = file.size;
+                sum += size;
+            }
+        }
+        totalSize = sum;
+    }
+
+    @SuppressWarnings("unused")
+    public InstanceFilesListResponse(@JsonProperty("files") final 
List<InstanceFileInfo> files,
+                                     @JsonProperty("totalSize") final long 
totalSize)
+    {
+        this.files = files;
+        this.totalSize = totalSize;
+    }
+
+    public List<InstanceFileInfo> getFiles()
+    {
+        return files;
+    }
+
+    public long getTotalSize()
+    {
+        return totalSize;
+    }
+
+    public boolean equals(Object o)

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationListInstanceFilesHandler.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.handlers.livemigration;
+
+import java.io.IOException;
+import java.util.Set;
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.auth.authorization.Authorization;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.acl.authorization.BasicPermissions;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.common.response.InstanceFilesListResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.handlers.AbstractHandler;
+import org.apache.cassandra.sidecar.handlers.AccessProtected;
+import org.apache.cassandra.sidecar.livemigration.CassandraInstanceFiles;
+import org.apache.cassandra.sidecar.livemigration.CassandraInstanceFilesImpl;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException;
+
+/**
+ * Endpoint for returning list of files that a destination instance can copy.
+ */
+public class LiveMigrationListInstanceFilesHandler extends 
AbstractHandler<Void> implements AccessProtected
+{
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(LiveMigrationListInstanceFilesHandler.class);
+    private final SidecarConfiguration sidecarConfiguration;
+    private final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationListInstanceFilesHandler(InstanceMetadataFetcher 
metadataFetcher,
+                                                 ExecutorPools executorPools,
+                                                 CassandraInputValidator 
validator,
+                                                 SidecarConfiguration 
sidecarConfiguration,
+                                                 InstancesMetadata 
instancesMetadata)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.sidecarConfiguration = sidecarConfiguration;
+        this.instancesMetadata = instancesMetadata;

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationMap.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.handlers.livemigration;
+
+import java.util.Map;
+
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Map of source to destination C* instances to do the Live Migration.
+ */
+public interface LiveMigrationMap
+{
+    /**
+     * Tells whether given instance is configured as source or not.
+     *
+     * @param instanceMeta Cassandra instance metadata
+     * @return true if given instance is configured as source for live 
migration.
+     */
+    default boolean isSource(@NotNull final InstanceMetadata instanceMeta)
+    {
+        final Map<String, String> map = getMigrationMap();
+        return map != null && 
map.containsKey(String.valueOf(instanceMeta.host()));
+    }
+
+    /**
+     * Tells whether given instance is configured as destination or not.
+     *
+     * @param instanceMeta Cassandra instance metadata
+     * @return true if given instance is configured as destination for live 
migration.
+     */
+    default boolean isDestination(@NotNull final InstanceMetadata instanceMeta)
+    {
+        final Map<String, String> map = getMigrationMap();

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationMap.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.handlers.livemigration;
+
+import java.util.Map;
+
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Map of source to destination C* instances to do the Live Migration.
+ */
+public interface LiveMigrationMap
+{
+    /**
+     * Tells whether given instance is configured as source or not.
+     *
+     * @param instanceMeta Cassandra instance metadata
+     * @return true if given instance is configured as source for live 
migration.
+     */
+    default boolean isSource(@NotNull final InstanceMetadata instanceMeta)
+    {
+        final Map<String, String> map = getMigrationMap();

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationListInstanceFilesHandler.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.handlers.livemigration;
+
+import java.io.IOException;
+import java.util.Set;
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.auth.authorization.Authorization;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.acl.authorization.BasicPermissions;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.common.response.InstanceFilesListResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.handlers.AbstractHandler;
+import org.apache.cassandra.sidecar.handlers.AccessProtected;
+import org.apache.cassandra.sidecar.livemigration.CassandraInstanceFiles;
+import org.apache.cassandra.sidecar.livemigration.CassandraInstanceFilesImpl;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException;
+
+/**
+ * Endpoint for returning list of files that a destination instance can copy.
+ */
+public class LiveMigrationListInstanceFilesHandler extends 
AbstractHandler<Void> implements AccessProtected
+{
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(LiveMigrationListInstanceFilesHandler.class);
+    private final SidecarConfiguration sidecarConfiguration;
+    private final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationListInstanceFilesHandler(InstanceMetadataFetcher 
metadataFetcher,
+                                                 ExecutorPools executorPools,
+                                                 CassandraInputValidator 
validator,
+                                                 SidecarConfiguration 
sidecarConfiguration,
+                                                 InstancesMetadata 
instancesMetadata)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.sidecarConfiguration = sidecarConfiguration;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    protected Void extractParamsOrThrow(RoutingContext context)

Review Comment:
   done



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/InstanceFilesListResponse.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.common.response;
+
+import java.util.List;
+import java.util.Objects;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Class representing response for
+ * Holds list of file urls (with their individual sizes) + total size of files
+ * <p>
+ * Sample format:
+ * <pre>
+ * {
+ *   "totalSize": 123456789,
+ *   "files" : [
+ *     {
+ *       "fileUrl": 
"/api/v1/live-migration/files/{type_of_directory}/{directory_index}/{relative_file_path}",
+ *       "size": 123456789,
+ *       "fileType": "FILE",
+ *       "lastModifiedTime": 1707193655406
+ *     },
+ *
+ *     {
+ *       "fileUrl": 
"/api/v1/live-migration/files/{type_of_directory}/{directory_index}/{relative_file_path}",
+ *       "size": -1,
+ *       "fileType": "DIRECTORY",
+ *       "lastModifiedTime": 1707798915999
+ *     }
+ *   ]
+ * }
+ * </pre>
+ */
+public class InstanceFilesListResponse
+{
+    private final List<InstanceFileInfo> files;
+    private final long totalSize;
+
+    public InstanceFilesListResponse(@NotNull final List<InstanceFileInfo> 
files)
+    {
+        this.files = files;
+        long sum = 0L;
+        for (InstanceFileInfo file : files)
+        {
+            if (file.fileType.equals(InstanceFileInfo.FileType.FILE))
+            {
+                long size = file.size;
+                sum += size;
+            }
+        }
+        totalSize = sum;
+    }
+
+    @SuppressWarnings("unused")
+    public InstanceFilesListResponse(@JsonProperty("files") final 
List<InstanceFileInfo> files,
+                                     @JsonProperty("totalSize") final long 
totalSize)
+    {
+        this.files = files;
+        this.totalSize = totalSize;
+    }
+
+    public List<InstanceFileInfo> getFiles()
+    {
+        return files;
+    }
+
+    public long getTotalSize()
+    {
+        return totalSize;
+    }
+
+    public boolean equals(Object o)
+    {
+        if (o == null || getClass() != o.getClass()) return false;
+        InstanceFilesListResponse that = (InstanceFilesListResponse) o;
+        return totalSize == that.totalSize && Objects.equals(files, 
that.files);
+    }
+
+    public int hashCode()

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationApiEnableDisableHandler.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.handlers.livemigration;
+
+import com.google.inject.Inject;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.config.LiveMigrationConfiguration;
+
+import static 
org.apache.cassandra.sidecar.handlers.AbstractHandler.extractHostAddressWithoutPort;
+
+
+/**
+ * Handler for enabling or disabling live-migration APIs. It helps to enable 
Live Migration APIs for
+ * either source/destination specified in {@link 
LiveMigrationConfiguration#migrationMap()}.
+ */
+public class LiveMigrationApiEnableDisableHandler
+{
+    final LiveMigrationMap liveMigrationMap;
+    final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationApiEnableDisableHandler(final LiveMigrationMap 
liveMigrationMap,
+                                                final InstancesMetadata 
instancesMetadata)
+    {
+        this.liveMigrationMap = liveMigrationMap;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    /**
+     * Enables route if local instance is getting live migrated (source).
+     *
+     * @param rc - routing context
+     */
+    public void isSource(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isSource(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    /**
+     * Enables route if local instance is the destination.
+     *
+     * @param rc - routing context
+     */
+    public void isDestination(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationListInstanceFilesHandler.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.handlers.livemigration;
+
+import java.io.IOException;
+import java.util.Set;
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.auth.authorization.Authorization;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.acl.authorization.BasicPermissions;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.common.response.InstanceFilesListResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.handlers.AbstractHandler;
+import org.apache.cassandra.sidecar.handlers.AccessProtected;
+import org.apache.cassandra.sidecar.livemigration.CassandraInstanceFiles;
+import org.apache.cassandra.sidecar.livemigration.CassandraInstanceFilesImpl;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException;
+
+/**
+ * Endpoint for returning list of files that a destination instance can copy.
+ */
+public class LiveMigrationListInstanceFilesHandler extends 
AbstractHandler<Void> implements AccessProtected
+{
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(LiveMigrationListInstanceFilesHandler.class);
+    private final SidecarConfiguration sidecarConfiguration;
+    private final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationListInstanceFilesHandler(InstanceMetadataFetcher 
metadataFetcher,
+                                                 ExecutorPools executorPools,
+                                                 CassandraInputValidator 
validator,
+                                                 SidecarConfiguration 
sidecarConfiguration,
+                                                 InstancesMetadata 
instancesMetadata)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.sidecarConfiguration = sidecarConfiguration;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    protected Void extractParamsOrThrow(RoutingContext context)
+    {
+        return null;
+    }
+
+    protected void handleInternal(RoutingContext context, HttpServerRequest 
httpRequest, @NotNull String host,
+                                  SocketAddress remoteAddress, Void request)
+    {
+        InstanceMetadata instanceMetadata = 
instancesMetadata.instanceFromHost(host);

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationApiEnableDisableHandler.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.handlers.livemigration;
+
+import com.google.inject.Inject;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.config.LiveMigrationConfiguration;
+
+import static 
org.apache.cassandra.sidecar.handlers.AbstractHandler.extractHostAddressWithoutPort;
+
+
+/**
+ * Handler for enabling or disabling live-migration APIs. It helps to enable 
Live Migration APIs for
+ * either source/destination specified in {@link 
LiveMigrationConfiguration#migrationMap()}.
+ */
+public class LiveMigrationApiEnableDisableHandler
+{
+    final LiveMigrationMap liveMigrationMap;
+    final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationApiEnableDisableHandler(final LiveMigrationMap 
liveMigrationMap,
+                                                final InstancesMetadata 
instancesMetadata)
+    {
+        this.liveMigrationMap = liveMigrationMap;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    /**
+     * Enables route if local instance is getting live migrated (source).
+     *
+     * @param rc - routing context
+     */
+    public void isSource(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isSource(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    /**
+     * Enables route if local instance is the destination.
+     *
+     * @param rc - routing context
+     */
+    public void isDestination(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isDestination(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    /**
+     * Enables route if local instance is either source or destination in live 
migration map.
+     *
+     * @param rc - routing context
+     */
+    public void isSourceOrDestination(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isAny(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    private InstanceMetadata getLocalInstanceMeta(final RoutingContext rc)

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationApiEnableDisableHandler.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.handlers.livemigration;
+
+import com.google.inject.Inject;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.config.LiveMigrationConfiguration;
+
+import static 
org.apache.cassandra.sidecar.handlers.AbstractHandler.extractHostAddressWithoutPort;
+
+
+/**
+ * Handler for enabling or disabling live-migration APIs. It helps to enable 
Live Migration APIs for
+ * either source/destination specified in {@link 
LiveMigrationConfiguration#migrationMap()}.
+ */
+public class LiveMigrationApiEnableDisableHandler
+{
+    final LiveMigrationMap liveMigrationMap;
+    final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationApiEnableDisableHandler(final LiveMigrationMap 
liveMigrationMap,
+                                                final InstancesMetadata 
instancesMetadata)
+    {
+        this.liveMigrationMap = liveMigrationMap;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    /**
+     * Enables route if local instance is getting live migrated (source).
+     *
+     * @param rc - routing context
+     */
+    public void isSource(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isSource(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    /**
+     * Enables route if local instance is the destination.
+     *
+     * @param rc - routing context
+     */
+    public void isDestination(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isDestination(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    /**
+     * Enables route if local instance is either source or destination in live 
migration map.
+     *
+     * @param rc - routing context
+     */
+    public void isSourceOrDestination(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);
+        if (liveMigrationMap.isAny(instanceMeta))
+        {
+            rc.next();
+        }
+        else
+        {
+            rc.fail(HttpResponseStatus.NOT_FOUND.code());
+        }
+    }
+
+    private InstanceMetadata getLocalInstanceMeta(final RoutingContext rc)
+    {
+        final String host = extractHostAddressWithoutPort(rc.request());

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationApiEnableDisableHandler.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.handlers.livemigration;
+
+import com.google.inject.Inject;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.config.LiveMigrationConfiguration;
+
+import static 
org.apache.cassandra.sidecar.handlers.AbstractHandler.extractHostAddressWithoutPort;
+
+
+/**
+ * Handler for enabling or disabling live-migration APIs. It helps to enable 
Live Migration APIs for
+ * either source/destination specified in {@link 
LiveMigrationConfiguration#migrationMap()}.
+ */
+public class LiveMigrationApiEnableDisableHandler
+{
+    final LiveMigrationMap liveMigrationMap;
+    final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationApiEnableDisableHandler(final LiveMigrationMap 
liveMigrationMap,
+                                                final InstancesMetadata 
instancesMetadata)
+    {
+        this.liveMigrationMap = liveMigrationMap;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    /**
+     * Enables route if local instance is getting live migrated (source).
+     *
+     * @param rc - routing context
+     */
+    public void isSource(final RoutingContext rc)
+    {
+        final InstanceMetadata instanceMeta = getLocalInstanceMeta(rc);

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationApiEnableDisableHandler.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.handlers.livemigration;
+
+import com.google.inject.Inject;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.config.LiveMigrationConfiguration;
+
+import static 
org.apache.cassandra.sidecar.handlers.AbstractHandler.extractHostAddressWithoutPort;
+
+
+/**
+ * Handler for enabling or disabling live-migration APIs. It helps to enable 
Live Migration APIs for
+ * either source/destination specified in {@link 
LiveMigrationConfiguration#migrationMap()}.
+ */
+public class LiveMigrationApiEnableDisableHandler
+{
+    final LiveMigrationMap liveMigrationMap;
+    final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationApiEnableDisableHandler(final LiveMigrationMap 
liveMigrationMap,
+                                                final InstancesMetadata 
instancesMetadata)
+    {
+        this.liveMigrationMap = liveMigrationMap;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    /**
+     * Enables route if local instance is getting live migrated (source).
+     *
+     * @param rc - routing context
+     */
+    public void isSource(final RoutingContext rc)

Review Comment:
   done



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/livemigration/LiveMigrationListInstanceFilesHandler.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.handlers.livemigration;
+
+import java.io.IOException;
+import java.util.Set;
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.auth.authorization.Authorization;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.acl.authorization.BasicPermissions;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.common.response.InstanceFilesListResponse;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.handlers.AbstractHandler;
+import org.apache.cassandra.sidecar.handlers.AccessProtected;
+import org.apache.cassandra.sidecar.livemigration.CassandraInstanceFiles;
+import org.apache.cassandra.sidecar.livemigration.CassandraInstanceFilesImpl;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException;
+
+/**
+ * Endpoint for returning list of files that a destination instance can copy.
+ */
+public class LiveMigrationListInstanceFilesHandler extends 
AbstractHandler<Void> implements AccessProtected
+{
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(LiveMigrationListInstanceFilesHandler.class);
+    private final SidecarConfiguration sidecarConfiguration;
+    private final InstancesMetadata instancesMetadata;
+
+    @Inject
+    public LiveMigrationListInstanceFilesHandler(InstanceMetadataFetcher 
metadataFetcher,
+                                                 ExecutorPools executorPools,
+                                                 CassandraInputValidator 
validator,
+                                                 SidecarConfiguration 
sidecarConfiguration,
+                                                 InstancesMetadata 
instancesMetadata)
+    {
+        super(metadataFetcher, executorPools, validator);
+        this.sidecarConfiguration = sidecarConfiguration;
+        this.instancesMetadata = instancesMetadata;
+    }
+
+    protected Void extractParamsOrThrow(RoutingContext context)
+    {
+        return null;
+    }
+
+    protected void handleInternal(RoutingContext context, HttpServerRequest 
httpRequest, @NotNull String host,
+                                  SocketAddress remoteAddress, Void request)
+    {
+        InstanceMetadata instanceMetadata = 
instancesMetadata.instanceFromHost(host);
+
+        CassandraInstanceFiles filesList = new 
CassandraInstanceFilesImpl(instanceMetadata,
+                                                                          
sidecarConfiguration.liveMigrationConfiguration());
+        try
+        {
+
+            context.json(new InstanceFilesListResponse(filesList.getFiles()));
+        }
+        catch (IOException e)
+        {
+            LOGGER.error("Could not fetch instance files information.", e);
+            
context.fail(wrapHttpException(HttpResponseStatus.INTERNAL_SERVER_ERROR, 
e.getMessage(), e));
+        }

Review Comment:
   done



-- 
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-unsubscr...@cassandra.apache.org

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


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

Reply via email to