-
Notifications
You must be signed in to change notification settings - Fork 25.2k
HLRC: ML Delete job from calendar #35713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
benwtrent
merged 2 commits into
elastic:master
from
benwtrent:feature/hlrc-ml-delete-job-from-calendar
Nov 20, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Maybe use Calendar.ID here?