Skip to content

Commit

Permalink
testing code change
Browse files Browse the repository at this point in the history
  • Loading branch information
brianf-aws committed Sep 13, 2024
1 parent 33ea2c8 commit 94acf53
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public abstract class AbstractConnector implements Connector {
@Setter
protected ConnectorClientConfig connectorClientConfig;

public AbstractConnector() {
this.createdTime = Instant.now();
this.lastUpdateTime = Instant.now();
}
// public AbstractConnector() {
// this.createdTime = Instant.now();
// this.lastUpdateTime = Instant.now();
// }

protected Map<String, String> createDecryptedHeaders(Map<String, String> headers) {
if (headers == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.text.StringSubstitutor;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
Expand All @@ -43,6 +45,8 @@ public interface Connector extends ToXContentObject, Writeable {
String getName();

String getProtocol();
void setCreatedTime(Instant createdTime);
void setLastUpdatedTime(Instant lastUpdatedTime);

User getOwner();

Expand Down Expand Up @@ -120,7 +124,10 @@ static Connector createConnector(XContentBuilder builder, String connectorProtoc

@SuppressWarnings("removal")
static Connector createConnector(XContentParser parser) throws IOException {
Map<String, Object> connectorMap = parser.map();
Map<String, Object> connectorMap = parser.map().entrySet().stream()
.filter(field -> field.getValue() != null)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

String jsonStr;
try {
jsonStr = AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> gson.toJson(connectorMap));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public HttpConnector(
User owner,
ConnectorClientConfig connectorClientConfig
) {
super();
validateProtocol(protocol);
this.name = name;
this.description = description;
Expand Down Expand Up @@ -147,6 +148,7 @@ public HttpConnector(String protocol, XContentParser parser) throws IOException

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
System.out.println("TEST MESSSAGE****");
builder.startObject();
if (name != null) {
builder.field(NAME_FIELD, name);
Expand Down Expand Up @@ -284,7 +286,9 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public void update(MLCreateConnectorInput updateContent, Function<String, String> function) {
this.setLastUpdateTime(Instant.now());
// if (this.lastUpdateTime != null) {
// this.setLastUpdateTime(Instant.now());
// }
if (updateContent.getName() != null) {
this.name = updateContent.getName();
}
Expand Down Expand Up @@ -391,6 +395,11 @@ public void encrypt(Function<String, String> function) {
}
}

@Override
public void setLastUpdatedTime(Instant lastUpdatedTime) {
this.lastUpdateTime = lastUpdatedTime;
}

@Override
public String getActionHttpMethod(String action) {
return findAction(action).get().getMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX;
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_TRUSTED_CONNECTOR_ENDPOINTS_REGEX;

import java.time.Instant;
import java.util.HashSet;
import java.util.List;

Expand Down Expand Up @@ -135,6 +136,11 @@ private void indexConnector(Connector connector, ActionListener<MLCreateConnecto
}, listener::onFailure);

IndexRequest indexRequest = new IndexRequest(ML_CONNECTOR_INDEX);
Instant currentTime = Instant.now();

connector.setCreatedTime(currentTime);
connector.setLastUpdatedTime(currentTime);

indexRequest.source(connector.toXContent(XContentBuilder.builder(XContentType.JSON.xContent()), ToXContent.EMPTY_PARAMS));
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
client.index(indexRequest, ActionListener.runBefore(indexResponseListener, context::restore));
Expand Down

0 comments on commit 94acf53

Please sign in to comment.