This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Adding new Search Detector Info API #286
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d8fcc08
Adding new Search Info API
saratvemulapalli 5703091
Adding Spotless changes
saratvemulapalli 6bee879
Merge branch 'master' of https://github.com/opendistro-for-elasticsea…
saratvemulapalli ed371e4
Merge branch 'master' into fgac-info-api
saratvemulapalli 9ce23c7
Rebasing changes and addressing comments
saratvemulapalli 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
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
79 changes: 79 additions & 0 deletions
79
...va/com/amazon/opendistroforelasticsearch/ad/rest/RestSearchAnomalyDetectorInfoAction.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 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.ad.rest; | ||
|
||
import static com.amazon.opendistroforelasticsearch.ad.util.RestHandlerUtils.COUNT; | ||
import static com.amazon.opendistroforelasticsearch.ad.util.RestHandlerUtils.MATCH; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
|
||
import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin; | ||
import com.amazon.opendistroforelasticsearch.ad.constant.CommonErrorMessages; | ||
import com.amazon.opendistroforelasticsearch.ad.settings.EnabledSetting; | ||
import com.amazon.opendistroforelasticsearch.ad.transport.SearchAnomalyDetectorInfoAction; | ||
import com.amazon.opendistroforelasticsearch.ad.transport.SearchAnomalyDetectorInfoRequest; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
public class RestSearchAnomalyDetectorInfoAction extends BaseRestHandler { | ||
|
||
public static final String SEARCH_ANOMALY_DETECTOR_INFO_ACTION = "search_anomaly_detector_info"; | ||
|
||
private static final Logger logger = LogManager.getLogger(RestSearchAnomalyDetectorInfoAction.class); | ||
|
||
public RestSearchAnomalyDetectorInfoAction() {} | ||
|
||
@Override | ||
public String getName() { | ||
return SEARCH_ANOMALY_DETECTOR_INFO_ACTION; | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, org.elasticsearch.client.node.NodeClient client) throws IOException { | ||
if (!EnabledSetting.isADPluginEnabled()) { | ||
throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG); | ||
} | ||
|
||
String detectorName = request.param("name", null); | ||
String rawPath = request.rawPath(); | ||
|
||
SearchAnomalyDetectorInfoRequest searchAnomalyDetectorInfoRequest = new SearchAnomalyDetectorInfoRequest(detectorName, rawPath); | ||
return channel -> client | ||
.execute(SearchAnomalyDetectorInfoAction.INSTANCE, searchAnomalyDetectorInfoRequest, new RestToXContentListener<>(channel)); | ||
} | ||
|
||
@Override | ||
public List<RestHandler.Route> routes() { | ||
return ImmutableList | ||
.of( | ||
// get the count of number of detectors | ||
new RestHandler.Route( | ||
RestRequest.Method.GET, | ||
String.format(Locale.ROOT, "%s/%s", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, COUNT) | ||
), | ||
// get if a detector name exists with name | ||
new RestHandler.Route(RestRequest.Method.GET, String.format("%s/%s", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, MATCH)) | ||
); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...a/com/amazon/opendistroforelasticsearch/ad/transport/SearchAnomalyDetectorInfoAction.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 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.ad.transport; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
|
||
public class SearchAnomalyDetectorInfoAction extends ActionType<SearchAnomalyDetectorInfoResponse> { | ||
public static final SearchAnomalyDetectorInfoAction INSTANCE = new SearchAnomalyDetectorInfoAction(); | ||
public static final String NAME = "cluster:admin/opendistro/ad/detector/info"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see PR #284 merged, change to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, will take care of it. |
||
|
||
private SearchAnomalyDetectorInfoAction() { | ||
super(NAME, SearchAnomalyDetectorInfoResponse::new); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
.../com/amazon/opendistroforelasticsearch/ad/transport/SearchAnomalyDetectorInfoRequest.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,61 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.ad.transport; | ||
|
||
import java.io.IOException; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
public class SearchAnomalyDetectorInfoRequest extends ActionRequest { | ||
|
||
private String name; | ||
private String rawPath; | ||
|
||
public SearchAnomalyDetectorInfoRequest(StreamInput in) throws IOException { | ||
super(in); | ||
name = in.readOptionalString(); | ||
rawPath = in.readString(); | ||
} | ||
|
||
public SearchAnomalyDetectorInfoRequest(String name, String rawPath) throws IOException { | ||
super(); | ||
this.name = name; | ||
this.rawPath = rawPath; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getRawPath() { | ||
return rawPath; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeOptionalString(name); | ||
out.writeString(rawPath); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...com/amazon/opendistroforelasticsearch/ad/transport/SearchAnomalyDetectorInfoResponse.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 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.ad.transport; | ||
|
||
import java.io.IOException; | ||
|
||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import com.amazon.opendistroforelasticsearch.ad.util.RestHandlerUtils; | ||
|
||
public class SearchAnomalyDetectorInfoResponse extends ActionResponse implements ToXContentObject { | ||
private long count; | ||
private boolean nameExists; | ||
|
||
public SearchAnomalyDetectorInfoResponse(StreamInput in) throws IOException { | ||
super(in); | ||
count = in.readLong(); | ||
nameExists = in.readBoolean(); | ||
} | ||
|
||
public SearchAnomalyDetectorInfoResponse(long count, boolean nameExists) { | ||
this.count = count; | ||
this.nameExists = nameExists; | ||
} | ||
|
||
public long getCount() { | ||
return count; | ||
} | ||
|
||
public boolean isNameExists() { | ||
return nameExists; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeLong(count); | ||
out.writeBoolean(nameExists); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(RestHandlerUtils.COUNT, count); | ||
builder.field(RestHandlerUtils.MATCH, nameExists); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
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.
I see you switched NAME and INSTANCE sequence in this PR #284 , why we need to do that? Should we do the same thing here?
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.
Sure makes sense.
I''ll rebase my changes and update it.
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.
I just saw the first part of the question, JVM is not smart enough, since INSTANCE depends on ACTION it must be defined first and if defined later string concat does not work. So I had to move it above.