-
Notifications
You must be signed in to change notification settings - Fork 37
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
[feature/agent_framework] Changing resources created format #231
Merged
amitgalitz
merged 5 commits into
opensearch-project:feature/agent_framework
from
amitgalitz:resoure-changes-feature
Dec 1, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8a6c2c
adding new resources created format and adding enum for resource types
amitgalitz e7186e1
remove spotless from java 17
amitgalitz 72122e1
add action listener to update resource created
amitgalitz 97b3aaf
fixing UT
amitgalitz adac953
changed exception type
amitgalitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/org/opensearch/flowframework/common/WorkflowResources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.common; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.flowframework.exception.FlowFrameworkException; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Enum encapsulating the different step names and the resources they create | ||
*/ | ||
public enum WorkflowResources { | ||
|
||
/** official workflow step name for creating a connector and associated created resource */ | ||
CREATE_CONNECTOR("create_connector", "connector_id"), | ||
/** official workflow step name for registering a remote model and associated created resource */ | ||
REGISTER_REMOTE_MODEL("register_remote_model", "model_id"), | ||
/** official workflow step name for registering a local model and associated created resource */ | ||
REGISTER_LOCAL_MODEL("register_local_model", "model_id"), | ||
/** official workflow step name for registering a model group and associated created resource */ | ||
REGISTER_MODEL_GROUP("register_model_group", "model_group_id"), | ||
/** official workflow step name for creating an ingest-pipeline and associated created resource */ | ||
CREATE_INGEST_PIPELINE("create_ingest_pipeline", "pipeline_id"), | ||
/** official workflow step name for creating an index and associated created resource */ | ||
CREATE_INDEX("create_index", "index_name"); | ||
|
||
private final String workflowStep; | ||
private final String resourceCreated; | ||
private static final Logger logger = LogManager.getLogger(WorkflowResources.class); | ||
private static final Set<String> allResources = Stream.of(values()) | ||
.map(WorkflowResources::getResourceCreated) | ||
.collect(Collectors.toSet()); | ||
|
||
WorkflowResources(String workflowStep, String resourceCreated) { | ||
this.workflowStep = workflowStep; | ||
this.resourceCreated = resourceCreated; | ||
} | ||
|
||
/** | ||
* Returns the workflowStep for the given enum Constant | ||
* @return the workflowStep of this data. | ||
*/ | ||
public String getWorkflowStep() { | ||
return workflowStep; | ||
} | ||
|
||
/** | ||
* Returns the resourceCreated for the given enum Constant | ||
* @return the resourceCreated of this data. | ||
*/ | ||
public String getResourceCreated() { | ||
return resourceCreated; | ||
} | ||
|
||
/** | ||
* gets the resources created type based on the workflowStep | ||
* @param workflowStep workflow step name | ||
* @return the resource that will be created | ||
* @throws FlowFrameworkException if workflow step doesn't exist in enum | ||
*/ | ||
public static String getResourceByWorkflowStep(String workflowStep) throws FlowFrameworkException { | ||
if (workflowStep != null && !workflowStep.isEmpty()) { | ||
for (WorkflowResources mapping : values()) { | ||
if (mapping.getWorkflowStep().equals(workflowStep)) { | ||
return mapping.getResourceCreated(); | ||
} | ||
} | ||
} | ||
logger.error("Unable to find resource type for step: " + workflowStep); | ||
throw new FlowFrameworkException("Unable to find resource type for step: " + workflowStep, RestStatus.BAD_REQUEST); | ||
} | ||
|
||
/** | ||
* Returns all the possible resource created types in enum | ||
* @return a set of all the resource created types | ||
*/ | ||
public static Set<String> getAllResourcesCreated() { | ||
return allResources; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we keep the resource type together with its ID? In order to know the meaning of the resource ID here I need to know its step. This way forces me to look it up from the enum (assuming a 1:1 mapping which I'm not sure of).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by resource type here? the field of
connector_id
will be the key here forresourceId
. Since we wanted to have a dynamic key it means it could be anything so I label it as resourceId here