-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HLRC: ML Delete job from calendar (#35713)
- Loading branch information
Showing
9 changed files
with
315 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
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
88 changes: 88 additions & 0 deletions
88
...t/rest-high-level/src/main/java/org/elasticsearch/client/ml/DeleteCalendarJobRequest.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,88 @@ | ||
/* | ||
* 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.security.InvalidParameterException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Request class for removing Machine Learning Jobs from an existing calendar | ||
*/ | ||
public class DeleteCalendarJobRequest extends ActionRequest { | ||
|
||
private final List<String> jobIds; | ||
private final String calendarId; | ||
|
||
/** | ||
* Create a new request referencing an existing Calendar and which JobIds to remove | ||
* from it. | ||
* | ||
* @param calendarId The non-null ID of the calendar | ||
* @param jobIds JobIds to remove from the calendar, cannot be empty, or contain null values. | ||
* It can be a list of jobs or groups. | ||
*/ | ||
public DeleteCalendarJobRequest(String calendarId, String... jobIds) { | ||
this.calendarId = Objects.requireNonNull(calendarId, "[calendar_id] must not be null."); | ||
if (jobIds.length == 0) { | ||
throw new InvalidParameterException("jobIds must not be empty."); | ||
} | ||
if (Arrays.stream(jobIds).anyMatch(Objects::isNull)) { | ||
throw new NullPointerException("jobIds must not contain null values."); | ||
} | ||
this.jobIds = Arrays.asList(jobIds); | ||
} | ||
|
||
public List<String> getJobIds() { | ||
return jobIds; | ||
} | ||
|
||
public String getCalendarId() { | ||
return calendarId; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobIds, calendarId); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
DeleteCalendarJobRequest that = (DeleteCalendarJobRequest) other; | ||
return Objects.equals(jobIds, that.jobIds) && | ||
Objects.equals(calendarId, that.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
...t-high-level/src/test/java/org/elasticsearch/client/ml/DeleteCalendarJobRequestTests.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; | ||
|
||
public class DeleteCalendarJobRequestTests extends ESTestCase { | ||
|
||
public void testWithNullId() { | ||
NullPointerException ex = expectThrows(NullPointerException.class, | ||
() -> new DeleteCalendarJobRequest(null, "job1")); | ||
assertEquals("[calendar_id] must not be null.", ex.getMessage()); | ||
} | ||
|
||
public void testSetJobIds() { | ||
String calendarId = randomAlphaOfLength(10); | ||
|
||
NullPointerException ex = expectThrows(NullPointerException.class, | ||
() ->new DeleteCalendarJobRequest(calendarId, "job1", null)); | ||
assertEquals("jobIds must not contain null values.", ex.getMessage()); | ||
|
||
IllegalArgumentException illegalArgumentException = | ||
expectThrows(IllegalArgumentException.class, () -> new DeleteCalendarJobRequest(calendarId)); | ||
assertEquals("jobIds must not be empty.", illegalArgumentException.getMessage()); | ||
} | ||
} |
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,36 @@ | ||
-- | ||
:api: delete-calendar-job | ||
:request: DeleteCalendarJobRequest | ||
:response: PutCalendarResponse | ||
-- | ||
[id="{upid}-{api}"] | ||
=== Delete Calendar Job API | ||
Removes {ml} jobs from an existing {ml} calendar. | ||
The API accepts a +{request}+ and responds | ||
with a +{response}+ object. | ||
|
||
[id="{upid}-{api}-request"] | ||
==== Delete Calendar Job Request | ||
|
||
A +{request}+ is constructed referencing a non-null | ||
calendar ID, and JobIDs which to remove from the calendar | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests-file}[{api}-request] | ||
-------------------------------------------------- | ||
<1> The ID of the calendar from which to remove the jobs | ||
<2> The JobIds to remove from the calendar | ||
|
||
[id="{upid}-{api}-response"] | ||
==== Delete Calendar Response | ||
|
||
The returned +{response}+ contains the updated Calendar: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests-file}[{api}-response] | ||
-------------------------------------------------- | ||
<1> The updated Calendar with the jobs removed | ||
|
||
include::../execution.asciidoc[] |
Oops, something went wrong.