Skip to content

Commit

Permalink
adding spotless in common module (opensearch-project#2658)
Browse files Browse the repository at this point in the history
* adding spotless in common module

Signed-off-by: Dhrubo Saha <[email protected]>

* applied spotless

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>
  • Loading branch information
dhrubo-os authored Aug 8, 2024
1 parent 1071a48 commit 684627a
Show file tree
Hide file tree
Showing 418 changed files with 9,079 additions and 7,926 deletions.
12 changes: 11 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id 'io.github.goooler.shadow' version "8.1.7"
id 'jacoco'
id "io.freefair.lombok"
id 'com.diffplug.spotless' version '6.25.0'
id 'maven-publish'
id 'signing'
}
Expand Down Expand Up @@ -67,6 +68,15 @@ jacocoTestCoverageVerification {
}
check.dependsOn jacocoTestCoverageVerification

spotless {
java {
removeUnusedImports()
importOrder 'java', 'javax', 'org', 'com'

eclipse().configFile rootProject.file('.eclipseformat.xml')
}
}

shadowJar {
destinationDirectory = file("${project.buildDir}/distributions")
archiveClassifier.set(null)
Expand Down Expand Up @@ -137,4 +147,4 @@ publishing {
}
}
}
publishShadowPublicationToMavenLocal.mustRunAfter shadowJar
publishShadowPublicationToMavenLocal.mustRunAfter shadowJar
4 changes: 2 additions & 2 deletions common/src/main/java/org/opensearch/ml/common/AccessMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

package org.opensearch.ml.common;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;

public enum AccessMode {
PUBLIC("public"),
PRIVATE("private"),
Expand Down
1,029 changes: 532 additions & 497 deletions common/src/main/java/org/opensearch/ml/common/CommonValue.java

Large diffs are not rendered by default.

23 changes: 10 additions & 13 deletions common/src/main/java/org/opensearch/ml/common/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@

package org.opensearch.ml.common;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;

import java.io.IOException;

import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;

import java.io.IOException;

import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Getter
@EqualsAndHashCode
Expand All @@ -30,9 +31,7 @@ public class Configuration implements ToXContentObject, Writeable {
private String agentId;

@Builder(toBuilder = true)
public Configuration(
String agentId
) {
public Configuration(String agentId) {
this.agentId = agentId;
}

Expand Down Expand Up @@ -76,8 +75,6 @@ public static Configuration parse(XContentParser parser) throws IOException {
break;
}
}
return Configuration.builder()
.agentId(agentId)
.build();
return Configuration.builder().agentId(agentId).build();
}
}
10 changes: 3 additions & 7 deletions common/src/main/java/org/opensearch/ml/common/FunctionName.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ public static FunctionName from(String value) {
}
}

private static final HashSet<FunctionName> DL_MODELS = new HashSet<>(Set.of(
TEXT_EMBEDDING,
TEXT_SIMILARITY,
SPARSE_ENCODING,
SPARSE_TOKENIZE,
QUESTION_ANSWERING
));
private static final HashSet<FunctionName> DL_MODELS = new HashSet<>(
Set.of(TEXT_EMBEDDING, TEXT_SIMILARITY, SPARSE_ENCODING, SPARSE_TOKENIZE, QUESTION_ANSWERING)
);

/**
* Check if model is deep learning model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@

package org.opensearch.ml.common;

import lombok.extern.log4j.Log4j2;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.ml.common.annotation.Connector;
import org.opensearch.ml.common.annotation.ExecuteInput;
Expand All @@ -20,14 +28,7 @@
import org.opensearch.ml.common.output.MLOutputType;
import org.reflections.Reflections;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import lombok.extern.log4j.Log4j2;

@Log4j2
@SuppressWarnings("removal")
Expand Down Expand Up @@ -93,7 +94,7 @@ private static void loadMLAlgoParameterClassMapping() {
if (mlAlgoParameter != null) {
FunctionName[] algorithms = mlAlgoParameter.algorithms();
if (algorithms != null && algorithms.length > 0) {
for(FunctionName name : algorithms){
for (FunctionName name : algorithms) {
parameterClassMap.put(name, clazz);
}
}
Expand Down Expand Up @@ -157,7 +158,7 @@ private static void loadExecuteInputClassMapping() {
if (executeInput != null) {
FunctionName[] algorithms = executeInput.algorithms();
if (algorithms != null && algorithms.length > 0) {
for(FunctionName name : algorithms){
for (FunctionName name : algorithms) {
executeInputClassMap.put(name, clazz);
}
}
Expand All @@ -176,7 +177,7 @@ private static void loadExecuteOutputClassMapping() {
if (executeOutput != null) {
FunctionName[] algorithms = executeOutput.algorithms();
if (algorithms != null && algorithms.length > 0) {
for(FunctionName name : algorithms){
for (FunctionName name : algorithms) {
executeOutputClassMap.put(name, clazz);
}
}
Expand All @@ -192,7 +193,7 @@ private static void loadMLInputClassMapping() {
if (mlInput != null) {
FunctionName[] algorithms = mlInput.functionNames();
if (algorithms != null && algorithms.length > 0) {
for(FunctionName name : algorithms){
for (FunctionName name : algorithms) {
mlInputClassMap.put(name, clazz);
}
}
Expand Down Expand Up @@ -242,7 +243,7 @@ private static <T, S, I extends Object> S init(Map<T, Class<?>> map, T type, I i
} catch (Exception e) {
Throwable cause = e.getCause();
if (cause instanceof MLException || cause instanceof IllegalArgumentException) {
throw (RuntimeException)cause;
throw (RuntimeException) cause;
} else {
log.error("Failed to init instance for type " + type, e);
return null;
Expand All @@ -254,19 +255,16 @@ public static boolean canInitMLInput(FunctionName functionName) {
return mlInputClassMap.containsKey(functionName);
}

public static <S> S initConnector(String name, Object[] initArgs,
Class<?>... constructorParameterTypes) {
public static <S> S initConnector(String name, Object[] initArgs, Class<?>... constructorParameterTypes) {
return init(connectorClassMap, name, initArgs, constructorParameterTypes);
}

@SuppressWarnings("unchecked")
public static <T extends Enum<T>, S> S initMLInput(T type, Object[] initArgs,
Class<?>... constructorParameterTypes) {
public static <T extends Enum<T>, S> S initMLInput(T type, Object[] initArgs, Class<?>... constructorParameterTypes) {
return init(mlInputClassMap, type, initArgs, constructorParameterTypes);
}

private static <T, S> S init(Map<T, Class<?>> map, T type,
Object[] initArgs, Class<?>... constructorParameterTypes) {
private static <T, S> S init(Map<T, Class<?>> map, T type, Object[] initArgs, Class<?>... constructorParameterTypes) {
Class<?> clazz = map.get(type);
if (clazz == null) {
throw new IllegalArgumentException("Can't find class for type " + type);
Expand All @@ -277,7 +275,7 @@ private static <T, S> S init(Map<T, Class<?>> map, T type,
} catch (Exception e) {
Throwable cause = e.getCause();
if (cause instanceof MLException) {
throw (MLException)cause;
throw (MLException) cause;
} else if (cause instanceof IllegalArgumentException) {
throw (IllegalArgumentException) cause;
} else {
Expand Down
38 changes: 17 additions & 21 deletions common/src/main/java/org/opensearch/ml/common/MLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@

package org.opensearch.ml.common;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;

import java.io.IOException;
import java.time.Instant;

import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;

import java.io.IOException;
import java.time.Instant;

import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Getter
@EqualsAndHashCode
Expand All @@ -38,7 +39,6 @@ public class MLConfig implements ToXContentObject, Writeable {

public static final String LAST_UPDATED_TIME_FIELD = "last_updated_time";


@Setter
private String type;

Expand All @@ -47,12 +47,7 @@ public class MLConfig implements ToXContentObject, Writeable {
private Instant lastUpdateTime;

@Builder(toBuilder = true)
public MLConfig(
String type,
Configuration configuration,
Instant createTime,
Instant lastUpdateTime
) {
public MLConfig(String type, Configuration configuration, Instant createTime, Instant lastUpdateTime) {
this.type = type;
this.configuration = configuration;
this.createTime = createTime;
Expand Down Expand Up @@ -145,11 +140,12 @@ public static MLConfig parse(XContentParser parser) throws IOException {
break;
}
}
return MLConfig.builder()
.type(configType == null ? type : configType)
.configuration(mlConfiguration == null ? configuration : mlConfiguration)
.createTime(createTime)
.lastUpdateTime(lastUpdatedTime == null ? lastUpdateTime : lastUpdatedTime)
.build();
return MLConfig
.builder()
.type(configType == null ? type : configType)
.configuration(mlConfiguration == null ? configuration : mlConfiguration)
.createTime(createTime)
.lastUpdateTime(lastUpdatedTime == null ? lastUpdateTime : lastUpdatedTime)
.build();
}
}
Loading

0 comments on commit 684627a

Please sign in to comment.