arjunashok commented on code in PR #265: URL: https://github.com/apache/cassandra-sidecar/pull/265#discussion_r2402863216
########## integration-tests/src/integrationTest/org/apache/cassandra/sidecar/routes/CassandraNodeOperationsIntegrationTest.java: ########## @@ -0,0 +1,161 @@ +/* + * 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; + +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.Test; + +import io.vertx.core.buffer.Buffer; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.web.client.HttpResponse; +import org.apache.cassandra.sidecar.common.ApiEndpointsV1; +import org.apache.cassandra.sidecar.common.data.OperationalJobStatus; +import org.apache.cassandra.sidecar.testing.SharedClusterSidecarIntegrationTestBase; + +import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED; +import static io.netty.handler.codec.http.HttpResponseStatus.OK; +import static org.apache.cassandra.testing.utils.AssertionUtils.getBlocking; +import static org.apache.cassandra.testing.utils.AssertionUtils.loopAssert; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for Cassandra node operations + */ +public class CassandraNodeOperationsIntegrationTest extends SharedClusterSidecarIntegrationTestBase +{ + public static final String CASSANDRA_VERSION_4_0 = "4.0"; + + @Override + protected void initializeSchemaForTest() + { + // No schema init needed + } + + @Override + protected void beforeTestStart() + { + // wait for the schema initialization + waitForSchemaReady(30, TimeUnit.SECONDS); + } + + @Test + void testNodeMoveOperationSuccess() + { + // Use a test token - this is a valid token for Murmur3Partitioner + String testToken = "123456789"; + + // Initiate move operation + HttpResponse<Buffer> moveResponse = getBlocking( + trustedClient().put(serverWrapper.serverPort, "localhost", ApiEndpointsV1.NODE_MOVE_ROUTE + "?newToken=" + testToken) + .send()); + + assertThat(moveResponse.statusCode()).isIn(OK.code(), ACCEPTED.code()); + + JsonObject responseBody = moveResponse.bodyAsJsonObject(); + assertThat(responseBody).isNotNull(); + assertThat(responseBody.getString("jobId")).isNotNull(); + assertThat(responseBody.getString("operation")).isEqualTo("move"); + assertThat(responseBody.getString("jobStatus")).isIn( + OperationalJobStatus.CREATED.name(), + OperationalJobStatus.RUNNING.name(), + OperationalJobStatus.SUCCEEDED.name() + ); + + // Verify the job eventually completes (or at least gets processed) + loopAssert(30, 500, () -> { + HttpResponse<Buffer> streamStatsResponse = getBlocking( + trustedClient().get(serverWrapper.serverPort, "localhost", ApiEndpointsV1.STREAM_STATS_ROUTE) + .send()); + + assertThat(streamStatsResponse.statusCode()).isEqualTo(OK.code()); + + JsonObject streamStats = streamStatsResponse.bodyAsJsonObject(); + assertThat(streamStats).isNotNull(); + // The operationMode should be either NORMAL (completed) or MOVING (in progress) + assertThat(streamStats.getString("operationMode")).isIn("NORMAL", "MOVING"); Review Comment: The concern with this is that we get a false negative when no move happened i.e. node remains in `NORMAL` state. We would need a more concrete way to validate that a move happened - eg. add data to ensure the move takes longer and evaluate validating the end state via ring or token-ranges endpoint. ########## server/src/main/java/org/apache/cassandra/sidecar/job/NodeMoveJob.java: ########## @@ -0,0 +1,71 @@ +/* + * 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.job; + +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.cassandra.sidecar.common.server.StorageOperations; + +/** + * Implementation of {@link OperationalJob} to perform node move operation. + */ +public class NodeMoveJob extends OperationalJob +{ + private static final Logger LOGGER = LoggerFactory.getLogger(NodeMoveJob.class); + private static final String OPERATION = "move"; + private static final String OPERATION_MODE_MOVING = "MOVING"; + private final String newToken; + protected StorageOperations storageOperations; + + public NodeMoveJob(UUID jobId, String newToken, StorageOperations storageOps) + { + super(jobId); + this.newToken = newToken; + this.storageOperations = storageOps; + } + + @Override + public boolean isRunningOnCassandra() + { + String operationMode = storageOperations.operationMode(); + return OPERATION_MODE_MOVING.equals(operationMode); Review Comment: Question is, do we want to fail-fast when we discover the node is not in a `NORMAL` state here. It would seem reasonable to do so, but worth checking Cassandra's behavior across versions. ########## client-common/src/main/java/org/apache/cassandra/sidecar/common/request/NodeMoveRequest.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.request; + +import io.netty.handler.codec.http.HttpMethod; +import org.apache.cassandra.sidecar.common.ApiEndpointsV1; +import org.apache.cassandra.sidecar.common.response.OperationalJobResponse; + +/** + * Represents a request to execute node move operation + */ +public class NodeMoveRequest extends JsonRequest<OperationalJobResponse> +{ + /** + * Constructs a request to execute a node move operation + * + * @param newToken the new token for the node to move to + */ + public NodeMoveRequest(String newToken) + { + super(ApiEndpointsV1.NODE_MOVE_ROUTE + "?newToken=" + newToken); Review Comment: +1, should be in the body since it is part of the actual resource being updated rather than an optional parameter/filter. -- 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]

