forked from liferay/liferay-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-test-elasticsearch6.xml
848 lines (733 loc) · 25.2 KB
/
build-test-elasticsearch6.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
<?xml version="1.0"?>
<project basedir="." name="portal-test-elasticsearch" xmlns:antelope="antlib:ise.antelope.tasks">
<import file="build-test.xml" />
<macrodef name="configure-elasticsearch-properties">
<sequential>
<echo append="true" file="${elasticsearch.dir}/config/elasticsearch.yml">${line.separator}cluster.name: LiferayElasticsearchCluster</echo>
</sequential>
</macrodef>
<macrodef name="configure-elasticsearch-x-pack-security-properties">
<sequential>
<echo append="true" file="${elasticsearch.dir}/config/elasticsearch.yml">${line.separator}xpack.security.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.ssl.certificate: certs/localhost/localhost.crt
xpack.ssl.certificate_authorities: [ "certs/ca/ca.crt" ]
xpack.ssl.key: certs/localhost/localhost.key</echo>
</sequential>
</macrodef>
<macrodef name="configure-kibana-properties">
<sequential>
<echo append="true" file="${elastic.kibana.dir}/config/kibana.yml">${line.separator}elasticsearch.url: "http://localhost:9200"
pid.file: ${elastic.kibana.dir}/bin/pid-kibana
server.basePath: "/o/portal-search-elasticsearch-xpack-monitoring/xpack-monitoring-proxy"
server.rewriteBasePath: false</echo>
</sequential>
</macrodef>
<macrodef name="configure-kibana-x-pack-security-properties">
<sequential>
<echo append="true" file="${elastic.kibana.dir}/config/kibana.yml">${line.separator}elasticsearch.password: "${elastic.xpack.kibana.user.password}"
elasticsearch.ssl.certificateAuthorities: [ "${elasticsearch.dir}-1/config/certs/ca/ca.crt" ]
elasticsearch.username: "kibana"
server.ssl.certificate: ${elasticsearch.dir}-1/config/certs/localhost/localhost.crt
server.ssl.enabled: true
server.ssl.key: ${elasticsearch.dir}-1/config/certs/localhost/localhost.key
xpack.security.encryptionKey: "xsomethingxatxleastx32xcharactersx"
xpack.security.sessionTimeout: 600000</echo>
<replace
file="${elastic.kibana.dir}/config/kibana.yml"
>
<replacetoken><![CDATA[elasticsearch.url: "http://localhost:9200"]]></replacetoken>
<replacevalue><![CDATA[elasticsearch.url: "https://localhost:9200"]]></replacevalue>
</replace>
</sequential>
</macrodef>
<macrodef name="configure-portal-elasticsearch-osgi-properties">
<sequential>
<echo append="true" file="${liferay.home}/osgi/configs/com.liferay.portal.search.elasticsearch6.configuration.ElasticsearchConfiguration.config">${line.separator}operationMode="REMOTE"</echo>
</sequential>
</macrodef>
<macrodef name="configure-portal-x-pack-osgi-properties">
<sequential>
<propertyregex
defaultValue="${elastic.xpack.elastic.user.password}"
input="${elastic.xpack.elastic.user.password}"
override="true"
property="osgi.config.elastic.user.password"
regexp="="
replace="\\\\="
/>
<echo append="true" file="${liferay.home}/osgi/configs/com.liferay.portal.search.elasticsearch6.xpack.monitoring.web.internal.configuration.XPackMonitoringConfiguration.config">kibanaPassword="${osgi.config.elastic.user.password}"
kibanaURL="https://localhost:5601"
proxyServletLogEnable="true"</echo>
<echo append="true" file="${liferay.home}/osgi/configs/com.liferay.portal.search.elasticsearch6.xpack.security.internal.configuration.XPackSecurityConfiguration.config">certificateFormat="PEM"
password="${osgi.config.elastic.user.password}"
requiresAuthentication="true"
sslCertificateAuthoritiesPaths="${elasticsearch.dir}-1/config/certs/ca/ca.crt"
sslCertificatePath="${elasticsearch.dir}-1/config/certs/localhost/localhost.crt"
sslKeyPath="${elasticsearch.dir}-1/config/certs/localhost/localhost.key"
transportSSLEnabled="true"</echo>
</sequential>
</macrodef>
<macrodef name="configure-portal-x-pack-security-truststore">
<sequential>
<if>
<os family="unix" />
<then>
<exec dir="${elasticsearch.dir}-1/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="./elasticsearch-certutil cert --ca-cert ${elasticsearch.dir}-1/config/certs/ca/ca.crt --ca-key ${elasticsearch.dir}-1/config/certs/ca/ca.key --pass liferay --ip 127.0.0.1 --dns localhost --name localhost --out ${elasticsearch.dir}-1/config/certs/localhost.p12" />
</exec>
<exec dir="${elasticsearch.dir}-1/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="keytool -importkeystore -deststorepass liferay -destkeystore ${elasticsearch.dir}-1/config/certs/localhost.jks -srckeystore ${elasticsearch.dir}-1/config/certs/localhost.p12 -srcstoretype PKCS12 -srcstorepass liferay" />
</exec>
</then>
<elseif>
<os family="windows" />
<then>
<exec dir="${elasticsearch.dir}-1/bin" executable="cmd">
<arg value="/c" />
<arg value="elasticsearch-certutil cert --ca-cert ${elasticsearch.dir}-1/config/certs/ca/ca.crt --ca-key ${elasticsearch.dir}-1/config/certs/ca/ca.key --pass liferay --ip 127.0.0.1 --dns localhost --name localhost --out ${elasticsearch.dir}-1/config/certs/localhost.p12" />
</exec>
<exec dir="${elasticsearch.dir}-1/bin" executable="cmd">
<arg value="/c" />
<arg value="keytool -importkeystore -deststorepass liferay -destkeystore ${elasticsearch.dir}-1/config/certs/localhost.jks -srckeystore ${elasticsearch.dir}-1/config/certs/localhost.p12 -srcstoretype PKCS12 -srcstorepass liferay" />
</exec>
</then>
</elseif>
</if>
<if>
<equals arg1="${app.server.type}" arg2="tomcat" />
<then>
<echo append="true" file="${app.server.tomcat.dir}/bin/setenv.bat">
${line.separator}CATALINA_OPTS="${CATALINA_OPTS} -Djavax.net.ssl.trustStore=${elasticsearch.dir}-1/config/certs/localhost.jks -Djavax.net.ssl.trustStorePassword=liferay"</echo>
<echo append="true" file="${app.server.tomcat.dir}/bin/setenv.sh">
${line.separator}CATALINA_OPTS="${CATALINA_OPTS} -Djavax.net.ssl.trustStore=${elasticsearch.dir}-1/config/certs/localhost.jks -Djavax.net.ssl.trustStorePassword=liferay"</echo>
</then>
<else>
<echo>Set setenv.bat and setenv.sh manually before attempting to connect with portal.</echo>
</else>
</if>
</sequential>
</macrodef>
<macrodef name="generate-x-pack-security-certificates">
<sequential>
<if>
<os family="unix" />
<then>
<exec dir="${elasticsearch.dir}/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="./elasticsearch-certutil ca --pem --ca-dn CN=localhost --out elastic-stack-ca.zip" />
</exec>
</then>
<elseif>
<os family="windows" />
<then>
<exec dir="${elasticsearch.dir}/bin" executable="cmd">
<arg value="/c" />
<arg value="elasticsearch-certutil ca --pem --ca-dn CN=localhost --out elastic-stack-ca.zip" />
</exec>
</then>
</elseif>
</if>
<unzip
dest="${elasticsearch.dir}/bin"
src="${elasticsearch.dir}/bin/elastic-stack-ca.zip"
/>
<if>
<os family="unix" />
<then>
<exec dir="${elasticsearch.dir}/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="./elasticsearch-certutil cert --ca-cert ca/ca.crt --ca-key ca/ca.key --pem --ip 127.0.0.1 --dns localhost --name localhost --out certificate-bundle.zip" />
</exec>
</then>
<elseif>
<os family="windows" />
<then>
<exec dir="${elasticsearch.dir}/bin" executable="cmd">
<arg value="/c" />
<arg value="elasticsearch-certutil cert --ca-cert ca/ca.crt --ca-key ca/ca.key --pem --ip 127.0.0.1 --dns localhost --name localhost --out certificate-bundle.zip" />
</exec>
</then>
</elseif>
</if>
<unzip
dest="${elasticsearch.dir}/bin"
src="${elasticsearch.dir}/bin/certificate-bundle.zip"
/>
<move
file="${elasticsearch.dir}/bin/ca"
todir="${elasticsearch.dir}/config/certs"
/>
<move
file="${elasticsearch.dir}/bin/localhost"
todir="${elasticsearch.dir}/config/certs"
/>
<delete file="${elasticsearch.dir}/bin/elastic-stack-ca.zip" />
<delete file="${elasticsearch.dir}/bin/certificate-bundle.zip" />
</sequential>
</macrodef>
<macrodef name="prepare-elasticsearch">
<sequential>
<lstopwatch action="start" name="prepare.elasticsearch" />
<chmod
file="${elasticsearch.dir}/bin/**"
perm="a+x"
/>
<if>
<not>
<available file="${elasticsearch.dir}/${elasticsearch.analysis-icu.zip.name}" />
</not>
<then>
<mirrors-get
dest="${elasticsearch.dir}/${elasticsearch.analysis-icu.zip.name}"
skipChecksum="true"
src="${elasticsearch.analysis-icu.zip.url}"
/>
</then>
</if>
<if>
<not>
<available file="${elasticsearch.dir}/${elasticsearch.analysis-kuromoji.zip.name}" />
</not>
<then>
<mirrors-get
dest="${elasticsearch.dir}/${elasticsearch.analysis-kuromoji.zip.name}"
skipChecksum="true"
src="${elasticsearch.analysis-kuromoji.zip.url}"
/>
</then>
</if>
<if>
<not>
<available file="${elasticsearch.dir}/${elasticsearch.analysis-smartcn.zip.name}" />
</not>
<then>
<mirrors-get
dest="${elasticsearch.dir}/${elasticsearch.analysis-smartcn.zip.name}"
skipChecksum="true"
src="${elasticsearch.analysis-smartcn.zip.url}"
/>
</then>
</if>
<if>
<not>
<available file="${elasticsearch.dir}/${elasticsearch.analysis-stempel.zip.name}" />
</not>
<then>
<mirrors-get
dest="${elasticsearch.dir}/${elasticsearch.analysis-stempel.zip.name}"
skipChecksum="true"
src="${elasticsearch.analysis-stempel.zip.url}"
/>
</then>
</if>
<if>
<os family="unix" />
<then>
<for list="${elasticsearch.analysis-icu.zip.name},${elasticsearch.analysis-kuromoji.zip.name},${elasticsearch.analysis-smartcn.zip.name},${elasticsearch.analysis-stempel.zip.name}" param="elasticsearch.plugin.name">
<sequential>
<exec dir="${elasticsearch.dir}/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="./elasticsearch-plugin install file:///${elasticsearch.dir}/@{elasticsearch.plugin.name}" />
</exec>
</sequential>
</for>
</then>
<elseif>
<os family="windows" />
<then>
<for list="${elasticsearch.analysis-icu.zip.name},${elasticsearch.analysis-kuromoji.zip.name},${elasticsearch.analysis-smartcn.zip.name},${elasticsearch.analysis-stempel.zip.name}" param="elasticsearch.plugin.name">
<sequential>
<exec dir="${elasticsearch.dir}/bin" executable="cmd">
<arg value="/c" />
<arg value="elasticsearch-plugin install file:///${elasticsearch.dir}/@{elasticsearch.plugin.name}" />
</exec>
</sequential>
</for>
</then>
</elseif>
</if>
<lstopwatch action="total" name="prepare.elasticsearch" />
</sequential>
</macrodef>
<macrodef name="set-x-pack-user-passwords">
<sequential>
<if>
<os family="unix" />
<then>
<exec dir="${elasticsearch.dir}-1/bin" executable="/bin/bash" outputproperty="elastic.xpack.user.passwords">
<arg value="-c" />
<arg value="./elasticsearch-setup-passwords auto --batch" />
</exec>
</then>
<elseif>
<os family="windows" />
<then>
<exec dir="${elasticsearch.dir}-1/bin" executable="cmd" outputproperty="elastic.xpack.user.passwords">
<arg value="/c" />
<arg value="elasticsearch-setup-passwords auto --batch" />
</exec>
</then>
</elseif>
</if>
<propertyregex
input="${elastic.xpack.user.passwords}"
override="true"
property="elastic.xpack.kibana.user.password"
regexp="(PASSWORD kibana = )(\S*)"
select="\2"
/>
<propertyregex
input="${elastic.xpack.user.passwords}"
override="true"
property="elastic.xpack.elastic.user.password"
regexp="(PASSWORD elastic = )(\S*)"
select="\2"
/>
<exec executable="curl" outputproperty="curl.output">
<arg value="https://localhost:9200" />
<arg value="-ku" />
<arg value="elastic:${elastic.xpack.elastic.user.password}" />
</exec>
<echo>${curl.output}</echo>
</sequential>
</macrodef>
<macrodef name="start-x-pack-trial">
<sequential>
<exec executable="curl" outputproperty="curl.output.trial">
<arg value="-k" />
<arg value="-X POST" />
<arg value="-ku" />
<arg value="elastic:${elastic.xpack.elastic.user.password}" />
<arg value="https://localhost:9200/_xpack/license/start_trial?acknowledge=true&pretty" />
</exec>
<echo>${curl.output.trial}</echo>
<if>
<and>
<contains string="${curl.output}" substring="You Know, for Search" />
<contains string="${curl.output.trial}" substring=""trial_was_started" : true" />
</and>
<then>
<echo>Elasticsearch started with X-Pack Security.</echo>
</then>
<else>
<fail>Elasticsearch failed to start with X-Pack Security.</fail>
</else>
</if>
</sequential>
</macrodef>
<macrodef name="unzip-boston-dataset-index">
<sequential>
<if>
<not>
<available file="${liferay.home}/${elasticsearch.boston-dataset-index.zip.name}" />
</not>
<then>
<mirrors-get
dest="${liferay.home}/${elasticsearch.boston-dataset-index.zip.name}"
skipChecksum="true"
src="${elasticsearch.boston-dataset-index.zip.url}"
/>
</then>
</if>
<unzip
dest="${liferay.home}/data/elasticsearch6/repo"
src="${liferay.home}/${elasticsearch.boston-dataset-index.zip.name}"
/>
</sequential>
</macrodef>
<macrodef name="unzip-elasticsearch">
<sequential>
<delete dir="${elasticsearch.dir}" />
<if>
<not>
<available file="${app.server.parent.dir}/${elasticsearch.zip.name}" />
</not>
<then>
<mirrors-get
dest="${app.server.parent.dir}/${elasticsearch.zip.name}"
skipChecksum="true"
src="${elasticsearch.zip.url}"
/>
</then>
</if>
<unzip
dest="${app.server.parent.dir}"
src="${app.server.parent.dir}/${elasticsearch.zip.name}"
/>
</sequential>
</macrodef>
<macrodef name="unzip-kibana">
<sequential>
<delete file="${app.server.parent.dir}/${elastic.kibana.tar.name.mac}" />
<delete file="${app.server.parent.dir}/${elastic.kibana.tar.name.linux}" />
<delete file="${app.server.parent.dir}/${elastic.kibana.zip.name.windows}" />
<if>
<and>
<not>
<available file="${app.server.parent.dir}/${elastic.kibana.tar.name.mac}" />
</not>
<os family="mac" />
</and>
<then>
<mirrors-get
dest="${app.server.parent.dir}/${elastic.kibana.tar.name.mac}"
skipChecksum="true"
src="${elastic.kibana.tar.url.mac}"
/>
<exec dir="${app.server.parent.dir}" executable="/bin/bash">
<arg value="-c" />
<arg value="tar -zxf ${elastic.kibana.tar.name.mac}" />
</exec>
</then>
<elseif>
<and>
<not>
<available file="${app.server.parent.dir}/${elastic.kibana.tar.name.linux}" />
</not>
<os family="unix" />
</and>
<then>
<mirrors-get
dest="${app.server.parent.dir}/${elastic.kibana.tar.name.linux}"
skipChecksum="true"
src="${elastic.kibana.tar.url.linux}"
/>
<untar
compression="gzip"
dest="${app.server.parent.dir}"
src="${app.server.parent.dir}/${elastic.kibana.tar.name.linux}"
/>
</then>
</elseif>
<elseif>
<and>
<not>
<available file="${app.server.parent.dir}/${elastic.kibana.zip.name}" />
</not>
<os family="windows" />
</and>
<then>
<mirrors-get
dest="${app.server.parent.dir}/${elastic.kibana.zip.name.windows}"
skipChecksum="true"
src="${elastic.kibana.zip.url.windows}"
/>
<unzip
dest="${app.server.parent.dir}"
src="${app.server.parent.dir}/${elastic.kibana.zip.name.windows}"
/>
</then>
</elseif>
</if>
<delete dir="${elastic.kibana.dir}" />
<if>
<os family="mac" />
<then>
<move
file="${app.server.parent.dir}/kibana-${elasticsearch.version}-darwin-x86_64"
tofile="${elastic.kibana.dir}"
/>
</then>
<elseif>
<os family="unix" />
<then>
<move
file="${app.server.parent.dir}/kibana-${elasticsearch.version}-linux-x86_64"
tofile="${elastic.kibana.dir}"
/>
</then>
</elseif>
<elseif>
<os family="windows" />
<then>
<move
file="${app.server.parent.dir}/kibana-${elasticsearch.version}-windows-x86"
tofile="${elastic.kibana.dir}"
/>
</then>
</elseif>
</if>
</sequential>
</macrodef>
<target name="add-boston-dataset-index">
<unzip-boston-dataset-index />
<exec executable="curl" outputproperty="curl.output">
<arg line="-X PUT "localhost:9200/_snapshot/my_backup" -H 'Content-Type: application/json' -d'{"type": "fs","settings": {"location": "${liferay.home}/data/elasticsearch6/repo"}}'" />
</exec>
<echo>Defining snapshot repository.${line.separator}${curl.output}</echo>
<exec executable="curl" outputproperty="curl.output">
<arg line="-X POST "localhost:9200/_snapshot/my_backup/snapshot_2/_restore" -H 'Content-Type: application/json' -d'{"indices": "boston311","ignore_unavailable": true,"include_global_state": true,"rename_pattern": "index_(.+)","rename_replacement": "restored_index_$1"}'" />
</exec>
<echo>Restoring Boston dataset snapshot.${line.separator}${curl.output}</echo>
<echo>Finished adding Boston dataset index.</echo>
</target>
<target name="configure-elasticsearch-cluster-properties">
<math
datatype="int"
operand1="${remote.elasticsearch.cluster.size}"
operand2="2"
operation="/"
result="elasticsearch.master-eligible.nodes.quorum"
/>
<math
datatype="int"
operand1="${elasticsearch.master-eligible.nodes.quorum}"
operand2="1"
operation="+"
result="elasticsearch.master-eligible.nodes.quorum"
/>
<echo append="true" file="${elasticsearch.dir}/config/elasticsearch.yml">${line.separator}discovery.zen.minimum_master_nodes: ${elasticsearch.master-eligible.nodes.quorum}
xpack.monitoring.collection.enabled: true</echo>
</target>
<target name="prepare-additional-elasticsearch-dirs">
<var name="elasticsearch.node.number" value="0" />
<antelope:repeat count="${remote.elasticsearch.cluster.size}">
<math
datatype="int"
operand1="${elasticsearch.node.number}"
operand2="1"
operation="+"
result="elasticsearch.node.number"
/>
<delete dir="${elasticsearch.dir}-${elasticsearch.node.number}" />
<copy
todir="${elasticsearch.dir}-${elasticsearch.node.number}"
>
<fileset
dir="${elasticsearch.dir}"
/>
</copy>
</antelope:repeat>
<delete dir="${elasticsearch.dir}" />
</target>
<target name="start-elasticsearch">
<lstopwatch action="start" name="start.elasticsearch" />
<unzip-elasticsearch />
<prepare-elasticsearch />
<configure-elasticsearch-properties />
<get-testcase-property property.name="elastic.xpack.enabled" />
<if>
<equals arg1="${elastic.xpack.enabled}" arg2="true" />
<then>
<generate-x-pack-security-certificates />
<configure-elasticsearch-x-pack-security-properties />
</then>
</if>
<configure-portal-elasticsearch-osgi-properties />
<get-testcase-property property.name="remote.elasticsearch.cluster.size" />
<if>
<not>
<isset property="remote.elasticsearch.cluster.size" />
</not>
<then>
<property name="remote.elasticsearch.cluster.size" value="1" />
</then>
</if>
<antcall target="configure-elasticsearch-cluster-properties" />
<antcall target="prepare-additional-elasticsearch-dirs" />
<antcall target="start-elasticsearch-node" />
<if>
<equals arg1="${elastic.xpack.enabled}" arg2="true" />
<then>
<sleep seconds="30" />
<set-x-pack-user-passwords />
<start-x-pack-trial />
<configure-portal-x-pack-osgi-properties />
<configure-portal-x-pack-security-truststore />
<antcall target="start-kibana" />
<lstopwatch action="total" name="start.elasticsearch" />
</then>
<else>
<waitfor maxwait="20" maxwaitunit="second" timeoutproperty="elasticsearch.server.not.started">
<http url="http://localhost:9200/" />
</waitfor>
<lstopwatch action="total" name="start.elasticsearch" />
<fail if="elasticsearch.server.not.started" message="Elasticsearch server failed to initialize." />
</else>
</if>
</target>
<target name="start-elasticsearch-node">
<sequential>
<lstopwatch action="start" name="start.elasticsearch.node" />
<var name="elasticsearch.node.number" value="0" />
<get-java-jdk-home />
<antelope:repeat count="${remote.elasticsearch.cluster.size}">
<math
datatype="int"
operand1="${elasticsearch.node.number}"
operand2="1"
operation="+"
result="elasticsearch.node.number"
/>
<chmod
maxparallel="10"
perm="a+rwx"
type="both"
>
<fileset
dir="${elasticsearch.dir}-${elasticsearch.node.number}"
/>
</chmod>
<if>
<os family="mac" />
<then>
<exec dir="${elasticsearch.dir}-${elasticsearch.node.number}/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="./elasticsearch -d -p pid-elasticsearch" />
</exec>
</then>
<elseif>
<os family="unix" />
<then>
<exec dir="${elasticsearch.dir}-${elasticsearch.node.number}/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="sudo -H -u shutdown bash -c 'export JAVA_HOME=${java.jdk.home} && ./elasticsearch -d -p pid-elasticsearch'" />
</exec>
</then>
</elseif>
<elseif>
<os family="windows" />
<then>
<exec dir="${elasticsearch.dir}-${elasticsearch.node.number}/bin" executable="cmd" spawn="true">
<arg value="/c" />
<arg value="elasticsearch -d -p pid-elasticsearch" />
</exec>
</then>
</elseif>
</if>
</antelope:repeat>
<lstopwatch action="total" name="start.elasticsearch.node" />
</sequential>
</target>
<target name="start-kibana">
<lstopwatch action="start" name="start.kibana" />
<unzip-kibana />
<chmod
maxparallel="10"
perm="a+x"
type="both"
>
<fileset
dir="${elastic.kibana.dir}/bin"
>
<include name="**" />
</fileset>
<fileset
dir="${elastic.kibana.dir}/node"
>
<include name="**" />
</fileset>
</chmod>
<configure-kibana-properties />
<get-testcase-property property.name="elastic.xpack.enabled" />
<if>
<equals arg1="${elastic.xpack.enabled}" arg2="true" />
<then>
<configure-kibana-x-pack-security-properties />
</then>
</if>
<if>
<os family="unix" />
<then>
<exec dir="${elastic.kibana.dir}/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="./kibana > kibana.log 2>&1 &" />
</exec>
</then>
<elseif>
<os family="windows" />
<then>
<exec dir="${elastic.kibana.dir}/bin" executable="cmd">
<arg value="/c" />
<arg value="kibana" />
</exec>
</then>
</elseif>
</if>
<lstopwatch action="total" name="start.kibana" />
</target>
<target name="stop-elasticsearch">
<get-testcase-property property.name="remote.elasticsearch.cluster.size" />
<if>
<not>
<isset property="remote.elasticsearch.cluster.size" />
</not>
<then>
<property name="remote.elasticsearch.cluster.size" value="1" />
</then>
</if>
<var name="elasticsearch.node.number" value="0" />
<antelope:repeat count="${remote.elasticsearch.cluster.size}">
<math
datatype="int"
operand1="${elasticsearch.node.number}"
operand2="1"
operation="+"
result="elasticsearch.node.number"
/>
<if>
<os family="unix" />
<then>
<loadfile
property="pid-elasticsearch"
srcFile="${elasticsearch.dir}-${elasticsearch.node.number}/pid-elasticsearch"
>
<filterchain>
<linecontainsregexp>
<regexp pattern="[0-9]*" />
</linecontainsregexp>
</filterchain>
</loadfile>
<exec dir="${elasticsearch.dir}-${elasticsearch.node.number}/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="kill ${pid-elasticsearch}" />
</exec>
<var name="pid-elasticsearch" unset="true" />
</then>
<elseif>
<os family="windows" />
<then>
<exec dir="${elasticsearch.dir}-${elasticsearch.node.number}/bin" executable="cmd" spawn="true">
<arg value="/c" />
<arg value="for /f %x in (pid-elasticsearch) do taskkill /f /pid %x" />
</exec>
</then>
</elseif>
</if>
<print-file file.name="${elasticsearch.dir}-${elasticsearch.node.number}/logs/LiferayElasticsearchCluster.log" />
</antelope:repeat>
<if>
<equals arg1="${elastic.xpack.enabled}" arg2="true" />
<then>
<print-file file.name="${elastic.kibana.dir}/bin/kibana.log" />
<antcall target="stop-kibana" />
</then>
</if>
</target>
<target name="stop-kibana">
<if>
<os family="unix" />
<then>
<loadfile
property="pid-kibana"
srcFile="${elastic.kibana.dir}/bin/pid-kibana"
>
<filterchain>
<linecontainsregexp>
<regexp pattern="[0-9]*" />
</linecontainsregexp>
</filterchain>
</loadfile>
<exec dir="${elastic.kibana.dir}/bin" executable="/bin/bash">
<arg value="-c" />
<arg value="kill ${pid-kibana}" />
</exec>
</then>
</if>
</target>
</project>