Skip to content
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

rename API/function/variable names #822

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion common/src/main/java/org/opensearch/ml/common/CommonValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CommonValue {
public static final String USER = "user";
public static final String META = "_meta";
public static final String SCHEMA_VERSION_FIELD = "schema_version";
public static final String UNLOADED = "unloaded";
public static final String UNDEPLOYED = "undeployed";
public static final String NOT_FOUND = "not_found";

public static final String BOX_TYPE_KEY = "box_type";
Expand Down Expand Up @@ -124,6 +124,15 @@ public class CommonValue {
+ " \""
+ MLModel.LAST_UNLOADED_TIME_FIELD
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n"
+ " \""
+ MLModel.LAST_REGISTERED_TIME_FIELD
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n"
+ " \""
+ MLModel.LAST_DEPLOYED_TIME_FIELD
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n"
+ " \""
+ MLModel.LAST_UNDEPLOYED_TIME_FIELD
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n"
+ USER_FIELD_MAPPING
+ " }\n"
+ "}";
Expand Down
66 changes: 42 additions & 24 deletions common/src/main/java/org/opensearch/ml/common/MLModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ public class MLModel implements ToXContentObject {
public static final String MODEL_CONFIG_FIELD = "model_config";
public static final String CREATED_TIME_FIELD = "created_time";
public static final String LAST_UPDATED_TIME_FIELD = "last_updated_time";
@Deprecated
public static final String LAST_UPLOADED_TIME_FIELD = "last_uploaded_time";
ylwu-amzn marked this conversation as resolved.
Show resolved Hide resolved
@Deprecated
public static final String LAST_LOADED_TIME_FIELD = "last_loaded_time";
@Deprecated
public static final String LAST_UNLOADED_TIME_FIELD = "last_unloaded_time";
public static final String LAST_REGISTERED_TIME_FIELD = "last_registered_time";
public static final String LAST_DEPLOYED_TIME_FIELD = "last_deployed_time";
public static final String LAST_UNDEPLOYED_TIME_FIELD = "last_undeployed_time";

public static final String MODEL_ID_FIELD = "model_id";
public static final String CHUNK_NUMBER_FIELD = "chunk_number";
Expand All @@ -74,9 +80,9 @@ public class MLModel implements ToXContentObject {
private MLModelConfig modelConfig;
private Instant createdTime;
private Instant lastUpdateTime;
private Instant lastUploadedTime;
private Instant lastLoadedTime;
private Instant lastUnloadedTime;
private Instant lastRegisteredTime;
private Instant lastDeployedTime;
private Instant lastUndeployedTime;

@Setter
private String modelId; // model chunk doc only
Expand All @@ -101,9 +107,9 @@ public MLModel(String name,
MLModelConfig modelConfig,
Instant createdTime,
Instant lastUpdateTime,
Instant lastUploadedTime,
Instant lastLoadedTime,
Instant lastUnloadedTime,
Instant lastRegisteredTime,
Instant lastDeployedTime,
Instant lastUndeployedTime,
String modelId, Integer chunkNumber,
Integer totalChunks,
Integer planningWorkerNodeCount,
Expand All @@ -123,9 +129,9 @@ public MLModel(String name,
this.modelConfig = modelConfig;
this.createdTime = createdTime;
this.lastUpdateTime = lastUpdateTime;
this.lastUploadedTime = lastUploadedTime;
this.lastLoadedTime = lastLoadedTime;
this.lastUnloadedTime = lastUnloadedTime;
this.lastRegisteredTime = lastRegisteredTime;
this.lastDeployedTime = lastDeployedTime;
this.lastUndeployedTime = lastUndeployedTime;
this.modelId = modelId;
this.chunkNumber = chunkNumber;
this.totalChunks = totalChunks;
Expand Down Expand Up @@ -160,9 +166,9 @@ public MLModel(StreamInput input) throws IOException{
}
createdTime = input.readOptionalInstant();
lastUpdateTime = input.readOptionalInstant();
lastUploadedTime = input.readOptionalInstant();
lastLoadedTime = input.readOptionalInstant();
lastUnloadedTime = input.readOptionalInstant();
lastRegisteredTime = input.readOptionalInstant();
lastDeployedTime = input.readOptionalInstant();
lastUndeployedTime = input.readOptionalInstant();
modelId = input.readOptionalString();
chunkNumber = input.readOptionalInt();
totalChunks = input.readOptionalInt();
Expand Down Expand Up @@ -207,9 +213,9 @@ public void writeTo(StreamOutput out) throws IOException {
}
out.writeOptionalInstant(createdTime);
out.writeOptionalInstant(lastUpdateTime);
out.writeOptionalInstant(lastUploadedTime);
out.writeOptionalInstant(lastLoadedTime);
out.writeOptionalInstant(lastUnloadedTime);
out.writeOptionalInstant(lastRegisteredTime);
out.writeOptionalInstant(lastDeployedTime);
out.writeOptionalInstant(lastUndeployedTime);
out.writeOptionalString(modelId);
out.writeOptionalInt(chunkNumber);
out.writeOptionalInt(totalChunks);
Expand Down Expand Up @@ -261,14 +267,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (lastUpdateTime != null) {
builder.field(LAST_UPDATED_TIME_FIELD, lastUpdateTime.toEpochMilli());
}
if (lastUploadedTime != null) {
builder.field(LAST_UPLOADED_TIME_FIELD, lastUploadedTime.toEpochMilli());
if (lastRegisteredTime != null) {
builder.field(LAST_REGISTERED_TIME_FIELD, lastRegisteredTime.toEpochMilli());
}
if (lastLoadedTime != null) {
builder.field(LAST_LOADED_TIME_FIELD, lastLoadedTime.toEpochMilli());
if (lastDeployedTime != null) {
builder.field(LAST_DEPLOYED_TIME_FIELD, lastDeployedTime.toEpochMilli());
}
if (lastUnloadedTime != null) {
builder.field(LAST_UNLOADED_TIME_FIELD, lastUnloadedTime.toEpochMilli());
if (lastUndeployedTime != null) {
builder.field(LAST_UNDEPLOYED_TIME_FIELD, lastUndeployedTime.toEpochMilli());
}
if (modelId != null) {
builder.field(MODEL_ID_FIELD, modelId);
Expand Down Expand Up @@ -315,6 +321,9 @@ public static MLModel parse(XContentParser parser) throws IOException {
Instant lastUploadedTime = null;
Instant lastLoadedTime = null;
Instant lastUnloadedTime = null;
Instant lastRegisteredTime = null;
Instant lastDeployedTime = null;
Instant lastUndeployedTime = null;
String modelId = null;
Integer chunkNumber = null;
Integer totalChunks = null;
Expand Down Expand Up @@ -407,6 +416,15 @@ public static MLModel parse(XContentParser parser) throws IOException {
case LAST_UNLOADED_TIME_FIELD:
lastUnloadedTime = Instant.ofEpochMilli(parser.longValue());
break;
case LAST_REGISTERED_TIME_FIELD:
lastRegisteredTime = Instant.ofEpochMilli(parser.longValue());
break;
case LAST_DEPLOYED_TIME_FIELD:
lastDeployedTime = Instant.ofEpochMilli(parser.longValue());
break;
case LAST_UNDEPLOYED_TIME_FIELD:
lastUndeployedTime = Instant.ofEpochMilli(parser.longValue());
break;
default:
parser.skipChildren();
break;
Expand All @@ -426,9 +444,9 @@ public static MLModel parse(XContentParser parser) throws IOException {
.modelConfig(modelConfig)
.createdTime(createdTime)
.lastUpdateTime(lastUpdateTime)
.lastUploadedTime(lastUploadedTime)
.lastLoadedTime(lastLoadedTime)
.lastUnloadedTime(lastUnloadedTime)
.lastRegisteredTime(lastRegisteredTime == null? lastUploadedTime : lastRegisteredTime)
.lastDeployedTime(lastDeployedTime == null? lastLoadedTime : lastDeployedTime)
.lastUndeployedTime(lastUndeployedTime == null? lastUnloadedTime : lastUndeployedTime)
.modelId(modelId)
.chunkNumber(chunkNumber)
.totalChunks(totalChunks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public enum MLTaskType {
PREDICTION,
TRAINING_AND_PREDICTION,
EXECUTION,
@Deprecated
UPLOAD_MODEL,
LOAD_MODEL
@Deprecated
LOAD_MODEL,
REGISTER_MODEL,
DEPLOY_MODEL
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@

public enum MLModelState {
TRAINED,
@Deprecated
UPLOADING,
@Deprecated
UPLOADED,
@Deprecated
LOADING,
@Deprecated
LOADED,
@Deprecated
PARTIALLY_LOADED,
@Deprecated
UNLOADED,
LOAD_FAILED;
@Deprecated
LOAD_FAILED,

REGISTERING,
REGISTERED,
DEPLOYING,
DEPLOYED,
PARTIALLY_DEPLOYED,
UNDEPLOYED,
DEPLOY_FAILED;

public static MLModelState from(String value) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.transport.deploy;

import org.opensearch.action.ActionType;

public class MLDeployModelAction extends ActionType<MLDeployModelResponse> {
public static MLDeployModelAction INSTANCE = new MLDeployModelAction();
public static final String NAME = "cluster:admin/opensearch/ml/deploy_model";

private MLDeployModelAction() {
super(NAME, MLDeployModelResponse::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.transport.load;
package org.opensearch.ml.common.transport.deploy;

import lombok.Builder;
import lombok.Data;
Expand All @@ -15,15 +15,15 @@
import java.io.IOException;

@Data
public class LoadModelInput implements Writeable {
public class MLDeployModelInput implements Writeable {
private String modelId;
private String taskId;
private String modelContentHash;
private Integer nodeCount;
private String coordinatingNodeId;
private MLTask mlTask;

public LoadModelInput(StreamInput in) throws IOException {
public MLDeployModelInput(StreamInput in) throws IOException {
this.modelId = in.readString();
this.taskId = in.readString();
this.modelContentHash = in.readOptionalString();
Expand All @@ -33,7 +33,7 @@ public LoadModelInput(StreamInput in) throws IOException {
}

@Builder
public LoadModelInput(String modelId, String taskId, String modelContentHash, Integer nodeCount, String coordinatingNodeId, MLTask mlTask) {
public MLDeployModelInput(String modelId, String taskId, String modelContentHash, Integer nodeCount, String coordinatingNodeId, MLTask mlTask) {
this.modelId = modelId;
this.taskId = taskId;
this.modelContentHash = modelContentHash;
Expand All @@ -42,7 +42,7 @@ public LoadModelInput(String modelId, String taskId, String modelContentHash, In
this.mlTask = mlTask;
}

public LoadModelInput() {
public MLDeployModelInput() {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.transport.load;
package org.opensearch.ml.common.transport.deploy;

import lombok.Getter;
import org.opensearch.action.support.nodes.BaseNodeRequest;
Expand All @@ -12,27 +12,27 @@

import java.io.IOException;

public class LoadModelNodeRequest extends BaseNodeRequest {
public class MLDeployModelNodeRequest extends BaseNodeRequest {
@Getter
private LoadModelNodesRequest loadModelNodesRequest;
private MLDeployModelNodesRequest MLDeployModelNodesRequest;

public LoadModelNodeRequest(StreamInput in) throws IOException {
public MLDeployModelNodeRequest(StreamInput in) throws IOException {
super(in);
this.loadModelNodesRequest = new LoadModelNodesRequest(in);
this.MLDeployModelNodesRequest = new MLDeployModelNodesRequest(in);
}

/**
* Constructor
*
* @param request MLStatsNodesRequest
*/
public LoadModelNodeRequest(LoadModelNodesRequest request) {
this.loadModelNodesRequest = request;
public MLDeployModelNodeRequest(MLDeployModelNodesRequest request) {
this.MLDeployModelNodesRequest = request;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
loadModelNodesRequest.writeTo(out);
MLDeployModelNodesRequest.writeTo(out);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.transport.load;
package org.opensearch.ml.common.transport.deploy;

import lombok.extern.log4j.Log4j2;
import org.opensearch.action.support.nodes.BaseNodeResponse;
Expand All @@ -16,58 +16,58 @@
import java.io.IOException;
import java.util.Map;
@Log4j2
public class LoadModelNodeResponse extends BaseNodeResponse implements ToXContentFragment {
public class MLDeployModelNodeResponse extends BaseNodeResponse implements ToXContentFragment {

/**
* Key is modelName + ":" + version
*/
private Map<String, String> modelLoadStatus;
private Map<String, String> modelDeployStatus;

public LoadModelNodeResponse(DiscoveryNode node, Map<String, String> modelLoadStatus) {
public MLDeployModelNodeResponse(DiscoveryNode node, Map<String, String> modelDeployStatus) {
super(node);
this.modelLoadStatus = modelLoadStatus;
this.modelDeployStatus = modelDeployStatus;
}
/**
* Constructor
*
* @param in StreamInput
* @throws IOException throws an IO exception if the StreamInput cannot be read from
*/
public LoadModelNodeResponse(StreamInput in) throws IOException {
public MLDeployModelNodeResponse(StreamInput in) throws IOException {
super(in);
if (in.readBoolean()) {
this.modelLoadStatus = in.readMap(s -> s.readString(), s-> s.readString());
this.modelDeployStatus = in.readMap(s -> s.readString(), s-> s.readString());
}

}

/**
* Creates a new UnloadNodeResponse object and read the stats from an input stream
* Creates a new MLDeployModelNodeResponse object and read the stats from an input stream
*
* @param in StreamInput to read from
* @return LoadModelNodeResponse object corresponding to the input stream
* @return MLDeployModelNodeResponse object corresponding to the input stream
* @throws IOException throws an IO exception if the StreamInput cannot be read from
*/
public static LoadModelNodeResponse readStats(StreamInput in) throws IOException {
return new LoadModelNodeResponse(in);
public static MLDeployModelNodeResponse readStats(StreamInput in) throws IOException {
return new MLDeployModelNodeResponse(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);

if (modelLoadStatus != null && modelLoadStatus.size() > 0) {
if (modelDeployStatus != null && modelDeployStatus.size() > 0) {
out.writeBoolean(true);
out.writeMap(modelLoadStatus, (stream, v) -> stream.writeString(v), (stream, stats) -> stream.writeString(stats));
out.writeMap(modelDeployStatus, (stream, v) -> stream.writeString(v), (stream, stats) -> stream.writeString(stats));
} else {
out.writeBoolean(false);
}
}

public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("stats");
if (modelLoadStatus != null && modelLoadStatus.size() > 0) {
for (Map.Entry<String, String> stat : modelLoadStatus.entrySet()) {
if (modelDeployStatus != null && modelDeployStatus.size() > 0) {
for (Map.Entry<String, String> stat : modelDeployStatus.entrySet()) {
builder.field(stat.getKey(), stat.getValue());
}
}
Expand Down
Loading