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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@ dependencies {
// Removed Common Utils dependency from AD
// 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:2.0.0'
implementation 'org.opensearch.client:opensearch-java:2.0.0'
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'
Expand All @@ -774,6 +776,7 @@ dependencies {
// implementation "com.fasterxml.jackson.core:jackson-core:${versions.jackson}"
// implementation "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
// implementation "com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.4"

// used for serializing/deserializing rcf models.
implementation group: 'io.protostuff', name: 'protostuff-core', version: '1.8.0'
Expand Down
24 changes: 23 additions & 1 deletion 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.*;
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
import org.opensearch.sdk.Extension;
import org.opensearch.sdk.ExtensionRestHandler;
import org.opensearch.sdk.ExtensionSettings;
import org.opensearch.sdk.ExtensionsRunner;
import org.opensearch.threadpool.ThreadPool;

import com.google.common.collect.ImmutableList;

Expand All @@ -39,7 +44,13 @@ public ExtensionSettings getExtensionSettings() {

@Override
public List<ExtensionRestHandler> getExtensionRestHandlers() {
return List.of(new RestCreateDetectorAction());
List<ExtensionRestHandler> handler = null;
try {
handler = List.of(new RestCreateDetectorAction());
owaiskazi19 marked this conversation as resolved.
Show resolved Hide resolved
} catch (IOException e) {
owaiskazi19 marked this conversation as resolved.
Show resolved Hide resolved
e.printStackTrace();
}
return handler;
}

@Override
Expand Down Expand Up @@ -83,6 +94,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 +107,12 @@ private static ExtensionSettings initializeSettings() throws IOException {
return settings;
}

public OpenSearchClient getClient() throws IOException {
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
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