Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Add CI/CD workflows #133

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -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/*"
62 changes: 62 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 {
Expand Down