diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml new file mode 100644 index 00000000..aeef4dd2 --- /dev/null +++ b/.github/workflows/CD.yml @@ -0,0 +1,42 @@ +name: Build and Release AD +on: + push: + tags: + - v* + +jobs: + Build-AD: + strategy: + matrix: + java: [14] + + name: Build and Release AD Plugin + runs-on: ubuntu-latest + + steps: + - name: Checkout AD + uses: actions/checkout@v1 + + - name: Configure AWS + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Setup Java ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + - name: Run build + run: | + ./gradlew buildPackages --console=plain -Dbuild.snapshot=false + artifact=`ls build/distributions/*.zip` + rpm_artifact=`ls build/distributions/*.rpm` + deb_artifact=`ls build/distributions/*.deb` + + aws s3 cp $artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/elasticsearch-plugins/opendistro-anomaly-detection/ + aws s3 cp $rpm_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/rpms/opendistro-anomaly-detection/ + aws s3 cp $deb_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/debs/opendistro-anomaly-detection/ + aws cloudfront create-invalidation --distribution-id E1VG5HMIWI4SA2 --paths "/downloads/*" diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..28db6aba --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,62 @@ +name: Build and Test Anomaly detection +on: + push: + branches: + - master + - opendistro-* + +jobs: + Build-ad: + strategy: + matrix: + java: [14] + + name: Build and Test Anomaly detection Plugin + runs-on: ubuntu-latest + + steps: + - name: Checkout AD + uses: actions/checkout@v1 + + - name: Setup Java ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + - name: Run build + run: | + ./gradlew build + ls -ltr build/distributions/ + + - name: Pull and Run Docker + run: | + plugin=`ls build/distributions/*.zip` + version=`echo $plugin|awk -F- '{print $4}'| cut -d. -f 1-3` + plugin_version=`echo $plugin|awk -F- '{print $4}'| cut -d. -f 1-4` + echo $version + cd .. + + if docker pull opendistroforelasticsearch/opendistroforelasticsearch:$version + then + echo "FROM opendistroforelasticsearch/opendistroforelasticsearch:$version" >> Dockerfile + + ## The ESRestTest Client uses http by default. + ## Need to disable the security plugin to call the rest api over http. + echo "RUN if [ -d /usr/share/elasticsearch/plugins/opendistro_security ]; then /usr/share/elasticsearch/bin/elasticsearch-plugin remove opendistro_security; fi" >> Dockerfile + echo "RUN if [ -d /usr/share/elasticsearch/plugins/opendistro-anomaly-detection ]; then /usr/share/elasticsearch/bin/elasticsearch-plugin remove opendistro-anomaly-detection; fi" >> Dockerfile + echo "ADD anomaly-detection/build/distributions/opendistro-anomaly-detection-$plugin_version.zip /tmp/" >> Dockerfile + echo "RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch file:/tmp/opendistro-anomaly-detection-$plugin_version.zip" >> Dockerfile + + docker build -t odfe-ad:test . + fi + + - name: Run Docker Image + run: | + cd .. + docker run -p 9200:9200 -d -p 9600:9600 -e "discovery.type=single-node" odfe-ad:test + sleep 90 + curl -XGET http://localhost:9200/_cat/plugins + + - name: Run AD Test + run: | + ./gradlew :integTestRunner --tests "com.amazon.opendistroforelasticsearch.ad.rest.*IT" --tests "com.amazon.opendistroforelasticsearch.ad.e2e.*IT" -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java index 076f4d83..5c2ad6aa 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -171,8 +171,21 @@ private void startDetector( getDetectionResult(detectorId, begin, end, client); } catch (Exception e) {} } - Thread.sleep(5_000); - getDetectionResult(detectorId, begin, end, client); + // It takes time to wait for model initialization + long startTime = System.currentTimeMillis(); + do { + try { + Thread.sleep(5_000); + getDetectionResult(detectorId, begin, end, client); + break; + } catch (Exception e) { + long duration = System.currentTimeMillis() - startTime; + // we wait at most 60 secs + if (duration > 60_000) { + throw new RuntimeException(e); + } + } + } while (true); } private String createDetector(String datasetName, int intervalMinutes, RestClient client) throws Exception {