-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature/extensions] Add Action for Validate detector API call (#732)
* add validate rest handler Signed-off-by: Frank Lou <[email protected]> * add another new router Signed-off-by: Frank Lou <[email protected]> * add one more route Signed-off-by: Frank Lou <[email protected]> * change route Signed-off-by: Frank Lou <[email protected]> * change route path Signed-off-by: Frank Lou <[email protected]> * change route path Signed-off-by: Frank Lou <[email protected]> * change route path Signed-off-by: Frank Lou <[email protected]> * change route path Signed-off-by: Frank Lou <[email protected]> Signed-off-by: Frank Lou <[email protected]> Co-authored-by: Daniel Widdis <[email protected]>
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
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
44 changes: 44 additions & 0 deletions
44
src/main/java/org/opensearch/ad/rest/RestValidateDetectorAction.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,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<Route> 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"); | ||
} | ||
} |