Skip to content

Commit

Permalink
Merge branch 'master' into field_caps_with_objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Sep 19, 2018
2 parents b47d6a9 + c4261ba commit 3635231
Show file tree
Hide file tree
Showing 139 changed files with 4,327 additions and 838 deletions.
6 changes: 6 additions & 0 deletions buildSrc/src/main/resources/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@
-->
<module name="ModifierOrder" />

<!-- Checks that we don't include modifier where they are implied. For
example, this does not allow interface methods to be declared public
because they are *always* public. -->
<module name="RedundantModifier" />
<!-- Checks that all java files have a package declaration and that it
lines up with the directory structure. -->
<module name="PackageDeclaration"/>

<!-- We don't use Java's builtin serialization and we suppress all warning
about it. The flip side of that coin is that we shouldn't _try_ to use
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/resources/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<!-- the constructors on some local classes in these tests must be public-->
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]plugins[/\\]PluginsServiceTests.java" checks="RedundantModifier" />

<!-- Intentionally doesn't have a package declaration to test logging
configuration of classes that aren't in packages. -->
<suppress files="test[/\\]framework[/\\]src[/\\]test[/\\]java[/\\]Dummy.java" checks="PackageDeclaration" />

<!-- Hopefully temporary suppression of LineLength on files that don't pass it. We should remove these when we the
files start to pass. -->
<suppress files="client[/\\]rest[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]HeapBufferedAsyncResponseConsumerTests.java" checks="LineLength" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testJarHellDetected() {
assertTaskFailed(result, ":jarHell");
assertOutputContains(
result.getOutput(),
"Exception in thread \"main\" java.lang.IllegalStateException: jar hell!",
"java.lang.IllegalStateException: jar hell!",
"class: org.apache.logging.log4j.Logger"
);
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/version.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
elasticsearch = 7.0.0-alpha1
lucene = 8.0.0-snapshot-66c671ea80
lucene = 8.0.0-snapshot-7d0a7782fa

# optional dependencies
spatial4j = 0.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.elasticsearch.client.ml.FlushJobRequest;
import org.elasticsearch.client.ml.ForecastJobRequest;
import org.elasticsearch.client.ml.GetBucketsRequest;
import org.elasticsearch.client.ml.GetCalendarsRequest;
import org.elasticsearch.client.ml.GetCategoriesRequest;
import org.elasticsearch.client.ml.GetDatafeedRequest;
import org.elasticsearch.client.ml.GetInfluencersRequest;
Expand Down Expand Up @@ -229,7 +230,7 @@ static Request deleteDatafeed(DeleteDatafeedRequest deleteDatafeedRequest) {
return request;
}

static Request deleteForecast(DeleteForecastRequest deleteForecastRequest) throws IOException {
static Request deleteForecast(DeleteForecastRequest deleteForecastRequest) {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("ml")
Expand Down Expand Up @@ -305,7 +306,7 @@ static Request getRecords(GetRecordsRequest getRecordsRequest) throws IOExceptio
return request;
}

static Request postData(PostDataRequest postDataRequest) throws IOException {
static Request postData(PostDataRequest postDataRequest) {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("ml")
Expand Down Expand Up @@ -359,4 +360,16 @@ static Request putCalendar(PutCalendarRequest putCalendarRequest) throws IOExcep
request.setEntity(createEntity(putCalendarRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request getCalendars(GetCalendarsRequest getCalendarsRequest) throws IOException {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("ml")
.addPathPartAsIs("calendars")
.addPathPart(getCalendarsRequest.getCalendarId())
.build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
request.setEntity(createEntity(getCalendarsRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.elasticsearch.client.ml.ForecastJobResponse;
import org.elasticsearch.client.ml.GetBucketsRequest;
import org.elasticsearch.client.ml.GetBucketsResponse;
import org.elasticsearch.client.ml.GetCalendarsRequest;
import org.elasticsearch.client.ml.GetCalendarsResponse;
import org.elasticsearch.client.ml.GetCategoriesRequest;
import org.elasticsearch.client.ml.GetCategoriesResponse;
import org.elasticsearch.client.ml.GetDatafeedRequest;
Expand Down Expand Up @@ -792,6 +794,44 @@ public void postDataAsync(PostDataRequest request, RequestOptions options, Actio
Collections.emptySet());
}

/**
* Gets a single or multiple calendars.
* <p>
* For additional info
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-calendar.html">ML GET calendars documentation</a>
*
* @param request The calendars request
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return {@link GetCalendarsResponse} response object containing the {@link org.elasticsearch.client.ml.calendars.Calendar}
* objects and the number of calendars found
*/
public GetCalendarsResponse getCalendars(GetCalendarsRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request,
MLRequestConverters::getCalendars,
options,
GetCalendarsResponse::fromXContent,
Collections.emptySet());
}

/**
* Gets a single or multiple calendars, notifies listener once the requested records are retrieved.
* <p>
* For additional info
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-calendar.html">ML GET calendars documentation</a>
*
* @param request The calendars request
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener Listener to be notified upon request completion
*/
public void getCalendarsAsync(GetCalendarsRequest request, RequestOptions options, ActionListener<GetCalendarsResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request,
MLRequestConverters::getCalendars,
options,
GetCalendarsResponse::fromXContent,
listener,
Collections.emptySet());
}

/**
* Gets the influencers for a Machine Learning Job.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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 org.elasticsearch.client.ml.calendars.Calendar;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;

import org.elasticsearch.client.ml.job.util.PageParams;

import java.io.IOException;
import java.util.Objects;

public class GetCalendarsRequest extends ActionRequest implements ToXContentObject {

public static final ObjectParser<GetCalendarsRequest, Void> PARSER =
new ObjectParser<>("get_calendars_request", GetCalendarsRequest::new);

static {
PARSER.declareString(GetCalendarsRequest::setCalendarId, Calendar.ID);
PARSER.declareObject(GetCalendarsRequest::setPageParams, PageParams.PARSER, PageParams.PAGE);
}

private String calendarId;
private PageParams pageParams;

public GetCalendarsRequest() {
}

public GetCalendarsRequest(String calendarId) {
this.calendarId = calendarId;
}

public String getCalendarId() {
return calendarId;
}

public void setCalendarId(String calendarId) {
this.calendarId = calendarId;
}

public PageParams getPageParams() {
return pageParams;
}

public void setPageParams(PageParams pageParams) {
this.pageParams = pageParams;
}

@Override
public ActionRequestValidationException validate() {
return null;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
if (calendarId != null) {
builder.field(Calendar.ID.getPreferredName(), calendarId);
}
if (pageParams != null) {
builder.field(PageParams.PAGE.getPreferredName(), pageParams);
}
builder.endObject();
return builder;
}

@Override
public int hashCode() {
return Objects.hash(calendarId, pageParams);
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
GetCalendarsRequest other = (GetCalendarsRequest) obj;
return Objects.equals(calendarId, other.calendarId) && Objects.equals(pageParams, other.pageParams);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.client.ml.calendars.Calendar;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;
import java.util.List;
import java.util.Objects;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;

public class GetCalendarsResponse extends AbstractResultResponse<Calendar> {

public static final ParseField RESULTS_FIELD = new ParseField("calendars");

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<GetCalendarsResponse, Void> PARSER =
new ConstructingObjectParser<>("calendars_response", true,
a -> new GetCalendarsResponse((List<Calendar>) a[0], (long) a[1]));

static {
PARSER.declareObjectArray(constructorArg(), Calendar.PARSER, RESULTS_FIELD);
PARSER.declareLong(constructorArg(), AbstractResultResponse.COUNT);
}

public static GetCalendarsResponse fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}

GetCalendarsResponse(List<Calendar> calendars, long count) {
super(RESULTS_FIELD, calendars, count);
}

/**
* The collection of {@link Calendar} objects found in the query
*/
public List<Calendar> calendars() {
return results;
}

@Override
public int hashCode() {
return Objects.hash(results, count);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}

if (obj == null || getClass() != obj.getClass()) {
return false;
}

GetCalendarsResponse other = (GetCalendarsResponse) obj;
return Objects.equals(results, other.results) && count == other.count;
}

@Override
public final String toString() {
return Strings.toString(this);
}
}
Loading

0 comments on commit 3635231

Please sign in to comment.