Skip to content

Commit

Permalink
Adding checkstyle and apply
Browse files Browse the repository at this point in the history
Signed-off-by: TrungBui59 <[email protected]>
  • Loading branch information
TrungBui59 committed Nov 22, 2023
1 parent 6325f62 commit 8dbd68e
Show file tree
Hide file tree
Showing 269 changed files with 5,552 additions and 4,736 deletions.
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
571 changes: 300 additions & 271 deletions common/src/main/java/org/opensearch/ml/common/CommonValue.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@

package org.opensearch.ml.common;

import lombok.extern.log4j.Log4j2;
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.ml.common.annotation.Connector;
import org.opensearch.ml.common.annotation.ExecuteInput;
import org.opensearch.ml.common.annotation.ExecuteOutput;
Expand All @@ -18,13 +25,7 @@
import org.opensearch.ml.common.output.MLOutputType;
import org.reflections.Reflections;

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
public class MLCommonsClassLoader {
Expand Down Expand Up @@ -89,7 +90,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 @@ -153,7 +154,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 @@ -172,7 +173,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 @@ -188,7 +189,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 @@ -223,7 +224,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 @@ -235,19 +236,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 @@ -258,8 +256,8 @@ 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;
} else if (cause instanceof IllegalArgumentException) {
throw (MLException) cause;
} else if (cause instanceof IllegalArgumentException) {
throw (IllegalArgumentException) cause;
} else {
log.error("Failed to init instance for type " + type, e);
Expand Down
150 changes: 78 additions & 72 deletions common/src/main/java/org/opensearch/ml/common/MLModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@

package org.opensearch.ml.common;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
import static org.opensearch.ml.common.CommonValue.USER;
import static org.opensearch.ml.common.connector.Connector.createConnector;

import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.opensearch.commons.authuser.User;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.commons.authuser.User;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
Expand All @@ -19,18 +26,12 @@
import org.opensearch.ml.common.model.MLModelConfig;
import org.opensearch.ml.common.model.MLModelFormat;
import org.opensearch.ml.common.model.MLModelState;
import org.opensearch.ml.common.model.TextEmbeddingModelConfig;
import org.opensearch.ml.common.model.MetricsCorrelationModelConfig;
import org.opensearch.ml.common.model.TextEmbeddingModelConfig;

import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
import static org.opensearch.ml.common.CommonValue.USER;
import static org.opensearch.ml.common.connector.Connector.createConnector;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Getter
public class MLModel implements ToXContentObject {
Expand All @@ -50,7 +51,7 @@ public class MLModel implements ToXContentObject {
public static final String MODEL_FORMAT_FIELD = "model_format";
public static final String MODEL_STATE_FIELD = "model_state";
public static final String MODEL_CONTENT_SIZE_IN_BYTES_FIELD = "model_content_size_in_bytes";
//SHA256 hash value of model content.
// SHA256 hash value of model content.
public static final String MODEL_CONTENT_HASH_VALUE_FIELD = "model_content_hash_value";

public static final String MODEL_CONFIG_FIELD = "model_config";
Expand Down Expand Up @@ -115,32 +116,35 @@ public class MLModel implements ToXContentObject {
private String connectorId;

@Builder(toBuilder = true)
public MLModel(String name,
String modelGroupId,
FunctionName algorithm,
String version,
String content,
User user,
String description,
MLModelFormat modelFormat,
MLModelState modelState,
Long modelContentSizeInBytes,
String modelContentHash,
MLModelConfig modelConfig,
Instant createdTime,
Instant lastUpdateTime,
Instant lastRegisteredTime,
Instant lastDeployedTime,
Instant lastUndeployedTime,
Integer autoRedeployRetryTimes,
String modelId, Integer chunkNumber,
Integer totalChunks,
Integer planningWorkerNodeCount,
Integer currentWorkerNodeCount,
String[] planningWorkerNodes,
boolean deployToAllNodes,
Connector connector,
String connectorId) {
public MLModel(
String name,
String modelGroupId,
FunctionName algorithm,
String version,
String content,
User user,
String description,
MLModelFormat modelFormat,
MLModelState modelState,
Long modelContentSizeInBytes,
String modelContentHash,
MLModelConfig modelConfig,
Instant createdTime,
Instant lastUpdateTime,
Instant lastRegisteredTime,
Instant lastDeployedTime,
Instant lastUndeployedTime,
Integer autoRedeployRetryTimes,
String modelId,
Integer chunkNumber,
Integer totalChunks,
Integer planningWorkerNodeCount,
Integer currentWorkerNodeCount,
String[] planningWorkerNodes,
boolean deployToAllNodes,
Connector connector,
String connectorId
) {
this.name = name;
this.modelGroupId = modelGroupId;
this.algorithm = algorithm;
Expand Down Expand Up @@ -170,7 +174,7 @@ public MLModel(String name,
this.connectorId = connectorId;
}

public MLModel(StreamInput input) throws IOException{
public MLModel(StreamInput input) throws IOException {
name = input.readOptionalString();
algorithm = input.readEnum(FunctionName.class);
version = input.readString();
Expand Down Expand Up @@ -371,7 +375,8 @@ public static MLModel parse(XContentParser parser, String algorithmName) throws
String oldContent = null;
User user = null;

String description = null;;
String description = null;
;
MLModelFormat modelFormat = null;
MLModelState modelState = null;
Long modelContentSizeInBytes = null;
Expand Down Expand Up @@ -511,35 +516,36 @@ public static MLModel parse(XContentParser parser, String algorithmName) throws
break;
}
}
return MLModel.builder()
.name(name)
.modelGroupId(modelGroupId)
.algorithm(algorithm)
.version(version == null ? oldVersion + "" : version)
.content(content == null ? oldContent : content)
.user(user)
.description(description)
.modelFormat(modelFormat)
.modelState(modelState)
.modelContentSizeInBytes(modelContentSizeInBytes)
.modelContentHash(modelContentHash)
.modelConfig(modelConfig)
.createdTime(createdTime)
.lastUpdateTime(lastUpdateTime)
.lastRegisteredTime(lastRegisteredTime == null? lastUploadedTime : lastRegisteredTime)
.lastDeployedTime(lastDeployedTime == null? lastLoadedTime : lastDeployedTime)
.lastUndeployedTime(lastUndeployedTime == null? lastUnloadedTime : lastUndeployedTime)
.modelId(modelId)
.autoRedeployRetryTimes(autoRedeployRetryTimes)
.chunkNumber(chunkNumber)
.totalChunks(totalChunks)
.planningWorkerNodeCount(planningWorkerNodeCount)
.currentWorkerNodeCount(currentWorkerNodeCount)
.planningWorkerNodes(planningWorkerNodes.toArray(new String[0]))
.deployToAllNodes(deployToAllNodes)
.connector(connector)
.connectorId(connectorId)
.build();
return MLModel
.builder()
.name(name)
.modelGroupId(modelGroupId)
.algorithm(algorithm)
.version(version == null ? oldVersion + "" : version)
.content(content == null ? oldContent : content)
.user(user)
.description(description)
.modelFormat(modelFormat)
.modelState(modelState)
.modelContentSizeInBytes(modelContentSizeInBytes)
.modelContentHash(modelContentHash)
.modelConfig(modelConfig)
.createdTime(createdTime)
.lastUpdateTime(lastUpdateTime)
.lastRegisteredTime(lastRegisteredTime == null ? lastUploadedTime : lastRegisteredTime)
.lastDeployedTime(lastDeployedTime == null ? lastLoadedTime : lastDeployedTime)
.lastUndeployedTime(lastUndeployedTime == null ? lastUnloadedTime : lastUndeployedTime)
.modelId(modelId)
.autoRedeployRetryTimes(autoRedeployRetryTimes)
.chunkNumber(chunkNumber)
.totalChunks(totalChunks)
.planningWorkerNodeCount(planningWorkerNodeCount)
.currentWorkerNodeCount(currentWorkerNodeCount)
.planningWorkerNodes(planningWorkerNodes.toArray(new String[0]))
.deployToAllNodes(deployToAllNodes)
.connector(connector)
.connectorId(connectorId)
.build();
}

public static MLModel fromStream(StreamInput in) throws IOException {
Expand Down
Loading

0 comments on commit 8dbd68e

Please sign in to comment.