forked from opensearch-project/ml-commons
-
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.
Adding connector http timeout in the connector level (opensearch-proj…
…ect#1835) * working on connector http timeout Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * adding more test + fixing integration test issue Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * updating default values Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * fixing unit tests Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * input format changed Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * removed unused code Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * fixing test Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * refactored more and add more tests Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * applying spotlessApply Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * addressing comments Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * removing spaces Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * addressed comments + updated open api model name and endpoints (deprecated) Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * updating test Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * adding fields Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * addresseing comments to rename client config Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> --------- Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
- Loading branch information
Showing
23 changed files
with
549 additions
and
90 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
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
121 changes: 121 additions & 0 deletions
121
common/src/main/java/org/opensearch/ml/common/connector/ConnectorClientConfig.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,121 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.connector; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
@Getter | ||
@EqualsAndHashCode | ||
public class ConnectorClientConfig implements ToXContentObject, Writeable { | ||
|
||
public static final String MAX_CONNECTION_FIELD = "max_connection"; | ||
public static final String CONNECTION_TIMEOUT_FIELD = "connection_timeout"; | ||
public static final String READ_TIMEOUT_FIELD = "read_timeout"; | ||
|
||
public static final Integer MAX_CONNECTION_DEFAULT_VALUE = Integer.valueOf(30); | ||
public static final Integer CONNECTION_TIMEOUT_DEFAULT_VALUE = Integer.valueOf(30000); | ||
public static final Integer READ_TIMEOUT_DEFAULT_VALUE = Integer.valueOf(30000); | ||
|
||
private Integer maxConnections; | ||
private Integer connectionTimeout; | ||
private Integer readTimeout; | ||
|
||
@Builder(toBuilder = true) | ||
public ConnectorClientConfig( | ||
Integer maxConnections, | ||
Integer connectionTimeout, | ||
Integer readTimeout | ||
) { | ||
this.maxConnections = maxConnections; | ||
this.connectionTimeout = connectionTimeout; | ||
this.readTimeout = readTimeout; | ||
|
||
} | ||
|
||
public ConnectorClientConfig(StreamInput input) throws IOException { | ||
this.maxConnections = input.readOptionalInt(); | ||
this.connectionTimeout = input.readOptionalInt(); | ||
this.readTimeout = input.readOptionalInt(); | ||
} | ||
|
||
public ConnectorClientConfig() { | ||
this.maxConnections = MAX_CONNECTION_DEFAULT_VALUE; | ||
this.connectionTimeout = CONNECTION_TIMEOUT_DEFAULT_VALUE; | ||
this.readTimeout = READ_TIMEOUT_DEFAULT_VALUE; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
|
||
out.writeOptionalInt(maxConnections); | ||
out.writeOptionalInt(connectionTimeout); | ||
out.writeOptionalInt(readTimeout); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params) throws IOException { | ||
XContentBuilder builder = xContentBuilder.startObject(); | ||
if (maxConnections != null) { | ||
builder.field(MAX_CONNECTION_FIELD, maxConnections); | ||
} | ||
if (connectionTimeout != null) { | ||
builder.field(CONNECTION_TIMEOUT_FIELD, connectionTimeout); | ||
} | ||
if (readTimeout != null) { | ||
builder.field(READ_TIMEOUT_FIELD, readTimeout); | ||
} | ||
return builder.endObject(); | ||
} | ||
|
||
public static ConnectorClientConfig fromStream(StreamInput in) throws IOException { | ||
ConnectorClientConfig connectorClientConfig = new ConnectorClientConfig(in); | ||
return connectorClientConfig; | ||
} | ||
|
||
public static ConnectorClientConfig parse(XContentParser parser) throws IOException { | ||
Integer maxConnections = null; | ||
Integer connectionTimeout = null; | ||
Integer readTimeout = null; | ||
|
||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser); | ||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
String fieldName = parser.currentName(); | ||
parser.nextToken(); | ||
|
||
switch (fieldName) { | ||
case MAX_CONNECTION_FIELD: | ||
maxConnections = parser.intValue(); | ||
break; | ||
case CONNECTION_TIMEOUT_FIELD: | ||
connectionTimeout = parser.intValue(); | ||
break; | ||
case READ_TIMEOUT_FIELD: | ||
readTimeout = parser.intValue(); | ||
break; | ||
default: | ||
parser.skipChildren(); | ||
break; | ||
} | ||
} | ||
return ConnectorClientConfig.builder() | ||
.maxConnections(maxConnections) | ||
.connectionTimeout(connectionTimeout) | ||
.readTimeout(readTimeout) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.