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.
Add remote info to the HLRC (elastic#50482)
Unreverts the commit that added the remote info api to HLRC (elastic#49657). The additional change to the original PR, is that `org.elasticsearch.client.cluster.RemoteConnectionInfo` now parses the initial_connect_timeout field as a string instead of a TimeValue instance. The reason that this is needed is because that the initial_connect_timeout field in the remote connection api is serialized for human consumption, but not for parsing purposes. Therefore the HLRC can't parse it correctly (which caused test failures in CI, but not in the PR CI :( ). The way this field is serialized needs to be changed in the remote connection api, but that is a breaking change. We should wait making this change until rest api versioning is introduced. Co-Authored-By: j-bean anton.shuvaev91@gmail.com
- Loading branch information
1 parent
d911f18
commit bea1600
Showing
23 changed files
with
773 additions
and
74 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
75 changes: 75 additions & 0 deletions
75
client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/ProxyModeInfo.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,75 @@ | ||
/* | ||
* 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.cluster; | ||
|
||
import java.util.Objects; | ||
|
||
public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo { | ||
static final String NAME = "proxy"; | ||
static final String ADDRESS = "address"; | ||
static final String NUM_SOCKETS_CONNECTED = "num_sockets_connected"; | ||
static final String MAX_SOCKET_CONNECTIONS = "max_socket_connections"; | ||
private final String address; | ||
private final int maxSocketConnections; | ||
private final int numSocketsConnected; | ||
|
||
ProxyModeInfo(String address, int maxSocketConnections, int numSocketsConnected) { | ||
this.address = address; | ||
this.maxSocketConnections = maxSocketConnections; | ||
this.numSocketsConnected = numSocketsConnected; | ||
} | ||
|
||
@Override | ||
public boolean isConnected() { | ||
return numSocketsConnected > 0; | ||
} | ||
|
||
@Override | ||
public String modeName() { | ||
return NAME; | ||
} | ||
|
||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
public int getMaxSocketConnections() { | ||
return maxSocketConnections; | ||
} | ||
|
||
public int getNumSocketsConnected() { | ||
return numSocketsConnected; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ProxyModeInfo otherProxy = (ProxyModeInfo) o; | ||
return maxSocketConnections == otherProxy.maxSocketConnections && | ||
numSocketsConnected == otherProxy.numSocketsConnected && | ||
Objects.equals(address, otherProxy.address); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(address, maxSocketConnections, numSocketsConnected); | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
.../rest-high-level/src/main/java/org/elasticsearch/client/cluster/RemoteConnectionInfo.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,139 @@ | ||
/* | ||
* 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.cluster; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
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; | ||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; | ||
|
||
/** | ||
* This class encapsulates all remote cluster information to be rendered on | ||
* {@code _remote/info} requests. | ||
*/ | ||
public final class RemoteConnectionInfo { | ||
private static final String CONNECTED = "connected"; | ||
private static final String MODE = "mode"; | ||
private static final String INITIAL_CONNECT_TIMEOUT = "initial_connect_timeout"; | ||
private static final String SKIP_UNAVAILABLE = "skip_unavailable"; | ||
|
||
@SuppressWarnings("unchecked") | ||
private static final ConstructingObjectParser<RemoteConnectionInfo, String> PARSER = new ConstructingObjectParser<>( | ||
"RemoteConnectionInfoObjectParser", | ||
false, | ||
(args, clusterAlias) -> { | ||
String mode = (String) args[1]; | ||
ModeInfo modeInfo; | ||
if (mode.equals(ProxyModeInfo.NAME)) { | ||
modeInfo = new ProxyModeInfo((String) args[4], (int) args[5], (int) args[6]); | ||
} else if (mode.equals(SniffModeInfo.NAME)) { | ||
modeInfo = new SniffModeInfo((List<String>) args[7], (int) args[8], (int) args[9]); | ||
} else { | ||
throw new IllegalArgumentException("mode cannot be " + mode); | ||
} | ||
return new RemoteConnectionInfo(clusterAlias, | ||
modeInfo, | ||
(String) args[2], | ||
(boolean) args[3]); | ||
}); | ||
|
||
static { | ||
PARSER.declareBoolean(constructorArg(), new ParseField(CONNECTED)); | ||
PARSER.declareString(constructorArg(), new ParseField(MODE)); | ||
PARSER.declareString(constructorArg(), new ParseField(INITIAL_CONNECT_TIMEOUT)); | ||
PARSER.declareBoolean(constructorArg(), new ParseField(SKIP_UNAVAILABLE)); | ||
|
||
PARSER.declareString(optionalConstructorArg(), new ParseField(ProxyModeInfo.ADDRESS)); | ||
PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.MAX_SOCKET_CONNECTIONS)); | ||
PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.NUM_SOCKETS_CONNECTED)); | ||
|
||
PARSER.declareStringArray(optionalConstructorArg(), new ParseField(SniffModeInfo.SEEDS)); | ||
PARSER.declareInt(optionalConstructorArg(), new ParseField(SniffModeInfo.MAX_CONNECTIONS_PER_CLUSTER)); | ||
PARSER.declareInt(optionalConstructorArg(), new ParseField(SniffModeInfo.NUM_NODES_CONNECTED)); | ||
} | ||
|
||
private final ModeInfo modeInfo; | ||
// TODO: deprecate and remove this field in favor of initialConnectionTimeout field that is of type TimeValue. | ||
// When rest api versioning exists then change org.elasticsearch.transport.RemoteConnectionInfo to properly serialize | ||
// the initialConnectionTimeout field so that we can properly parse initialConnectionTimeout as TimeValue | ||
private final String initialConnectionTimeoutString; | ||
private final String clusterAlias; | ||
private final boolean skipUnavailable; | ||
|
||
RemoteConnectionInfo(String clusterAlias, ModeInfo modeInfo, String initialConnectionTimeoutString, boolean skipUnavailable) { | ||
this.clusterAlias = clusterAlias; | ||
this.modeInfo = modeInfo; | ||
this.initialConnectionTimeoutString = initialConnectionTimeoutString; | ||
this.skipUnavailable = skipUnavailable; | ||
} | ||
|
||
public boolean isConnected() { | ||
return modeInfo.isConnected(); | ||
} | ||
|
||
public String getClusterAlias() { | ||
return clusterAlias; | ||
} | ||
|
||
public ModeInfo getModeInfo() { | ||
return modeInfo; | ||
} | ||
|
||
public String getInitialConnectionTimeoutString() { | ||
return initialConnectionTimeoutString; | ||
} | ||
|
||
public boolean isSkipUnavailable() { | ||
return skipUnavailable; | ||
} | ||
|
||
public static RemoteConnectionInfo fromXContent(XContentParser parser, String clusterAlias) throws IOException { | ||
return PARSER.parse(parser, clusterAlias); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
RemoteConnectionInfo that = (RemoteConnectionInfo) o; | ||
return skipUnavailable == that.skipUnavailable && | ||
Objects.equals(modeInfo, that.modeInfo) && | ||
Objects.equals(initialConnectionTimeoutString, that.initialConnectionTimeoutString) && | ||
Objects.equals(clusterAlias, that.clusterAlias); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(modeInfo, initialConnectionTimeoutString, clusterAlias, skipUnavailable); | ||
} | ||
|
||
public interface ModeInfo { | ||
|
||
boolean isConnected(); | ||
|
||
String modeName(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/RemoteInfoRequest.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,28 @@ | ||
/* | ||
* 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.cluster; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
|
||
/** | ||
* The request object used by the Remote cluster info API. | ||
*/ | ||
public final class RemoteInfoRequest implements Validatable { | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...nt/rest-high-level/src/main/java/org/elasticsearch/client/cluster/RemoteInfoResponse.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,59 @@ | ||
/* | ||
* 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.cluster; | ||
|
||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
/** | ||
* A response to _remote/info API request. | ||
*/ | ||
public final class RemoteInfoResponse { | ||
|
||
private List<RemoteConnectionInfo> infos; | ||
|
||
RemoteInfoResponse(Collection<RemoteConnectionInfo> infos) { | ||
this.infos = List.copyOf(infos); | ||
} | ||
|
||
public List<RemoteConnectionInfo> getInfos() { | ||
return infos; | ||
} | ||
|
||
public static RemoteInfoResponse fromXContent(XContentParser parser) throws IOException { | ||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation); | ||
|
||
List<RemoteConnectionInfo> infos = new ArrayList<>(); | ||
|
||
XContentParser.Token token; | ||
while ((token = parser.nextToken()) == XContentParser.Token.FIELD_NAME) { | ||
String clusterAlias = parser.currentName(); | ||
RemoteConnectionInfo info = RemoteConnectionInfo.fromXContent(parser, clusterAlias); | ||
infos.add(info); | ||
} | ||
ensureExpectedToken(XContentParser.Token.END_OBJECT, token, parser::getTokenLocation); | ||
return new RemoteInfoResponse(infos); | ||
} | ||
} |
Oops, something went wrong.