-
Notifications
You must be signed in to change notification settings - Fork 52
CASSSIDECAR-360: Sidecar API Endpoint for Nodetool Compaction Stop #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
e59a7ad
1621d35
ff07a40
fc26e34
faa9f7c
3e60ced
a6b5497
f404939
0a9b3f4
39c9242
a439508
08fce25
6a023d6
b4bb71e
dcf5c94
4d9101d
f83d1bb
1ed12a2
9767b72
bddf663
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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.adapters.base; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
|
|
||
| /** | ||
| * Supported compaction types based on Cassandra's OperationType enum | ||
| */ | ||
| public enum CompactionType | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the catch - I may have been looking at another C* version. Just changed it to reflect this list: https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/db/compaction/OperationType.java |
||
| { | ||
| CLEANUP, | ||
| SCRUB, | ||
| UPGRADE_SSTABLES, | ||
| VERIFY, | ||
| RELOCATE, | ||
| GARBAGE_COLLECT, | ||
| ANTICOMPACTION, | ||
| VALIDATION, | ||
| INDEX_BUILD, | ||
| VIEW_BUILD, | ||
| COMPACTION, | ||
| TOMBSTONE_COMPACTION, | ||
| KEY_CACHE_SAVE, | ||
| ROW_CACHE_SAVE, | ||
| COUNTER_CACHE_SAVE, | ||
| INDEX_SUMMARY; | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return name(); | ||
| } | ||
|
|
||
| /** | ||
| * Case-insensitive factory method for Jackson deserialization | ||
| * @return {@link CompactionType} from string | ||
| */ | ||
| @JsonCreator | ||
| public static CompactionType fromString(String name) | ||
| { | ||
| if (name == null || name.trim().isEmpty()) | ||
| { | ||
| return null; | ||
| } | ||
| try | ||
| { | ||
| return valueOf(name.trim().toUpperCase(Locale.ROOT)); | ||
| } | ||
| catch (IllegalArgumentException unknownEnum) | ||
| { | ||
| String validTypes = String.join(", ", | ||
| java.util.Arrays.stream(CompactionType.values()) | ||
| .map(CompactionType::name) | ||
| .toArray(String[]::new)); | ||
| throw new IllegalArgumentException( | ||
| String.format("Unsupported compactionType: '%s'. Valid types are: %s", | ||
| name, validTypes)); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * 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.adapters.base; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import org.apache.cassandra.sidecar.adapters.base.jmx.CompactionManagerJmxOperations; | ||
| import org.apache.cassandra.sidecar.common.server.JmxClient; | ||
|
|
||
| import static org.apache.cassandra.sidecar.adapters.base.jmx.CompactionManagerJmxOperations.COMPACTION_MANAGER_OBJ_NAME; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * Tests for {@link CassandraCompactionManagerOperations} class | ||
| */ | ||
| class CassandraCompactionManagerOperationsTest | ||
| { | ||
| private CassandraCompactionManagerOperations compactionManagerOperations; | ||
| private JmxClient mockJmxClient; | ||
| private CompactionManagerJmxOperations mockJmxOperations; | ||
|
|
||
| @BeforeEach | ||
| void setUp() | ||
| { | ||
| mockJmxClient = mock(JmxClient.class); | ||
| mockJmxOperations = mock(CompactionManagerJmxOperations.class); | ||
| compactionManagerOperations = new CassandraCompactionManagerOperations(mockJmxClient); | ||
|
|
||
| // Setup JMX proxy mock | ||
| when(mockJmxClient.proxy(CompactionManagerJmxOperations.class, COMPACTION_MANAGER_OBJ_NAME)) | ||
| .thenReturn(mockJmxOperations); | ||
| } | ||
|
|
||
| @Test | ||
| void testStopCompactionByIdOnly() | ||
| { | ||
| // Test stopCompactionById called when providing compactionId | ||
| String compactionId = "abc-123"; | ||
| compactionManagerOperations.stopCompactionById(compactionId); | ||
|
|
||
| verify(mockJmxOperations, times(1)).stopCompactionById(compactionId); | ||
| verify(mockJmxOperations, times(0)).stopCompaction(org.mockito.ArgumentMatchers.anyString()); | ||
| } | ||
|
|
||
| @Test | ||
| void testStopCompactionByTypeOnly() | ||
| { | ||
| // Test stopCompaction called when no compactionId provided | ||
| String compactionType = "COMPACTION"; | ||
| compactionManagerOperations.stopCompaction(compactionType); | ||
|
|
||
| verify(mockJmxOperations, times(1)).stopCompaction(compactionType); | ||
| verify(mockJmxOperations, times(0)).stopCompactionById(org.mockito.ArgumentMatchers.anyString()); | ||
| } | ||
|
|
||
| @Test | ||
| void testStopCompactionByIdWithWhitespace() | ||
| { | ||
| // Test trim does not result in empty string | ||
| String compactionId = " abc-123 "; | ||
| compactionManagerOperations.stopCompactionById(compactionId); | ||
|
|
||
| verify(mockJmxOperations, times(1)).stopCompactionById(compactionId); | ||
| verify(mockJmxOperations, times(0)).stopCompaction(org.mockito.ArgumentMatchers.anyString()); | ||
| } | ||
|
|
||
| @Test | ||
| void testStopCompactionAllSupportedTypes() | ||
| { | ||
| // Test no failures upon any supported type being provided as param | ||
| String[] supportedTypes = { | ||
| "COMPACTION", "VALIDATION", "KEY_CACHE_SAVE", "ROW_CACHE_SAVE", | ||
| "COUNTER_CACHE_SAVE", "CLEANUP", "SCRUB", "UPGRADE_SSTABLES", | ||
| "INDEX_BUILD", "TOMBSTONE_COMPACTION", "ANTICOMPACTION", | ||
| "VERIFY", "VIEW_BUILD", "INDEX_SUMMARY", "RELOCATE", | ||
| "GARBAGE_COLLECT" | ||
| }; | ||
|
|
||
| for (String type : supportedTypes) | ||
| { | ||
| compactionManagerOperations.stopCompaction(type); | ||
| verify(mockJmxOperations, times(1)).stopCompaction(type); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testStopCompactionJmxProxyCalledOnce() | ||
| { | ||
| // Test JMX proxy obtained exactly once per call | ||
| compactionManagerOperations.stopCompactionById("test-id"); | ||
|
|
||
| verify(mockJmxClient, times(1)) | ||
| .proxy(CompactionManagerJmxOperations.class, COMPACTION_MANAGER_OBJ_NAME); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.