arjunashok commented on code in PR #258:
URL: https://github.com/apache/cassandra-sidecar/pull/258#discussion_r2376154036


##########
server/src/main/java/org/apache/cassandra/sidecar/job/NodeDrainJob.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.io.IOException;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.sidecar.common.data.OperationalJobStatus;
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+import 
org.apache.cassandra.sidecar.common.server.exceptions.OperationalJobException;
+
+/**
+ * Implementation of {@link OperationalJob} to perform node drain operation.
+ */
+public class NodeDrainJob extends OperationalJob
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(NodeDrainJob.class);
+    private static final String OPERATION = "drain";
+    protected StorageOperations storageOperations;
+
+    /**
+     * Enum representing the various drain states of a Cassandra node.
+     */
+    public enum NodeDrainStateEnum

Review Comment:
   Should this be a generic `OperationMode` enum (minus the Enum suffix in the 
name)? This could then be leveraged by other jobs that interpret or map them 
into job states (eg. decommission). Unless you see a need for a drain specific 
enum. 



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/NodeDecommissionHandler.java:
##########
@@ -89,22 +84,7 @@ public void handleInternal(RoutingContext context,
     {
         StorageOperations operations = 
metadataFetcher.delegate(host).storageOperations();
         NodeDecommissionJob job = new NodeDecommissionJob(UUIDs.timeBased(), 
operations, isForce);
-        try
-        {
-            jobManager.trySubmitJob(job);
-        }
-        catch (OperationalJobConflictException oje)
-        {
-            String reason = oje.getMessage();
-            logger.error("Conflicting job encountered. reason={}", reason);
-            
context.response().setStatusCode(HttpResponseStatus.CONFLICT.code());
-            context.json(new OperationalJobResponse(job.jobId(), 
OperationalJobStatus.FAILED, job.name(), reason));
-            return;
-        }
-
-        // Get the result, waiting for the specified wait time for result
-        job.asyncResult(executorPools.service(), 
config.operationalJobExecutionMaxWaitTime())
-           .onComplete(v -> 
OperationalJobUtils.sendStatusBasedResponse(context, job));
+        handleOperationalJob(this.jobManager, this.config, context, job);

Review Comment:
   nice



##########
integration-tests/src/integrationTest/org/apache/cassandra/sidecar/routes/CassandraNodeOperationsIntegrationTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.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 drain 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 testNodeDrainOperationSuccess()
+    {
+        // Initiate drain operation
+        HttpResponse<Buffer> drainResponse = getBlocking(
+        trustedClient().put(serverWrapper.serverPort, "localhost", 
ApiEndpointsV1.NODE_DRAIN_ROUTE)
+                       .send());
+
+        assertThat(drainResponse.statusCode()).isEqualTo(OK.code());
+
+        JsonObject responseBody = drainResponse.bodyAsJsonObject();
+        assertThat(responseBody).isNotNull();
+        assertThat(responseBody.getString("jobId")).isNotNull();
+        assertThat(responseBody.getString("jobStatus")).isIn(
+        OperationalJobStatus.CREATED.name(),
+        OperationalJobStatus.RUNNING.name(),
+        OperationalJobStatus.SUCCEEDED.name()
+        );
+
+        loopAssert(30, 500, () -> {
+            // Verify node status is DRAINED by checking the operationMode via 
stream stats endpoint
+            HttpResponse<Buffer> streamStatsResponse = getBlocking(

Review Comment:
   We should also validate that the operational job `status` endpoint behaves 
as expected.



-- 
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