forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HLRC: Delete ML calendar (elastic#33775)
- Loading branch information
Showing
9 changed files
with
296 additions
and
0 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
65 changes: 65 additions & 0 deletions
65
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/DeleteCalendarRequest.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 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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 org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Request to delete a Machine Learning Calendar | ||
*/ | ||
public class DeleteCalendarRequest extends ActionRequest { | ||
|
||
private final String calendarId; | ||
|
||
/** | ||
* The constructor requires a single calendar id. | ||
* @param calendarId The calendar to delete. Must be {@code non-null} | ||
*/ | ||
public DeleteCalendarRequest(String calendarId) { | ||
this.calendarId = Objects.requireNonNull(calendarId, "[calendar_id] must not be null"); | ||
} | ||
|
||
public String getCalendarId() { | ||
return calendarId; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(calendarId); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
DeleteCalendarRequest other = (DeleteCalendarRequest) obj; | ||
return Objects.equals(calendarId, other.calendarId); | ||
} | ||
} |
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
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
43 changes: 43 additions & 0 deletions
43
...rest-high-level/src/test/java/org/elasticsearch/client/ml/DeleteCalendarRequestTests.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,43 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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 org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
|
||
public class DeleteCalendarRequestTests extends ESTestCase { | ||
|
||
public void testWithNullId() { | ||
NullPointerException ex = expectThrows(NullPointerException.class, () -> new DeleteCalendarRequest(null)); | ||
assertEquals("[calendar_id] must not be null", ex.getMessage()); | ||
} | ||
|
||
public void testEqualsAndHash() { | ||
String id1 = randomAlphaOfLength(8); | ||
String id2 = id1 + "_a"; | ||
assertThat(new DeleteCalendarRequest(id1), equalTo(new DeleteCalendarRequest(id1))); | ||
assertThat(new DeleteCalendarRequest(id1).hashCode(), equalTo(new DeleteCalendarRequest(id1).hashCode())); | ||
assertThat(new DeleteCalendarRequest(id1), not(equalTo(new DeleteCalendarRequest(id2)))); | ||
assertThat(new DeleteCalendarRequest(id1).hashCode(), not(equalTo(new DeleteCalendarRequest(id2).hashCode()))); | ||
} | ||
} |
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,59 @@ | ||
[[java-rest-high-x-pack-ml-delete-calendar]] | ||
=== Delete Calendar API | ||
Delete a {ml} calendar. | ||
The API accepts a `DeleteCalendarRequest` and responds | ||
with a `AcknowledgedResponse` object. | ||
|
||
[[java-rest-high-x-pack-ml-delete-calendar-request]] | ||
==== Delete Calendar Request | ||
|
||
A `DeleteCalendar` object requires a non-null `calendarId`. | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
--------------------------------------------------- | ||
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-delete-calendar-request] | ||
--------------------------------------------------- | ||
<1> Constructing a new request referencing an existing Calendar | ||
|
||
[[java-rest-high-x-pack-ml-delete-calendar-response]] | ||
==== Delete Calendar Response | ||
|
||
The returned `AcknowledgedResponse` object indicates the acknowledgement of the request: | ||
["source","java",subs="attributes,callouts,macros"] | ||
--------------------------------------------------- | ||
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-delete-calendar-response] | ||
--------------------------------------------------- | ||
<1> `isAcknowledged` was the deletion request acknowledged or not | ||
|
||
[[java-rest-high-x-pack-ml-delete-calendar-execution]] | ||
==== Execution | ||
The request can be executed through the `MachineLearningClient` contained | ||
in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method. | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-delete-calendar-execute] | ||
-------------------------------------------------- | ||
|
||
[[java-rest-high-x-pack-ml-delete-calendar-async]] | ||
==== Delete Calendar Asynchronously | ||
|
||
This request can also be made asynchronously. | ||
["source","java",subs="attributes,callouts,macros"] | ||
--------------------------------------------------- | ||
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-delete-calendar-execute-async] | ||
--------------------------------------------------- | ||
<1> The `DeleteCalendarRequest` to execute and the `ActionListener` to alert on completion or error. | ||
|
||
The deletion request returns immediately. Once the request is completed, the `ActionListener` is | ||
called back using the `onResponse` or `onFailure`. The latter indicates some failure occurred when | ||
making the request. | ||
|
||
A typical listener for a `DeleteCalendarRequest` could be defined as follows: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
--------------------------------------------------- | ||
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-delete-calendar-listener] | ||
--------------------------------------------------- | ||
<1> The action to be taken when it is completed | ||
<2> What to do when a failure occurs |
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