7
7
import java .util .Collections ;
8
8
import java .util .List ;
9
9
import java .util .Map ;
10
- import java .util .Objects ;
11
10
import java .util .Optional ;
12
11
import javax .annotation .Nonnull ;
13
12
import javax .annotation .Nullable ;
14
13
15
- import io .kubernetes .client .openapi .models .V1Container ;
16
- import io .kubernetes .client .openapi .models .V1ContainerPort ;
17
14
import io .kubernetes .client .openapi .models .V1DeleteOptions ;
18
15
import io .kubernetes .client .openapi .models .V1EnvVar ;
19
16
import io .kubernetes .client .openapi .models .V1ObjectMeta ;
38
35
import oracle .kubernetes .operator .work .NextAction ;
39
36
import oracle .kubernetes .operator .work .Packet ;
40
37
import oracle .kubernetes .operator .work .Step ;
41
- import oracle .kubernetes .weblogic .domain .model .MonitoringExporterSpecification ;
42
38
import oracle .kubernetes .weblogic .domain .model .ServerSpec ;
43
39
import oracle .kubernetes .weblogic .domain .model .Shutdown ;
44
40
45
- import static oracle .kubernetes .operator .KubernetesConstants .DEFAULT_EXPORTER_SIDECAR_PORT ;
46
- import static oracle .kubernetes .operator .KubernetesConstants .EXPORTER_CONTAINER_NAME ;
47
41
import static oracle .kubernetes .operator .LabelConstants .CLUSTERNAME_LABEL ;
48
42
import static oracle .kubernetes .operator .LabelConstants .SERVERNAME_LABEL ;
49
43
import static oracle .kubernetes .operator .ProcessingConstants .SERVERS_TO_ROLL ;
@@ -405,26 +399,15 @@ static class ManagedPodStepContext extends PodStepContext {
405
399
406
400
private final String clusterName ;
407
401
private final Packet packet ;
408
- private final ExporterContext exporterContext ;
409
402
410
403
ManagedPodStepContext (Step conflictStep , Packet packet ) {
411
404
super (conflictStep , packet );
412
405
this .packet = packet ;
413
406
clusterName = (String ) packet .get (ProcessingConstants .CLUSTER_NAME );
414
- exporterContext = createExporterContext ();
415
407
416
408
init ();
417
409
}
418
410
419
- ExporterContext createExporterContext () {
420
- return useSidecar () ? new SidecarExporterContext () : new WebAppExporterContext ();
421
- }
422
-
423
- // Use the monitoring exporter sidecar if an exporter configuration is part of the domain.
424
- private boolean useSidecar () {
425
- return getDomain ().getMonitoringExporterConfiguration () != null ;
426
- }
427
-
428
411
@ Override
429
412
ServerSpec getServerSpec () {
430
413
return getDomain ().getServer (getServerName (), getClusterName ());
@@ -513,21 +496,6 @@ protected String getPodReplacedMessageKey() {
513
496
return MessageKeys .MANAGED_POD_REPLACED ;
514
497
}
515
498
516
- @ Override
517
- V1Pod withNonHashedElements (V1Pod pod ) {
518
- V1Pod v1Pod = super .withNonHashedElements (pod );
519
-
520
- // Add prometheus annotations. This will overwrite any custom annotations with same name.
521
- // Prometheus does not support "prometheus.io/scheme". The scheme(http/https) can be set
522
- // in the Prometheus Chart values yaml under the "extraScrapeConfigs:" section.
523
- if (exporterContext .isEnabled ()) {
524
- final V1ObjectMeta metadata = v1Pod .getMetadata ();
525
- AnnotationHelper .annotateForPrometheus (metadata , exporterContext .getBasePath (), exporterContext .getPort ());
526
- }
527
-
528
- return v1Pod ;
529
- }
530
-
531
499
@ Override
532
500
protected V1ObjectMeta createMetadata () {
533
501
V1ObjectMeta metadata = super .createMetadata ();
@@ -548,13 +516,6 @@ protected List<String> getContainerCommand() {
548
516
return new ArrayList <>(super .getContainerCommand ());
549
517
}
550
518
551
- @ Override
552
- protected List <V1Container > getContainers () {
553
- List <V1Container > containers = new ArrayList <>(super .getContainers ());
554
- exporterContext .addContainer (containers );
555
- return containers ;
556
- }
557
-
558
519
@ Override
559
520
@ SuppressWarnings ("unchecked" )
560
521
List <V1EnvVar > getConfiguredEnvVars (TuningParameters tuningParameters ) {
@@ -564,106 +525,6 @@ List<V1EnvVar> getConfiguredEnvVars(TuningParameters tuningParameters) {
564
525
addStartupEnvVars (vars );
565
526
return vars ;
566
527
}
567
-
568
- abstract class ExporterContext {
569
- int getWebLogicRestPort () {
570
- return scan .getLocalAdminProtocolChannelPort ();
571
- }
572
-
573
- boolean isWebLogicSecure () {
574
- return !Objects .equals (getWebLogicRestPort (), getListenPort ());
575
- }
576
-
577
- abstract boolean isEnabled ();
578
-
579
- abstract int getPort ();
580
-
581
- abstract String getBasePath ();
582
-
583
- abstract void addContainer (List <V1Container > containers );
584
- }
585
-
586
- class WebAppExporterContext extends ExporterContext {
587
-
588
- @ Override
589
- boolean isEnabled () {
590
- return getListenPort () != null ;
591
- }
592
-
593
- @ Override
594
- int getPort () {
595
- return getListenPort ();
596
- }
597
-
598
- @ Override
599
- String getBasePath () {
600
- return "/wls-exporter" ;
601
- }
602
-
603
- @ Override
604
- void addContainer (List <V1Container > containers ) {
605
- // do nothing
606
- }
607
- }
608
-
609
- class SidecarExporterContext extends ExporterContext {
610
- private static final int DEBUG_PORT = 30055 ;
611
- private final int metricsPort ;
612
-
613
- public SidecarExporterContext () {
614
- metricsPort = MonitoringExporterSpecification .getRestPort (scan );
615
- }
616
-
617
- @ Override
618
- boolean isEnabled () {
619
- return true ;
620
- }
621
-
622
- @ Override
623
- int getPort () {
624
- return metricsPort ;
625
- }
626
-
627
- @ Override
628
- String getBasePath () {
629
- return "" ;
630
- }
631
-
632
- @ Override
633
- void addContainer (List <V1Container > containers ) {
634
- containers .add (createMonitoringExporterContainer ());
635
- }
636
-
637
- private V1Container createMonitoringExporterContainer () {
638
- return new V1Container ()
639
- .name (EXPORTER_CONTAINER_NAME )
640
- .image (getDomain ().getMonitoringExporterImage ())
641
- .imagePullPolicy (getDomain ().getMonitoringExporterImagePullPolicy ())
642
- .addEnvItem (new V1EnvVar ().name ("JAVA_OPTS" ).value (createJavaOptions ()))
643
- .addPortsItem (new V1ContainerPort ().name ("metrics" ).protocol ("TCP" ).containerPort (getPort ()))
644
- .addPortsItem (new V1ContainerPort ().name ("debugger" ).protocol ("TCP" ).containerPort (DEBUG_PORT ));
645
- }
646
-
647
- private String createJavaOptions () {
648
- final List <String > args = new ArrayList <>();
649
- args .add ("-DDOMAIN=" + getDomainUid ());
650
- args .add ("-DWLS_PORT=" + getWebLogicRestPort ());
651
- if (isWebLogicSecure ()) {
652
- args .add ("-DWLS_SECURE=true" );
653
- }
654
- if (metricsPort != DEFAULT_EXPORTER_SIDECAR_PORT ) {
655
- args .add ("-DEXPORTER_PORT=" + metricsPort );
656
- }
657
- args .add (getDebugOption ());
658
-
659
- return String .join (" " , args );
660
- }
661
-
662
- private String getDebugOption () {
663
- return "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:" + DEBUG_PORT ;
664
- }
665
- }
666
-
667
528
}
668
529
669
530
static class ManagedPodStep extends Step {
0 commit comments