diff --git a/src/main/java/org/opensearch/ad/AnomalyDetectorExtension.java b/src/main/java/org/opensearch/ad/AnomalyDetectorExtension.java index bd2acbc8d..633bcd381 100644 --- a/src/main/java/org/opensearch/ad/AnomalyDetectorExtension.java +++ b/src/main/java/org/opensearch/ad/AnomalyDetectorExtension.java @@ -21,6 +21,7 @@ import org.opensearch.ad.model.DetectorInternalState; import org.opensearch.ad.rest.RestCreateDetectorAction; import org.opensearch.ad.rest.RestGetDetectorAction; +import org.opensearch.ad.rest.RestValidateDetectorAction; import org.opensearch.ad.settings.AnomalyDetectorSettings; import org.opensearch.ad.settings.EnabledSetting; import org.opensearch.client.opensearch.OpenSearchClient; @@ -43,7 +44,7 @@ public AnomalyDetectorExtension() { @Override public List getExtensionRestHandlers() { - return List.of(new RestCreateDetectorAction(extensionsRunner, this), new RestGetDetectorAction()); + return List.of(new RestCreateDetectorAction(extensionsRunner, this), new RestGetDetectorAction(), new RestValidateDetectorAction()); } @Override diff --git a/src/main/java/org/opensearch/ad/rest/RestValidateDetectorAction.java b/src/main/java/org/opensearch/ad/rest/RestValidateDetectorAction.java new file mode 100644 index 000000000..611333ed2 --- /dev/null +++ b/src/main/java/org/opensearch/ad/rest/RestValidateDetectorAction.java @@ -0,0 +1,44 @@ +package org.opensearch.ad.rest; + +import static org.opensearch.rest.RestRequest.Method.POST; +import static org.opensearch.rest.RestStatus.NOT_FOUND; +import static org.opensearch.rest.RestStatus.OK; + +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.ad.constant.CommonErrorMessages; +import org.opensearch.ad.settings.EnabledSetting; +import org.opensearch.extensions.rest.ExtensionRestRequest; +import org.opensearch.extensions.rest.ExtensionRestResponse; +import org.opensearch.rest.RestHandler.Route; +import org.opensearch.rest.RestRequest.Method; +import org.opensearch.sdk.ExtensionRestHandler; + +public class RestValidateDetectorAction implements ExtensionRestHandler { + private final Logger logger = LogManager.getLogger(RestValidateDetectorAction.class); + + @Override + public List routes() { + return List.of(new Route(POST, "/detectors/_validate"), new Route(POST, "/detectors/_validate/{type}")); + } + + @Override + public ExtensionRestResponse handleRequest(ExtensionRestRequest request) { + if (!EnabledSetting.isADPluginEnabled()) { + throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG); + } + Method method = request.method(); + + if (!Method.POST.equals(method)) { + return new ExtensionRestResponse( + request, + NOT_FOUND, + "Extension REST action improperly configured to handle " + request.toString() + ); + } + // do things with request + return new ExtensionRestResponse(request, OK, "placeholder"); + } +}