Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/extensions] Create Detector Workflow #692

Merged
Merged
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ configurations.all {
resolutionStrategy {
force "joda-time:joda-time:2.10.13"
force "commons-logging:commons-logging:1.2"
force "org.apache.httpcomponents:httpcore:4.4.15"
force "org.apache.httpcomponents:httpcore5:5.1.4"
force "commons-codec:commons-codec:1.15"

force "org.mockito:mockito-core:2.25.0"
Expand Down Expand Up @@ -757,6 +757,8 @@ dependencies {
// implementation "org.opensearch:common-utils:${common_utils_version}"
implementation "org.opensearch:opensearch-sdk-java:1.0.0-SNAPSHOT"
implementation "org.opensearch.client:opensearch-rest-client:${opensearch_version}"
implementation "org.opensearch.client:opensearch-java:${opensearch_version}"
implementation "org.opensearch.client:opensearch-rest-client:${opensearch_version}"
implementation group: 'com.google.guava', name: 'guava', version:'31.0.1-jre'
implementation group: 'com.google.guava', name: 'failureaccess', version:'1.0.1'
implementation group: 'org.javassist', name: 'javassist', version:'3.28.0-GA'
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/opensearch/ad/AnomalyDetectorExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
import static java.util.Collections.unmodifiableList;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.opensearch.ad.rest.RestCreateDetectorAction;
import org.opensearch.ad.settings.AnomalyDetectorSettings;
import org.opensearch.ad.settings.EnabledSetting;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.settings.Setting;
import org.opensearch.sdk.Extension;
import org.opensearch.sdk.ExtensionRestHandler;
import org.opensearch.sdk.ExtensionSettings;
import org.opensearch.sdk.ExtensionsRunner;
import org.opensearch.sdk.SDKClient;
import org.opensearch.threadpool.ThreadPool;

import com.google.common.collect.ImmutableList;

Expand Down Expand Up @@ -83,6 +88,11 @@ public List<Setting<?>> getSettings() {
);
}

@Override
public Collection<Object> createComponents(SDKClient sdkClient, ClusterService clusterService, ThreadPool threadPool) {
return null;
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
}

private static ExtensionSettings initializeSettings() throws IOException {
ExtensionSettings settings = Extension.readSettingsFromYaml(EXTENSION_SETTINGS_PATH);
if (settings == null || settings.getHostAddress() == null || settings.getHostPort() == null) {
Expand All @@ -91,6 +101,12 @@ private static ExtensionSettings initializeSettings() throws IOException {
return settings;
}

public OpenSearchClient getClient() {
SDKClient sdkClient = new SDKClient();
OpenSearchClient client = sdkClient.initializeClient("localhost", 9200);
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
return client;
}

public static void main(String[] args) throws IOException {
// Execute this extension by instantiating it and passing to ExtensionsRunner
ExtensionsRunner.run(new AnomalyDetectorExtension());
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/opensearch/ad/auth/UserIdentity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import java.util.Map;
import java.util.Objects;

import org.apache.http.util.EntityUtils;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.opensearch.client.Response;
import org.opensearch.common.Nullable;
import org.opensearch.common.Strings;
Expand Down Expand Up @@ -110,7 +111,7 @@ public UserIdentity(
* @param response The security plugin response.
* @throws IOException If there was an error receiving the response.
*/
public UserIdentity(final Response response) throws IOException {
public UserIdentity(final Response response) throws IOException, ParseException {
this(EntityUtils.toString(response.getEntity()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@
* in code rather than config it in anomaly-detection-state.json file.
*/
public class AnomalyDetector implements Writeable, ToXContentObject {

public static final String PARSE_FIELD_NAME = "AnomalyDetector";
public static final NamedXContentRegistry.Entry XCONTENT_REGISTRY = new NamedXContentRegistry.Entry(
AnomalyDetector.class,
new ParseField(PARSE_FIELD_NAME),
it -> parse(it)
);
public static final String NO_ID = "";
public static final String ANOMALY_DETECTORS_INDEX = ".opendistro-anomaly-detectors";
public static final String ANOMALY_DETECTORS_INDEX = "opendistro-anomaly-detectors";
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
public static final String TYPE = "_doc";
public static final String QUERY_PARAM_PERIOD_START = "period_start";
public static final String QUERY_PARAM_PERIOD_END = "period_end";
Expand Down
Loading