Skip to content

Commit 81c2643

Browse files
authored
Refactor DeployModel and RegisterRemoteModel steps to use const (#1306)
Refactor to const DeployModel & RegisterRemoteModel Steps Signed-off-by: kokibas <[email protected]>
1 parent 1687540 commit 81c2643

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

src/main/java/org/opensearch/flowframework/workflow/DeployModelStep.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public class DeployModelStep extends AbstractRetryableWorkflowStep {
4141

4242
/** The name of this step, used as a key in the template and the {@link WorkflowStepFactory} */
4343
public static final String NAME = "deploy_model";
44+
/** Required input keys **/
45+
public static final Set<String> REQUIRED_INPUTS = Set.of(MODEL_ID);
46+
/** Optional input keys */
47+
public static final Set<String> OPTIONAL_INPUTS = Collections.emptySet();
48+
/** Provided output keys */
49+
public static final Set<String> PROVIDED_OUTPUTS = Set.of(MODEL_ID);
4450

4551
/**
4652
* Instantiate this class
@@ -71,13 +77,10 @@ public PlainActionFuture<WorkflowData> execute(
7177

7278
PlainActionFuture<WorkflowData> deployModelFuture = PlainActionFuture.newFuture();
7379

74-
Set<String> requiredKeys = Set.of(MODEL_ID);
75-
Set<String> optionalKeys = Collections.emptySet();
76-
7780
try {
7881
Map<String, Object> inputs = ParseUtils.getInputsFromPreviousSteps(
79-
requiredKeys,
80-
optionalKeys,
82+
REQUIRED_INPUTS,
83+
OPTIONAL_INPUTS,
8184
currentNodeInputs,
8285
outputs,
8386
previousNodeInputs,

src/main/java/org/opensearch/flowframework/workflow/RegisterRemoteModelStep.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import static org.opensearch.flowframework.common.CommonValue.REGISTER_MODEL_STATUS;
4242
import static org.opensearch.flowframework.common.WorkflowResources.CONNECTOR_ID;
4343
import static org.opensearch.flowframework.common.WorkflowResources.MODEL_GROUP_ID;
44+
import static org.opensearch.flowframework.common.WorkflowResources.MODEL_ID;
4445
import static org.opensearch.flowframework.common.WorkflowResources.getResourceByWorkflowStep;
4546
import static org.opensearch.flowframework.exception.WorkflowStepException.getSafeException;
4647

@@ -57,6 +58,18 @@ public class RegisterRemoteModelStep implements WorkflowStep {
5758

5859
/** The name of this step, used as a key in the template and the {@link WorkflowStepFactory} */
5960
public static final String NAME = "register_remote_model";
61+
/** Required input keys **/
62+
public static final Set<String> REQUIRED_INPUTS = Set.of(NAME_FIELD, CONNECTOR_ID);
63+
/** Optional input keys */
64+
public static final Set<String> OPTIONAL_INPUTS = Set.of(
65+
MODEL_GROUP_ID,
66+
DESCRIPTION_FIELD,
67+
DEPLOY_FIELD,
68+
GUARDRAILS_FIELD,
69+
INTERFACE_FIELD
70+
);
71+
/** Provided output keys */
72+
public static final Set<String> PROVIDED_OUTPUTS = Set.of(MODEL_ID, REGISTER_MODEL_STATUS);
6073

6174
/**
6275
* Instantiate this class
@@ -80,13 +93,10 @@ public PlainActionFuture<WorkflowData> execute(
8093

8194
PlainActionFuture<WorkflowData> registerRemoteModelFuture = PlainActionFuture.newFuture();
8295

83-
Set<String> requiredKeys = Set.of(NAME_FIELD, CONNECTOR_ID);
84-
Set<String> optionalKeys = Set.of(MODEL_GROUP_ID, DESCRIPTION_FIELD, DEPLOY_FIELD, GUARDRAILS_FIELD, INTERFACE_FIELD);
85-
8696
try {
8797
Map<String, Object> inputs = ParseUtils.getInputsFromPreviousSteps(
88-
requiredKeys,
89-
optionalKeys,
98+
REQUIRED_INPUTS,
99+
OPTIONAL_INPUTS,
90100
currentNodeInputs,
91101
outputs,
92102
previousNodeInputs,

src/main/java/org/opensearch/flowframework/workflow/WorkflowStepFactory.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ public enum WorkflowSteps {
198198
/** Register Remote Model Step */
199199
REGISTER_REMOTE_MODEL(
200200
RegisterRemoteModelStep.NAME,
201-
List.of(NAME_FIELD, CONNECTOR_ID),
202-
List.of(MODEL_ID, REGISTER_MODEL_STATUS),
201+
RegisterRemoteModelStep.REQUIRED_INPUTS,
202+
RegisterRemoteModelStep.PROVIDED_OUTPUTS,
203203
List.of(OPENSEARCH_ML),
204204
null
205205
),
@@ -214,7 +214,13 @@ public enum WorkflowSteps {
214214
),
215215

216216
/** Deploy Model Step */
217-
DEPLOY_MODEL(DeployModelStep.NAME, List.of(MODEL_ID), List.of(MODEL_ID), List.of(OPENSEARCH_ML), TimeValue.timeValueSeconds(15)),
217+
DEPLOY_MODEL(
218+
DeployModelStep.NAME,
219+
DeployModelStep.REQUIRED_INPUTS,
220+
DeployModelStep.PROVIDED_OUTPUTS,
221+
List.of(OPENSEARCH_ML),
222+
TimeValue.timeValueSeconds(15)
223+
),
218224

219225
/** Undeploy Model Step */
220226
UNDEPLOY_MODEL(UndeployModelStep.NAME, List.of(MODEL_ID), List.of(SUCCESS), List.of(OPENSEARCH_ML), null),

src/test/java/org/opensearch/flowframework/model/WorkflowStepValidatorTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.opensearch.flowframework.workflow.CreateConnectorStep;
1212
import org.opensearch.flowframework.workflow.CreateIndexStep;
1313
import org.opensearch.flowframework.workflow.DeleteIndexStep;
14+
import org.opensearch.flowframework.workflow.DeployModelStep;
15+
import org.opensearch.flowframework.workflow.RegisterRemoteModelStep;
1416
import org.opensearch.flowframework.workflow.WorkflowStepFactory;
1517
import org.opensearch.test.OpenSearchTestCase;
1618

@@ -71,4 +73,22 @@ public void testCreateIndexStepValidator() throws IOException {
7173
);
7274
}
7375

76+
public void testDeployModelStepValidator() throws IOException {
77+
assertStepValidatorMatches(
78+
WorkflowStepFactory.WorkflowSteps.DEPLOY_MODEL,
79+
DeployModelStep.NAME,
80+
DeployModelStep.REQUIRED_INPUTS,
81+
DeployModelStep.PROVIDED_OUTPUTS
82+
);
83+
}
84+
85+
public void testRegisterRemoteModelStepValidator() throws IOException {
86+
assertStepValidatorMatches(
87+
WorkflowStepFactory.WorkflowSteps.REGISTER_REMOTE_MODEL,
88+
RegisterRemoteModelStep.NAME,
89+
RegisterRemoteModelStep.REQUIRED_INPUTS,
90+
RegisterRemoteModelStep.PROVIDED_OUTPUTS
91+
);
92+
}
93+
7494
}

0 commit comments

Comments
 (0)