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

Commit

Permalink
Include RCA bits in build distribution (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid Narayan authored Jun 26, 2020
1 parent 76765f6 commit 620b6e7
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 28 deletions.
80 changes: 56 additions & 24 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ ext {
licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')
}

test {
enabled = true
}
Expand Down Expand Up @@ -164,27 +165,6 @@ dependencyLicenses.doFirst {
updateShas.updateShas()
}

bundlePlugin {
from ("pa_config") {
into "pa_config"
}
from ("pa_bin") {
into "pa_bin"
include "performance-analyzer-agent"
}
from ("pa_bin") {
into "extensions"
include "performance-analyzer-agent"
}
from ('build/resources/main/') {
include "plugin-security.policy"
}
exclude ('tools.jar')
from ("config/opendistro_performance_analyzer") {
into "config"
}
}

gradle.startParameter.excludedTaskNames += [ "forbiddenApisMain",
"forbiddenApisTest",
"thirdPartyAudit",
Expand All @@ -193,6 +173,7 @@ import java.nio.file.Paths
import org.ajoberstar.gradle.git.tasks.GitClone

String rcaDir
String rcaArtifactsDir

static def propEnabled(property) {
return System.getProperty(property) != null
Expand All @@ -201,9 +182,6 @@ static def propEnabled(property) {
// The following Gradle tasks are used to create a PA/RCA enabled Elasticsearch cluster
// Pass the -Dtests.enableIT property to Gradle to run ITs
task cloneGitRepo(type: GitClone) {
onlyIf = {
propEnabled("tests.enableIT")
}
rcaDir = Paths.get(getProject().getBuildDir().toString(), "performance-analyzer-rca").toString()
def destination = file(rcaDir)
uri = "https://github.com/opendistro-for-elasticsearch/performance-analyzer-rca.git"
Expand All @@ -212,6 +190,57 @@ task cloneGitRepo(type: GitClone) {
enabled = !destination.exists() // to clone only once
}

task buildRca() {
dependsOn(cloneGitRepo)
doLast {
exec {
workingDir("$rcaDir")
commandLine './gradlew', 'build', '-x', 'test'
}
}
}

task unpackRca(type: Copy) {
dependsOn(buildRca)
from(zipTree("$rcaDir/build/distributions/performance-analyzer-rca.zip")) {
}
into "$rcaDir/build/distributions"
rcaArtifactsDir = "$rcaDir/build/distributions/performance-analyzer-rca/"
}

bundlePlugin {
dependsOn 'cloneGitRepo'
from("$rcaArtifactsDir/pa_config") {
into "pa_config"
}
from("$rcaArtifactsDir/pa_bin") {
into "pa_bin"
include "performance-analyzer-agent"
}
from("$rcaArtifactsDir/pa_bin") {
into "extensions"
include "performance-analyzer-agent"
}
from("$rcaArtifactsDir") {
into "performance-analyzer-rca"
}
from("packaging") {
include "performance-analyzer-agent-cli", "opendistro-performance-analyzer.service"
into "bin"
}
from("packaging") {
include "deb/**", "rpm/**"
into "install"
}
from('build/resources/main/') {
include "plugin-security.policy"
}
exclude('tools.jar')
from("config/opendistro_performance_analyzer") {
into "config"
}
}

task setupEsCluster() {
dependsOn(cloneGitRepo)
onlyIf = {
Expand Down Expand Up @@ -299,3 +328,6 @@ afterEvaluate {
tasks = ['build', 'buildRpm', 'buildDeb']
}
}

bundlePlugin.mustRunAfter unpackRca
build.dependsOn unpackRca
22 changes: 22 additions & 0 deletions packaging/deb/postinst
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#!/bin/sh
set -e

# Make sure the ES_HOME environment variable is set
if [ -z "$ES_HOME" ]; then
echo "ES_HOME must be properly set before running this script"
echo 'Try running export ES_HOME=/path/to/ES_HOME'
echo 'ES_HOME is usually located in /usr/share/elasticsearch'
exit 1
fi

# Prepare the RCA reader process for execution
cp -r "$ES_HOME"/plugins/opendistro_performance_analyzer/performance-analyzer-rca $ES_HOME
cp "$ES_HOME"/bin/opendistro_performance_analyzer/opendistro-performance-analyzer.service /usr/lib/systemd/system/opendistro-performance-analyzer.service
mkdir -p "$ES_HOME"/data
mkdir -p "/var/lib/elasticsearch"
touch "$ES_HOME"/data/rca_enabled.conf
echo 'true' > "$ES_HOME"/data/rca_enabled.conf
echo 'true' > /var/lib/elasticsearch/performance_analyzer_enabled.conf
echo 'true' > /var/lib/elasticsearch/rca_enabled.conf
chown elasticsearch /var/lib/elasticsearch/performance_analyzer_enabled.conf
chown elasticsearch /var/lib/elasticsearch/rca_enabled.conf
chown -R elasticsearch "$ES_HOME/performance-analyzer-rca"
chmod a+rw /tmp

if ! grep -q '## OpenDistro Performance Analyzer' /etc/elasticsearch/jvm.options; then
CLK_TCK=`/usr/bin/getconf CLK_TCK`
echo >> /etc/elasticsearch/jvm.options
Expand Down
2 changes: 1 addition & 1 deletion packaging/opendistro-performance-analyzer.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=Opendistro for Elasticsearch Performance Analyzer
PartOf=elasticsearch.service

[Service]
ExecStart=/usr/share/elasticsearch/bin/performance-analyzer-agent-cli
ExecStart=/usr/share/elasticsearch/bin/opendistro_performance_analyzer/performance-analyzer-agent-cli
Restart=on-failure
User=elasticsearch
Group=elasticsearch
Expand Down
4 changes: 2 additions & 2 deletions packaging/performance-analyzer-agent-cli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PA_AGENT_JAVA_OPTS="-Dlog4j.configurationFile=$ES_HOME/plugins/opendistro_perfor
-XX:InitialBootClassLoaderMetaspaceSize=30720 -XX:MaxRAM=400m"

ES_MAIN_CLASS="com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp" \
ES_ADDITIONAL_CLASSPATH_DIRECTORIES=plugins/opendistro_performance_analyzer \
ES_ADDITIONAL_CLASSPATH_DIRECTORIES=performance-analyzer-rca/lib \
ES_JAVA_OPTS=$PA_AGENT_JAVA_OPTS \
"`dirname "$0"`"/elasticsearch-cli \
/usr/share/elasticsearch/bin/elasticsearch-cli \
"$@"
25 changes: 24 additions & 1 deletion packaging/rpm/postinst
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@

#!/bin/sh
set -e

# Post install script for Redhat like distros. Tested on CentOS 7.

# Make sure the ES_HOME environment variable is set
if [ -z "$ES_HOME" ]; then
echo "ES_HOME must be properly set before running this script"
echo 'Try running export ES_HOME=/path/to/ES_HOME'
echo 'ES_HOME is usually located in /usr/share/elasticsearch'
exit 1
fi

# Prepare the RCA reader process for execution
cp -r "$ES_HOME"/plugins/opendistro_performance_analyzer/performance-analyzer-rca $ES_HOME
cp "$ES_HOME"/bin/opendistro_performance_analyzer/opendistro-performance-analyzer.service /usr/lib/systemd/system/opendistro-performance-analyzer.service
mkdir -p "$ES_HOME"/data
mkdir -p "/var/lib/elasticsearch"
touch "$ES_HOME"/data/rca_enabled.conf
echo 'true' > "$ES_HOME"/data/rca_enabled.conf
echo 'true' > /var/lib/elasticsearch/performance_analyzer_enabled.conf
echo 'true' > /var/lib/elasticsearch/rca_enabled.conf
chown elasticsearch /var/lib/elasticsearch/performance_analyzer_enabled.conf
chown elasticsearch /var/lib/elasticsearch/rca_enabled.conf
chown -R elasticsearch "$ES_HOME/performance-analyzer-rca"
chmod a+rw /tmp

if ! grep -q '## OpenDistro Performance Analyzer' /etc/elasticsearch/jvm.options; then
CLK_TCK=`/usr/bin/getconf CLK_TCK`
echo >> /etc/elasticsearch/jvm.options
Expand Down

0 comments on commit 620b6e7

Please sign in to comment.