OpenSearch/dev-tools/src/main/resources/ant/integration-tests.xml

435 lines
16 KiB
XML

<?xml version="1.0"?>
<project name="elasticsearch-integration-tests">
<!-- our pid file for easy cleanup -->
<property name="integ.pidfile" location="${integ.scratch}/es.pid"/>
<!-- if this exists, ES is running (maybe) -->
<available property="integ.pidfile.exists" file="${integ.pidfile}"/>
<!-- name of our cluster, maybe needs changing -->
<property name="integ.cluster.name" value="prepare_release"/>
<!-- runs an OS script -->
<macrodef name="run-script">
<attribute name="script"/>
<attribute name="spawn" default="false"/>
<element name="nested" optional="true"/>
<sequential>
<local name="failonerror"/>
<condition property="failonerror">
<isfalse value="@{spawn}"/>
</condition>
<!-- create a temp CWD, to enforce that commands don't rely on CWD -->
<local name="temp.cwd"/>
<tempfile property="temp.cwd" destDir="${integ.temp}"/>
<mkdir dir="${temp.cwd}"/>
<!-- print commands we run -->
<local name="script.base"/>
<basename file="@{script}" property="script.base"/>
<!-- crappy way to output, but we need it. make it nice later -->
<echoxml><exec script="${script.base}"><nested/></exec></echoxml>
<exec executable="cmd" osfamily="winnt" dir="${temp.cwd}" failonerror="${failonerror}" spawn="@{spawn}" taskname="${script.base}">
<arg value="/c"/>
<arg value="@{script}.bat"/>
<nested/>
</exec>
<exec executable="sh" osfamily="unix" dir="${temp.cwd}" failonerror="${failonerror}" spawn="@{spawn}" taskname="${script.base}">
<arg value="@{script}"/>
<nested/>
</exec>
</sequential>
</macrodef>
<!-- extracts PID from file -->
<macrodef name="extract-pid">
<attribute name="file"/>
<attribute name="property"/>
<sequential>
<loadfile srcFile="@{file}" property="@{property}">
<filterchain>
<striplinebreaks/>
</filterchain>
</loadfile>
</sequential>
</macrodef>
<!-- applies transformations to src and stores in dst -->
<macrodef name="filter-property">
<attribute name="src"/>
<attribute name="dest"/>
<element name="chain"/>
<sequential>
<loadresource property="@{dest}">
<propertyresource name="@{src}"/>
<filterchain>
<tokenfilter>
<chain/>
</tokenfilter>
</filterchain>
</loadresource>
</sequential>
</macrodef>
<!-- installs a plugin into elasticsearch -->
<macrodef name="install-plugin">
<attribute name="home" default="${integ.scratch}/elasticsearch-${elasticsearch.version}"/>
<attribute name="name"/>
<attribute name="file"/>
<sequential>
<local name="url"/>
<makeurl property="url" file="@{file}"/>
<!-- install plugin -->
<echo>Installing plugin @{name}...</echo>
<run-script script="@{home}/bin/plugin">
<nested>
<arg value="install"/>
<arg value="@{name}"/>
<arg value="-u"/>
<arg value="${url}"/>
</nested>
</run-script>
<!-- check that plugin was installed into correct place -->
<local name="longname"/>
<property name="longname" value="@{name}"/>
<local name="shortname"/>
<filter-property src="longname" dest="shortname">
<chain>
<replaceregex pattern="^elasticsearch-" replace=""/>
</chain>
</filter-property>
<fail message="did not find plugin installed as ${shortname}">
<condition>
<not>
<resourceexists>
<file file="@{home}/plugins/${shortname}"/>
</resourceexists>
</not>
</condition>
</fail>
</sequential>
</macrodef>
<!-- waits for elasticsearch to start -->
<macrodef name="waitfor-elasticsearch">
<attribute name="port"/>
<attribute name="timeoutproperty"/>
<sequential>
<echo>Waiting for elasticsearch to become available on port @{port}...</echo>
<waitfor maxwait="30" maxwaitunit="second"
checkevery="500" checkeveryunit="millisecond"
timeoutproperty="@{timeoutproperty}">
<http url="http://127.0.0.1:@{port}"/>
</waitfor>
</sequential>
</macrodef>
<!-- waits for cluster to form and have exactly two nodes -->
<macrodef name="waitfor-two-nodes">
<attribute name="port"/>
<attribute name="timeoutproperty"/>
<sequential>
<echo>Waiting for elasticsearch to form a cluster of two...</echo>
<waitfor maxwait="30" maxwaitunit="second"
checkevery="500" checkeveryunit="millisecond"
timeoutproperty="@{timeoutproperty}">
<http url="http://127.0.0.1:@{port}/_cluster/health?wait_for_nodes=2"/>
</waitfor>
</sequential>
</macrodef>
<!-- start elasticsearch and wait until its ready -->
<macrodef name="startup-elasticsearch">
<attribute name="home" default="${integ.scratch}/elasticsearch-${elasticsearch.version}"/>
<attribute name="spawn" default="true"/>
<attribute name="args" default="${integ.args}"/>
<attribute name="es.unicast.enabled" default="false"/>
<attribute name="es.unicast.hosts" default=""/>
<attribute name="es.cluster.name" default="${integ.cluster.name}"/>
<attribute name="es.http.port" default="${integ.http.port}"/>
<attribute name="es.transport.tcp.port" default="${integ.transport.port}"/>
<attribute name="es.pidfile" default="${integ.pidfile}"/>
<attribute name="jvm.args" default="${tests.jvm.argline}"/>
<element name="additional-args" optional="true"/>
<sequential>
<!-- run bin/elasticsearch with args -->
<echo>Starting up external cluster...</echo>
<run-script script="@{home}/bin/elasticsearch"
spawn="@{spawn}">
<nested>
<env key="JAVA_HOME" value="${java.home}"/>
<!-- we pass these as gc options, even if they arent, to avoid conflicting gc options -->
<env key="ES_GC_OPTS" value="@{jvm.args}"/>
<arg value="-Des.cluster.name=@{es.cluster.name}"/>
<arg value="-Des.http.port=@{es.http.port}"/>
<arg value="-Des.transport.tcp.port=@{es.transport.tcp.port}"/>
<arg value="-Des.pidfile=@{es.pidfile}"/>
<arg value="-Des.discovery.zen.ping.unicast.enabled=@{es.unicast.enabled}"/>
<arg value="-Des.discovery.zen.ping.unicast.hosts=@{es.unicast.hosts}"/>
<arg value="-Des.path.repo=@{home}/repo"/>
<arg value="-Des.path.shared_data=@{home}/../"/>
<arg value="-Des.discovery.zen.ping.multicast.enabled=false"/>
<arg value="-Des.script.inline=on"/>
<arg value="-Des.script.indexed=on"/>
<arg value="-Des.repositories.url.allowed_urls=http://snapshot.test*"/>
<additional-args/>
</nested>
</run-script>
<!-- wait for startup -->
<local name="failed.to.start"/>
<waitfor-elasticsearch port="@{es.http.port}"
timeoutproperty="failed.to.start"/>
<!-- best effort, print console log. useful if it fails especially -->
<local name="log.contents"/>
<loadfile srcFile="@{home}/logs/@{es.cluster.name}.log"
property="log.contents"
failonerror="false"/>
<echo message="${log.contents}" taskname="elasticsearch"/>
<fail message="ES instance did not start" if="failed.to.start"/>
<local name="integ.pid"/>
<extract-pid file="@{es.pidfile}" property="integ.pid"/>
<echo>External node started PID ${integ.pid}</echo>
</sequential>
</macrodef>
<!-- Takes a plugin zip file and return the plugin name. For instance
'elasticsearch-analysis-icu-2.0.0.zip' would return
'elasticsearch-analysis-icu'. -->
<macrodef name="convert-plugin-name">
<attribute name="file"/>
<attribute name="outputproperty"/>
<sequential>
<local name="file.base"/>
<basename file="@{file}" property="file.base"/>
<filter-property src="file.base" dest="@{outputproperty}">
<chain>
<replaceregex pattern="^elasticsearch-" replace=""/>
<replacestring from="-${elasticsearch.version}.zip" to=""/>
</chain>
</filter-property>
</sequential>
</macrodef>
<macrodef name="stop-node">
<attribute name="es.pidfile" default="${integ.pidfile}"/>
<sequential>
<local name="integ.pid"/>
<extract-pid file="@{es.pidfile}" property="integ.pid"/>
<echo>Shutting down external node PID ${integ.pid}</echo>
<!-- verify with jps that this actually is the correct pid.
See if we can find the line "pid org.elasticsearch.bootstrap.Elasticsearch" in the output of jps -l.-->
<exec executable="jps">
<arg value="-l"/>
<redirector outputproperty="jps.pid.line">
<outputfilterchain>
<linecontains>
<contains value="${integ.pid} org.elasticsearch.bootstrap.Elasticsearch"/>
</linecontains>
</outputfilterchain>
</redirector>
</exec>
<fail
message="pid file at @{es.pidfile} is ${integ.pid} but jps -l did not report any process with org.elasticsearch.bootstrap.Elasticsearch and this pid.
Did you run mvn clean? Maybe an old pid file is still lying around.">
<condition>
<not>
<isset property="jps.pid.line"/>
</not>
</condition>
</fail>
<exec executable="taskkill" failonerror="true" osfamily="winnt">
<arg value="/F"/>
<arg value="/PID"/>
<arg value="${integ.pid}"/>
</exec>
<exec executable="kill" failonerror="true" osfamily="unix">
<arg value="-9"/>
<arg value="${integ.pid}"/>
</exec>
<delete file="@{es.pidfile}"/>
</sequential>
</macrodef>
<!-- starts a unicast node on an already setup workspace-->
<macrodef name="start-unicast-node">
<attribute name="es.http.port" default="${integ.http.port}"/>
<attribute name="es.transport.port" default="${integ.transport.port}"/>
<attribute name="es.pidfile" default="${integ.pidfile}"/>
<attribute name="es.peer.list" />
<sequential>
<startup-elasticsearch es.pidfile="@{es.pidfile}" es.unicast.enabled="true"
es.transport.tcp.port="@{es.transport.port}" es.http.port="@{es.http.port}"
es.unicast.hosts="@{es.peer.list}"/>
</sequential>
</macrodef>
<!-- unzip the elasticsearch zip -->
<target name="setup-workspace" depends="stop-external-cluster">
<sequential>
<delete dir="${integ.scratch}"/>
<unzip src="${integ.deps}/elasticsearch-${elasticsearch.version}.zip" dest="${integ.scratch}"/>
</sequential>
</target>
<!-- run elasticsearch in the foreground (for debugging etc) -->
<!-- TODO: doesn't belong here, but we will figure it out -->
<target name="start-foreground" depends="stop-external-cluster">
<delete dir="${integ.scratch}"/>
<unzip src="${project.build.directory}/releases/${project.artifactId}-${project.version}.zip" dest="${integ.scratch}"/>
<local name="home"/>
<property name="home" location="${integ.scratch}/${project.artifactId}-${elasticsearch.version}"/>
<startup-elasticsearch spawn="false" home="${home}"
jvm.args="${tests.jvm.argline} -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"/>
</target>
<!-- unzip core release artifact, install plugin, then start ES -->
<target name="start-external-cluster-with-plugin" depends="setup-workspace">
<install-plugin name="${project.artifactId}" file="${project.build.directory}/releases/${project.artifactId}-${project.version}.zip"/>
<startup-elasticsearch/>
</target>
<target name="stop-external-cluster" if="integ.pidfile.exists">
<stop-node/>
</target>
<!-- distribution tests: .zip -->
<target name="setup-workspace-zip" depends="stop-external-cluster">
<sequential>
<delete dir="${integ.scratch}"/>
<unzip src="${project.build.directory}/releases/${project.artifactId}-${project.version}.zip"
dest="${integ.scratch}"/>
</sequential>
</target>
<target name="start-external-cluster-zip" depends="setup-workspace-zip">
<startup-elasticsearch/>
</target>
<!-- distribution tests: .tar.gz -->
<target name="setup-workspace-tar" depends="stop-external-cluster">
<sequential>
<delete dir="${integ.scratch}"/>
<untar src="${project.build.directory}/releases/${project.artifactId}-${project.version}.tar.gz"
dest="${integ.scratch}"
compression="gzip"/>
</sequential>
</target>
<target name="start-external-cluster-tar" depends="setup-workspace-tar">
<startup-elasticsearch/>
</target>
<!-- distribution tests: .deb -->
<target name="setup-workspace-deb" depends="stop-external-cluster">
<sequential>
<delete dir="${integ.scratch}"/>
<mkdir dir="${integ.scratch}/deb-extracted"/>
<local name="debfile"/>
<property name="debfile" location="${project.build.directory}/releases/${project.artifactId}-${project.version}.deb"/>
<!-- print some basic package info -->
<exec executable="dpkg-deb" failonerror="true" taskname="deb-info">
<arg value="-I"/>
<arg value="${debfile}"/>
</exec>
<!-- extract contents from .deb package -->
<exec executable="dpkg-deb" failonerror="true">
<arg value="-x"/>
<arg value="${debfile}"/>
<arg value="${integ.scratch}/deb-extracted"/>
</exec>
</sequential>
</target>
<target name="start-external-cluster-deb" depends="setup-workspace-deb">
<startup-elasticsearch home="${integ.scratch}/deb-extracted/usr/share/elasticsearch/"/>
</target>
<!-- distribution tests: .rpm -->
<target name="setup-workspace-rpm" depends="stop-external-cluster">
<sequential>
<delete dir="${integ.scratch}"/>
<!-- use full paths with paranoia, we will be doing relocations -->
<local name="rpm.file"/>
<local name="rpm.database"/>
<local name="rpm.extracted"/>
<property name="rpm.file" location="${project.build.directory}/releases/${project.artifactId}-${project.version}.rpm"/>
<property name="rpm.database" location="${integ.scratch}/rpm-database"/>
<property name="rpm.extracted" location="${integ.scratch}/rpm-extracted"/>
<mkdir dir="${rpm.database}"/>
<mkdir dir="${rpm.extracted}"/>
<!-- print some basic package info -->
<exec executable="rpm" failonerror="true" taskname="rpm-info">
<arg value="-q"/>
<arg value="-i"/>
<arg value="-p"/>
<arg value="${rpm.file}"/>
</exec>
<!-- extract contents from .rpm package -->
<exec executable="rpm" failonerror="true" taskname="rpm">
<arg value="--dbpath"/>
<arg value="${rpm.database}"/>
<arg value="--badreloc"/>
<arg value="--relocate"/>
<arg value="/=${rpm.extracted}"/>
<arg value="--nodeps"/>
<arg value="--noscripts"/>
<arg value="--notriggers"/>
<arg value="-i"/>
<arg value="${rpm.file}"/>
</exec>
</sequential>
</target>
<target name="start-external-cluster-rpm" depends="setup-workspace-rpm">
<startup-elasticsearch home="${integ.scratch}/rpm-extracted/usr/share/elasticsearch/"/>
</target>
<!-- check shaded jar for jar hell -->
<target name="check-for-jar-hell">
<java failonerror="true" fork="true" classname="org.elasticsearch.bootstrap.JarHell">
<classpath>
<pathelement location="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
<pathelement location="${org.apache.lucene:lucene-core:jar}"/>
</classpath>
</java>
</target>
<target name="check-shaded-jar-packages">
<!-- we unzip the jar, vs zipfileset, zipfileset toString is useless -->
<delete dir="${integ.temp}/unzipped"/>
<mkdir dir="${integ.temp}/unzipped"/>
<unzip src="${project.build.directory}/${project.artifactId}-${project.version}.jar"
dest="${integ.temp}/unzipped"/>
<local name="unshaded.classes"/>
<fileset id="unshaded.classes"
dir="${integ.temp}/unzipped"
includes="**/*.class"
excludes="org/elasticsearch/**,org/apache/lucene/**"/>
<fail message="shaded jar contains packages outside of org.elasticsearch: ${toString:unshaded.classes}">
<condition>
<not>
<resourcecount count="0">
<fileset refid="unshaded.classes"/>
</resourcecount>
</not>
</condition>
</fail>
</target>
</project>