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.
[ML] Data Frame HLRC start & stop APIs (elastic#40154)
- Loading branch information
Showing
18 changed files
with
1,067 additions
and
4 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
99 changes: 99 additions & 0 deletions
99
...est-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedTasksResponse.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,99 @@ | ||
/* | ||
* 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.core; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.TaskOperationFailure; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.TriFunction; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; | ||
|
||
public class AcknowledgedTasksResponse { | ||
|
||
protected static final ParseField TASK_FAILURES = new ParseField("task_failures"); | ||
protected static final ParseField NODE_FAILURES = new ParseField("node_failures"); | ||
|
||
@SuppressWarnings("unchecked") | ||
protected static <T extends AcknowledgedTasksResponse> ConstructingObjectParser<T, Void> generateParser( | ||
String name, | ||
TriFunction<Boolean, List<TaskOperationFailure>, List<? extends ElasticsearchException>, T> ctor, | ||
String ackFieldName) { | ||
|
||
ConstructingObjectParser<T, Void> parser = new ConstructingObjectParser<>(name, true, | ||
args -> ctor.apply((boolean) args[0], (List<TaskOperationFailure>) args[1], (List<ElasticsearchException>) args[2])); | ||
parser.declareBoolean(constructorArg(), new ParseField(ackFieldName)); | ||
parser.declareObjectArray(optionalConstructorArg(), (p, c) -> TaskOperationFailure.fromXContent(p), TASK_FAILURES); | ||
parser.declareObjectArray(optionalConstructorArg(), (p, c) -> ElasticsearchException.fromXContent(p), NODE_FAILURES); | ||
return parser; | ||
} | ||
|
||
private boolean acknowledged; | ||
private List<TaskOperationFailure> taskFailures; | ||
private List<ElasticsearchException> nodeFailures; | ||
|
||
public AcknowledgedTasksResponse(boolean acknowledged, @Nullable List<TaskOperationFailure> taskFailures, | ||
@Nullable List<? extends ElasticsearchException> nodeFailures) { | ||
this.acknowledged = acknowledged; | ||
this.taskFailures = taskFailures == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(taskFailures)); | ||
this.nodeFailures = nodeFailures == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(nodeFailures)); | ||
} | ||
|
||
public boolean isAcknowledged() { | ||
return acknowledged; | ||
} | ||
|
||
public List<TaskOperationFailure> getTaskFailures() { | ||
return taskFailures; | ||
} | ||
|
||
public List<ElasticsearchException> getNodeFailures() { | ||
return nodeFailures; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
AcknowledgedTasksResponse other = (AcknowledgedTasksResponse) obj; | ||
return acknowledged == other.acknowledged | ||
&& taskFailures.equals(other.taskFailures) | ||
&& nodeFailures.equals(other.nodeFailures); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(acknowledged, taskFailures, nodeFailures); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...evel/src/main/java/org/elasticsearch/client/dataframe/StartDataFrameTransformRequest.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,84 @@ | ||
/* | ||
* 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.dataframe; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.client.ValidationException; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class StartDataFrameTransformRequest implements Validatable { | ||
|
||
private final String id; | ||
private TimeValue timeout; | ||
|
||
public StartDataFrameTransformRequest(String id) { | ||
this.id = id; | ||
} | ||
|
||
public StartDataFrameTransformRequest(String id, TimeValue timeout) { | ||
this.id = id; | ||
this.timeout = timeout; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public TimeValue getTimeout() { | ||
return timeout; | ||
} | ||
|
||
public void setTimeout(TimeValue timeout) { | ||
this.timeout = timeout; | ||
} | ||
|
||
@Override | ||
public Optional<ValidationException> validate() { | ||
if (id == null) { | ||
ValidationException validationException = new ValidationException(); | ||
validationException.addValidationError("data frame transform id must not be null"); | ||
return Optional.of(validationException); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, timeout); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
StartDataFrameTransformRequest other = (StartDataFrameTransformRequest) obj; | ||
return Objects.equals(this.id, other.id) | ||
&& Objects.equals(this.timeout, other.timeout); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...vel/src/main/java/org/elasticsearch/client/dataframe/StartDataFrameTransformResponse.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,51 @@ | ||
/* | ||
* 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.dataframe; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.TaskOperationFailure; | ||
import org.elasticsearch.client.core.AcknowledgedTasksResponse; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class StartDataFrameTransformResponse extends AcknowledgedTasksResponse { | ||
|
||
private static final String STARTED = "started"; | ||
|
||
private static final ConstructingObjectParser<StartDataFrameTransformResponse, Void> PARSER = | ||
AcknowledgedTasksResponse.generateParser("start_data_frame_transform_response", StartDataFrameTransformResponse::new, STARTED); | ||
|
||
public static StartDataFrameTransformResponse fromXContent(final XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
public StartDataFrameTransformResponse(boolean started, @Nullable List<TaskOperationFailure> taskFailures, | ||
@Nullable List<? extends ElasticsearchException> nodeFailures) { | ||
super(started, taskFailures, nodeFailures); | ||
} | ||
|
||
public boolean isStarted() { | ||
return isAcknowledged(); | ||
} | ||
} |
Oops, something went wrong.