8
8
import java .nio .file .Path ;
9
9
import java .nio .file .Paths ;
10
10
import java .nio .file .StandardCopyOption ;
11
+ import java .time .OffsetDateTime ;
11
12
import java .util .HashMap ;
12
13
import java .util .List ;
13
14
import java .util .Map ;
14
15
15
16
import io .kubernetes .client .custom .Quantity ;
16
17
import io .kubernetes .client .openapi .ApiException ;
18
+ import io .kubernetes .client .openapi .models .CoreV1Event ;
17
19
import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
18
20
import io .kubernetes .client .openapi .models .V1ResourceRequirements ;
21
+ import io .kubernetes .client .util .Yaml ;
19
22
import oracle .weblogic .domain .ClusterResource ;
20
23
import oracle .weblogic .domain .DomainResource ;
21
24
import oracle .weblogic .domain .ServerPod ;
56
59
import static oracle .weblogic .kubernetes .actions .TestActions .deletePersistentVolumeClaim ;
57
60
import static oracle .weblogic .kubernetes .actions .TestActions .deletePod ;
58
61
import static oracle .weblogic .kubernetes .actions .TestActions .getServiceNodePort ;
62
+ import static oracle .weblogic .kubernetes .actions .TestActions .now ;
59
63
import static oracle .weblogic .kubernetes .actions .TestActions .uninstallNginx ;
60
64
import static oracle .weblogic .kubernetes .actions .impl .primitive .Kubernetes .deleteNamespace ;
61
65
import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterAndVerify ;
62
66
import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterResource ;
63
67
import static oracle .weblogic .kubernetes .utils .CommonMiiTestUtils .createDomainResource ;
68
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkClusterReplicaCountMatches ;
64
69
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
65
70
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
66
71
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .withLongRetryPolicy ;
69
74
import static oracle .weblogic .kubernetes .utils .FileUtils .replaceStringInFile ;
70
75
import static oracle .weblogic .kubernetes .utils .ImageUtils .createBaseRepoSecret ;
71
76
import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
77
+ import static oracle .weblogic .kubernetes .utils .K8sEvents .getEvents ;
72
78
import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .createIngressForDomainAndVerify ;
73
79
import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .installAndVerifyNginx ;
74
80
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .cleanupPromGrafanaClusterRoles ;
80
86
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installMonitoringExporter ;
81
87
import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
82
88
import static oracle .weblogic .kubernetes .utils .PersistentVolumeUtils .createPvAndPvc ;
83
- import static oracle .weblogic .kubernetes .utils .PodUtils .checkPodDeleted ;
89
+ import static oracle .weblogic .kubernetes .utils .PodUtils .isPodDeleted ;
84
90
import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
85
91
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
86
92
import static org .assertj .core .api .Assertions .assertThat ;
87
93
import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
94
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
88
95
import static org .junit .jupiter .api .Assertions .assertNotNull ;
89
96
import static org .junit .jupiter .api .Assertions .assertTrue ;
90
97
@@ -296,6 +303,7 @@ void testHPAWithCustomMetrics() {
296
303
//reboot server1 and server2 to kill open sessions
297
304
assertDoesNotThrow (() -> deletePod (managedServerPrefix + 1 , domainNamespace ));
298
305
assertDoesNotThrow (() -> deletePod (managedServerPrefix + 2 , domainNamespace ));
306
+ OffsetDateTime timestamp = now ();
299
307
// wait until reboot
300
308
for (int i = 1 ; i < 3 ; i ++) {
301
309
checkPodReadyAndServiceExists (managedServerPrefix + i , domainUid , domainNamespace );
@@ -312,21 +320,42 @@ void testHPAWithCustomMetrics() {
312
320
logger ,
313
321
"Checking if replica switched to 2" );
314
322
315
- try {
316
- checkPodDeleted (managedServerPrefix + 3 , domainUid , domainNamespace );
317
- } catch (Exception ex ) {
323
+ if (!isPodDeleted (managedServerPrefix + 3 , domainUid , domainNamespace )) {
324
+
318
325
//check if different server was scaled down
319
- try {
320
- if (!Kubernetes .doesPodExist (domainNamespace , domainUid , managedServerPrefix + 1 )) {
326
+ assertDoesNotThrow (() -> {
327
+ logger .info ("Checking if HPA scaled down managed server 1 or managed server 2" );
328
+ String command = KUBERNETES_CLI + " get pods -n" + domainNamespace ;
329
+
330
+ logger .info ("Executing command " + command );
331
+ ExecResult result = ExecCommand .exec (command );
332
+ logger .info (" Result output: " + result .stdout ());
333
+ command = KUBERNETES_CLI + " describe pod " + managedServerPrefix + 3 + " -n" + domainNamespace ;
334
+
335
+ logger .info ("Executing command " + command );
336
+ result = ExecCommand .exec (command );
337
+ logger .info (" Result output: " + result .stdout ());
338
+ List <CoreV1Event > events = getEvents (domainNamespace ,timestamp );
339
+ for (CoreV1Event event : events ) {
340
+ logger .info ("Generated events after HPA scaling " + Yaml .dump (event ));
341
+ }
342
+ int numberOfManagedSvs = 3 ;
343
+ if (!Kubernetes .doesPodExist (domainNamespace , domainUid , managedServerPrefix + 1 )
344
+ || Kubernetes .isPodTerminating (domainNamespace , domainUid , managedServerPrefix + 1 )) {
321
345
logger .info ("HPA scaled down managed server 1" );
322
- } else if (!Kubernetes .doesPodExist (domainNamespace , domainUid , managedServerPrefix + 2 )) {
346
+ --numberOfManagedSvs ;
347
+ } else if (!Kubernetes .doesPodExist (domainNamespace , domainUid , managedServerPrefix + 2 )
348
+ || Kubernetes .isPodTerminating (domainNamespace , domainUid , managedServerPrefix + 2 )) {
323
349
logger .info ("HPA scaled down managed server 2" );
324
- } else {
325
- checkPodDeleted (managedServerPrefix + 3 , domainUid , domainNamespace );
350
+ --numberOfManagedSvs ;
351
+ } else if (!Kubernetes .doesPodExist (domainNamespace , domainUid , managedServerPrefix + 3 )
352
+ || Kubernetes .isPodTerminating (domainNamespace , domainUid , managedServerPrefix + 2 )) {
353
+ logger .info ("HPA scaled down managed server 3" );
354
+ --numberOfManagedSvs ;
326
355
}
327
- } catch ( Exception ex1 ) {
328
- throw ex ;
329
- }
356
+ assertTrue ( checkClusterReplicaCountMatches ( clusterResName , domainNamespace , 2 ));
357
+ assertEquals ( 2 , numberOfManagedSvs ) ;
358
+ });
330
359
}
331
360
}
332
361
0 commit comments