-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xun Zhang <[email protected]>
- Loading branch information
1 parent
cb4c209
commit 50ca665
Showing
13 changed files
with
984 additions
and
3 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
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
67 changes: 67 additions & 0 deletions
67
plugin/src/main/java/org/opensearch/ml/rest/RestMLCreateConnectorAction.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,67 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.rest; | ||
|
||
import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
import static org.opensearch.ml.plugin.MachineLearningPlugin.ML_BASE_URI; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.ml.common.transport.connector.MLCreateConnectorAction; | ||
import org.opensearch.ml.common.transport.connector.MLCreateConnectorInput; | ||
import org.opensearch.ml.common.transport.connector.MLCreateConnectorRequest; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.action.RestToXContentListener; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
public class RestMLCreateConnectorAction extends BaseRestHandler { | ||
private static final String ML_CREATE_CONNECTOR_ACTION = "ml_create_connector_action"; | ||
|
||
/** | ||
* Constructor * | ||
*/ | ||
public RestMLCreateConnectorAction() {} | ||
|
||
@Override | ||
public String getName() { | ||
return ML_CREATE_CONNECTOR_ACTION; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return ImmutableList.of(new Route(RestRequest.Method.POST, String.format(Locale.ROOT, "%s/connectors/_create", ML_BASE_URI))); | ||
} | ||
|
||
@Override | ||
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
MLCreateConnectorRequest mlCreateConnectorRequest = getRequest(request); | ||
return channel -> client.execute(MLCreateConnectorAction.INSTANCE, mlCreateConnectorRequest, new RestToXContentListener<>(channel)); | ||
} | ||
|
||
/** | ||
* * Creates a MLCreateConnectorRequest from a RestRequest | ||
* @param request | ||
* @return MLCreateConnectorRequest | ||
* @throws IOException | ||
*/ | ||
@VisibleForTesting | ||
MLCreateConnectorRequest getRequest(RestRequest request) throws IOException { | ||
if (!request.hasContent()) { | ||
throw new IOException("Create Connector request has empty body"); | ||
} | ||
XContentParser parser = request.contentParser(); | ||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); | ||
MLCreateConnectorInput mlCreateConnectorInput = MLCreateConnectorInput.parse(parser); | ||
return new MLCreateConnectorRequest(mlCreateConnectorInput); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
plugin/src/main/java/org/opensearch/ml/rest/RestMLDeleteConnectorAction.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,53 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.rest; | ||
|
||
import static org.opensearch.ml.plugin.MachineLearningPlugin.ML_BASE_URI; | ||
import static org.opensearch.ml.utils.RestActionUtils.PARAMETER_CONNECTOR_ID; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.ml.common.transport.connector.MLConnectorDeleteAction; | ||
import org.opensearch.ml.common.transport.connector.MLConnectorDeleteRequest; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.action.RestToXContentListener; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
/** | ||
* This class consists of the REST handler to delete ML Connector. | ||
*/ | ||
public class RestMLDeleteConnectorAction extends BaseRestHandler { | ||
private static final String ML_DELETE_CONNECTOR_ACTION = "ml_delete_connector_action"; | ||
|
||
public void RestMLDeleteConnectorAction() {} | ||
|
||
@Override | ||
public String getName() { | ||
return ML_DELETE_CONNECTOR_ACTION; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return ImmutableList | ||
.of( | ||
new Route(RestRequest.Method.DELETE, String.format(Locale.ROOT, "%s/connectors/{%s}", ML_BASE_URI, PARAMETER_CONNECTOR_ID)) | ||
); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
String connectorId = request.param(PARAMETER_CONNECTOR_ID); | ||
|
||
MLConnectorDeleteRequest mlConnectorDeleteRequest = new MLConnectorDeleteRequest(connectorId); | ||
return channel -> client.execute(MLConnectorDeleteAction.INSTANCE, mlConnectorDeleteRequest, new RestToXContentListener<>(channel)); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
plugin/src/main/java/org/opensearch/ml/rest/RestMLGetConnectorAction.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,65 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.rest; | ||
|
||
import static org.opensearch.ml.plugin.MachineLearningPlugin.ML_BASE_URI; | ||
import static org.opensearch.ml.utils.RestActionUtils.PARAMETER_CONNECTOR_ID; | ||
import static org.opensearch.ml.utils.RestActionUtils.getParameterId; | ||
import static org.opensearch.ml.utils.RestActionUtils.returnContent; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.ml.common.transport.connector.MLConnectorGetAction; | ||
import org.opensearch.ml.common.transport.connector.MLConnectorGetRequest; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.action.RestToXContentListener; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
public class RestMLGetConnectorAction extends BaseRestHandler { | ||
private static final String ML_GET_CONNECTOR_ACTION = "ml_get_connector_action"; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public RestMLGetConnectorAction() {} | ||
|
||
@Override | ||
public String getName() { | ||
return ML_GET_CONNECTOR_ACTION; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return ImmutableList | ||
.of(new Route(RestRequest.Method.GET, String.format(Locale.ROOT, "%s/connectors/{%s}", ML_BASE_URI, PARAMETER_CONNECTOR_ID))); | ||
} | ||
|
||
@Override | ||
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
MLConnectorGetRequest mlConnectorGetRequest = getRequest(request); | ||
return channel -> client.execute(MLConnectorGetAction.INSTANCE, mlConnectorGetRequest, new RestToXContentListener<>(channel)); | ||
} | ||
|
||
/** | ||
* Creates a MLConnectorGetRequest from a RestRequest | ||
* | ||
* @param request RestRequest | ||
* @return MLConnectorGetRequest | ||
*/ | ||
@VisibleForTesting | ||
MLConnectorGetRequest getRequest(RestRequest request) throws IOException { | ||
String connectorId = getParameterId(request, PARAMETER_CONNECTOR_ID); | ||
boolean returnContent = returnContent(request); | ||
|
||
return new MLConnectorGetRequest(connectorId, returnContent); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
plugin/src/main/java/org/opensearch/ml/rest/RestMLSearchConnectorAction.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 | ||
*/ | ||
|
||
package org.opensearch.ml.rest; | ||
|
||
import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX; | ||
import static org.opensearch.ml.plugin.MachineLearningPlugin.ML_BASE_URI; | ||
|
||
import org.opensearch.ml.common.connector.Connector; | ||
import org.opensearch.ml.common.transport.connector.MLConnectorSearchAction; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
public class RestMLSearchConnectorAction extends AbstractMLSearchAction<Connector> { | ||
private static final String ML_SEARCH_CONNECTOR_ACTION = "ml_search_connector_action"; | ||
private static final String SEARCH_CONNECTOR_PATH = ML_BASE_URI + "/connectors/_search"; | ||
|
||
public RestMLSearchConnectorAction() { | ||
super(ImmutableList.of(SEARCH_CONNECTOR_PATH), ML_CONNECTOR_INDEX, Connector.class, MLConnectorSearchAction.INSTANCE); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return ML_SEARCH_CONNECTOR_ACTION; | ||
} | ||
} |
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.