-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial create ingest pipeline implementation
Signed-off-by: Joshua Palis <[email protected]>
- Loading branch information
Showing
8 changed files
with
244 additions
and
8 deletions.
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
42 changes: 42 additions & 0 deletions
42
src/main/java/org/opensearch/flowframework/workflow/CreateIngestPipelineRequestData.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,42 @@ | ||
/* | ||
* 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.workflow; | ||
|
||
import org.opensearch.action.ingest.PutPipelineRequest; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class CreateIngestPipelineRequestData implements WorkflowInputData { | ||
|
||
private Map<String, String> params = new HashMap<>(); | ||
private Map<String, Object> content = new HashMap<>(); | ||
|
||
public CreateIngestPipelineRequestData(PutPipelineRequest request) { | ||
super(); | ||
|
||
// RestPutPipelineAction params | ||
params.put("id", request.getId()); | ||
|
||
// PutPipelineRequest content | ||
content.put("source", request.getSource()); | ||
content.put("mediaType", request.getMediaType()); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getContent() { | ||
return Map.copyOf(content); | ||
} | ||
|
||
@Override | ||
public Map<String, String> getParams() { | ||
return Map.copyOf(params); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/opensearch/flowframework/workflow/CreateIngestPipelineResponseData.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,28 @@ | ||
/* | ||
* 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.workflow; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class CreateIngestPipelineResponseData implements WorkflowData { | ||
|
||
private Map<String, Object> content = new HashMap<>(); | ||
|
||
public CreateIngestPipelineResponseData(String ingestPipelineId) { | ||
super(); | ||
// PutPipelineAction returns only an acknodledged response, returning ingest pipeline id instead | ||
content.put("pipelineId", ingestPipelineId); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getContent() { | ||
return Map.copyOf(content); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/org/opensearch/flowframework/workflow/CreateIngestPipelineStep.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,79 @@ | ||
/* | ||
* 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.workflow; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.action.ingest.PutPipelineRequest; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.client.ClusterAdminClient; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.common.bytes.BytesReference; | ||
import org.opensearch.core.xcontent.MediaType; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Workflow step to create an ingest pipeline | ||
*/ | ||
public class CreateIngestPipelineStep implements WorkflowStep { | ||
|
||
private static final Logger logger = LogManager.getLogger(CreateIngestPipelineStep.class); | ||
private static final String NAME = "create_ingest_pipeline_step"; | ||
|
||
private final ClusterAdminClient clusterAdminClient; | ||
|
||
public CreateIngestPipelineStep(Client client) { | ||
this.clusterAdminClient = client.admin().cluster(); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<WorkflowData> execute(List<WorkflowData> data) { | ||
|
||
CompletableFuture<WorkflowData> createIngestPipelineFuture = new CompletableFuture<>(); | ||
PutPipelineRequest putPipelineRequest = null; | ||
|
||
// TODO : Still not clear if this is the correct way to retrieve data from the parsed use case tempalte | ||
for (WorkflowData workflowData : data) { | ||
if (workflowData instanceof WorkflowInputData) { | ||
|
||
WorkflowInputData inputData = (WorkflowInputData) workflowData; | ||
logger.debug("Previous step sent params: {}, content: {}", inputData.getParams(), workflowData.getContent()); | ||
|
||
// Extract params and content to create request | ||
String pipelineId = inputData.getParams().get("id"); | ||
BytesReference source = (BytesReference) inputData.getContent().get("source"); | ||
MediaType mediaType = (MediaType) inputData.getContent().get("mediaType"); | ||
putPipelineRequest = new PutPipelineRequest(pipelineId, source, mediaType); | ||
} | ||
} | ||
|
||
if (putPipelineRequest != null) { | ||
String pipelineId = putPipelineRequest.getId(); | ||
clusterAdminClient.putPipeline(putPipelineRequest, ActionListener.wrap(response -> { | ||
logger.info("Created pipeline : " + pipelineId); | ||
CreateIngestPipelineResponseData responseData = new CreateIngestPipelineResponseData(pipelineId); | ||
createIngestPipelineFuture.complete(responseData); | ||
}, exception -> { | ||
logger.error("Failed to create pipeline : " + exception.getMessage()); | ||
createIngestPipelineFuture.completeExceptionally(exception); | ||
})); | ||
} else { | ||
createIngestPipelineFuture.completeExceptionally(new Exception("Failed to create pipeline")); | ||
} | ||
return createIngestPipelineFuture; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/org/opensearch/flowframework/workflow/WorkflowInputData.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,24 @@ | ||
/* | ||
* 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.workflow; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Interface for handling the input of the building blocks. | ||
*/ | ||
public interface WorkflowInputData extends WorkflowData { | ||
|
||
/** | ||
* Accesses a map containing the params of this workflow step. This represents the params associated with a Rest API request, parsed from the URI. | ||
* @return the params of this step. | ||
*/ | ||
Map<String, String> getParams(); | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="INFO"> | ||
<Appenders> | ||
<Console name="ConsoleAppender" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level o.o.f.%logger{-3} - %msg%n" /> | ||
</Console> | ||
<File name="FileAppender" fileName="application-${date:yyyyMMdd}.log" immediateFlush="false" append="true"> | ||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> | ||
</File> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="debug"> | ||
<AppenderRef ref="ConsoleAppender" /> | ||
<AppenderRef ref="FileAppender"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |