frankgh commented on code in PR #144: URL: https://github.com/apache/cassandra-sidecar/pull/144#discussion_r1914213331
########## client-common/src/main/java/org/apache/cassandra/sidecar/common/request/NodeDecommissionRequest.java: ########## @@ -0,0 +1,45 @@ +/* + * 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 decommission operation + */ +public class NodeDecommissionRequest extends JsonRequest<OperationalJobResponse> +{ + /** + * Constructs a request to execute a node decommission operation + */ + public NodeDecommissionRequest() + { + super(ApiEndpointsV1.NODE_DECOMMISSION_ROUTE); + } + + /** + * {@inheritDoc} + */ + public HttpMethod method() Review Comment: let's make sure you add override annotations ########## adapters/cassandra41/src/main/java/org/apache/cassandra/sidecar/adapters/cassandra41/Cassandra41StorageOperations.java: ########## @@ -34,6 +37,8 @@ */ public class Cassandra41StorageOperations extends CassandraStorageOperations { + + private static final Logger LOGGER = LoggerFactory.getLogger(Cassandra41StorageOperations.class); Review Comment: seems unused, can we remove it? ########## server/src/test/java/org/apache/cassandra/sidecar/routes/NodeDecommissionHandlerTest.java: ########## @@ -0,0 +1,216 @@ +/* + * 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.Collections; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.util.Modules; +import io.vertx.core.Vertx; +import io.vertx.ext.web.client.WebClient; +import io.vertx.ext.web.client.predicate.ResponsePredicate; +import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTestContext; +import org.apache.cassandra.sidecar.TestModule; +import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate; +import org.apache.cassandra.sidecar.cluster.InstancesMetadata; +import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata; +import org.apache.cassandra.sidecar.common.response.OperationalJobResponse; +import org.apache.cassandra.sidecar.common.server.StorageOperations; +import org.apache.cassandra.sidecar.server.MainModule; +import org.apache.cassandra.sidecar.server.Server; +import org.mockito.AdditionalAnswers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED; +import static io.netty.handler.codec.http.HttpResponseStatus.CONFLICT; +import static io.netty.handler.codec.http.HttpResponseStatus.OK; +import static org.apache.cassandra.sidecar.common.data.OperationalJobStatus.RUNNING; +import static org.apache.cassandra.sidecar.common.data.OperationalJobStatus.SUCCEEDED; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Tests for the {@link NodeDecommissionHandler} + */ +@ExtendWith(VertxExtension.class) +public class NodeDecommissionHandlerTest +{ + static final Logger LOGGER = LoggerFactory.getLogger(NodeDecommissionHandlerTest.class); + Vertx vertx; + Server server; + + @Mock + static Review Comment: you can pass the mock to the ctor of the module and use it there. ########## server/src/main/java/org/apache/cassandra/sidecar/job/NodeDecommissionJob.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.job; + +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.cassandra.sidecar.common.data.OperationalJobStatus; +import org.apache.cassandra.sidecar.common.server.StorageOperations; + +/** + * Implementation of {@link OperationalJob} to perform node decommission operation. + */ +public class NodeDecommissionJob extends OperationalJob +{ + private static final Logger LOGGER = LoggerFactory.getLogger(NodeDecommissionJob.class); + private static final String operation = "decommission"; + private final boolean isForce; + protected StorageOperations storageOperations; + + public NodeDecommissionJob(UUID jobId, StorageOperations storageOps, boolean isForce) + { + super(jobId); + this.storageOperations = storageOps; + this.isForce = isForce; + } + + @Override + public boolean isRunningOnCassandra() + { + String operationMode = storageOperations.getOperationMode(); + return operationMode.equals("LEAVING") || operationMode.equals("DECOMMISSIONED"); + } + + /** + * {@inheritDoc} + */ + @Override + public OperationalJobStatus status() + { + String operationMode = storageOperations.getOperationMode(); + + if (operationMode.equals("LEAVING")) Review Comment: use switch instead? ########## server/src/main/java/org/apache/cassandra/sidecar/job/NodeDecommissionJob.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.job; + +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.cassandra.sidecar.common.data.OperationalJobStatus; +import org.apache.cassandra.sidecar.common.server.StorageOperations; + +/** + * Implementation of {@link OperationalJob} to perform node decommission operation. + */ +public class NodeDecommissionJob extends OperationalJob +{ + private static final Logger LOGGER = LoggerFactory.getLogger(NodeDecommissionJob.class); + private static final String operation = "decommission"; + private final boolean isForce; + protected StorageOperations storageOperations; + + public NodeDecommissionJob(UUID jobId, StorageOperations storageOps, boolean isForce) + { + super(jobId); + this.storageOperations = storageOps; + this.isForce = isForce; + } + + @Override + public boolean isRunningOnCassandra() + { + String operationMode = storageOperations.getOperationMode(); + return operationMode.equals("LEAVING") || operationMode.equals("DECOMMISSIONED"); + } + + /** + * {@inheritDoc} + */ + @Override + public OperationalJobStatus status() + { + String operationMode = storageOperations.getOperationMode(); + + if (operationMode.equals("LEAVING")) + { + return OperationalJobStatus.RUNNING; + } + else if (operationMode.equals("DECOMMISSIONED")) + { + return OperationalJobStatus.SUCCEEDED; + } + else + { + return super.status(); + } + } + + /** + * {@inheritDoc} + */ + protected void executeInternal() Review Comment: needs override annotations ########## server/src/test/java/org/apache/cassandra/sidecar/routes/ListOperationalJobsHandlerTest.java: ########## @@ -149,6 +149,11 @@ protected SampleOperationalJob(UUID jobId) super(jobId); } + public boolean isRunningOnCassandra() Review Comment: override ########## server-common/src/main/java/org/apache/cassandra/sidecar/common/server/StorageOperations.java: ########## @@ -102,4 +102,16 @@ default void outOfRangeDataCleanup(@NotNull String keyspace, @NotNull String tab { outOfRangeDataCleanup(keyspace, table, 1); } + + /** + * @return the operation-mode of the Cassandra instance + */ + String getOperationMode(); Review Comment: I don't think we can cache the value because it can change during the lifecycle of the C* process. also this method should be `operationMode` ########## server/src/main/java/org/apache/cassandra/sidecar/job/NodeDecommissionJob.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.job; + +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.cassandra.sidecar.common.data.OperationalJobStatus; +import org.apache.cassandra.sidecar.common.server.StorageOperations; + +/** + * Implementation of {@link OperationalJob} to perform node decommission operation. + */ +public class NodeDecommissionJob extends OperationalJob +{ + private static final Logger LOGGER = LoggerFactory.getLogger(NodeDecommissionJob.class); + private static final String operation = "decommission"; + private final boolean isForce; + protected StorageOperations storageOperations; + + public NodeDecommissionJob(UUID jobId, StorageOperations storageOps, boolean isForce) + { + super(jobId); + this.storageOperations = storageOps; + this.isForce = isForce; + } + + @Override + public boolean isRunningOnCassandra() + { + String operationMode = storageOperations.getOperationMode(); + return operationMode.equals("LEAVING") || operationMode.equals("DECOMMISSIONED"); + } + + /** + * {@inheritDoc} + */ + @Override + public OperationalJobStatus status() + { + String operationMode = storageOperations.getOperationMode(); + + if (operationMode.equals("LEAVING")) + { + return OperationalJobStatus.RUNNING; + } + else if (operationMode.equals("DECOMMISSIONED")) + { + return OperationalJobStatus.SUCCEEDED; + } + else + { + return super.status(); + } + } + + /** + * {@inheritDoc} + */ + protected void executeInternal() + { + if (isRunningOnCassandra()) + { + LOGGER.info("Not executing job as an ongoing or completed decommission operation was found jobId={}", jobId); Review Comment: info is the right level here? ########## server/src/main/java/org/apache/cassandra/sidecar/job/OperationalJob.java: ########## @@ -42,7 +41,7 @@ public abstract class OperationalJob implements Task<Void> private static final Logger LOGGER = LoggerFactory.getLogger(OperationalJob.class); // use v1 time-based uuid - public final UUID jobId; + protected final UUID jobId; Review Comment: why is this protected if we already expose it via a public method? -- 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]

