forked from liferay/liferay-portal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-test-analytics-cloud.xml
906 lines (667 loc) · 25.7 KB
/
build-test-analytics-cloud.xml
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
<?xml version="1.0"?>
<project basedir="." name="portal-test-analytics-cloud" xmlns:antelope="antlib:ise.antelope.tasks">
<import file="build-test.xml" />
<macrodef name="build-analytics-cloud-images">
<sequential>
<create-analytics-cloud-docker-compose start.analytics.cloud="false" />
<if>
<available file="${project.dir}/dist/liferay-docker-asah.tar" />
<then>
<execute>
docker load --input ${project.dir}/dist/liferay-docker-asah.tar
</execute>
</then>
<else>
<pull-docker-image-dependencies
analytics.cloud.image.names.excludes="${analytics.cloud.asah.image.names.excludes}"
analytics.cloud.repository.dir="${analytics.cloud.asah.dir}"
/>
<execute dir="${analytics.cloud.asah.dir}">
./gradlew jar -Dliferay.ci=true
./gradlew clean assemble -Dliferay.ci=true
docker compose --file=${analytics.cloud.docker.test.yaml} --project-name=${analytics.cloud.project.name} build
docker images
</execute>
<for list="${analytics.cloud.asah.image.names}" param="analytics.cloud.asah.image.name">
<sequential>
<if>
<not>
<matches pattern=".*com-liferay-osb-.*" string="@{analytics.cloud.asah.image.name}" />
</not>
<then>
<execute dir="${project.dir}">
docker pull @{analytics.cloud.asah.image.name}
</execute>
</then>
</if>
</sequential>
</for>
<antelope:stringutil property="analytics.cloud.asah.image.names.list" string="${analytics.cloud.asah.image.names}">
<antelope:replace regex="," replacement=" " />
</antelope:stringutil>
<execute dir="${project.dir}">
docker save --output ${project.dir}/dist/liferay-docker-asah.tar ${analytics.cloud.asah.image.names.list}
</execute>
</else>
</if>
<if>
<available file="${project.dir}/dist/liferay-docker-faro.tar" />
<then>
<execute>
docker load --input ${project.dir}/dist/liferay-docker-faro.tar
</execute>
</then>
<else>
<download-gradle-wrapper-binary workspace.dir="${analytics.cloud.asah.dir}" />
<pull-docker-image-dependencies
analytics.cloud.image.names.excludes="${analytics.cloud.faro.image.names.excludes}"
analytics.cloud.repository.dir="${analytics.cloud.faro.dir}"
/>
<local name="portal.base.dir" />
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
File analyticsCloudFaroDir = new File(project.getProperty("analytics.cloud.faro.dir"));
File gradleWrapperDir = analyticsCloudFaroDir.getParentFile();
File gradleWrapperFile = new File(gradleWrapperDir, "gradlew");
while (true) {
if (gradleWrapperFile.exists()) {
break;
}
gradleWrapperDir = gradleWrapperDir.getParentFile();
if (gradleWrapperDir == null) {
break;
}
gradleWrapperFile = new File(gradleWrapperDir, "gradlew");
}
if (gradleWrapperFile.exists()) {
project.setProperty("portal.base.dir", JenkinsResultsParserUtil.getCanonicalPath(gradleWrapperFile.getParentFile()));
project.setProperty("portal.gradlew", JenkinsResultsParserUtil.getCanonicalPath(gradleWrapperFile));
}
else {
project.setProperty("portal.gradlew", "gradle");
}
]]>
</beanshell>
<if>
<and>
<available file="${portal.base.dir}" />
<not>
<equals arg1="${portal.base.dir}" arg2="${project.dir}" />
</not>
</and>
<then>
<echo>Set up portal for OSB Faro (${portal.base.dir}).</echo>
<execute dir="${portal.base.dir}">
ant setup-profile-dxp
ant setup-sdk
ant setup-libs
ant compile
ant install-portal-snapshots
</execute>
</then>
</if>
<loadfile
property="analytics.cloud.docker.test.yaml.content"
srcfile="${analytics.cloud.docker.test.yaml}"
/>
<propertyregex
input="${analytics.cloud.docker.test.yaml.content}"
override="true"
property="analytics.cloud.faro.tag.name"
regexp="[\S\s]*image: (liferay\/com-liferay-osb-faro\:[^\s]+)[\S\s]*"
replace="\1"
/>
<execute dir="${analytics.cloud.faro.dir}">
${portal.gradlew} createDocker -Pcom.liferay.osb.faro.environment.name=local -Dliferay.ci=true
docker tag ${analytics.cloud.faro.image.name} ${analytics.cloud.faro.tag.name}
docker rm ${analytics.cloud.faro.container.name}
docker save --output ${project.dir}/dist/liferay-docker-faro.tar ${analytics.cloud.faro.image.name}
</execute>
</else>
</if>
</sequential>
</macrodef>
<macrodef name="create-analytics-cloud-docker-compose">
<attribute default="false" name="start.analytics.cloud" />
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<var name="analytics.cloud.docker.test.yaml" unset="true" />
<var name="analytics.cloud.service.images.available" unset="true" />
<property location="${analytics.cloud.asah.dir}/docker-compose.test.yml" name="analytics.cloud.docker.test.yaml" />
<mkdir dir="${project.dir}/dist" />
<get-host-git-dir />
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
public void downloadImageTarFile(File imageTarFile) {
if (imageTarFile.exists()) {
return;
}
String distPath = getDistPath();
if (JenkinsResultsParserUtil.isNullOrEmpty(distPath)) {
return;
}
File parentDir = imageTarFile.getParentFile();
parentDir.mkdirs();
long analyticsCloudRsyncTimeout = Long.valueOf(project.getProperty("analytics.cloud.rsync.timeout"));
int retryCount = 0;
while (true) {
String distNode = getDistNode();
if (JenkinsResultsParserUtil.isNullOrEmpty(distNode)) {
return;
}
StringBuilder sb = new StringBuilder();
sb.append("time timeout ");
sb.append(analyticsCloudRsyncTimeout / 1000);
sb.append(" rsync -qs ");
sb.append(distNode);
sb.append(":");
sb.append(distPath);
sb.append("/");
sb.append(imageTarFile.getName());
sb.append(" ");
sb.append(JenkinsResultsParserUtil.getCanonicalPath(imageTarFile));
sb.append(" ");
try {
Process process = JenkinsResultsParserUtil.executeBashCommands(false, new File("."), analyticsCloudRsyncTimeout, new String[] {sb.toString()});
if (process.exitValue() != 0) {
continue;
}
System.out.println(JenkinsResultsParserUtil.readInputStream(process.getInputStream()));
break;
}
catch (Exception exception) {
continue;
}
finally {
if (retryCount >= 2) {
System.out.println("WARNING: Unable to download " + imageTarFile.getName() + " after " + retryCount + " retries");
}
retryCount++;
}
break;
}
}
public void downloadImageTarFiles() {
File distDir = new File(project.getProperty("project.dir") + "/dist");
downloadImageTarFile(new File(distDir, "liferay-docker-asah.tar"));
downloadImageTarFile(new File(distDir, "liferay-docker-faro.tar"));
}
public void dumpYamlMap(Map yamlMap) {
Yaml yaml = getYaml();
FileWriter fileWriter = new FileWriter(new File(project.getProperty("analytics.cloud.docker.test.yaml")));
yaml.dump(yamlMap, fileWriter);
}
public String getAnalyticsCloudAsahImageNames(Map dockerComposeMap) {
StringBuilder sb = new StringBuilder();
Map servicesMap = dockerComposeMap.get("services");
for (String serviceName : servicesMap.keySet()) {
Map serviceMap = servicesMap.get(serviceName);
if (serviceName.contains("faro")) {
continue;
}
String imageName = serviceMap.get("image");
if (JenkinsResultsParserUtil.isNullOrEmpty(imageName)) {
imageName = "com-liferay-osb-asah-private-" + serviceName;
}
sb.append(imageName);
sb.append(",");
}
if (sb.length() > 0) {
sb.setLength(sb.length() - 1);
}
return sb.toString();
}
public String getDistNode() {
String distNodes = project.getProperty("env.DIST_NODES");
if (JenkinsResultsParserUtil.isNullOrEmpty(distNodes)) {
return null;
}
return JenkinsResultsParserUtil.getRandomString(Arrays.asList(distNodes.split(",")));
}
public String getDistPath() {
String distPath = project.getProperty("env.DIST_PATH");
if (JenkinsResultsParserUtil.isNullOrEmpty(distPath)) {
return null;
}
distPath = distPath.replaceAll("\\(", "\\\\(");
distPath = distPath.replaceAll("\\)", "\\\\)");
return distPath;
}
public Map getDockerComposeMap() {
Yaml yaml = getYaml();
InputStream inputStream = new FileInputStream(project.getProperty("analytics.cloud.asah.dir") + "/docker-compose.yml");
return yaml.load(inputStream);
}
public List getServiceNames(Map dockerComposeMap) {
Map servicesMap = dockerComposeMap.get("services");
return new ArrayList(servicesMap.keySet());
}
public getShortHostname() {
String hostname = project.getProperty("env.HOSTNAME");
String hostnameRegex = "(cloud-[^\\.]+|test-\\d+-\\d+-\\d+)(\\.lax\\.liferay\\.com)?";
if (!hostname.matches(hostnameRegex)) {
return null;
}
return hostname.replaceAll(hostnameRegex, "$1");
}
public Yaml getYaml() {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setIndent(4);
return new Yaml(dumperOptions);
}
public boolean serviceImagesAvailable(Map dockerComposeMap) {
Map servicesMap = dockerComposeMap.get("services");
for (String serviceName : servicesMap.keySet()) {
File serviceImageTarFile = new File(project.getProperty("project.dir") + "/dist/liferay-docker-" + serviceName + ".tar");
if (!serviceImageTarFile.exists()) {
System.out.println("Could not find " + serviceImageTarFile);
return false;
}
}
return true;
}
public void updateDockerNetwork(Map dockerComposeMap) {
String shortHostname = getShortHostname();
if (shortHostname == null) {
return;
}
Map defaultMap = new HashMap();
Map externalMap = new HashMap();
Map nameMap = new HashMap();
Map networksMap = new HashMap();
dockerComposeMap.put("networks", networksMap);
networksMap.put("default", defaultMap);
defaultMap.put("external", externalMap);
externalMap.put("name", shortHostname);
}
public void updateOSBFaroFrontendService(Map dockerComposeMap) {
Map servicesMap = dockerComposeMap.get("services");
Map osbFaroFrontendServiceMap = servicesMap.get("osbfarofrontend");
osbFaroFrontendServiceMap.put("container_name", project.getProperty("analytics.cloud.faro.container.name"));
osbFaroFrontendServiceMap.put("image", project.getProperty("analytics.cloud.faro.image.name"));
List ports = osbFaroFrontendServiceMap.get("ports");
ports.remove("8080:8080");
ports.remove("11311:11311");
ports.add(project.getProperty("analytics.cloud.faro.dxp.port") + ":8080");
ports.add(project.getProperty("analytics.cloud.faro.osgi.console.port") + ":11311");
osbFaroFrontendServiceMap.put("ports", ports);
}
public void updateServiceImages(Map dockerComposeMap) {
if (!"@{start.analytics.cloud}".equals("true")) {
return;
}
Map servicesMap = dockerComposeMap.get("services");
for (String serviceName : servicesMap.keySet()) {
Map serviceMap = servicesMap.get(serviceName);
if (serviceMap.containsKey("image")) {
continue;
}
serviceMap.put("image", "com-liferay-osb-asah-private-" + serviceName);
}
}
public void updateVolumes(Map dockerComposeMap) {
String hostGitDir = project.getProperty("host.git.dir");
if (JenkinsResultsParserUtil.isNullOrEmpty(hostGitDir)) {
return;
}
Map servicesMap = dockerComposeMap.get("services");
for (String serviceName : servicesMap.keySet()) {
Map serviceMap = servicesMap.get(serviceName);
List updatedVolumes = new ArrayList();
List currentVolumes = serviceMap.get("volumes");
if (currentVolumes == null) {
continue;
}
for (String currentVolume : currentVolumes) {
updatedVolumes.add(currentVolume.replaceAll("\\./", hostGitDir + "/com-liferay-osb-asah-private/"));
}
serviceMap.put("volumes", updatedVolumes);
}
}
downloadImageTarFiles();
Map dockerComposeMap = getDockerComposeMap();
updateDockerNetwork(dockerComposeMap);
updateOSBFaroFrontendService(dockerComposeMap);
updateServiceImages(dockerComposeMap);
updateVolumes(dockerComposeMap);
dumpYamlMap(dockerComposeMap);
project.setProperty("analytics.cloud.asah.image.names", getAnalyticsCloudAsahImageNames(dockerComposeMap));
]]>
</beanshell>
<local name="analytics.cloud.faro.build.gradle" />
<condition else="${analytics.cloud.faro.dir}/build.gradle" property="analytics.cloud.faro.build.gradle" value="${analytics.cloud.faro.dir}/build-ext.gradle">
<available file="${analytics.cloud.faro.dir}/build-ext.gradle" />
</condition>
<replaceregexp
file="${analytics.cloud.faro.build.gradle}"
match="def dockerContainerId = \"([^\"]+)\""
replace="def dockerContainerId = \"${analytics.cloud.faro.container.name}\""
/>
<replaceregexp
file="${analytics.cloud.faro.build.gradle}"
match="network \"([^\"]+)\""
replace="network \"${analytics.cloud.project.name}_default\""
/>
<replaceregexp
file="${analytics.cloud.faro.dir}/osb-faro-docker/local/Dockerfile"
match="FARO_URL=http://localhost:8080"
replace="FARO_URL=${analytics.cloud.faro.frontend.url}"
/>
<echo file="${analytics.cloud.asah.dir}/local.env">OSB_ASAH_BACKEND_URL=${analytics.cloud.asah.backend.url}
OSB_ASAH_POSTGRESQL_ENABLED=false
OSB_ASAH_PUBLISHER_URL=${analytics.cloud.asah.publisher.url}
OSB_FARO_FRONTEND_URL=${analytics.cloud.faro.frontend.url}</echo>
<if>
<isset property="test.portal.license.url" />
<then>
<mkdir dir="${analytics.cloud.faro.dir}/osb-faro-docker/common/license/" />
<mirrors-get
dest="${analytics.cloud.faro.dir}/osb-faro-docker/common/license/"
src="${test.portal.license.url}"
/>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="print-analytics-cloud-logs">
<sequential>
<execute>
docker stats --no-stream
</execute>
<property location="${analytics.cloud.asah.dir}/docker-compose.test.yml" name="analytics.cloud.docker.test.yaml" />
<local name="container.names" />
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public static List getContainerNames() {
File dockerComposeFile = new File(project.getProperty("analytics.cloud.docker.test.yaml"));
if (!dockerComposeFile.exists()) {
return new ArrayList();
}
List containerNames = new ArrayList();
String content = JenkinsResultsParserUtil.read(dockerComposeFile);
Pattern pattern = Pattern.compile("container_name: (.*)");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
containerNames.add(matcher.group(1));
}
return containerNames;
}
project.setProperty("container.names", JenkinsResultsParserUtil.join(",", getContainerNames()))
]]>
</beanshell>
<local name="docker.logs.dir" />
<condition else="/tmp/docker-logs" property="docker.logs.dir" value="${env.BUILD_DIR}/docker-logs">
<and>
<isset property="env.BUILD_DIR" />
<isset property="env.BUILD_USER_CONTENT_URL" />
</and>
</condition>
<mkdir dir="${docker.logs.dir}" />
<for list="${container.names}" param="container.name">
<sequential>
<local name="container.file.name" />
<beanshell>
<![CDATA[
String containerFileName = "@{container.name}.log";
File containerFile = new File(project.getProperty("docker.logs.dir"), containerFileName);
if (containerFile.exists()) {
continue;
}
project.setProperty("container.file.name", containerFileName);
]]>
</beanshell>
<execute failonerror="false">
<![CDATA[
docker logs @{container.name} > ${docker.logs.dir}/${container.file.name}
]]>
</execute>
<if>
<isset property="env.BUILD_USER_CONTENT_URL" />
<then>
<echo>${env.BUILD_USER_CONTENT_URL}/docker-logs/${container.file.name}</echo>
</then>
<else>
<print-file file.name="${docker.logs.dir}/${container.file.name}" />
</else>
</if>
</sequential>
</for>
<for list="${analytics.cloud.jstack.dumps}" param="analytics.cloud.jstack.dump">
<sequential>
<local name="analytics.cloud.container.name" />
<local name="analytics.cloud.java.process" />
<propertyregex
input="@{analytics.cloud.jstack.dump}"
override="true"
property="analytics.cloud.container.name"
regexp="([^=]+)=([^=]+)"
replace="\1"
/>
<propertyregex
input="@{analytics.cloud.jstack.dump}"
override="true"
property="analytics.cloud.java.process"
regexp="([^=]+)=([^=]+)"
replace="\2"
/>
<local name="analytics.cloud.jstack.log.file.name" />
<property name="analytics.cloud.jstack.log.file.name" value="${analytics.cloud.container.name}.${analytics.cloud.java.process}.jstack.log" />
<execute failonerror="false">
<![CDATA[
docker exec ${analytics.cloud.container.name} jstack -l ${analytics.cloud.java.process} > ${docker.logs.dir}/${analytics.cloud.jstack.log.file.name}
]]>
</execute>
<if>
<isset property="env.BUILD_USER_CONTENT_URL" />
<then>
<echo>${env.BUILD_USER_CONTENT_URL}/docker-logs/${analytics.cloud.jstack.log.file.name}</echo>
</then>
<else>
<print-file file.name="${docker.logs.dir}/${analytics.cloud.jstack.log.file.name}" />
</else>
</if>
</sequential>
</for>
</sequential>
</macrodef>
<macrodef name="pull-docker-image-dependencies">
<attribute default="" name="analytics.cloud.image.names.excludes" />
<attribute name="analytics.cloud.repository.dir" />
<sequential>
<local name="analytics.cloud.image.names.excludes" />
<property name="analytics.cloud.image.names.excludes" value="@{analytics.cloud.image.names.excludes}" />
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
String excludedImageNames = project.getProperty("analytics.cloud.image.names.excludes");
JenkinsResultsParserUtil.pullDockerImageDependencies(new File("@{analytics.cloud.repository.dir}"), excludedImageNames.split(","));
]]>
</beanshell>
</sequential>
</macrodef>
<macrodef name="start-analytics-cloud">
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<build-analytics-cloud-images />
<create-analytics-cloud-docker-compose start.analytics.cloud="true" />
<property location="${analytics.cloud.asah.dir}/start_analytics_cloud.sh" name="analytics.cloud.start.sh" />
<print-file file.name="${analytics.cloud.docker.test.yaml}" />
<echo file="${analytics.cloud.start.sh}">
#!/bin/bash
touch local.env
docker system prune --volumes -f
docker-compose --file=${analytics.cloud.docker.test.yaml} --project-name=${analytics.cloud.project.name} up --detach
while [[ -n $(docker ps | grep "health: starting") ]] || [[ -n $(docker ps | grep "unhealthy") ]]
do
echo "Waiting for docker compose to be healthy."
sleep 30
done
echo "Docker compose is healthy."
while [[ -z $(docker logs ${analytics.cloud.faro.container.name} | grep "Completed demo data creation") ]]
do
echo "Waiting for Faro demo data to be created."
sleep 15
done
echo "Faro demo data was created."
docker logs ${analytics.cloud.faro.container.name}
docker system df
</echo>
<trycatch>
<try>
<trycatch property="analytics.cloud.error">
<try>
<local name="analytics.cloud.start.result" />
<exec dir="${analytics.cloud.asah.dir}" executable="/bin/bash" resultproperty="analytics.cloud.start.result" timeout="${analytics.cloud.start.timeout}">
<arg value="${analytics.cloud.start.sh}" />
</exec>
<if>
<not>
<equals arg1="${analytics.cloud.start.result}" arg2="0" />
</not>
<then>
<fail message="Failed to start Analytics Cloud with error code ${analytics.cloud.start.result}." />
</then>
</if>
</try>
<catch>
<print-analytics-cloud-logs />
<stop-analytics-cloud />
<fail message="${analytics.cloud.error}" />
</catch>
</trycatch>
</try>
<catch>
<fail message="${analytics.cloud.error}" />
</catch>
</trycatch>
<delete file="${analytics.cloud.start.sh}" />
</sequential>
</macrodef>
<macrodef name="start-analytics-cloud-integration">
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<replaceregexp
file="${analytics.cloud.asah.dir}/docker-compose.integration-test.yml"
match="\"9200:9200\""
replace=""${analytics.cloud.asah.elasticsearch.port}:9200""
/>
<local name="short.hostname" />
<propertyregex
input="${env.HOSTNAME}"
override="true"
property="short.hostname"
regexp="(cloud-[^\.]+|test-\d+-\d+-\d+)(\.lax\.liferay\.com)?"
replace="\1"
/>
<if>
<isset property="short.hostname" />
<then>
<echo append="true" file="${analytics.cloud.asah.dir}/docker-compose.integration-test.yml"><![CDATA[
networks:
default:
external:
name: ${short.hostname}]]></echo>
</then>
</if>
<pull-docker-image-dependencies
analytics.cloud.image.names.excludes="${analytics.cloud.asah.image.names.excludes}"
analytics.cloud.repository.dir="${analytics.cloud.asah.dir}"
/>
<execute dir="${analytics.cloud.asah.dir}">
docker-compose -f docker-compose.integration-test.yml up -d
docker ps
</execute>
<exec executable="/bin/bash" outputproperty="network.ip.address">
<arg value="-c" />
<arg value="docker inspect ${short.hostname} -f '{{range .NetworkSettings.Networks}}{{.Gateway}}{{end}}'" />
</exec>
<echo file="${analytics.cloud.asah.dir}/temp-build-ext.gradle">import org.apache.tools.ant.taskdefs.condition.Os
subprojects {
tasks.withType(Test) {
doFirst {
environment "LCP_ENGINE_ELASTICSEARCH_SERVER_IP", "${network.ip.address}"
environment "LCP_PROJECT_ID", "test"
environment "POSTGRESQL_SERVER_IP", "test_postgresql"
environment "OSB_ASAH_BIG_QUERY_URL", "http://${network.ip.address}:9050"
environment "OSB_ASAH_PUBSUB_EMULATOR_URL", "http://${network.ip.address}:8095"
environment "OSB_ASAH_REDIS_URL", "http://${network.ip.address}:6379"
environment.remove("GOOGLE_APPLICATION_CREDENTIALS")
}
maxHeapSize = "4096m"
}
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
subprojects {
afterEvaluate {
project.tasks.withType(Test) {
environment "DOCKER_COMPOSE_LOCATION", "C:/Program Files/Docker/Docker/resources/bin/docker-compose.exe"
environment "DOCKER_LOCATION", "C:/Program Files/Docker/Docker/resources/bin/docker.exe"
}
}
}
}</echo>
<copy
file="${analytics.cloud.asah.dir}/temp-build-ext.gradle"
tofile="${analytics.cloud.asah.dir}/build-ext.gradle"
/>
<execute dir="${analytics.cloud.asah.dir}">
docker ps
docker network ls
docker network inspect ${short.hostname}
cat build-ext.gradle
./gradlew testIntegration
</execute>
</sequential>
</macrodef>
<macrodef name="stop-analytics-cloud">
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<create-analytics-cloud-docker-compose start.analytics.cloud="true" />
<property location="${analytics.cloud.asah.dir}/docker-compose.test.yml" name="analytics.cloud.docker.test.yaml" />
<execute dir="${analytics.cloud.asah.dir}">
docker ps -a
touch local.env
docker-compose --file=${analytics.cloud.docker.test.yaml} --project-name=${analytics.cloud.project.name} down --volumes
docker system df
</execute>
</sequential>
</macrodef>
<macrodef name="stop-analytics-cloud-integration">
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<execute dir="${analytics.cloud.asah.dir}">
docker ps -a
docker-compose -f docker-compose.integration-test.yml down --volumes
docker system df
</execute>
</sequential>
</macrodef>
<target name="build-analytics-cloud-images">
<build-analytics-cloud-images />
</target>
<target name="start-analytics-cloud">
<stop-analytics-cloud />
<start-analytics-cloud />
</target>
<target name="start-analytics-cloud-integration">
<stop-analytics-cloud-integration />
<start-analytics-cloud-integration />
</target>
<target name="stop-analytics-cloud">
<print-analytics-cloud-logs />
<stop-analytics-cloud />
</target>
<target name="stop-analytics-cloud-integration">
<print-analytics-cloud-logs />
<stop-analytics-cloud-integration />
</target>
</project>