77import java .util .Collections ;
88import java .util .List ;
99import java .util .Map ;
10- import java .util .Objects ;
1110import java .util .Optional ;
1211import javax .annotation .Nonnull ;
1312import javax .annotation .Nullable ;
1413
15- import io .kubernetes .client .openapi .models .V1Container ;
16- import io .kubernetes .client .openapi .models .V1ContainerPort ;
1714import io .kubernetes .client .openapi .models .V1DeleteOptions ;
1815import io .kubernetes .client .openapi .models .V1EnvVar ;
1916import io .kubernetes .client .openapi .models .V1ObjectMeta ;
3835import oracle .kubernetes .operator .work .NextAction ;
3936import oracle .kubernetes .operator .work .Packet ;
4037import oracle .kubernetes .operator .work .Step ;
41- import oracle .kubernetes .weblogic .domain .model .MonitoringExporterSpecification ;
4238import oracle .kubernetes .weblogic .domain .model .ServerSpec ;
4339import oracle .kubernetes .weblogic .domain .model .Shutdown ;
4440
45- import static oracle .kubernetes .operator .KubernetesConstants .DEFAULT_EXPORTER_SIDECAR_PORT ;
46- import static oracle .kubernetes .operator .KubernetesConstants .EXPORTER_CONTAINER_NAME ;
4741import static oracle .kubernetes .operator .LabelConstants .CLUSTERNAME_LABEL ;
4842import static oracle .kubernetes .operator .LabelConstants .SERVERNAME_LABEL ;
4943import static oracle .kubernetes .operator .ProcessingConstants .SERVERS_TO_ROLL ;
@@ -405,26 +399,15 @@ static class ManagedPodStepContext extends PodStepContext {
405399
406400 private final String clusterName ;
407401 private final Packet packet ;
408- private final ExporterContext exporterContext ;
409402
410403 ManagedPodStepContext (Step conflictStep , Packet packet ) {
411404 super (conflictStep , packet );
412405 this .packet = packet ;
413406 clusterName = (String ) packet .get (ProcessingConstants .CLUSTER_NAME );
414- exporterContext = createExporterContext ();
415407
416408 init ();
417409 }
418410
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-
428411 @ Override
429412 ServerSpec getServerSpec () {
430413 return getDomain ().getServer (getServerName (), getClusterName ());
@@ -513,21 +496,6 @@ protected String getPodReplacedMessageKey() {
513496 return MessageKeys .MANAGED_POD_REPLACED ;
514497 }
515498
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-
531499 @ Override
532500 protected V1ObjectMeta createMetadata () {
533501 V1ObjectMeta metadata = super .createMetadata ();
@@ -548,13 +516,6 @@ protected List<String> getContainerCommand() {
548516 return new ArrayList <>(super .getContainerCommand ());
549517 }
550518
551- @ Override
552- protected List <V1Container > getContainers () {
553- List <V1Container > containers = new ArrayList <>(super .getContainers ());
554- exporterContext .addContainer (containers );
555- return containers ;
556- }
557-
558519 @ Override
559520 @ SuppressWarnings ("unchecked" )
560521 List <V1EnvVar > getConfiguredEnvVars (TuningParameters tuningParameters ) {
@@ -564,106 +525,6 @@ List<V1EnvVar> getConfiguredEnvVars(TuningParameters tuningParameters) {
564525 addStartupEnvVars (vars );
565526 return vars ;
566527 }
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-
667528 }
668529
669530 static class ManagedPodStep extends Step {
0 commit comments