forked from elastic/kibana
/
build.gradle
executable file
·110 lines (95 loc) · 3.65 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
@description: Build tasks for cloud provisioning and executing tests
@author: Liza Dayoub
*/
import com.sun.org.apache.xalan.internal.xslt.Process
import groovy.json.JsonSlurper
import groovy.json.JsonException
import org.estf.gradle.SetupCloudCluster
import org.estf.gradle.DeleteCloudCluster
group 'org.estf.cloud'
version '1.0'
project.ext.sdkVersion = '1.2.0-SNAPSHOT'
apply plugin: 'groovy'
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
/**
* This task download the cloud-java-sdk to libs/
* Github makes it difficult to download artifacts from the releases page.
* First, we must locate the asset for the release by tag.
* Next, we must find the asset's URL in the response, and make a request to download it following redirects.
*
* THIS IS TEMPORARY UNTIL WE HAVE A PRIVATE COMMON MAVEN FOR ALL TEAMS TO SHARE
*/
task getJavaSdk {
def libsFolder = new File('libs')
if (!libsFolder.exists()) {
libsFolder.mkdirs()
}
def ghOwner = System.env['GH_OWNER']
def ghToken = System.env['GH_TOKEN']
if (ghOwner == null || ghToken == null) {
throw new GradleException('GH_OWNER and GH_TOKEN must be set.')
}
def getReleaseByTagTemplate = 'https://api.github.com/repos/%s/cloud-sdk-java/releases/tags/v%s?access_token=%s'
def getReleaseByTagUrl = String.format(getReleaseByTagTemplate, ghOwner, project.sdkVersion, ghToken)
def getReleaseByTagCommand = ['curl', getReleaseByTagUrl]
def getReleaseByTagResponse = getReleaseByTagCommand.execute()
handleCurlExitCode(getReleaseByTagResponse, getReleaseByTagCommand)
def json = new JsonSlurper().parseText(getReleaseByTagResponse.text)
handleErrorMessage(json, getReleaseByTagUrl)
def assetUrl = json.assets[0].url + "?access_token=${ghToken}"
def filename = "libs/${json.assets[0].name}"
def getAssetCommand =
['curl', '-L', '-H', 'Accept: application/octet-stream', assetUrl, '-o', filename]
def getAssetResponse = getAssetCommand.execute()
handleCurlExitCode(getAssetResponse, getAssetCommand)
// If the download fails, the error message will be written as the contents of the .jar.
// If the .jar is a parseable json body we can assume something went wrong with the download.
try {
json = new JsonSlurper().parseText(new File(filename).text)
handleErrorMessage(json, assetUrl)
} catch (JsonException jsonException) {
// NOP
}
}
def handleErrorMessage(json, url) {
if (json.message) {
throw new GradleException("An error message was returned when attempting to find the release by tag\n" +
"URL: ${url}\n" +
"ERROR: ${json.message}")
}
}
def handleCurlExitCode(response, command) {
if (response.waitFor() != 0) {
throw new GradleException("The following command exited with nonzero status\n" +
"Command: ${command}")
}
}
dependencies {
compile group: 'co.elastic.cloud', name: 'sdk-java', version: project.sdkVersion
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
def genSetupTask(testname) {
return tasks.create("setup_" + testname, SetupCloudCluster)
}
def genCleanupTask(testname, clusterId) {
return tasks.create("cleanup_" + testname, DeleteCloudCluster) {
cluster_id = clusterId
}
}
task someTest {
doFirst {
def _setup_task = genSetupTask(name)
_setup_task.execute()
println "sleeping 25s ......."
// TODO: Here is where we plugin in the callable for system test
sleep(25 * 1000)
genCleanupTask(name, _setup_task.getClusterId()).execute()
}
}