@@ -125,7 +125,7 @@ public ConfigurationImpl() throws IOException, ConfigureFileNotFoundException {
125
125
}
126
126
}
127
127
128
- this .configuration = loadCaseConfiguration (configureFile );
128
+ this .configuration = loadCaseConfiguration (configureFile , scenarioName );
129
129
130
130
//set scenario timeout
131
131
if (this .configuration .getTimeout () > 0 ) {
@@ -163,7 +163,7 @@ private boolean isDebug() {
163
163
return debugPatterns != null && debugPatterns .size () > 0 ;
164
164
}
165
165
166
- private CaseConfiguration loadCaseConfiguration (String configureFile ) throws IOException {
166
+ private CaseConfiguration loadCaseConfiguration (String configureFile , String scenarioName ) throws IOException {
167
167
// read 'props'
168
168
String configYaml = FileUtil .readFully (configureFile );
169
169
CaseConfiguration tmpConfiguration = parseConfiguration (configYaml );
@@ -210,7 +210,7 @@ private CaseConfiguration loadCaseConfiguration(String configureFile) throws IOE
210
210
caseConfiguration .setServices (newServices );
211
211
}
212
212
213
- fillupServices (caseConfiguration );
213
+ fillupServices (caseConfiguration , scenarioName );
214
214
return caseConfiguration ;
215
215
}
216
216
@@ -252,9 +252,15 @@ private CaseConfiguration parseConfiguration(String configYaml) {
252
252
return new Yaml ().loadAs (configYaml , CaseConfiguration .class );
253
253
}
254
254
255
- private void fillupServices (CaseConfiguration caseConfiguration ) throws IOException {
255
+ private void fillupServices (CaseConfiguration caseConfiguration , String scenarioName ) throws IOException {
256
256
List <String > caseSystemProps = caseConfiguration .getSystemProps ();
257
257
int index = 0 ;
258
+ //normalize hostname by concatenating scenarioName with index number, hostname length should less than 64.
259
+ Map <String , String > hostnameMap = new HashMap <>();
260
+ for (String serviceName : caseConfiguration .getServices ().keySet ()) {
261
+ hostnameMap .put (serviceName , scenarioName + index ++);
262
+ }
263
+ index = 0 ;
258
264
for (Map .Entry <String , ServiceComponent > entry : caseConfiguration .getServices ().entrySet ()) {
259
265
String serviceName = entry .getKey ();
260
266
ServiceComponent service = entry .getValue ();
@@ -280,7 +286,7 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept
280
286
281
287
//set wait ports
282
288
if (isNotEmpty (service .getWaitPortsBeforeRun ())) {
283
- String str = convertAddrPortsToString (service .getWaitPortsBeforeRun ());
289
+ String str = convertAddrPortsToString (service .getWaitPortsBeforeRun (), hostnameMap );
284
290
setEnv (service , ENV_WAIT_PORTS_BEFORE_RUN , str );
285
291
}
286
292
@@ -351,7 +357,7 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept
351
357
//set check ports
352
358
if (isNotEmpty (service .getCheckPorts ())) {
353
359
addHealthcheck = true ;
354
- String str = convertAddrPortsToString (service .getCheckPorts ());
360
+ String str = convertAddrPortsToString (service .getCheckPorts (), hostnameMap );
355
361
setEnv (service , ENV_CHECK_PORTS , str );
356
362
}
357
363
@@ -395,7 +401,7 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept
395
401
396
402
//set wait ports
397
403
if (isNotEmpty (service .getWaitPortsBeforeRun ())) {
398
- String str = convertAddrPortsToString (service .getWaitPortsBeforeRun ());
404
+ String str = convertAddrPortsToString (service .getWaitPortsBeforeRun (), hostnameMap );
399
405
setEnv (service , ENV_WAIT_PORTS_BEFORE_RUN , str );
400
406
}
401
407
@@ -423,7 +429,7 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept
423
429
//set check ports
424
430
if (isNotEmpty (service .getCheckPorts ())) {
425
431
addHealthcheck = true ;
426
- String str = convertAddrPortsToString (service .getCheckPorts ());
432
+ String str = convertAddrPortsToString (service .getCheckPorts (), hostnameMap );
427
433
setEnv (service , ENV_CHECK_PORTS , str );
428
434
}
429
435
@@ -436,7 +442,8 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept
436
442
437
443
// set hostname to serviceId if absent
438
444
if (StringUtils .isBlank (service .getHostname ())) {
439
- service .setHostname (serviceName );
445
+ //use normalized hostname.
446
+ service .setHostname (hostnameMap .get (serviceName ));
440
447
}
441
448
442
449
//set jvmFlags
@@ -445,6 +452,27 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept
445
452
appendEnv (service , ENV_JAVA_OPTS , str );
446
453
}
447
454
455
+ //revise hostname properties of service
456
+ List <String > serviceSystemProps = service .getSystemProps ();
457
+ if (serviceSystemProps != null ) {
458
+ List <String > revisedServiceSystemProps = new ArrayList <>();
459
+ serviceSystemProps .forEach (serviceProp -> {
460
+ String [] strs = serviceProp .split ("=" );
461
+ if (strs .length == 2 ) {
462
+ String hostname = hostnameMap .get (strs [1 ]);
463
+ if (null != hostname ) {
464
+ //use normalized hostname.
465
+ revisedServiceSystemProps .add (strs [0 ] + "=" + hostname );
466
+ } else {
467
+ revisedServiceSystemProps .add (serviceProp );
468
+ }
469
+ } else {
470
+ revisedServiceSystemProps .add (serviceProp );
471
+ }
472
+ });
473
+ service .setSystemProps (revisedServiceSystemProps );
474
+ }
475
+
448
476
//set systemProps
449
477
List <String > systemProps = mergeSystemProps (caseSystemProps , service .getSystemProps ());
450
478
if (isNotEmpty (systemProps )) {
@@ -526,13 +554,23 @@ private boolean isNotEmpty(List<String> list) {
526
554
return list != null && list .size () > 0 ;
527
555
}
528
556
529
- private String convertAddrPortsToString (List <String > addrPorts ) {
557
+ private String convertAddrPortsToString (List <String > addrPorts , Map < String , String > hostnameMap ) {
530
558
StringBuilder sb = new StringBuilder ();
531
559
for (String addrPort : addrPorts ) {
532
- if (!addrPort .contains (":" )) {
560
+ int idx = addrPort .indexOf (":" );
561
+ if (idx > 0 ) {
562
+ String hostname = hostnameMap .get (addrPort .substring (0 , idx ));
563
+ if (null != hostname ) {
564
+ // use normalized hostname.
565
+ sb .append (hostname ).append (addrPort .substring (idx ));
566
+ } else {
567
+ sb .append (addrPort );
568
+ }
569
+ } else {
533
570
addrPort = "127.0.0.1" + ":" + addrPort ;
571
+ sb .append (addrPort );
534
572
}
535
- sb .append (addrPort ). append ( ";" );
573
+ sb .append (";" );
536
574
}
537
575
return sb .toString ();
538
576
}
0 commit comments