Skip to content

Commit eb697c5

Browse files
committed
Revert "eliminate duplication logger creation (#1225)"
This reverts commit 218331d.
1 parent a38a7f6 commit eb697c5

File tree

66 files changed

+769
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+769
-560
lines changed

operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import oracle.kubernetes.operator.helpers.PodHelper;
4141
import oracle.kubernetes.operator.helpers.ResponseStep;
4242
import oracle.kubernetes.operator.helpers.ServiceHelper;
43+
import oracle.kubernetes.operator.logging.LoggingFacade;
44+
import oracle.kubernetes.operator.logging.LoggingFactory;
4345
import oracle.kubernetes.operator.logging.LoggingFilter;
4446
import oracle.kubernetes.operator.logging.MessageKeys;
4547
import oracle.kubernetes.operator.logging.OncePerMessageLoggingFilter;
@@ -63,17 +65,18 @@
6365
import oracle.kubernetes.weblogic.domain.model.DomainSpec;
6466

6567
import static oracle.kubernetes.operator.helpers.LegalNames.toJobIntrospectorName;
66-
import static oracle.kubernetes.operator.logging.LoggingFacade.LOGGER;
6768

6869
public class DomainProcessorImpl implements DomainProcessor {
6970

71+
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
72+
7073
private static final Map<String, FiberGate> makeRightFiberGates = new ConcurrentHashMap<>();
7174
private static final Map<String, FiberGate> statusFiberGates = new ConcurrentHashMap<>();
7275
// Map from namespace to map of domainUID to Domain
7376
private static final Map<String, Map<String, DomainPresenceInfo>> DOMAINS =
74-
new ConcurrentHashMap<>();
77+
new ConcurrentHashMap<>();
7578
private static final ConcurrentMap<String, ConcurrentMap<String, ScheduledFuture<?>>>
76-
statusUpdaters = new ConcurrentHashMap<>();
79+
statusUpdaters = new ConcurrentHashMap<>();
7780
private DomainProcessorDelegate delegate;
7881

7982
public DomainProcessorImpl(DomainProcessorDelegate delegate) {
@@ -86,8 +89,8 @@ private static DomainPresenceInfo getExistingDomainPresenceInfo(String ns, Strin
8689

8790
private static void registerDomainPresenceInfo(DomainPresenceInfo info) {
8891
DOMAINS
89-
.computeIfAbsent(info.getNamespace(), k -> new ConcurrentHashMap<>())
90-
.put(info.getDomainUid(), info);
92+
.computeIfAbsent(info.getNamespace(), k -> new ConcurrentHashMap<>())
93+
.put(info.getDomainUid(), info);
9194
}
9295

9396
private static void unregisterPresenceInfo(String ns, String domainUid) {
@@ -98,9 +101,9 @@ private static void unregisterPresenceInfo(String ns, String domainUid) {
98101
}
99102

100103
private static void registerStatusUpdater(
101-
String ns, String domainUid, ScheduledFuture<?> future) {
104+
String ns, String domainUid, ScheduledFuture<?> future) {
102105
ScheduledFuture<?> existing =
103-
statusUpdaters.computeIfAbsent(ns, k -> new ConcurrentHashMap<>()).put(domainUid, future);
106+
statusUpdaters.computeIfAbsent(ns, k -> new ConcurrentHashMap<>()).put(domainUid, future);
104107
if (existing != null) {
105108
existing.cancel(false);
106109
}
@@ -127,29 +130,29 @@ private static void onEvent(V1Event event) {
127130
if (status == null) return;
128131

129132
Optional.ofNullable(DOMAINS.get(event.getMetadata().getNamespace()))
130-
.map(m -> m.get(domainUid))
131-
.ifPresent(info -> info.updateLastKnownServerStatus(serverName, status));
133+
.map(m -> m.get(domainUid))
134+
.ifPresent(info -> info.updateLastKnownServerStatus(serverName, status));
132135
}
133136

134137
private static String getReadinessStatus(V1Event event) {
135138
return Optional.ofNullable(event.getMessage())
136-
.filter(m -> m.contains(WebLogicConstants.READINESS_PROBE_NOT_READY_STATE))
137-
.map(m -> m.substring(m.lastIndexOf(':') + 1).trim())
138-
.orElse(null);
139+
.filter(m -> m.contains(WebLogicConstants.READINESS_PROBE_NOT_READY_STATE))
140+
.map(m -> m.substring(m.lastIndexOf(':') + 1).trim())
141+
.orElse(null);
139142
}
140143

141144
private static Step readExistingPods(DomainPresenceInfo info) {
142145
return new CallBuilder()
143-
.withLabelSelectors(
144-
LabelConstants.forDomainUidSelector(info.getDomainUid()),
145-
LabelConstants.CREATEDBYOPERATOR_LABEL)
146-
.listPodAsync(info.getNamespace(), new PodListStep(info));
146+
.withLabelSelectors(
147+
LabelConstants.forDomainUidSelector(info.getDomainUid()),
148+
LabelConstants.CREATEDBYOPERATOR_LABEL)
149+
.listPodAsync(info.getNamespace(), new PodListStep(info));
147150
}
148151

149152
// pre-conditions: DomainPresenceInfo SPI
150153
// "principal"
151154
static Step bringAdminServerUp(
152-
DomainPresenceInfo info, PodAwaiterStepFactory podAwaiterStepFactory, Step next) {
155+
DomainPresenceInfo info, PodAwaiterStepFactory podAwaiterStepFactory, Step next) {
153156
return Step.chain(bringAdminServerUpSteps(info, podAwaiterStepFactory, next));
154157
}
155158

@@ -161,7 +164,7 @@ private static Step[] domainIntrospectionSteps(Step next) {
161164
}
162165

163166
private static Step[] bringAdminServerUpSteps(
164-
DomainPresenceInfo info, PodAwaiterStepFactory podAwaiterStepFactory, Step next) {
167+
DomainPresenceInfo info, PodAwaiterStepFactory podAwaiterStepFactory, Step next) {
165168
List<Step> resources = new ArrayList<>();
166169
resources.add(new BeforeAdminServiceStep(null));
167170
resources.add(PodHelper.createAdminPodStep(null));
@@ -469,7 +472,8 @@ private void internalMakeRightDomainPresence(
469472
Step strategy =
470473
new StartPlanStep(
471474
info, isDeleting ? createDomainDownPlan(info) : createDomainUpPlan(info));
472-
if (!isDeleting && dom != null) strategy = new DomainValidationStep(dom, strategy);
475+
if (!isDeleting && dom != null)
476+
strategy = new DomainValidationStep(dom, strategy);
473477

474478
runDomainPlan(
475479
dom,
@@ -628,8 +632,8 @@ private static class PodListStep extends ResponseStep<V1PodList> {
628632
@Override
629633
public NextAction onFailure(Packet packet, CallResponse<V1PodList> callResponse) {
630634
return callResponse.getStatusCode() == CallBuilder.NOT_FOUND
631-
? onSuccess(packet, callResponse)
632-
: super.onFailure(packet, callResponse);
635+
? onSuccess(packet, callResponse)
636+
: super.onFailure(packet, callResponse);
633637
}
634638

635639
@Override
@@ -685,8 +689,8 @@ private class ServiceListStep extends ResponseStep<V1ServiceList> {
685689
@Override
686690
public NextAction onFailure(Packet packet, CallResponse<V1ServiceList> callResponse) {
687691
return callResponse.getStatusCode() == CallBuilder.NOT_FOUND
688-
? onSuccess(packet, callResponse)
689-
: super.onFailure(packet, callResponse);
692+
? onSuccess(packet, callResponse)
693+
: super.onFailure(packet, callResponse);
690694
}
691695

692696
@Override
@@ -720,10 +724,10 @@ public NextAction apply(Packet packet) {
720724
PodAwaiterStepFactory pw = delegate.getPodAwaiterStepFactory(info.getNamespace());
721725
info.setDeleting(false);
722726
packet
723-
.getComponents()
724-
.put(
725-
ProcessingConstants.DOMAIN_COMPONENT_NAME,
726-
Component.createFor(info, delegate.getVersion(), PodAwaiterStepFactory.class, pw));
727+
.getComponents()
728+
.put(
729+
ProcessingConstants.DOMAIN_COMPONENT_NAME,
730+
Component.createFor(info, delegate.getVersion(), PodAwaiterStepFactory.class, pw));
727731
return doNext(packet);
728732
}
729733
}
@@ -763,10 +767,10 @@ public NextAction apply(Packet packet) {
763767
unregisterStatusUpdater(ns, info.getDomainUid());
764768
PodAwaiterStepFactory pw = delegate.getPodAwaiterStepFactory(ns);
765769
packet
766-
.getComponents()
767-
.put(
768-
ProcessingConstants.DOMAIN_COMPONENT_NAME,
769-
Component.createFor(info, delegate.getVersion(), PodAwaiterStepFactory.class, pw));
770+
.getComponents()
771+
.put(
772+
ProcessingConstants.DOMAIN_COMPONENT_NAME,
773+
Component.createFor(info, delegate.getVersion(), PodAwaiterStepFactory.class, pw));
770774
return doNext(packet);
771775
}
772776
}
@@ -784,9 +788,9 @@ private class DomainStatusUpdate {
784788

785789
public void invoke() {
786790
Optional.ofNullable(getMatchingContainerStatus())
787-
.map(V1ContainerStatus::getState)
788-
.map(V1ContainerState::getWaiting)
789-
.ifPresent(waiting -> updateStatus(waiting.getReason(), waiting.getMessage()));
791+
.map(V1ContainerStatus::getState)
792+
.map(V1ContainerState::getWaiting)
793+
.ifPresent(waiting -> updateStatus(waiting.getReason(), waiting.getMessage()));
790794
}
791795

792796
private void updateStatus(String reason, String message) {
@@ -795,13 +799,12 @@ private void updateStatus(String reason, String message) {
795799

796800
private V1ContainerStatus getMatchingContainerStatus() {
797801
return Optional.ofNullable(pod.getStatus())
798-
.map(V1PodStatus::getContainerStatuses)
799-
.flatMap(this::getMatchingContainerStatus)
800-
.orElse(null);
802+
.map(V1PodStatus::getContainerStatuses)
803+
.flatMap(this::getMatchingContainerStatus)
804+
.orElse(null);
801805
}
802806

803-
private Optional<V1ContainerStatus> getMatchingContainerStatus(
804-
Collection<V1ContainerStatus> statuses) {
807+
private Optional<V1ContainerStatus> getMatchingContainerStatus(Collection<V1ContainerStatus> statuses) {
805808
return statuses.stream().filter(this::hasInstrospectorJobName).findFirst();
806809
}
807810

operator/src/main/java/oracle/kubernetes/operator/DomainStatusUpdater.java

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
2424
import oracle.kubernetes.operator.helpers.DomainPresenceInfo.ServerStartupInfo;
2525
import oracle.kubernetes.operator.helpers.PodHelper;
26+
import oracle.kubernetes.operator.logging.LoggingFacade;
27+
import oracle.kubernetes.operator.logging.LoggingFactory;
2628
import oracle.kubernetes.operator.logging.MessageKeys;
2729
import oracle.kubernetes.operator.rest.Scan;
2830
import oracle.kubernetes.operator.rest.ScanCache;
@@ -45,7 +47,6 @@
4547
import static oracle.kubernetes.operator.ProcessingConstants.SERVER_STATE_MAP;
4648
import static oracle.kubernetes.operator.WebLogicConstants.RUNNING_STATE;
4749
import static oracle.kubernetes.operator.WebLogicConstants.SHUTDOWN_STATE;
48-
import static oracle.kubernetes.operator.logging.LoggingFacade.LOGGER;
4950
import static oracle.kubernetes.weblogic.domain.model.DomainConditionType.Available;
5051
import static oracle.kubernetes.weblogic.domain.model.DomainConditionType.Failed;
5152
import static oracle.kubernetes.weblogic.domain.model.DomainConditionType.Progressing;
@@ -56,12 +57,11 @@
5657
* processing flow can use to explicitly set the condition to Progressing or Failed.
5758
*/
5859
public class DomainStatusUpdater {
60+
public static final String INSPECTING_DOMAIN_PROGRESS_REASON = "InspectingDomainPrescence";
5961
public static final String MANAGED_SERVERS_STARTING_PROGRESS_REASON = "ManagedServersStarting";
62+
public static final String SERVERS_READY_REASON = "ServersReady";
6063
public static final String ALL_STOPPED_AVAILABLE_REASON = "AllServersStopped";
61-
62-
static final String INSPECTING_DOMAIN_PROGRESS_REASON = "InspectingDomainPresence";
63-
static final String SERVERS_READY_REASON = "ServersReady";
64-
64+
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
6565
private static final String TRUE = "True";
6666
private static final String FALSE = "False";
6767

@@ -129,7 +129,7 @@ private static NextAction doDomainUpdate(
129129
meta.getName(),
130130
meta.getNamespace(),
131131
dom,
132-
new DefaultResponseStep<>(next) {
132+
new DefaultResponseStep<Domain>(next) {
133133
@Override
134134
public NextAction onFailure(Packet packet, CallResponse<Domain> callResponse) {
135135
if (callResponse.getStatusCode() == CallBuilder.NOT_FOUND) {
@@ -159,7 +159,7 @@ private static Step getRereadDomainConflictStep(
159159
.readDomainAsync(
160160
meta.getName(),
161161
meta.getNamespace(),
162-
new DefaultResponseStep<>(next) {
162+
new DefaultResponseStep<Domain>(next) {
163163
@Override
164164
public NextAction onSuccess(Packet packet, CallResponse<Domain> callResponse) {
165165
info.setDomain(callResponse.getResult());
@@ -290,8 +290,9 @@ private boolean allIntendedServersRunning() {
290290
}
291291

292292
private Stream<ServerStartupInfo> getServerStartupInfos() {
293-
return Optional.ofNullable(getInfo().getServerStartupInfo()).stream()
294-
.flatMap(Collection::stream);
293+
return Optional.ofNullable(getInfo().getServerStartupInfo())
294+
.map(Collection::stream)
295+
.orElse(Stream.empty());
295296
}
296297

297298
private Optional<WlsDomainConfig> getDomainConfig() {
@@ -301,7 +302,7 @@ private Optional<WlsDomainConfig> getDomainConfig() {
301302
private Optional<WlsDomainConfig> getScanCacheDomainConfig() {
302303
DomainPresenceInfo info = getInfo();
303304
Scan scan = ScanCache.INSTANCE.lookupScan(info.getNamespace(), info.getDomainUid());
304-
return Optional.ofNullable(scan).map(Scan::getWlsDomainConfig);
305+
return Optional.ofNullable(scan).map(s -> s.getWlsDomainConfig());
305306
}
306307

307308
private boolean shouldBeRunning(ServerStartupInfo startupInfo) {
@@ -321,9 +322,7 @@ private boolean hasServerPod(String serverName) {
321322
}
322323

323324
private boolean hasReadyServerPod(String serverName) {
324-
return Optional.ofNullable(getInfo().getServerPod(serverName))
325-
.filter(PodHelper::getReadyStatus)
326-
.isPresent();
325+
return Optional.ofNullable(getInfo().getServerPod(serverName)).filter(PodHelper::getReadyStatus).isPresent();
327326
}
328327

329328
Map<String, ServerStatus> getServerStatuses() {
@@ -377,17 +376,13 @@ Map<String, ClusterStatus> getClusterStatuses() {
377376
private ClusterStatus createClusterStatus(String clusterName) {
378377
return new ClusterStatus()
379378
.withClusterName(clusterName)
380-
.withReplicas(
381-
Optional.ofNullable(getClusterCounts().get(clusterName))
382-
.map(Long::intValue)
383-
.orElse(null))
379+
.withReplicas(Optional.ofNullable(getClusterCounts().get(clusterName)).map(Long::intValue).orElse(null))
384380
.withReadyReplicas(
385-
Optional.ofNullable(getClusterCounts(true).get(clusterName))
386-
.map(Long::intValue)
387-
.orElse(null))
381+
Optional.ofNullable(getClusterCounts(true).get(clusterName)).map(Long::intValue).orElse(null))
388382
.withMaximumReplicas(getClusterMaximumSize(clusterName));
389383
}
390384

385+
391386
private String getNodeName(String serverName) {
392387
return Optional.ofNullable(getInfo().getServerPod(serverName))
393388
.map(p -> p.getSpec().getNodeName())
@@ -408,34 +403,26 @@ private String getClusterNameFromPod(String serverName) {
408403

409404
private Collection<String> getServerNames() {
410405
Set<String> result = new HashSet<>();
411-
getDomainConfig()
412-
.ifPresent(
413-
config -> {
414-
result.addAll(config.getServerConfigs().keySet());
415-
for (WlsClusterConfig cluster : config.getConfiguredClusters()) {
416-
Optional.ofNullable(cluster.getDynamicServersConfig())
417-
.ifPresent(
418-
dynamicConfig ->
419-
Optional.ofNullable(dynamicConfig.getServerConfigs())
420-
.ifPresent(
421-
servers ->
422-
servers.forEach(item -> result.add(item.getName()))));
423-
}
424-
});
406+
getDomainConfig().stream().forEach(config -> {
407+
result.addAll(config.getServerConfigs().keySet());
408+
for (WlsClusterConfig cluster : config.getConfiguredClusters()) {
409+
Optional.ofNullable(cluster.getDynamicServersConfig())
410+
.ifPresent(dynamicConfig -> Optional.ofNullable(dynamicConfig.getServerConfigs())
411+
.ifPresent(servers -> servers.stream().forEach(item -> result.add(item.getName()))));
412+
}
413+
});
425414
return result;
426415
}
427416

428417
private Collection<String> getClusterNames() {
429418
Set<String> result = new HashSet<>();
430-
getDomainConfig().ifPresent(config -> result.addAll(config.getClusterConfigs().keySet()));
419+
getDomainConfig().stream().forEach(config -> result.addAll(config.getClusterConfigs().keySet()));
431420
return result;
432421
}
433422

434423
private Integer getClusterMaximumSize(String clusterName) {
435-
return getDomainConfig()
436-
.map(config -> Optional.ofNullable(config.getClusterConfig(clusterName)))
437-
.map(cluster -> cluster.map(WlsClusterConfig::getMaxClusterSize).orElse(0))
438-
.get();
424+
return getDomainConfig().map(config -> Optional.ofNullable(config.getClusterConfig(clusterName)))
425+
.map(cluster -> cluster.map(c -> c.getMaxClusterSize()).orElse(0)).get();
439426
}
440427
}
441428
}
@@ -542,8 +529,7 @@ public NextAction apply(Packet packet) {
542529
}
543530
}
544531

545-
private static boolean modifyDomainStatus(
546-
DomainStatus domainStatus, Consumer<DomainStatus> statusUpdateConsumer) {
532+
private static boolean modifyDomainStatus(DomainStatus domainStatus, Consumer<DomainStatus> statusUpdateConsumer) {
547533
final DomainStatus currentStatus = new DomainStatus(domainStatus);
548534
synchronized (domainStatus) {
549535
statusUpdateConsumer.accept(domainStatus);
@@ -580,6 +566,7 @@ public NextAction apply(Packet packet) {
580566
}
581567
});
582568

569+
583570
LOGGER.info(MessageKeys.DOMAIN_STATUS, context.getDomain().getDomainUid(), status);
584571
LOGGER.exiting();
585572

0 commit comments

Comments
 (0)