sklaha commented on code in PR #258: URL: https://github.com/apache/cassandra-sidecar/pull/258#discussion_r2371221491
########## server/src/main/java/org/apache/cassandra/sidecar/job/NodeDrainJob.java: ########## @@ -0,0 +1,140 @@ +/* + * 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 + { + DRAINING(OperationalJobStatus.RUNNING), + DRAINED(OperationalJobStatus.SUCCEEDED); + + final OperationalJobStatus jobStatus; + + NodeDrainStateEnum(OperationalJobStatus jobStatus) + { + this.jobStatus = jobStatus; + } + + /** + * Converts a string operation mode to a DrainState enum. + * + * @param operationMode the operation mode string + * @return the corresponding DrainState, or null if not a drain state + */ + public static NodeDrainStateEnum fromOperationMode(String operationMode) + { + try + { + return valueOf(operationMode); + } + catch (IllegalArgumentException | NullPointerException e) + { + return null; + } + } + } + + public NodeDrainJob(UUID jobId, StorageOperations storageOps) + { + super(jobId); + this.storageOperations = storageOps; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isRunningOnCassandra() + { + String operationMode = storageOperations.operationMode(); + NodeDrainStateEnum nodeDrainStateEnum = NodeDrainStateEnum.fromOperationMode(operationMode); + return nodeDrainStateEnum != null && nodeDrainStateEnum.jobStatus == OperationalJobStatus.RUNNING; Review Comment: Updated. -- 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]

