Skip to content

Commit

Permalink
A round of linting changes across the codebase.
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Schohn <[email protected]>
  • Loading branch information
gregschohn committed Sep 24, 2024
1 parent 6d3eea1 commit 011e0ef
Show file tree
Hide file tree
Showing 27 changed files with 227 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
@Slf4j
public class ParallelDocumentMigrationsTest extends SourceTestBase {

final static List<SearchClusterContainer.ContainerVersion> SOURCE_IMAGES = List.of(
static final List<SearchClusterContainer.ContainerVersion> SOURCE_IMAGES = List.of(
SearchClusterContainer.ES_V7_10_2
);
final static List<SearchClusterContainer.ContainerVersion> TARGET_IMAGES = List.of(SearchClusterContainer.OS_V2_14_0);
static final List<SearchClusterContainer.ContainerVersion> TARGET_IMAGES = List.of(SearchClusterContainer.OS_V2_14_0);

public static Stream<Arguments> makeDocumentMigrationArgs() {
List<Object[]> sourceImageArgs = SOURCE_IMAGES.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
@Slf4j
public class SourceTestBase {
public static final String GENERATOR_BASE_IMAGE = "migrations/elasticsearch_client_test_console:latest";
public final static int MAX_SHARD_SIZE_BYTES = 64 * 1024 * 1024;
public static final int MAX_SHARD_SIZE_BYTES = 64 * 1024 * 1024;
public static final String SOURCE_SERVER_ALIAS = "source";
public final static long TOLERABLE_CLIENT_SERVER_CLOCK_DIFFERENCE_SECONDS = 3600;
public static final long TOLERABLE_CLIENT_SERVER_CLOCK_DIFFERENCE_SECONDS = 3600;

protected static Object[] makeParamsForBase(SearchClusterContainer.ContainerVersion baseSourceImage) {
return new Object[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class InvalidResponse extends RfsException {
private static final Pattern unknownSetting = Pattern.compile("unknown setting \\[(.+)\\].+");
private static final ObjectMapper objectMapper = new ObjectMapper();
private final HttpResponse response;
private final transient HttpResponse response;

public InvalidResponse(String message, HttpResponse response) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public String getFailureMessage() {
}

public static class OperationFailed extends RfsException {
public final HttpResponse response;
public final transient HttpResponse response;

public OperationFailed(String message, HttpResponse response) {
super(message +"\nBody:\n" + response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@
import org.opensearch.migrations.metadata.tracing.IMetadataMigrationContexts;
import org.opensearch.migrations.tracing.IScopedInstrumentationAttributes;

public abstract class IRfsContexts {
public static class ActivityNames {
public interface IRfsContexts {
class ActivityNames {
private ActivityNames() {}

public static final String HTTP_REQUEST = "httpRequest";
public static final String CHECK_THEN_PUT_REQUESTS = "checkThenPutRequest";
}

public static class MetricNames {
class MetricNames {
private MetricNames() {}

public static final String BYTES_READ = "bytesRead";
public static final String BYTES_SENT = "bytesSent";
}

public interface IRequestContext extends IScopedInstrumentationAttributes {
interface IRequestContext extends IScopedInstrumentationAttributes {
String ACTIVITY_NAME = ActivityNames.HTTP_REQUEST;

void addBytesSent(int i);

void addBytesRead(int i);
}

public interface ICheckedIdempotentPutRequestContext extends IScopedInstrumentationAttributes {
interface ICheckedIdempotentPutRequestContext extends IScopedInstrumentationAttributes {
String ACTIVITY_NAME = ActivityNames.CHECK_THEN_PUT_REQUESTS;

IRequestContext createCheckRequestContext();

IRequestContext createPutContext();
}

public interface ICreateSnapshotContext extends IScopedInstrumentationAttributes {
interface ICreateSnapshotContext extends IScopedInstrumentationAttributes {
String ACTIVITY_NAME = IMetadataMigrationContexts.ActivityNames.CREATE_SNAPSHOT;

IRequestContext createRegisterRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import org.opensearch.migrations.bulkload.workcoordination.OpenSearchWorkCoordinator;
import org.opensearch.migrations.tracing.IScopedInstrumentationAttributes;

public abstract class IWorkCoordinationContexts {
public interface IWorkCoordinationContexts {

public static class ActivityNames {
class ActivityNames {
public static final String COORDINATION_INITIALIZATION = "workCoordinationInitialization";
public static final String CREATE_UNASSIGNED_WORK_ITEM = "createUnassignedWork";
public static final String PENDING_WORK_CHECK = "pendingWorkCheck";
Expand All @@ -17,7 +17,7 @@ public static class ActivityNames {
private ActivityNames() {}
}

public static class MetricNames {
class MetricNames {
public static final String NEXT_WORK_ASSIGNED = "nextWorkAssignedCount";
public static final String NO_NEXT_WORK_AVAILABLE = "noNextWorkAvailableCount";
public static final String RECOVERABLE_CLOCK_ERROR = "recoverableClockErrorCount";
Expand All @@ -26,37 +26,37 @@ public static class MetricNames {
private MetricNames() {}
}

public interface IRetryableActivityContext extends IScopedInstrumentationAttributes {
interface IRetryableActivityContext extends IScopedInstrumentationAttributes {
void recordRetry();

void recordFailure();
}

public interface IInitializeCoordinatorStateContext extends IRetryableActivityContext {
interface IInitializeCoordinatorStateContext extends IRetryableActivityContext {
String ACTIVITY_NAME = ActivityNames.COORDINATION_INITIALIZATION;
}

public interface ICreateUnassignedWorkItemContext extends IRetryableActivityContext {
interface ICreateUnassignedWorkItemContext extends IRetryableActivityContext {
String ACTIVITY_NAME = ActivityNames.CREATE_UNASSIGNED_WORK_ITEM;
}

public interface IPendingWorkItemsContext extends IScopedInstrumentationAttributes {
interface IPendingWorkItemsContext extends IScopedInstrumentationAttributes {
String ACTIVITY_NAME = ActivityNames.PENDING_WORK_CHECK;

IRefreshContext getRefreshContext();
}

public interface IRefreshContext extends IRetryableActivityContext {
interface IRefreshContext extends IRetryableActivityContext {
String ACTIVITY_NAME = ActivityNames.SYNC_REFRESH_CLUSTER;
}

public interface IBaseAcquireWorkContext extends IRetryableActivityContext {}
interface IBaseAcquireWorkContext extends IRetryableActivityContext {}

public interface IAcquireSpecificWorkContext extends IBaseAcquireWorkContext {
interface IAcquireSpecificWorkContext extends IBaseAcquireWorkContext {
String ACTIVITY_NAME = ActivityNames.ACQUIRE_SPECIFIC_WORK;
}

public interface IAcquireNextWorkItemContext extends IBaseAcquireWorkContext {
interface IAcquireNextWorkItemContext extends IBaseAcquireWorkContext {
String ACTIVITY_NAME = ActivityNames.ACQUIRE_NEXT_WORK;

IRefreshContext getRefreshContext();
Expand All @@ -70,13 +70,13 @@ public interface IAcquireNextWorkItemContext extends IBaseAcquireWorkContext {
void recordFailure(OpenSearchWorkCoordinator.PotentialClockDriftDetectedException e);
}

public interface ICompleteWorkItemContext extends IRetryableActivityContext {
interface ICompleteWorkItemContext extends IRetryableActivityContext {
String ACTIVITY_NAME = ActivityNames.COMPLETE_WORK;

IRefreshContext getRefreshContext();
}

public interface IScopedWorkContext<C extends IBaseAcquireWorkContext> extends IScopedInstrumentationAttributes {
interface IScopedWorkContext<C extends IBaseAcquireWorkContext> extends IScopedInstrumentationAttributes {
C createOpeningContext();

ICompleteWorkItemContext createCloseContet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
import lombok.Getter;
import lombok.NonNull;

public class RfsContexts extends IRfsContexts {
public interface RfsContexts extends IRfsContexts {

private RfsContexts() {}
String COUNT_UNITS = "count";

public static final String COUNT_UNITS = "count";

public static class GenericRequestContext extends BaseSpanContext<BaseRootRfsContext>
class GenericRequestContext extends BaseSpanContext<BaseRootRfsContext>
implements
IRfsContexts.IRequestContext {

Expand Down Expand Up @@ -97,7 +95,7 @@ public void addBytesRead(int i) {
}
}

public static class CheckedIdempotentPutRequestContext extends BaseSpanContext<BaseRootRfsContext>
class CheckedIdempotentPutRequestContext extends BaseSpanContext<BaseRootRfsContext>
implements
IRfsContexts.ICheckedIdempotentPutRequestContext {
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import lombok.Getter;
import lombok.NonNull;

public class WorkCoordinationContexts extends IWorkCoordinationContexts {
private WorkCoordinationContexts() {}

public interface WorkCoordinationContexts extends IWorkCoordinationContexts {
@AllArgsConstructor
public static class RetryLabels {
class RetryLabels {
CommonScopedMetricInstruments.ScopeLabels scopeLabels;
public final String retry;
public final String failure;
Expand All @@ -30,7 +28,7 @@ private static RetryLabels autoLabels(String activityName) {
);
}

public static class RetryMetricInstruments extends CommonScopedMetricInstruments {
class RetryMetricInstruments extends CommonScopedMetricInstruments {
public final LongCounter retryCounter;
public final LongCounter failureCounter;

Expand All @@ -41,7 +39,7 @@ private RetryMetricInstruments(Meter meter, RetryLabels retryLabels) {
}
}

public interface RetryableActivityContextMetricMixin<T extends RetryMetricInstruments>
interface RetryableActivityContextMetricMixin<T extends RetryMetricInstruments>
extends
IRetryableActivityContext {
T getRetryMetrics();
Expand All @@ -60,7 +58,7 @@ default void recordFailure() {
}

@Getter
public static class InitializeCoordinatorStateContext extends BaseSpanContext<RootWorkCoordinationContext>
class InitializeCoordinatorStateContext extends BaseSpanContext<RootWorkCoordinationContext>
implements
IInitializeCoordinatorStateContext,
RetryableActivityContextMetricMixin<InitializeCoordinatorStateContext.MetricInstruments> {
Expand Down Expand Up @@ -101,7 +99,7 @@ public MetricInstruments getRetryMetrics() {
}

@Getter
public static class CreateUnassignedWorkItemContext extends BaseSpanContext<RootWorkCoordinationContext>
class CreateUnassignedWorkItemContext extends BaseSpanContext<RootWorkCoordinationContext>
implements
ICreateUnassignedWorkItemContext,
RetryableActivityContextMetricMixin<CreateUnassignedWorkItemContext.MetricInstruments> {
Expand Down Expand Up @@ -138,7 +136,7 @@ public MetricInstruments getRetryMetrics() {
}

@Getter
public static class PendingItems extends BaseSpanContext<RootWorkCoordinationContext>
class PendingItems extends BaseSpanContext<RootWorkCoordinationContext>
implements
IPendingWorkItemsContext {
final IScopedInstrumentationAttributes enclosingScope;
Expand Down Expand Up @@ -180,7 +178,7 @@ public MetricInstruments getMetrics() {
}

@Getter
public static class Refresh extends BaseSpanContext<RootWorkCoordinationContext>
class Refresh extends BaseSpanContext<RootWorkCoordinationContext>
implements
IRefreshContext,
RetryableActivityContextMetricMixin<Refresh.MetricInstruments> {
Expand Down Expand Up @@ -217,7 +215,7 @@ public MetricInstruments getRetryMetrics() {
}

@Getter
public static class AcquireSpecificWorkContext extends BaseSpanContext<RootWorkCoordinationContext>
class AcquireSpecificWorkContext extends BaseSpanContext<RootWorkCoordinationContext>
implements
IAcquireSpecificWorkContext,
RetryableActivityContextMetricMixin<AcquireSpecificWorkContext.MetricInstruments> {
Expand Down Expand Up @@ -254,7 +252,7 @@ public MetricInstruments getRetryMetrics() {
}

@Getter
public static class AcquireNextWorkItemContext extends BaseSpanContext<RootWorkCoordinationContext>
class AcquireNextWorkItemContext extends BaseSpanContext<RootWorkCoordinationContext>
implements
IAcquireNextWorkItemContext,
RetryableActivityContextMetricMixin<AcquireNextWorkItemContext.MetricInstruments> {
Expand Down Expand Up @@ -326,7 +324,7 @@ public void recordFailure(OpenSearchWorkCoordinator.PotentialClockDriftDetectedE
}

@Getter
public static class CompleteWorkItemContext extends BaseSpanContext<RootWorkCoordinationContext>
class CompleteWorkItemContext extends BaseSpanContext<RootWorkCoordinationContext>
implements
ICompleteWorkItemContext,
RetryableActivityContextMetricMixin<CompleteWorkItemContext.MetricInstruments> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

public class TransformFunctions {
private static final ObjectMapper mapper = new ObjectMapper();
public static final String MAPPINGS_KEY_STR = "mappings";
public static final String SETTINGS_KEY_STR = "settings";
public static final String NUMBER_OF_REPLICAS_KEY_STR = "number_of_replicas";
public static final String INDEX_KEY_STR = "index";

private TransformFunctions() {}

public static Transformer getTransformer(
Version sourceVersion,
Expand Down Expand Up @@ -61,13 +67,11 @@ public static ObjectNode convertFlatSettingsToTree(ObjectNode flatSettings) {
* - [{"audit_message":{"properties":{"address":{"type":"text"}}}}]
*/
public static void removeIntermediateMappingsLevels(ObjectNode root) {
if (root.has("mappings")) {
try {
ArrayNode mappingsList = (ArrayNode) root.get("mappings");
root.set("mappings", getMappingsFromBeneathIntermediate(mappingsList));
} catch (ClassCastException e) {
// mappings isn't an array
return;
if (root.has(MAPPINGS_KEY_STR)) {
var val = root.get(MAPPINGS_KEY_STR);
if (val instanceof ArrayNode) {
ArrayNode mappingsList = (ArrayNode) val;
root.set(MAPPINGS_KEY_STR, getMappingsFromBeneathIntermediate(mappingsList));
}
}
}
Expand All @@ -94,13 +98,13 @@ public static ObjectNode getMappingsFromBeneathIntermediate(ArrayNode mappingsRo
public static void removeIntermediateIndexSettingsLevel(ObjectNode root) {
// Remove the intermediate key "index" under "settings", will start like:
// {"index":{"number_of_shards":"1","number_of_replicas":"1"}}
if (root.has("settings")) {
ObjectNode settingsRoot = (ObjectNode) root.get("settings");
if (settingsRoot.has("index")) {
ObjectNode indexSettingsRoot = (ObjectNode) settingsRoot.get("index");
if (root.has(SETTINGS_KEY_STR)) {
ObjectNode settingsRoot = (ObjectNode) root.get(SETTINGS_KEY_STR);
if (settingsRoot.has(INDEX_KEY_STR)) {
ObjectNode indexSettingsRoot = (ObjectNode) settingsRoot.get(INDEX_KEY_STR);
settingsRoot.setAll(indexSettingsRoot);
settingsRoot.remove("index");
root.set("settings", settingsRoot);
settingsRoot.remove(INDEX_KEY_STR);
root.set(SETTINGS_KEY_STR, settingsRoot);
}
}
}
Expand All @@ -112,20 +116,20 @@ public static void removeIntermediateIndexSettingsLevel(ObjectNode root) {
* the minimum number of replicas being 2.
*/
public static void fixReplicasForDimensionality(ObjectNode root, int dimensionality) {
if (root.has("settings")) {
ObjectNode settingsRoot = (ObjectNode) root.get("settings");
if (settingsRoot.has("number_of_replicas")) {
if (root.has(SETTINGS_KEY_STR)) {
ObjectNode settingsRoot = (ObjectNode) root.get(SETTINGS_KEY_STR);
if (settingsRoot.has(NUMBER_OF_REPLICAS_KEY_STR)) {
// dimensionality must be at least 1
dimensionality = Math.max(dimensionality, 1);
// If the total number of copies requested in the original settings is not a multiple of the
// dimensionality, then up it to the next largest multiple of the dimensionality.
int numberOfCopies = settingsRoot.get("number_of_replicas").asInt() + 1;
int numberOfCopies = settingsRoot.get(NUMBER_OF_REPLICAS_KEY_STR).asInt() + 1;
int remainder = numberOfCopies % dimensionality;
int newNumberOfCopies = (remainder > 0)
? (numberOfCopies + dimensionality - remainder)
: numberOfCopies;
int newNumberOfReplicas = newNumberOfCopies - 1;
settingsRoot.put("number_of_replicas", newNumberOfReplicas);
settingsRoot.put(NUMBER_OF_REPLICAS_KEY_STR, newNumberOfReplicas);
}
}
}
Expand Down
Loading

0 comments on commit 011e0ef

Please sign in to comment.